File:  [Coherent Logic Development] / ChivanetAimPidgin / oscarprpl / src / c / family_admin.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 0x0007 - Account Administration.
   23:  *
   24:  * Used for stuff like changing the formating of your username, changing your
   25:  * email address, requesting an account confirmation email, getting account info,
   26:  */
   27: 
   28: #include "oscar.h"
   29: 
   30: /**
   31:  * Subtype 0x0002 - Request a bit of account info.
   32:  *
   33:  * Info should be one of the following:
   34:  * 0x0001 - Username formatting
   35:  * 0x0011 - Email address
   36:  * 0x0013 - Unknown
   37:  */
   38: void
   39: aim_admin_getinfo(OscarData *od, FlapConnection *conn, guint16 info)
   40: {
   41: 	ByteStream bs;
   42: 	aim_snacid_t snacid;
   43: 
   44: 	byte_stream_new(&bs, 4);
   45: 
   46: 	byte_stream_put16(&bs, info);
   47: 	byte_stream_put16(&bs, 0x0000);
   48: 
   49: 	snacid = aim_cachesnac(od, SNAC_FAMILY_ADMIN, 0x0002, 0x0000, NULL, 0);
   50: 	flap_connection_send_snac(od, conn, SNAC_FAMILY_ADMIN, 0x0002, snacid, &bs);
   51: 
   52: 	byte_stream_destroy(&bs);
   53: }
   54: 
   55: /**
   56:  * Subtypes 0x0003 and 0x0005 - Parse account info.
   57:  *
   58:  * Called in reply to both an information request (subtype 0x0002) and
   59:  * an information change (subtype 0x0004).
   60:  */
   61: static void
   62: infochange(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
   63: {
   64: 	aim_rxcallback_t userfunc;
   65: 	char *url=NULL, *sn=NULL, *email=NULL;
   66: 	guint16 perms, tlvcount, err=0;
   67: 
   68: 	perms = byte_stream_get16(bs);
   69: 	tlvcount = byte_stream_get16(bs);
   70: 
   71: 	while (tlvcount && byte_stream_bytes_left(bs)) {
   72: 		guint16 type, length;
   73: 
   74: 		type = byte_stream_get16(bs);
   75: 		length = byte_stream_get16(bs);
   76: 
   77: 		switch (type) {
   78: 			case 0x0001: {
   79: 				g_free(sn);
   80: 				sn = byte_stream_getstr(bs, length);
   81: 			} break;
   82: 
   83: 			case 0x0004: {
   84: 				g_free(url);
   85: 				url = byte_stream_getstr(bs, length);
   86: 			} break;
   87: 
   88: 			case 0x0008: {
   89: 				err = byte_stream_get16(bs);
   90: 			} break;
   91: 
   92: 			case 0x0011: {
   93: 				g_free(email);
   94: 				if (length == 0)
   95: 					email = g_strdup("*suppressed");
   96: 				else
   97: 					email = byte_stream_getstr(bs, length);
   98: 			} break;
   99: 		}
  100: 
  101: 		tlvcount--;
  102: 	}
  103: 
  104: 	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
  105: 		userfunc(od, conn, frame, (snac->subtype == 0x0005) ? 1 : 0, perms, err, url, sn, email);
  106: 
  107: 	g_free(sn);
  108: 	g_free(url);
  109: 	g_free(email);
  110: }
  111: 
  112: /**
  113:  * Subtype 0x0004 - Set the formatting of username (change spaces and capitalization).
  114:  */
  115: void
  116: aim_admin_setnick(OscarData *od, FlapConnection *conn, const char *newnick)
  117: {
  118: 	ByteStream bs;
  119: 	aim_snacid_t snacid;
  120: 	GSList *tlvlist = NULL;
  121: 
  122: 	byte_stream_new(&bs, 2+2+strlen(newnick));
  123: 
  124: 	aim_tlvlist_add_str(&tlvlist, 0x0001, newnick);
  125: 
  126: 	aim_tlvlist_write(&bs, &tlvlist);
  127: 	aim_tlvlist_free(tlvlist);
  128: 
  129: 	snacid = aim_cachesnac(od, SNAC_FAMILY_ADMIN, 0x0004, 0x0000, NULL, 0);
  130: 	flap_connection_send_snac(od, conn, SNAC_FAMILY_ADMIN, 0x0004, snacid, &bs);
  131: 
  132: 	byte_stream_destroy(&bs);
  133: }
  134: 
  135: /**
  136:  * Subtype 0x0004 - Change password.
  137:  */
  138: void
  139: aim_admin_changepasswd(OscarData *od, FlapConnection *conn, const char *newpw, const char *curpw)
  140: {
  141: 	ByteStream bs;
  142: 	GSList *tlvlist = NULL;
  143: 	aim_snacid_t snacid;
  144: 
  145: 	byte_stream_new(&bs, 4+strlen(curpw)+4+strlen(newpw));
  146: 
  147: 	/* new password TLV t(0002) */
  148: 	aim_tlvlist_add_str(&tlvlist, 0x0002, newpw);
  149: 
  150: 	/* current password TLV t(0012) */
  151: 	aim_tlvlist_add_str(&tlvlist, 0x0012, curpw);
  152: 
  153: 	aim_tlvlist_write(&bs, &tlvlist);
  154: 	aim_tlvlist_free(tlvlist);
  155: 
  156: 	snacid = aim_cachesnac(od, SNAC_FAMILY_ADMIN, 0x0004, 0x0000, NULL, 0);
  157: 	flap_connection_send_snac(od, conn, SNAC_FAMILY_ADMIN, 0x0004, snacid, &bs);
  158: 
  159: 	byte_stream_destroy(&bs);
  160: }
  161: 
  162: /**
  163:  * Subtype 0x0004 - Change email address.
  164:  */
  165: void
  166: aim_admin_setemail(OscarData *od, FlapConnection *conn, const char *newemail)
  167: {
  168: 	ByteStream bs;
  169: 	aim_snacid_t snacid;
  170: 	GSList *tlvlist = NULL;
  171: 
  172: 	byte_stream_new(&bs, 2+2+strlen(newemail));
  173: 
  174: 	aim_tlvlist_add_str(&tlvlist, 0x0011, newemail);
  175: 
  176: 	aim_tlvlist_write(&bs, &tlvlist);
  177: 	aim_tlvlist_free(tlvlist);
  178: 
  179: 	snacid = aim_cachesnac(od, SNAC_FAMILY_ADMIN, 0x0004, 0x0000, NULL, 0);
  180: 	flap_connection_send_snac(od, conn, SNAC_FAMILY_ADMIN, 0x0004, snacid, &bs);
  181: 
  182: 	byte_stream_destroy(&bs);
  183: }
  184: 
  185: /*
  186:  * Subtype 0x0006 - Request account confirmation.
  187:  *
  188:  * This will cause an email to be sent to the address associated with
  189:  * the account.  By following the instructions in the mail, you can
  190:  * get the TRIAL flag removed from your account.
  191:  *
  192:  */
  193: void
  194: aim_admin_reqconfirm(OscarData *od, FlapConnection *conn)
  195: {
  196: 	aim_genericreq_n(od, conn, SNAC_FAMILY_ADMIN, 0x0006);
  197: }
  198: 
  199: /**
  200:  * Subtype SNAC_FAMILY_ADMIN - Account confirmation request acknowledgement.
  201:  */
  202: static int
  203: accountconfirm(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
  204: {
  205: 	int ret = 0;
  206: 	aim_rxcallback_t userfunc;
  207: 	guint16 status;
  208: 	/* GSList *tlvlist; */
  209: 
  210: 	status = byte_stream_get16(bs);
  211: 	/* Status is 0x0013 if unable to confirm at this time */
  212: 
  213: 	/* tlvlist = aim_tlvlist_read(bs); */
  214: 
  215: 	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
  216: 		ret = userfunc(od, conn, frame, status);
  217: 
  218: 	/* aim_tlvlist_free(tlvlist); */
  219: 
  220: 	return ret;
  221: }
  222: 
  223: static int
  224: snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
  225: {
  226: 	if ((snac->subtype == 0x0003) || (snac->subtype == 0x0005)) {
  227: 		infochange(od, conn, mod, frame, snac, bs);
  228: 		return 1;
  229: 	} else if (snac->subtype == SNAC_FAMILY_ADMIN)
  230: 		return accountconfirm(od, conn, mod, frame, snac, bs);
  231: 
  232: 	return 0;
  233: }
  234: 
  235: int admin_modfirst(OscarData *od, aim_module_t *mod)
  236: {
  237: 	mod->family = SNAC_FAMILY_ADMIN;
  238: 	mod->version = 0x0001;
  239: 	mod->toolid = 0x0010;
  240: 	mod->toolversion = 0x0629;
  241: 	mod->flags = 0;
  242: 	strncpy(mod->name, "admin", sizeof(mod->name));
  243: 	mod->snachandler = snachandler;
  244: 
  245: 	return 0;
  246: }

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