| 246 plugin_info = perl_get_hv("PLUGIN_INFO", FALSE); |
244 plugin_info = perl_get_hv("PLUGIN_INFO", FALSE); |
| 247 |
245 |
| 248 if (plugin_info == NULL) |
246 if (plugin_info == NULL) |
| 249 status = FALSE; |
247 status = FALSE; |
| 250 else if (!hv_exists(plugin_info, "perl_api_version", |
248 else if (!hv_exists(plugin_info, "perl_api_version", |
| 251 strlen("perl_api_version")) || |
249 strlen("perl_api_version")) || |
| 252 !hv_exists(plugin_info, "name", strlen("name")) || |
250 !hv_exists(plugin_info, "name", strlen("name")) || |
| 253 !hv_exists(plugin_info, "load", strlen("load"))) |
251 !hv_exists(plugin_info, "load", strlen("load"))) { |
| 254 { |
|
| 255 /* Not a valid plugin. */ |
252 /* Not a valid plugin. */ |
| 256 |
253 |
| 257 status = FALSE; |
254 status = FALSE; |
| 258 } |
255 } else { |
| 259 else |
|
| 260 { |
|
| 261 SV **key; |
256 SV **key; |
| 262 int perl_api_ver; |
257 int perl_api_ver; |
| 263 |
258 |
| 264 key = hv_fetch(plugin_info, "perl_api_version", |
259 key = hv_fetch(plugin_info, "perl_api_version", |
| 265 strlen("perl_api_version"), 0); |
260 strlen("perl_api_version"), 0); |
| 266 |
261 |
| 267 perl_api_ver = SvIV(*key); |
262 perl_api_ver = SvIV(*key); |
| 268 |
263 |
| 269 if (perl_api_ver != 2) |
264 if (perl_api_ver != 2) |
| 270 status = FALSE; |
265 status = FALSE; |
| 271 else |
266 else { |
| 272 { |
|
| 273 GaimPluginInfo *info; |
267 GaimPluginInfo *info; |
| 274 GaimPerlScript *gps; |
268 GaimPerlScript *gps; |
| 275 char *basename; |
269 char *basename; |
| 276 STRLEN len; |
270 STRLEN len; |
| 277 |
271 |
| 278 gaim_debug(GAIM_DEBUG_INFO, "perl", "Found plugin info\n"); |
272 gaim_debug(GAIM_DEBUG_INFO, "perl", |
| |
273 "Found plugin info\n"); |
| 279 |
274 |
| 280 info = g_new0(GaimPluginInfo, 1); |
275 info = g_new0(GaimPluginInfo, 1); |
| 281 gps = g_new0(GaimPerlScript, 1); |
276 gps = g_new0(GaimPerlScript, 1); |
| 282 |
277 |
| 283 info->magic = GAIM_PLUGIN_MAGIC; |
278 info->magic = GAIM_PLUGIN_MAGIC; |
| 284 info->major_version = GAIM_MAJOR_VERSION; |
279 info->major_version = GAIM_MAJOR_VERSION; |
| 285 info->minor_version = GAIM_MINOR_VERSION; |
280 info->minor_version = GAIM_MINOR_VERSION; |
| 286 info->type = GAIM_PLUGIN_STANDARD; |
281 info->type = GAIM_PLUGIN_STANDARD; |
| 287 |
282 |
| 288 info->dependencies = g_list_append(info->dependencies, |
283 info->dependencies = g_list_append(info->dependencies, |
| 289 PERL_PLUGIN_ID); |
284 PERL_PLUGIN_ID); |
| 290 |
285 |
| 291 gps->plugin = plugin; |
286 gps->plugin = plugin; |
| 292 |
287 |
| 293 basename = g_path_get_basename(plugin->path); |
288 basename = g_path_get_basename(plugin->path); |
| 294 gaim_perl_normalize_script_name(basename); |
289 gaim_perl_normalize_script_name(basename); |
| 295 gps->package = g_strdup_printf("Gaim::Script::%s", basename); |
290 gps->package = g_strdup_printf("Gaim::Script::%s", |
| |
291 basename); |
| 296 g_free(basename); |
292 g_free(basename); |
| 297 |
293 |
| 298 /* We know this one exists. */ |
294 /* We know this one exists. */ |
| 299 key = hv_fetch(plugin_info, "name", strlen("name"), 0); |
295 key = hv_fetch(plugin_info, "name", strlen("name"), 0); |
| 300 info->name = g_strdup(SvPV(*key, len)); |
296 info->name = g_strdup(SvPV(*key, len)); |
| 301 |
297 |
| 302 if ((key = hv_fetch(plugin_info, "GTK_UI", strlen("GTK_UI"), 0))) |
298 if ((key = hv_fetch(plugin_info, "GTK_UI", |
| |
299 strlen("GTK_UI"), 0))) |
| 303 info->ui_requirement = GAIM_GTK_PLUGIN_TYPE; |
300 info->ui_requirement = GAIM_GTK_PLUGIN_TYPE; |
| 304 |
301 |
| 305 if ((key = hv_fetch(plugin_info, "url", strlen("url"), 0))) |
302 if ((key = hv_fetch(plugin_info, "url", |
| |
303 strlen("url"), 0))) |
| 306 info->homepage = g_strdup(SvPV(*key, len)); |
304 info->homepage = g_strdup(SvPV(*key, len)); |
| 307 |
305 |
| 308 if ((key = hv_fetch(plugin_info, "author", strlen("author"), 0))) |
306 if ((key = hv_fetch(plugin_info, "author", |
| |
307 strlen("author"), 0))) |
| 309 info->author = g_strdup(SvPV(*key, len)); |
308 info->author = g_strdup(SvPV(*key, len)); |
| 310 |
309 |
| 311 if ((key = hv_fetch(plugin_info, "summary", |
310 if ((key = hv_fetch(plugin_info, "summary", |
| 312 strlen("summary"), 0))) |
311 strlen("summary"), 0))) |
| 313 info->summary = g_strdup(SvPV(*key, len)); |
312 info->summary = g_strdup(SvPV(*key, len)); |
| 314 |
313 |
| 315 if ((key = hv_fetch(plugin_info, "description", |
314 if ((key = hv_fetch(plugin_info, "description", |
| 316 strlen("description"), 0))) |
315 strlen("description"), 0))) |
| 317 info->description = g_strdup(SvPV(*key, len)); |
316 info->description = g_strdup(SvPV(*key, len)); |
| 318 |
317 |
| 319 if ((key = hv_fetch(plugin_info, "version", strlen("version"), 0))) |
318 if ((key = hv_fetch(plugin_info, "version", |
| |
319 strlen("version"), 0))) |
| 320 info->version = g_strdup(SvPV(*key, len)); |
320 info->version = g_strdup(SvPV(*key, len)); |
| 321 |
321 |
| 322 if ((key = hv_fetch(plugin_info, "load", strlen("load"), 0))) |
322 if ((key = hv_fetch(plugin_info, "load", |
| 323 gps->load_sub = g_strdup_printf("%s::%s", gps->package, |
323 strlen("load"), 0))) |
| 324 SvPV(*key, len)); |
324 gps->load_sub = g_strdup_printf("%s::%s", |
| 325 |
325 gps->package, |
| 326 if ((key = hv_fetch(plugin_info, "unload", strlen("unload"), 0))) |
326 SvPV(*key, len)); |
| 327 gps->unload_sub = g_strdup_printf("%s::%s", gps->package, |
327 |
| 328 SvPV(*key, len)); |
328 if ((key = hv_fetch(plugin_info, "unload", |
| 329 |
329 strlen("unload"), 0))) |
| 330 /********************************************************/ |
330 gps->unload_sub = g_strdup_printf("%s::%s", |
| 331 /* Only one of the next two options should be present */ |
331 gps->package, |
| 332 /* */ |
332 SvPV(*key, len)); |
| 333 /* prefs_info - Uses non-GUI (read GTK) gaim API calls */ |
333 |
| 334 /* and creates a GaimPluginPrefInfo type. */ |
334 /********************************************************/ |
| 335 /* */ |
335 /* Only one of the next two options should be present */ |
| 336 /* gtk_prefs_info - Requires gtk2-perl be installed by */ |
336 /* */ |
| 337 /* the user and he must create a GtkWidget */ |
337 /* prefs_info - Uses non-GUI (read GTK) gaim API calls */ |
| 338 /* representing the plugin preferences */ |
338 /* and creates a GaimPluginPrefInfo type. */ |
| 339 /* page. */ |
339 /* */ |
| 340 /********************************************************/ |
340 /* gtk_prefs_info - Requires gtk2-perl be installed by */ |
| 341 if ((key = hv_fetch(plugin_info, "prefs_info", strlen("prefs_info"), 0))) { |
341 /* the user and he must create a GtkWidget */ |
| |
342 /* representing the plugin preferences */ |
| |
343 /* page. */ |
| |
344 /********************************************************/ |
| |
345 if ((key = hv_fetch(plugin_info, "prefs_info", |
| |
346 strlen("prefs_info"), 0))) { |
| 342 char *tmp = g_strdup_printf("%s::%s", gps->package, SvPV(*key, len)); |
347 char *tmp = g_strdup_printf("%s::%s", gps->package, SvPV(*key, len)); |
| 343 /* key now is the name of the Perl sub that will create a frame for us */ |
348 /* key now is the name of the Perl sub that |
| |
349 * will create a frame for us */ |
| 344 info->prefs_info = gaim_perl_plugin_pref(tmp); |
350 info->prefs_info = gaim_perl_plugin_pref(tmp); |
| 345 g_free(tmp); |
351 g_free(tmp); |
| 346 } |
352 } |
| 347 |
353 |
| 348 if ((key = hv_fetch(plugin_info, "gtk_prefs_info", strlen("gtk_prefs_info"), 0))) { |
354 if ((key = hv_fetch(plugin_info, "gtk_prefs_info", |
| |
355 strlen("gtk_prefs_info"), 0))) { |
| 349 char *tmp = g_strdup_printf("%s::%s", gps->package, SvPV(*key, len)); |
356 char *tmp = g_strdup_printf("%s::%s", gps->package, SvPV(*key, len)); |
| 350 /* key now is the name of the Perl sub that will create a frame for us */ |
357 /* key now is the name of the Perl sub that |
| |
358 * will create a frame for us */ |
| 351 info->ui_info = gaim_perl_gtk_plugin_pref(tmp); |
359 info->ui_info = gaim_perl_gtk_plugin_pref(tmp); |
| 352 g_free(tmp); |
360 g_free(tmp); |
| 353 } |
361 } |
| 354 |
362 |
| 355 /********************************************************/ |
363 /********************************************************/ |
| 356 /* */ |
364 /* */ |
| 357 /* plugin_action - This is given to the plugin info */ |
365 /* plugin_action - This is given to the plugin info */ |
| 358 /* as the action GList. There are two parts */ |
366 /* as the action GList. There are two */ |
| 359 /* so the user can set the title as it will appear */ |
367 /* parts so the user can set the title */ |
| 360 /* in the plugin action menu. The name is */ |
368 /* as it will appear in the plugin */ |
| 361 /* extracted and then the callback perl sub's name */ |
369 /* action menu. The name is extracted */ |
| 362 /* both of which then are handled by an internal */ |
370 /* and then the callback perl sub's */ |
| 363 /* gaim_perl function that sets up the single cb */ |
371 /* name both of which then are handled */ |
| 364 /* function which is then inserted into 'info'. */ |
372 /* by an internal gaim_perl function */ |
| 365 /********************************************************/ |
373 /* that sets up the single cb function */ |
| 366 if ((key = hv_fetch(plugin_info, "plugin_action_label", strlen("plugin_action_label"), 0))) { |
374 /* which is then inserted into 'info'. */ |
| |
375 /********************************************************/ |
| |
376 if ((key = hv_fetch(plugin_info, "plugin_action_label", |
| |
377 strlen("plugin_action_label"), 0))) { |
| 367 gaim_perl_plugin_action_label = g_strdup(SvPV(*key, len)); |
378 gaim_perl_plugin_action_label = g_strdup(SvPV(*key, len)); |
| 368 } |
379 } |
| 369 |
380 |
| 370 if ((key = hv_fetch(plugin_info, "plugin_action", strlen("plugin_action"), 0))) { |
381 if ((key = hv_fetch(plugin_info, "plugin_action", |
| |
382 strlen("plugin_action"), 0))) { |
| 371 gaim_perl_plugin_action_callback_sub = g_strdup_printf("%s::%s", gps->package, SvPV(*key, len)); |
383 gaim_perl_plugin_action_callback_sub = g_strdup_printf("%s::%s", gps->package, SvPV(*key, len)); |
| 372 info->actions = gaim_perl_plugin_action; |
384 info->actions = gaim_perl_plugin_action; |
| 373 } |
385 } |
| 374 |
386 |
| 375 plugin->info = info; |
387 plugin->info = info; |
| 376 info->extra_info = gps; |
388 info->extra_info = gps; |
| 377 |
389 |
| 378 status = gaim_plugin_register(plugin); |
390 status = gaim_plugin_register(plugin); |
| 379 } |
391 } |
| 380 } |
392 } |
| 381 |
393 |
| 382 PL_perl_destruct_level = 1; |
394 PL_perl_destruct_level = 1; |
| 383 PERL_SET_CONTEXT(prober); |
395 PERL_SET_CONTEXT(prober); |
| 384 perl_destruct(prober); |
396 perl_destruct(prober); |
| 385 perl_free(prober); |
397 perl_free(prober); |
| 386 return status; |
398 return status; |
| 387 } |
399 } |
| 388 |
400 |