Line data Source code
1 : #include "../../burp.h" 2 : #include "../../alloc.h" 3 : #include "../../log.h" 4 : #include "lline.h" 5 : 6 8 : static void lline_free_content(struct lline *lline) 7 : { 8 8 : free_w(&lline->line); 9 : } 10 : 11 8 : static void lline_free(struct lline **lline) 12 : { 13 8 : if(!lline || !*lline) return; 14 8 : lline_free_content(*lline); 15 8 : free_v((void **)lline); 16 : } 17 : 18 36 : void llines_free(struct lline **lline) 19 : { 20 36 : struct lline *l; 21 36 : struct lline *lhead=*lline; 22 44 : while(lhead) 23 : { 24 8 : l=lhead; 25 8 : lhead=lhead->next; 26 8 : lline_free(&l); 27 : } 28 36 : *lline=NULL; 29 36 : } 30 : 31 9 : static struct lline *lline_alloc(char *line) 32 : { 33 9 : struct lline *llnew=NULL; 34 9 : if(!line) 35 : { 36 1 : logp("%s called with NULL line!\n", __func__); 37 1 : return NULL; 38 : } 39 16 : if(!(llnew=(struct lline *) 40 8 : calloc_w(1, sizeof(struct lline), __func__)) 41 8 : || !(llnew->line=strdup_w(line, __func__))) 42 0 : return NULL; 43 : return llnew; 44 : } 45 : 46 9 : int lline_add(struct lline **lline, char *line) 47 : { 48 9 : struct lline *l=NULL; 49 9 : struct lline *llast=NULL; 50 9 : struct lline *llnew=NULL; 51 : 52 9 : if(!(llnew=lline_alloc(line))) return -1; 53 : 54 17 : for(l=*lline; l; l=l->next) 55 : { 56 9 : l->prev=llast; 57 9 : llast=l; 58 : } 59 8 : if(llast) 60 : { 61 5 : llnew->next=llast->next; 62 5 : llast->next=llnew; 63 5 : llnew->prev=llast; 64 : } 65 : else 66 : { 67 3 : *lline=llnew; 68 3 : llnew->next=l; 69 : } 70 : 71 : return 0; 72 : }