changeset 13810:a84523152a24

[gaim-migrate @ 16240] This is not a completed update, but it has useful bits and bug fixes and the completed update will take some more time. This adds support for some of the status API to Tcl, as well as improving the handling of several of the pointer types (by introducing a gaim reference object type and appropriate string roundtrip functions) and introducing some "type safety". committer: Tailor Script <tailor@pidgin.im>
author Ethan Blanton <elb@pidgin.im>
date Sat, 10 Jun 2006 18:01:11 +0000
parents cd93e6e90044
children e0e8959d92a0
files plugins/tcl/Makefile.am plugins/tcl/tcl.c plugins/tcl/tcl_cmds.c plugins/tcl/tcl_gaim.h plugins/tcl/tcl_signals.c
diffstat 5 files changed, 444 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/tcl/Makefile.am	Sat Jun 10 17:39:15 2006 +0000
+++ b/plugins/tcl/Makefile.am	Sat Jun 10 18:01:11 2006 +0000
@@ -4,7 +4,8 @@
 
 plugin_LTLIBRARIES = tcl.la
 
-tcl_la_SOURCES = tcl.c tcl_glib.c tcl_glib.h tcl_cmds.c tcl_signals.c tcl_gaim.h
+tcl_la_SOURCES = tcl.c tcl_glib.c tcl_glib.h tcl_cmds.c tcl_signals.c tcl_gaim.h \
+                 tcl_ref.c
 
 EXTRA_DIST = signal-test.tcl Makefile.mingw
 
--- a/plugins/tcl/tcl.c	Sat Jun 10 17:39:15 2006 +0000
+++ b/plugins/tcl/tcl.c	Sat Jun 10 18:01:11 2006 +0000
@@ -50,6 +50,12 @@
 	Tcl_Interp *interp;
 };
 
+GaimStringref *GaimTclRefAccount;
+GaimStringref *GaimTclRefConversation;
+GaimStringref *GaimTclRefStatus;
+GaimStringref *GaimTclRefStatusAttr;
+GaimStringref *GaimTclRefStatusType;
+
 static GHashTable *tcl_plugins = NULL;
 
 GaimPlugin *_tcl_plugin;
@@ -125,6 +131,9 @@
 	Tcl_CreateObjCommand(interp, "::gaim::prefs", tcl_cmd_prefs, (ClientData)NULL, NULL);
 	Tcl_CreateObjCommand(interp, "::gaim::send_im", tcl_cmd_send_im, (ClientData)NULL, NULL);
 	Tcl_CreateObjCommand(interp, "::gaim::signal", tcl_cmd_signal, (ClientData)NULL, NULL);
+	Tcl_CreateObjCommand(interp, "::gaim::status", tcl_cmd_status_type, (ClientData)NULL, NULL);
+	Tcl_CreateObjCommand(interp, "::gaim::status_attr", tcl_cmd_status_type, (ClientData)NULL, NULL);
+	Tcl_CreateObjCommand(interp, "::gaim::status_type", tcl_cmd_status_type, (ClientData)NULL, NULL);
 	Tcl_CreateObjCommand(interp, "::gaim::unload", tcl_cmd_unload, (ClientData)NULL, NULL);
 
 	return 0;
@@ -329,6 +338,14 @@
 		return FALSE;
 	tcl_glib_init();
 	tcl_signal_init();
+	gaim_tcl_ref_init();
+
+	GaimTclRefAccount = gaim_stringref_new("Account");
+	GaimTclRefConversation = gaim_stringref_new("Conversation");
+	GaimTclRefStatus = gaim_stringref_new("Status");
+	GaimTclRefStatusAttr = gaim_stringref_new("StatusAttr");
+	GaimTclRefStatusType = gaim_stringref_new("StatusType");
+
 	tcl_plugins = g_hash_table_new(g_direct_hash, g_direct_equal);
 
 #ifdef HAVE_TK
@@ -343,6 +360,12 @@
 	g_hash_table_destroy(tcl_plugins);
 	tcl_plugins = NULL;
 
+	gaim_stringref_unref(GaimTclRefAccount);
+	gaim_stringref_unref(GaimTclRefConversation);
+	gaim_stringref_unref(GaimTclRefStatus);
+	gaim_stringref_unref(GaimTclRefStatusAttr);
+	gaim_stringref_unref(GaimTclRefStatusType);
+
 	return TRUE;
 }
 
--- a/plugins/tcl/tcl_cmds.c	Sat Jun 10 17:39:15 2006 +0000
+++ b/plugins/tcl/tcl_cmds.c	Sat Jun 10 18:01:11 2006 +0000
@@ -35,33 +35,46 @@
 
 #include "tcl_gaim.h"
 
-static gboolean tcl_validate_account(GaimAccount *account, Tcl_Interp *interp);
-static gboolean tcl_validate_conversation(GaimConversation *convo, Tcl_Interp *interp);
+static GaimAccount *tcl_validate_account(Tcl_Obj *obj, Tcl_Interp *interp);
+static GaimConversation *tcl_validate_conversation(Tcl_Obj *obj, Tcl_Interp *interp);
 static gboolean tcl_validate_gc(GaimConnection *gc);
 
-static gboolean tcl_validate_account(GaimAccount *account, Tcl_Interp *interp)
+static GaimAccount *tcl_validate_account(Tcl_Obj *obj, Tcl_Interp *interp)
 {
+	GaimAccount *account;
 	GList *cur;
+
+	account = gaim_tcl_ref_get(interp, obj, GaimTclRefAccount);
+
+	if (account == NULL)
+		return NULL;
+
 	for (cur = gaim_accounts_get_all(); cur != NULL; cur = g_list_next(cur)) {
 		if (account == cur->data)
-			return TRUE;
+			return account;
 	}
 	if (interp != NULL)
 		Tcl_SetStringObj(Tcl_GetObjResult(interp), "invalid account", -1);
-	return FALSE;
+	return NULL;
 }
 
-static gboolean tcl_validate_conversation(GaimConversation *convo, Tcl_Interp *interp)
+static GaimConversation *tcl_validate_conversation(Tcl_Obj *obj, Tcl_Interp *interp)
 {
+	GaimConversation *convo;
 	GList *cur;
 
+	convo = gaim_tcl_ref_get(interp, obj, GaimTclRefConversation);
+
+	if (convo == NULL)
+		return NULL;
+
 	for (cur = gaim_get_conversations(); cur != NULL; cur = g_list_next(cur)) {
 		if (convo == cur->data)
-			return TRUE;
+			return convo;
 	}
 	if (interp != NULL)
 		Tcl_SetStringObj(Tcl_GetObjResult(interp), "invalid account", -1);
-	return FALSE;
+	return NULL;
 }
 
 static gboolean tcl_validate_gc(GaimConnection *gc)
@@ -77,19 +90,24 @@
 int tcl_cmd_account(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
 {
 	Tcl_Obj *result = Tcl_GetObjResult(interp), *list, *elem;
-	const char *cmds[] = { "alias", "connect", "connection", "disconnect", "find",
-			 "handle", "isconnected", "list",
-			 "protocol", "username", NULL };
-	enum { CMD_ACCOUNT_ALIAS, CMD_ACCOUNT_CONNECT, CMD_ACCOUNT_CONNECTION,
-	       CMD_ACCOUNT_DISCONNECT, CMD_ACCOUNT_FIND, CMD_ACCOUNT_HANDLE,
-	       CMD_ACCOUNT_ISCONNECTED, CMD_ACCOUNT_LIST,
-	       CMD_ACCOUNT_PROTOCOL, CMD_ACCOUNT_USERNAME } cmd;
+	const char *cmds[] = { "active_status", "alias", "connect",
+	                       "connection", "disconnect", "enabled", "find",
+	                       "handle", "isconnected", "list", "protocol",
+	                       "status_type", "status_types", "username", NULL };
+	enum { CMD_ACCOUNT_ACTIVE_STATUS, CMD_ACCOUNT_ALIAS,
+	       CMD_ACCOUNT_CONNECT, CMD_ACCOUNT_CONNECTION,
+	       CMD_ACCOUNT_DISCONNECT, CMD_ACCOUNT_ENABLED, CMD_ACCOUNT_FIND,
+	       CMD_ACCOUNT_HANDLE, CMD_ACCOUNT_ISCONNECTED, CMD_ACCOUNT_LIST,
+	       CMD_ACCOUNT_PROTOCOL, CMD_ACCOUNT_STATUS_TYPE,
+	       CMD_ACCOUNT_STATUS_TYPES, CMD_ACCOUNT_USERNAME } cmd;
 	const char *listopts[] = { "-all", "-online", NULL };
 	enum { CMD_ACCOUNTLIST_ALL, CMD_ACCOUNTLIST_ONLINE } listopt;
 	const char *alias;
-	GList *cur;
+	const GList *cur;
 	GaimAccount *account;
+	GaimStatusType *status_type;
 	int error;
+	int b;
 
 	if (objc < 2) {
 		Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?");
@@ -100,13 +118,23 @@
 		return error;
 
 	switch (cmd) {
+	case CMD_ACCOUNT_ACTIVE_STATUS:
+		if (objc != 3) {
+			Tcl_WrongNumArgs(interp, 2, objv, "account");
+			return TCL_ERROR;
+		}
+		if ((account = tcl_validate_account(objv[2], interp)) == NULL)
+			return TCL_ERROR;
+		Tcl_SetObjResult(interp,
+		                 gaim_tcl_ref_new(GaimTclRefStatus,
+		                                  gaim_account_get_active_status(account)));
+		break;
 	case CMD_ACCOUNT_ALIAS:
 		if (objc != 3) {
 			Tcl_WrongNumArgs(interp, 2, objv, "account");
 			return TCL_ERROR;
 		}
-		error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account);
-		if (error || !tcl_validate_account(account, interp))
+		if ((account = tcl_validate_account(objv[2], interp)) == NULL)
 			return TCL_ERROR;
 		alias = gaim_account_get_alias(account);
 		Tcl_SetStringObj(result, alias ? (char *)alias : "", -1);
@@ -116,8 +144,7 @@
 			Tcl_WrongNumArgs(interp, 2, objv, "account");
 			return TCL_ERROR;
 		}
-		error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account);
-		if (error || !tcl_validate_account(account, interp))
+		if ((account = tcl_validate_account(objv[2], interp)) == NULL)
 			return TCL_ERROR;
 		if (!gaim_account_is_connected(account))
 			gaim_account_connect(account);
@@ -128,8 +155,8 @@
 			Tcl_WrongNumArgs(interp, 2, objv, "account");
 			return TCL_ERROR;
 		}
-		error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account);
-		if (error || !tcl_validate_account(account, interp))
+
+		if ((account = tcl_validate_account(objv[2], interp)) == NULL)
 			return TCL_ERROR;
 		Tcl_SetIntObj(result, (int)gaim_account_get_connection(account));
 		break;
@@ -138,11 +165,27 @@
 			Tcl_WrongNumArgs(interp, 2, objv, "account");
 			return TCL_ERROR;
 		}
-		error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account);
-		if (error || !tcl_validate_account(account, interp))
+		if ((account = tcl_validate_account(objv[2], interp)) == NULL)
 			return TCL_ERROR;
 		gaim_account_disconnect(account);
 		break;
+	case CMD_ACCOUNT_ENABLED:
+		if (objc != 3 && objc != 4) {
+			Tcl_WrongNumArgs(interp, 2, objv, "account ?enabled?");
+			return TCL_ERROR;
+		}
+		if ((account = tcl_validate_account(objv[2], interp)) == NULL)
+			return TCL_ERROR;
+		if (objc == 3) {
+			Tcl_SetBooleanObj(result,
+					  gaim_account_get_enabled(account,
+								   gaim_core_get_ui()));
+		} else {
+			if ((error = Tcl_GetBooleanFromObj(interp, objv[3], &b)) != TCL_OK)
+				return TCL_ERROR;
+			gaim_account_set_enabled(account, gaim_core_get_ui(), b);
+		}
+		break;
 	case CMD_ACCOUNT_FIND:
 		if (objc != 4) {
 			Tcl_WrongNumArgs(interp, 2, objv, "username protocol");
@@ -163,8 +206,7 @@
 			Tcl_WrongNumArgs(interp, 2, objv, "account");
 			return TCL_ERROR;
 		}
-		error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account);
-		if (error || !tcl_validate_account(account, interp))
+		if ((account = tcl_validate_account(objv[2], interp)) == NULL)
 			return TCL_ERROR;
 		Tcl_SetBooleanObj(result, gaim_account_is_connected(account));
 		break;
@@ -183,7 +225,7 @@
 			account = cur->data;
 			if (listopt == CMD_ACCOUNTLIST_ONLINE && !gaim_account_is_connected(account))
 				continue;
-			elem = Tcl_NewIntObj((int)account);
+			elem = gaim_tcl_ref_new(GaimTclRefAccount, account);
 			Tcl_ListObjAppendElement(interp, list, elem);
 		}
 		Tcl_SetObjResult(interp, list);
@@ -193,18 +235,63 @@
 			Tcl_WrongNumArgs(interp, 2, objv, "account");
 			return TCL_ERROR;
 		}
-		error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account);
-		if (error || !tcl_validate_account(account, interp))
+		if ((account = tcl_validate_account(objv[2], interp)) == NULL)
 			return TCL_ERROR;
 		Tcl_SetStringObj(result, (char *)gaim_account_get_protocol_id(account), -1);
 		break;
+	case CMD_ACCOUNT_STATUS_TYPE:
+		if (objc != 4 && objc != 5) {
+			Tcl_WrongNumArgs(interp, 2, objv, "account ?statustype? ?-primitive primitive?");
+			return TCL_ERROR;
+		}
+		if ((account = tcl_validate_account(objv[2], interp)) == NULL)
+			return TCL_ERROR;
+		if (objc == 4) {
+			status_type = gaim_account_get_status_type(account,
+								   Tcl_GetString(objv[3]));
+		} else {
+			GaimStatusPrimitive primitive;
+			if (strcmp(Tcl_GetString(objv[3]), "-primitive")) {
+				Tcl_SetStringObj(result, "bad option \"", -1);
+				Tcl_AppendObjToObj(result, objv[3]);
+				Tcl_AppendToObj(result,
+						"\": should be -primitive", -1);
+				return TCL_ERROR;
+			}
+			primitive = gaim_primitive_get_type_from_id(Tcl_GetString(objv[4]));
+			status_type = gaim_account_get_status_type_with_primitive(account,
+										  primitive);
+		}
+		if (status_type == NULL) {
+			Tcl_SetStringObj(result, "status type not found", -1);
+			return TCL_ERROR;
+		}
+		Tcl_SetObjResult(interp,
+				 gaim_tcl_ref_new(GaimTclRefStatusType,
+						  status_type));
+		break;
+	case CMD_ACCOUNT_STATUS_TYPES:
+		if (objc != 3) {
+			Tcl_WrongNumArgs(interp, 2, objv, "account");
+			return TCL_ERROR;
+		}
+		if ((account = tcl_validate_account(objv[2], interp)) == NULL)
+			return TCL_ERROR;
+		list = Tcl_NewListObj(0, NULL);
+		for (cur = gaim_account_get_status_types(account); cur != NULL;
+		     cur = g_list_next(cur)) {
+			Tcl_ListObjAppendElement(interp, list,
+						 gaim_tcl_ref_new(GaimTclRefStatusType,
+								  cur->data));
+		}
+		Tcl_SetObjResult(interp, list);
+		break;
 	case CMD_ACCOUNT_USERNAME:
 		if (objc != 3) {
 			Tcl_WrongNumArgs(interp, 2, objv, "account");
 			return TCL_ERROR;
 		}
-		error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account);
-		if (error || !tcl_validate_account(account, interp))
+		if ((account = tcl_validate_account(objv[2], interp)) == NULL)
 			return TCL_ERROR;
 		Tcl_SetStringObj(result, (char *)gaim_account_get_username(account), -1);
 		break;
@@ -227,9 +314,7 @@
 
 	type = Tcl_GetString(elems[0]);
 	name = Tcl_GetString(elems[1]);
-	if (Tcl_GetIntFromObj(interp, elems[2], (int *)&account) != TCL_OK)
-		return NULL;
-	if (!tcl_validate_account(account, interp))
+	if ((account = tcl_validate_account(elems[2], interp)) == NULL)
 		return NULL;
 
 	if (!strcmp(type, "buddy")) {
@@ -301,15 +386,11 @@
 				Tcl_SetStringObj(result, "invalid buddy", -1);
 				return TCL_ERROR;
 			}
-			if ((error = Tcl_GetIntFromObj(interp, elems[2], (int *)&account)) != TCL_OK)
-				return TCL_ERROR;
-			if (!tcl_validate_account(account, interp))
+			if ((account = tcl_validate_account(elems[2], interp)) == NULL)
 				return TCL_ERROR;
 			serv_get_info(gaim_account_get_connection(account), Tcl_GetString(elems[1]));
 		} else {
-			if ((error = Tcl_GetIntFromObj(interp, objv[2], (int *)&account)) != TCL_OK)
-				return error;
-			if (!tcl_validate_account(account, interp))
+			if ((account = tcl_validate_account(objv[2], interp)) == NULL)
 				return TCL_ERROR;
 			serv_get_info(gaim_account_get_connection(account), Tcl_GetString(objv[3]));
 		}
@@ -351,7 +432,7 @@
 						tclbud = Tcl_NewListObj(0, NULL);
 						Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj("buddy", -1));
 						Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj(bud->name, -1));
-						Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewIntObj((int)bud->account));
+						Tcl_ListObjAppendElement(interp, tclbud, gaim_tcl_ref_new(GaimTclRefAccount, bud->account));
 						Tcl_ListObjAppendElement(interp, tclcontactlist, tclbud);
 					}
 					if (count) {
@@ -368,7 +449,7 @@
 					tclbud = Tcl_NewListObj(0, NULL);
 					Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj("chat", -1));
 					Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewStringObj(cnode->alias, -1));
-					Tcl_ListObjAppendElement(interp, tclbud, Tcl_NewIntObj((int)cnode->account));
+					Tcl_ListObjAppendElement(interp, tclbud, gaim_tcl_ref_new(GaimTclRefAccount, cnode->account));
 					Tcl_ListObjAppendElement(interp, tclgrouplist, tclbud);
 					break;
 				default:
@@ -483,10 +564,7 @@
 			return TCL_ERROR;
 		}
 		account = NULL;
-		if ((error = Tcl_GetIntFromObj(interp, objv[2],
-					       (int *)&account)) != TCL_OK)
-			return error;
-		if (!tcl_validate_account(account, interp))
+		if ((account = tcl_validate_account(objv[2], interp)) == NULL)
 			return TCL_ERROR;
 		convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_ANY,
 							    Tcl_GetString(objv[3]),
@@ -538,9 +616,7 @@
 			Tcl_WrongNumArgs(interp, 2, objv, "?options? account name");
 			return TCL_ERROR;
 		}
-		if ((error = Tcl_GetIntFromObj(interp, objv[argsused++], (int *)&account)) != TCL_OK)
-			return error;
-		if (!tcl_validate_account(account, interp))
+		if ((account = tcl_validate_account(objv[argsused++], interp)) == NULL)
 			return TCL_ERROR;
 		convo = gaim_conversation_new(type, account, Tcl_GetString(objv[argsused]));
 		Tcl_SetIntObj(result, (int)convo);
@@ -550,12 +626,10 @@
 			Tcl_WrongNumArgs(interp, 2, objv, "conversation style from what");
 			return TCL_ERROR;
 		}
-		if ((error = Tcl_GetIntFromObj(interp, objv[2], (int *)&convo)) != TCL_OK)
-			return error;
+		if ((convo = tcl_validate_conversation(objv[2], interp)) == NULL)
+			return TCL_ERROR;
 		if ((error = Tcl_GetIndexFromObj(interp, objv[3], styles, "style", 0, (int *)&style)) != TCL_OK)
 			return error;
-		if (!tcl_validate_conversation(convo, interp))
-			return TCL_ERROR;
 		from = Tcl_GetString(objv[4]);
 		what = Tcl_GetString(objv[5]);
 		
@@ -856,6 +930,7 @@
 			return error;
 		}
 		handler->signal = objv[3];
+		Tcl_IncrRefCount(handler->signal);
 		handler->args = objv[4];
 		handler->proc = objv[5];
 		handler->interp = interp;
@@ -868,7 +943,7 @@
 		break;
 	case CMD_SIGNAL_DISCONNECT:
 		if (objc != 4) {
-			Tcl_WrongNumArgs(interp, 2, objv, "signal");
+			Tcl_WrongNumArgs(interp, 2, objv, "instance signal");
 			return TCL_ERROR;
 		}
 		if ((error = Tcl_GetIntFromObj(interp, objv[2], (int *)&instance)) != TCL_OK)
@@ -880,6 +955,248 @@
 	return TCL_OK;
 }
 
+int tcl_cmd_status(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
+{
+	const char *cmds[] = { "attr", "type" };
+	enum { CMD_STATUS_ATTR, CMD_STATUS_TYPE } cmd;
+	Tcl_Obj *result = Tcl_GetObjResult(interp);
+	GaimStatus *status;
+	GaimStatusType *status_type;
+	GaimValue *value;
+	int error;
+
+	if (objc < 2) {
+		Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?");
+		return TCL_ERROR;
+	}
+
+	if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK)
+		return error;
+
+	switch (cmd) {
+	case CMD_STATUS_ATTR:
+		if (objc != 4) {
+			Tcl_WrongNumArgs(interp, 2, objv, "status attr_id");
+			return TCL_ERROR;
+		}
+		if ((status = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatus)) == NULL)
+			return TCL_ERROR;
+		value = gaim_status_get_attr_value(status, Tcl_GetString(objv[3]));
+		if (value == NULL) {
+			Tcl_SetStringObj(result, "no such attribute", -1);
+			return TCL_ERROR;
+		}
+		switch (gaim_value_get_type(value)) {
+		case GAIM_TYPE_BOOLEAN:
+			Tcl_SetBooleanObj(result, gaim_value_get_boolean(value));
+			break;
+		case GAIM_TYPE_INT:
+			Tcl_SetIntObj(result, gaim_value_get_int(value));
+			break;
+		case GAIM_TYPE_STRING:
+			Tcl_SetStringObj(result, gaim_value_get_string(value), -1);
+			break;
+		default:
+			Tcl_SetStringObj(result, "attribute has unknown type", -1);
+			return TCL_ERROR;
+		}
+		break;
+	case CMD_STATUS_TYPE:
+		if (objc != 3) {
+			Tcl_WrongNumArgs(interp, 2, objv, "status");
+			return TCL_ERROR;
+		}
+		if ((status = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatus)) == NULL)
+			return TCL_ERROR;
+		status_type = gaim_status_get_type(status);
+		Tcl_SetObjResult(interp, gaim_tcl_ref_new(GaimTclRefStatusType,
+		                                          status_type));
+		break;
+	}
+
+	return TCL_OK;
+}
+
+int tcl_cmd_status_attr(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
+{
+	const char *cmds[] = { "id", "name", NULL };
+	enum { CMD_STATUS_ATTR_ID, CMD_STATUS_ATTR_NAME } cmd;
+	Tcl_Obj *result = Tcl_GetObjResult(interp);
+	GaimStatusAttr *attr;
+	int error;
+
+	if (objc < 2) {
+		Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?");
+		return TCL_ERROR;
+	}
+
+	if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK)
+		return error;
+
+	switch (cmd) {
+	case CMD_STATUS_ATTR_ID:
+		if (objc != 3) {
+			Tcl_WrongNumArgs(interp, 2, objv, "attr");
+			return TCL_ERROR;
+		}
+		if ((attr = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusAttr)) == NULL)
+			return TCL_ERROR;
+		Tcl_SetStringObj(result, gaim_status_attr_get_id(attr), -1);
+		break;
+	case CMD_STATUS_ATTR_NAME:
+		if (objc != 3) {
+			Tcl_WrongNumArgs(interp, 2, objv, "attr");
+			return TCL_ERROR;
+		}
+		if ((attr = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusAttr)) == NULL)
+			return TCL_ERROR;
+		Tcl_SetStringObj(result, gaim_status_attr_get_name(attr), -1);
+		break;
+	}
+
+	return TCL_OK;
+}
+
+int tcl_cmd_status_type(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
+{
+	const char *cmds[] = { "attr", "attrs", "available", "exclusive", "id",
+	                       "independent", "name", "primary_attr",
+	                       "primitive", "saveable", "user_settable",
+	                       NULL };
+	enum { CMD_STATUS_TYPE_ATTR, CMD_STATUS_TYPE_ATTRS,
+	       CMD_STATUS_TYPE_AVAILABLE, CMD_STATUS_TYPE_EXCLUSIVE,
+	       CMD_STATUS_TYPE_ID, CMD_STATUS_TYPE_INDEPENDENT,
+	       CMD_STATUS_TYPE_NAME, CMD_STATUS_TYPE_PRIMARY_ATTR,
+	       CMD_STATUS_TYPE_PRIMITIVE, CMD_STATUS_TYPE_SAVEABLE,
+	       CMD_STATUS_TYPE_USER_SETTABLE } cmd;
+	Tcl_Obj *result = Tcl_GetObjResult(interp);
+	GaimStatusType *status_type;
+	Tcl_Obj *list, *elem;
+	const GList *cur;
+	int error;
+
+	if (objc < 2) {
+		Tcl_WrongNumArgs(interp, 1, objv, "subcommand ?args?");
+		return TCL_ERROR;
+	}
+
+	if ((error = Tcl_GetIndexFromObj(interp, objv[1], cmds, "subcommand", 0, (int *)&cmd)) != TCL_OK)
+		return error;
+
+	switch (cmd) {
+	case CMD_STATUS_TYPE_AVAILABLE:
+		if (objc != 3) {
+			Tcl_WrongNumArgs(interp, 2, objv, "statustype");
+			return TCL_ERROR;
+		}
+		if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL)
+			return TCL_ERROR;
+		Tcl_SetBooleanObj(result, gaim_status_type_is_available(status_type));
+		break;
+	case CMD_STATUS_TYPE_ATTR:
+		if (objc != 4) {
+			Tcl_WrongNumArgs(interp, 2, objv, "statustype attr");
+			return TCL_ERROR;
+		}
+		if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL)
+			return TCL_ERROR;
+		Tcl_SetObjResult(interp,
+				 gaim_tcl_ref_new(GaimTclRefStatusAttr,
+						  gaim_status_type_get_attr(status_type,
+									    Tcl_GetStringFromObj(objv[3], NULL))));
+		break;
+	case CMD_STATUS_TYPE_ATTRS:
+		if (objc != 3) {
+			Tcl_WrongNumArgs(interp, 2, objv, "statustype");
+			return TCL_ERROR;
+		}
+		if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL)
+			return TCL_ERROR;
+		list = Tcl_NewListObj(0, NULL);
+		for (cur = gaim_status_type_get_attrs(status_type);
+		     cur != NULL; cur = g_list_next(cur)) {
+			elem = gaim_tcl_ref_new(GaimTclRefStatusAttr, cur->data);
+			Tcl_ListObjAppendElement(interp, list, elem);
+		}
+		Tcl_SetObjResult(interp, list);
+		break;
+	case CMD_STATUS_TYPE_EXCLUSIVE:
+		if (objc != 3) {
+			Tcl_WrongNumArgs(interp, 2, objv, "statustype");
+			return TCL_ERROR;
+		}
+		if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL)
+			return TCL_ERROR;
+		Tcl_SetBooleanObj(result, gaim_status_type_is_exclusive(status_type));
+		break;
+	case CMD_STATUS_TYPE_ID:
+		if (objc != 3) {
+			Tcl_WrongNumArgs(interp, 2, objv, "statustype");
+			return TCL_ERROR;
+		}
+		if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL)
+			return TCL_ERROR;
+		Tcl_SetStringObj(result, gaim_status_type_get_id(status_type), -1);
+		break;
+	case CMD_STATUS_TYPE_INDEPENDENT:
+		if (objc != 3) {
+			Tcl_WrongNumArgs(interp, 2, objv, "statustype");
+			return TCL_ERROR;
+		}
+		if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL)
+			return TCL_ERROR;
+		Tcl_SetBooleanObj(result, gaim_status_type_is_independent(status_type));
+		break;
+	case CMD_STATUS_TYPE_NAME:
+		if (objc != 3) {
+			Tcl_WrongNumArgs(interp, 2, objv, "statustype");
+			return TCL_ERROR;
+		}
+		if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL)
+			return TCL_ERROR;
+		Tcl_SetStringObj(result, gaim_status_type_get_name(status_type), -1);
+		break;
+	case CMD_STATUS_TYPE_PRIMITIVE:
+		if (objc != 3) {
+			Tcl_WrongNumArgs(interp, 2, objv, "statustype");
+			return TCL_ERROR;
+		}
+		if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL)
+			return TCL_ERROR;
+		Tcl_SetStringObj(result, gaim_primitive_get_id_from_type(gaim_status_type_get_primitive(status_type)), -1);
+		break;
+	case CMD_STATUS_TYPE_PRIMARY_ATTR:
+		if (objc != 3) {
+			Tcl_WrongNumArgs(interp, 2, objv, "statustype");
+			return TCL_ERROR;
+		}
+		if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL)
+			return TCL_ERROR;
+		Tcl_SetStringObj(result, gaim_status_type_get_primary_attr(status_type), -1);
+		break;
+	case CMD_STATUS_TYPE_SAVEABLE:
+		if (objc != 3) {
+			Tcl_WrongNumArgs(interp, 2, objv, "statustype");
+			return TCL_ERROR;
+		}
+		if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL)
+			return TCL_ERROR;
+		Tcl_SetBooleanObj(result, gaim_status_type_is_saveable(status_type));
+		break;
+	case CMD_STATUS_TYPE_USER_SETTABLE:
+		if (objc != 3) {
+			Tcl_WrongNumArgs(interp, 2, objv, "statustype");
+			return TCL_ERROR;
+		}
+		if ((status_type = gaim_tcl_ref_get(interp, objv[2], GaimTclRefStatusType)) == NULL)
+			return TCL_ERROR;
+		Tcl_SetBooleanObj(result, gaim_status_type_is_user_settable(status_type));
+		break;
+	}
+
+	return TCL_OK;
+}
+
 static gboolean unload_self(gpointer data)
 {
 	GaimPlugin *plugin = data;
--- a/plugins/tcl/tcl_gaim.h	Sat Jun 10 17:39:15 2006 +0000
+++ b/plugins/tcl/tcl_gaim.h	Sat Jun 10 18:01:11 2006 +0000
@@ -28,6 +28,7 @@
 #include "internal.h"
 #include "plugin.h"
 #include "value.h"
+#include "stringref.h"
 
 struct tcl_signal_handler {
 	Tcl_Obj *signal;
@@ -46,6 +47,13 @@
 
 extern GaimPlugin *_tcl_plugin;
 
+/* Capitalized this way because these are "types" */
+extern GaimStringref *GaimTclRefAccount;
+extern GaimStringref *GaimTclRefConversation;
+extern GaimStringref *GaimTclRefStatus;
+extern GaimStringref *GaimTclRefStatusAttr;
+extern GaimStringref *GaimTclRefStatusType;
+
 GaimPlugin *tcl_interp_get_plugin(Tcl_Interp *interp);
 
 void tcl_signal_init(void);
@@ -54,6 +62,10 @@
 gboolean tcl_signal_connect(struct tcl_signal_handler *handler);
 void tcl_signal_disconnect(void *instance, const char *signal, Tcl_Interp *interp);
 
+void gaim_tcl_ref_init();
+void *gaim_tcl_ref_get(Tcl_Interp *interp, Tcl_Obj *obj, GaimStringref *type);
+Tcl_Obj *gaim_tcl_ref_new(GaimStringref *type, void *value);
+
 Tcl_ObjCmdProc tcl_cmd_account;
 Tcl_ObjCmdProc tcl_cmd_signal_connect;
 Tcl_ObjCmdProc tcl_cmd_buddy;
@@ -65,6 +77,9 @@
 Tcl_ObjCmdProc tcl_cmd_prefs;
 Tcl_ObjCmdProc tcl_cmd_send_im;
 Tcl_ObjCmdProc tcl_cmd_signal;
+Tcl_ObjCmdProc tcl_cmd_status;
+Tcl_ObjCmdProc tcl_cmd_status_attr;
+Tcl_ObjCmdProc tcl_cmd_status_type;
 Tcl_ObjCmdProc tcl_cmd_unload;
 
 #endif /* _GAIM_TCL_GAIM_H_ */
--- a/plugins/tcl/tcl_signals.c	Sat Jun 10 17:39:15 2006 +0000
+++ b/plugins/tcl/tcl_signals.c	Sat Jun 10 18:01:11 2006 +0000
@@ -48,7 +48,8 @@
 		return;
 
 	Tcl_DecrRefCount(handler->signal);
-	Tcl_DecrRefCount(handler->namespace);
+	if (handler->namespace)
+		Tcl_DecrRefCount(handler->namespace);
 	g_free(handler);
 }
 
@@ -86,7 +87,6 @@
 				       (void *)handler))
 		return FALSE;
 
-	Tcl_IncrRefCount(handler->signal);
 	handler->namespace = new_cb_namespace ();
 	Tcl_IncrRefCount(handler->namespace);
 	proc = g_string_new("");
@@ -256,8 +256,12 @@
 			case GAIM_SUBTYPE_UNKNOWN:
 				gaim_debug(GAIM_DEBUG_ERROR, "tcl", "subtype unknown\n");
 			case GAIM_SUBTYPE_ACCOUNT:
+			case GAIM_SUBTYPE_CONVERSATION:
+				if (gaim_value_is_outgoing(handler->argtypes[i]))
+					gaim_debug_error("tcl", "pointer subtypes do not currently support outgoing arguments\n");
+				arg = gaim_tcl_ref_new(GaimTclRefAccount, va_arg(args, void *));
+				break;
 			case GAIM_SUBTYPE_CONNECTION:
-			case GAIM_SUBTYPE_CONVERSATION:
 			case GAIM_SUBTYPE_PLUGIN:
 			case GAIM_SUBTYPE_XFER:
 				/* pointers again */
@@ -281,24 +285,40 @@
 					node = va_arg(args, GaimBlistNode *);
 				switch (node->type) {
 				case GAIM_BLIST_GROUP_NODE:
-					g_string_printf(val, "group {%s}", ((GaimGroup *)node)->name);
+					arg = Tcl_NewListObj(0, NULL);
+					Tcl_ListObjAppendElement(handler->interp, arg,
+								 Tcl_NewStringObj("group", -1));
+					Tcl_ListObjAppendElement(handler->interp, arg,
+								 Tcl_NewStringObj(((GaimGroup *)node)->name, -1));
 					break;
 				case GAIM_BLIST_CONTACT_NODE:
 					/* g_string_printf(val, "contact {%s}", Contact Name? ); */
+					arg = Tcl_NewStringObj("contact", -1);
 					break;
 				case GAIM_BLIST_BUDDY_NODE:
-					g_string_printf(val, "buddy {%s} %lu", ((GaimBuddy *)node)->name,
-							(unsigned long)((GaimBuddy *)node)->account);
+					arg = Tcl_NewListObj(0, NULL);
+					Tcl_ListObjAppendElement(handler->interp, arg,
+								 Tcl_NewStringObj("buddy", -1));
+					Tcl_ListObjAppendElement(handler->interp, arg,
+								 Tcl_NewStringObj(((GaimBuddy *)node)->name, -1));
+					Tcl_ListObjAppendElement(handler->interp, arg,
+								 gaim_tcl_ref_new(GaimTclRefAccount,
+										  ((GaimBuddy *)node)->account));
 					break;
 				case GAIM_BLIST_CHAT_NODE:
-					g_string_printf(val, "chat {%s} %lu", ((GaimChat *)node)->alias,
-							(unsigned long)((GaimChat *)node)->account);
+					arg = Tcl_NewListObj(0, NULL);
+					Tcl_ListObjAppendElement(handler->interp, arg,
+								 Tcl_NewStringObj("chat", -1));
+					Tcl_ListObjAppendElement(handler->interp, arg,
+								 Tcl_NewStringObj(((GaimChat *)node)->alias, -1));
+					Tcl_ListObjAppendElement(handler->interp, arg,
+								 gaim_tcl_ref_new(GaimTclRefAccount,
+										  ((GaimChat *)node)->account));
 					break;
 				case GAIM_BLIST_OTHER_NODE:
-					g_string_printf(val, "other");
+					arg = Tcl_NewStringObj("other", -1);
 					break;
 				}
-				arg = Tcl_NewStringObj(val->str, -1);
 				break;
 			}
 		}
@@ -329,8 +349,10 @@
 	for (i = 0; i < handler->nargs; i++) {
 		g_string_printf(name, "%s::arg%d",
 				Tcl_GetString(handler->namespace), i);
-		if (gaim_value_is_outgoing(handler->argtypes[i]))
+		if (gaim_value_is_outgoing(handler->argtypes[i])
+		    && gaim_value_get_type(handler->argtypes[i]) != GAIM_TYPE_SUBTYPE)
 			Tcl_UnlinkVar(handler->interp, name->str);
+
 		/* We basically only have to deal with strings on the
 		 * way out */
 		switch (gaim_value_get_type(handler->argtypes[i])) {