LCOV - code coverage report
Current view: top level - src - slist.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 80 80 100.0 %
Date: 2019-11-30 11:33:35 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         326 : struct slist *slist_alloc(void)
       9             : {
      10         326 :         struct slist *slist=NULL;
      11         326 :         if(!(slist=(struct slist *)calloc_w(1, sizeof(struct slist), __func__))
      12         325 :           || !(slist->blist=blist_alloc()))
      13           1 :                 slist_free(&slist);
      14         326 :         return slist;
      15             : }
      16             : 
      17         349 : void slist_free(struct slist **slist)
      18             : {
      19             :         struct sbuf *sb;
      20             :         struct sbuf *shead;
      21         349 :         if(!slist || !*slist)
      22          24 :                 return;
      23         325 :         blist_free(&(*slist)->blist);
      24         325 :         shead=(*slist)->head;
      25       58829 :         while(shead)
      26             :         {
      27       58179 :                 sb=shead;
      28       58179 :                 shead=shead->next;
      29       58179 :                 sbuf_free(&sb);
      30             :         }
      31         325 :         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 :         slist->count++;
      65       91906 : }
      66             : 
      67       33705 : static void adjust_dropped_markers(struct slist *slist, struct sbuf *sb)
      68             : {
      69       33705 :         if(sb==slist->tail)
      70          10 :                 slist->tail=sb->next;
      71       33705 :         if(sb==slist->last_requested)
      72          17 :                 slist->last_requested=sb->next;
      73       33705 :         if(sb==slist->add_sigs_here)
      74          26 :                 slist->add_sigs_here=sb->next;
      75       33705 :         if(sb==slist->blks_to_request)
      76       16861 :                 slist->blks_to_request=sb->next;
      77       33705 :         if(sb==slist->blks_to_send)
      78       33694 :                 slist->blks_to_send=sb->next;
      79       33705 : }
      80             : 
      81          13 : int slist_del_sbuf(struct slist *slist, struct sbuf *sb)
      82             : {
      83             :         struct sbuf *s;
      84          13 :         if(!slist)
      85             :                 return 0;
      86          12 :         if(sb->protocol2->bstart
      87          11 :           || sb->protocol2->bend
      88          11 :           || sb->protocol2->bsighead)
      89             :         {
      90           1 :                 logp("Cannot delete sbuf with blk markers: %s\n",
      91             :                         iobuf_to_printable(&sb->path));
      92           1 :                 return -1;
      93             :         }
      94             : 
      95          11 :         if(slist->head==sb)
      96             :         {
      97             :                 // There is one entry in the list.
      98           6 :                 slist->head=slist->head->next;
      99           6 :                 slist->count--;
     100             :         }
     101             :         else
     102             :         {
     103           9 :                 for(s=slist->head; s; s=s->next)
     104             :                 {
     105           7 :                         if(s->next!=sb) continue;
     106           5 :                         s->next=sb->next;
     107           5 :                         if(!sb->next)
     108           2 :                                 slist->tail=s;
     109           5 :                         slist->count--;
     110           5 :                         break;
     111             :                 }
     112             :         }
     113             : 
     114             :         // It is possible for the markers to drop behind.
     115          11 :         adjust_dropped_markers(slist, sb);
     116             : 
     117          11 :         return 0;
     118             : }
     119             : 
     120           1 : int slist_del_sbuf_by_index(struct slist *slist, uint64_t index)
     121             : {
     122             :         struct sbuf *sb;
     123           3 :         for(sb=slist->head; sb; sb=sb->next)
     124             :         {
     125           3 :                 if(sb->protocol2->index==index)
     126             :                 {
     127           1 :                         if(slist_del_sbuf(slist, sb))
     128             :                                 return -1;
     129           1 :                         sbuf_free(&sb);
     130           1 :                         break;
     131             :                 }
     132             :         }
     133             :         return 0;
     134             : }
     135             : 
     136       33694 : void slist_advance(struct slist *slist)
     137             : {
     138             :         struct sbuf *sb;
     139       33694 :         sb=slist->head;
     140             : 
     141             :         // It is possible for the markers to drop behind.
     142       33694 :         adjust_dropped_markers(slist, sb);
     143             : 
     144       33694 :         slist->head=sb->next;
     145             : 
     146       33694 :         slist->count--;
     147             : 
     148       33694 :         sbuf_free(&sb);
     149       33694 : }

Generated by: LCOV version 1.13