X-Git-Url: http://andersk.mit.edu/gitweb/libfaim.git/blobdiff_plain/24286d932574981faaace4ff3d41fc1231119122..a25832e66b80e7159f37795cff5593b748ac5f59:/aim_snac.c diff --git a/aim_snac.c b/aim_snac.c index f2701ec..1d2c4fb 100644 --- a/aim_snac.c +++ b/aim_snac.c @@ -12,52 +12,60 @@ * */ -#include -#include +#include -struct aim_snac_t *aim_outstanding_snacs = NULL; -u_long aim_snac_nextid = 0x00000001; - -u_long aim_newsnac(struct aim_snac_t *newsnac) { - struct aim_snac_t *snac = NULL, *cur = aim_outstanding_snacs; +u_long aim_newsnac(struct aim_session_t *sess, + struct aim_snac_t *newsnac) +{ + struct aim_snac_t *snac = NULL, *cur = NULL; - assert(newsnac != NULL); - snac = calloc(1, sizeof(struct aim_snac_t)); - assert(snac != NULL); - memcpy(snac, newsnac, sizeof(struct aim_snac_t)); - snac->issuetime = time(&snac->issuetime); - snac->next = NULL; + if (!newsnac) + return 0; - if (cur == NULL) { - aim_outstanding_snacs = snac; - return(snac->id); - } - while (cur->next != NULL) - cur = cur->next; - cur->next = snac; - return(snac->id); -} + cur = sess->outstanding_snacs; -struct aim_snac_t *aim_remsnac(u_long id) { - struct aim_snac_t *cur = aim_outstanding_snacs; + snac = calloc(1, sizeof(struct aim_snac_t)); + if (!snac) + return 0; + memcpy(snac, newsnac, sizeof(struct aim_snac_t)); + snac->issuetime = time(&snac->issuetime); + snac->next = NULL; + + if (cur == NULL) { + sess->outstanding_snacs = snac; + return(snac->id); + } + while (cur->next != NULL) + cur = cur->next; + cur->next = snac; + return(snac->id); +} - if (cur == NULL) - return(NULL); - if (cur->id == id) { - aim_outstanding_snacs = cur->next; - return(cur); - } - while (cur->next != NULL) { - if (cur->next->id == id) { - struct aim_snac_t *tmp = NULL; +struct aim_snac_t *aim_remsnac(struct aim_session_t *sess, + u_long id) +{ + struct aim_snac_t *cur; + + if (cur == NULL) + return(NULL); - tmp = cur->next; - cur->next = cur->next->next; - return(tmp); - } - cur = cur->next; - } - return(NULL); + cur = sess->outstanding_snacs; + + if (cur->id == id) { + sess->outstanding_snacs = cur->next; + return(cur); + } + while (cur->next != NULL) { + if (cur->next->id == id) { + struct aim_snac_t *tmp = NULL; + + tmp = cur->next; + cur->next = cur->next->next; + return(tmp); + } + cur = cur->next; + } + return(NULL); } /* @@ -68,14 +76,17 @@ struct aim_snac_t *aim_remsnac(u_long id) { * why its called _max_age). * */ -int aim_cleansnacs(int maxage) +int aim_cleansnacs(struct aim_session_t *sess, + int maxage) { - struct aim_snac_t *cur = aim_outstanding_snacs; + struct aim_snac_t *cur; struct aim_snac_t *remed = NULL; time_t curtime; + + cur = sess->outstanding_snacs; curtime = time(&curtime); - + while (cur) { if ( (cur) && (((cur->issuetime) + maxage) < curtime)) @@ -83,7 +94,7 @@ int aim_cleansnacs(int maxage) #if DEBUG > 1 printf("aimsnac: WARNING purged obsolete snac %ul\n", cur->id); #endif - remed = aim_remsnac(cur->id); + remed = aim_remsnac(sess, cur->id); if (remed) { if (remed->data) @@ -93,7 +104,7 @@ int aim_cleansnacs(int maxage) } cur = cur->next; } - + return 0; }