source: libfaim/odir.c @ 24a791f

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 24a791f was cf02dd6, checked in by James M. Kretchmar <kretch@mit.edu>, 20 years ago
*** empty log message ***
  • Property mode set to 100644
File size: 7.6 KB
Line 
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 */
22faim_export int aim_odir_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_tlvlist_add_raw(&tl, 0x001c, strlen(region), region);
34        aim_tlvlist_add_16(&tl, 0x000a, 0x0001); /* Type of search */
35        aim_tlvlist_add_raw(&tl, 0x0005, strlen(email), email);
36
37        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_tlvlist_size(&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_tlvlist_write(&fr->data, &tl);
43        aim_tlvlist_free(&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 */
71faim_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)
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_tlvlist_add_raw(&tl, 0x001c, strlen(region), region);
83        aim_tlvlist_add_16(&tl, 0x000a, 0x0000); /* Type of search */
84        if (first)
85                aim_tlvlist_add_raw(&tl, 0x0001, strlen(first), first);
86        if (last)
87                aim_tlvlist_add_raw(&tl, 0x0002, strlen(last), last);
88        if (middle)
89                aim_tlvlist_add_raw(&tl, 0x0003, strlen(middle), middle);
90        if (maiden)
91                aim_tlvlist_add_raw(&tl, 0x0004, strlen(maiden), maiden);
92        if (country)
93                aim_tlvlist_add_raw(&tl, 0x0006, strlen(country), country);
94        if (state)
95                aim_tlvlist_add_raw(&tl, 0x0007, strlen(state), state);
96        if (city)
97                aim_tlvlist_add_raw(&tl, 0x0008, strlen(city), city);
98        if (nick)
99                aim_tlvlist_add_raw(&tl, 0x000c, strlen(nick), nick);
100        if (zip)
101                aim_tlvlist_add_raw(&tl, 0x000d, strlen(zip), zip);
102        if (address)
103                aim_tlvlist_add_raw(&tl, 0x0021, strlen(address), address);
104
105        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_tlvlist_size(&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_tlvlist_write(&fr->data, &tl);
111        aim_tlvlist_free(&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 */
126faim_export int aim_odir_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_tlvlist_add_raw(&tl, 0x001c, strlen(region), region);
138        aim_tlvlist_add_16(&tl, 0x000a, 0x0001); /* Type of search */
139        if (interest)
140                aim_tlvlist_add_raw(&tl, 0x0001, strlen(interest), interest);
141
142        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+aim_tlvlist_size(&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_tlvlist_write(&fr->data, &tl);
148        aim_tlvlist_free(&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 */
160static int parseresults(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
161{
162        int ret = 0;
163        aim_rxcallback_t userfunc;
164        fu16_t tmp, numresults;
165        struct aim_odir *results = NULL;
166
167        tmp = aimbs_get16(bs); /* Unknown */
168        tmp = aimbs_get16(bs); /* Unknown */
169        aim_bstream_advance(bs, tmp);
170
171        numresults = aimbs_get16(bs); /* Number of results to follow */
172
173        /* Allocate a linked list, 1 node per result */
174        while (numresults) {
175                struct aim_odir *new;
176                aim_tlvlist_t *tl = aim_tlvlist_readnum(bs, aimbs_get16(bs));
177                new = (struct aim_odir *)malloc(sizeof(struct aim_odir));
178                new->first = aim_tlv_getstr(tl, 0x0001, 1);
179                new->last = aim_tlv_getstr(tl, 0x0002, 1);
180                new->middle = aim_tlv_getstr(tl, 0x0003, 1);
181                new->maiden = aim_tlv_getstr(tl, 0x0004, 1);
182                new->email = aim_tlv_getstr(tl, 0x0005, 1);
183                new->country = aim_tlv_getstr(tl, 0x0006, 1);
184                new->state = aim_tlv_getstr(tl, 0x0007, 1);
185                new->city = aim_tlv_getstr(tl, 0x0008, 1);
186                new->sn = aim_tlv_getstr(tl, 0x0009, 1);
187                new->interest = aim_tlv_getstr(tl, 0x000b, 1);
188                new->nick = aim_tlv_getstr(tl, 0x000c, 1);
189                new->zip = aim_tlv_getstr(tl, 0x000d, 1);
190                new->region = aim_tlv_getstr(tl, 0x001c, 1);
191                new->address = aim_tlv_getstr(tl, 0x0021, 1);
192                new->next = results;
193                results = new;
194                numresults--;
195        }
196
197        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
198                ret = userfunc(sess, rx, results);
199
200        /* Now free everything from above */
201        while (results) {
202                struct aim_odir *del = results;
203                results = results->next;
204                free(del->first);
205                free(del->last);
206                free(del->middle);
207                free(del->maiden);
208                free(del->email);
209                free(del->country);
210                free(del->state);
211                free(del->city);
212                free(del->sn);
213                free(del->interest);
214                free(del->nick);
215                free(del->zip);
216                free(del->region);
217                free(del->address);
218                free(del);
219        }
220
221        return ret;
222}
223
224static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
225{
226
227        if (snac->subtype == 0x0003)
228                return parseresults(sess, mod, rx, snac, bs);
229
230        return 0;
231}
232
233faim_internal int odir_modfirst(aim_session_t *sess, aim_module_t *mod)
234{
235
236        mod->family = 0x000f;
237        mod->version = 0x0001;
238        mod->toolid = 0x0010;
239        mod->toolversion = 0x0629;
240        mod->flags = 0;
241        strncpy(mod->name, "odir", sizeof(mod->name));
242        mod->snachandler = snachandler;
243
244        return 0;
245}
Note: See TracBrowser for help on using the repository browser.