4 * Various SNAC-related dodads...
6 * outstanding_snacs is a list of aim_snac_t structs. A SNAC should be added
7 * whenever a new SNAC is sent and it should remain in the list until the
8 * response for it has been receieved.
10 * First edition badly written by Adam Fritzler (afritz@delphid.ml.org)
11 * Current edition nicely rewritten (it even works) by n (n@ml.org)
18 struct aim_snac_t *aim_outstanding_snacs = NULL;
19 u_long aim_snac_nextid = 0x00000001;
21 u_long aim_newsnac(struct aim_snac_t *newsnac) {
22 struct aim_snac_t *snac = NULL, *cur = aim_outstanding_snacs;
24 assert(newsnac != NULL);
25 snac = calloc(1, sizeof(struct aim_snac_t));
27 memcpy(snac, newsnac, sizeof(struct aim_snac_t));
28 snac->issuetime = time(&snac->issuetime);
32 aim_outstanding_snacs = snac;
35 while (cur->next != NULL)
41 struct aim_snac_t *aim_remsnac(u_long id) {
42 struct aim_snac_t *cur = aim_outstanding_snacs;
47 aim_outstanding_snacs = cur->next;
50 while (cur->next != NULL) {
51 if (cur->next->id == id) {
52 struct aim_snac_t *tmp = NULL;
55 cur->next = cur->next->next;
64 * This is for cleaning up old SNACs that either don't get replies or
65 * a reply was never received for. Garabage collection. Plain and simple.
67 * maxage is the _minimum_ age in seconds to keep SNACs (though I don't know
68 * why its called _max_age).
71 int aim_cleansnacs(int maxage)
73 struct aim_snac_t *cur = aim_outstanding_snacs;
74 struct aim_snac_t *remed = NULL;
77 curtime = time(&curtime);
81 if ( (cur) && (((cur->issuetime) + maxage) < curtime))
84 printf("aimsnac: WARNING purged obsolete snac %ul\n", cur->id);
86 remed = aim_remsnac(cur->id);
100 int aim_putsnac(u_char *buf, int family, int subtype, int flags, u_long snacid)
103 curbyte += aimutil_put16(buf+curbyte, (u_short)(family&0xffff));
104 curbyte += aimutil_put16(buf+curbyte, (u_short)(subtype&0xffff));
105 curbyte += aimutil_put16(buf+curbyte, (u_short)(flags&0xffff));
106 curbyte += aimutil_put32(buf+curbyte, snacid);