Sun, 20 May 2007 06:19:49 +0000
merge of 'b98e72d4089afb8a1879e5fe9627cfb132ee88de'
and 'b2836a24d81e7a1bd1d21b3aea8794b094391344'
| 6694 | 1 | /** |
| 2 | * @file tcl.c Gaim Tcl plugin bindings | |
| 3 | * | |
| 4 | * gaim | |
| 5 | * | |
| 6 | * Copyright (C) 2003 Ethan Blanton <eblanton@cs.purdue.edu> | |
| 9943 | 7 | * |
| 6694 | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 | */ | |
| 22 | ||
| 23 | #include "config.h" | |
| 24 | ||
| 25 | #include <tcl.h> | |
| 26 | ||
| 27 | #ifdef HAVE_TK | |
| 28 | #include <tk.h> | |
| 29 | #endif | |
| 30 | ||
| 31 | #include <stdio.h> | |
| 32 | #include <sys/types.h> | |
| 33 | #include <sys/stat.h> | |
| 34 | #include <unistd.h> | |
| 35 | #include <string.h> | |
| 36 | ||
| 37 | #include "tcl_glib.h" | |
| 38 | #include "tcl_gaim.h" | |
| 39 | ||
| 40 | #include "internal.h" | |
| 41 | #include "connection.h" | |
| 42 | #include "plugin.h" | |
| 43 | #include "signals.h" | |
| 44 | #include "debug.h" | |
| 45 | #include "util.h" | |
| 9943 | 46 | #include "version.h" |
| 6694 | 47 | |
| 48 | struct tcl_plugin_data { | |
| 49 | GaimPlugin *plugin; | |
| 50 | Tcl_Interp *interp; | |
| 51 | }; | |
| 52 | ||
| 13812 | 53 | GaimStringref *GaimTclRefAccount; |
| 13817 | 54 | GaimStringref *GaimTclRefConnection; |
| 13812 | 55 | GaimStringref *GaimTclRefConversation; |
| 13819 | 56 | GaimStringref *GaimTclRefPointer; |
| 14008 | 57 | GaimStringref *GaimTclRefPlugin; |
| 13823 | 58 | GaimStringref *GaimTclRefPresence; |
| 13812 | 59 | GaimStringref *GaimTclRefStatus; |
| 60 | GaimStringref *GaimTclRefStatusAttr; | |
| 61 | GaimStringref *GaimTclRefStatusType; | |
| 14008 | 62 | GaimStringref *GaimTclRefXfer; |
| 13812 | 63 | |
| 6694 | 64 | static GHashTable *tcl_plugins = NULL; |
| 65 | ||
| 66 | GaimPlugin *_tcl_plugin; | |
| 67 | ||
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
68 | static gboolean tcl_loaded = FALSE; |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
69 | |
| 6694 | 70 | GaimPlugin *tcl_interp_get_plugin(Tcl_Interp *interp) |
| 71 | { | |
| 72 | struct tcl_plugin_data *data; | |
| 73 | ||
| 74 | if (tcl_plugins == NULL) | |
| 75 | return NULL; | |
| 76 | ||
| 77 | data = g_hash_table_lookup(tcl_plugins, (gpointer)interp); | |
| 78 | return data != NULL ? data->plugin : NULL; | |
| 79 | } | |
| 80 | ||
| 81 | static int tcl_init_interp(Tcl_Interp *interp) | |
| 82 | { | |
| 83 | char *rcfile; | |
| 9943 | 84 | char init[] = |
| 6694 | 85 | "namespace eval ::gaim {\n" |
| 86 | " namespace export account buddy connection conversation\n" | |
| 87 | " namespace export core debug notify prefs send_im\n" | |
| 88 | " namespace export signal unload\n" | |
| 89 | " namespace eval _callback { }\n" | |
| 90 | "\n" | |
| 91 | " proc conv_send { account who text } {\n" | |
| 92 | " set gc [gaim::account connection $account]\n" | |
| 93 | " set convo [gaim::conversation new $account $who]\n" | |
| 94 | " set myalias [gaim::account alias $account]\n" | |
| 95 | "\n" | |
| 96 | " if {![string length $myalias]} {\n" | |
| 97 | " set myalias [gaim::account username $account]\n" | |
| 98 | " }\n" | |
| 99 | "\n" | |
| 100 | " gaim::send_im $gc $who $text\n" | |
| 101 | " gaim::conversation write $convo send $myalias $text\n" | |
| 102 | " }\n" | |
| 103 | "}\n" | |
| 104 | "\n" | |
| 105 | "proc bgerror { message } {\n" | |
| 106 | " global errorInfo\n" | |
| 107 | " gaim::notify -error \"Tcl Error\" \"Tcl Error: $message\" \"$errorInfo\"\n" | |
| 108 | "}\n"; | |
| 109 | ||
| 110 | if (Tcl_EvalEx(interp, init, -1, TCL_EVAL_GLOBAL) != TCL_OK) { | |
| 111 | return 1; | |
| 112 | } | |
| 113 | ||
| 114 | Tcl_SetVar(interp, "argc", "0", TCL_GLOBAL_ONLY); | |
| 115 | Tcl_SetVar(interp, "argv0", "gaim", TCL_GLOBAL_ONLY); | |
| 116 | Tcl_SetVar(interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); | |
| 117 | rcfile = g_strdup_printf("%s" G_DIR_SEPARATOR_S "tclrc", gaim_user_dir()); | |
| 118 | Tcl_SetVar(interp, "tcl_rcFileName", rcfile, TCL_GLOBAL_ONLY); | |
| 119 | g_free(rcfile); | |
| 120 | ||
| 121 | Tcl_SetVar(interp, "::gaim::version", VERSION, TCL_GLOBAL_ONLY); | |
| 122 | Tcl_SetVar(interp, "::gaim::user_dir", gaim_user_dir(), TCL_GLOBAL_ONLY); | |
| 123 | #ifdef HAVE_TK | |
| 124 | Tcl_SetVar(interp, "::gaim::tk_available", "1", TCL_GLOBAL_ONLY); | |
| 125 | #else | |
| 126 | Tcl_SetVar(interp, "::gaim::tk_available", "0", TCL_GLOBAL_ONLY); | |
| 127 | #endif /* HAVE_TK */ | |
| 128 | ||
| 129 | Tcl_CreateObjCommand(interp, "::gaim::account", tcl_cmd_account, (ClientData)NULL, NULL); | |
| 130 | Tcl_CreateObjCommand(interp, "::gaim::buddy", tcl_cmd_buddy, (ClientData)NULL, NULL); | |
| 13847 | 131 | Tcl_CreateObjCommand(interp, "::gaim::cmd", tcl_cmd_cmd, (ClientData)NULL, NULL); |
| 6694 | 132 | Tcl_CreateObjCommand(interp, "::gaim::connection", tcl_cmd_connection, (ClientData)NULL, NULL); |
| 133 | Tcl_CreateObjCommand(interp, "::gaim::conversation", tcl_cmd_conversation, (ClientData)NULL, NULL); | |
| 134 | Tcl_CreateObjCommand(interp, "::gaim::core", tcl_cmd_core, (ClientData)NULL, NULL); | |
| 135 | Tcl_CreateObjCommand(interp, "::gaim::debug", tcl_cmd_debug, (ClientData)NULL, NULL); | |
| 136 | Tcl_CreateObjCommand(interp, "::gaim::notify", tcl_cmd_notify, (ClientData)NULL, NULL); | |
| 137 | Tcl_CreateObjCommand(interp, "::gaim::prefs", tcl_cmd_prefs, (ClientData)NULL, NULL); | |
| 13823 | 138 | Tcl_CreateObjCommand(interp, "::gaim::presence", tcl_cmd_presence, (ClientData)NULL, NULL); |
| 6694 | 139 | Tcl_CreateObjCommand(interp, "::gaim::send_im", tcl_cmd_send_im, (ClientData)NULL, NULL); |
| 140 | Tcl_CreateObjCommand(interp, "::gaim::signal", tcl_cmd_signal, (ClientData)NULL, NULL); | |
| 13827 | 141 | Tcl_CreateObjCommand(interp, "::gaim::status", tcl_cmd_status, (ClientData)NULL, NULL); |
| 142 | Tcl_CreateObjCommand(interp, "::gaim::status_attr", tcl_cmd_status_attr, (ClientData)NULL, NULL); | |
| 13812 | 143 | Tcl_CreateObjCommand(interp, "::gaim::status_type", tcl_cmd_status_type, (ClientData)NULL, NULL); |
| 6694 | 144 | Tcl_CreateObjCommand(interp, "::gaim::unload", tcl_cmd_unload, (ClientData)NULL, NULL); |
| 145 | ||
| 146 | return 0; | |
| 147 | } | |
| 148 | ||
| 149 | static Tcl_Interp *tcl_create_interp() | |
| 150 | { | |
| 151 | Tcl_Interp *interp; | |
| 152 | ||
| 153 | interp = Tcl_CreateInterp(); | |
| 154 | if (Tcl_Init(interp) == TCL_ERROR) { | |
| 155 | Tcl_DeleteInterp(interp); | |
| 156 | return NULL; | |
| 157 | } | |
| 158 | ||
| 159 | if (tcl_init_interp(interp)) { | |
| 160 | Tcl_DeleteInterp(interp); | |
| 161 | return NULL; | |
| 162 | } | |
| 163 | Tcl_StaticPackage(interp, "gaim", tcl_init_interp, NULL); | |
| 164 | ||
| 165 | return interp; | |
| 166 | } | |
| 167 | ||
| 168 | static gboolean tcl_probe_plugin(GaimPlugin *plugin) | |
| 169 | { | |
| 170 | GaimPluginInfo *info; | |
| 171 | Tcl_Interp *interp; | |
| 172 | Tcl_Parse parse; | |
| 173 | Tcl_Obj *result, **listitems; | |
| 174 | struct stat st; | |
| 175 | FILE *fp; | |
| 176 | char *buf, *cur; | |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
177 | const char *next; |
| 6694 | 178 | int len, found = 0, err = 0, nelems; |
| 179 | gboolean status = FALSE; | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10454
diff
changeset
|
180 | if ((fp = g_fopen(plugin->path, "r")) == NULL) |
| 6694 | 181 | return FALSE; |
| 182 | if (fstat(fileno(fp), &st)) { | |
| 183 | fclose(fp); | |
| 184 | return FALSE; | |
| 185 | } | |
| 186 | len = st.st_size; | |
| 187 | ||
| 188 | buf = g_malloc(len + 1); | |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
189 | |
|
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
190 | cur = buf; |
| 14008 | 191 | while (fgets(cur, GPOINTER_TO_INT(buf) - (buf - cur), fp)) { |
| 8989 | 192 | cur += strlen(cur); |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
193 | if (feof(fp)) |
| 8989 | 194 | break; |
| 195 | } | |
| 196 | ||
| 197 | if (ferror(fp)) { | |
| 198 | gaim_debug(GAIM_DEBUG_ERROR, "tcl", "error reading %s (%s)\n", plugin->path, strerror(errno)); | |
| 6694 | 199 | g_free(buf); |
| 200 | fclose(fp); | |
| 201 | return FALSE; | |
| 202 | } | |
| 8989 | 203 | |
| 6694 | 204 | fclose(fp); |
| 205 | ||
| 206 | if ((interp = tcl_create_interp()) == NULL) { | |
| 207 | return FALSE; | |
| 208 | } | |
| 209 | ||
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
210 | next = buf; |
| 6694 | 211 | do { |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
212 | if (Tcl_ParseCommand(interp, next, len, 0, &parse) == TCL_ERROR) { |
| 6694 | 213 | gaim_debug(GAIM_DEBUG_ERROR, "tcl", "parse error in %s: %s\n", plugin->path, |
| 214 | Tcl_GetString(Tcl_GetObjResult(interp))); | |
| 215 | err = 1; | |
| 216 | break; | |
| 217 | } | |
| 218 | if (parse.tokenPtr[0].type == TCL_TOKEN_SIMPLE_WORD | |
| 219 | && !strncmp(parse.tokenPtr[0].start, "proc", parse.tokenPtr[0].size)) { | |
| 220 | if (!strncmp(parse.tokenPtr[2].start, "plugin_init", parse.tokenPtr[2].size)) { | |
| 221 | if (Tcl_EvalEx(interp, parse.commandStart, parse.commandSize, TCL_EVAL_GLOBAL) != TCL_OK) { | |
| 222 | Tcl_FreeParse(&parse); | |
| 223 | break; | |
| 224 | } | |
| 225 | found = 1; | |
| 226 | /* We'll continue parsing the file, just in case */ | |
| 227 | } | |
| 228 | } | |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
229 | len -= (parse.commandStart + parse.commandSize) - next; |
|
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
230 | next = parse.commandStart + parse.commandSize; |
| 6694 | 231 | Tcl_FreeParse(&parse); |
| 232 | } while (len); | |
| 233 | ||
| 234 | if (found && !err) { | |
| 235 | if (Tcl_EvalEx(interp, "plugin_init", -1, TCL_EVAL_GLOBAL) == TCL_OK) { | |
| 236 | result = Tcl_GetObjResult(interp); | |
| 237 | if (Tcl_ListObjGetElements(interp, result, &nelems, &listitems) == TCL_OK) { | |
| 12987 | 238 | if ((nelems == 6) || (nelems == 7)) { |
| 6694 | 239 | info = g_new0(GaimPluginInfo, 1); |
|
8761
2d596fd60ba8
[gaim-migrate @ 9516]
Mark Doliner <markdoliner@pidgin.im>
parents:
8759
diff
changeset
|
240 | |
| 9943 | 241 | info->magic = GAIM_PLUGIN_MAGIC; |
| 242 | info->major_version = GAIM_MAJOR_VERSION; | |
| 243 | info->minor_version = GAIM_MINOR_VERSION; | |
| 6694 | 244 | info->type = GAIM_PLUGIN_STANDARD; |
| 245 | info->dependencies = g_list_append(info->dependencies, "core-tcl"); | |
|
8761
2d596fd60ba8
[gaim-migrate @ 9516]
Mark Doliner <markdoliner@pidgin.im>
parents:
8759
diff
changeset
|
246 | |
| 6694 | 247 | info->name = g_strdup(Tcl_GetString(listitems[0])); |
| 248 | info->version = g_strdup(Tcl_GetString(listitems[1])); | |
| 8117 | 249 | info->summary = g_strdup(Tcl_GetString(listitems[2])); |
|
9775
e3a3555b0621
[gaim-migrate @ 10643]
Daniel Atallah <datallah@pidgin.im>
parents:
8993
diff
changeset
|
250 | info->description = g_strdup(Tcl_GetString(listitems[3])); |
|
10454
48b2b0d6a957
[gaim-migrate @ 11722]
Balwinder S Dheeman <bsd@rubyforge.org>
parents:
10344
diff
changeset
|
251 | info->author = g_strdup(Tcl_GetString(listitems[4])); |
| 8117 | 252 | info->homepage = g_strdup(Tcl_GetString(listitems[5])); |
|
8761
2d596fd60ba8
[gaim-migrate @ 9516]
Mark Doliner <markdoliner@pidgin.im>
parents:
8759
diff
changeset
|
253 | |
| 12987 | 254 | if (nelems == 6) |
| 255 | info->id = g_strdup_printf("tcl-%s", Tcl_GetString(listitems[0])); | |
| 256 | else if (nelems == 7) | |
| 257 | info->id = g_strdup_printf("tcl-%s", Tcl_GetString(listitems[6])); | |
| 258 | ||
| 6694 | 259 | plugin->info = info; |
|
8761
2d596fd60ba8
[gaim-migrate @ 9516]
Mark Doliner <markdoliner@pidgin.im>
parents:
8759
diff
changeset
|
260 | |
| 6694 | 261 | if (gaim_plugin_register(plugin)) |
| 262 | status = TRUE; | |
| 263 | } | |
| 264 | } | |
| 265 | } | |
| 266 | } | |
| 267 | ||
| 268 | Tcl_DeleteInterp(interp); | |
| 269 | g_free(buf); | |
| 270 | return status; | |
| 271 | } | |
| 272 | ||
| 273 | static gboolean tcl_load_plugin(GaimPlugin *plugin) | |
| 274 | { | |
| 275 | struct tcl_plugin_data *data; | |
| 276 | Tcl_Interp *interp; | |
| 277 | Tcl_Obj *result; | |
| 278 | ||
| 279 | plugin->extra = NULL; | |
| 280 | ||
| 281 | if ((interp = tcl_create_interp()) == NULL) { | |
| 282 | gaim_debug(GAIM_DEBUG_ERROR, "tcl", "Could not initialize Tcl interpreter\n"); | |
| 283 | return FALSE; | |
| 284 | } | |
| 285 | ||
| 286 | Tcl_SourceRCFile(interp); | |
| 287 | ||
| 288 | if (Tcl_EvalFile(interp, plugin->path) != TCL_OK) { | |
| 289 | result = Tcl_GetObjResult(interp); | |
| 13847 | 290 | gaim_debug(GAIM_DEBUG_ERROR, "tcl", |
| 291 | "Error evaluating %s: %s\n", plugin->path, | |
| 292 | Tcl_GetString(result)); | |
| 6694 | 293 | Tcl_DeleteInterp(interp); |
| 294 | return FALSE; | |
| 295 | } | |
| 296 | ||
| 297 | Tcl_Preserve((ClientData)interp); | |
| 298 | ||
| 299 | data = g_new0(struct tcl_plugin_data, 1); | |
| 300 | data->plugin = plugin; | |
| 301 | data->interp = interp; | |
| 302 | plugin->extra = data; | |
| 303 | ||
| 304 | g_hash_table_insert(tcl_plugins, (gpointer)interp, (gpointer)data); | |
| 305 | ||
| 306 | return TRUE; | |
| 307 | } | |
| 308 | ||
| 309 | static gboolean tcl_unload_plugin(GaimPlugin *plugin) | |
| 310 | { | |
| 311 | struct tcl_plugin_data *data; | |
| 312 | ||
| 313 | if (plugin == NULL) | |
| 314 | return TRUE; | |
| 315 | ||
| 316 | data = plugin->extra; | |
| 317 | ||
| 318 | if (data != NULL) { | |
|
13439
1ef0c638a216
[gaim-migrate @ 15813]
Richard Laager <rlaager@pidgin.im>
parents:
13199
diff
changeset
|
319 | g_hash_table_remove(tcl_plugins, (gpointer)(data->interp)); |
| 6694 | 320 | gaim_signals_disconnect_by_handle(data->interp); |
| 13847 | 321 | tcl_cmd_cleanup(data->interp); |
| 6694 | 322 | tcl_signal_cleanup(data->interp); |
| 323 | Tcl_Release((ClientData)data->interp); | |
| 324 | Tcl_DeleteInterp(data->interp); | |
| 325 | g_free(data); | |
| 326 | } | |
| 327 | ||
| 328 | return TRUE; | |
| 329 | } | |
| 330 | ||
| 331 | static void tcl_destroy_plugin(GaimPlugin *plugin) | |
| 332 | { | |
| 333 | if (plugin->info != NULL) { | |
| 13199 | 334 | g_free(plugin->info->id); |
| 6694 | 335 | g_free(plugin->info->name); |
| 336 | g_free(plugin->info->version); | |
| 337 | g_free(plugin->info->description); | |
| 338 | g_free(plugin->info->author); | |
| 339 | g_free(plugin->info->homepage); | |
| 340 | } | |
| 341 | ||
| 342 | return; | |
| 343 | } | |
| 344 | ||
| 345 | static gboolean tcl_load(GaimPlugin *plugin) | |
| 346 | { | |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
347 | if(!tcl_loaded) |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
348 | return FALSE; |
| 6694 | 349 | tcl_glib_init(); |
| 13847 | 350 | tcl_cmd_init(); |
| 6694 | 351 | tcl_signal_init(); |
| 13812 | 352 | gaim_tcl_ref_init(); |
| 353 | ||
| 354 | GaimTclRefAccount = gaim_stringref_new("Account"); | |
| 13817 | 355 | GaimTclRefConnection = gaim_stringref_new("Connection"); |
| 13812 | 356 | GaimTclRefConversation = gaim_stringref_new("Conversation"); |
| 13819 | 357 | GaimTclRefPointer = gaim_stringref_new("Pointer"); |
| 14008 | 358 | GaimTclRefPlugin = gaim_stringref_new("Plugin"); |
| 13823 | 359 | GaimTclRefPresence = gaim_stringref_new("Presence"); |
| 13812 | 360 | GaimTclRefStatus = gaim_stringref_new("Status"); |
| 361 | GaimTclRefStatusAttr = gaim_stringref_new("StatusAttr"); | |
| 362 | GaimTclRefStatusType = gaim_stringref_new("StatusType"); | |
| 14008 | 363 | GaimTclRefXfer = gaim_stringref_new("Xfer"); |
| 13812 | 364 | |
| 6694 | 365 | tcl_plugins = g_hash_table_new(g_direct_hash, g_direct_equal); |
| 366 | ||
| 7828 | 367 | #ifdef HAVE_TK |
| 368 | Tcl_StaticPackage(NULL, "Tk", Tk_Init, Tk_SafeInit); | |
| 369 | #endif /* HAVE_TK */ | |
| 370 | ||
| 6694 | 371 | return TRUE; |
| 372 | } | |
| 373 | ||
| 374 | static gboolean tcl_unload(GaimPlugin *plugin) | |
| 375 | { | |
| 376 | g_hash_table_destroy(tcl_plugins); | |
| 377 | tcl_plugins = NULL; | |
| 378 | ||
| 13812 | 379 | gaim_stringref_unref(GaimTclRefAccount); |
| 13817 | 380 | gaim_stringref_unref(GaimTclRefConnection); |
| 13812 | 381 | gaim_stringref_unref(GaimTclRefConversation); |
| 13819 | 382 | gaim_stringref_unref(GaimTclRefPointer); |
|
14016
2d2e0f347601
[gaim-migrate @ 16502]
Mark Doliner <markdoliner@pidgin.im>
parents:
14008
diff
changeset
|
383 | gaim_stringref_unref(GaimTclRefPlugin); |
| 13823 | 384 | gaim_stringref_unref(GaimTclRefPresence); |
| 13812 | 385 | gaim_stringref_unref(GaimTclRefStatus); |
| 386 | gaim_stringref_unref(GaimTclRefStatusAttr); | |
| 387 | gaim_stringref_unref(GaimTclRefStatusType); | |
|
14016
2d2e0f347601
[gaim-migrate @ 16502]
Mark Doliner <markdoliner@pidgin.im>
parents:
14008
diff
changeset
|
388 | gaim_stringref_unref(GaimTclRefXfer); |
| 13812 | 389 | |
| 6694 | 390 | return TRUE; |
| 391 | } | |
| 392 | ||
| 393 | static GaimPluginLoaderInfo tcl_loader_info = | |
| 394 | { | |
| 395 | NULL, | |
| 396 | tcl_probe_plugin, | |
| 397 | tcl_load_plugin, | |
| 398 | tcl_unload_plugin, | |
| 399 | tcl_destroy_plugin, | |
| 400 | }; | |
| 401 | ||
| 402 | static GaimPluginInfo tcl_info = | |
| 403 | { | |
| 9943 | 404 | GAIM_PLUGIN_MAGIC, |
| 405 | GAIM_MAJOR_VERSION, | |
| 406 | GAIM_MINOR_VERSION, | |
| 6694 | 407 | GAIM_PLUGIN_LOADER, |
| 408 | NULL, | |
| 409 | 0, | |
| 410 | NULL, | |
| 411 | GAIM_PRIORITY_DEFAULT, | |
| 412 | "core-tcl", | |
| 413 | N_("Tcl Plugin Loader"), | |
| 414 | VERSION, | |
| 415 | N_("Provides support for loading Tcl plugins"), | |
| 416 | N_("Provides support for loading Tcl plugins"), | |
| 417 | "Ethan Blanton <eblanton@cs.purdue.edu>", | |
| 418 | GAIM_WEBSITE, | |
| 419 | tcl_load, | |
| 420 | tcl_unload, | |
| 421 | NULL, | |
| 422 | NULL, | |
| 8993 | 423 | &tcl_loader_info, |
| 424 | NULL, | |
| 425 | NULL | |
| 6694 | 426 | }; |
| 427 | ||
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
428 | #ifdef _WIN32 |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
429 | typedef Tcl_Interp* (CALLBACK* LPFNTCLCREATEINTERP)(void); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
430 | typedef void (CALLBACK* LPFNTKINIT)(Tcl_Interp*); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
431 | |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
432 | LPFNTCLCREATEINTERP wtcl_CreateInterp = NULL; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
433 | LPFNTKINIT wtk_Init = NULL; |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
434 | #undef Tcl_CreateInterp |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
435 | #define Tcl_CreateInterp wtcl_CreateInterp |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
436 | #undef Tk_Init |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
437 | #define Tk_Init wtk_Init |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
438 | |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
439 | static gboolean tcl_win32_init() { |
| 14913 | 440 | const char regkey[] = "SOFTWARE\\ActiveState\\ActiveTcl\\"; |
| 441 | char *version = NULL; | |
| 442 | gboolean retval = FALSE; | |
| 443 | ||
| 444 | if ((version = wgaim_read_reg_string(HKEY_LOCAL_MACHINE, regkey, "CurrentVersion")) | |
| 445 | || (version = wgaim_read_reg_string(HKEY_CURRENT_USER, regkey, "CurrentVersion"))) { | |
| 446 | char *path; | |
| 447 | char *regkey2; | |
| 448 | ||
| 449 | regkey2 = g_strdup_printf("%s%s\\", regkey, version); | |
| 450 | if ((path = wgaim_read_reg_string(HKEY_LOCAL_MACHINE, regkey2, NULL)) || (path = wgaim_read_reg_string(HKEY_CURRENT_USER, regkey2, NULL))) { | |
| 451 | char *tclpath; | |
| 452 | char *tkpath; | |
| 453 | ||
| 454 | gaim_debug(GAIM_DEBUG_INFO, "tcl", "Loading ActiveTCL version %s from \"%s\"\n", version, path); | |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
455 | |
| 14913 | 456 | tclpath = g_build_filename(path, "bin", "tcl84.dll", NULL); |
| 457 | tkpath = g_build_filename(path, "bin", "tk84.dll", NULL); | |
| 458 | ||
| 459 | if(!(wtcl_CreateInterp = (LPFNTCLCREATEINTERP) wgaim_find_and_loadproc(tclpath, "Tcl_CreateInterp"))) { | |
| 460 | gaim_debug(GAIM_DEBUG_INFO, "tcl", "tcl_win32_init error loading Tcl_CreateInterp\n"); | |
| 461 | } else { | |
| 462 | if(!(wtk_Init = (LPFNTKINIT) wgaim_find_and_loadproc(tkpath, "Tk_Init"))) { | |
| 463 | HMODULE mod; | |
| 464 | gaim_debug(GAIM_DEBUG_INFO, "tcl", "tcl_win32_init error loading Tk_Init\n"); | |
| 465 | if((mod = GetModuleHandle("tcl84.dll"))) | |
| 466 | FreeLibrary(mod); | |
| 467 | } else { | |
| 468 | retval = TRUE; | |
| 469 | } | |
| 470 | } | |
| 471 | g_free(tclpath); | |
| 472 | g_free(tkpath); | |
| 473 | } | |
| 474 | g_free(path); | |
| 475 | g_free(regkey2); | |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
476 | } |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
477 | |
| 14913 | 478 | g_free(version); |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
479 | |
| 14913 | 480 | if (!retval) |
| 481 | gaim_debug(GAIM_DEBUG_INFO, "tcl", _("Unable to detect ActiveTCL installation. If you wish to use TCL plugins, install ActiveTCL from http://www.activestate.com\n")); | |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
482 | |
| 14913 | 483 | return retval; |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
484 | } |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
485 | |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
486 | #endif /* _WIN32 */ |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
487 | |
| 6694 | 488 | static void tcl_init_plugin(GaimPlugin *plugin) |
| 489 | { | |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
490 | #ifdef USE_TCL_STUBS |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
491 | Tcl_Interp *interp = NULL; |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
492 | #endif |
| 6694 | 493 | _tcl_plugin = plugin; |
| 494 | ||
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
495 | #ifdef USE_TCL_STUBS |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
496 | #ifdef _WIN32 |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
497 | if(!tcl_win32_init()) |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
498 | return; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
499 | #endif |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
500 | if(!(interp = Tcl_CreateInterp())) |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
501 | return; |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
502 | |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
503 | if(!Tcl_InitStubs(interp, TCL_VERSION, 0)) { |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
504 | gaim_debug(GAIM_DEBUG_ERROR, "tcl", "Tcl_InitStubs: %s\n", interp->result); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
505 | return; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
506 | } |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
507 | #endif |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
508 | |
| 6694 | 509 | Tcl_FindExecutable("gaim"); |
| 510 | ||
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
511 | #if defined(USE_TK_STUBS) && defined(HAVE_TK) |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
512 | Tk_Init(interp); |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
513 | |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
514 | if(!Tk_InitStubs(interp, TK_VERSION, 0)) { |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
515 | gaim_debug(GAIM_DEBUG_ERROR, "tcl", "Error Tk_InitStubs: %s\n", interp->result); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
516 | Tcl_DeleteInterp(interp); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
517 | return; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
518 | } |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
519 | #endif |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
520 | tcl_loaded = TRUE; |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
521 | #ifdef USE_TCL_STUBS |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
522 | Tcl_DeleteInterp(interp); |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
523 | #endif |
| 6694 | 524 | tcl_loader_info.exts = g_list_append(tcl_loader_info.exts, "tcl"); |
| 525 | } | |
| 526 | ||
|
6735
a8c70aeddbe7
[gaim-migrate @ 7267]
Mark Doliner <markdoliner@pidgin.im>
parents:
6694
diff
changeset
|
527 | GAIM_INIT_PLUGIN(tcl, tcl_init_plugin, tcl_info) |