changeset 18897:d0be4366e876

Change msim_msg_new() and msim_msg_new_v() to accept the first key name as the first argument, instead of a boolean value indicating that variadic arguments follow. So now, you don't need to pass TRUE as the first argument all the time. NULL can still be passed in the first argument (well, instead of FALSE) to create a new empty message.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sat, 11 Aug 2007 17:57:19 +0000
parents 945a77c7079c
children b94f831750e0
files libpurple/protocols/myspace/message.c libpurple/protocols/myspace/message.h libpurple/protocols/myspace/myspace.c
diffstat 3 files changed, 56 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/message.c	Sat Aug 11 06:22:21 2007 +0000
+++ b/libpurple/protocols/myspace/message.c	Sat Aug 11 17:57:19 2007 +0000
@@ -27,7 +27,7 @@
 static void msim_msg_debug_string_element(gpointer data, gpointer user_data);
 static gchar *msim_msg_pack_using(MsimMessage *msg, GFunc gf, const gchar *sep, const gchar *begin, const gchar *end);
 static GList *msim_msg_get_node(MsimMessage *msg, const gchar *name);
-static MsimMessage *msim_msg_new_v(va_list argp);
+static MsimMessage *msim_msg_new_v(gchar *first_key, va_list argp);
 
 /* Escape codes and associated replacement text, used for protocol message
  * escaping and unescaping. */
@@ -101,20 +101,19 @@
 
 /** Create a new MsimMessage. 
  * 
- * @param not_empty FALSE if message is empty, TRUE if variadic arguments follow.
+ * @param first_key The first key in the sequence, or NULL for an empty message.
  * @param ... A sequence of gchar* key/type/value triplets, terminated with NULL. 
  *
  * See msim_msg_append() documentation for details on types.
  */
 MsimMessage *
-msim_msg_new(gboolean not_empty, ...)
+msim_msg_new(gchar *first_key, ...)
 {
 	va_list argp;
 
-	va_start(argp, not_empty);
-
-	if (not_empty) {
-		return msim_msg_new_v(argp);
+	if (first_key) {
+        va_start(argp, first_key);
+		return msim_msg_new_v(first_key, argp);
 	} else {
 		return NULL;
 	}
@@ -122,32 +121,43 @@
 
 /** Create a new message from va_list and its first argument.
  *
+ * @param first_key The first argument (a key), or NULL to take all arguments
+ *    from argp.
  * @param argp A va_list of variadic arguments, already started with va_start(). Will be va_end()'d.
  * @return New MsimMessage *, must be freed with msim_msg_free().
  *
  * For internal use - users probably want msim_msg_new() or msim_send().
  */
 static MsimMessage *
-msim_msg_new_v(va_list argp)
+msim_msg_new_v(gchar *first_key, va_list argp)
 {
 	gchar *key, *value;
 	MsimMessageType type;
 	MsimMessage *msg;
+    gboolean first;
 
 	GString *gs;
 	GList *gl;
 	MsimMessage *dict;
 
-
 	/* Begin with an empty message. */
 	msg = NULL;
+    
+    /* First parameter can be given explicitly. */
+    first = first_key != NULL;
 
 	/* Read key, type, value triplets until NULL. */
 	do {
-		key = va_arg(argp, gchar *);
-		if (!key) {
-			break;
-		}
+        if (first)
+        {
+            key = first_key;
+            first = FALSE;
+        } else {
+            key = va_arg(argp, gchar *);
+            if (!key) {
+                break;
+            }
+        }
 
 		type = va_arg(argp, int);
 
@@ -440,7 +450,7 @@
 	va_list argp;
 	
 	va_start(argp, session);
-	msg = msim_msg_new_v(argp);
+	msg = msim_msg_new_v(NULL, argp);
 
 	/* Actually send the message. */
 	success = msim_msg_send(session, msg);
--- a/libpurple/protocols/myspace/message.h	Sat Aug 11 06:22:21 2007 +0000
+++ b/libpurple/protocols/myspace/message.h	Sat Aug 11 17:57:19 2007 +0000
@@ -47,7 +47,7 @@
 gchar *msim_escape(const gchar *msg);
 gchar *msim_unescape(const gchar *msg);
 
-MsimMessage *msim_msg_new(gboolean not_empty, ...);
+MsimMessage *msim_msg_new(gchar *first_key, ...);
 /* No sentinel attribute, because can leave off varargs if not_empty is FALSE. */
 
 MsimMessage *msim_msg_clone(MsimMessage *old);
--- a/libpurple/protocols/myspace/myspace.c	Sat Aug 11 06:22:21 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Sat Aug 11 17:57:19 2007 +0000
@@ -830,8 +830,8 @@
 	purple_debug_info("msim", "sending %d message from %s to %s: %s\n",
 				  type, from_username, who, text);
 
-	msg = msim_msg_new(TRUE,
-			"bm", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(type),
+	msg = msim_msg_new(
+            "bm", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(type),
 			"sesskey", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(session->sesskey),
 			/* 't' will be inserted here */
 			"cv", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(MSIM_CLIENT_VERSION),
@@ -1846,7 +1846,7 @@
 	 * by userid, the userinfo message will only contain the uid (not 
 	 * the username).
 	 */
-	user_msg = msim_msg_new(TRUE, 
+	user_msg = msim_msg_new(
 			"user", MSIM_TYPE_STRING, g_strdup(user),
 			NULL);
 	purple_debug_info("msim", "msim_get_info, setting up lookup, user=%s\n", user);
@@ -2366,7 +2366,7 @@
 		purple_debug_info("msim_we_are_logged_on", "TODO: pick username");
 	}
 
-	body = msim_msg_new(TRUE,
+	body = msim_msg_new(
 			"UserID", MSIM_TYPE_INTEGER, session->userid,
 			NULL);
 
@@ -2402,7 +2402,7 @@
 
 	/* TODO: setinfo */
 	/*
-	body = msim_msg_new(TRUE,
+	body = msim_msg_new(
 		"TotalFriends", MSIM_TYPE_INTEGER, 666,
 		NULL);
 	msim_send(session,
@@ -2825,7 +2825,7 @@
 	purple_debug_info("msim", "msim_add_buddy: want to add %s to %s\n", 
 			buddy->name, (group && group->name) ? group->name : "(no group)");
 
-	msg = msim_msg_new(TRUE,
+	msg = msim_msg_new(
 			"addbuddy", MSIM_TYPE_BOOLEAN, TRUE,
 			"sesskey", MSIM_TYPE_INTEGER, session->sesskey,
 			/* "newprofileid" will be inserted here with uid. */
@@ -2842,7 +2842,7 @@
 	/* TODO: if addbuddy fails ('error' message is returned), delete added buddy from
 	 * buddy list since Purple adds it locally. */
 
-	body = msim_msg_new(TRUE,
+	body = msim_msg_new(
 			"ContactID", MSIM_TYPE_STRING, g_strdup("<uid>"),
 			"GroupName", MSIM_TYPE_STRING, g_strdup(group->name),
 			"Position", MSIM_TYPE_INTEGER, 1000,
@@ -2854,7 +2854,7 @@
 	/* TODO: Update blocklist. */
 
 #if 0
-	msg_persist = msim_msg_new(TRUE,
+	msg_persist = msim_msg_new(
 		"persist", MSIM_TYPE_INTEGER, 1,
 		"sesskey", MSIM_TYPE_INTEGER, session->sesskey,
 		"cmd", MSIM_TYPE_INTEGER, MSIM_CMD_BIT_ACTION | MSIM_CMD_PUT,
@@ -3075,7 +3075,7 @@
 
 	session = (MsimSession *)gc->proto_data;
 
-	delbuddy_msg = msim_msg_new(TRUE,
+	delbuddy_msg = msim_msg_new(
 				"delbuddy", MSIM_TYPE_BOOLEAN, TRUE,
 				"sesskey", MSIM_TYPE_INTEGER, session->sesskey,
 				/* 'delprofileid' with uid will be inserted here. */
@@ -3088,7 +3088,7 @@
 	}
 	msim_msg_free(delbuddy_msg);
 
-	persist_msg = msim_msg_new(TRUE, 
+	persist_msg = msim_msg_new(
 			"persist", MSIM_TYPE_INTEGER, 1,
 			"sesskey", MSIM_TYPE_INTEGER, session->sesskey,
 			"cmd", MSIM_TYPE_INTEGER, MSIM_CMD_BIT_ACTION | MSIM_CMD_DELETE,
@@ -3114,7 +3114,7 @@
 	blocklist_updates = g_list_prepend(blocklist_updates, "<uid>");
 	blocklist_updates = g_list_reverse(blocklist_updates);
 
-	blocklist_msg = msim_msg_new(TRUE,
+	blocklist_msg = msim_msg_new(
 			"blocklist", MSIM_TYPE_BOOLEAN, TRUE,
 			"sesskey", MSIM_TYPE_INTEGER, session->sesskey,
 			/* TODO: MsimMessage lists. Currently <uid> isn't replaced in lists. */
@@ -3517,7 +3517,7 @@
 		lid = MG_MYSPACE_INFO_BY_STRING_LID;
 	}
 
-	body = msim_msg_new(TRUE,
+	body = msim_msg_new(
 			field_name, MSIM_TYPE_STRING, g_strdup(user),
 			NULL);
 
@@ -3829,7 +3829,7 @@
 	failures = 0;
 
 	purple_debug_info("msim", "\n\nTesting MsimMessage\n");
-	msg = msim_msg_new(FALSE);      /* Create a new, empty message. */
+	msg = msim_msg_new(NULL);      /* Create a new, empty message. */
 
 	/* Append some new elements. */
 	msg = msim_msg_append(msg, "bx", MSIM_TYPE_BINARY, g_string_new_len(g_strdup("XXX"), 3));
@@ -3874,7 +3874,7 @@
 	list = g_list_prepend(list, "item1");
 	list = g_list_prepend(list, "item0");
 
-	msg = msim_msg_new(FALSE);
+	msg = msim_msg_new(NULL);
 	msg = msim_msg_append(msg, "string", MSIM_TYPE_STRING, g_strdup("string value"));
 	msg = msim_msg_append(msg, "raw", MSIM_TYPE_RAW, g_strdup("raw value"));
 	msg = msim_msg_append(msg, "integer", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(3140));
@@ -3884,7 +3884,7 @@
 	msim_msg_dump("msg with list=%s\n", msg);
 	purple_debug_info("msim", "msg with list packed=%s\n", msim_msg_pack(msg));
 
-	msg2 = msim_msg_new(FALSE);
+	msg2 = msim_msg_new(NULL);
 	msg2 = msim_msg_append(msg2, "outer", MSIM_TYPE_STRING, g_strdup("outer value"));
 	msg2 = msim_msg_append(msg2, "body", MSIM_TYPE_DICTIONARY, msg);
 	msim_msg_dump("msg with dict=%s\n", msg2);      /* msg2 now 'owns' msg */
@@ -3962,6 +3962,22 @@
 	option = purple_account_option_int_new(_("Base font size (points)"), "base_font_size", MSIM_BASE_FONT_POINT_SIZE);
 	prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
 #endif
+
+	/* TODO: /zap command. Problem with this is that there are different kinds of zaps,
+	 * and the selection is best made available in a drop-down menu, instead of forcing
+	 * the user to type the kind of zap and memorizing available zaps (or putting it in the
+	 * help menu). A new "attention" API, for zap/buzz/nudge (different protocols) will
+	 * solve this. */
+#if 0
+	purple_cmd_register("zap",                                        /* cmd */
+			"w",                                              /* args - accept a single word */
+			PURPLE_CMD_P_PRPL,                                /* priority */
+			PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY,   /* flags */
+			"prpl-myspace",                                   /* prpl_id */
+			msim_cmd_zap,                                     /* func */
+			_("zap: zap a user to get their attention"),      /* helpstr */
+			NULL);                                            /* data */
+#endif
 }
 
 PURPLE_INIT_PLUGIN(myspace, init_plugin, info);