]> andersk Git - libfaim.git/blame - aim_snac.c
More printfs.
[libfaim.git] / aim_snac.c
CommitLineData
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 17u_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;
128a9903 41 printf("faim: snac: added %08lx\n", snac->id);
a25832e6 42 return(snac->id);
43}
9de3ca7e 44
a25832e6 45struct aim_snac_t *aim_remsnac(struct aim_session_t *sess,
46 u_long id)
47{
48 struct aim_snac_t *cur;
49
50 if (cur == NULL)
51 return(NULL);
9de3ca7e 52
128a9903 53 printf("faim: snac: searching for %08lx to remove\n", id);
54
a25832e6 55 cur = sess->outstanding_snacs;
56
57 if (cur->id == id) {
58 sess->outstanding_snacs = cur->next;
59 return(cur);
60 }
61 while (cur->next != NULL) {
62 if (cur->next->id == id) {
63 struct aim_snac_t *tmp = NULL;
64
65 tmp = cur->next;
66 cur->next = cur->next->next;
67 return(tmp);
68 }
69 cur = cur->next;
70 }
71 return(NULL);
9de3ca7e 72}
73
74/*
75 * This is for cleaning up old SNACs that either don't get replies or
76 * a reply was never received for. Garabage collection. Plain and simple.
77 *
78 * maxage is the _minimum_ age in seconds to keep SNACs (though I don't know
79 * why its called _max_age).
80 *
81 */
a25832e6 82int aim_cleansnacs(struct aim_session_t *sess,
83 int maxage)
9de3ca7e 84{
a25832e6 85 struct aim_snac_t *cur;
9de3ca7e 86 struct aim_snac_t *remed = NULL;
87 time_t curtime;
a25832e6 88
89 cur = sess->outstanding_snacs;
9de3ca7e 90
91 curtime = time(&curtime);
a25832e6 92
9de3ca7e 93 while (cur)
94 {
95 if ( (cur) && (((cur->issuetime) + maxage) < curtime))
96 {
128a9903 97#if 1/* DEBUG > 1*/
98 printf("aimsnac: WARNING purged obsolete snac %08lx\n", cur->id);
9de3ca7e 99#endif
a25832e6 100 remed = aim_remsnac(sess, cur->id);
9de3ca7e 101 if (remed)
102 {
103 if (remed->data)
104 free(remed->data);
105 free(remed);
106 }
107 }
108 cur = cur->next;
109 }
a25832e6 110
9de3ca7e 111 return 0;
112}
113
114int aim_putsnac(u_char *buf, int family, int subtype, int flags, u_long snacid)
115{
116 int curbyte = 0;
117 curbyte += aimutil_put16(buf+curbyte, (u_short)(family&0xffff));
118 curbyte += aimutil_put16(buf+curbyte, (u_short)(subtype&0xffff));
119 curbyte += aimutil_put16(buf+curbyte, (u_short)(flags&0xffff));
120 curbyte += aimutil_put32(buf+curbyte, snacid);
121 return curbyte;
122}
This page took 0.063279 seconds and 5 git commands to generate.