LCOV - code coverage report
Current view: top level - src/client - monitor.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 19 27 70.4 %
Date: 2020-07-02 21:37:08 Functions: 2 3 66.7 %

          Line data    Source code
       1             : #include "../burp.h"
       2             : #include "../asfd.h"
       3             : #include "../async.h"
       4             : #include "../conf.h"
       5             : #include "../cmd.h"
       6             : #include "../iobuf.h"
       7             : #include "../log.h"
       8             : #include "monitor.h"
       9             : 
      10           4 : static int copy_input_to_output(struct asfd *in, struct asfd *out)
      11             : {
      12             :         struct iobuf wbuf;
      13           4 :         iobuf_set(&wbuf, CMD_GEN, in->rbuf->buf, in->rbuf->len);
      14           4 :         return out->write(out, &wbuf);
      15             : }
      16             : 
      17             : #ifndef UTEST
      18             : static
      19             : #endif
      20           3 : int monitor_client_main_loop(struct async *as)
      21             : {
      22             :         struct asfd *asfd;
      23             :         struct asfd *sfd; // Server fd.
      24             :         struct asfd *sin;
      25             :         struct asfd *sout;
      26             : 
      27           3 :         sfd=as->asfd;
      28           3 :         sin=sfd->next;
      29           3 :         sout=sin->next;
      30             : 
      31             :         while(1)
      32             :         {
      33           7 :                 if(as->read_write(as))
      34             :                 {
      35           3 :                         logp("Exiting main loop\n");
      36           3 :                         break;
      37             :                 }
      38             : 
      39          16 :                 for(asfd=as->asfd; asfd; asfd=asfd->next)
      40          16 :                         while(asfd->rbuf->buf)
      41             :                 {
      42           4 :                         if(asfd==sfd)
      43             :                         {
      44           2 :                                 if(copy_input_to_output(sfd, sout))
      45             :                                         goto error;
      46             :                         }
      47           2 :                         else if(asfd==sin)
      48             :                         {
      49           2 :                                 if(copy_input_to_output(sin, sfd))
      50             :                                         goto error;
      51             :                         }
      52           4 :                         iobuf_free_content(asfd->rbuf);
      53           4 :                         if(asfd->parse_readbuf(asfd))
      54             :                                 goto error;
      55             :                 }
      56             : 
      57             :                 //if(sel) logp("sel: %s\n", sel->name);
      58             :         }
      59             : 
      60             : error:
      61           3 :         return -1;
      62             : }
      63             : 
      64           0 : int do_monitor_client(struct asfd *asfd)
      65             : {
      66           0 :         int ret=-1;
      67           0 :         struct async *as=asfd->as;
      68           0 : logp("in monitor\n");
      69             : 
      70             :         // I tried to just printf to stdout, but the strings to print would be
      71             :         // so long that I would start to get printf errors.
      72             :         // Using the asfd stuff works well though.
      73           0 :         if(!setup_asfd_stdin(as)
      74           0 :          || !setup_asfd_stdout(as))
      75             :                 goto end;
      76           0 :         ret=monitor_client_main_loop(as);
      77             : end:
      78           0 :         return ret;
      79             : }

Generated by: LCOV version 1.13