Line data Source code
1 : #include "burp.h"
2 : #include "alloc.h"
3 : #include "sbuf.h"
4 : #include "slist.h"
5 : #include "protocol2/blist.h"
6 :
7 256 : struct slist *slist_alloc(void)
8 : {
9 256 : struct slist *slist=NULL;
10 768 : if(!(slist=(struct slist *)calloc_w(1, sizeof(struct slist), __func__))
11 512 : || !(slist->blist=blist_alloc()))
12 0 : slist_free(&slist);
13 256 : return slist;
14 : }
15 :
16 257 : void slist_free(struct slist **slist)
17 : {
18 : struct sbuf *sb;
19 : struct sbuf *shead;
20 514 : if(!slist || !*slist) return;
21 256 : blist_free(&(*slist)->blist);
22 256 : shead=(*slist)->head;
23 24457 : while(shead)
24 : {
25 23945 : sb=shead;
26 23945 : shead=shead->next;
27 23945 : sbuf_free(&sb);
28 : }
29 256 : free_v((void **)slist);
30 : }
31 :
32 23945 : void slist_add_sbuf(struct slist *slist, struct sbuf *sb)
33 : {
34 23945 : if(slist->tail)
35 : {
36 : // Add to the end of the list.
37 23699 : slist->tail->next=sb;
38 23699 : slist->tail=sb;
39 : // Markers might have fallen off the end. Start them again
40 : // on the tail.
41 23699 : if(!slist->last_requested) slist->last_requested=slist->tail;
42 23699 : if(!slist->add_sigs_here) slist->add_sigs_here=slist->tail;
43 23699 : if(!slist->blks_to_request) slist->blks_to_request=slist->tail;
44 23699 : if(!slist->blks_to_send) slist->blks_to_send=slist->tail;
45 : }
46 : else
47 : {
48 : // Start the list.
49 246 : slist->head=sb;
50 246 : slist->tail=sb;
51 : // Pointers to the head that can move along the list
52 : // at a different rate.
53 246 : slist->last_requested=sb;
54 246 : slist->add_sigs_here=sb;
55 246 : slist->blks_to_request=sb;
56 246 : slist->blks_to_send=sb;
57 : }
58 23945 : }
|