LCOV - code coverage report
Current view: top level - src - incexc_send.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 40 47 85.1 %
Date: 2022-12-03 01:09:05 Functions: 9 10 90.0 %

          Line data    Source code
       1             : #include "burp.h"
       2             : #include "alloc.h"
       3             : #include "asfd.h"
       4             : #include "cmd.h"
       5             : #include "log.h"
       6             : #include "prepend.h"
       7             : #include "strlist.h"
       8             : #include "incexc_send.h"
       9             : 
      10          49 : static int send_incexc_string(struct asfd *asfd,
      11             :         const char *field, const char *str)
      12             : {
      13          49 :         char *tosend=NULL;
      14          49 :         int ret=-1;
      15          49 :         if(!str) return 0;
      16          27 :         if(!(tosend=prepend_n(field, str, strlen(str), " = ")))
      17             :                 goto end;
      18          27 :         if(asfd->write_str(asfd, CMD_GEN, tosend))
      19             :         {
      20           0 :                 logp("Error in async_write_str when sending incexc\n");
      21           0 :                 goto end;
      22             :         }
      23             :         ret=0;
      24             : end:
      25          27 :         free_w(&tosend);
      26          27 :         return ret;
      27             : }
      28             : 
      29          23 : static int send_incexc_str(struct asfd *asfd, struct conf *conf)
      30             : {
      31          23 :         return send_incexc_string(asfd, conf->field, get_string(conf));
      32             : }
      33             : 
      34          24 : static int send_incexc_uint(struct asfd *asfd, struct conf *conf)
      35             : {
      36          24 :         char tmp[64]="";
      37          24 :         snprintf(tmp, sizeof(tmp), "%d", get_int(conf));
      38          24 :         return send_incexc_string(asfd, conf->field, tmp);
      39             : }
      40             : 
      41           2 : static int send_incexc_uint64(struct asfd *asfd, struct conf *conf)
      42             : {
      43           2 :         char tmp[32]="";
      44           2 :         snprintf(tmp, sizeof(tmp), "%" PRIu64, get_uint64_t(conf));
      45           2 :         return send_incexc_string(asfd, conf->field, tmp);
      46             : }
      47             : 
      48          24 : static int send_incexc_strlist(struct asfd *asfd, struct conf *conf)
      49             : {
      50             :         struct strlist *l;
      51          24 :         for(l=get_strlist(conf); l; l=l->next)
      52           0 :                 if(send_incexc_string(asfd, conf->field, l->path)) return -1;
      53             :         return 0;
      54             : }
      55             : 
      56           5 : static int do_sends(struct asfd *asfd, struct conf **confs, int flag)
      57             : {
      58           5 :         int i=0;
      59           5 :         int r=-1;
      60         965 :         for(i=0; i<OPT_MAX; i++)
      61             :         {
      62         960 :                 if(!(confs[i]->flags & flag)) continue;
      63          73 :                 switch(confs[i]->conf_type)
      64             :                 {
      65             :                         case CT_STRING:
      66          23 :                                 if(send_incexc_str(asfd, confs[i]))
      67             :                                         goto end;
      68             :                                 break;
      69             :                         case CT_STRLIST:
      70          24 :                                 if(send_incexc_strlist(asfd, confs[i]))
      71             :                                         goto end;
      72             :                                 break;
      73             :                         case CT_UINT:
      74          24 :                                 if(send_incexc_uint(asfd, confs[i]))
      75             :                                         goto end;
      76             :                                 break;
      77             :                         case CT_SSIZE_T:
      78           2 :                                 if(send_incexc_uint64(asfd, confs[i]))
      79             :                                         goto end;
      80             :                                 break;
      81             :                         case CT_FLOAT:
      82             :                         case CT_MODE_T:
      83             :                         case CT_E_BURP_MODE:
      84             :                         case CT_E_RECOVERY_METHOD:
      85             :                         case CT_E_RSHASH:
      86             :                         case CT_CNTR:
      87             :                                 break;
      88             :                 }
      89             :         }
      90             :         r=0;
      91             : end:
      92           5 :         return r;
      93             : }
      94             : 
      95           5 : static int do_request_response(struct asfd *asfd,
      96             :         const char *reqstr, const char *repstr)
      97             : {
      98           5 :         return (asfd->write_str(asfd, CMD_GEN, reqstr)
      99           5 :           || asfd_read_expect(asfd, CMD_GEN, repstr));
     100             : }
     101             : 
     102           0 : int incexc_send_client(struct asfd *asfd, struct conf **confs)
     103             : {
     104           0 :         if(do_request_response(asfd, "incexc", "incexc ok")
     105           0 :           || do_sends(asfd, confs, CONF_FLAG_INCEXC)
     106           0 :           || do_request_response(asfd, "incexc end", "incexc end ok"))
     107             :                 return -1;
     108             :         return 0;
     109             : }
     110             : 
     111           1 : int incexc_send_server(struct asfd *asfd, struct conf **confs)
     112             : {
     113             :         /* 'sincexc' and 'sincexc ok' have already been exchanged,
     114             :            so go straight into doing the sends. */
     115           1 :         if(do_sends(asfd, confs, CONF_FLAG_INCEXC)
     116           1 :           || do_request_response(asfd, "sincexc end", "sincexc end ok"))
     117             :                 return -1;
     118             :         return 0;
     119             : }
     120             : 
     121           4 : int incexc_send_server_restore(struct asfd *asfd, struct conf **confs)
     122             : {
     123             :         /* 'srestore' and 'srestore ok' have already been exchanged,
     124             :            so go straight into doing the sends. */
     125           4 :         if(do_sends(asfd, confs, CONF_FLAG_INCEXC_RESTORE)
     126           4 :           || do_request_response(asfd, "srestore end", "srestore end ok"))
     127             :                 return -1;
     128             :         return 0;
     129             : }

Generated by: LCOV version 1.13