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 0x000a - User Search.
|
|
23 *
|
|
24 * TODO: Add aim_usersearch_name()
|
|
25 *
|
|
26 */
|
|
27
|
|
28 #include "oscar.h"
|
|
29
|
|
30 /*
|
|
31 * Subtype 0x0001
|
|
32 *
|
|
33 * XXX can this be integrated with the rest of the error handling?
|
|
34 */
|
|
35 static int error(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
36 {
|
|
37 int ret = 0;
|
|
38 aim_rxcallback_t userfunc;
|
|
39 aim_snac_t *snac2;
|
|
40
|
|
41 /* XXX the modules interface should have already retrieved this for us */
|
|
42 if (!(snac2 = aim_remsnac(sess, snac->id))) {
|
|
43 gaim_debug_misc("oscar", "search error: couldn't get a snac for 0x%08lx\n", snac->id);
|
|
44 return 0;
|
|
45 }
|
|
46
|
|
47 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
48 ret = userfunc(sess, rx, snac2->data /* address */);
|
|
49
|
|
50 /* XXX freesnac()? */
|
|
51 if (snac2)
|
|
52 free(snac2->data);
|
|
53 free(snac2);
|
|
54
|
|
55 return ret;
|
|
56 }
|
|
57
|
|
58 /*
|
|
59 * Subtype 0x0002
|
|
60 *
|
|
61 */
|
|
62 faim_export int aim_search_address(aim_session_t *sess, aim_conn_t *conn, const char *address)
|
|
63 {
|
|
64 aim_frame_t *fr;
|
|
65 aim_snacid_t snacid;
|
|
66
|
|
67 if (!sess || !conn || !address)
|
|
68 return -EINVAL;
|
|
69
|
|
70 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+strlen(address))))
|
|
71 return -ENOMEM;
|
|
72
|
|
73 snacid = aim_cachesnac(sess, 0x000a, 0x0002, 0x0000, strdup(address), strlen(address)+1);
|
|
74 aim_putsnac(&fr->data, 0x000a, 0x0002, 0x0000, snacid);
|
|
75
|
|
76 aimbs_putstr(&fr->data, address);
|
|
77
|
|
78 aim_tx_enqueue(sess, fr);
|
|
79
|
|
80 return 0;
|
|
81 }
|
|
82
|
|
83 /*
|
|
84 * Subtype 0x0003
|
|
85 *
|
|
86 */
|
|
87 static int reply(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
88 {
|
|
89 int j = 0, m, ret = 0;
|
|
90 aim_tlvlist_t *tlvlist;
|
|
91 char *cur = NULL, *buf = NULL;
|
|
92 aim_rxcallback_t userfunc;
|
|
93 aim_snac_t *snac2;
|
|
94 char *searchaddr = NULL;
|
|
95
|
|
96 if ((snac2 = aim_remsnac(sess, snac->id)))
|
|
97 searchaddr = (char *)snac2->data;
|
|
98
|
|
99 tlvlist = aim_tlvlist_read(bs);
|
|
100 m = aim_tlvlist_count(&tlvlist);
|
|
101
|
|
102 /* XXX uhm.
|
|
103 * This is the only place that uses something other than 1 for the 3rd
|
|
104 * parameter to aim_tlv_gettlv_whatever().
|
|
105 */
|
|
106 while ((cur = aim_tlv_getstr(tlvlist, 0x0001, j+1)) && j < m) {
|
|
107 buf = realloc(buf, (j+1) * (MAXSNLEN+1));
|
|
108
|
|
109 strncpy(&buf[j * (MAXSNLEN+1)], cur, MAXSNLEN);
|
|
110 free(cur);
|
|
111
|
|
112 j++;
|
|
113 }
|
|
114
|
|
115 aim_tlvlist_free(&tlvlist);
|
|
116
|
|
117 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
|
118 ret = userfunc(sess, rx, searchaddr, j, buf);
|
|
119
|
|
120 /* XXX freesnac()? */
|
|
121 if (snac2)
|
|
122 free(snac2->data);
|
|
123 free(snac2);
|
|
124
|
|
125 free(buf);
|
|
126
|
|
127 return ret;
|
|
128 }
|
|
129
|
|
130 static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
131 {
|
|
132
|
|
133 if (snac->subtype == 0x0001)
|
|
134 return error(sess, mod, rx, snac, bs);
|
|
135 else if (snac->subtype == 0x0003)
|
|
136 return reply(sess, mod, rx, snac, bs);
|
|
137
|
|
138 return 0;
|
|
139 }
|
|
140
|
|
141 faim_internal int search_modfirst(aim_session_t *sess, aim_module_t *mod)
|
|
142 {
|
|
143
|
|
144 mod->family = 0x000a;
|
|
145 mod->version = 0x0001;
|
|
146 mod->toolid = 0x0110;
|
|
147 mod->toolversion = 0x0629;
|
|
148 mod->flags = 0;
|
|
149 strncpy(mod->name, "userlookup", sizeof(mod->name));
|
|
150 mod->snachandler = snachandler;
|
|
151
|
|
152 return 0;
|
|
153 }
|