Mercurial > pidgin.yaz
annotate src/protocols/oscar/buddylist.c @ 3952:07283934dedd
[gaim-migrate @ 4133]
Ok, big commit with little functionality change.
Most of it is me shuffling crap around because I'm one of them neat freaks. Lots of general code
cleanup too. I'm trying to move to that whole "one-family-per-file" thing.
The details...
I added libfaim support for aim's new search family, 0x000f. I only tested this briefly, so if
anyone uses it for anything, be aware that it could be buggy. I'll add oscar support sometime.
Advantages of this family are... when you search for someone, you get the directory info for that
person. So like, first name, middle name, last name, maiden name, city, state, country, zip,
address, interests, nickname, and maybe some other stuff. Basically all the info that they've set in
their directory info thing. Info. Oh, and I'm calling it "new search" because seach was already
taken, and cookie monster ate my right brain.
The reason I didn't add support to oscar.c... the new search family requires making a connection to
another server. While moving stuff around I realized that I didn't really like how new connections
are made. It's kind of sloppy. I'm thinking it would be nice to have an outgoing queue for each
type of connection, and then let the client queue messages as much as they want. Then, if libfaim
sees that there is a message for a certain type of connection, and there is no open connection of
that type, it will connect, and then flush the queue when the connection is made. This seems a lot
cleaner, but it also seems like a pain in the ass. I should do ssi for icq first, anyway :-)
Also, I think it would be neat if there was an ICBM file that handled channels 1 through 4. Then
im.c and chat.c could pass the ICBM part to the icbm stuff and it could get parsed there. im.c is
really huge right now.
I applied a patch from Graham Booker that paves the way for unicode in direct IMs. Thanks Graham.
Now we just need Paco-Paco to git a little free time and write a patch for this.
http://sourceforge.net/tracker/index.php?func=detail&aid=633589&group_id=235&atid=300235
I applied 2 patches from Will Mahan dealing with file transfer/oft/rendezous/whatever. Here's some
info on them, from The Man himself:
Patch 1
"Currently the Rendezvous code is rather messy; this
patch attempts to bring it up to speed with the rest of
the Oscar prpl. Its changes include:
* Rewrite several ft.c functions to use bstreams.
Apparently the code in question was written before
bstreams were implemented.
* Handle incoming Rendezvous packets through the
rxqueue like FLAP packets, rather than handling them as
a special case as soon as they are received. This
takes advantage of the bstream cleanup to unify some
code and simplify the aim_frame_t struct.
* Change some names used to try to clarify the
distinction between OFT, which refers specifically to
file transfer, and Rendezvous, which encompasses OFT as
well as other types of client-to-client connections."
Patch 2
"* Add some comments I inadvertently left out of my last patch.
* Fix a double-free that occurs when connections time out.
* Correct a bug causing filenames to be truncated by 4 characters on
some clients.
* Preserve directory structure when sending multiple files.
* Handle (throw away) resource forks sent by Mac clients."
I also changed all indents to tabs in ft.c.
And split all the bstream stuff from rxqueue.c and put it in bstream.c. It really is a separate
thing. Especially since it can be used for outgoing connections.
Also, I was going to look over the whole patch tonight to make sure it's all good, but it's like 6000
lines, so, uh, I'll do it later.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 13 Nov 2002 07:01:37 +0000 |
parents | 7ed9fa994055 |
children | 2532f1192da3 |
rev | line source |
---|---|
3952 | 1 /* |
2 * Family 0x0003 - Old-style Buddylist Management (non-SSI). | |
3 * | |
4 */ | |
2086 | 5 |
6 #define FAIM_INTERNAL | |
7 #include <aim.h> | |
8 | |
9 /* | |
3952 | 10 * Subtype 0x0002 - Request rights. |
2086 | 11 * |
3952 | 12 * Request Buddy List rights. |
2086 | 13 * |
14 */ | |
3952 | 15 faim_export int aim_bos_reqbuddyrights(aim_session_t *sess, aim_conn_t *conn) |
2086 | 16 { |
3952 | 17 return aim_genericreq_n(sess, conn, 0x0003, 0x0002); |
2086 | 18 } |
19 | |
3952 | 20 /* |
21 * Subtype 0x0003 - Rights. | |
22 * | |
23 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
24 static int rights(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
2086 | 25 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
26 aim_rxcallback_t userfunc; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
27 aim_tlvlist_t *tlvlist; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
28 fu16_t maxbuddies = 0, maxwatchers = 0; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
29 int ret = 0; |
2086 | 30 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
31 /* |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
32 * TLVs follow |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
33 */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
34 tlvlist = aim_readtlvchain(bs); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
35 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
36 /* |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
37 * TLV type 0x0001: Maximum number of buddies. |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
38 */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
39 if (aim_gettlv(tlvlist, 0x0001, 1)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
40 maxbuddies = aim_gettlv16(tlvlist, 0x0001, 1); |
2086 | 41 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
42 /* |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
43 * TLV type 0x0002: Maximum number of watchers. |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
44 * |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
45 * Watchers are other users who have you on their buddy |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
46 * list. (This is called the "reverse list" by a certain |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
47 * other IM protocol.) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
48 * |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
49 */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
50 if (aim_gettlv(tlvlist, 0x0002, 1)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
51 maxwatchers = aim_gettlv16(tlvlist, 0x0002, 1); |
2086 | 52 |
3213 | 53 /* |
54 * TLV type 0x0003: Unknown. | |
55 * | |
56 * ICQ only? | |
57 */ | |
58 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
59 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
60 ret = userfunc(sess, rx, maxbuddies, maxwatchers); |
2086 | 61 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
62 aim_freetlvchain(&tlvlist); |
2086 | 63 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
64 return ret; |
2086 | 65 } |
66 | |
67 /* | |
3952 | 68 * Subtype 0x0004 - Add buddy to list. |
2086 | 69 * |
70 * Adds a single buddy to your buddy list after login. | |
3952 | 71 * XXX This should just be an extension of setbuddylist() |
2086 | 72 * |
73 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
74 faim_export int aim_add_buddy(aim_session_t *sess, aim_conn_t *conn, const char *sn) |
2086 | 75 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
76 aim_frame_t *fr; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
77 aim_snacid_t snacid; |
2086 | 78 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
79 if (!sn || !strlen(sn)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
80 return -EINVAL; |
2086 | 81 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
82 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
83 return -ENOMEM; |
2086 | 84 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
85 snacid = aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, sn, strlen(sn)+1); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
86 aim_putsnac(&fr->data, 0x0003, 0x0004, 0x0000, snacid); |
2086 | 87 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
88 aimbs_put8(&fr->data, strlen(sn)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
89 aimbs_putraw(&fr->data, sn, strlen(sn)); |
2086 | 90 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
91 aim_tx_enqueue(sess, fr); |
2086 | 92 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
93 return 0; |
2086 | 94 } |
95 | |
96 /* | |
3952 | 97 * Subtype 0x0004 - Add multiple buddies to your buddy list. |
98 * | |
99 * This just builds the "set buddy list" command then queues it. | |
100 * | |
101 * buddy_list = "Screen Name One&ScreenNameTwo&"; | |
102 * | |
103 * XXX Clean this up. | |
104 * | |
105 */ | |
106 faim_export int aim_bos_setbuddylist(aim_session_t *sess, aim_conn_t *conn, const char *buddy_list) | |
107 { | |
108 aim_frame_t *fr; | |
109 aim_snacid_t snacid; | |
110 int len = 0; | |
111 char *localcpy = NULL; | |
112 char *tmpptr = NULL; | |
113 | |
114 if (!buddy_list || !(localcpy = strdup(buddy_list))) | |
115 return -EINVAL; | |
116 | |
117 for (tmpptr = strtok(localcpy, "&"); tmpptr; ) { | |
118 faimdprintf(sess, 2, "---adding: %s (%d)\n", tmpptr, strlen(tmpptr)); | |
119 len += 1 + strlen(tmpptr); | |
120 tmpptr = strtok(NULL, "&"); | |
121 } | |
122 | |
123 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+len))) | |
124 return -ENOMEM; | |
125 | |
126 snacid = aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, NULL, 0); | |
127 aim_putsnac(&fr->data, 0x0003, 0x0004, 0x0000, snacid); | |
128 | |
129 strncpy(localcpy, buddy_list, strlen(buddy_list) + 1); | |
130 | |
131 for (tmpptr = strtok(localcpy, "&"); tmpptr; ) { | |
132 | |
133 faimdprintf(sess, 2, "---adding: %s (%d)\n", tmpptr, strlen(tmpptr)); | |
134 | |
135 aimbs_put8(&fr->data, strlen(tmpptr)); | |
136 aimbs_putraw(&fr->data, tmpptr, strlen(tmpptr)); | |
137 tmpptr = strtok(NULL, "&"); | |
138 } | |
139 | |
140 aim_tx_enqueue(sess, fr); | |
141 | |
142 free(localcpy); | |
143 | |
144 return 0; | |
145 } | |
146 | |
147 /* | |
148 * Subtype 0x0005 - Remove buddy from list. | |
149 * | |
2086 | 150 * XXX generalise to support removing multiple buddies (basically, its |
151 * the same as setbuddylist() but with a different snac subtype). | |
152 * | |
153 */ | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
154 faim_export int aim_remove_buddy(aim_session_t *sess, aim_conn_t *conn, const char *sn) |
2086 | 155 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
156 aim_frame_t *fr; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
157 aim_snacid_t snacid; |
2086 | 158 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
159 if (!sn || !strlen(sn)) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
160 return -EINVAL; |
2086 | 161 |
2315
7ec21662ffc2
[gaim-migrate @ 2325]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2246
diff
changeset
|
162 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)))) |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
163 return -ENOMEM; |
2086 | 164 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
165 snacid = aim_cachesnac(sess, 0x0003, 0x0005, 0x0000, sn, strlen(sn)+1); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
166 aim_putsnac(&fr->data, 0x0003, 0x0005, 0x0000, snacid); |
2086 | 167 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
168 aimbs_put8(&fr->data, strlen(sn)); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
169 aimbs_putraw(&fr->data, sn, strlen(sn)); |
2086 | 170 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
171 aim_tx_enqueue(sess, fr); |
2086 | 172 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
173 return 0; |
2086 | 174 } |
175 | |
3952 | 176 /* |
177 * Subtype 0x000b | |
178 * | |
179 * XXX Why would we send this? | |
180 * | |
181 */ | |
182 faim_export int aim_sendbuddyoncoming(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *info) | |
183 { | |
184 aim_frame_t *fr; | |
185 aim_snacid_t snacid; | |
186 | |
187 if (!sess || !conn || !info) | |
188 return -EINVAL; | |
189 | |
190 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 1152))) | |
191 return -ENOMEM; | |
192 | |
193 snacid = aim_cachesnac(sess, 0x0003, 0x000b, 0x0000, NULL, 0); | |
194 | |
195 aim_putsnac(&fr->data, 0x0003, 0x000b, 0x0000, snacid); | |
196 aim_putuserinfo(&fr->data, info); | |
197 | |
198 aim_tx_enqueue(sess, fr); | |
199 | |
200 return 0; | |
201 } | |
202 | |
203 /* | |
204 * Subtype 0x000c | |
205 * | |
206 * XXX Why would we send this? | |
207 * | |
208 */ | |
209 faim_export int aim_sendbuddyoffgoing(aim_session_t *sess, aim_conn_t *conn, const char *sn) | |
210 { | |
211 aim_frame_t *fr; | |
212 aim_snacid_t snacid; | |
213 | |
214 if (!sess || !conn || !sn) | |
215 return -EINVAL; | |
216 | |
217 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+strlen(sn)))) | |
218 return -ENOMEM; | |
219 | |
220 snacid = aim_cachesnac(sess, 0x0003, 0x000c, 0x0000, NULL, 0); | |
221 | |
222 aim_putsnac(&fr->data, 0x0003, 0x000c, 0x0000, snacid); | |
223 aimbs_put8(&fr->data, strlen(sn)); | |
224 aimbs_putraw(&fr->data, sn, strlen(sn)); | |
225 | |
226 aim_tx_enqueue(sess, fr); | |
227 | |
228 return 0; | |
229 } | |
230 | |
231 /* | |
232 * Subtypes 0x000b and 0x000c - Change in buddy status | |
233 * | |
234 * Oncoming Buddy notifications contain a subset of the | |
235 * user information structure. Its close enough to run | |
236 * through aim_extractuserinfo() however. | |
237 * | |
238 * Although the offgoing notification contains no information, | |
239 * it is still in a format parsable by extractuserinfo. | |
240 * | |
241 */ | |
242 static int buddychange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
243 { | |
244 aim_userinfo_t userinfo; | |
245 aim_rxcallback_t userfunc; | |
246 | |
247 aim_extractuserinfo(sess, bs, &userinfo); | |
248 | |
249 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
250 return userfunc(sess, rx, &userinfo); | |
251 | |
252 return 0; | |
253 } | |
254 | |
255 static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) | |
256 { | |
257 | |
258 if (snac->subtype == 0x0003) | |
259 return rights(sess, mod, rx, snac, bs); | |
260 else if ((snac->subtype == 0x000b) || (snac->subtype == 0x000c)) | |
261 return buddychange(sess, mod, rx, snac, bs); | |
262 | |
263 return 0; | |
264 } | |
265 | |
266 faim_internal int buddylist_modfirst(aim_session_t *sess, aim_module_t *mod) | |
267 { | |
268 | |
269 mod->family = 0x0003; | |
270 mod->version = 0x0001; | |
271 mod->toolid = 0x0110; | |
272 mod->toolversion = 0x047b; | |
273 mod->flags = 0; | |
274 strncpy(mod->name, "buddylist", sizeof(mod->name)); | |
275 mod->snachandler = snachandler; | |
276 | |
277 return 0; | |
278 } |