LCOV - code coverage report
Current view: top level - src - slist.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 67 67 100.0 %
Date: 2022-08-30 22:36:43 Functions: 6 6 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             : 
       7         148 : struct slist *slist_alloc(void)
       8             : {
       9         148 :         struct slist *slist=NULL;
      10         148 :         if(!(slist=(struct slist *)calloc_w(1, sizeof(struct slist), __func__)))
      11           1 :                 slist_free(&slist);
      12         148 :         return slist;
      13             : }
      14             : 
      15         155 : void slist_free(struct slist **slist)
      16             : {
      17             :         struct sbuf *sb;
      18             :         struct sbuf *shead;
      19         155 :         if(!slist || !*slist)
      20           8 :                 return;
      21         147 :         shead=(*slist)->head;
      22       12173 :         while(shead)
      23             :         {
      24       11879 :                 sb=shead;
      25       11879 :                 shead=shead->next;
      26       11879 :                 sbuf_free(&sb);
      27             :         }
      28         147 :         free_v((void **)slist);
      29             : }
      30             : 
      31       11887 : void slist_add_sbuf(struct slist *slist, struct sbuf *sb)
      32             : {
      33       11887 :         if(slist->tail)
      34             :         {
      35             :                 // Add to the end of the list.
      36       11746 :                 slist->tail->next=sb;
      37       11746 :                 slist->tail=sb;
      38             :                 // Markers might have fallen off the end. Start them again
      39             :                 // on the tail.
      40       11746 :                 if(!slist->last_requested)
      41           1 :                         slist->last_requested=slist->tail;
      42       11746 :                 if(!slist->add_sigs_here)
      43           1 :                         slist->add_sigs_here=slist->tail;
      44       11746 :                 if(!slist->blks_to_request)
      45           1 :                         slist->blks_to_request=slist->tail;
      46       11746 :                 if(!slist->blks_to_send)
      47           1 :                         slist->blks_to_send=slist->tail;
      48             :         }
      49             :         else
      50             :         {
      51             :                 // Start the list.
      52         141 :                 slist->head=sb;
      53         141 :                 slist->tail=sb;
      54             :                 // Pointers to the head that can move along the list
      55             :                 // at a different rate.
      56         141 :                 slist->last_requested=sb;
      57         141 :                 slist->add_sigs_here=sb;
      58         141 :                 slist->blks_to_request=sb;
      59         141 :                 slist->blks_to_send=sb;
      60             :         }
      61       11887 :         slist->count++;
      62       11887 : }
      63             : 
      64           8 : static void adjust_dropped_markers(struct slist *slist, struct sbuf *sb)
      65             : {
      66           8 :         if(sb==slist->tail)
      67           1 :                 slist->tail=sb->next;
      68           8 :         if(sb==slist->last_requested)
      69           6 :                 slist->last_requested=sb->next;
      70           8 :         if(sb==slist->add_sigs_here)
      71           6 :                 slist->add_sigs_here=sb->next;
      72           8 :         if(sb==slist->blks_to_request)
      73           6 :                 slist->blks_to_request=sb->next;
      74           8 :         if(sb==slist->blks_to_send)
      75           6 :                 slist->blks_to_send=sb->next;
      76           8 : }
      77             : 
      78           8 : int slist_del_sbuf(struct slist *slist, struct sbuf *sb)
      79             : {
      80             :         struct sbuf *s;
      81           8 :         if(!slist)
      82             :                 return 0;
      83             : 
      84           7 :         if(slist->head==sb)
      85             :         {
      86             :                 // There is one entry in the list.
      87           4 :                 slist->head=slist->head->next;
      88           4 :                 slist->count--;
      89             :         }
      90             :         else
      91             :         {
      92           5 :                 for(s=slist->head; s; s=s->next)
      93             :                 {
      94           4 :                         if(s->next!=sb) continue;
      95           3 :                         s->next=sb->next;
      96           3 :                         if(!sb->next)
      97           1 :                                 slist->tail=s;
      98           3 :                         slist->count--;
      99           3 :                         break;
     100             :                 }
     101             :         }
     102             : 
     103             :         // It is possible for the markers to drop behind.
     104           7 :         adjust_dropped_markers(slist, sb);
     105             : 
     106           7 :         return 0;
     107             : }
     108             : 
     109           1 : void slist_advance(struct slist *slist)
     110             : {
     111             :         struct sbuf *sb;
     112           1 :         sb=slist->head;
     113             : 
     114             :         // It is possible for the markers to drop behind.
     115           1 :         adjust_dropped_markers(slist, sb);
     116             : 
     117           1 :         slist->head=sb->next;
     118             : 
     119           1 :         slist->count--;
     120             : 
     121           1 :         sbuf_free(&sb);
     122           1 : }

Generated by: LCOV version 1.13