13234
|
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 0x000f - Newer Search Method
|
|
23 *
|
|
24 * Used for searching for other AIM users by email address, name,
|
|
25 * location, commmon interests, and a few other similar things.
|
|
26 *
|
|
27 */
|
|
28
|
|
29 #include "oscar.h"
|
|
30
|
|
31 /**
|
|
32 * Subtype 0x0002 - Submit a User Search Request
|
|
33 *
|
|
34 * Search for an AIM screen name based on their email address.
|
|
35 *
|
13592
|
36 * @param od The oscar session.
|
13234
|
37 * @param region Should be "us-ascii" unless you know what you're doing.
|
|
38 * @param email The email address you want to search for.
|
|
39 * @return Return 0 if no errors, otherwise return the error number.
|
|
40 */
|
13592
|
41 int aim_odir_email(OscarData *od, const char *region, const char *email)
|
13234
|
42 {
|
13592
|
43 FlapConnection *conn;
|
|
44 FlapFrame *frame;
|
13234
|
45 aim_snacid_t snacid;
|
|
46 aim_tlvlist_t *tl = NULL;
|
|
47
|
13592
|
48 if (!od || !(conn = flap_connection_findbygroup(od, 0x000f)) || !region || !email)
|
13234
|
49 return -EINVAL;
|
|
50
|
|
51 /* Create a TLV chain, write it to the outgoing frame, then free the chain */
|
|
52 aim_tlvlist_add_str(&tl, 0x001c, region);
|
|
53 aim_tlvlist_add_16(&tl, 0x000a, 0x0001); /* Type of search */
|
|
54 aim_tlvlist_add_str(&tl, 0x0005, email);
|
|
55
|
13592
|
56 frame = flap_frame_new(od, 0x02, 10+aim_tlvlist_size(&tl));
|
|
57 snacid = aim_cachesnac(od, 0x000f, 0x0002, 0x0000, NULL, 0);
|
|
58 aim_putsnac(&frame->data, 0x000f, 0x0002, 0x0000, snacid);
|
13234
|
59
|
13592
|
60 aim_tlvlist_write(&frame->data, &tl);
|
13234
|
61 aim_tlvlist_free(&tl);
|
|
62
|
13592
|
63 flap_connection_send(conn, frame);
|
13234
|
64
|
|
65 return 0;
|
|
66 }
|
|
67
|
|
68
|
|
69 /**
|
|
70 * Subtype 0x0002 - Submit a User Search Request
|
|
71 *
|
|
72 * Search for an AIM screen name based on various info
|
|
73 * about the person.
|
|
74 *
|
13592
|
75 * @param od The oscar session.
|
13234
|
76 * @param region Should be "us-ascii" unless you know what you're doing.
|
|
77 * @param first The first name of the person you want to search for.
|
|
78 * @param middle The middle name of the person you want to search for.
|
|
79 * @param last The last name of the person you want to search for.
|
|
80 * @param maiden The maiden name of the person you want to search for.
|
|
81 * @param nick The nick name of the person you want to search for.
|
|
82 * @param city The city where the person you want to search for resides.
|
|
83 * @param state The state where the person you want to search for resides.
|
|
84 * @param country The country where the person you want to search for resides.
|
|
85 * @param zip The zip code where the person you want to search for resides.
|
|
86 * @param address The street address where the person you want to seach for resides.
|
|
87 * @return Return 0 if no errors, otherwise return the error number.
|
|
88 */
|
13592
|
89 int aim_odir_name(OscarData *od, const char *region, const char *first, const char *middle, const char *last, const char *maiden, const char *nick, const char *city, const char *state, const char *country, const char *zip, const char *address)
|
13234
|
90 {
|
13592
|
91 FlapConnection *conn;
|
|
92 FlapFrame *frame;
|
13234
|
93 aim_snacid_t snacid;
|
|
94 aim_tlvlist_t *tl = NULL;
|
|
95
|
13592
|
96 if (!od || !(conn = flap_connection_findbygroup(od, 0x000f)) || !region)
|
13234
|
97 return -EINVAL;
|
|
98
|
|
99 /* Create a TLV chain, write it to the outgoing frame, then free the chain */
|
|
100 aim_tlvlist_add_str(&tl, 0x001c, region);
|
|
101 aim_tlvlist_add_16(&tl, 0x000a, 0x0000); /* Type of search */
|
|
102 if (first)
|
|
103 aim_tlvlist_add_str(&tl, 0x0001, first);
|
|
104 if (last)
|
|
105 aim_tlvlist_add_str(&tl, 0x0002, last);
|
|
106 if (middle)
|
|
107 aim_tlvlist_add_str(&tl, 0x0003, middle);
|
|
108 if (maiden)
|
|
109 aim_tlvlist_add_str(&tl, 0x0004, maiden);
|
|
110 if (country)
|
|
111 aim_tlvlist_add_str(&tl, 0x0006, country);
|
|
112 if (state)
|
|
113 aim_tlvlist_add_str(&tl, 0x0007, state);
|
|
114 if (city)
|
|
115 aim_tlvlist_add_str(&tl, 0x0008, city);
|
|
116 if (nick)
|
|
117 aim_tlvlist_add_str(&tl, 0x000c, nick);
|
|
118 if (zip)
|
|
119 aim_tlvlist_add_str(&tl, 0x000d, zip);
|
|
120 if (address)
|
|
121 aim_tlvlist_add_str(&tl, 0x0021, address);
|
|
122
|
13592
|
123 frame = flap_frame_new(od, 0x02, 10+aim_tlvlist_size(&tl));
|
|
124 snacid = aim_cachesnac(od, 0x000f, 0x0002, 0x0000, NULL, 0);
|
|
125 aim_putsnac(&frame->data, 0x000f, 0x0002, 0x0000, snacid);
|
13234
|
126
|
13592
|
127 aim_tlvlist_write(&frame->data, &tl);
|
13234
|
128 aim_tlvlist_free(&tl);
|
|
129
|
13592
|
130 flap_connection_send(conn, frame);
|
13234
|
131
|
|
132 return 0;
|
|
133 }
|
|
134
|
|
135
|
|
136 /**
|
|
137 * Subtype 0x0002 - Submit a User Search Request
|
|
138 *
|
13592
|
139 * @param od The oscar session.
|
13234
|
140 * @param interest1 An interest you want to search for.
|
|
141 * @return Return 0 if no errors, otherwise return the error number.
|
|
142 */
|
13592
|
143 int aim_odir_interest(OscarData *od, const char *region, const char *interest)
|
13234
|
144 {
|
13592
|
145 FlapConnection *conn;
|
|
146 FlapFrame *frame;
|
13234
|
147 aim_snacid_t snacid;
|
|
148 aim_tlvlist_t *tl = NULL;
|
|
149
|
13592
|
150 if (!od || !(conn = flap_connection_findbygroup(od, 0x000f)) || !region)
|
13234
|
151 return -EINVAL;
|
|
152
|
|
153 /* Create a TLV chain, write it to the outgoing frame, then free the chain */
|
|
154 aim_tlvlist_add_str(&tl, 0x001c, region);
|
|
155 aim_tlvlist_add_16(&tl, 0x000a, 0x0001); /* Type of search */
|
|
156 if (interest)
|
|
157 aim_tlvlist_add_str(&tl, 0x0001, interest);
|
|
158
|
13592
|
159 frame = flap_frame_new(od, 0x02, 10+aim_tlvlist_size(&tl));
|
|
160 snacid = aim_cachesnac(od, 0x000f, 0x0002, 0x0000, NULL, 0);
|
|
161 aim_putsnac(&frame->data, 0x000f, 0x0002, 0x0000, snacid);
|
13234
|
162
|
13592
|
163 aim_tlvlist_write(&frame->data, &tl);
|
13234
|
164 aim_tlvlist_free(&tl);
|
|
165
|
13592
|
166 flap_connection_send(conn, frame);
|
13234
|
167
|
|
168 return 0;
|
|
169 }
|
|
170
|
|
171
|
|
172 /**
|
|
173 * Subtype 0x0003 - Receive Reply From a User Search
|
|
174 *
|
|
175 */
|
13592
|
176 static int parseresults(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
177 {
|
|
178 int ret = 0;
|
|
179 aim_rxcallback_t userfunc;
|
|
180 guint16 tmp, numresults;
|
|
181 struct aim_odir *results = NULL;
|
|
182
|
13592
|
183 tmp = byte_stream_get16(bs); /* Unknown */
|
|
184 tmp = byte_stream_get16(bs); /* Unknown */
|
|
185 byte_stream_advance(bs, tmp);
|
13234
|
186
|
13592
|
187 numresults = byte_stream_get16(bs); /* Number of results to follow */
|
13234
|
188
|
|
189 /* Allocate a linked list, 1 node per result */
|
|
190 while (numresults) {
|
|
191 struct aim_odir *new;
|
13592
|
192 aim_tlvlist_t *tl = aim_tlvlist_readnum(bs, byte_stream_get16(bs));
|
13234
|
193 new = (struct aim_odir *)malloc(sizeof(struct aim_odir));
|
|
194 new->first = aim_tlv_getstr(tl, 0x0001, 1);
|
|
195 new->last = aim_tlv_getstr(tl, 0x0002, 1);
|
|
196 new->middle = aim_tlv_getstr(tl, 0x0003, 1);
|
|
197 new->maiden = aim_tlv_getstr(tl, 0x0004, 1);
|
|
198 new->email = aim_tlv_getstr(tl, 0x0005, 1);
|
|
199 new->country = aim_tlv_getstr(tl, 0x0006, 1);
|
|
200 new->state = aim_tlv_getstr(tl, 0x0007, 1);
|
|
201 new->city = aim_tlv_getstr(tl, 0x0008, 1);
|
|
202 new->sn = aim_tlv_getstr(tl, 0x0009, 1);
|
|
203 new->interest = aim_tlv_getstr(tl, 0x000b, 1);
|
|
204 new->nick = aim_tlv_getstr(tl, 0x000c, 1);
|
|
205 new->zip = aim_tlv_getstr(tl, 0x000d, 1);
|
|
206 new->region = aim_tlv_getstr(tl, 0x001c, 1);
|
|
207 new->address = aim_tlv_getstr(tl, 0x0021, 1);
|
|
208 new->next = results;
|
|
209 results = new;
|
|
210 numresults--;
|
|
211 }
|
|
212
|
13592
|
213 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
|
|
214 ret = userfunc(od, conn, frame, results);
|
13234
|
215
|
|
216 /* Now free everything from above */
|
|
217 while (results) {
|
|
218 struct aim_odir *del = results;
|
|
219 results = results->next;
|
|
220 free(del->first);
|
|
221 free(del->last);
|
|
222 free(del->middle);
|
|
223 free(del->maiden);
|
|
224 free(del->email);
|
|
225 free(del->country);
|
|
226 free(del->state);
|
|
227 free(del->city);
|
|
228 free(del->sn);
|
|
229 free(del->interest);
|
|
230 free(del->nick);
|
|
231 free(del->zip);
|
|
232 free(del->region);
|
|
233 free(del->address);
|
|
234 free(del);
|
|
235 }
|
|
236
|
|
237 return ret;
|
|
238 }
|
|
239
|
13592
|
240 static int
|
|
241 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
|
13234
|
242 {
|
|
243 if (snac->subtype == 0x0003)
|
13592
|
244 return parseresults(od, conn, mod, frame, snac, bs);
|
13234
|
245
|
|
246 return 0;
|
|
247 }
|
|
248
|
13592
|
249 int
|
|
250 odir_modfirst(OscarData *od, aim_module_t *mod)
|
13234
|
251 {
|
|
252 mod->family = 0x000f;
|
|
253 mod->version = 0x0001;
|
|
254 mod->toolid = 0x0010;
|
|
255 mod->toolversion = 0x0629;
|
|
256 mod->flags = 0;
|
|
257 strncpy(mod->name, "odir", sizeof(mod->name));
|
|
258 mod->snachandler = snachandler;
|
|
259
|
|
260 return 0;
|
|
261 }
|