Wed, 30 Jul 2008 03:58:21 +0000
Cleanup unnecessary casts and etc.
| 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 | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
17629
diff
changeset
|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 6694 | 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; | |
|
20393
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
63 | PurpleStringref *PurpleTclRefHandle; |
| 13812 | 64 | |
| 6694 | 65 | static GHashTable *tcl_plugins = NULL; |
| 66 | ||
| 15884 | 67 | PurplePlugin *_tcl_plugin; |
| 6694 | 68 | |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
69 | static gboolean tcl_loaded = FALSE; |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
70 | |
| 15884 | 71 | PurplePlugin *tcl_interp_get_plugin(Tcl_Interp *interp) |
| 6694 | 72 | { |
| 73 | struct tcl_plugin_data *data; | |
| 74 | ||
| 75 | if (tcl_plugins == NULL) | |
| 76 | return NULL; | |
| 77 | ||
| 78 | data = g_hash_table_lookup(tcl_plugins, (gpointer)interp); | |
| 79 | return data != NULL ? data->plugin : NULL; | |
| 80 | } | |
| 81 | ||
| 82 | static int tcl_init_interp(Tcl_Interp *interp) | |
| 83 | { | |
| 84 | char *rcfile; | |
| 9943 | 85 | char init[] = |
| 15884 | 86 | "namespace eval ::purple {\n" |
| 6694 | 87 | " namespace export account buddy connection conversation\n" |
| 88 | " namespace export core debug notify prefs send_im\n" | |
| 89 | " namespace export signal unload\n" | |
| 90 | " namespace eval _callback { }\n" | |
| 91 | "\n" | |
| 92 | " proc conv_send { account who text } {\n" | |
| 15884 | 93 | " set gc [purple::account connection $account]\n" |
| 94 | " set convo [purple::conversation new $account $who]\n" | |
| 95 | " set myalias [purple::account alias $account]\n" | |
| 6694 | 96 | "\n" |
| 97 | " if {![string length $myalias]} {\n" | |
| 15884 | 98 | " set myalias [purple::account username $account]\n" |
| 6694 | 99 | " }\n" |
| 100 | "\n" | |
| 15884 | 101 | " purple::send_im $gc $who $text\n" |
| 102 | " purple::conversation write $convo send $myalias $text\n" | |
| 6694 | 103 | " }\n" |
| 104 | "}\n" | |
| 105 | "\n" | |
| 106 | "proc bgerror { message } {\n" | |
| 107 | " global errorInfo\n" | |
| 15884 | 108 | " purple::notify -error \"Tcl Error\" \"Tcl Error: $message\" \"$errorInfo\"\n" |
| 6694 | 109 | "}\n"; |
| 110 | ||
| 111 | if (Tcl_EvalEx(interp, init, -1, TCL_EVAL_GLOBAL) != TCL_OK) { | |
| 112 | return 1; | |
| 113 | } | |
| 114 | ||
| 115 | Tcl_SetVar(interp, "argc", "0", TCL_GLOBAL_ONLY); | |
| 15884 | 116 | Tcl_SetVar(interp, "argv0", "purple", TCL_GLOBAL_ONLY); |
| 6694 | 117 | Tcl_SetVar(interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); |
| 15884 | 118 | rcfile = g_strdup_printf("%s" G_DIR_SEPARATOR_S "tclrc", purple_user_dir()); |
| 6694 | 119 | Tcl_SetVar(interp, "tcl_rcFileName", rcfile, TCL_GLOBAL_ONLY); |
| 120 | g_free(rcfile); | |
| 121 | ||
| 15884 | 122 | Tcl_SetVar(interp, "::purple::version", VERSION, TCL_GLOBAL_ONLY); |
| 123 | Tcl_SetVar(interp, "::purple::user_dir", purple_user_dir(), TCL_GLOBAL_ONLY); | |
| 6694 | 124 | #ifdef HAVE_TK |
| 15884 | 125 | Tcl_SetVar(interp, "::purple::tk_available", "1", TCL_GLOBAL_ONLY); |
| 6694 | 126 | #else |
| 15884 | 127 | Tcl_SetVar(interp, "::purple::tk_available", "0", TCL_GLOBAL_ONLY); |
| 6694 | 128 | #endif /* HAVE_TK */ |
| 129 | ||
| 15884 | 130 | Tcl_CreateObjCommand(interp, "::purple::account", tcl_cmd_account, (ClientData)NULL, NULL); |
| 131 | Tcl_CreateObjCommand(interp, "::purple::buddy", tcl_cmd_buddy, (ClientData)NULL, NULL); | |
| 132 | Tcl_CreateObjCommand(interp, "::purple::cmd", tcl_cmd_cmd, (ClientData)NULL, NULL); | |
| 133 | Tcl_CreateObjCommand(interp, "::purple::connection", tcl_cmd_connection, (ClientData)NULL, NULL); | |
| 134 | Tcl_CreateObjCommand(interp, "::purple::conversation", tcl_cmd_conversation, (ClientData)NULL, NULL); | |
| 135 | Tcl_CreateObjCommand(interp, "::purple::core", tcl_cmd_core, (ClientData)NULL, NULL); | |
| 136 | Tcl_CreateObjCommand(interp, "::purple::debug", tcl_cmd_debug, (ClientData)NULL, NULL); | |
| 137 | Tcl_CreateObjCommand(interp, "::purple::notify", tcl_cmd_notify, (ClientData)NULL, NULL); | |
| 138 | Tcl_CreateObjCommand(interp, "::purple::plugins", tcl_cmd_plugins, (ClientData)NULL, NULL); | |
| 139 | Tcl_CreateObjCommand(interp, "::purple::prefs", tcl_cmd_prefs, (ClientData)NULL, NULL); | |
| 140 | Tcl_CreateObjCommand(interp, "::purple::presence", tcl_cmd_presence, (ClientData)NULL, NULL); | |
| 141 | Tcl_CreateObjCommand(interp, "::purple::send_im", tcl_cmd_send_im, (ClientData)NULL, NULL); | |
| 142 | Tcl_CreateObjCommand(interp, "::purple::savedstatus", tcl_cmd_savedstatus, (ClientData)NULL, NULL); | |
| 143 | Tcl_CreateObjCommand(interp, "::purple::signal", tcl_cmd_signal, (ClientData)NULL, NULL); | |
| 144 | Tcl_CreateObjCommand(interp, "::purple::status", tcl_cmd_status, (ClientData)NULL, NULL); | |
| 145 | Tcl_CreateObjCommand(interp, "::purple::status_attr", tcl_cmd_status_attr, (ClientData)NULL, NULL); | |
| 146 | Tcl_CreateObjCommand(interp, "::purple::status_type", tcl_cmd_status_type, (ClientData)NULL, NULL); | |
| 147 | Tcl_CreateObjCommand(interp, "::purple::unload", tcl_cmd_unload, (ClientData)NULL, NULL); | |
| 6694 | 148 | |
| 149 | return 0; | |
| 150 | } | |
| 151 | ||
|
22104
56970903b8e9
Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@pidgin.im>
parents:
21389
diff
changeset
|
152 | static Tcl_Interp *tcl_create_interp(void) |
| 6694 | 153 | { |
| 154 | Tcl_Interp *interp; | |
| 155 | ||
| 156 | interp = Tcl_CreateInterp(); | |
| 157 | if (Tcl_Init(interp) == TCL_ERROR) { | |
| 158 | Tcl_DeleteInterp(interp); | |
| 159 | return NULL; | |
| 160 | } | |
| 161 | ||
| 162 | if (tcl_init_interp(interp)) { | |
| 163 | Tcl_DeleteInterp(interp); | |
| 164 | return NULL; | |
| 165 | } | |
| 15884 | 166 | Tcl_StaticPackage(interp, "purple", tcl_init_interp, NULL); |
| 6694 | 167 | |
| 168 | return interp; | |
| 169 | } | |
| 170 | ||
| 15884 | 171 | static gboolean tcl_probe_plugin(PurplePlugin *plugin) |
| 6694 | 172 | { |
| 15884 | 173 | PurplePluginInfo *info; |
| 6694 | 174 | Tcl_Interp *interp; |
| 175 | Tcl_Parse parse; | |
| 176 | Tcl_Obj *result, **listitems; | |
| 177 | struct stat st; | |
| 178 | FILE *fp; | |
| 179 | char *buf, *cur; | |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
180 | const char *next; |
| 6694 | 181 | int len, found = 0, err = 0, nelems; |
| 182 | gboolean status = FALSE; | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10454
diff
changeset
|
183 | if ((fp = g_fopen(plugin->path, "r")) == NULL) |
| 6694 | 184 | return FALSE; |
| 185 | if (fstat(fileno(fp), &st)) { | |
| 186 | fclose(fp); | |
| 187 | return FALSE; | |
| 188 | } | |
| 189 | len = st.st_size; | |
| 190 | ||
| 191 | buf = g_malloc(len + 1); | |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
192 | |
|
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
193 | cur = buf; |
| 14008 | 194 | while (fgets(cur, GPOINTER_TO_INT(buf) - (buf - cur), fp)) { |
| 8989 | 195 | cur += strlen(cur); |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
196 | if (feof(fp)) |
| 8989 | 197 | break; |
| 198 | } | |
| 199 | ||
| 200 | if (ferror(fp)) { | |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
21106
diff
changeset
|
201 | purple_debug(PURPLE_DEBUG_ERROR, "tcl", "error reading %s (%s)\n", plugin->path, g_strerror(errno)); |
| 6694 | 202 | g_free(buf); |
| 203 | fclose(fp); | |
| 204 | return FALSE; | |
| 205 | } | |
| 8989 | 206 | |
| 6694 | 207 | fclose(fp); |
| 208 | ||
| 209 | if ((interp = tcl_create_interp()) == NULL) { | |
| 210 | return FALSE; | |
| 211 | } | |
| 212 | ||
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
213 | next = buf; |
| 6694 | 214 | do { |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
215 | if (Tcl_ParseCommand(interp, next, len, 0, &parse) == TCL_ERROR) { |
| 15884 | 216 | purple_debug(PURPLE_DEBUG_ERROR, "tcl", "parse error in %s: %s\n", plugin->path, |
| 6694 | 217 | Tcl_GetString(Tcl_GetObjResult(interp))); |
| 218 | err = 1; | |
| 219 | break; | |
| 220 | } | |
| 221 | if (parse.tokenPtr[0].type == TCL_TOKEN_SIMPLE_WORD | |
| 222 | && !strncmp(parse.tokenPtr[0].start, "proc", parse.tokenPtr[0].size)) { | |
| 223 | if (!strncmp(parse.tokenPtr[2].start, "plugin_init", parse.tokenPtr[2].size)) { | |
| 224 | if (Tcl_EvalEx(interp, parse.commandStart, parse.commandSize, TCL_EVAL_GLOBAL) != TCL_OK) { | |
| 225 | Tcl_FreeParse(&parse); | |
| 226 | break; | |
| 227 | } | |
| 228 | found = 1; | |
| 229 | /* We'll continue parsing the file, just in case */ | |
| 230 | } | |
| 231 | } | |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
232 | len -= (parse.commandStart + parse.commandSize) - next; |
|
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
233 | next = parse.commandStart + parse.commandSize; |
| 6694 | 234 | Tcl_FreeParse(&parse); |
| 235 | } while (len); | |
| 236 | ||
| 237 | if (found && !err) { | |
| 238 | if (Tcl_EvalEx(interp, "plugin_init", -1, TCL_EVAL_GLOBAL) == TCL_OK) { | |
| 239 | result = Tcl_GetObjResult(interp); | |
| 240 | if (Tcl_ListObjGetElements(interp, result, &nelems, &listitems) == TCL_OK) { | |
| 12987 | 241 | if ((nelems == 6) || (nelems == 7)) { |
| 15884 | 242 | info = g_new0(PurplePluginInfo, 1); |
|
8761
2d596fd60ba8
[gaim-migrate @ 9516]
Mark Doliner <markdoliner@pidgin.im>
parents:
8759
diff
changeset
|
243 | |
| 15884 | 244 | info->magic = PURPLE_PLUGIN_MAGIC; |
| 245 | info->major_version = PURPLE_MAJOR_VERSION; | |
| 246 | info->minor_version = PURPLE_MINOR_VERSION; | |
| 247 | info->type = PURPLE_PLUGIN_STANDARD; | |
| 6694 | 248 | info->dependencies = g_list_append(info->dependencies, "core-tcl"); |
|
8761
2d596fd60ba8
[gaim-migrate @ 9516]
Mark Doliner <markdoliner@pidgin.im>
parents:
8759
diff
changeset
|
249 | |
| 6694 | 250 | info->name = g_strdup(Tcl_GetString(listitems[0])); |
| 251 | info->version = g_strdup(Tcl_GetString(listitems[1])); | |
| 8117 | 252 | info->summary = g_strdup(Tcl_GetString(listitems[2])); |
|
9775
e3a3555b0621
[gaim-migrate @ 10643]
Daniel Atallah <datallah@pidgin.im>
parents:
8993
diff
changeset
|
253 | info->description = g_strdup(Tcl_GetString(listitems[3])); |
|
10454
48b2b0d6a957
[gaim-migrate @ 11722]
Balwinder S Dheeman <bsd@rubyforge.org>
parents:
10344
diff
changeset
|
254 | info->author = g_strdup(Tcl_GetString(listitems[4])); |
| 8117 | 255 | info->homepage = g_strdup(Tcl_GetString(listitems[5])); |
|
8761
2d596fd60ba8
[gaim-migrate @ 9516]
Mark Doliner <markdoliner@pidgin.im>
parents:
8759
diff
changeset
|
256 | |
| 12987 | 257 | if (nelems == 6) |
| 258 | info->id = g_strdup_printf("tcl-%s", Tcl_GetString(listitems[0])); | |
| 259 | else if (nelems == 7) | |
| 260 | info->id = g_strdup_printf("tcl-%s", Tcl_GetString(listitems[6])); | |
| 261 | ||
| 6694 | 262 | plugin->info = info; |
|
8761
2d596fd60ba8
[gaim-migrate @ 9516]
Mark Doliner <markdoliner@pidgin.im>
parents:
8759
diff
changeset
|
263 | |
| 15884 | 264 | if (purple_plugin_register(plugin)) |
| 6694 | 265 | status = TRUE; |
| 266 | } | |
| 267 | } | |
| 268 | } | |
| 269 | } | |
| 270 | ||
| 271 | Tcl_DeleteInterp(interp); | |
| 272 | g_free(buf); | |
| 273 | return status; | |
| 274 | } | |
| 275 | ||
| 15884 | 276 | static gboolean tcl_load_plugin(PurplePlugin *plugin) |
| 6694 | 277 | { |
| 278 | struct tcl_plugin_data *data; | |
| 279 | Tcl_Interp *interp; | |
| 280 | Tcl_Obj *result; | |
| 281 | ||
| 282 | plugin->extra = NULL; | |
| 283 | ||
| 284 | if ((interp = tcl_create_interp()) == NULL) { | |
| 15884 | 285 | purple_debug(PURPLE_DEBUG_ERROR, "tcl", "Could not initialize Tcl interpreter\n"); |
| 6694 | 286 | return FALSE; |
| 287 | } | |
| 288 | ||
| 289 | Tcl_SourceRCFile(interp); | |
| 290 | ||
| 291 | if (Tcl_EvalFile(interp, plugin->path) != TCL_OK) { | |
| 292 | result = Tcl_GetObjResult(interp); | |
| 15884 | 293 | purple_debug(PURPLE_DEBUG_ERROR, "tcl", |
| 13847 | 294 | "Error evaluating %s: %s\n", plugin->path, |
| 295 | Tcl_GetString(result)); | |
| 6694 | 296 | Tcl_DeleteInterp(interp); |
| 297 | return FALSE; | |
| 298 | } | |
| 299 | ||
| 300 | Tcl_Preserve((ClientData)interp); | |
| 301 | ||
| 302 | data = g_new0(struct tcl_plugin_data, 1); | |
| 303 | data->plugin = plugin; | |
| 304 | data->interp = interp; | |
| 305 | plugin->extra = data; | |
| 306 | ||
| 307 | g_hash_table_insert(tcl_plugins, (gpointer)interp, (gpointer)data); | |
| 308 | ||
| 309 | return TRUE; | |
| 310 | } | |
| 311 | ||
| 15884 | 312 | static gboolean tcl_unload_plugin(PurplePlugin *plugin) |
| 6694 | 313 | { |
| 314 | struct tcl_plugin_data *data; | |
| 315 | ||
| 316 | if (plugin == NULL) | |
| 317 | return TRUE; | |
| 318 | ||
| 319 | data = plugin->extra; | |
| 320 | ||
| 321 | if (data != NULL) { | |
|
13439
1ef0c638a216
[gaim-migrate @ 15813]
Richard Laager <rlaager@pidgin.im>
parents:
13199
diff
changeset
|
322 | g_hash_table_remove(tcl_plugins, (gpointer)(data->interp)); |
| 15884 | 323 | purple_signals_disconnect_by_handle(data->interp); |
| 13847 | 324 | tcl_cmd_cleanup(data->interp); |
| 6694 | 325 | tcl_signal_cleanup(data->interp); |
| 326 | Tcl_Release((ClientData)data->interp); | |
| 327 | Tcl_DeleteInterp(data->interp); | |
| 328 | g_free(data); | |
| 329 | } | |
| 330 | ||
| 331 | return TRUE; | |
| 332 | } | |
| 333 | ||
| 15884 | 334 | static void tcl_destroy_plugin(PurplePlugin *plugin) |
| 6694 | 335 | { |
| 336 | if (plugin->info != NULL) { | |
| 13199 | 337 | g_free(plugin->info->id); |
| 6694 | 338 | g_free(plugin->info->name); |
| 339 | g_free(plugin->info->version); | |
| 340 | g_free(plugin->info->description); | |
| 341 | g_free(plugin->info->author); | |
| 342 | g_free(plugin->info->homepage); | |
| 343 | } | |
| 344 | ||
| 345 | return; | |
| 346 | } | |
| 347 | ||
| 15884 | 348 | static gboolean tcl_load(PurplePlugin *plugin) |
| 6694 | 349 | { |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
350 | if(!tcl_loaded) |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
351 | return FALSE; |
| 6694 | 352 | tcl_glib_init(); |
| 13847 | 353 | tcl_cmd_init(); |
| 6694 | 354 | tcl_signal_init(); |
| 15884 | 355 | purple_tcl_ref_init(); |
| 13812 | 356 | |
| 15884 | 357 | PurpleTclRefAccount = purple_stringref_new("Account"); |
| 358 | PurpleTclRefConnection = purple_stringref_new("Connection"); | |
| 359 | PurpleTclRefConversation = purple_stringref_new("Conversation"); | |
| 360 | PurpleTclRefPointer = purple_stringref_new("Pointer"); | |
| 361 | PurpleTclRefPlugin = purple_stringref_new("Plugin"); | |
| 362 | PurpleTclRefPresence = purple_stringref_new("Presence"); | |
| 363 | PurpleTclRefStatus = purple_stringref_new("Status"); | |
| 364 | PurpleTclRefStatusAttr = purple_stringref_new("StatusAttr"); | |
| 365 | PurpleTclRefStatusType = purple_stringref_new("StatusType"); | |
| 366 | PurpleTclRefXfer = purple_stringref_new("Xfer"); | |
|
20393
6280efb8c658
Another fabulous patch to our Tcl loader from venks on irc.freenode.net.
Ethan Blanton <elb@pidgin.im>
parents:
19859
diff
changeset
|
367 | PurpleTclRefHandle = purple_stringref_new("Handle"); |
| 13812 | 368 | |
| 6694 | 369 | tcl_plugins = g_hash_table_new(g_direct_hash, g_direct_equal); |
| 370 | ||
| 7828 | 371 | #ifdef HAVE_TK |
| 372 | Tcl_StaticPackage(NULL, "Tk", Tk_Init, Tk_SafeInit); | |
| 373 | #endif /* HAVE_TK */ | |
| 374 | ||
| 6694 | 375 | return TRUE; |
| 376 | } | |
| 377 | ||
| 15884 | 378 | static gboolean tcl_unload(PurplePlugin *plugin) |
| 6694 | 379 | { |
| 380 | g_hash_table_destroy(tcl_plugins); | |
| 381 | tcl_plugins = NULL; | |
| 382 | ||
| 15884 | 383 | purple_stringref_unref(PurpleTclRefAccount); |
| 384 | purple_stringref_unref(PurpleTclRefConnection); | |
| 385 | purple_stringref_unref(PurpleTclRefConversation); | |
| 386 | purple_stringref_unref(PurpleTclRefPointer); | |
| 387 | purple_stringref_unref(PurpleTclRefPlugin); | |
| 388 | purple_stringref_unref(PurpleTclRefPresence); | |
| 389 | purple_stringref_unref(PurpleTclRefStatus); | |
| 390 | purple_stringref_unref(PurpleTclRefStatusAttr); | |
| 391 | purple_stringref_unref(PurpleTclRefStatusType); | |
| 392 | purple_stringref_unref(PurpleTclRefXfer); | |
| 13812 | 393 | |
| 6694 | 394 | return TRUE; |
| 395 | } | |
| 396 | ||
| 15884 | 397 | static PurplePluginLoaderInfo tcl_loader_info = |
| 6694 | 398 | { |
| 399 | NULL, | |
| 400 | tcl_probe_plugin, | |
| 401 | tcl_load_plugin, | |
| 402 | tcl_unload_plugin, | |
| 403 | tcl_destroy_plugin, | |
|
16750
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
404 | |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
405 | /* pidgin */ |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
406 | NULL, |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
407 | NULL, |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
408 | NULL, |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
409 | NULL |
| 6694 | 410 | }; |
| 411 | ||
| 15884 | 412 | static PurplePluginInfo tcl_info = |
| 6694 | 413 | { |
| 15884 | 414 | PURPLE_PLUGIN_MAGIC, |
| 415 | PURPLE_MAJOR_VERSION, | |
| 416 | PURPLE_MINOR_VERSION, | |
| 417 | PURPLE_PLUGIN_LOADER, | |
| 6694 | 418 | NULL, |
| 419 | 0, | |
| 420 | NULL, | |
| 15884 | 421 | PURPLE_PRIORITY_DEFAULT, |
| 6694 | 422 | "core-tcl", |
| 423 | N_("Tcl Plugin Loader"), | |
|
21106
b85fbef13eed
Add a --with-extraversion option to ./configure so packagers can fine tune
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
20393
diff
changeset
|
424 | DISPLAY_VERSION, |
| 6694 | 425 | N_("Provides support for loading Tcl plugins"), |
| 426 | N_("Provides support for loading Tcl plugins"), | |
| 427 | "Ethan Blanton <eblanton@cs.purdue.edu>", | |
| 15884 | 428 | PURPLE_WEBSITE, |
| 6694 | 429 | tcl_load, |
| 430 | tcl_unload, | |
| 431 | NULL, | |
| 432 | NULL, | |
| 8993 | 433 | &tcl_loader_info, |
| 434 | NULL, | |
|
16750
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
435 | NULL, |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
436 | |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
437 | /* padding */ |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
438 | NULL, |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
439 | NULL, |
|
a568944eee52
Updating the loaders since I missed them since I'm not building any of them right now
Gary Kramlich <grim@reaperworld.com>
parents:
15884
diff
changeset
|
440 | NULL, |
| 8993 | 441 | NULL |
| 6694 | 442 | }; |
| 443 | ||
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
444 | #ifdef _WIN32 |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
445 | typedef Tcl_Interp* (CALLBACK* LPFNTCLCREATEINTERP)(void); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
446 | typedef void (CALLBACK* LPFNTKINIT)(Tcl_Interp*); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
447 | |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
448 | LPFNTCLCREATEINTERP wtcl_CreateInterp = NULL; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
449 | LPFNTKINIT wtk_Init = NULL; |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
450 | #undef Tcl_CreateInterp |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
451 | #define Tcl_CreateInterp wtcl_CreateInterp |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
452 | #undef Tk_Init |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
453 | #define Tk_Init wtk_Init |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
454 | |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
455 | static gboolean tcl_win32_init() { |
| 14913 | 456 | const char regkey[] = "SOFTWARE\\ActiveState\\ActiveTcl\\"; |
| 457 | char *version = NULL; | |
| 458 | gboolean retval = FALSE; | |
| 459 | ||
| 15884 | 460 | if ((version = wpurple_read_reg_string(HKEY_LOCAL_MACHINE, regkey, "CurrentVersion")) |
| 461 | || (version = wpurple_read_reg_string(HKEY_CURRENT_USER, regkey, "CurrentVersion"))) { | |
|
17629
877897645980
Don't load the tcl loader plugin on Windows unless ActiveTcl 8.4.5 or newer is present. Fixes #538.
Daniel Atallah <datallah@pidgin.im>
parents:
16750
diff
changeset
|
462 | char *path = NULL; |
| 14913 | 463 | char *regkey2; |
|
17629
877897645980
Don't load the tcl loader plugin on Windows unless ActiveTcl 8.4.5 or newer is present. Fixes #538.
Daniel Atallah <datallah@pidgin.im>
parents:
16750
diff
changeset
|
464 | char **tokens; |
|
877897645980
Don't load the tcl loader plugin on Windows unless ActiveTcl 8.4.5 or newer is present. Fixes #538.
Daniel Atallah <datallah@pidgin.im>
parents:
16750
diff
changeset
|
465 | int major = 0, minor = 0, micro = 0; |
|
877897645980
Don't load the tcl loader plugin on Windows unless ActiveTcl 8.4.5 or newer is present. Fixes #538.
Daniel Atallah <datallah@pidgin.im>
parents:
16750
diff
changeset
|
466 | |
|
877897645980
Don't load the tcl loader plugin on Windows unless ActiveTcl 8.4.5 or newer is present. Fixes #538.
Daniel Atallah <datallah@pidgin.im>
parents:
16750
diff
changeset
|
467 | tokens = g_strsplit(version, ".", 0); |
|
877897645980
Don't load the tcl loader plugin on Windows unless ActiveTcl 8.4.5 or newer is present. Fixes #538.
Daniel Atallah <datallah@pidgin.im>
parents:
16750
diff
changeset
|
468 | if (tokens[0] && tokens[1] && tokens[2]) { |
|
877897645980
Don't load the tcl loader plugin on Windows unless ActiveTcl 8.4.5 or newer is present. Fixes #538.
Daniel Atallah <datallah@pidgin.im>
parents:
16750
diff
changeset
|
469 | major = atoi(tokens[0]); |
|
877897645980
Don't load the tcl loader plugin on Windows unless ActiveTcl 8.4.5 or newer is present. Fixes #538.
Daniel Atallah <datallah@pidgin.im>
parents:
16750
diff
changeset
|
470 | minor = atoi(tokens[1]); |
|
877897645980
Don't load the tcl loader plugin on Windows unless ActiveTcl 8.4.5 or newer is present. Fixes #538.
Daniel Atallah <datallah@pidgin.im>
parents:
16750
diff
changeset
|
471 | micro = atoi(tokens[2]); |
|
877897645980
Don't load the tcl loader plugin on Windows unless ActiveTcl 8.4.5 or newer is present. Fixes #538.
Daniel Atallah <datallah@pidgin.im>
parents:
16750
diff
changeset
|
472 | } |
|
877897645980
Don't load the tcl loader plugin on Windows unless ActiveTcl 8.4.5 or newer is present. Fixes #538.
Daniel Atallah <datallah@pidgin.im>
parents:
16750
diff
changeset
|
473 | g_strfreev(tokens); |
| 14913 | 474 | |
| 475 | regkey2 = g_strdup_printf("%s%s\\", regkey, version); | |
|
17629
877897645980
Don't load the tcl loader plugin on Windows unless ActiveTcl 8.4.5 or newer is present. Fixes #538.
Daniel Atallah <datallah@pidgin.im>
parents:
16750
diff
changeset
|
476 | if (!(major == 8 && minor == 4 && micro >= 5)) |
|
877897645980
Don't load the tcl loader plugin on Windows unless ActiveTcl 8.4.5 or newer is present. Fixes #538.
Daniel Atallah <datallah@pidgin.im>
parents:
16750
diff
changeset
|
477 | purple_debug(PURPLE_DEBUG_INFO, "tcl", "Unsupported ActiveTCL version %s found.\n", version); |
|
877897645980
Don't load the tcl loader plugin on Windows unless ActiveTcl 8.4.5 or newer is present. Fixes #538.
Daniel Atallah <datallah@pidgin.im>
parents:
16750
diff
changeset
|
478 | else if ((path = wpurple_read_reg_string(HKEY_LOCAL_MACHINE, regkey2, NULL)) || (path = wpurple_read_reg_string(HKEY_CURRENT_USER, regkey2, NULL))) { |
| 14913 | 479 | char *tclpath; |
| 480 | char *tkpath; | |
| 481 | ||
| 15884 | 482 | 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
|
483 | |
| 14913 | 484 | tclpath = g_build_filename(path, "bin", "tcl84.dll", NULL); |
| 485 | tkpath = g_build_filename(path, "bin", "tk84.dll", NULL); | |
| 486 | ||
| 15884 | 487 | if(!(wtcl_CreateInterp = (LPFNTCLCREATEINTERP) wpurple_find_and_loadproc(tclpath, "Tcl_CreateInterp"))) { |
| 488 | purple_debug(PURPLE_DEBUG_INFO, "tcl", "tcl_win32_init error loading Tcl_CreateInterp\n"); | |
| 14913 | 489 | } else { |
| 15884 | 490 | if(!(wtk_Init = (LPFNTKINIT) wpurple_find_and_loadproc(tkpath, "Tk_Init"))) { |
| 14913 | 491 | HMODULE mod; |
| 15884 | 492 | purple_debug(PURPLE_DEBUG_INFO, "tcl", "tcl_win32_init error loading Tk_Init\n"); |
| 14913 | 493 | if((mod = GetModuleHandle("tcl84.dll"))) |
| 494 | FreeLibrary(mod); | |
| 495 | } else { | |
| 496 | retval = TRUE; | |
| 497 | } | |
| 498 | } | |
| 499 | g_free(tclpath); | |
| 500 | g_free(tkpath); | |
| 501 | } | |
| 502 | g_free(path); | |
| 503 | g_free(regkey2); | |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
504 | } |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
505 | |
| 14913 | 506 | g_free(version); |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
507 | |
| 14913 | 508 | if (!retval) |
| 15884 | 509 | 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
|
510 | |
| 14913 | 511 | return retval; |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
512 | } |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
513 | |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
514 | #endif /* _WIN32 */ |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
515 | |
| 15884 | 516 | static void tcl_init_plugin(PurplePlugin *plugin) |
| 6694 | 517 | { |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
518 | #ifdef USE_TCL_STUBS |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
519 | Tcl_Interp *interp = NULL; |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
520 | #endif |
| 6694 | 521 | _tcl_plugin = plugin; |
| 522 | ||
|
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 | #ifdef _WIN32 |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
525 | if(!tcl_win32_init()) |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
526 | return; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
527 | #endif |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
528 | if(!(interp = Tcl_CreateInterp())) |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
529 | return; |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
530 | |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
531 | if(!Tcl_InitStubs(interp, TCL_VERSION, 0)) { |
| 15884 | 532 | 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
|
533 | return; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
534 | } |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
535 | #endif |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
536 | |
| 15884 | 537 | Tcl_FindExecutable("purple"); |
| 6694 | 538 | |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
539 | #if defined(USE_TK_STUBS) && defined(HAVE_TK) |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
540 | Tk_Init(interp); |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
541 | |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
542 | if(!Tk_InitStubs(interp, TK_VERSION, 0)) { |
| 15884 | 543 | 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
|
544 | Tcl_DeleteInterp(interp); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
545 | return; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
546 | } |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
547 | #endif |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
548 | tcl_loaded = TRUE; |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
549 | #ifdef USE_TCL_STUBS |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
550 | Tcl_DeleteInterp(interp); |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
551 | #endif |
| 6694 | 552 | tcl_loader_info.exts = g_list_append(tcl_loader_info.exts, "tcl"); |
| 553 | } | |
| 554 | ||
| 15884 | 555 | PURPLE_INIT_PLUGIN(tcl, tcl_init_plugin, tcl_info) |