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