File:  [Coherent Logic Development] / ChivanetAimPidgin / oscarprpl / src / c / family_userlookup.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Mon Jan 27 19:48:25 2025 UTC (6 months ago) by snw
Branches: MAIN, CoherentLogicDevelopment
CVS tags: test-tag, start, HEAD
Pidgin AIM Plugin for ChivaNet

    1: /*
    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.
    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., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  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(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *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(od, snac->id))) {
   43: 		purple_debug_misc("oscar", "search error: couldn't get a snac for 0x%08x\n", snac->id);
   44: 		return 0;
   45: 	}
   46: 
   47: 	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
   48: 		ret = userfunc(od, conn, frame, snac2->data /* address */);
   49: 
   50: 	/* XXX freesnac()? */
   51: 	if (snac2)
   52: 		g_free(snac2->data);
   53: 	g_free(snac2);
   54: 
   55: 	return ret;
   56: }
   57: 
   58: /*
   59:  * Subtype 0x0002
   60:  *
   61:  */
   62: int aim_search_address(OscarData *od, const char *address)
   63: {
   64: 	FlapConnection *conn;
   65: 	ByteStream bs;
   66: 	aim_snacid_t snacid;
   67: 
   68: 	conn = flap_connection_findbygroup(od, SNAC_FAMILY_USERLOOKUP);
   69: 
   70: 	if (!conn || !address)
   71: 		return -EINVAL;
   72: 
   73: 	byte_stream_new(&bs, strlen(address));
   74: 
   75: 	byte_stream_putstr(&bs, address);
   76: 
   77: 	snacid = aim_cachesnac(od, SNAC_FAMILY_USERLOOKUP, 0x0002, 0x0000, address, strlen(address)+1);
   78: 	flap_connection_send_snac(od, conn, SNAC_FAMILY_USERLOOKUP, 0x0002, snacid, &bs);
   79: 
   80: 	byte_stream_destroy(&bs);
   81: 
   82: 	return 0;
   83: }
   84: 
   85: /*
   86:  * Subtype 0x0003
   87:  *
   88:  */
   89: static int reply(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
   90: {
   91: 	int j = 0, m, ret = 0;
   92: 	GSList *tlvlist;
   93: 	char *cur = NULL, *buf = NULL;
   94: 	aim_rxcallback_t userfunc;
   95: 	aim_snac_t *snac2;
   96: 	const char *searchaddr = NULL;
   97: 
   98: 	if ((snac2 = aim_remsnac(od, snac->id)))
   99: 		searchaddr = (const char *)snac2->data;
  100: 
  101: 	tlvlist = aim_tlvlist_read(bs);
  102: 	m = aim_tlvlist_count(tlvlist);
  103: 
  104: 	/* XXX uhm.
  105: 	 * This is the only place that uses something other than 1 for the 3rd
  106: 	 * parameter to aim_tlv_gettlv_whatever().
  107: 	 */
  108: 	while ((cur = aim_tlv_getstr(tlvlist, 0x0001, j+1)) && j < m)
  109: 	{
  110: 		buf = g_realloc(buf, (j+1) * (MAXSNLEN+1));
  111: 
  112: 		strncpy(&buf[j * (MAXSNLEN+1)], cur, MAXSNLEN);
  113: 		g_free(cur);
  114: 
  115: 		j++;
  116: 	}
  117: 	g_free(cur);
  118: 
  119: 	aim_tlvlist_free(tlvlist);
  120: 
  121: 	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
  122: 		ret = userfunc(od, conn, frame, searchaddr, j, buf);
  123: 
  124: 	/* XXX freesnac()? */
  125: 	if (snac2)
  126: 		g_free(snac2->data);
  127: 	g_free(snac2);
  128: 
  129: 	g_free(buf);
  130: 
  131: 	return ret;
  132: }
  133: 
  134: static int
  135: snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
  136: {
  137: 	if (snac->subtype == 0x0001)
  138: 		return error(od, conn, mod, frame, snac, bs);
  139: 	else if (snac->subtype == 0x0003)
  140: 		return reply(od, conn, mod, frame, snac, bs);
  141: 
  142: 	return 0;
  143: }
  144: 
  145: int
  146: search_modfirst(OscarData *od, aim_module_t *mod)
  147: {
  148: 	mod->family = SNAC_FAMILY_USERLOOKUP;
  149: 	mod->version = 0x0001;
  150: 	mod->toolid = 0x0110;
  151: 	mod->toolversion = 0x0629;
  152: 	mod->flags = 0;
  153: 	strncpy(mod->name, "userlookup", sizeof(mod->name));
  154: 	mod->snachandler = snachandler;
  155: 
  156: 	return 0;
  157: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>