Mercurial > pidgin.yaz
changeset 13815:724e4c08391a
[gaim-migrate @ 16247]
This cleans up a few missed account and conversation cases, and moves
GaimConnections to the typed pointer references.
committer: Tailor Script <tailor@pidgin.im>
author | Ethan Blanton <elb@pidgin.im> |
---|---|
date | Sat, 10 Jun 2006 19:16:58 +0000 |
parents | 6e14740ea2a0 |
children | 1b783830ca06 |
files | plugins/tcl/tcl.c plugins/tcl/tcl_cmds.c plugins/tcl/tcl_gaim.h plugins/tcl/tcl_signals.c |
diffstat | 4 files changed, 54 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/tcl/tcl.c Sat Jun 10 19:03:24 2006 +0000 +++ b/plugins/tcl/tcl.c Sat Jun 10 19:16:58 2006 +0000 @@ -51,6 +51,7 @@ }; GaimStringref *GaimTclRefAccount; +GaimStringref *GaimTclRefConnection; GaimStringref *GaimTclRefConversation; GaimStringref *GaimTclRefStatus; GaimStringref *GaimTclRefStatusAttr; @@ -341,6 +342,7 @@ gaim_tcl_ref_init(); GaimTclRefAccount = gaim_stringref_new("Account"); + GaimTclRefConnection = gaim_stringref_new("Connection"); GaimTclRefConversation = gaim_stringref_new("Conversation"); GaimTclRefStatus = gaim_stringref_new("Status"); GaimTclRefStatusAttr = gaim_stringref_new("StatusAttr"); @@ -361,6 +363,7 @@ tcl_plugins = NULL; gaim_stringref_unref(GaimTclRefAccount); + gaim_stringref_unref(GaimTclRefConnection); gaim_stringref_unref(GaimTclRefConversation); gaim_stringref_unref(GaimTclRefStatus); gaim_stringref_unref(GaimTclRefStatusAttr);
--- a/plugins/tcl/tcl_cmds.c Sat Jun 10 19:03:24 2006 +0000 +++ b/plugins/tcl/tcl_cmds.c Sat Jun 10 19:16:58 2006 +0000 @@ -37,7 +37,7 @@ 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 GaimConnection *tcl_validate_gc(Tcl_Obj *obj, Tcl_Interp *interp); static GaimAccount *tcl_validate_account(Tcl_Obj *obj, Tcl_Interp *interp) { @@ -77,14 +77,21 @@ return NULL; } -static gboolean tcl_validate_gc(GaimConnection *gc) +static GaimConnection *tcl_validate_gc(Tcl_Obj *obj, Tcl_Interp *interp) { + GaimConnection *gc; GList *cur; + + gc = gaim_tcl_ref_get(interp, obj, GaimTclRefConnection); + + if (gc == NULL) + return NULL; + for (cur = gaim_connections_get_all(); cur != NULL; cur = g_list_next(cur)) { if (gc == cur->data) - return TRUE; + return gc; } - return FALSE; + return NULL; } int tcl_cmd_account(ClientData unused, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) @@ -148,7 +155,9 @@ return TCL_ERROR; if (!gaim_account_is_connected(account)) gaim_account_connect(account); - Tcl_SetIntObj(result, (int)gaim_account_get_connection(account)); + Tcl_SetObjResult(interp, + gaim_tcl_ref_new(GaimTclRefConnection, + gaim_account_get_connection(account))); break; case CMD_ACCOUNT_CONNECTION: if (objc != 3) { @@ -158,7 +167,9 @@ if ((account = tcl_validate_account(objv[2], interp)) == NULL) return TCL_ERROR; - Tcl_SetIntObj(result, (int)gaim_account_get_connection(account)); + Tcl_SetObjResult(interp, + gaim_tcl_ref_new(GaimTclRefConnection, + gaim_account_get_connection(account))); break; case CMD_ACCOUNT_DISCONNECT: if (objc != 3) { @@ -191,8 +202,10 @@ Tcl_WrongNumArgs(interp, 2, objv, "username protocol"); return TCL_ERROR; } - Tcl_SetIntObj(result, (int)gaim_accounts_find(Tcl_GetString(objv[2]), - Tcl_GetString(objv[3]))); + account = gaim_accounts_find(Tcl_GetString(objv[2]), + Tcl_GetString(objv[3])); + Tcl_SetObjResult(interp, + gaim_tcl_ref_new(GaimTclRefAccount, account)); break; case CMD_ACCOUNT_HANDLE: if (objc != 2) { @@ -490,23 +503,19 @@ Tcl_WrongNumArgs(interp, 2, objv, "gc"); return TCL_ERROR; } - error = Tcl_GetIntFromObj(interp, objv[2], (int *)&gc); - if (error || !tcl_validate_gc(gc)) { - Tcl_SetStringObj(result, "invalid gc", -1); + if ((gc = tcl_validate_gc(objv[2], interp)) == NULL) return TCL_ERROR; - } - Tcl_SetIntObj(result, (int)gaim_connection_get_account(gc)); + Tcl_SetObjResult(interp, + gaim_tcl_ref_new(GaimTclRefAccount, + gaim_connection_get_account(gc))); break; case CMD_CONN_DISPLAYNAME: if (objc != 3) { Tcl_WrongNumArgs(interp, 2, objv, "gc"); return TCL_ERROR; } - error = Tcl_GetIntFromObj(interp, objv[2], (int *)&gc); - if (error || !tcl_validate_gc(gc)) { - Tcl_SetStringObj(result, "invalid gc", -1); + if ((gc = tcl_validate_gc(objv[2], interp)) == NULL) return TCL_ERROR; - } Tcl_SetStringObj(result, (char *)gaim_connection_get_display_name(gc), -1); break; case CMD_CONN_HANDLE: @@ -523,7 +532,7 @@ } list = Tcl_NewListObj(0, NULL); for (cur = gaim_connections_get_all(); cur != NULL; cur = g_list_next(cur)) { - elem = Tcl_NewIntObj((int)cur->data); + elem = gaim_tcl_ref_new(GaimTclRefConnection, cur->data); Tcl_ListObjAppendElement(interp, list, elem); } Tcl_SetObjResult(interp, list); @@ -569,7 +578,7 @@ convo = gaim_find_conversation_with_account(GAIM_CONV_TYPE_ANY, Tcl_GetString(objv[3]), account); - Tcl_SetIntObj(result, (int)convo); + Tcl_SetObjResult(interp, gaim_tcl_ref_new(GaimTclRefConversation, convo)); break; case CMD_CONV_HANDLE: if (objc != 2) { @@ -581,7 +590,7 @@ case CMD_CONV_LIST: list = Tcl_NewListObj(0, NULL); for (cur = gaim_get_conversations(); cur != NULL; cur = g_list_next(cur)) { - elem = Tcl_NewIntObj((int)cur->data); + elem = gaim_tcl_ref_new(GaimTclRefConversation, cur->data); Tcl_ListObjAppendElement(interp, list, elem); } Tcl_SetObjResult(interp, list); @@ -619,7 +628,7 @@ 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); + Tcl_SetObjResult(interp, gaim_tcl_ref_new(GaimTclRefConversation, convo)); break; case CMD_CONV_WRITE: if (objc != 6) { @@ -877,21 +886,14 @@ { GaimConnection *gc; char *who, *text; - int error; - Tcl_Obj *result; if (objc != 4) { Tcl_WrongNumArgs(interp, 1, objv, "gc who text"); return TCL_ERROR; } - if ((error = Tcl_GetIntFromObj(interp, objv[1], (int *)&gc)) != TCL_OK) - return error; - if (!tcl_validate_gc(gc)) { - result = Tcl_GetObjResult(interp); - Tcl_SetStringObj(result, "invalid gc", -1); + if ((gc = tcl_validate_gc(objv[1], interp)) == NULL) return TCL_ERROR; - } who = Tcl_GetString(objv[2]); text = Tcl_GetString(objv[3]);
--- a/plugins/tcl/tcl_gaim.h Sat Jun 10 19:03:24 2006 +0000 +++ b/plugins/tcl/tcl_gaim.h Sat Jun 10 19:16:58 2006 +0000 @@ -49,6 +49,7 @@ /* Capitalized this way because these are "types" */ extern GaimStringref *GaimTclRefAccount; +extern GaimStringref *GaimTclRefConnection; extern GaimStringref *GaimTclRefConversation; extern GaimStringref *GaimTclRefStatus; extern GaimStringref *GaimTclRefStatusAttr;
--- a/plugins/tcl/tcl_signals.c Sat Jun 10 19:03:24 2006 +0000 +++ b/plugins/tcl/tcl_signals.c Sat Jun 10 19:16:58 2006 +0000 @@ -134,6 +134,22 @@ tcl_callbacks = g_list_remove_all(tcl_callbacks, NULL); } +static GaimStringref *ref_type(GaimSubType type) +{ + switch (type) { + case GAIM_SUBTYPE_ACCOUNT: + return GaimTclRefAccount; + case GAIM_SUBTYPE_CONNECTION: + return GaimTclRefConnection; + case GAIM_SUBTYPE_CONVERSATION: + return GaimTclRefConversation; + case GAIM_SUBTYPE_STATUS: + return GaimTclRefStatus; + default: + return NULL; + } +} + static void *tcl_signal_callback(va_list args, struct tcl_signal_handler *handler) { GString *name, *val; @@ -256,12 +272,13 @@ case GAIM_SUBTYPE_UNKNOWN: gaim_debug(GAIM_DEBUG_ERROR, "tcl", "subtype unknown\n"); case GAIM_SUBTYPE_ACCOUNT: + case GAIM_SUBTYPE_CONNECTION: case GAIM_SUBTYPE_CONVERSATION: + case GAIM_SUBTYPE_STATUS: 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 *)); + arg = gaim_tcl_ref_new(ref_type(gaim_value_get_subtype(handler->argtypes[i])), va_arg(args, void *)); break; - case GAIM_SUBTYPE_CONNECTION: case GAIM_SUBTYPE_PLUGIN: case GAIM_SUBTYPE_XFER: /* pointers again */