File:  [Coherent Logic Development] / ChivanetAimPidgin / oscarprpl / src / c / family_bart.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 0x0010 - Server stored buddy art
   23:  *
   24:  * Used for storing and retrieving your cute little buddy icon
   25:  * from the AIM servers.
   26:  *
   27:  */
   28: 
   29: #include "oscar.h"
   30: 
   31: /**
   32:  * Subtype 0x0002 - Upload your icon.
   33:  *
   34:  * @param od The oscar session.
   35:  * @param icon The raw data of the icon image file.
   36:  * @param iconlen Length of the raw data of the icon image file.
   37:  * @return Return 0 if no errors, otherwise return the error number.
   38:  */
   39: int
   40: aim_bart_upload(OscarData *od, const guint8 *icon, guint16 iconlen)
   41: {
   42: 	FlapConnection *conn;
   43: 	ByteStream bs;
   44: 	aim_snacid_t snacid;
   45: 
   46: 	if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_BART)) || !icon || !iconlen)
   47: 		return -EINVAL;
   48: 
   49: 	byte_stream_new(&bs, 2 + 2 + iconlen);
   50: 
   51: 	/* The reference number for the icon */
   52: 	byte_stream_put16(&bs, 1);
   53: 
   54: 	/* The icon */
   55: 	byte_stream_put16(&bs, iconlen);
   56: 	byte_stream_putraw(&bs, icon, iconlen);
   57: 
   58: 	snacid = aim_cachesnac(od, SNAC_FAMILY_BART, 0x0002, 0x0000, NULL, 0);
   59: 	flap_connection_send_snac(od, conn, SNAC_FAMILY_BART, 0x0002, snacid, &bs);
   60: 
   61: 	byte_stream_destroy(&bs);
   62: 
   63: 	return 0;
   64: }
   65: 
   66: /**
   67:  * Subtype 0x0003 - Acknowledgement for uploading a buddy icon.
   68:  *
   69:  * You get this honky after you upload a buddy icon.
   70:  */
   71: static int
   72: uploadack(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
   73: {
   74: 	int ret = 0;
   75: 	aim_rxcallback_t userfunc;
   76: 
   77: 	byte_stream_get16(bs);
   78: 	byte_stream_get16(bs);
   79: 	byte_stream_get8(bs);
   80: 
   81: 	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
   82: 		ret = userfunc(od, conn, frame);
   83: 
   84: 	return ret;
   85: }
   86: 
   87: /**
   88:  * Subtype 0x0004 - Request someone's icon.
   89:  *
   90:  * @param od The oscar session.
   91:  * @param bn The name of the buddy whose icon you are requesting.
   92:  * @param iconcsum The MD5 checksum of the icon you are requesting.
   93:  * @param iconcsumlen Length of the MD5 checksum given above.  Should be 10 bytes.
   94:  * @return Return 0 if no errors, otherwise return the error number.
   95:  */
   96: int
   97: aim_bart_request(OscarData *od, const char *bn, guint8 iconcsumtype, const guint8 *iconcsum, guint16 iconcsumlen)
   98: {
   99: 	FlapConnection *conn;
  100: 	ByteStream bs;
  101: 	aim_snacid_t snacid;
  102: 
  103: 	if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_BART)) || !bn || !strlen(bn) || !iconcsum || !iconcsumlen)
  104: 		return -EINVAL;
  105: 
  106: 	byte_stream_new(&bs, 1+strlen(bn) + 4 + 1+iconcsumlen);
  107: 
  108: 	/* Buddy name */
  109: 	byte_stream_put8(&bs, strlen(bn));
  110: 	byte_stream_putstr(&bs, bn);
  111: 
  112: 	/* Some numbers.  You like numbers, right? */
  113: 	byte_stream_put8(&bs, 0x01);
  114: 	byte_stream_put16(&bs, 0x0001);
  115: 	byte_stream_put8(&bs, iconcsumtype);
  116: 
  117: 	/* Icon string */
  118: 	byte_stream_put8(&bs, iconcsumlen);
  119: 	byte_stream_putraw(&bs, iconcsum, iconcsumlen);
  120: 
  121: 	snacid = aim_cachesnac(od, SNAC_FAMILY_BART, 0x0004, 0x0000, NULL, 0);
  122: 	flap_connection_send_snac(od, conn, SNAC_FAMILY_BART, 0x0004, snacid, &bs);
  123: 
  124: 	byte_stream_destroy(&bs);
  125: 
  126: 	return 0;
  127: }
  128: 
  129: /**
  130:  * Subtype 0x0005 - Receive a buddy icon.
  131:  *
  132:  * This is sent in response to a buddy icon request.
  133:  */
  134: static int
  135: parseicon(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
  136: {
  137: 	int ret = 0;
  138: 	aim_rxcallback_t userfunc;
  139: 	char *bn;
  140: 	guint16 iconlen;
  141: 	guint8 iconcsumtype, iconcsumlen, *iconcsum, *icon;
  142: 
  143: 	bn = byte_stream_getstr(bs, byte_stream_get8(bs));
  144: 	byte_stream_get16(bs); /* flags */
  145: 	iconcsumtype = byte_stream_get8(bs);
  146: 	iconcsumlen = byte_stream_get8(bs);
  147: 	iconcsum = byte_stream_getraw(bs, iconcsumlen);
  148: 	iconlen = byte_stream_get16(bs);
  149: 	icon = byte_stream_getraw(bs, iconlen);
  150: 
  151: 	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
  152: 		ret = userfunc(od, conn, frame, bn, iconcsumtype, iconcsum, iconcsumlen, icon, iconlen);
  153: 
  154: 	g_free(bn);
  155: 	g_free(iconcsum);
  156: 	g_free(icon);
  157: 
  158: 	return ret;
  159: }
  160: 
  161: static int
  162: snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
  163: {
  164: 	if (snac->subtype == 0x0003)
  165: 		return uploadack(od, conn, mod, frame, snac, bs);
  166: 	else if (snac->subtype == 0x0005)
  167: 		return parseicon(od, conn, mod, frame, snac, bs);
  168: 
  169: 	return 0;
  170: }
  171: 
  172: int
  173: bart_modfirst(OscarData *od, aim_module_t *mod)
  174: {
  175: 	mod->family = SNAC_FAMILY_BART;
  176: 	mod->version = 0x0001;
  177: 	mod->toolid = 0x0010;
  178: 	mod->toolversion = 0x0629;
  179: 	mod->flags = 0;
  180: 	strncpy(mod->name, "bart", sizeof(mod->name));
  181: 	mod->snachandler = snachandler;
  182: 
  183: 	return 0;
  184: }

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