changeset 17311:3720176bdac6

Pass postprocessing parameters inside MsimMessage * instead of in a new struct. (UNTESTED)
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Wed, 06 Jun 2007 02:49:35 +0000
parents 05723949f75d
children 962edb051146
files libpurple/protocols/myspace/message.c libpurple/protocols/myspace/myspace.c
diffstat 2 files changed, 41 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/myspace/message.c	Tue Jun 05 05:06:04 2007 +0000
+++ b/libpurple/protocols/myspace/message.c	Wed Jun 06 02:49:35 2007 +0000
@@ -25,7 +25,7 @@
 static void msim_msg_free_element(gpointer data, gpointer user_data);
 static void msim_msg_debug_string_element(gpointer data, gpointer user_data);
 static gchar *msim_msg_pack_using(MsimMessage *msg, GFunc gf, gchar *sep, gchar *begin, gchar *end);
-static gchar *msim_msg_element_pack(MsimMessageElement *elem);
+static gchar *msim_msg_pack_element_data(MsimMessageElement *elem);
 static GList *msim_msg_get_node(MsimMessage *msg, gchar *name);
 static MsimMessage *msim_msg_new_v(va_list argp);
 
@@ -166,7 +166,7 @@
 {
 	MsimMessage *new;
 
-	if (!old)
+	if (old == NULL)
 		return NULL;
 
 	new = msim_msg_new(FALSE);
@@ -245,6 +245,8 @@
 	raw = msim_msg_pack(msg);
 	success = msim_send_raw(session, raw);
 	g_free(raw);
+
+	msim_msg_dump("msim_msg_send()ing %s\n", msg);
 	
 	return success;
 }
@@ -473,7 +475,7 @@
  * optimal for human consumption. For example, strings are escaped. Use 
  * msim_msg_get_string() if you want a string, which in some cases is same as this.
  */
-static gchar *msim_msg_element_pack(MsimMessageElement *elem)
+static gchar *msim_msg_pack_element_data(MsimMessageElement *elem)
 {
 	switch (elem->type)
 	{
@@ -482,7 +484,7 @@
 
 		case MSIM_TYPE_RAW:
 			/* Not un-escaped - this is a raw element, already escaped if necessary. */
-			return (gchar *)elem->data;
+			return g_strdup((gchar *)elem->data);
 
 		case MSIM_TYPE_STRING:
 			/* Strings get escaped. msim_escape() creates a new string. */
@@ -498,9 +500,8 @@
 			}
 
 		case MSIM_TYPE_BOOLEAN:
-			/* These strings are not actually used by the wire protocol
-			 * -- see msim_msg_pack_element. */
-			return g_strdup(GPOINTER_TO_UINT(elem->data) ? "True" : "False");
+			/* Not used by the wire protocol * -- see msim_msg_pack_element. */
+			return NULL;
 
 		case MSIM_TYPE_DICTIONARY:
 			/* TODO: pack using k=v\034k2=v2\034... */
@@ -535,7 +536,15 @@
 	elem = (MsimMessageElement *)data;
 	items = user_data;
 
-	data_string = msim_msg_element_pack(elem);
+	/* Exclude elements beginning with '_' from packed protocol messages. */
+	if (elem->name[0] == '_')
+	{
+		**items = g_strdup("");
+		++(*items);
+		return;
+	}
+
+	data_string = msim_msg_pack_element_data(elem);
 
 	switch (elem->type)
 	{
@@ -768,7 +777,7 @@
  *
  * @return gchar * The data as a string. Caller must g_free().
  *
- * Note that msim_msg_element_pack() is similar, but returns a string
+ * Note that msim_msg_pack_element_data() is similar, but returns a string
  * for inclusion into a raw protocol string (escaped and everything).
  * This function unescapes the string for you, if needed.
  */
--- a/libpurple/protocols/myspace/myspace.c	Tue Jun 05 05:06:04 2007 +0000
+++ b/libpurple/protocols/myspace/myspace.c	Wed Jun 06 02:49:35 2007 +0000
@@ -1120,23 +1120,17 @@
 	}
 }
 
-typedef struct _POSTPROCESS_INFO
-{
-	MsimMessage *msg;
-	gchar *username;
-	gchar *uid_field_name;
-	gchar *uid_before;
-} POSTPROCESS_INFO;
-
 /* Callback for msim_postprocess_outgoing() to add a uid field, after resolving username/email.  */
 void msim_postprocess_outgoing_cb(MsimSession *session, MsimMessage *userinfo, gpointer data)
 {
 	gchar *body_str;
 	GHashTable *body;
-	gchar *uid;
-	POSTPROCESS_INFO *pi;
+	gchar *uid, *uid_field_name, *uid_before;
+	MsimMessage *msg;
 
-	pi = (POSTPROCESS_INFO *)data;
+	msg = (MsimMessage *)data;
+
+	msim_msg_dump("msim_postprocess_outgoing_cb() got msg=%s\n", msg);
 
 	/* Obtain userid from userinfo message. */
 	body_str = msim_msg_get_string(userinfo, "body");
@@ -1148,22 +1142,25 @@
 	g_hash_table_destroy(body);
 
 	/* Insert into outgoing message. */
-	pi->msg = msim_msg_insert_before(pi->msg, pi->uid_before,
-			pi->uid_field_name, MSIM_TYPE_STRING, uid);
+	uid_field_name = msim_msg_get_string(msg, "_uid_field_name");
+	uid_before = msim_msg_get_string(msg, "_uid_before");
+
+	msg = msim_msg_insert_before(msg, uid_field_name, uid_before, MSIM_TYPE_STRING, uid);
+
+	g_free(uid_field_name);
+	g_free(uid_before);
 
 	/* Send */
-	g_return_if_fail(msim_msg_send(session, pi->msg));
-
-	g_free(pi);
+	g_return_if_fail(msim_msg_send(session, msg));
 }
 
 /** Postprocess and send a message.
  *
  * @param session
  * @param msg Message to postprocess.
- * @param username Username to resolve.
- * @param uid_field_name Name of new field to add, containing uid of username.
- * @param uid_before Name of existing field to insert username field before.
+ * @param username Username to resolve. Assumed to be a static string (will not be freed or copied).
+ * @param uid_field_name Name of new field to add, containing uid of username. Static string.
+ * @param uid_before Name of existing field to insert username field before. Static string.
  *
  * @return Postprocessed message.
  */
@@ -1172,14 +1169,13 @@
 {
     PurpleBuddy *buddy;
 	guint uid;
-	POSTPROCESS_INFO* pi;
 
-	pi = g_new0(POSTPROCESS_INFO, 1);
-
-	pi->msg = msim_msg_clone(msg);
-	pi->uid_before = uid_before;
-	pi->uid_field_name = uid_field_name;
-	pi->username = username;
+	/* Store information for msim_postprocess_outgoing_cb(). */
+	purple_debug_info("msim", "msim_postprocess_outgoing(u=%s,ufn=%s,ub=%s)\n",
+			username, uid_field_name, uid_before);
+	msg = msim_msg_append(msg, "_username", MSIM_TYPE_STRING, g_strdup(username));
+	msg = msim_msg_append(msg, "_uid_field_name", MSIM_TYPE_STRING, g_strdup(uid_field_name));
+	msg = msim_msg_append(msg, "_uid_before", MSIM_TYPE_STRING, g_strdup(uid_before));
 
 	/* First, try the most obvious. If numeric userid is given, use that directly. */
     if (msim_is_userid(username))
@@ -1199,7 +1195,7 @@
 		{
 			purple_debug_info("msim", ">>> msim_postprocess_outgoing: couldn't find username %s in blist\n",
 					username);
-			msim_lookup_user(session, username, msim_postprocess_outgoing_cb, pi);
+			msim_lookup_user(session, username, msim_postprocess_outgoing_cb, msim_msg_clone(msg));
 			return TRUE;		/* not sure of status yet - haven't sent! */
 		}
 	}