2 * Purple's oscar protocol plugin
3 * This file is the legal property of its developers.
4 * Please see the AUTHORS file distributed alongside this file.
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 * Family 0x000a - User Search.
24 * TODO: Add aim_usersearch_name()
33 * XXX can this be integrated with the rest of the error handling?
35 static int error(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
38 aim_rxcallback_t userfunc
;
41 /* XXX the modules interface should have already retrieved this for us */
42 if (!(snac2
= aim_remsnac(od
, snac
->id
))) {
43 purple_debug_misc("oscar", "search error: couldn't get a snac for 0x%08x\n", snac
->id
);
47 if ((userfunc
= aim_callhandler(od
, snac
->family
, snac
->subtype
)))
48 ret
= userfunc(od
, conn
, frame
, snac2
->data
/* address */);
61 int aim_search_address(OscarData
*od
, const char *address
)
67 conn
= flap_connection_findbygroup(od
, SNAC_FAMILY_USERLOOKUP
);
69 if (!conn
|| !address
)
72 byte_stream_new(&bs
, strlen(address
));
74 byte_stream_putstr(&bs
, address
);
76 snacid
= aim_cachesnac(od
, SNAC_FAMILY_USERLOOKUP
, 0x0002, 0x0000, address
, strlen(address
)+1);
77 flap_connection_send_snac(od
, conn
, SNAC_FAMILY_USERLOOKUP
, 0x0002, snacid
, &bs
);
79 byte_stream_destroy(&bs
);
88 static int reply(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
90 int j
= 0, m
, ret
= 0;
92 char *cur
= NULL
, *buf
= NULL
;
93 aim_rxcallback_t userfunc
;
95 const char *searchaddr
= NULL
;
97 if ((snac2
= aim_remsnac(od
, snac
->id
)))
98 searchaddr
= (const char *)snac2
->data
;
100 tlvlist
= aim_tlvlist_read(bs
);
101 m
= aim_tlvlist_count(tlvlist
);
104 * This is the only place that uses something other than 1 for the 3rd
105 * parameter to aim_tlv_gettlv_whatever().
107 while ((cur
= aim_tlv_getstr(tlvlist
, 0x0001, j
+1)) && j
< m
)
109 buf
= g_realloc(buf
, (j
+1) * (MAXSNLEN
+1));
111 strncpy(&buf
[j
* (MAXSNLEN
+1)], cur
, MAXSNLEN
);
118 aim_tlvlist_free(tlvlist
);
120 if ((userfunc
= aim_callhandler(od
, snac
->family
, snac
->subtype
)))
121 ret
= userfunc(od
, conn
, frame
, searchaddr
, j
, buf
);
123 /* XXX freesnac()? */
134 snachandler(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
136 if (snac
->subtype
== 0x0001)
137 return error(od
, conn
, mod
, frame
, snac
, bs
);
138 else if (snac
->subtype
== 0x0003)
139 return reply(od
, conn
, mod
, frame
, snac
, bs
);
145 search_modfirst(OscarData
*od
, aim_module_t
*mod
)
147 mod
->family
= SNAC_FAMILY_USERLOOKUP
;
148 mod
->version
= 0x0001;
149 mod
->toolid
= 0x0110;
150 mod
->toolversion
= 0x0629;
152 strncpy(mod
->name
, "userlookup", sizeof(mod
->name
));
153 mod
->snachandler
= snachandler
;