changeset 15625:3548e64b0245

Combine two functions that did similar things. This is a little cleaner, but more importantly it's more extensible.
author Mark Doliner <mark@kingant.net>
date Mon, 12 Feb 2007 08:43:04 +0000
parents 71af5b6209d5
children fc586f7f23bd 2261750cf4e9
files libpurple/protocols/oscar/family_oservice.c libpurple/protocols/oscar/oscar.c libpurple/protocols/oscar/oscar.h
diffstat 3 files changed, 50 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/oscar/family_oservice.c	Sun Feb 11 21:58:50 2007 +0000
+++ b/libpurple/protocols/oscar/family_oservice.c	Mon Feb 12 08:43:04 2007 +0000
@@ -779,8 +779,8 @@
 	return 1;
 }
 
-/*
- * Subtype 0x001e - Set various account settings (mostly ICQ related).
+/**
+ * Subtype 0x001e - Extended Status/Extra Info.
  *
  * These settings are transient, not server-stored (i.e. they only
  * apply to this session, and must be re-set the next time you sign
@@ -791,36 +791,67 @@
  * if your status is visible on ICQ web sites, and you can set
  * your IP address info and what not.
  *
+ * You can also set your "available" message.  This is currently
+ * only supported by iChat, Gaim and other 3rd party clients.
+ *
  * These are the same TLVs seen in user info.  You can
  * also set 0x0008 and 0x000c.
- *
- * TODO: Combine this with the function below.
  */
 int
-aim_srv_setextstatus(OscarData *od, guint32 status)
+aim_srv_setextrainfo(OscarData *od,
+		gboolean seticqstatus, guint32 icqstatus,
+		gboolean setavailmsg, const char *availmsg)
 {
 	FlapConnection *conn;
 	FlapFrame *frame;
 	aim_snacid_t snacid;
 	aim_tlvlist_t *tl = NULL;
-	guint32 data;
 
 	if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_ICBM)))
 		return -EINVAL;
 
-	data = AIM_ICQ_STATE_HIDEIP | AIM_ICQ_STATE_DIRECTREQUIREAUTH | status;
+	if (seticqstatus)
+	{
+		aim_tlvlist_add_32(&tl, 0x0006, icqstatus |
+				AIM_ICQ_STATE_HIDEIP | AIM_ICQ_STATE_DIRECTREQUIREAUTH);
+	}
+
+#if 0
+	if (other_stuff_that_isnt_implemented)
+	{
+		aim_tlvlist_add_raw(&tl, 0x000c, 0x0025,
+				chunk_of_x25_bytes_with_ip_address_etc);
+		aim_tlvlist_add_raw(&tl, 0x0011, 0x0005, unknown 0x01 61 10 f6 41);
+		aim_tlvlist_add_16(&tl, 0x0012, unknown 0x00 00);
+	}
+#endif
 
-	frame = flap_frame_new(od, 0x02, 10 + 8);
+	if (setavailmsg)
+	{
+		int availmsglen;
+		ByteStream tmpbs;
+
+		availmsglen = (availmsg != NULL) ? strlen(availmsg) : 0;
+
+		byte_stream_new(&tmpbs, availmsglen + 8);
+		byte_stream_put16(&tmpbs, 0x0002);
+		byte_stream_put8(&tmpbs, 0x04);
+		byte_stream_put8(&tmpbs, availmsglen + 4);
+		byte_stream_put16(&tmpbs, availmsglen);
+		if (availmsglen > 0)
+			byte_stream_putstr(&tmpbs, availmsg);
+		byte_stream_put16(&tmpbs, 0x0000);
+
+		aim_tlvlist_add_raw(&tl, 0x001d,
+				byte_stream_curpos(&tmpbs), tmpbs.data);
+		g_free(tmpbs.data);
+	}
+
+	frame = flap_frame_new(od, 0x02, 10 + aim_tlvlist_size(&tl));
 
 	snacid = aim_cachesnac(od, 0x0001, 0x001e, 0x0000, NULL, 0);
 	aim_putsnac(&frame->data, 0x0001, 0x001e, 0x0000, snacid);
 
-	aim_tlvlist_add_32(&tl, 0x0006, data);
-#if 0
-	aim_tlvlist_add_raw(&tl, 0x000c, 0x0025, chunk_of_x25_bytes_with_ip_address_etc);
-	aim_tlvlist_add_raw(&tl, 0x0011, 0x0005, unknown 0x01 61 10 f6 41);
-	aim_tlvlist_add_16(&tl, 0x0012, unknown 0x00 00);
-#endif
 	aim_tlvlist_write(&frame->data, &tl);
 	aim_tlvlist_free(&tl);
 
@@ -829,54 +860,7 @@
 	return 0;
 }
 
-/*
- * Subtype 0x001e - Extended Status.
- *
- * Sets your "available" message.  This is currently only supported by iChat
- * and Gaim.
- *
- * These are the same TLVs seen in user info.  You can
- * also set 0x0008 and 0x000c.
- *
- * TODO: Combine this with the above function.
- */
-int
-aim_srv_setstatusmsg(OscarData *od, const char *msg)
-{
-	FlapConnection *conn;
-	FlapFrame *frame;
-	aim_snacid_t snacid;
-	int msglen;
-
-	if (!od || !(conn = flap_connection_findbygroup(od, 0x0004)))
-		return -EINVAL;
-
-	if (msg == NULL)
-		msglen = 0;
-	else
-		msglen = strlen(msg);
-
-	frame = flap_frame_new(od, 0x02, 10 + 4 + msglen + 8);
-
-	snacid = aim_cachesnac(od, 0x0001, 0x001e, 0x0000, NULL, 0);
-	aim_putsnac(&frame->data, 0x0001, 0x001e, 0x0000, snacid);
-
-	byte_stream_put16(&frame->data, 0x001d); /* userinfo TLV type */
-	byte_stream_put16(&frame->data, msglen + 8); /* total length of userinfo TLV data */
-	byte_stream_put16(&frame->data, 0x0002);
-	byte_stream_put8(&frame->data, 0x04);
-	byte_stream_put8(&frame->data, msglen+4);
-	byte_stream_put16(&frame->data, msglen);
-	if (msglen > 0)
-		byte_stream_putstr(&frame->data, msg);
-	byte_stream_put16(&frame->data, 0x0000);
-
-	flap_connection_send(conn, frame);
-
-	return 0;
-}
-
-/*
+/**
  * Starting this past week (26 Mar 2001, say), AOL has started sending
  * this nice little extra SNAC.  AFAIK, it has never been used until now.
  *
--- a/libpurple/protocols/oscar/oscar.c	Sun Feb 11 21:58:50 2007 +0000
+++ b/libpurple/protocols/oscar/oscar.c	Mon Feb 12 08:43:04 2007 +0000
@@ -3605,7 +3605,7 @@
 	else
 		message = NULL;
 	tmp = gaim_markup_strip_html(message);
-	aim_srv_setstatusmsg(od, tmp);
+	aim_srv_setextrainfo(od, FALSE, 0, TRUE, tmp);
 	g_free(tmp);
 
 	aim_srv_setidle(od, 0);
@@ -4411,7 +4411,7 @@
 	else if (!strcmp(status_id, OSCAR_STATUS_ID_CUSTOM))
 		data |= AIM_ICQ_STATE_OUT | AIM_ICQ_STATE_AWAY;
 
-	aim_srv_setextstatus(od, data);
+	aim_srv_setextrainfo(od, TRUE, data, FALSE, NULL);
 }
 
 static void
@@ -4492,7 +4492,7 @@
 			}
 		}
 
-		aim_srv_setstatusmsg(od, status_text);
+		aim_srv_setextrainfo(od, FALSE, 0, TRUE, status_text);
 		g_free(status_text);
 
 		/* This is needed for us to un-set any previous away message. */
--- a/libpurple/protocols/oscar/oscar.h	Sun Feb 11 21:58:50 2007 +0000
+++ b/libpurple/protocols/oscar/oscar.h	Mon Feb 12 08:43:04 2007 +0000
@@ -625,8 +625,7 @@
 /* 0x0014 */ void aim_srv_setprivacyflags(OscarData *od, FlapConnection *conn, guint32);
 /* 0x0016 */ void aim_srv_nop(OscarData *od, FlapConnection *conn);
 /* 0x0017 */ void aim_srv_setversions(OscarData *od, FlapConnection *conn);
-/* 0x001e */ int aim_srv_setstatusmsg(OscarData *od, const char *msg);
-/* 0x001e */ int aim_srv_setextstatus(OscarData *od, guint32 status);
+/* 0x001e */ int aim_srv_setextrainfo(OscarData *od, gboolean seticqstatus, guint32 icqstatus, gboolean setavailmsg, const char *availmsg);
 
 
 void aim_bos_reqrights(OscarData *od, FlapConnection *conn);