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

Generated by: LCOV version 1.10