roster.c (1309B)
1 /* 2 * Copy me if you can. 3 * by 20h 4 */ 5 6 #include <u.h> 7 #include <libc.h> 8 #include "dat.h" 9 #include "roster.h" 10 11 void 12 freeilist(ilist *i) 13 { 14 while(i != nil){ 15 if(i->name != nil) 16 free(i->name); 17 if(i->val != nil) 18 free(i->val); 19 if(i->n != nil){ 20 i = i->n; 21 free(i->p); 22 } else { 23 free(i); 24 i = nil; 25 } 26 } 27 } 28 29 30 void 31 freejabberc(jabberc *j) 32 { 33 if(j != nil){ 34 if(j->stat != nil) 35 free(j->stat); 36 if(j->name != nil) 37 free(j->name); 38 if(j->reso != nil) 39 free(j->reso); 40 if(j->serv != nil) 41 free(j->serv); 42 if(j->jid != nil) 43 free(j->jid); 44 if(j->show != nil) 45 free(j->show); 46 if(j->dest != nil) 47 free(j->dest); 48 if(j->list != nil) 49 freeilist(j->list); 50 free(j); 51 } 52 return; 53 } 54 55 jabberc * 56 mkjabberc(void) 57 { 58 return reallocj(nil, sizeof(jabberc), 2); 59 } 60 61 ilist * 62 lastilist(ilist *i) 63 { 64 if(i != nil) 65 while(i->n != nil) 66 i = i->n; 67 68 return i; 69 } 70 71 ilist * 72 mkilist(char *name, char *val) 73 { 74 ilist *ret; 75 76 ret = reallocj(nil, sizeof(ilist), 2); 77 if(name != nil) 78 ret->name = strdup(name); 79 if(val != nil) 80 ret->val = strdup(val); 81 82 return ret; 83 } 84 85 ilist * 86 addilist(ilist *i, char *name, char *val) 87 { 88 ilist *ret; 89 90 ret = lastilist(i); 91 if(ret == nil) 92 return mkilist(name, val); 93 else { 94 ret->n = mkilist(name, val); 95 ret->n->p = ret; 96 } 97 ret->n->n = nil; 98 99 return i; 100 } 101 102