Fix a crash when remote users have certain characters in their
[pidgin-git.git] / libpurple / plugin.h
blob9225aecd9260ffa17d7a727394eb9c37f263f53a
1 /**
2 * @file plugin.h Plugin API
3 * @ingroup core
4 * @see @ref plugin-signals
5 * @see @ref plugin-ids
6 * @see @ref plugin-i18n
7 */
9 /* purple
11 * Purple is the legal property of its developers, whose names are too numerous
12 * to list here. Please refer to the COPYRIGHT file distributed with this
13 * source distribution.
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
29 #ifndef _PURPLE_PLUGIN_H_
30 #define _PURPLE_PLUGIN_H_
32 #include <glib.h>
33 #include <gmodule.h>
34 #include "signals.h"
35 #include "value.h"
37 /** @copydoc _PurplePlugin */
38 typedef struct _PurplePlugin PurplePlugin;
39 /** @copydoc _PurplePluginInfo */
40 typedef struct _PurplePluginInfo PurplePluginInfo;
41 /** @copydoc _PurplePluginUiInfo */
42 typedef struct _PurplePluginUiInfo PurplePluginUiInfo;
43 /** @copydoc _PurplePluginLoaderInfo */
44 typedef struct _PurplePluginLoaderInfo PurplePluginLoaderInfo;
46 /** @copydoc _PurplePluginAction */
47 typedef struct _PurplePluginAction PurplePluginAction;
49 typedef int PurplePluginPriority; /**< Plugin priority. */
51 #include "pluginpref.h"
53 /**
54 * Plugin types.
56 typedef enum
58 PURPLE_PLUGIN_UNKNOWN = -1, /**< Unknown type. */
59 PURPLE_PLUGIN_STANDARD = 0, /**< Standard plugin. */
60 PURPLE_PLUGIN_LOADER, /**< Loader plugin. */
61 PURPLE_PLUGIN_PROTOCOL /**< Protocol plugin. */
63 } PurplePluginType;
65 #define PURPLE_PRIORITY_DEFAULT 0
66 #define PURPLE_PRIORITY_HIGHEST 9999
67 #define PURPLE_PRIORITY_LOWEST -9999
69 #define PURPLE_PLUGIN_FLAG_INVISIBLE 0x01
71 #define PURPLE_PLUGIN_MAGIC 5 /* once we hit 6.0.0 I think we can remove this */
73 /**
74 * Detailed information about a plugin.
76 * This is used in the version 2.0 API and up.
78 struct _PurplePluginInfo
80 unsigned int magic;
81 unsigned int major_version;
82 unsigned int minor_version;
83 PurplePluginType type;
84 char *ui_requirement;
85 unsigned long flags;
86 GList *dependencies;
87 PurplePluginPriority priority;
89 char *id;
90 char *name;
91 char *version;
92 char *summary;
93 char *description;
94 char *author;
95 char *homepage;
97 /**
98 * If a plugin defines a 'load' function, and it returns FALSE,
99 * then the plugin will not be loaded.
101 gboolean (*load)(PurplePlugin *plugin);
102 gboolean (*unload)(PurplePlugin *plugin);
103 void (*destroy)(PurplePlugin *plugin);
105 void *ui_info; /**< Used only by UI-specific plugins to build a preference screen with a custom UI */
106 void *extra_info;
107 PurplePluginUiInfo *prefs_info; /**< Used by any plugin to display preferences. If #ui_info has been specified, this will be ignored. */
110 * This callback has a different use depending on whether this
111 * plugin type is PURPLE_PLUGIN_STANDARD or PURPLE_PLUGIN_PROTOCOL.
113 * If PURPLE_PLUGIN_STANDARD then the list of actions will show up
114 * in the Tools menu, under a submenu with the name of the plugin.
115 * context will be NULL.
117 * If PURPLE_PLUGIN_PROTOCOL then the list of actions will show up
118 * in the Accounts menu, under a submenu with the name of the
119 * account. context will be set to the PurpleConnection for that
120 * account. This callback will only be called for online accounts.
122 GList *(*actions)(PurplePlugin *plugin, gpointer context);
124 void (*_purple_reserved1)(void);
125 void (*_purple_reserved2)(void);
126 void (*_purple_reserved3)(void);
127 void (*_purple_reserved4)(void);
131 * Extra information for loader plugins.
133 struct _PurplePluginLoaderInfo
135 GList *exts;
137 gboolean (*probe)(PurplePlugin *plugin);
138 gboolean (*load)(PurplePlugin *plugin);
139 gboolean (*unload)(PurplePlugin *plugin);
140 void (*destroy)(PurplePlugin *plugin);
142 void (*_purple_reserved1)(void);
143 void (*_purple_reserved2)(void);
144 void (*_purple_reserved3)(void);
145 void (*_purple_reserved4)(void);
149 * A plugin handle.
151 struct _PurplePlugin
153 gboolean native_plugin; /**< Native C plugin. */
154 gboolean loaded; /**< The loaded state. */
155 void *handle; /**< The module handle. */
156 char *path; /**< The path to the plugin. */
157 PurplePluginInfo *info; /**< The plugin information. */
158 char *error;
159 void *ipc_data; /**< IPC data. */
160 void *extra; /**< Plugin-specific data. */
161 gboolean unloadable; /**< Unloadable */
162 GList *dependent_plugins; /**< Plugins depending on this */
164 void (*_purple_reserved1)(void);
165 void (*_purple_reserved2)(void);
166 void (*_purple_reserved3)(void);
167 void (*_purple_reserved4)(void);
170 #define PURPLE_PLUGIN_LOADER_INFO(plugin) \
171 ((PurplePluginLoaderInfo *)(plugin)->info->extra_info)
173 struct _PurplePluginUiInfo {
174 PurplePluginPrefFrame *(*get_plugin_pref_frame)(PurplePlugin *plugin);
176 int page_num; /**< Reserved */
177 PurplePluginPrefFrame *frame; /**< Reserved */
179 void (*_purple_reserved1)(void);
180 void (*_purple_reserved2)(void);
181 void (*_purple_reserved3)(void);
182 void (*_purple_reserved4)(void);
185 #define PURPLE_PLUGIN_HAS_PREF_FRAME(plugin) \
186 ((plugin)->info != NULL && (plugin)->info->prefs_info != NULL)
188 #define PURPLE_PLUGIN_UI_INFO(plugin) \
189 ((PurplePluginUiInfo*)(plugin)->info->prefs_info)
193 * The structure used in the actions member of PurplePluginInfo
195 struct _PurplePluginAction {
196 char *label;
197 void (*callback)(PurplePluginAction *);
199 /** set to the owning plugin */
200 PurplePlugin *plugin;
202 /** NULL for plugin actions menu, set to the PurpleConnection for
203 account actions menu */
204 gpointer context;
206 gpointer user_data;
209 #define PURPLE_PLUGIN_HAS_ACTIONS(plugin) \
210 ((plugin)->info != NULL && (plugin)->info->actions != NULL)
212 #define PURPLE_PLUGIN_ACTIONS(plugin, context) \
213 (PURPLE_PLUGIN_HAS_ACTIONS(plugin)? \
214 (plugin)->info->actions(plugin, context): NULL)
218 * Handles the initialization of modules.
220 #if !defined(PURPLE_PLUGINS) || defined(PURPLE_STATIC_PRPL)
221 # define _FUNC_NAME(x) purple_init_##x##_plugin
222 # define PURPLE_INIT_PLUGIN(pluginname, initfunc, plugininfo) \
223 gboolean _FUNC_NAME(pluginname)(void);\
224 gboolean _FUNC_NAME(pluginname)(void) { \
225 PurplePlugin *plugin = purple_plugin_new(TRUE, NULL); \
226 plugin->info = &(plugininfo); \
227 initfunc((plugin)); \
228 purple_plugin_load((plugin)); \
229 return purple_plugin_register(plugin); \
231 #else /* PURPLE_PLUGINS && !PURPLE_STATIC_PRPL */
232 # define PURPLE_INIT_PLUGIN(pluginname, initfunc, plugininfo) \
233 G_MODULE_EXPORT gboolean purple_init_plugin(PurplePlugin *plugin); \
234 G_MODULE_EXPORT gboolean purple_init_plugin(PurplePlugin *plugin) { \
235 plugin->info = &(plugininfo); \
236 initfunc((plugin)); \
237 return purple_plugin_register(plugin); \
239 #endif
242 #ifdef __cplusplus
243 extern "C" {
244 #endif
246 /**************************************************************************/
247 /** @name Plugin API */
248 /**************************************************************************/
249 /*@{*/
252 * Creates a new plugin structure.
254 * @param native Whether or not the plugin is native.
255 * @param path The path to the plugin, or @c NULL if statically compiled.
257 * @return A new PurplePlugin structure.
259 PurplePlugin *purple_plugin_new(gboolean native, const char *path);
262 * Probes a plugin, retrieving the information on it and adding it to the
263 * list of available plugins.
265 * @param filename The plugin's filename.
267 * @return The plugin handle.
269 * @see purple_plugin_load()
270 * @see purple_plugin_destroy()
272 PurplePlugin *purple_plugin_probe(const char *filename);
275 * Registers a plugin and prepares it for loading.
277 * This shouldn't be called by anything but the internal module code.
278 * Plugins should use the PURPLE_INIT_PLUGIN() macro to register themselves
279 * with the core.
281 * @param plugin The plugin to register.
283 * @return @c TRUE if the plugin was registered successfully. Otherwise
284 * @c FALSE is returned (this happens if the plugin does not contain
285 * the necessary information).
287 gboolean purple_plugin_register(PurplePlugin *plugin);
290 * Attempts to load a previously probed plugin.
292 * @param plugin The plugin to load.
294 * @return @c TRUE if successful, or @c FALSE otherwise.
296 * @see purple_plugin_reload()
297 * @see purple_plugin_unload()
299 gboolean purple_plugin_load(PurplePlugin *plugin);
302 * Unloads the specified plugin.
304 * @param plugin The plugin handle.
306 * @return @c TRUE if successful, or @c FALSE otherwise.
308 * @see purple_plugin_load()
309 * @see purple_plugin_reload()
311 gboolean purple_plugin_unload(PurplePlugin *plugin);
314 * Disable a plugin.
316 * This function adds the plugin to a list of plugins to "disable at the next
317 * startup" by excluding said plugins from the list of plugins to save. The
318 * UI needs to call purple_plugins_save_loaded() after calling this for it
319 * to have any effect.
321 * @since 2.3.0
323 void purple_plugin_disable(PurplePlugin *plugin);
326 * Reloads a plugin.
328 * @param plugin The old plugin handle.
330 * @return @c TRUE if successful, or @c FALSE otherwise.
332 * @see purple_plugin_load()
333 * @see purple_plugin_unload()
335 gboolean purple_plugin_reload(PurplePlugin *plugin);
338 * Unloads a plugin and destroys the structure from memory.
340 * @param plugin The plugin handle.
342 void purple_plugin_destroy(PurplePlugin *plugin);
345 * Returns whether or not a plugin is currently loaded.
347 * @param plugin The plugin.
349 * @return @c TRUE if loaded, or @c FALSE otherwise.
351 gboolean purple_plugin_is_loaded(const PurplePlugin *plugin);
354 * Returns whether or not a plugin is unloadable.
356 * If this returns @c TRUE, the plugin is guaranteed to not
357 * be loadable. However, a return value of @c FALSE does not
358 * guarantee the plugin is loadable.
360 * @param plugin The plugin.
362 * @return @c TRUE if the plugin is known to be unloadable,\
363 * @c FALSE otherwise
365 gboolean purple_plugin_is_unloadable(const PurplePlugin *plugin);
368 * Returns a plugin's id.
370 * @param plugin The plugin.
372 * @return The plugin's id.
374 const gchar *purple_plugin_get_id(const PurplePlugin *plugin);
377 * Returns a plugin's name.
379 * @param plugin The plugin.
381 * @return THe name of the plugin, or @c NULL.
383 const gchar *purple_plugin_get_name(const PurplePlugin *plugin);
386 * Returns a plugin's version.
388 * @param plugin The plugin.
390 * @return The plugin's version or @c NULL.
392 const gchar *purple_plugin_get_version(const PurplePlugin *plugin);
395 * Returns a plugin's summary.
397 * @param plugin The plugin.
399 * @return The plugin's summary.
401 const gchar *purple_plugin_get_summary(const PurplePlugin *plugin);
404 * Returns a plugin's description.
406 * @param plugin The plugin.
408 * @return The plugin's description.
410 const gchar *purple_plugin_get_description(const PurplePlugin *plugin);
413 * Returns a plugin's author.
415 * @param plugin The plugin.
417 * @return The plugin's author.
419 const gchar *purple_plugin_get_author(const PurplePlugin *plugin);
422 * Returns a plugin's homepage.
424 * @param plugin The plugin.
426 * @return The plugin's homepage.
428 const gchar *purple_plugin_get_homepage(const PurplePlugin *plugin);
430 /*@}*/
432 /**************************************************************************/
433 /** @name Plugin IPC API */
434 /**************************************************************************/
435 /*@{*/
438 * Registers an IPC command in a plugin.
440 * @param plugin The plugin to register the command with.
441 * @param command The name of the command.
442 * @param func The function to execute.
443 * @param marshal The marshalling function.
444 * @param ret_value The return value type.
445 * @param num_params The number of parameters.
446 * @param ... The parameter types.
448 * @return TRUE if the function was registered successfully, or
449 * FALSE otherwise.
451 gboolean purple_plugin_ipc_register(PurplePlugin *plugin, const char *command,
452 PurpleCallback func,
453 PurpleSignalMarshalFunc marshal,
454 PurpleValue *ret_value, int num_params, ...);
457 * Unregisters an IPC command in a plugin.
459 * @param plugin The plugin to unregister the command from.
460 * @param command The name of the command.
462 void purple_plugin_ipc_unregister(PurplePlugin *plugin, const char *command);
465 * Unregisters all IPC commands in a plugin.
467 * @param plugin The plugin to unregister the commands from.
469 void purple_plugin_ipc_unregister_all(PurplePlugin *plugin);
472 * Returns a list of value types used for an IPC command.
474 * @param plugin The plugin.
475 * @param command The name of the command.
476 * @param ret_value The returned return value.
477 * @param num_params The returned number of parameters.
478 * @param params The returned list of parameters.
480 * @return TRUE if the command was found, or FALSE otherwise.
482 gboolean purple_plugin_ipc_get_params(PurplePlugin *plugin, const char *command,
483 PurpleValue **ret_value, int *num_params,
484 PurpleValue ***params);
487 * Executes an IPC command.
489 * @param plugin The plugin to execute the command on.
490 * @param command The name of the command.
491 * @param ok TRUE if the call was successful, or FALSE otherwise.
492 * @param ... The parameters to pass.
494 * @return The return value, which will be NULL if the command doesn't
495 * return a value.
497 void *purple_plugin_ipc_call(PurplePlugin *plugin, const char *command,
498 gboolean *ok, ...);
500 /*@}*/
502 /**************************************************************************/
503 /** @name Plugins API */
504 /**************************************************************************/
505 /*@{*/
508 * Add a new directory to search for plugins
510 * @param path The new search path.
512 void purple_plugins_add_search_path(const char *path);
515 * Returns a list of plugin search paths.
517 * @constreturn A list of searched paths.
519 * @since 2.6.0
521 GList *purple_plugins_get_search_paths(void);
524 * Unloads all loaded plugins.
526 void purple_plugins_unload_all(void);
529 * Unloads all plugins of a specific type.
531 void purple_plugins_unload(PurplePluginType type);
534 * Destroys all registered plugins.
536 void purple_plugins_destroy_all(void);
539 * Saves the list of loaded plugins to the specified preference key
541 * @param key The preference key to save the list of plugins to.
543 void purple_plugins_save_loaded(const char *key);
546 * Attempts to load all the plugins in the specified preference key
547 * that were loaded when purple last quit.
549 * @param key The preference key containing the list of plugins.
551 void purple_plugins_load_saved(const char *key);
554 * Probes for plugins in the registered module paths.
556 * @param ext The extension type to probe for, or @c NULL for all.
558 * @see purple_plugin_set_probe_path()
560 void purple_plugins_probe(const char *ext);
563 * Returns whether or not plugin support is enabled.
565 * @return TRUE if plugin support is enabled, or FALSE otherwise.
567 gboolean purple_plugins_enabled(void);
569 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_PLUGIN_C_)
571 * Registers a function that will be called when probing is finished.
573 * @param func The callback function.
574 * @param data Data to pass to the callback.
575 * @deprecated If you need this, ask for a plugin-probe signal to be added.
577 void purple_plugins_register_probe_notify_cb(void (*func)(void *), void *data);
578 #endif
580 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_PLUGIN_C_)
582 * Unregisters a function that would be called when probing is finished.
584 * @param func The callback function.
585 * @deprecated If you need this, ask for a plugin-probe signal to be added.
587 void purple_plugins_unregister_probe_notify_cb(void (*func)(void *));
588 #endif
590 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_PLUGIN_C_)
592 * Registers a function that will be called when a plugin is loaded.
594 * @param func The callback function.
595 * @param data Data to pass to the callback.
596 * @deprecated Use the plugin-load signal instead.
598 void purple_plugins_register_load_notify_cb(void (*func)(PurplePlugin *, void *),
599 void *data);
600 #endif
602 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_PLUGIN_C_)
604 * Unregisters a function that would be called when a plugin is loaded.
606 * @param func The callback function.
607 * @deprecated Use the plugin-load signal instead.
609 void purple_plugins_unregister_load_notify_cb(void (*func)(PurplePlugin *, void *));
610 #endif
612 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_PLUGIN_C_)
614 * Registers a function that will be called when a plugin is unloaded.
616 * @param func The callback function.
617 * @param data Data to pass to the callback.
618 * @deprecated Use the plugin-unload signal instead.
620 void purple_plugins_register_unload_notify_cb(void (*func)(PurplePlugin *, void *),
621 void *data);
622 #endif
624 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_PLUGIN_C_)
626 * Unregisters a function that would be called when a plugin is unloaded.
628 * @param func The callback function.
629 * @deprecated Use the plugin-unload signal instead.
631 void purple_plugins_unregister_unload_notify_cb(void (*func)(PurplePlugin *,
632 void *));
633 #endif
636 * Finds a plugin with the specified name.
638 * @param name The plugin name.
640 * @return The plugin if found, or @c NULL if not found.
642 PurplePlugin *purple_plugins_find_with_name(const char *name);
645 * Finds a plugin with the specified filename (filename with a path).
647 * @param filename The plugin filename.
649 * @return The plugin if found, or @c NULL if not found.
651 PurplePlugin *purple_plugins_find_with_filename(const char *filename);
654 * Finds a plugin with the specified basename (filename without a path).
656 * @param basename The plugin basename.
658 * @return The plugin if found, or @c NULL if not found.
660 PurplePlugin *purple_plugins_find_with_basename(const char *basename);
663 * Finds a plugin with the specified plugin ID.
665 * @param id The plugin ID.
667 * @return The plugin if found, or @c NULL if not found.
669 PurplePlugin *purple_plugins_find_with_id(const char *id);
672 * Returns a list of all loaded plugins.
674 * @constreturn A list of all loaded plugins.
676 GList *purple_plugins_get_loaded(void);
679 * Returns a list of all valid protocol plugins. A protocol
680 * plugin is considered invalid if it does not contain the call
681 * to the PURPLE_INIT_PLUGIN() macro, or if it was compiled
682 * against an incompatable API version.
684 * @constreturn A list of all protocol plugins.
686 GList *purple_plugins_get_protocols(void);
689 * Returns a list of all plugins, whether loaded or not.
691 * @constreturn A list of all plugins.
693 GList *purple_plugins_get_all(void);
695 /*@}*/
697 /**************************************************************************/
698 /** @name Plugins SubSytem API */
699 /**************************************************************************/
700 /*@{*/
703 * Returns the plugin subsystem handle.
705 * @return The plugin sybsystem handle.
707 void *purple_plugins_get_handle(void);
710 * Initializes the plugin subsystem
712 void purple_plugins_init(void);
715 * Uninitializes the plugin subsystem
717 void purple_plugins_uninit(void);
719 /*@}*/
722 * Allocates and returns a new PurplePluginAction.
724 * @param label The description of the action to show to the user.
725 * @param callback The callback to call when the user selects this action.
727 PurplePluginAction *purple_plugin_action_new(const char* label, void (*callback)(PurplePluginAction *));
730 * Frees a PurplePluginAction
732 * @param action The PurplePluginAction to free.
734 void purple_plugin_action_free(PurplePluginAction *action);
736 #ifdef __cplusplus
738 #endif
740 #endif /* _PURPLE_PLUGIN_H_ */