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