annotate plugins/tcl/tcl_signals.c @ 11848:434181b96f44

[gaim-migrate @ 14139] Peter Lawler decided it'd be nice if the gtk signals test plugin built... committer: Tailor Script <tailor@pidgin.im>
author Gary Kramlich <grim@reaperworld.com>
date Thu, 27 Oct 2005 04:56:33 +0000
parents 9eb235c6dc0a
children 8d1cf3f847b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
1 /**
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
2 * @file tcl_signals.c Gaim Tcl signal API
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
3 *
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
4 * gaim
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
5 *
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
6 * Copyright (C) 2003 Ethan Blanton <eblanton@cs.purdue.edu>
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
7 *
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
11 * (at your option) any later version.
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
12 *
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
16 * GNU General Public License for more details.
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
17 *
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
21 */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
22 #include <tcl.h>
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
23 #include <stdarg.h>
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
24
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
25 #include "tcl_gaim.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
26
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
27 #include "internal.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
28 #include "connection.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
29 #include "conversation.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
30 #include "signals.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
31 #include "debug.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
32 #include "value.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
33 #include "core.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
34
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
35 static GList *tcl_callbacks;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
36
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
37 static void *tcl_signal_callback(va_list args, struct tcl_signal_handler *handler);
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
38 static Tcl_Obj *new_cb_namespace ();
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
39
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
40 void tcl_signal_init()
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
41 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
42 tcl_callbacks = NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
43 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
44
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
45 void tcl_signal_handler_free(struct tcl_signal_handler *handler)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
46 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
47 if (handler == NULL)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
48 return;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
49
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
50 Tcl_DecrRefCount(handler->signal);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
51 Tcl_DecrRefCount(handler->namespace);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
52 g_free(handler);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
53 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
54
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
55 void tcl_signal_cleanup(Tcl_Interp *interp)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
56 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
57 GList *cur;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
58 struct tcl_signal_handler *handler;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
59
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
60 for (cur = tcl_callbacks; cur != NULL; cur = g_list_next(cur)) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
61 handler = cur->data;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
62 if (handler->interp == interp) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
63 tcl_signal_handler_free(handler);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
64 cur->data = NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
65 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
66 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
67 tcl_callbacks = g_list_remove_all(tcl_callbacks, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
68 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
69
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
70 gboolean tcl_signal_connect(struct tcl_signal_handler *handler)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
71 {
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
72 GString *proc;
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
73
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
74 gaim_signal_get_values(handler->instance,
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
75 Tcl_GetString(handler->signal),
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
76 &handler->returntype, &handler->nargs,
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
77 &handler->argtypes);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
78
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
79 tcl_signal_disconnect(handler->interp, Tcl_GetString(handler->signal),
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
80 handler->interp);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
81
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
82 if (!gaim_signal_connect_vargs(handler->instance,
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
83 Tcl_GetString(handler->signal),
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
84 (void *)handler->interp,
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
85 GAIM_CALLBACK(tcl_signal_callback),
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
86 (void *)handler))
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
87 return FALSE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
88
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
89 Tcl_IncrRefCount(handler->signal);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
90 handler->namespace = new_cb_namespace ();
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
91 Tcl_IncrRefCount(handler->namespace);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
92 proc = g_string_new("");
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
93 g_string_append_printf(proc, "namespace eval %s { proc cb { %s } { %s } }",
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
94 Tcl_GetString(handler->namespace),
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
95 Tcl_GetString(handler->args),
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
96 Tcl_GetString(handler->proc));
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
97 if (Tcl_Eval(handler->interp, proc->str) != TCL_OK) {
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
98 Tcl_DecrRefCount(handler->namespace);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
99 g_string_free(proc, TRUE);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
100 return FALSE;
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
101 }
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
102 g_string_free(proc, TRUE);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
103
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
104 tcl_callbacks = g_list_append(tcl_callbacks, (gpointer)handler);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
105
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
106 return TRUE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
107 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
108
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
109 void tcl_signal_disconnect(void *instance, const char *signal, Tcl_Interp *interp)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
110 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
111 GList *cur;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
112 struct tcl_signal_handler *handler;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
113 gboolean found = FALSE;
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
114 GString *cmd;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
115
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
116 for (cur = tcl_callbacks; cur != NULL; cur = g_list_next(cur)) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
117 handler = cur->data;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
118 if (handler->interp == interp && handler->instance == instance
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
119 && !strcmp(signal, Tcl_GetString(handler->signal))) {
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
120 gaim_signal_disconnect(instance, signal, handler->interp,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
121 GAIM_CALLBACK(tcl_signal_callback));
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
122 cmd = g_string_sized_new(64);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
123 g_string_printf(cmd, "namespace delete %s",
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
124 Tcl_GetString(handler->namespace));
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
125 Tcl_EvalEx(interp, cmd->str, -1, TCL_EVAL_GLOBAL);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
126 tcl_signal_handler_free(handler);
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
127 g_string_free(cmd, TRUE);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
128 cur->data = NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
129 found = TRUE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
130 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
131 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
132 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
133 if (found)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
134 tcl_callbacks = g_list_remove_all(tcl_callbacks, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
135 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
136
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
137 static void *tcl_signal_callback(va_list args, struct tcl_signal_handler *handler)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
138 {
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
139 GString *name, *val;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
140 GaimBlistNode *node;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
141 int error, i;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
142 void *retval = NULL;
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
143 Tcl_Obj *cmd, *arg, *result;
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
144 void **vals; /* Used for inout parameters */
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
145 char ***strs;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
146
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
147 vals = g_new0(void *, handler->nargs);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
148 strs = g_new0(char **, handler->nargs);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
149 name = g_string_sized_new(32);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
150 val = g_string_sized_new(32);
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
151
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
152 cmd = Tcl_NewListObj(0, NULL);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
153 Tcl_IncrRefCount(cmd);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
154
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
155 arg = Tcl_DuplicateObj(handler->namespace);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
156 Tcl_AppendStringsToObj(arg, "::cb", NULL);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
157 Tcl_ListObjAppendElement(handler->interp, cmd, arg);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
158
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
159 for (i = 0; i < handler->nargs; i++) {
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
160 if (gaim_value_is_outgoing(handler->argtypes[i]))
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
161 g_string_printf(name, "%s::arg%d",
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
162 Tcl_GetString(handler->namespace), i);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
163
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
164 switch(gaim_value_get_type(handler->argtypes[i])) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
165 case GAIM_TYPE_UNKNOWN: /* What? I guess just pass the word ... */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
166 /* treat this as a pointer, but complain first */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
167 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "unknown GaimValue type %d\n",
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
168 gaim_value_get_type(handler->argtypes[i]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
169 case GAIM_TYPE_POINTER:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
170 case GAIM_TYPE_OBJECT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
171 case GAIM_TYPE_BOXED:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
172 /* These are all "pointer" types to us */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
173 if (gaim_value_is_outgoing(handler->argtypes[i])) {
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
174 vals[i] = va_arg(args, void **);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
175 Tcl_LinkVar(handler->interp, name->str,
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
176 vals[i], TCL_LINK_INT);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
177 arg = Tcl_NewStringObj(name->str, -1);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
178 } else {
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
179 arg = Tcl_NewIntObj((int)va_arg(args, void *));
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
180 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
181 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
182 case GAIM_TYPE_BOOLEAN:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
183 if (gaim_value_is_outgoing(handler->argtypes[i])) {
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
184 vals[i] = va_arg(args, gboolean *);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
185 Tcl_LinkVar(handler->interp, name->str,
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
186 (char *)&vals[i], TCL_LINK_BOOLEAN);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
187 arg = Tcl_NewStringObj(name->str, -1);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
188 } else {
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
189 arg = Tcl_NewBooleanObj(va_arg(args, gboolean));
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
190 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
191 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
192 case GAIM_TYPE_CHAR:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
193 case GAIM_TYPE_UCHAR:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
194 case GAIM_TYPE_SHORT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
195 case GAIM_TYPE_USHORT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
196 case GAIM_TYPE_INT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
197 case GAIM_TYPE_UINT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
198 case GAIM_TYPE_LONG:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
199 case GAIM_TYPE_ULONG:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
200 case GAIM_TYPE_ENUM:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
201 /* I should really cast these individually to
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
202 * preserve as much information as possible ...
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
203 * but heh */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
204 if (gaim_value_is_outgoing(handler->argtypes[i])) {
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
205 vals[i] = va_arg(args, int *);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
206 Tcl_LinkVar(handler->interp, name->str,
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
207 vals[i], TCL_LINK_INT);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
208 arg = Tcl_NewStringObj(name->str, -1);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
209 } else {
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
210 arg = Tcl_NewIntObj(va_arg(args, int));
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
211 }
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
212 case GAIM_TYPE_INT64:
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
213 case GAIM_TYPE_UINT64:
10625
9eb235c6dc0a [gaim-migrate @ 12099]
Ethan Blanton <elb@pidgin.im>
parents: 10597
diff changeset
214 /* Tcl < 8.4 doesn't have wide ints, so we have ugly
9eb235c6dc0a [gaim-migrate @ 12099]
Ethan Blanton <elb@pidgin.im>
parents: 10597
diff changeset
215 * ifdefs in here */
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
216 if (gaim_value_is_outgoing(handler->argtypes[i])) {
10625
9eb235c6dc0a [gaim-migrate @ 12099]
Ethan Blanton <elb@pidgin.im>
parents: 10597
diff changeset
217 vals[i] = (void *)va_arg(args, gint64 *);
9eb235c6dc0a [gaim-migrate @ 12099]
Ethan Blanton <elb@pidgin.im>
parents: 10597
diff changeset
218 #if (TCL_MAJOR_VERSION >= 8 && TCL_MINOR_VERSION >= 4)
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
219 Tcl_LinkVar(handler->interp, name->str,
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
220 vals[i], TCL_LINK_WIDE_INT);
10625
9eb235c6dc0a [gaim-migrate @ 12099]
Ethan Blanton <elb@pidgin.im>
parents: 10597
diff changeset
221 #else
9eb235c6dc0a [gaim-migrate @ 12099]
Ethan Blanton <elb@pidgin.im>
parents: 10597
diff changeset
222 /* This is going to cause weirdness at best,
9eb235c6dc0a [gaim-migrate @ 12099]
Ethan Blanton <elb@pidgin.im>
parents: 10597
diff changeset
223 * but what do you want ... we're losing
9eb235c6dc0a [gaim-migrate @ 12099]
Ethan Blanton <elb@pidgin.im>
parents: 10597
diff changeset
224 * precision */
9eb235c6dc0a [gaim-migrate @ 12099]
Ethan Blanton <elb@pidgin.im>
parents: 10597
diff changeset
225 Tcl_LinkVar(handler->interp, name->str,
9eb235c6dc0a [gaim-migrate @ 12099]
Ethan Blanton <elb@pidgin.im>
parents: 10597
diff changeset
226 vals[i], TCL_LINK_INT);
9eb235c6dc0a [gaim-migrate @ 12099]
Ethan Blanton <elb@pidgin.im>
parents: 10597
diff changeset
227 #endif /* Tcl >= 8.4 */
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
228 arg = Tcl_NewStringObj(name->str, -1);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
229 } else {
10625
9eb235c6dc0a [gaim-migrate @ 12099]
Ethan Blanton <elb@pidgin.im>
parents: 10597
diff changeset
230 #if (TCL_MAJOR_VERSION >= 8 && TCL_MINOR_VERSION >= 4)
9eb235c6dc0a [gaim-migrate @ 12099]
Ethan Blanton <elb@pidgin.im>
parents: 10597
diff changeset
231 arg = Tcl_NewWideIntObj(va_arg(args, gint64));
9eb235c6dc0a [gaim-migrate @ 12099]
Ethan Blanton <elb@pidgin.im>
parents: 10597
diff changeset
232 #else
9eb235c6dc0a [gaim-migrate @ 12099]
Ethan Blanton <elb@pidgin.im>
parents: 10597
diff changeset
233 arg = Tcl_NewIntObj((int)va_arg(args, int));
9eb235c6dc0a [gaim-migrate @ 12099]
Ethan Blanton <elb@pidgin.im>
parents: 10597
diff changeset
234 #endif /* Tcl >= 8.4 */
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
235 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
236 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
237 case GAIM_TYPE_STRING:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
238 if (gaim_value_is_outgoing(handler->argtypes[i])) {
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
239 strs[i] = va_arg(args, char **);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
240 if (strs[i] == NULL || *strs[i] == NULL) {
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
241 vals[i] = ckalloc(1);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
242 *(char *)vals[i] = '\0';
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
243 } else {
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
244 vals[i] = ckalloc(strlen(*strs[i]) + 1);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
245 strcpy(vals[i], *strs[i]);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
246 }
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
247 Tcl_LinkVar(handler->interp, name->str,
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
248 (char *)&vals[i], TCL_LINK_STRING);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
249 arg = Tcl_NewStringObj(name->str, -1);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
250 } else {
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
251 arg = Tcl_NewStringObj(va_arg(args, char *), -1);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
252 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
253 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
254 case GAIM_TYPE_SUBTYPE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
255 switch (gaim_value_get_subtype(handler->argtypes[i])) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
256 case GAIM_SUBTYPE_UNKNOWN:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
257 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "subtype unknown\n");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
258 case GAIM_SUBTYPE_ACCOUNT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
259 case GAIM_SUBTYPE_CONNECTION:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
260 case GAIM_SUBTYPE_CONVERSATION:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
261 case GAIM_SUBTYPE_CONV_WINDOW:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
262 case GAIM_SUBTYPE_PLUGIN:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
263 /* pointers again */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
264 if (gaim_value_is_outgoing(handler->argtypes[i])) {
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
265 vals[i] = va_arg(args, void **);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
266 Tcl_LinkVar(handler->interp, name->str,
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
267 vals[i], TCL_LINK_INT);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
268 arg = Tcl_NewStringObj(name->str, -1);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
269 } else {
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
270 arg = Tcl_NewIntObj((int)va_arg(args, void *));
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
271 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
272 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
273 case GAIM_SUBTYPE_BLIST:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
274 case GAIM_SUBTYPE_BLIST_BUDDY:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
275 case GAIM_SUBTYPE_BLIST_GROUP:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
276 case GAIM_SUBTYPE_BLIST_CHAT:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
277 /* We're going to switch again for code-deduping */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
278 if (gaim_value_is_outgoing(handler->argtypes[i]))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
279 node = *va_arg(args, GaimBlistNode **);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
280 else
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
281 node = va_arg(args, GaimBlistNode *);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
282 switch (node->type) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
283 case GAIM_BLIST_GROUP_NODE:
6700
57161e3abbb5 [gaim-migrate @ 7226]
Ethan Blanton <elb@pidgin.im>
parents: 6694
diff changeset
284 g_string_printf(val, "group {%s}", ((GaimGroup *)node)->name);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
285 break;
6735
b0913ab92893 [gaim-migrate @ 7267]
Mark Doliner <mark@kingant.net>
parents: 6700
diff changeset
286 case GAIM_BLIST_CONTACT_NODE:
b0913ab92893 [gaim-migrate @ 7267]
Mark Doliner <mark@kingant.net>
parents: 6700
diff changeset
287 /* g_string_printf(val, "contact {%s}", Contact Name? ); */
b0913ab92893 [gaim-migrate @ 7267]
Mark Doliner <mark@kingant.net>
parents: 6700
diff changeset
288 break;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
289 case GAIM_BLIST_BUDDY_NODE:
6700
57161e3abbb5 [gaim-migrate @ 7226]
Ethan Blanton <elb@pidgin.im>
parents: 6694
diff changeset
290 g_string_printf(val, "buddy {%s} %lu", ((GaimBuddy *)node)->name,
57161e3abbb5 [gaim-migrate @ 7226]
Ethan Blanton <elb@pidgin.im>
parents: 6694
diff changeset
291 (unsigned long)((GaimBuddy *)node)->account);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
292 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
293 case GAIM_BLIST_CHAT_NODE:
7118
bf630f7dfdcd [gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
294 g_string_printf(val, "chat {%s} %lu", ((GaimChat *)node)->alias,
bf630f7dfdcd [gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents: 6735
diff changeset
295 (unsigned long)((GaimChat *)node)->account);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
296 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
297 case GAIM_BLIST_OTHER_NODE:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
298 g_string_printf(val, "other");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
299 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
300 }
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
301 arg = Tcl_NewStringObj(val->str, -1);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
302 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
303 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
304 }
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
305 Tcl_ListObjAppendElement(handler->interp, cmd, arg);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
306 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
307
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
308 /* Call the friggin' procedure already */
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
309 if ((error = Tcl_EvalObjEx(handler->interp, cmd, TCL_EVAL_GLOBAL)) != TCL_OK) {
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
310 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "error evaluating callback: %s\n",
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
311 Tcl_GetString(Tcl_GetObjResult(handler->interp)));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
312 } else {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
313 result = Tcl_GetObjResult(handler->interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
314 /* handle return values -- strings and words only */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
315 if (handler->returntype) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
316 if (gaim_value_get_type(handler->returntype) == GAIM_TYPE_STRING) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
317 retval = (void *)g_strdup(Tcl_GetString(result));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
318 } else {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
319 if ((error = Tcl_GetIntFromObj(handler->interp, result, (int *)&retval)) != TCL_OK) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
320 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "Error retrieving procedure result: %s\n",
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
321 Tcl_GetString(Tcl_GetObjResult(handler->interp)));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
322 retval = NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
323 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
324 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
325 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
326 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
327
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
328 /* And finally clean up */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
329 for (i = 0; i < handler->nargs; i++) {
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
330 g_string_printf(name, "%s::arg%d",
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
331 Tcl_GetString(handler->namespace), i);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
332 if (gaim_value_is_outgoing(handler->argtypes[i]))
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
333 Tcl_UnlinkVar(handler->interp, name->str);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
334 /* We basically only have to deal with strings on the
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
335 * way out */
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
336 switch (gaim_value_get_type(handler->argtypes[i])) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
337 case GAIM_TYPE_STRING:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
338 if (gaim_value_is_outgoing(handler->argtypes[i])) {
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
339 if (vals[i] != NULL && *(char **)vals[i] != NULL) {
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
340 g_free(*strs[i]);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
341 *strs[i] = g_strdup(vals[i]);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
342 }
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
343 ckfree(vals[i]);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
344 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
345 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
346 default:
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
347 /* nothing */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
348 ;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
349 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
350 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
351
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
352 g_string_free(name, TRUE);
10504
1a97d5e88d12 [gaim-migrate @ 11796]
Stu Tomlinson <stu@nosnilmot.com>
parents: 7118
diff changeset
353 g_string_free(val, TRUE);
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
354 g_free(vals);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
355 g_free(strs);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
356
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
357
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
358 return retval;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
359 }
10597
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
360
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
361 static Tcl_Obj *new_cb_namespace ()
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
362 {
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
363 static int cbnum;
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
364 char name[32];
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
365
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
366 g_snprintf (name, sizeof(name), "::gaim::_callback::cb_%d", cbnum++);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
367 return Tcl_NewStringObj (name, -1);
0e886a234d92 [gaim-migrate @ 12012]
Ethan Blanton <elb@pidgin.im>
parents: 10519
diff changeset
368 }