LCOV - code coverage report
Current view: top level - src - incexc_recv.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 25 25 100.0 %
Date: 2022-05-01 01:22:11 Functions: 6 6 100.0 %

          Line data    Source code
       1             : #include "burp.h"
       2             : #include "alloc.h"
       3             : #include "asfd.h"
       4             : #include "async.h"
       5             : #include "cmd.h"
       6             : #include "iobuf.h"
       7             : #include "prepend.h"
       8             : #include "incexc_recv.h"
       9             : 
      10             : static const char *endreqstrf;
      11             : static const char *endrepstrf;
      12             : 
      13          18 : static int add_to_incexc(char **incexc, const char *src, size_t len)
      14             : {
      15             :         char *tmp;
      16          18 :         if(!(tmp=prepend_n(*incexc?:"", src, len, *incexc?"\n":""))) return -1;
      17          18 :         free_w(incexc);
      18          18 :         *incexc=tmp;
      19          18 :         return 0;
      20             : }
      21             : 
      22          18 : static enum asl_ret incexc_recv_func(struct asfd *asfd,
      23             :         __attribute__ ((unused)) struct conf **confs, void *param)
      24             : {
      25          18 :         char **incexc=(char **)param;
      26          18 :         if(!strcmp(asfd->rbuf->buf, endreqstrf))
      27             :         {
      28           6 :                 if(asfd->write_str(asfd, CMD_GEN, endrepstrf))
      29             :                         return ASL_END_ERROR;
      30           6 :                 return ASL_END_OK;
      31             :         }
      32          12 :         if(add_to_incexc(incexc,
      33             :                 asfd->rbuf->buf, asfd->rbuf->len))
      34             :                         return ASL_END_ERROR;
      35          12 :         return ASL_CONTINUE;
      36             : }
      37             : 
      38             : 
      39           6 : static int incexc_recv(struct asfd *asfd, char **incexc,
      40             :         const char *repstr, const char *endreqstr,
      41             :         const char *endrepstr, struct conf **confs)
      42             : {
      43           6 :         free_w(incexc);
      44           6 :         if(asfd->write_str(asfd, CMD_GEN, repstr)) return -1;
      45             : 
      46           6 :         endreqstrf=endreqstr;
      47           6 :         endrepstrf=endrepstr;
      48           6 :         if(asfd->simple_loop(asfd, confs, incexc, __func__, incexc_recv_func))
      49             :                 return -1;
      50             : 
      51             :         // Need to put another new line at the end.
      52           6 :         return add_to_incexc(incexc, "\n", 1);
      53             : }
      54             : 
      55           1 : int incexc_recv_client(struct asfd *asfd,
      56             :         char **incexc, struct conf **confs)
      57             : {
      58           1 :         return incexc_recv(asfd, incexc,
      59             :                 "sincexc ok", "sincexc end", "sincexc end ok",
      60             :                 confs);
      61             : }
      62             : 
      63           4 : int incexc_recv_client_restore(struct asfd *asfd,
      64             :         char **incexc, struct conf **confs)
      65             : {
      66           4 :         return incexc_recv(asfd, incexc,
      67             :                 "srestore ok", "srestore end", "srestore end ok",
      68             :                 confs);
      69             : }
      70             : 
      71           1 : int incexc_recv_server(struct asfd *asfd,
      72             :         char **incexc, struct conf **confs)
      73             : {
      74           1 :         return incexc_recv(asfd, incexc,
      75             :                 "incexc ok", "incexc end", "incexc end ok",
      76             :                 confs);
      77             : }

Generated by: LCOV version 1.13