LCOV - code coverage report
Current view: top level - src - slist.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 76 76 100.0 %
Date: 2016-11-07 Functions: 7 7 100.0 %

          Line data    Source code
       1             : #include "burp.h"
       2             : #include "alloc.h"
       3             : #include "log.h"
       4             : #include "sbuf.h"
       5             : #include "slist.h"
       6             : #include "protocol2/blist.h"
       7             : 
       8         324 : struct slist *slist_alloc(void)
       9             : {
      10         324 :         struct slist *slist=NULL;
      11         324 :         if(!(slist=(struct slist *)calloc_w(1, sizeof(struct slist), __func__))
      12         323 :           || !(slist->blist=blist_alloc()))
      13           1 :                 slist_free(&slist);
      14         324 :         return slist;
      15             : }
      16             : 
      17         347 : void slist_free(struct slist **slist)
      18             : {
      19             :         struct sbuf *sb;
      20             :         struct sbuf *shead;
      21         347 :         if(!slist || !*slist)
      22          24 :                 return;
      23         323 :         blist_free(&(*slist)->blist);
      24         323 :         shead=(*slist)->head;
      25       58823 :         while(shead)
      26             :         {
      27       58177 :                 sb=shead;
      28       58177 :                 shead=shead->next;
      29       58177 :                 sbuf_free(&sb);
      30             :         }
      31         323 :         free_v((void **)slist);
      32             : }
      33             : 
      34       91906 : void slist_add_sbuf(struct slist *slist, struct sbuf *sb)
      35             : {
      36       91906 :         if(slist->tail)
      37             :         {
      38             :                 // Add to the end of the list.
      39       91607 :                 slist->tail->next=sb;
      40       91607 :                 slist->tail=sb;
      41             :                 // Markers might have fallen off the end. Start them again
      42             :                 // on the tail.
      43       91607 :                 if(!slist->last_requested)
      44          12 :                         slist->last_requested=slist->tail;
      45       91607 :                 if(!slist->add_sigs_here)
      46           1 :                         slist->add_sigs_here=slist->tail;
      47       91607 :                 if(!slist->blks_to_request)
      48           1 :                         slist->blks_to_request=slist->tail;
      49       91607 :                 if(!slist->blks_to_send)
      50          12 :                         slist->blks_to_send=slist->tail;
      51             :         }
      52             :         else
      53             :         {
      54             :                 // Start the list.
      55         299 :                 slist->head=sb;
      56         299 :                 slist->tail=sb;
      57             :                 // Pointers to the head that can move along the list
      58             :                 // at a different rate.
      59         299 :                 slist->last_requested=sb;
      60         299 :                 slist->add_sigs_here=sb;
      61         299 :                 slist->blks_to_request=sb;
      62         299 :                 slist->blks_to_send=sb;
      63             :         }
      64       91906 : }
      65             : 
      66       33705 : static void adjust_dropped_markers(struct slist *slist, struct sbuf *sb)
      67             : {
      68       33705 :         if(sb==slist->tail)
      69          10 :                 slist->tail=sb->next;
      70       33705 :         if(sb==slist->last_requested)
      71          17 :                 slist->last_requested=sb->next;
      72       33705 :         if(sb==slist->add_sigs_here)
      73          26 :                 slist->add_sigs_here=sb->next;
      74       33705 :         if(sb==slist->blks_to_request)
      75       16861 :                 slist->blks_to_request=sb->next;
      76       33705 :         if(sb==slist->blks_to_send)
      77       33694 :                 slist->blks_to_send=sb->next;
      78       33705 : }
      79             : 
      80          13 : int slist_del_sbuf(struct slist *slist, struct sbuf *sb)
      81             : {
      82             :         struct sbuf *s;
      83          13 :         if(!slist)
      84             :                 return 0;
      85          12 :         if(sb->protocol2->bstart
      86          11 :           || sb->protocol2->bend
      87          11 :           || sb->protocol2->bsighead)
      88             :         {
      89           2 :                 logp("Cannot delete sbuf with blk markers: %c:%s\n",
      90           1 :                         sb->path.cmd, sb->path.buf);
      91           1 :                 return -1;
      92             :         }
      93             : 
      94          11 :         if(slist->head==sb)
      95             :         {
      96             :                 // There is one entry in the list.
      97           6 :                 slist->head=slist->head->next;
      98             :         }
      99             :         else
     100             :         {
     101           9 :                 for(s=slist->head; s; s=s->next)
     102             :                 {
     103           7 :                         if(s->next!=sb) continue;
     104           5 :                         s->next=sb->next;
     105           5 :                         if(!sb->next)
     106           2 :                                 slist->tail=s;
     107             :                         break;
     108             :                 }
     109             :         }
     110             : 
     111             :         // It is possible for the markers to drop behind.
     112          11 :         adjust_dropped_markers(slist, sb);
     113             : 
     114          11 :         return 0;
     115             : }
     116             : 
     117           1 : int slist_del_sbuf_by_index(struct slist *slist, uint64_t index)
     118             : {
     119             :         struct sbuf *sb;
     120           3 :         for(sb=slist->head; sb; sb=sb->next)
     121             :         {
     122           3 :                 if(sb->protocol2->index==index)
     123             :                 {
     124           1 :                         if(slist_del_sbuf(slist, sb))
     125             :                                 return -1;
     126           1 :                         sbuf_free(&sb);
     127           1 :                         break;
     128             :                 }
     129             :         }
     130             :         return 0;
     131             : }
     132             : 
     133       33694 : void slist_advance(struct slist *slist)
     134             : {
     135             :         struct sbuf *sb;
     136       33694 :         sb=slist->head;
     137             : 
     138             :         // It is possible for the markers to drop behind.
     139       33694 :         adjust_dropped_markers(slist, sb);
     140             : 
     141       33694 :         slist->head=sb->next;
     142             : 
     143       33694 :         sbuf_free(&sb);
     144       33694 : }

Generated by: LCOV version 1.10