comparison src/protocols/oscar/snac.c @ 13592:6519aeb66b31

[gaim-migrate @ 15978] Holy cow this is crazy. 34 files changed, 5760 insertions(+), 8517 deletions(-) * Non-blocking I/O for all of oscar. That includes normal FLAP connections as well as file transfers and direct IM. * Kick-ass file transfer and direct IM. Either party can request the connection. Gaim will try both the "public" IP and the "client" IP. It'll fall back to transferring through a proxy if that fails. Should be relatively few memleaks (I didn't have a lot of confidence in the non-memleakiness of the old code). And the code is reasonably generic, so it shouldn't be too much work to add voice chat. This might still be a LITTLE buggy, but it shouldn't be too bad. If anything, file transfer will be more buggy than direct IM. And sending a file will be more buggy than receiving a file. Bug reports with a series of steps to reproduce are welcome. * I merged OscarData and aim_session_t * Somewhere between 50 and 100 hours of work. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 07 Apr 2006 05:10:56 +0000
parents 87a7c3077c19
children
comparison
equal deleted inserted replaced
13591:dcfda39ad547 13592:6519aeb66b31
35 #include "oscar.h" 35 #include "oscar.h"
36 36
37 /* 37 /*
38 * Called from oscar_session_new() to initialize the hash. 38 * Called from oscar_session_new() to initialize the hash.
39 */ 39 */
40 faim_internal void aim_initsnachash(OscarSession *sess) 40 void aim_initsnachash(OscarData *od)
41 { 41 {
42 int i; 42 int i;
43 43
44 for (i = 0; i < FAIM_SNAC_HASH_SIZE; i++) 44 for (i = 0; i < FAIM_SNAC_HASH_SIZE; i++)
45 sess->snac_hash[i] = NULL; 45 od->snac_hash[i] = NULL;
46 46
47 return; 47 return;
48 } 48 }
49 49
50 faim_internal aim_snacid_t aim_cachesnac(OscarSession *sess, const guint16 family, const guint16 type, const guint16 flags, const void *data, const int datalen) 50 aim_snacid_t aim_cachesnac(OscarData *od, const guint16 family, const guint16 type, const guint16 flags, const void *data, const int datalen)
51 { 51 {
52 aim_snac_t snac; 52 aim_snac_t snac;
53 53
54 snac.id = sess->snacid_next++; 54 snac.id = od->snacid_next++;
55 snac.family = family; 55 snac.family = family;
56 snac.type = type; 56 snac.type = type;
57 snac.flags = flags; 57 snac.flags = flags;
58 58
59 if (datalen) { 59 if (datalen) {
61 return 0; /* er... */ 61 return 0; /* er... */
62 memcpy(snac.data, data, datalen); 62 memcpy(snac.data, data, datalen);
63 } else 63 } else
64 snac.data = NULL; 64 snac.data = NULL;
65 65
66 return aim_newsnac(sess, &snac); 66 return aim_newsnac(od, &snac);
67 } 67 }
68 68
69 /* 69 /*
70 * Clones the passed snac structure and caches it in the 70 * Clones the passed snac structure and caches it in the
71 * list/hash. 71 * list/hash.
72 */ 72 */
73 faim_internal aim_snacid_t aim_newsnac(OscarSession *sess, aim_snac_t *newsnac) 73 aim_snacid_t aim_newsnac(OscarData *od, aim_snac_t *newsnac)
74 { 74 {
75 aim_snac_t *snac; 75 aim_snac_t *snac;
76 int index; 76 int index;
77 77
78 if (!newsnac) 78 if (!newsnac)
83 memcpy(snac, newsnac, sizeof(aim_snac_t)); 83 memcpy(snac, newsnac, sizeof(aim_snac_t));
84 snac->issuetime = time(NULL); 84 snac->issuetime = time(NULL);
85 85
86 index = snac->id % FAIM_SNAC_HASH_SIZE; 86 index = snac->id % FAIM_SNAC_HASH_SIZE;
87 87
88 snac->next = (aim_snac_t *)sess->snac_hash[index]; 88 snac->next = (aim_snac_t *)od->snac_hash[index];
89 sess->snac_hash[index] = (void *)snac; 89 od->snac_hash[index] = (void *)snac;
90 90
91 return snac->id; 91 return snac->id;
92 } 92 }
93 93
94 /* 94 /*
95 * Finds a snac structure with the passed SNAC ID, 95 * Finds a snac structure with the passed SNAC ID,
96 * removes it from the list/hash, and returns a pointer to it. 96 * removes it from the list/hash, and returns a pointer to it.
97 * 97 *
98 * The returned structure must be freed by the caller. 98 * The returned structure must be freed by the caller.
99 * 99 *
100 */ 100 */
101 faim_internal aim_snac_t *aim_remsnac(OscarSession *sess, aim_snacid_t id) 101 aim_snac_t *aim_remsnac(OscarData *od, aim_snacid_t id)
102 { 102 {
103 aim_snac_t *cur, **prev; 103 aim_snac_t *cur, **prev;
104 int index; 104 int index;
105 105
106 index = id % FAIM_SNAC_HASH_SIZE; 106 index = id % FAIM_SNAC_HASH_SIZE;
107 107
108 for (prev = (aim_snac_t **)&sess->snac_hash[index]; (cur = *prev); ) { 108 for (prev = (aim_snac_t **)&od->snac_hash[index]; (cur = *prev); ) {
109 if (cur->id == id) { 109 if (cur->id == id) {
110 *prev = cur->next; 110 *prev = cur->next;
111 if (cur->flags & AIM_SNACFLAGS_DESTRUCTOR) { 111 if (cur->flags & AIM_SNACFLAGS_DESTRUCTOR) {
112 free(cur->data); 112 free(cur->data);
113 cur->data = NULL; 113 cur->data = NULL;
125 * a reply was never received for. Garbage collection. Plain and simple. 125 * a reply was never received for. Garbage collection. Plain and simple.
126 * 126 *
127 * maxage is the _minimum_ age in seconds to keep SNACs. 127 * maxage is the _minimum_ age in seconds to keep SNACs.
128 * 128 *
129 */ 129 */
130 faim_export void aim_cleansnacs(OscarSession *sess, int maxage) 130 void aim_cleansnacs(OscarData *od, int maxage)
131 { 131 {
132 int i; 132 int i;
133 133
134 for (i = 0; i < FAIM_SNAC_HASH_SIZE; i++) { 134 for (i = 0; i < FAIM_SNAC_HASH_SIZE; i++) {
135 aim_snac_t *cur, **prev; 135 aim_snac_t *cur, **prev;
136 time_t curtime; 136 time_t curtime;
137 137
138 if (!sess->snac_hash[i]) 138 if (!od->snac_hash[i])
139 continue; 139 continue;
140 140
141 curtime = time(NULL); /* done here in case we waited for the lock */ 141 curtime = time(NULL); /* done here in case we waited for the lock */
142 142
143 for (prev = (aim_snac_t **)&sess->snac_hash[i]; (cur = *prev); ) { 143 for (prev = (aim_snac_t **)&od->snac_hash[i]; (cur = *prev); ) {
144 if ((curtime - cur->issuetime) > maxage) { 144 if ((curtime - cur->issuetime) > maxage) {
145 145
146 *prev = cur->next; 146 *prev = cur->next;
147 147
148 free(cur->data); 148 free(cur->data);
153 } 153 }
154 154
155 return; 155 return;
156 } 156 }
157 157
158 faim_internal int aim_putsnac(ByteStream *bs, guint16 family, guint16 subtype, guint16 flags, aim_snacid_t snacid) 158 int aim_putsnac(ByteStream *bs, guint16 family, guint16 subtype, guint16 flags, aim_snacid_t snacid)
159 { 159 {
160 160
161 aimbs_put16(bs, family); 161 byte_stream_put16(bs, family);
162 aimbs_put16(bs, subtype); 162 byte_stream_put16(bs, subtype);
163 aimbs_put16(bs, flags); 163 byte_stream_put16(bs, flags);
164 aimbs_put32(bs, snacid); 164 byte_stream_put32(bs, snacid);
165 165
166 return 10; 166 return 10;
167 } 167 }