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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
2 /*
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
3 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
4 * Various SNAC-related dodads...
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
5 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
6 * outstanding_snacs is a list of aim_snac_t structs. A SNAC should be added
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 * whenever a new SNAC is sent and it should remain in the list until the
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
8 * response for it has been receieved.
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
9 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10 * First edition badly written by Adam Fritzler (afritz@delphid.ml.org)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
11 * Current edition nicely rewritten (it even works) by n (n@ml.org)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
12 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
13 */
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
14
283
0f14e6d8a51b [gaim-migrate @ 293]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 237
diff changeset
15 #include <faim/aim.h>
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
16
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
17 u_long aim_newsnac(struct aim_session_t *sess,
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
18 struct aim_snac_t *newsnac)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
19 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
20 struct aim_snac_t *snac = NULL, *cur = NULL;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
22 if (!newsnac)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
23 return 0;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
24
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
25 cur = sess->outstanding_snacs;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
26
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
27 snac = calloc(1, sizeof(struct aim_snac_t));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
28 if (!snac)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
29 return 0;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
30 memcpy(snac, newsnac, sizeof(struct aim_snac_t));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
31 snac->issuetime = time(&snac->issuetime);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
32 snac->next = NULL;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
33
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
34 if (cur == NULL) {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
35 sess->outstanding_snacs = snac;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
36 return(snac->id);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
37 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
38 while (cur->next != NULL)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
39 cur = cur->next;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
40 cur->next = snac;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
41
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
42 return(snac->id);
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
43 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
44
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
45 struct aim_snac_t *aim_remsnac(struct aim_session_t *sess,
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
46 u_long id)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
47 {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
48 struct aim_snac_t *cur;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
49
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
50 cur = sess->outstanding_snacs;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
51
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
52 if (cur == NULL)
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
53 return(NULL);
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
54
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
55 if (cur->id == id) {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
56 sess->outstanding_snacs = cur->next;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
57 return(cur);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
58 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
59 while (cur->next != NULL) {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
60 if (cur->next->id == id) {
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
61 struct aim_snac_t *tmp = NULL;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
62
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
63 tmp = cur->next;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
64 cur->next = cur->next->next;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
65 return(tmp);
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
66 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
67 cur = cur->next;
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
68 }
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
69 return(NULL);
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
70 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
71
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
72 /*
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
73 * This is for cleaning up old SNACs that either don't get replies or
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
74 * a reply was never received for. Garabage collection. Plain and simple.
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
75 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
76 * maxage is the _minimum_ age in seconds to keep SNACs (though I don't know
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
77 * why its called _max_age).
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
78 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
79 */
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
80 int aim_cleansnacs(struct aim_session_t *sess,
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
81 int maxage)
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
82 {
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
83 struct aim_snac_t *cur;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
84 struct aim_snac_t *remed = NULL;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
85 time_t curtime;
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
86
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
87 cur = sess->outstanding_snacs;
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
88
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
89 curtime = time(&curtime);
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
90
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
91 while (cur)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
92 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
93 if ( (cur) && (((cur->issuetime) + maxage) < curtime))
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
94 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
95 #if DEBUG > 1
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
96 printf("aimsnac: WARNING purged obsolete snac %08lx\n", cur->id);
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
97 #endif
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
98 remed = aim_remsnac(sess, cur->id);
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
99 if (remed)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
100 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
101 if (remed->data)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
102 free(remed->data);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
103 free(remed);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
104 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
105 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
106 cur = cur->next;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
107 }
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
108
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
109 return 0;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
110 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
111
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
112 int aim_putsnac(u_char *buf, int family, int subtype, int flags, u_long snacid)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
113 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
114 int curbyte = 0;
237
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
115 curbyte += aimutil_put16(buf+curbyte, (u_short)(family&0xffff));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
116 curbyte += aimutil_put16(buf+curbyte, (u_short)(subtype&0xffff));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
117 curbyte += aimutil_put16(buf+curbyte, (u_short)(flags&0xffff));
6ced2f1c8b24 [gaim-migrate @ 247]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2
diff changeset
118 curbyte += aimutil_put32(buf+curbyte, snacid);
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
119 return curbyte;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
120 }