Tue, 24 Apr 2007 02:51:53 +0000
<elb> nosnilmot: those magic numbers should probably have been fixed to not
be so magic ;-)
This should help us for the next time we need to rename.
| 6694 | 1 | /** |
| 15884 | 2 | * @file tcl.c Purple Tcl plugin bindings |
| 6694 | 3 | * |
| 15884 | 4 | * purple |
| 6694 | 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" | |
| 15884 | 38 | #include "tcl_purple.h" |
| 6694 | 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 { | |
| 15884 | 49 | PurplePlugin *plugin; |
| 6694 | 50 | Tcl_Interp *interp; |
| 51 | }; | |
| 52 | ||
| 15884 | 53 | PurpleStringref *PurpleTclRefAccount; |
| 54 | PurpleStringref *PurpleTclRefConnection; | |
| 55 | PurpleStringref *PurpleTclRefConversation; | |
| 56 | PurpleStringref *PurpleTclRefPointer; | |
| 57 | PurpleStringref *PurpleTclRefPlugin; | |
| 58 | PurpleStringref *PurpleTclRefPresence; | |
| 59 | PurpleStringref *PurpleTclRefStatus; | |
| 60 | PurpleStringref *PurpleTclRefStatusAttr; | |
| 61 | PurpleStringref *PurpleTclRefStatusType; | |
| 62 | PurpleStringref *PurpleTclRefXfer; | |
| 13812 | 63 | |
| 6694 | 64 | static GHashTable *tcl_plugins = NULL; |
| 65 | ||
| 15884 | 66 | PurplePlugin *_tcl_plugin; |
| 6694 | 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 | |
| 15884 | 70 | PurplePlugin *tcl_interp_get_plugin(Tcl_Interp *interp) |
| 6694 | 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[] = |
| 15884 | 85 | "namespace eval ::purple {\n" |
| 6694 | 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" | |
| 15884 | 92 | " set gc [purple::account connection $account]\n" |
| 93 | " set convo [purple::conversation new $account $who]\n" | |
| 94 | " set myalias [purple::account alias $account]\n" | |
| 6694 | 95 | "\n" |
| 96 | " if {![string length $myalias]} {\n" | |
| 15884 | 97 | " set myalias [purple::account username $account]\n" |
| 6694 | 98 | " }\n" |
| 99 | "\n" | |
| 15884 | 100 | " purple::send_im $gc $who $text\n" |
| 101 | " purple::conversation write $convo send $myalias $text\n" | |
| 6694 | 102 | " }\n" |
| 103 | "}\n" | |
| 104 | "\n" | |
| 105 | "proc bgerror { message } {\n" | |
| 106 | " global errorInfo\n" | |
| 15884 | 107 | " purple::notify -error \"Tcl Error\" \"Tcl Error: $message\" \"$errorInfo\"\n" |
| 6694 | 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); | |
| 15884 | 115 | Tcl_SetVar(interp, "argv0", "purple", TCL_GLOBAL_ONLY); |
| 6694 | 116 | Tcl_SetVar(interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); |
| 15884 | 117 | rcfile = g_strdup_printf("%s" G_DIR_SEPARATOR_S "tclrc", purple_user_dir()); |
| 6694 | 118 | Tcl_SetVar(interp, "tcl_rcFileName", rcfile, TCL_GLOBAL_ONLY); |
| 119 | g_free(rcfile); | |
| 120 | ||
| 15884 | 121 | Tcl_SetVar(interp, "::purple::version", VERSION, TCL_GLOBAL_ONLY); |
| 122 | Tcl_SetVar(interp, "::purple::user_dir", purple_user_dir(), TCL_GLOBAL_ONLY); | |
| 6694 | 123 | #ifdef HAVE_TK |
| 15884 | 124 | Tcl_SetVar(interp, "::purple::tk_available", "1", TCL_GLOBAL_ONLY); |
| 6694 | 125 | #else |
| 15884 | 126 | Tcl_SetVar(interp, "::purple::tk_available", "0", TCL_GLOBAL_ONLY); |
| 6694 | 127 | #endif /* HAVE_TK */ |
| 128 | ||
| 15884 | 129 | Tcl_CreateObjCommand(interp, "::purple::account", tcl_cmd_account, (ClientData)NULL, NULL); |
| 130 | Tcl_CreateObjCommand(interp, "::purple::buddy", tcl_cmd_buddy, (ClientData)NULL, NULL); | |
| 131 | Tcl_CreateObjCommand(interp, "::purple::cmd", tcl_cmd_cmd, (ClientData)NULL, NULL); | |
| 132 | Tcl_CreateObjCommand(interp, "::purple::connection", tcl_cmd_connection, (ClientData)NULL, NULL); | |
| 133 | Tcl_CreateObjCommand(interp, "::purple::conversation", tcl_cmd_conversation, (ClientData)NULL, NULL); | |
| 134 | Tcl_CreateObjCommand(interp, "::purple::core", tcl_cmd_core, (ClientData)NULL, NULL); | |
| 135 | Tcl_CreateObjCommand(interp, "::purple::debug", tcl_cmd_debug, (ClientData)NULL, NULL); | |
| 136 | Tcl_CreateObjCommand(interp, "::purple::notify", tcl_cmd_notify, (ClientData)NULL, NULL); | |
| 137 | Tcl_CreateObjCommand(interp, "::purple::plugins", tcl_cmd_plugins, (ClientData)NULL, NULL); | |
| 138 | Tcl_CreateObjCommand(interp, "::purple::prefs", tcl_cmd_prefs, (ClientData)NULL, NULL); | |
| 139 | Tcl_CreateObjCommand(interp, "::purple::presence", tcl_cmd_presence, (ClientData)NULL, NULL); | |
| 140 | Tcl_CreateObjCommand(interp, "::purple::send_im", tcl_cmd_send_im, (ClientData)NULL, NULL); | |
| 141 | Tcl_CreateObjCommand(interp, "::purple::savedstatus", tcl_cmd_savedstatus, (ClientData)NULL, NULL); | |
| 142 | Tcl_CreateObjCommand(interp, "::purple::signal", tcl_cmd_signal, (ClientData)NULL, NULL); | |
| 143 | Tcl_CreateObjCommand(interp, "::purple::status", tcl_cmd_status, (ClientData)NULL, NULL); | |
| 144 | Tcl_CreateObjCommand(interp, "::purple::status_attr", tcl_cmd_status_attr, (ClientData)NULL, NULL); | |
| 145 | Tcl_CreateObjCommand(interp, "::purple::status_type", tcl_cmd_status_type, (ClientData)NULL, NULL); | |
| 146 | Tcl_CreateObjCommand(interp, "::purple::unload", tcl_cmd_unload, (ClientData)NULL, NULL); | |
| 6694 | 147 | |
| 148 | return 0; | |
| 149 | } | |
| 150 | ||
| 151 | static Tcl_Interp *tcl_create_interp() | |
| 152 | { | |
| 153 | Tcl_Interp *interp; | |
| 154 | ||
| 155 | interp = Tcl_CreateInterp(); | |
| 156 | if (Tcl_Init(interp) == TCL_ERROR) { | |
| 157 | Tcl_DeleteInterp(interp); | |
| 158 | return NULL; | |
| 159 | } | |
| 160 | ||
| 161 | if (tcl_init_interp(interp)) { | |
| 162 | Tcl_DeleteInterp(interp); | |
| 163 | return NULL; | |
| 164 | } | |
| 15884 | 165 | Tcl_StaticPackage(interp, "purple", tcl_init_interp, NULL); |
| 6694 | 166 | |
| 167 | return interp; | |
| 168 | } | |
| 169 | ||
| 15884 | 170 | static gboolean tcl_probe_plugin(PurplePlugin *plugin) |
| 6694 | 171 | { |
| 15884 | 172 | PurplePluginInfo *info; |
| 6694 | 173 | Tcl_Interp *interp; |
| 174 | Tcl_Parse parse; | |
| 175 | Tcl_Obj *result, **listitems; | |
| 176 | struct stat st; | |
| 177 | FILE *fp; | |
| 178 | char *buf, *cur; | |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
179 | const char *next; |
| 6694 | 180 | int len, found = 0, err = 0, nelems; |
| 181 | gboolean status = FALSE; | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10454
diff
changeset
|
182 | if ((fp = g_fopen(plugin->path, "r")) == NULL) |
| 6694 | 183 | return FALSE; |
| 184 | if (fstat(fileno(fp), &st)) { | |
| 185 | fclose(fp); | |
| 186 | return FALSE; | |
| 187 | } | |
| 188 | len = st.st_size; | |
| 189 | ||
| 190 | buf = g_malloc(len + 1); | |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
191 | |
|
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
192 | cur = buf; |
| 14008 | 193 | while (fgets(cur, GPOINTER_TO_INT(buf) - (buf - cur), fp)) { |
| 8989 | 194 | cur += strlen(cur); |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
195 | if (feof(fp)) |
| 8989 | 196 | break; |
| 197 | } | |
| 198 | ||
| 199 | if (ferror(fp)) { | |
| 15884 | 200 | purple_debug(PURPLE_DEBUG_ERROR, "tcl", "error reading %s (%s)\n", plugin->path, strerror(errno)); |
| 6694 | 201 | g_free(buf); |
| 202 | fclose(fp); | |
| 203 | return FALSE; | |
| 204 | } | |
| 8989 | 205 | |
| 6694 | 206 | fclose(fp); |
| 207 | ||
| 208 | if ((interp = tcl_create_interp()) == NULL) { | |
| 209 | return FALSE; | |
| 210 | } | |
| 211 | ||
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
212 | next = buf; |
| 6694 | 213 | do { |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
214 | if (Tcl_ParseCommand(interp, next, len, 0, &parse) == TCL_ERROR) { |
| 15884 | 215 | purple_debug(PURPLE_DEBUG_ERROR, "tcl", "parse error in %s: %s\n", plugin->path, |
| 6694 | 216 | Tcl_GetString(Tcl_GetObjResult(interp))); |
| 217 | err = 1; | |
| 218 | break; | |
| 219 | } | |
| 220 | if (parse.tokenPtr[0].type == TCL_TOKEN_SIMPLE_WORD | |
| 221 | && !strncmp(parse.tokenPtr[0].start, "proc", parse.tokenPtr[0].size)) { | |
| 222 | if (!strncmp(parse.tokenPtr[2].start, "plugin_init", parse.tokenPtr[2].size)) { | |
| 223 | if (Tcl_EvalEx(interp, parse.commandStart, parse.commandSize, TCL_EVAL_GLOBAL) != TCL_OK) { | |
| 224 | Tcl_FreeParse(&parse); | |
| 225 | break; | |
| 226 | } | |
| 227 | found = 1; | |
| 228 | /* We'll continue parsing the file, just in case */ | |
| 229 | } | |
| 230 | } | |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
231 | len -= (parse.commandStart + parse.commandSize) - next; |
|
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
232 | next = parse.commandStart + parse.commandSize; |
| 6694 | 233 | Tcl_FreeParse(&parse); |
| 234 | } while (len); | |
| 235 | ||
| 236 | if (found && !err) { | |
| 237 | if (Tcl_EvalEx(interp, "plugin_init", -1, TCL_EVAL_GLOBAL) == TCL_OK) { | |
| 238 | result = Tcl_GetObjResult(interp); | |
| 239 | if (Tcl_ListObjGetElements(interp, result, &nelems, &listitems) == TCL_OK) { | |
| 12987 | 240 | if ((nelems == 6) || (nelems == 7)) { |
| 15884 | 241 | info = g_new0(PurplePluginInfo, 1); |
|
8761
2d596fd60ba8
[gaim-migrate @ 9516]
Mark Doliner <markdoliner@pidgin.im>
parents:
8759
diff
changeset
|
242 | |
| 15884 | 243 | info->magic = PURPLE_PLUGIN_MAGIC; |
| 244 | info->major_version = PURPLE_MAJOR_VERSION; | |
| 245 | info->minor_version = PURPLE_MINOR_VERSION; | |
| 246 | info->type = PURPLE_PLUGIN_STANDARD; | |
| 6694 | 247 | info->dependencies = g_list_append(info->dependencies, "core-tcl"); |
|
8761
2d596fd60ba8
[gaim-migrate @ 9516]
Mark Doliner <markdoliner@pidgin.im>
parents:
8759
diff
changeset
|
248 | |
| 6694 | 249 | info->name = g_strdup(Tcl_GetString(listitems[0])); |
| 250 | info->version = g_strdup(Tcl_GetString(listitems[1])); | |
| 8117 | 251 | info->summary = g_strdup(Tcl_GetString(listitems[2])); |
|
9775
e3a3555b0621
[gaim-migrate @ 10643]
Daniel Atallah <datallah@pidgin.im>
parents:
8993
diff
changeset
|
252 | info->description = g_strdup(Tcl_GetString(listitems[3])); |
|
10454
48b2b0d6a957
[gaim-migrate @ 11722]
Balwinder S Dheeman <bsd@rubyforge.org>
parents:
10344
diff
changeset
|
253 | info->author = g_strdup(Tcl_GetString(listitems[4])); |
| 8117 | 254 | info->homepage = g_strdup(Tcl_GetString(listitems[5])); |
|
8761
2d596fd60ba8
[gaim-migrate @ 9516]
Mark Doliner <markdoliner@pidgin.im>
parents:
8759
diff
changeset
|
255 | |
| 12987 | 256 | if (nelems == 6) |
| 257 | info->id = g_strdup_printf("tcl-%s", Tcl_GetString(listitems[0])); | |
| 258 | else if (nelems == 7) | |
| 259 | info->id = g_strdup_printf("tcl-%s", Tcl_GetString(listitems[6])); | |
| 260 | ||
| 6694 | 261 | plugin->info = info; |
|
8761
2d596fd60ba8
[gaim-migrate @ 9516]
Mark Doliner <markdoliner@pidgin.im>
parents:
8759
diff
changeset
|
262 | |
| 15884 | 263 | if (purple_plugin_register(plugin)) |
| 6694 | 264 | status = TRUE; |
| 265 | } | |
| 266 | } | |
| 267 | } | |
| 268 | } | |
| 269 | ||
| 270 | Tcl_DeleteInterp(interp); | |
| 271 | g_free(buf); | |
| 272 | return status; | |
| 273 | } | |
| 274 | ||
| 15884 | 275 | static gboolean tcl_load_plugin(PurplePlugin *plugin) |
| 6694 | 276 | { |
| 277 | struct tcl_plugin_data *data; | |
| 278 | Tcl_Interp *interp; | |
| 279 | Tcl_Obj *result; | |
| 280 | ||
| 281 | plugin->extra = NULL; | |
| 282 | ||
| 283 | if ((interp = tcl_create_interp()) == NULL) { | |
| 15884 | 284 | purple_debug(PURPLE_DEBUG_ERROR, "tcl", "Could not initialize Tcl interpreter\n"); |
| 6694 | 285 | return FALSE; |
| 286 | } | |
| 287 | ||
| 288 | Tcl_SourceRCFile(interp); | |
| 289 | ||
| 290 | if (Tcl_EvalFile(interp, plugin->path) != TCL_OK) { | |
| 291 | result = Tcl_GetObjResult(interp); | |
| 15884 | 292 | purple_debug(PURPLE_DEBUG_ERROR, "tcl", |
| 13847 | 293 | "Error evaluating %s: %s\n", plugin->path, |
| 294 | Tcl_GetString(result)); | |
| 6694 | 295 | Tcl_DeleteInterp(interp); |
| 296 | return FALSE; | |
| 297 | } | |
| 298 | ||
| 299 | Tcl_Preserve((ClientData)interp); | |
| 300 | ||
| 301 | data = g_new0(struct tcl_plugin_data, 1); | |
| 302 | data->plugin = plugin; | |
| 303 | data->interp = interp; | |
| 304 | plugin->extra = data; | |
| 305 | ||
| 306 | g_hash_table_insert(tcl_plugins, (gpointer)interp, (gpointer)data); | |
| 307 | ||
| 308 | return TRUE; | |
| 309 | } | |
| 310 | ||
| 15884 | 311 | static gboolean tcl_unload_plugin(PurplePlugin *plugin) |
| 6694 | 312 | { |
| 313 | struct tcl_plugin_data *data; | |
| 314 | ||
| 315 | if (plugin == NULL) | |
| 316 | return TRUE; | |
| 317 | ||
| 318 | data = plugin->extra; | |
| 319 | ||
| 320 | if (data != NULL) { | |
|
13439
1ef0c638a216
[gaim-migrate @ 15813]
Richard Laager <rlaager@pidgin.im>
parents:
13199
diff
changeset
|
321 | g_hash_table_remove(tcl_plugins, (gpointer)(data->interp)); |
| 15884 | 322 | purple_signals_disconnect_by_handle(data->interp); |
| 13847 | 323 | tcl_cmd_cleanup(data->interp); |
| 6694 | 324 | tcl_signal_cleanup(data->interp); |
| 325 | Tcl_Release((ClientData)data->interp); | |
| 326 | Tcl_DeleteInterp(data->interp); | |
| 327 | g_free(data); | |
| 328 | } | |
| 329 | ||
| 330 | return TRUE; | |
| 331 | } | |
| 332 | ||
| 15884 | 333 | static void tcl_destroy_plugin(PurplePlugin *plugin) |
| 6694 | 334 | { |
| 335 | if (plugin->info != NULL) { | |
| 13199 | 336 | g_free(plugin->info->id); |
| 6694 | 337 | g_free(plugin->info->name); |
| 338 | g_free(plugin->info->version); | |
| 339 | g_free(plugin->info->description); | |
| 340 | g_free(plugin->info->author); | |
| 341 | g_free(plugin->info->homepage); | |
| 342 | } | |
| 343 | ||
| 344 | return; | |
| 345 | } | |
| 346 | ||
| 15884 | 347 | static gboolean tcl_load(PurplePlugin *plugin) |
| 6694 | 348 | { |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
349 | if(!tcl_loaded) |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
350 | return FALSE; |
| 6694 | 351 | tcl_glib_init(); |
| 13847 | 352 | tcl_cmd_init(); |
| 6694 | 353 | tcl_signal_init(); |
| 15884 | 354 | purple_tcl_ref_init(); |
| 13812 | 355 | |
| 15884 | 356 | PurpleTclRefAccount = purple_stringref_new("Account"); |
| 357 | PurpleTclRefConnection = purple_stringref_new("Connection"); | |
| 358 | PurpleTclRefConversation = purple_stringref_new("Conversation"); | |
| 359 | PurpleTclRefPointer = purple_stringref_new("Pointer"); | |
| 360 | PurpleTclRefPlugin = purple_stringref_new("Plugin"); | |
| 361 | PurpleTclRefPresence = purple_stringref_new("Presence"); | |
| 362 | PurpleTclRefStatus = purple_stringref_new("Status"); | |
| 363 | PurpleTclRefStatusAttr = purple_stringref_new("StatusAttr"); | |
| 364 | PurpleTclRefStatusType = purple_stringref_new("StatusType"); | |
| 365 | PurpleTclRefXfer = purple_stringref_new("Xfer"); | |
| 13812 | 366 | |
| 6694 | 367 | tcl_plugins = g_hash_table_new(g_direct_hash, g_direct_equal); |
| 368 | ||
| 7828 | 369 | #ifdef HAVE_TK |
| 370 | Tcl_StaticPackage(NULL, "Tk", Tk_Init, Tk_SafeInit); | |
| 371 | #endif /* HAVE_TK */ | |
| 372 | ||
| 6694 | 373 | return TRUE; |
| 374 | } | |
| 375 | ||
| 15884 | 376 | static gboolean tcl_unload(PurplePlugin *plugin) |
| 6694 | 377 | { |
| 378 | g_hash_table_destroy(tcl_plugins); | |
| 379 | tcl_plugins = NULL; | |
| 380 | ||
| 15884 | 381 | purple_stringref_unref(PurpleTclRefAccount); |
| 382 | purple_stringref_unref(PurpleTclRefConnection); | |
| 383 | purple_stringref_unref(PurpleTclRefConversation); | |
| 384 | purple_stringref_unref(PurpleTclRefPointer); | |
| 385 | purple_stringref_unref(PurpleTclRefPlugin); | |
| 386 | purple_stringref_unref(PurpleTclRefPresence); | |
| 387 | purple_stringref_unref(PurpleTclRefStatus); | |
| 388 | purple_stringref_unref(PurpleTclRefStatusAttr); | |
| 389 | purple_stringref_unref(PurpleTclRefStatusType); | |
| 390 | purple_stringref_unref(PurpleTclRefXfer); | |
| 13812 | 391 | |
| 6694 | 392 | return TRUE; |
| 393 | } | |
| 394 | ||
| 15884 | 395 | static PurplePluginLoaderInfo tcl_loader_info = |
| 6694 | 396 | { |
| 397 | NULL, | |
| 398 | tcl_probe_plugin, | |
| 399 | tcl_load_plugin, | |
| 400 | tcl_unload_plugin, | |
| 401 | tcl_destroy_plugin, | |
| 402 | }; | |
| 403 | ||
| 15884 | 404 | static PurplePluginInfo tcl_info = |
| 6694 | 405 | { |
| 15884 | 406 | PURPLE_PLUGIN_MAGIC, |
| 407 | PURPLE_MAJOR_VERSION, | |
| 408 | PURPLE_MINOR_VERSION, | |
| 409 | PURPLE_PLUGIN_LOADER, | |
| 6694 | 410 | NULL, |
| 411 | 0, | |
| 412 | NULL, | |
| 15884 | 413 | PURPLE_PRIORITY_DEFAULT, |
| 6694 | 414 | "core-tcl", |
| 415 | N_("Tcl Plugin Loader"), | |
| 416 | VERSION, | |
| 417 | N_("Provides support for loading Tcl plugins"), | |
| 418 | N_("Provides support for loading Tcl plugins"), | |
| 419 | "Ethan Blanton <eblanton@cs.purdue.edu>", | |
| 15884 | 420 | PURPLE_WEBSITE, |
| 6694 | 421 | tcl_load, |
| 422 | tcl_unload, | |
| 423 | NULL, | |
| 424 | NULL, | |
| 8993 | 425 | &tcl_loader_info, |
| 426 | NULL, | |
| 427 | NULL | |
| 6694 | 428 | }; |
| 429 | ||
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
430 | #ifdef _WIN32 |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
431 | typedef Tcl_Interp* (CALLBACK* LPFNTCLCREATEINTERP)(void); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
432 | typedef void (CALLBACK* LPFNTKINIT)(Tcl_Interp*); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
433 | |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
434 | LPFNTCLCREATEINTERP wtcl_CreateInterp = NULL; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
435 | LPFNTKINIT wtk_Init = NULL; |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
436 | #undef Tcl_CreateInterp |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
437 | #define Tcl_CreateInterp wtcl_CreateInterp |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
438 | #undef Tk_Init |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
439 | #define Tk_Init wtk_Init |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
440 | |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
441 | static gboolean tcl_win32_init() { |
| 14913 | 442 | const char regkey[] = "SOFTWARE\\ActiveState\\ActiveTcl\\"; |
| 443 | char *version = NULL; | |
| 444 | gboolean retval = FALSE; | |
| 445 | ||
| 15884 | 446 | if ((version = wpurple_read_reg_string(HKEY_LOCAL_MACHINE, regkey, "CurrentVersion")) |
| 447 | || (version = wpurple_read_reg_string(HKEY_CURRENT_USER, regkey, "CurrentVersion"))) { | |
| 14913 | 448 | char *path; |
| 449 | char *regkey2; | |
| 450 | ||
| 451 | regkey2 = g_strdup_printf("%s%s\\", regkey, version); | |
| 15884 | 452 | if ((path = wpurple_read_reg_string(HKEY_LOCAL_MACHINE, regkey2, NULL)) || (path = wpurple_read_reg_string(HKEY_CURRENT_USER, regkey2, NULL))) { |
| 14913 | 453 | char *tclpath; |
| 454 | char *tkpath; | |
| 455 | ||
| 15884 | 456 | purple_debug(PURPLE_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
|
457 | |
| 14913 | 458 | tclpath = g_build_filename(path, "bin", "tcl84.dll", NULL); |
| 459 | tkpath = g_build_filename(path, "bin", "tk84.dll", NULL); | |
| 460 | ||
| 15884 | 461 | if(!(wtcl_CreateInterp = (LPFNTCLCREATEINTERP) wpurple_find_and_loadproc(tclpath, "Tcl_CreateInterp"))) { |
| 462 | purple_debug(PURPLE_DEBUG_INFO, "tcl", "tcl_win32_init error loading Tcl_CreateInterp\n"); | |
| 14913 | 463 | } else { |
| 15884 | 464 | if(!(wtk_Init = (LPFNTKINIT) wpurple_find_and_loadproc(tkpath, "Tk_Init"))) { |
| 14913 | 465 | HMODULE mod; |
| 15884 | 466 | purple_debug(PURPLE_DEBUG_INFO, "tcl", "tcl_win32_init error loading Tk_Init\n"); |
| 14913 | 467 | if((mod = GetModuleHandle("tcl84.dll"))) |
| 468 | FreeLibrary(mod); | |
| 469 | } else { | |
| 470 | retval = TRUE; | |
| 471 | } | |
| 472 | } | |
| 473 | g_free(tclpath); | |
| 474 | g_free(tkpath); | |
| 475 | } | |
| 476 | g_free(path); | |
| 477 | g_free(regkey2); | |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
478 | } |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
479 | |
| 14913 | 480 | g_free(version); |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
481 | |
| 14913 | 482 | if (!retval) |
| 15884 | 483 | purple_debug(PURPLE_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
|
484 | |
| 14913 | 485 | return retval; |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
486 | } |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
487 | |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
488 | #endif /* _WIN32 */ |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
489 | |
| 15884 | 490 | static void tcl_init_plugin(PurplePlugin *plugin) |
| 6694 | 491 | { |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
492 | #ifdef USE_TCL_STUBS |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
493 | Tcl_Interp *interp = NULL; |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
494 | #endif |
| 6694 | 495 | _tcl_plugin = plugin; |
| 496 | ||
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
497 | #ifdef USE_TCL_STUBS |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
498 | #ifdef _WIN32 |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
499 | if(!tcl_win32_init()) |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
500 | return; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
501 | #endif |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
502 | if(!(interp = Tcl_CreateInterp())) |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
503 | return; |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
504 | |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
505 | if(!Tcl_InitStubs(interp, TCL_VERSION, 0)) { |
| 15884 | 506 | purple_debug(PURPLE_DEBUG_ERROR, "tcl", "Tcl_InitStubs: %s\n", interp->result); |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
507 | return; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
508 | } |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
509 | #endif |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
510 | |
| 15884 | 511 | Tcl_FindExecutable("purple"); |
| 6694 | 512 | |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
513 | #if defined(USE_TK_STUBS) && defined(HAVE_TK) |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
514 | Tk_Init(interp); |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
515 | |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
516 | if(!Tk_InitStubs(interp, TK_VERSION, 0)) { |
| 15884 | 517 | purple_debug(PURPLE_DEBUG_ERROR, "tcl", "Error Tk_InitStubs: %s\n", interp->result); |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
518 | Tcl_DeleteInterp(interp); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
519 | return; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
520 | } |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
521 | #endif |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
522 | tcl_loaded = TRUE; |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
523 | #ifdef USE_TCL_STUBS |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
524 | Tcl_DeleteInterp(interp); |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
525 | #endif |
| 6694 | 526 | tcl_loader_info.exts = g_list_append(tcl_loader_info.exts, "tcl"); |
| 527 | } | |
| 528 | ||
| 15884 | 529 | PURPLE_INIT_PLUGIN(tcl, tcl_init_plugin, tcl_info) |