Mercurial > pidgin.yaz
annotate libfaim/aim_snac.c @ 520:fd6a3294366f
[gaim-migrate @ 530]
Should fix problem with smileys causing resize to lose <BR>
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Mon, 24 Jul 2000 19:50:34 +0000 |
parents | 0f14e6d8a51b |
children | 58106806ac2b |
rev | line source |
---|---|
2 | 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 | |
283
0f14e6d8a51b
[gaim-migrate @ 293]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
237
diff
changeset
|
15 #include <faim/aim.h> |
2 | 16 |
237 | 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; | |
2 | 21 |
237 | 22 if (!newsnac) |
23 return 0; | |
24 | |
25 cur = sess->outstanding_snacs; | |
2 | 26 |
237 | 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 | |
42 return(snac->id); | |
2 | 43 } |
44 | |
237 | 45 struct aim_snac_t *aim_remsnac(struct aim_session_t *sess, |
46 u_long id) | |
47 { | |
48 struct aim_snac_t *cur; | |
49 | |
50 cur = sess->outstanding_snacs; | |
51 | |
52 if (cur == NULL) | |
53 return(NULL); | |
2 | 54 |
237 | 55 if (cur->id == id) { |
56 sess->outstanding_snacs = cur->next; | |
57 return(cur); | |
58 } | |
59 while (cur->next != NULL) { | |
60 if (cur->next->id == id) { | |
61 struct aim_snac_t *tmp = NULL; | |
62 | |
63 tmp = cur->next; | |
64 cur->next = cur->next->next; | |
65 return(tmp); | |
66 } | |
67 cur = cur->next; | |
68 } | |
69 return(NULL); | |
2 | 70 } |
71 | |
72 /* | |
73 * This is for cleaning up old SNACs that either don't get replies or | |
74 * a reply was never received for. Garabage collection. Plain and simple. | |
75 * | |
76 * maxage is the _minimum_ age in seconds to keep SNACs (though I don't know | |
77 * why its called _max_age). | |
78 * | |
79 */ | |
237 | 80 int aim_cleansnacs(struct aim_session_t *sess, |
81 int maxage) | |
2 | 82 { |
237 | 83 struct aim_snac_t *cur; |
2 | 84 struct aim_snac_t *remed = NULL; |
85 time_t curtime; | |
237 | 86 |
87 cur = sess->outstanding_snacs; | |
2 | 88 |
89 curtime = time(&curtime); | |
237 | 90 |
2 | 91 while (cur) |
92 { | |
93 if ( (cur) && (((cur->issuetime) + maxage) < curtime)) | |
94 { | |
95 #if DEBUG > 1 | |
237 | 96 printf("aimsnac: WARNING purged obsolete snac %08lx\n", cur->id); |
2 | 97 #endif |
237 | 98 remed = aim_remsnac(sess, cur->id); |
2 | 99 if (remed) |
100 { | |
101 if (remed->data) | |
102 free(remed->data); | |
103 free(remed); | |
104 } | |
105 } | |
106 cur = cur->next; | |
107 } | |
237 | 108 |
2 | 109 return 0; |
110 } | |
111 | |
112 int aim_putsnac(u_char *buf, int family, int subtype, int flags, u_long snacid) | |
113 { | |
114 int curbyte = 0; | |
237 | 115 curbyte += aimutil_put16(buf+curbyte, (u_short)(family&0xffff)); |
116 curbyte += aimutil_put16(buf+curbyte, (u_short)(subtype&0xffff)); | |
117 curbyte += aimutil_put16(buf+curbyte, (u_short)(flags&0xffff)); | |
118 curbyte += aimutil_put32(buf+curbyte, snacid); | |
2 | 119 return curbyte; |
120 } |