diff src/protocols/oscar/admin.c @ 3912:e73c48cf1645

[gaim-migrate @ 4071] Little touchups in the "admin" family. Not much has changed, but I moved some functions around because I'm weird. (This is the stuff in "protocol actions" for oscar accounts.) Some of the dialogs should look a little more, I dunno, uniform or something. Change password, format screenname, and change current registered screen name should give you some slightly userfriendly error messages now. Also "confirm account" will pop up that little message that says you should be expecting an email... I think that was one of those brain mistakes, where something was backwards, or something. Uh, so let me know if you see any problems with any of that. Why did I work on this instead of ssi? I don't know. This is funner, I guess. I'll get to ssi eventually... Meow. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 07 Nov 2002 02:25:12 +0000
parents 8e924e4aa256
children 07283934dedd
line wrap: on
line diff
--- a/src/protocols/oscar/admin.c	Thu Nov 07 01:39:24 2002 +0000
+++ b/src/protocols/oscar/admin.c	Thu Nov 07 02:25:12 2002 +0000
@@ -1,60 +1,209 @@
+/*
+ * Family 0x0007 - Account Administration.
+ *
+ * Used for stuff like changing the formating of your screen name, changing your 
+ * email address, requesting an account confirmation email, getting account info, 
+ * 
+ */
 
 #define FAIM_INTERNAL
 #include <aim.h>
 
-/* called for both reply and change-reply */
+/*
+ * Subtype 0x0002 - Request a bit of account info.
+ *
+ * Info should be one of the following:
+ * 0x0001 - Screen name formatting
+ * 0x0011 - Email address
+ * 0x0013 - Unknown
+ *
+ */ 
+faim_export int aim_admin_getinfo(aim_session_t *sess, aim_conn_t *conn, fu16_t info)
+{
+	aim_frame_t *tx;
+	aim_snacid_t snacid;
+
+	if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 14)))
+		return -ENOMEM;
+
+	snacid = aim_cachesnac(sess, 0x0007, 0x0002, 0x0000, NULL, 0);
+	aim_putsnac(&tx->data, 0x0007, 0x0002, 0x0000, snacid);
+
+	aimbs_put16(&tx->data, info);
+	aimbs_put16(&tx->data, 0x0000);
+
+	aim_tx_enqueue(sess, tx);
+
+	return 0;
+}
+
+/*
+ * Subtypes 0x0003 and 0x0005 - Parse account info.
+ *
+ * Called in reply to both an information request (subtype 0x0002) and 
+ * an information change (subtype 0x0004).
+ *
+ */
 static int infochange(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
 {
+	aim_rxcallback_t userfunc;
+	char *url=NULL, *sn=NULL, *email=NULL;
+	fu16_t perms, tlvcount, err=0;
 
-	/*
-	 * struct {
-	 *    unsigned short perms;
-	 *    unsigned short tlvcount;
-	 *    aim_tlv_t tlvs[tlvcount];
-	 *  } admin_info[n];
-	 */
-	while (aim_bstream_empty(bs)) {
-		fu16_t perms, tlvcount;
+	perms = aimbs_get16(bs);
+	tlvcount = aimbs_get16(bs);
+
+	while (tlvcount && aim_bstream_empty(bs)) {
+		fu16_t type, length;
+
+		type = aimbs_get16(bs);
+		length = aimbs_get16(bs);
 
-		perms = aimbs_get16(bs);
-		tlvcount = aimbs_get16(bs);
+		switch (type) {
+			case 0x0001: {
+				sn = aimbs_getstr(bs, length);
+			} break;
 
-		while (tlvcount && aim_bstream_empty(bs)) {
-			aim_rxcallback_t userfunc;
-			fu16_t type, len;
-			fu8_t *val;
-			int str = 0;
+			case 0x0004: {
+				url = aimbs_getstr(bs, length);
+			} break;
 
-			type = aimbs_get16(bs);
-			len = aimbs_get16(bs);
-
-			if ((type == 0x0011) || (type == 0x0004))
-				str = 1;
+			case 0x0008: {
+				err = aimbs_get16(bs);
+			} break;
 
-			if (str)
-				val = aimbs_getstr(bs, len);
-			else
-				val = aimbs_getraw(bs, len);
+			case 0x0011: {
+				if (length == 0) {
+					email = (char*)malloc(13*sizeof(char));
+					strcpy(email, "*suppressed*");
+				} else
+					email = aimbs_getstr(bs, length);
+			} break;
+		}
 
-			/* XXX fix so its only called once for the entire packet */
-			if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
-				userfunc(sess, rx, (snac->subtype == 0x0005) ? 1 : 0, perms, type, len, val, str);
+		tlvcount--;
+	}
 
-			free(val);
+	if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
+		userfunc(sess, rx, (snac->subtype == 0x0005) ? 1 : 0, perms, err, url, sn, email);
 
-			tlvcount--;
-		}
-	}
+	if (sn) free(sn);
+	if (url) free(url);
+	if (email) free(email);
 
 	return 1;
 }
 
+/*
+ * Subtype 0x0004 - Set screenname formatting.
+ *
+ */
+faim_export int aim_admin_setnick(aim_session_t *sess, aim_conn_t *conn, const char *newnick)
+{
+	aim_frame_t *tx;
+	aim_snacid_t snacid;
+	aim_tlvlist_t *tl = NULL;
+
+	if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(newnick))))
+		return -ENOMEM;
+
+	snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0);
+	aim_putsnac(&tx->data, 0x0007, 0x0004, 0x0000, snacid);
+
+	aim_addtlvtochain_raw(&tl, 0x0001, strlen(newnick), newnick);
+	
+	aim_writetlvchain(&tx->data, &tl);
+	aim_freetlvchain(&tl);
+	
+	aim_tx_enqueue(sess, tx);
+
+
+	return 0;
+}
+
+/*
+ * Subtype 0x0004 - Change password.
+ *
+ */
+faim_export int aim_admin_changepasswd(aim_session_t *sess, aim_conn_t *conn, const char *newpw, const char *curpw)
+{
+	aim_frame_t *tx;
+	aim_tlvlist_t *tl = NULL;
+	aim_snacid_t snacid;
+
+	if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4+strlen(curpw)+4+strlen(newpw))))
+		return -ENOMEM;
+
+	snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0);
+	aim_putsnac(&tx->data, 0x0007, 0x0004, 0x0000, snacid);
+
+	/* new password TLV t(0002) */
+	aim_addtlvtochain_raw(&tl, 0x0002, strlen(newpw), newpw);
+
+	/* current password TLV t(0012) */
+	aim_addtlvtochain_raw(&tl, 0x0012, strlen(curpw), curpw);
+
+	aim_writetlvchain(&tx->data, &tl);
+	aim_freetlvchain(&tl);
+
+	aim_tx_enqueue(sess, tx);
+
+	return 0;
+}
+
+/*
+ * Subtype 0x0004 - Change email address.
+ *
+ */
+faim_export int aim_admin_setemail(aim_session_t *sess, aim_conn_t *conn, const char *newemail)
+{
+	aim_frame_t *tx;
+	aim_snacid_t snacid;
+	aim_tlvlist_t *tl = NULL;
+
+	if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(newemail))))
+		return -ENOMEM;
+
+	snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0);
+	aim_putsnac(&tx->data, 0x0007, 0x0004, 0x0000, snacid);
+
+	aim_addtlvtochain_raw(&tl, 0x0011, strlen(newemail), newemail);
+	
+	aim_writetlvchain(&tx->data, &tl);
+	aim_freetlvchain(&tl);
+	
+	aim_tx_enqueue(sess, tx);
+
+	return 0;
+}
+
+/*
+ * Subtype 0x0006 - Request account confirmation.
+ *
+ * This will cause an email to be sent to the address associated with
+ * the account.  By following the instructions in the mail, you can
+ * get the TRIAL flag removed from your account.
+ *
+ */
+faim_export int aim_admin_reqconfirm(aim_session_t *sess, aim_conn_t *conn)
+{
+	return aim_genericreq_n(sess, conn, 0x0007, 0x0006);
+}
+
+/*
+ * Subtype 0x0007 - Account confirmation request acknowledgement.
+ *
+ */
 static int accountconfirm(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
 {
 	aim_rxcallback_t userfunc;
 	fu16_t status;
+	aim_tlvlist_t *tl;
 
 	status = aimbs_get16(bs);
+	/* This is 0x0013 if unable to confirm at this time */
+
+	tl = aim_readtlvchain(bs);
 
 	if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
 		return userfunc(sess, rx, status);
@@ -86,112 +235,3 @@
 
 	return 0;
 }
-
-faim_export int aim_admin_changepasswd(aim_session_t *sess, aim_conn_t *conn, const char *newpw, const char *curpw)
-{
-	aim_frame_t *tx;
-	aim_tlvlist_t *tl = NULL;
-	aim_snacid_t snacid;
-
-	if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+4+strlen(curpw)+4+strlen(newpw))))
-		return -ENOMEM;
-
-	snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0);
-	aim_putsnac(&tx->data, 0x0007, 0x0004, 0x0000, snacid);
-
-	/* new password TLV t(0002) */
-	aim_addtlvtochain_raw(&tl, 0x0002, strlen(newpw), newpw);
-
-	/* current password TLV t(0012) */
-	aim_addtlvtochain_raw(&tl, 0x0012, strlen(curpw), curpw);
-
-	aim_writetlvchain(&tx->data, &tl);
-	aim_freetlvchain(&tl);
-
-	aim_tx_enqueue(sess, tx);
-
-	return 0;
-}
-
-/*
- * Request account confirmation. 
- *
- * This will cause an email to be sent to the address associated with
- * the account.  By following the instructions in the mail, you can
- * get the TRIAL flag removed from your account.
- *
- */
-faim_export int aim_admin_reqconfirm(aim_session_t *sess, aim_conn_t *conn)
-{
-	return aim_genericreq_n(sess, conn, 0x0007, 0x0006);
-}
-
-/*
- * Request a bit of account info.
- *
- * The only known valid tag is 0x0011 (email address).
- *
- */ 
-faim_export int aim_admin_getinfo(aim_session_t *sess, aim_conn_t *conn, fu16_t info)
-{
-	aim_frame_t *tx;
-	aim_snacid_t snacid;
-
-	if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 14)))
-		return -ENOMEM;
-
-	snacid = aim_cachesnac(sess, 0x0002, 0x0002, 0x0000, NULL, 0);
-	aim_putsnac(&tx->data, 0x0007, 0x0002, 0x0000, snacid);
-
-	aimbs_put16(&tx->data, info);
-	aimbs_put16(&tx->data, 0x0000);
-
-	aim_tx_enqueue(sess, tx);
-
-	return 0;
-}
-
-faim_export int aim_admin_setemail(aim_session_t *sess, aim_conn_t *conn, const char *newemail)
-{
-	aim_frame_t *tx;
-	aim_snacid_t snacid;
-	aim_tlvlist_t *tl = NULL;
-
-	if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(newemail))))
-		return -ENOMEM;
-
-	snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0);
-	aim_putsnac(&tx->data, 0x0007, 0x0004, 0x0000, snacid);
-
-	aim_addtlvtochain_raw(&tl, 0x0011, strlen(newemail), newemail);
-	
-	aim_writetlvchain(&tx->data, &tl);
-	aim_freetlvchain(&tl);
-	
-	aim_tx_enqueue(sess, tx);
-
-	return 0;
-}
-
-faim_export int aim_admin_setnick(aim_session_t *sess, aim_conn_t *conn, const char *newnick)
-{
-	aim_frame_t *tx;
-	aim_snacid_t snacid;
-	aim_tlvlist_t *tl = NULL;
-
-	if (!(tx = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+2+strlen(newnick))))
-		return -ENOMEM;
-
-	snacid = aim_cachesnac(sess, 0x0007, 0x0004, 0x0000, NULL, 0);
-	aim_putsnac(&tx->data, 0x0007, 0x0004, 0x0000, snacid);
-
-	aim_addtlvtochain_raw(&tl, 0x0001, strlen(newnick), newnick);
-	
-	aim_writetlvchain(&tx->data, &tl);
-	aim_freetlvchain(&tl);
-	
-	aim_tx_enqueue(sess, tx);
-
-
-	return 0;
-}