# HG changeset patch
# Node ID 6599714282da
# Parent  2dbfbaeefe40
diff --git a/libpurple/protocols/zephyr/zephyr.c b/libpurple/protocols/zephyr/zephyr.c
--- a/libpurple/protocols/zephyr/zephyr.c
+++ b/libpurple/protocols/zephyr/zephyr.c
@@ -64,7 +64,7 @@
 
 typedef gssize (*PollableInputStreamReadFunc)(GPollableInputStream *stream, void *bufcur, GError **error);
 typedef gboolean (*ZephyrLoginFunc)(zephyr_account *zephyr);
-typedef Code_t (*ZephyrSubscribeToFunc)(zephyr_account *zephyr, char *class, char *instance, char *recipient);
+typedef Code_t (*ZephyrSubscribeToFunc)(zephyr_account *zephyr, ZSubscription_t *sub);
 
 typedef enum {
 	PURPLE_ZEPHYR_NONE, /* Non-kerberized ZEPH0.2 */
@@ -100,9 +100,7 @@
 #define MAXCHILDREN 20
 
 struct _zephyr_triple {
-	char *class;
-	char *instance;
-	char *recipient;
+	ZSubscription_t sub;
 	char *name;
 	gboolean open;
 	int id;
@@ -145,14 +143,14 @@
 }
 
 static Code_t
-subscribe_to_tzc(zephyr_account *zephyr, char *class, char *instance, char *recipient)
+subscribe_to_tzc(zephyr_account *zephyr, ZSubscription_t *sub)
 {
 	Code_t ret_val = -1;
 	gchar *zsubstr;
 
 	/* ((tzcfodder . subscribe) ("class" "instance" "recipient")) */
 	zsubstr = g_strdup_printf("((tzcfodder . subscribe) (\"%s\" \"%s\" \"%s\"))\n",
-	                          class, instance, recipient);
+	                          sub->zsub_class, sub->zsub_classinst, sub->zsub_recipient);
 	if (zephyr_write_message(zephyr, zsubstr)) {
 		ret_val = ZERR_NONE;
 	}
@@ -161,13 +159,9 @@
 }
 
 static Code_t
-subscribe_to_zeph02(G_GNUC_UNUSED zephyr_account *zephyr, char *class, char *instance, char *recipient)
+subscribe_to_zeph02(G_GNUC_UNUSED zephyr_account *zephyr, ZSubscription_t *sub)
 {
-	ZSubscription_t sub;
-	sub.zsub_class = class;
-	sub.zsub_classinst = instance;
-	sub.zsub_recipient = recipient;
-	return ZSubscribeTo(&sub, 1, 0);
+	return ZSubscribeTo(sub, 1, 0);
 }
 
 static char *
@@ -210,98 +204,93 @@
 }
 
 
-static zephyr_triple *new_triple(zephyr_account *zephyr,const char *c, const char *i, const char *r)
+static zephyr_triple *
+new_triple(zephyr_account *zephyr, const ZSubscription_t *sub)
 {
 	zephyr_triple *zt;
 
 	zt = g_new0(zephyr_triple, 1);
-	zt->class = g_strdup(c);
-	zt->instance = g_strdup(i);
-	zt->recipient = g_strdup(r);
-	zt->name = g_strdup_printf("%s,%s,%s", c, i?i:"", r?r:"");
+	zt->sub.zsub_class = g_strdup(sub->zsub_class);
+	zt->sub.zsub_classinst = g_strdup(sub->zsub_classinst);
+	zt->sub.zsub_recipient = g_strdup(sub->zsub_recipient);
+	zt->name = g_strdup_printf("%s,%s,%s", sub->zsub_class,
+	                           sub->zsub_classinst ? sub->zsub_classinst : "",
+	                           sub->zsub_recipient ? sub->zsub_recipient : "");
 	zt->id = ++(zephyr->last_id);
 	zt->open = FALSE;
 	return zt;
 }
 
-static void free_triple(zephyr_triple * zt)
+static void
+free_triple(zephyr_triple *zt)
 {
-	g_free(zt->class);
-	g_free(zt->instance);
-	g_free(zt->recipient);
+	g_free(zt->sub.zsub_class);
+	g_free(zt->sub.zsub_classinst);
+	g_free(zt->sub.zsub_recipient);
 	g_free(zt->name);
 	g_free(zt);
 }
 
-/* returns true if zt1 is a subset of zt2.  This function is used to
-   determine whether a zephyr sent to zt1 should be placed in the chat
-   with triple zt2
-
-   zt1 is a subset of zt2
+/* returns true if sub1 is a subset of sub2.  This function is used to
+   determine whether a zephyr sent to sub1 should be placed in the chat
+   with triple sub2
+
+   sub1 is a subset of sub2
    iff. the classnames are identical ignoring case
-   AND. the instance names are identical (ignoring case), or zt2->instance is *.
+   AND. the instance names are identical (ignoring case), or sub2->instance is *.
    AND. the recipient names are identical
 */
-
-static gboolean triple_subset(zephyr_triple * zt1, zephyr_triple * zt2)
+static gboolean
+subscription_subset(const ZSubscription_t *sub1, const ZSubscription_t *sub2)
 {
-
-	if (!zt2) {
-		purple_debug_error("zephyr","zt2 doesn't exist\n");
+	if (!sub1->zsub_class) {
+		purple_debug_error("zephyr", "sub1c doesn't exist\n");
 		return FALSE;
 	}
-	if (!zt1) {
-		purple_debug_error("zephyr","zt1 doesn't exist\n");
+	if (!sub1->zsub_classinst) {
+		purple_debug_error("zephyr", "sub1i doesn't exist\n");
 		return FALSE;
 	}
-	if (!(zt1->class)) {
-		purple_debug_error("zephyr","zt1c doesn't exist\n");
+	if (!sub1->zsub_recipient) {
+		purple_debug_error("zephyr", "sub1r doesn't exist\n");
 		return FALSE;
 	}
-	if (!(zt1->instance)) {
-		purple_debug_error("zephyr","zt1i doesn't exist\n");
-		return FALSE;
-	}
-	if (!(zt1->recipient)) {
-		purple_debug_error("zephyr","zt1r doesn't exist\n");
+	if (!sub2->zsub_class) {
+		purple_debug_error("zephyr", "sub2c doesn't exist\n");
 		return FALSE;
 	}
-	if (!(zt2->class)) {
-		purple_debug_error("zephyr","zt2c doesn't exist\n");
+	if (!sub2->zsub_classinst) {
+		purple_debug_error("zephyr", "sub2i doesn't exist\n");
 		return FALSE;
 	}
-	if (!(zt2->recipient)) {
-		purple_debug_error("zephyr","zt2r doesn't exist\n");
+	if (!sub2->zsub_recipient) {
+		purple_debug_error("zephyr", "sub2r doesn't exist\n");
 		return FALSE;
 	}
-	if (!(zt2->instance)) {
-		purple_debug_error("zephyr","zt2i doesn't exist\n");
+
+	if (g_ascii_strcasecmp(sub2->zsub_class, sub1->zsub_class)) {
 		return FALSE;
 	}
-
-	if (g_ascii_strcasecmp(zt2->class, zt1->class)) {
+	if (g_ascii_strcasecmp(sub2->zsub_classinst, sub1->zsub_classinst) && g_ascii_strcasecmp(sub2->zsub_classinst, "*")) {
 		return FALSE;
 	}
-	if (g_ascii_strcasecmp(zt2->instance, zt1->instance) && g_ascii_strcasecmp(zt2->instance, "*")) {
+	if (g_ascii_strcasecmp(sub2->zsub_recipient, sub1->zsub_recipient)) {
 		return FALSE;
 	}
-	if (g_ascii_strcasecmp(zt2->recipient, zt1->recipient)) {
-		return FALSE;
-	}
-	purple_debug_info("zephyr","<%s,%s,%s> is in <%s,%s,%s>\n",zt1->class,zt1->instance,zt1->recipient,zt2->class,zt2->instance,zt2->recipient);
+	purple_debug_info("zephyr", "<%s,%s,%s> is in <%s,%s,%s>\n",
+	                  sub1->zsub_class, sub1->zsub_classinst, sub1->zsub_recipient,
+	                  sub2->zsub_class, sub2->zsub_classinst, sub2->zsub_recipient);
 	return TRUE;
 }
 
-static zephyr_triple *find_sub_by_triple(zephyr_account *zephyr,zephyr_triple * zt)
+static zephyr_triple *
+find_sub_by_sub(const zephyr_account *zephyr, const ZSubscription_t *sub)
 {
-	zephyr_triple *curr_t;
-	GSList *curr = zephyr->subscrips;
-
-	while (curr) {
-		curr_t = curr->data;
-		if (triple_subset(zt, curr_t))
+	for (GSList *curr = zephyr->subscrips; curr; curr = curr->next) {
+		zephyr_triple *curr_t = curr->data;
+		if (subscription_subset(sub, &curr_t->sub)) {
 			return curr_t;
-		curr = curr->next;
+		}
 	}
 	return NULL;
 }
@@ -497,21 +486,25 @@
 				purple_serv_got_im(gc, stripped_sender, buf3, flags, time(NULL));
 
 		} else {
-			zephyr_triple *zt1, *zt2;
+			ZSubscription_t sub = {
+			        .zsub_class = notice.z_class,
+			        .zsub_classinst = notice.z_class_inst,
+			        .zsub_recipient = notice.z_recipient
+			};
+			zephyr_triple *zt;
 			gchar *send_inst_utf8;
 			zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
-			zt1 = new_triple(zephyr,notice.z_class, notice.z_class_inst, notice.z_recipient);
-			zt2 = find_sub_by_triple(zephyr,zt1);
-			if (!zt2) {
+			zt = find_sub_by_sub(zephyr, &sub);
+			if (!zt) {
 				/* This is a server supplied subscription */
-				zephyr->subscrips = g_slist_append(zephyr->subscrips, new_triple(zephyr,zt1->class,zt1->instance,zt1->recipient));
-				zt2 = find_sub_by_triple(zephyr,zt1);
+				zephyr->subscrips = g_slist_append(zephyr->subscrips, new_triple(zephyr, &sub));
+				zt = find_sub_by_sub(zephyr, &sub);
 			}
 
-			if (!zt2->open) {
-				zt2->open = TRUE;
-				purple_serv_got_joined_chat(gc, zt2->id, zt2->name);
-				zephyr_chat_set_topic(gc,zt2->id,notice.z_class_inst);
+			if (!zt->open) {
+				zt->open = TRUE;
+				purple_serv_got_joined_chat(gc, zt->id, zt->name);
+				zephyr_chat_set_topic(gc, zt->id, notice.z_class_inst);
 			}
 
 			if (!g_ascii_strcasecmp(notice.z_class_inst,"PERSONAL"))
@@ -526,8 +519,7 @@
 				}
 			}
 
-			gcc = purple_conversations_find_chat_with_account(
-														 zt2->name, purple_connection_get_account(gc));
+			gcc = purple_conversations_find_chat_with_account(zt->name, purple_connection_get_account(gc));
 			if (!purple_chat_conversation_has_user(gcc, stripped_sender)) {
 				GInetAddress *inet_addr = NULL;
 				gchar *ipaddr = NULL;
@@ -541,11 +533,9 @@
 				g_free(ipaddr);
 				g_object_unref(inet_addr);
 			}
-			purple_serv_got_chat_in(gc, zt2->id, send_inst_utf8,
+			purple_serv_got_chat_in(gc, zt->id, send_inst_utf8,
 				PURPLE_MESSAGE_RECV, buf3, time(NULL));
 			g_free(send_inst_utf8);
-
-			free_triple(zt1);
 		}
 		g_free(stripped_sender);
 		g_free(buf3);
@@ -1028,9 +1018,7 @@
 	f = g_fopen(fname, "r");
 	if (f) {
 		char **triple;
-		char *recip;
-		char *z_class;
-		char *z_instance;
+		ZSubscription_t sub;
 
 		while (fgets(buff, BUFSIZ, f)) {
 			strip_comments(buff);
@@ -1041,16 +1029,16 @@
 					char *atptr;
 
 					if (triple[2] == NULL) {
-						recip = g_malloc0(1);
+						sub.zsub_recipient = g_malloc0(1);
 					} else if (!g_ascii_strcasecmp(triple[2], "%me%")) {
-						recip = g_strdup(zephyr->username);
+						sub.zsub_recipient = g_strdup(zephyr->username);
 					} else if (!g_ascii_strcasecmp(triple[2], "*")) {
 						/* wildcard
 						 * form of class,instance,* */
-						recip = g_malloc0(1);
+						sub.zsub_recipient = g_malloc0(1);
 					} else if (!g_ascii_strcasecmp(triple[2], tmp)) {
 						/* form of class,instance,aatharuv@ATHENA.MIT.EDU */
-						recip = g_strdup(triple[2]);
+						sub.zsub_recipient = g_strdup(triple[2]);
 					} else if ((atptr = strchr(triple[2], '@')) != NULL) {
 						/* form of class,instance,*@ANDREW.CMU.EDU
 						 * class,instance,@ANDREW.CMU.EDU
@@ -1059,44 +1047,46 @@
 						 */
 						char *realmat = g_strdup_printf("@%s",zephyr->realm);
 
-						if (!g_ascii_strcasecmp(atptr, realmat))
-							recip = g_malloc0(1);
-						else
-							recip = g_strdup(atptr);
+						if (!g_ascii_strcasecmp(atptr, realmat)) {
+							sub.zsub_recipient = g_malloc0(1);
+						} else {
+							sub.zsub_recipient = g_strdup(atptr);
+						}
 						g_free(realmat);
 					} else {
-						recip = g_strdup(triple[2]);
+						sub.zsub_recipient = g_strdup(triple[2]);
 					}
 					g_free(tmp);
 
-					if (!g_ascii_strcasecmp(triple[0],"%host%")) {
-						z_class = g_strdup(zephyr->ourhost);
-					} else if (!g_ascii_strcasecmp(triple[0],"%canon%")) {
-						z_class = g_strdup(zephyr->ourhostcanon);
+					if (!g_ascii_strcasecmp(triple[0], "%host%")) {
+						sub.zsub_class = g_strdup(zephyr->ourhost);
+					} else if (!g_ascii_strcasecmp(triple[0], "%canon%")) {
+						sub.zsub_class = g_strdup(zephyr->ourhostcanon);
 					} else {
-						z_class = g_strdup(triple[0]);
+						sub.zsub_class = g_strdup(triple[0]);
 					}
 
-					if (!g_ascii_strcasecmp(triple[1],"%host%")) {
-						z_instance = g_strdup(zephyr->ourhost);
-					} else if (!g_ascii_strcasecmp(triple[1],"%canon%")) {
-						z_instance = g_strdup(zephyr->ourhostcanon);
+					if (!g_ascii_strcasecmp(triple[1], "%host%")) {
+						sub.zsub_classinst = g_strdup(zephyr->ourhost);
+					} else if (!g_ascii_strcasecmp(triple[1], "%canon%")) {
+						sub.zsub_classinst = g_strdup(zephyr->ourhostcanon);
 					} else {
-						z_instance = g_strdup(triple[1]);
+						sub.zsub_classinst = g_strdup(triple[1]);
 					}
 
 					/* There should be some sort of error report listing classes that couldn't be subbed to.
 					   Not important right now though */
 
-					if (zephyr->subscribe_to(zephyr, z_class, z_instance, recip) != ZERR_NONE) {
-						purple_debug_error("zephyr", "Couldn't subscribe to %s, %s, %s\n", z_class,z_instance,recip);
+					if (zephyr->subscribe_to(zephyr, &sub) != ZERR_NONE) {
+						purple_debug_error("zephyr", "Couldn't subscribe to %s, %s, %s\n",
+						                   sub.zsub_class, sub.zsub_classinst, sub.zsub_recipient);
 					}
 
-					zephyr->subscrips = g_slist_append(zephyr->subscrips, new_triple(zephyr,z_class,z_instance,recip));
+					zephyr->subscrips = g_slist_append(zephyr->subscrips, new_triple(zephyr, &sub));
 					/*					  g_hash_table_destroy(sub_hash_table); */
-					g_free(z_instance);
-					g_free(z_class);
-					g_free(recip);
+					g_free(sub.zsub_class);
+					g_free(sub.zsub_classinst);
+					g_free(sub.zsub_recipient);
 				}
 				g_strfreev(triple);
 			}
@@ -1424,6 +1414,7 @@
 	zephyr_account *zephyr;
 	ZephyrLoginFunc login;
 	GSourceFunc check_notify;
+	ZSubscription_t sub;
 
 	gc = purple_account_get_connection(account);
 
@@ -1465,7 +1456,11 @@
 	zephyr->krbtkfile = NULL;
 	zephyr_inithosts(zephyr);
 
-	if (zephyr->subscribe_to(zephyr, "MESSAGE", "PERSONAL", zephyr->username) != ZERR_NONE) {
+	sub.zsub_class = "MESSAGE";
+	sub.zsub_classinst = "PERSONAL";
+	sub.zsub_recipient = zephyr->username;
+
+	if (zephyr->subscribe_to(zephyr, &sub) != ZERR_NONE) {
 		/* XXX don't translate this yet. It could be written better */
 		/* XXX error messages could be handled with more detail */
 		purple_notify_error(gc, NULL,
@@ -1665,18 +1660,17 @@
 
 	sig = zephyr_get_signature();
 
-	gcc = purple_conversations_find_chat_with_account(zt->name,
-												 purple_connection_get_account(gc));
+	gcc = purple_conversations_find_chat_with_account(zt->name, purple_connection_get_account(gc));
 
 	if (!(inst = (char *)purple_chat_conversation_get_topic(gcc)))
 		inst = g_strdup("PERSONAL");
 
-	if (!g_ascii_strcasecmp(zt->recipient, "*"))
-		recipient = local_zephyr_normalize(zephyr,"");
-	else
-		recipient = local_zephyr_normalize(zephyr,zt->recipient);
-
-	zephyr_send_message(zephyr, zt->class, inst, recipient,
+	if (!g_ascii_strcasecmp(zt->sub.zsub_recipient, "*")) {
+		recipient = local_zephyr_normalize(zephyr, "");
+	} else {
+		recipient = local_zephyr_normalize(zephyr, zt->sub.zsub_recipient);
+	}
+	zephyr_send_message(zephyr, zt->sub.zsub_class, inst, recipient,
 		purple_message_get_contents(msg), sig, "");
 	return 0;
 }
@@ -1976,9 +1970,11 @@
 
 /* Called when the server notifies us a message couldn't get sent */
 
-static void zephyr_subscribe_failed(PurpleConnection *gc,char * z_class, char *z_instance, char * z_recipient, char* z_galaxy)
+static void
+zephyr_subscribe_failed(PurpleConnection *gc, const ZSubscription_t *sub)
 {
-	gchar* subscribe_failed = g_strdup_printf(_("Attempt to subscribe to %s,%s,%s failed"), z_class, z_instance,z_recipient);
+	gchar* subscribe_failed = g_strdup_printf(_("Attempt to subscribe to %s,%s,%s failed"),
+	                                          sub->zsub_class, sub->zsub_classinst, sub->zsub_recipient);
 	purple_notify_error(gc,"", subscribe_failed, NULL, purple_request_cpar_from_connection(gc));
 	g_free(subscribe_failed);
 }
@@ -1998,79 +1994,77 @@
 }
 
 
-static void zephyr_join_chat(PurpleConnection * gc, GHashTable * data)
+static void
+zephyr_open_sub(PurpleConnection *gc, zephyr_triple *zt, char *instance)
 {
-	/*	ZSubscription_t sub; */
-	zephyr_triple *zt1, *zt2;
-	const char *classname;
-	const char *instname;
-	const char *recip;
+	zt->open = TRUE;
+	purple_serv_got_joined_chat(gc, zt->id, zt->name);
+	if (!g_ascii_strcasecmp(instance, "*")) {
+		instance = "PERSONAL";
+	}
+	zephyr_chat_set_topic(gc, zt->id, instance);
+}
+
+static void
+zephyr_join_chat(PurpleConnection *gc, ZSubscription_t *sub)
+{
+	zephyr_triple *zt;
 	zephyr_account *zephyr = purple_connection_get_protocol_data(gc);
 
 	g_return_if_fail(zephyr != NULL);
 
-	classname = g_hash_table_lookup(data, "class");
-	instname = g_hash_table_lookup(data, "instance");
-	recip = g_hash_table_lookup(data, "recipient");
-	if (!classname)
+	if (!sub->zsub_class) {
 		return;
-
-	if (!g_ascii_strcasecmp(classname,"%host%"))
-		classname = zephyr->ourhost;
-	if (!g_ascii_strcasecmp(classname,"%canon%"))
-		classname = zephyr->ourhostcanon;
-
-	if (!instname || *instname == '\0')
-		instname = "*";
-
-	if (!g_ascii_strcasecmp(instname,"%host%"))
-		instname = zephyr->ourhost;
-	if (!g_ascii_strcasecmp(instname,"%canon%"))
-		instname = zephyr->ourhostcanon;
-
-	if (!recip || (*recip == '*'))
-		recip = "";
-	if (!g_ascii_strcasecmp(recip, "%me%"))
-		recip = zephyr->username;
-
-	zt1 = new_triple(zephyr,classname, instname, recip);
-	zt2 = find_sub_by_triple(zephyr,zt1);
-	if (zt2) {
-		free_triple(zt1);
-		if (!zt2->open) {
-			if (!g_ascii_strcasecmp(instname,"*"))
-				instname = "PERSONAL";
-			purple_serv_got_joined_chat(gc, zt2->id, zt2->name);
-			zephyr_chat_set_topic(gc,zt2->id,instname);
-			zt2->open = TRUE;
+	}
+	if (!g_ascii_strcasecmp(sub->zsub_class, "%host%")) {
+		sub->zsub_class = zephyr->ourhost;
+	} else if (!g_ascii_strcasecmp(sub->zsub_class, "%canon%")) {
+		sub->zsub_class = zephyr->ourhostcanon;
+	}
+
+	if (!sub->zsub_classinst || *sub->zsub_classinst == '\0') {
+		sub->zsub_classinst = "*";
+	} else if (!g_ascii_strcasecmp(sub->zsub_classinst, "%host%")) {
+		sub->zsub_classinst = zephyr->ourhost;
+	} else if (!g_ascii_strcasecmp(sub->zsub_classinst, "%canon%")) {
+		sub->zsub_classinst = zephyr->ourhostcanon;
+	}
+
+	if (!sub->zsub_recipient || *sub->zsub_recipient == '*') {
+		sub->zsub_recipient = "";
+	} else if (!g_ascii_strcasecmp(sub->zsub_recipient, "%me%")) {
+		sub->zsub_recipient = zephyr->username;
+	}
+
+	zt = find_sub_by_sub(zephyr, sub);
+	if (zt) {
+		if (!zt->open) {
+			zephyr_open_sub(gc, zt, sub->zsub_classinst);
 		}
 		return;
 	}
 
-	/*	sub.zsub_class = zt1->class;
-		sub.zsub_classinst = zt1->instance;
-		sub.zsub_recipient = zt1->recipient; */
-
-	if (zephyr->subscribe_to(zephyr, zt1->class, zt1->instance, zt1->recipient) != ZERR_NONE) {
+	if (zephyr->subscribe_to(zephyr, sub) != ZERR_NONE) {
 		/* XXX output better subscription information */
-		zephyr_subscribe_failed(gc,zt1->class,zt1->instance,zt1->recipient,NULL);
-		free_triple(zt1);
+		zephyr_subscribe_failed(gc, sub);
 		return;
 	}
 
-	zephyr->subscrips = g_slist_append(zephyr->subscrips, zt1);
-	zt1->open = TRUE;
-	purple_serv_got_joined_chat(gc, zt1->id, zt1->name);
-	if (!g_ascii_strcasecmp(instname,"*"))
-		instname = "PERSONAL";
-	zephyr_chat_set_topic(gc,zt1->id,instname);
+	zt = new_triple(zephyr, sub);
+	zephyr->subscrips = g_slist_append(zephyr->subscrips, zt);
+	zephyr_open_sub(gc, zt, sub->zsub_classinst);
 }
 
 static void
 zephyr_protocol_chat_join(PurpleProtocolChat *protocol_chat,
                           PurpleConnection *gc, GHashTable * data)
 {
-	zephyr_join_chat(gc, data);
+	ZSubscription_t sub = {
+	        .zsub_class = g_hash_table_lookup(data, "class"),
+	        .zsub_classinst = g_hash_table_lookup(data, "instance"),
+	        .zsub_recipient = g_hash_table_lookup(data, "recipient")
+	};
+	zephyr_join_chat(gc, &sub);
 }
 
 static void
@@ -2248,11 +2242,12 @@
 					       const char *cmd, char **args, char **error, void *data)
 {
 	/* Join a new zephyr chat */
-	GHashTable *triple = g_hash_table_new(NULL,NULL);
-	g_hash_table_insert(triple,"class",args[0]);
-	g_hash_table_insert(triple,"instance",args[1]);
-	g_hash_table_insert(triple,"recipient",args[2]);
-	zephyr_join_chat(purple_conversation_get_connection(conv),triple);
+	ZSubscription_t sub = {
+	        .zsub_class = args[0],
+	        .zsub_classinst = args[1],
+	        .zsub_recipient = args[2]
+	};
+	zephyr_join_chat(purple_conversation_get_connection(conv), &sub);
 	return PURPLE_CMD_RET_OK;
 }
 
@@ -2413,7 +2408,7 @@
 	for (GSList *s = zephyr->subscrips; s; s = s->next) {
 		zephyr_triple *zt = s->data;
 		/* XXX We really should care if this fails */
-		zephyr->subscribe_to(zephyr, zt->class, zt->instance, zt->recipient);
+		zephyr->subscribe_to(zephyr, &zt->sub);
 	}
 	/* XXX handle unsubscriptions */
 }
