comparison libpurple/protocols/oscar/family_buddy.c @ 15374:5fe8042783c1

Rename gtk/ and libgaim/ to pidgin/ and libpurple/
author Sean Egan <seanegan@gmail.com>
date Sat, 20 Jan 2007 02:32:10 +0000
parents
children 32c366eeeb99
comparison
equal deleted inserted replaced
15373:f79e0f4df793 15374:5fe8042783c1
1 /*
2 * Gaim's oscar protocol plugin
3 * This file is the legal property of its developers.
4 * Please see the AUTHORS file distributed alongside this file.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 /*
22 * Family 0x0003 (SNAC_FAMILY_BUDDY) - Old-style Buddylist Management (non-SSI).
23 *
24 */
25
26 #include "oscar.h"
27
28 #include <string.h>
29
30 /*
31 * Subtype 0x0002 - Request rights.
32 *
33 * Request Buddy List rights.
34 *
35 */
36 void
37 aim_buddylist_reqrights(OscarData *od, FlapConnection *conn)
38 {
39 aim_genericreq_n_snacid(od, conn, SNAC_FAMILY_BUDDY, SNAC_SUBTYPE_BUDDY_REQRIGHTS);
40 }
41
42 /*
43 * Subtype 0x0003 - Rights.
44 *
45 */
46 static int
47 rights(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
48 {
49 aim_rxcallback_t userfunc;
50 aim_tlvlist_t *tlvlist;
51 guint16 maxbuddies = 0, maxwatchers = 0;
52 int ret = 0;
53
54 /*
55 * TLVs follow
56 */
57 tlvlist = aim_tlvlist_read(bs);
58
59 /*
60 * TLV type 0x0001: Maximum number of buddies.
61 */
62 if (aim_tlv_gettlv(tlvlist, 0x0001, 1))
63 maxbuddies = aim_tlv_get16(tlvlist, 0x0001, 1);
64
65 /*
66 * TLV type 0x0002: Maximum number of watchers.
67 *
68 * Watchers are other users who have you on their buddy
69 * list. (This is called the "reverse list" by a certain
70 * other IM protocol.)
71 *
72 */
73 if (aim_tlv_gettlv(tlvlist, 0x0002, 1))
74 maxwatchers = aim_tlv_get16(tlvlist, 0x0002, 1);
75
76 /*
77 * TLV type 0x0003: Unknown.
78 *
79 * ICQ only?
80 */
81
82 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
83 ret = userfunc(od, conn, frame, maxbuddies, maxwatchers);
84
85 aim_tlvlist_free(&tlvlist);
86
87 return ret;
88 }
89
90 /*
91 * Subtype 0x0004 (SNAC_SUBTYPE_BUDDY_ADDBUDDY) - Add buddy to list.
92 *
93 * Adds a single buddy to your buddy list after login.
94 * XXX This should just be an extension of setbuddylist()
95 *
96 */
97 int
98 aim_buddylist_addbuddy(OscarData *od, FlapConnection *conn, const char *sn)
99 {
100 FlapFrame *frame;
101 aim_snacid_t snacid;
102
103 if (!sn || !strlen(sn))
104 return -EINVAL;
105
106 frame = flap_frame_new(od, 0x02, 10+1+strlen(sn));
107
108 snacid = aim_cachesnac(od, 0x0003, 0x0004, 0x0000, sn, strlen(sn)+1);
109 aim_putsnac(&frame->data, 0x0003, 0x0004, 0x0000, snacid);
110
111 byte_stream_put8(&frame->data, strlen(sn));
112 byte_stream_putstr(&frame->data, sn);
113
114 flap_connection_send(conn, frame);
115
116 return 0;
117 }
118
119 /*
120 * Subtype 0x0004 (SNAC_SUBTYPE_BUDDY_ADDBUDDY) - Add multiple buddies to your buddy list.
121 *
122 * This just builds the "set buddy list" command then queues it.
123 *
124 * buddy_list = "Screen Name One&ScreenNameTwo&";
125 *
126 * XXX Clean this up.
127 *
128 */
129 int
130 aim_buddylist_set(OscarData *od, FlapConnection *conn, const char *buddy_list)
131 {
132 FlapFrame *frame;
133 aim_snacid_t snacid;
134 int len = 0;
135 char *localcpy = NULL;
136 char *tmpptr = NULL;
137
138 if (!buddy_list || !(localcpy = strdup(buddy_list)))
139 return -EINVAL;
140
141 for (tmpptr = strtok(localcpy, "&"); tmpptr; ) {
142 gaim_debug_misc("oscar", "---adding: %s (%d)\n", tmpptr, strlen(tmpptr));
143 len += 1 + strlen(tmpptr);
144 tmpptr = strtok(NULL, "&");
145 }
146
147 frame = flap_frame_new(od, 0x02, 10+len);
148
149 snacid = aim_cachesnac(od, 0x0003, 0x0004, 0x0000, NULL, 0);
150 aim_putsnac(&frame->data, 0x0003, 0x0004, 0x0000, snacid);
151
152 strncpy(localcpy, buddy_list, strlen(buddy_list) + 1);
153
154 for (tmpptr = strtok(localcpy, "&"); tmpptr; ) {
155
156 gaim_debug_misc("oscar", "---adding: %s (%d)\n", tmpptr, strlen(tmpptr));
157
158 byte_stream_put8(&frame->data, strlen(tmpptr));
159 byte_stream_putstr(&frame->data, tmpptr);
160 tmpptr = strtok(NULL, "&");
161 }
162
163 flap_connection_send(conn, frame);
164
165 free(localcpy);
166
167 return 0;
168 }
169
170 /*
171 * Subtype 0x0005 (SNAC_SUBTYPE_BUDDY_REMBUDDY) - Remove buddy from list.
172 *
173 * XXX generalise to support removing multiple buddies (basically, its
174 * the same as setbuddylist() but with a different snac subtype).
175 *
176 */
177 int
178 aim_buddylist_removebuddy(OscarData *od, FlapConnection *conn, const char *sn)
179 {
180 FlapFrame *frame;
181 aim_snacid_t snacid;
182
183 if (!sn || !strlen(sn))
184 return -EINVAL;
185
186 frame = flap_frame_new(od, 0x02, 10+1+strlen(sn));
187
188 snacid = aim_cachesnac(od, 0x0003, 0x0005, 0x0000, sn, strlen(sn)+1);
189 aim_putsnac(&frame->data, 0x0003, 0x0005, 0x0000, snacid);
190
191 byte_stream_put8(&frame->data, strlen(sn));
192 byte_stream_putstr(&frame->data, sn);
193
194 flap_connection_send(conn, frame);
195
196 return 0;
197 }
198
199 /*
200 * Subtypes 0x000b (SNAC_SUBTYPE_BUDDY_ONCOMING) and 0x000c (SNAC_SUBTYPE_BUDDY_OFFGOING) - Change in buddy status
201 *
202 * Oncoming Buddy notifications contain a subset of the
203 * user information structure. It's close enough to run
204 * through aim_info_extract() however.
205 *
206 * Although the offgoing notification contains no information,
207 * it is still in a format parsable by aim_info_extract().
208 *
209 */
210 static int
211 buddychange(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
212 {
213 int ret = 0;
214 aim_userinfo_t userinfo;
215 aim_rxcallback_t userfunc;
216
217 aim_info_extract(od, bs, &userinfo);
218
219 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
220 ret = userfunc(od, conn, frame, &userinfo);
221
222 if (snac->subtype == SNAC_SUBTYPE_BUDDY_ONCOMING)
223 aim_locate_requestuserinfo(od, userinfo.sn);
224 aim_info_free(&userinfo);
225
226 return ret;
227 }
228
229 static int
230 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
231 {
232 if (snac->subtype == SNAC_SUBTYPE_BUDDY_RIGHTSINFO)
233 return rights(od, conn, mod, frame, snac, bs);
234 else if ((snac->subtype == SNAC_SUBTYPE_BUDDY_ONCOMING) || (snac->subtype == SNAC_SUBTYPE_BUDDY_OFFGOING))
235 return buddychange(od, conn, mod, frame, snac, bs);
236
237 return 0;
238 }
239
240 int
241 buddylist_modfirst(OscarData *od, aim_module_t *mod)
242 {
243 mod->family = 0x0003;
244 mod->version = 0x0001;
245 mod->toolid = 0x0110;
246 mod->toolversion = 0x0629;
247 mod->flags = 0;
248 strncpy(mod->name, "buddy", sizeof(mod->name));
249 mod->snachandler = snachandler;
250
251 return 0;
252 }