]>
Commit | Line | Data |
---|---|---|
9de3ca7e | 1 | |
2 | /* | |
3 | * | |
4 | * Various SNAC-related dodads... | |
5 | * | |
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. | |
9 | * | |
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) | |
12 | * | |
13 | */ | |
14 | ||
a25832e6 | 15 | #include <faim/aim.h> |
9de3ca7e | 16 | |
a25832e6 | 17 | u_long aim_newsnac(struct aim_session_t *sess, |
18 | struct aim_snac_t *newsnac) | |
19 | { | |
20 | struct aim_snac_t *snac = NULL, *cur = NULL; | |
9de3ca7e | 21 | |
a25832e6 | 22 | if (!newsnac) |
23 | return 0; | |
9de3ca7e | 24 | |
a25832e6 | 25 | cur = sess->outstanding_snacs; |
9de3ca7e | 26 | |
a25832e6 | 27 | snac = calloc(1, sizeof(struct aim_snac_t)); |
28 | if (!snac) | |
29 | return 0; | |
30 | memcpy(snac, newsnac, sizeof(struct aim_snac_t)); | |
31 | snac->issuetime = time(&snac->issuetime); | |
32 | snac->next = NULL; | |
33 | ||
34 | if (cur == NULL) { | |
35 | sess->outstanding_snacs = snac; | |
36 | return(snac->id); | |
37 | } | |
38 | while (cur->next != NULL) | |
39 | cur = cur->next; | |
40 | cur->next = snac; | |
41 | return(snac->id); | |
42 | } | |
9de3ca7e | 43 | |
a25832e6 | 44 | struct aim_snac_t *aim_remsnac(struct aim_session_t *sess, |
45 | u_long id) | |
46 | { | |
47 | struct aim_snac_t *cur; | |
48 | ||
49 | if (cur == NULL) | |
50 | return(NULL); | |
9de3ca7e | 51 | |
a25832e6 | 52 | cur = sess->outstanding_snacs; |
53 | ||
54 | if (cur->id == id) { | |
55 | sess->outstanding_snacs = cur->next; | |
56 | return(cur); | |
57 | } | |
58 | while (cur->next != NULL) { | |
59 | if (cur->next->id == id) { | |
60 | struct aim_snac_t *tmp = NULL; | |
61 | ||
62 | tmp = cur->next; | |
63 | cur->next = cur->next->next; | |
64 | return(tmp); | |
65 | } | |
66 | cur = cur->next; | |
67 | } | |
68 | return(NULL); | |
9de3ca7e | 69 | } |
70 | ||
71 | /* | |
72 | * This is for cleaning up old SNACs that either don't get replies or | |
73 | * a reply was never received for. Garabage collection. Plain and simple. | |
74 | * | |
75 | * maxage is the _minimum_ age in seconds to keep SNACs (though I don't know | |
76 | * why its called _max_age). | |
77 | * | |
78 | */ | |
a25832e6 | 79 | int aim_cleansnacs(struct aim_session_t *sess, |
80 | int maxage) | |
9de3ca7e | 81 | { |
a25832e6 | 82 | struct aim_snac_t *cur; |
9de3ca7e | 83 | struct aim_snac_t *remed = NULL; |
84 | time_t curtime; | |
a25832e6 | 85 | |
86 | cur = sess->outstanding_snacs; | |
9de3ca7e | 87 | |
88 | curtime = time(&curtime); | |
a25832e6 | 89 | |
9de3ca7e | 90 | while (cur) |
91 | { | |
92 | if ( (cur) && (((cur->issuetime) + maxage) < curtime)) | |
93 | { | |
94 | #if DEBUG > 1 | |
95 | printf("aimsnac: WARNING purged obsolete snac %ul\n", cur->id); | |
96 | #endif | |
a25832e6 | 97 | remed = aim_remsnac(sess, cur->id); |
9de3ca7e | 98 | if (remed) |
99 | { | |
100 | if (remed->data) | |
101 | free(remed->data); | |
102 | free(remed); | |
103 | } | |
104 | } | |
105 | cur = cur->next; | |
106 | } | |
a25832e6 | 107 | |
9de3ca7e | 108 | return 0; |
109 | } | |
110 | ||
111 | int aim_putsnac(u_char *buf, int family, int subtype, int flags, u_long snacid) | |
112 | { | |
113 | int curbyte = 0; | |
114 | curbyte += aimutil_put16(buf+curbyte, (u_short)(family&0xffff)); | |
115 | curbyte += aimutil_put16(buf+curbyte, (u_short)(subtype&0xffff)); | |
116 | curbyte += aimutil_put16(buf+curbyte, (u_short)(flags&0xffff)); | |
117 | curbyte += aimutil_put32(buf+curbyte, snacid); | |
118 | return curbyte; | |
119 | } |