LCOV - code coverage report
Current view: top level - src - incexc_send.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 42 50 84.0 %
Date: 2016-07-31 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             : 
       9          39 : static int send_incexc_string(struct asfd *asfd,
      10             :         const char *field, const char *str)
      11             : {
      12          39 :         char *tosend=NULL;
      13          39 :         int ret=-1;
      14          39 :         if(!str) return 0;
      15          22 :         if(!(tosend=prepend_n(field, str, strlen(str), " = ")))
      16             :                 goto end;
      17          22 :         if(asfd->write_str(asfd, CMD_GEN, tosend))
      18             :         {
      19           0 :                 logp("Error in async_write_str when sending incexc\n");
      20           0 :                 goto end;
      21             :         }
      22             :         ret=0;
      23             : end:
      24          22 :         free_w(&tosend);
      25          22 :         return ret;
      26             : }
      27             : 
      28          18 : static int send_incexc_str(struct asfd *asfd, struct conf *conf)
      29             : {
      30          18 :         return send_incexc_string(asfd, conf->field, get_string(conf));
      31             : }
      32             : 
      33          19 : static int send_incexc_uint(struct asfd *asfd, struct conf *conf)
      34             : {
      35          19 :         char tmp[64]="";
      36          19 :         snprintf(tmp, sizeof(tmp), "%d", get_int(conf));
      37          19 :         return send_incexc_string(asfd, conf->field, tmp);
      38             : }
      39             : 
      40           2 : static int send_incexc_uint64(struct asfd *asfd, struct conf *conf)
      41             : {
      42           2 :         char tmp[32]="";
      43           2 :         snprintf(tmp, sizeof(tmp), "%" PRIu64, get_uint64_t(conf));
      44           2 :         return send_incexc_string(asfd, conf->field, tmp);
      45             : }
      46             : 
      47          21 : static int send_incexc_strlist(struct asfd *asfd, struct conf *conf)
      48             : {
      49             :         struct strlist *l;
      50          21 :         for(l=get_strlist(conf); l; l=l->next)
      51           0 :                 if(send_incexc_string(asfd, conf->field, l->path)) return -1;
      52             :         return 0;
      53             : }
      54             : 
      55           5 : static int do_sends(struct asfd *asfd, struct conf **confs, int flag)
      56             : {
      57           5 :         int i=0;
      58           5 :         int r=-1;
      59         790 :         for(i=0; i<OPT_MAX; i++)
      60             :         {
      61         785 :                 if(!(confs[i]->flags & flag)) continue;
      62          60 :                 switch(confs[i]->conf_type)
      63             :                 {
      64             :                         case CT_STRING:
      65          18 :                                 if(send_incexc_str(asfd, confs[i]))
      66             :                                         goto end;
      67             :                                 break;
      68             :                         case CT_STRLIST:
      69          21 :                                 if(send_incexc_strlist(asfd, confs[i]))
      70             :                                         goto end;
      71             :                                 break;
      72             :                         case CT_UINT:
      73          19 :                                 if(send_incexc_uint(asfd, confs[i]))
      74             :                                         goto end;
      75             :                                 break;
      76             :                         case CT_SSIZE_T:
      77           2 :                                 if(send_incexc_uint64(asfd, confs[i]))
      78             :                                         goto end;
      79             :                                 break;
      80             :                         case CT_FLOAT:
      81             :                         case CT_MODE_T:
      82             :                         case CT_E_BURP_MODE:
      83             :                         case CT_E_PROTOCOL:
      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           0 :         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           2 :         if(do_sends(asfd, confs, CONF_FLAG_INCEXC)
     116           1 :           || do_request_response(asfd, "sincexc end", "sincexc end ok"))
     117             :                 return -1;
     118           1 :         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           8 :         if(do_sends(asfd, confs, CONF_FLAG_INCEXC_RESTORE)
     126           4 :           || do_request_response(asfd, "srestore end", "srestore end ok"))
     127             :                 return -1;
     128           3 :         return 0;
     129             : }

Generated by: LCOV version 1.10