comparison src/protocols/oscar/misc.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 10a2d4d5bcf2
children ad243bc63184
comparison
equal deleted inserted replaced
3951:32942c49dced 3952:07283934dedd
1
2 /* 1 /*
3 * aim_misc.c 2 * misc.c
4 * 3 *
5 * TODO: Seperate a lot of this into an aim_bos.c. 4 * Random stuff. Basically just a few functions for sending
6 * 5 * simple SNACs, and then the generic error handler.
7 * Other things...
8 *
9 * - Idle setting
10 *
11 * 6 *
12 */ 7 */
13 8
14 #define FAIM_INTERNAL 9 #define FAIM_INTERNAL
15 #include <aim.h> 10 #include <aim.h>
16
17 /*
18 * aim_bos_setbuddylist(buddylist)
19 *
20 * This just builds the "set buddy list" command then queues it.
21 *
22 * buddy_list = "Screen Name One&ScreenNameTwo&";
23 *
24 * TODO: Clean this up.
25 *
26 * XXX: I can't stress the TODO enough.
27 *
28 */
29 faim_export int aim_bos_setbuddylist(aim_session_t *sess, aim_conn_t *conn, const char *buddy_list)
30 {
31 aim_frame_t *fr;
32 aim_snacid_t snacid;
33 int len = 0;
34 char *localcpy = NULL;
35 char *tmpptr = NULL;
36
37 if (!buddy_list || !(localcpy = strdup(buddy_list)))
38 return -EINVAL;
39
40 for (tmpptr = strtok(localcpy, "&"); tmpptr; ) {
41 faimdprintf(sess, 2, "---adding: %s (%d)\n", tmpptr, strlen(tmpptr));
42 len += 1 + strlen(tmpptr);
43 tmpptr = strtok(NULL, "&");
44 }
45
46 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+len)))
47 return -ENOMEM;
48
49 snacid = aim_cachesnac(sess, 0x0003, 0x0004, 0x0000, NULL, 0);
50 aim_putsnac(&fr->data, 0x0003, 0x0004, 0x0000, snacid);
51
52 strncpy(localcpy, buddy_list, strlen(buddy_list) + 1);
53
54 for (tmpptr = strtok(localcpy, "&"); tmpptr; ) {
55
56 faimdprintf(sess, 2, "---adding: %s (%d)\n", tmpptr, strlen(tmpptr));
57
58 aimbs_put8(&fr->data, strlen(tmpptr));
59 aimbs_putraw(&fr->data, tmpptr, strlen(tmpptr));
60 tmpptr = strtok(NULL, "&");
61 }
62
63 aim_tx_enqueue(sess, fr);
64
65 free(localcpy);
66
67 return 0;
68 }
69
70 /*
71 * aim_bos_setprofile(profile)
72 *
73 * Gives BOS your profile.
74 *
75 */
76 faim_export int aim_bos_setprofile(aim_session_t *sess, aim_conn_t *conn, const char *profile, const char *awaymsg, fu32_t caps)
77 {
78 static const char defencoding[] = {"text/aolrtf; charset=\"us-ascii\""};
79 aim_frame_t *fr;
80 aim_tlvlist_t *tl = NULL;
81 aim_snacid_t snacid;
82
83 /* Build to packet first to get real length */
84 if (profile) {
85 aim_addtlvtochain_raw(&tl, 0x0001, strlen(defencoding), defencoding);
86 aim_addtlvtochain_raw(&tl, 0x0002, strlen(profile), profile);
87 }
88
89 /*
90 * So here's how this works:
91 * - You are away when you have a non-zero-length type 4 TLV stored.
92 * - You become unaway when you clear the TLV with a zero-length
93 * type 4 TLV.
94 * - If you do not send the type 4 TLV, your status does not change
95 * (that is, if you were away, you'll remain away).
96 */
97 if (awaymsg) {
98 if (strlen(awaymsg)) {
99 aim_addtlvtochain_raw(&tl, 0x0003, strlen(defencoding), defencoding);
100 aim_addtlvtochain_raw(&tl, 0x0004, strlen(awaymsg), awaymsg);
101 } else
102 aim_addtlvtochain_noval(&tl, 0x0004);
103 }
104
105 aim_addtlvtochain_caps(&tl, 0x0005, caps);
106
107 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + aim_sizetlvchain(&tl))))
108 return -ENOMEM;
109
110 snacid = aim_cachesnac(sess, 0x0002, 0x0004, 0x0000, NULL, 0);
111
112 aim_putsnac(&fr->data, 0x0002, 0x004, 0x0000, snacid);
113 aim_writetlvchain(&fr->data, &tl);
114 aim_freetlvchain(&tl);
115
116 aim_tx_enqueue(sess, fr);
117
118 return 0;
119 }
120
121 /*
122 * aim_bos_reqbuddyrights()
123 *
124 * Request Buddy List rights.
125 *
126 */
127 faim_export int aim_bos_reqbuddyrights(aim_session_t *sess, aim_conn_t *conn)
128 {
129 return aim_genericreq_n(sess, conn, 0x0003, 0x0002);
130 }
131
132 /*
133 * Send a warning to destsn.
134 *
135 * Flags:
136 * AIM_WARN_ANON Send as an anonymous (doesn't count as much)
137 *
138 * returns -1 on error (couldn't alloc packet), 0 on success.
139 *
140 */
141 faim_export int aim_send_warning(aim_session_t *sess, aim_conn_t *conn, const char *destsn, fu32_t flags)
142 {
143 aim_frame_t *fr;
144 aim_snacid_t snacid;
145 fu16_t outflags = 0x0000;
146
147 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, strlen(destsn)+13)))
148 return -ENOMEM;
149
150 snacid = aim_cachesnac(sess, 0x0004, 0x0008, 0x0000, destsn, strlen(destsn)+1);
151
152 aim_putsnac(&fr->data, 0x0004, 0x0008, 0x0000, snacid);
153
154 if (flags & AIM_WARN_ANON)
155 outflags |= 0x0001;
156
157 aimbs_put16(&fr->data, outflags);
158 aimbs_put8(&fr->data, strlen(destsn));
159 aimbs_putraw(&fr->data, destsn, strlen(destsn));
160
161 aim_tx_enqueue(sess, fr);
162
163 return 0;
164 }
165 11
166 /* 12 /*
167 * Generic routine for sending commands. 13 * Generic routine for sending commands.
168 * 14 *
169 * 15 *
247 93
248 return 0; 94 return 0;
249 } 95 }
250 96
251 /* 97 /*
252 * aim_bos_reqlocaterights()
253 *
254 * Request Location services rights.
255 *
256 */
257 faim_export int aim_bos_reqlocaterights(aim_session_t *sess, aim_conn_t *conn)
258 {
259 return aim_genericreq_n(sess, conn, 0x0002, 0x0002);
260 }
261
262 /*
263 * Set directory profile data (not the same as aim_bos_setprofile!)
264 *
265 * privacy: 1 to allow searching, 0 to disallow.
266 */
267 faim_export int aim_setdirectoryinfo(aim_session_t *sess, aim_conn_t *conn, const char *first, const char *middle, const char *last, const char *maiden, const char *nickname, const char *street, const char *city, const char *state, const char *zip, int country, fu16_t privacy)
268 {
269 aim_frame_t *fr;
270 aim_snacid_t snacid;
271 aim_tlvlist_t *tl = NULL;
272
273
274 aim_addtlvtochain16(&tl, 0x000a, privacy);
275
276 if (first)
277 aim_addtlvtochain_raw(&tl, 0x0001, strlen(first), first);
278 if (last)
279 aim_addtlvtochain_raw(&tl, 0x0002, strlen(last), last);
280 if (middle)
281 aim_addtlvtochain_raw(&tl, 0x0003, strlen(middle), middle);
282 if (maiden)
283 aim_addtlvtochain_raw(&tl, 0x0004, strlen(maiden), maiden);
284
285 if (state)
286 aim_addtlvtochain_raw(&tl, 0x0007, strlen(state), state);
287 if (city)
288 aim_addtlvtochain_raw(&tl, 0x0008, strlen(city), city);
289
290 if (nickname)
291 aim_addtlvtochain_raw(&tl, 0x000c, strlen(nickname), nickname);
292 if (zip)
293 aim_addtlvtochain_raw(&tl, 0x000d, strlen(zip), zip);
294
295 if (street)
296 aim_addtlvtochain_raw(&tl, 0x0021, strlen(street), street);
297
298 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_sizetlvchain(&tl))))
299 return -ENOMEM;
300
301 snacid = aim_cachesnac(sess, 0x0002, 0x0009, 0x0000, NULL, 0);
302
303 aim_putsnac(&fr->data, 0x0002, 0x0009, 0x0000, snacid);
304 aim_writetlvchain(&fr->data, &tl);
305 aim_freetlvchain(&tl);
306
307 aim_tx_enqueue(sess, fr);
308
309 return 0;
310 }
311
312 /* XXX pass these in better */
313 faim_export int aim_setuserinterests(aim_session_t *sess, aim_conn_t *conn, const char *interest1, const char *interest2, const char *interest3, const char *interest4, const char *interest5, fu16_t privacy)
314 {
315 aim_frame_t *fr;
316 aim_snacid_t snacid;
317 aim_tlvlist_t *tl = NULL;
318
319 /* ?? privacy ?? */
320 aim_addtlvtochain16(&tl, 0x000a, privacy);
321
322 if (interest1)
323 aim_addtlvtochain_raw(&tl, 0x0000b, strlen(interest1), interest1);
324 if (interest2)
325 aim_addtlvtochain_raw(&tl, 0x0000b, strlen(interest2), interest2);
326 if (interest3)
327 aim_addtlvtochain_raw(&tl, 0x0000b, strlen(interest3), interest3);
328 if (interest4)
329 aim_addtlvtochain_raw(&tl, 0x0000b, strlen(interest4), interest4);
330 if (interest5)
331 aim_addtlvtochain_raw(&tl, 0x0000b, strlen(interest5), interest5);
332
333 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_sizetlvchain(&tl))))
334 return -ENOMEM;
335
336 snacid = aim_cachesnac(sess, 0x0002, 0x000f, 0x0000, NULL, 0);
337
338 aim_putsnac(&fr->data, 0x0002, 0x000f, 0x0000, 0);
339 aim_writetlvchain(&fr->data, &tl);
340 aim_freetlvchain(&tl);
341
342 aim_tx_enqueue(sess, fr);
343
344 return 0;
345 }
346
347 /*
348 * Should be generic enough to handle the errors for all groups. 98 * Should be generic enough to handle the errors for all groups.
349 * 99 *
350 */ 100 */
351 static int generror(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) 101 static int generror(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
352 { 102 {
394 strncpy(mod->name, "misc", sizeof(mod->name)); 144 strncpy(mod->name, "misc", sizeof(mod->name));
395 mod->snachandler = snachandler; 145 mod->snachandler = snachandler;
396 146
397 return 0; 147 return 0;
398 } 148 }
399
400