X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmodules%2Fentry.c;h=60543db4312883ceb5866b2a3ece0ffe43ce35c7;hb=ffce1e460279dab9e890ae6f28074fb5bffc70d9;hp=3abc6cb8c725190b294b06a8107e30a5d7dc3fb6;hpb=8e17cc40106fd1b44b6f48fec0bdc1298b27c2bf;p=vlc diff --git a/src/modules/entry.c b/src/modules/entry.c index 3abc6cb8c7..60543db431 100644 --- a/src/modules/entry.c +++ b/src/modules/entry.c @@ -25,255 +25,287 @@ #include #include +#include #include #include +#include #include "modules/modules.h" #include "config/configuration.h" #include "libvlc.h" -static const char default_name[] = "unnamed"; +static char *strdup_null (const char *str) +{ + return (str != NULL) ? strdup (str) : NULL; +} -module_t *vlc_module_create (vlc_object_t *obj) +module_t *vlc_module_create (module_t *parent) { - module_t *module = - (module_t *)vlc_custom_create (obj, sizeof (module_t), - VLC_OBJECT_MODULE, "module"); + module_t *module = malloc (sizeof (*module)); if (module == NULL) return NULL; - module->b_reentrant = module->b_unloadable = true; - module->psz_object_name = strdup( default_name ); - module->psz_longname = default_name; - module->psz_capability = (char*)""; - module->i_score = 1; - module->i_config_items = module->i_bool_items = 0; + /* TODO: replace module/submodules with plugin/modules */ + if (parent == NULL) + { + module->next = NULL; + module->parent = NULL; + } + else + { + module->next = parent->submodule; + parent->submodule = module; + parent->submodule_count++; + module->parent = parent; + } + module->submodule = NULL; + module->submodule_count = 0; + + module->psz_shortname = NULL; + module->psz_longname = NULL; + module->psz_help = NULL; + module->pp_shortcuts = NULL; + module->i_shortcuts = 0; + module->psz_capability = NULL; + module->i_score = (parent != NULL) ? parent->i_score : 1; + module->b_loaded = false; + module->b_unloadable = parent == NULL; + module->pf_activate = NULL; + module->pf_deactivate = NULL; + module->p_config = NULL; + module->confsize = 0; + module->i_config_items = 0; + module->i_bool_items = 0; + /*module->handle = garbage */ + module->psz_filename = NULL; + module->domain = NULL; return module; } +/** + * Destroys a plug-in. + * @warning If the plug-in is loaded in memory, the handle will be leaked. + */ +void vlc_module_destroy (module_t *module) +{ + assert (!module->b_loaded || !module->b_unloadable); -module_t *vlc_submodule_create (module_t *module) + for (module_t *m = module->submodule, *next; m != NULL; m = next) + { + next = m->next; + vlc_module_destroy (m); + } + + config_Free (module->p_config, module->confsize); + + free (module->domain); + free (module->psz_filename); + for (unsigned i = 0; i < module->i_shortcuts; i++) + free (module->pp_shortcuts[i]); + free (module->pp_shortcuts); + free (module->psz_capability); + free (module->psz_help); + free (module->psz_longname); + free (module->psz_shortname); + free (module); +} + +static module_config_t *vlc_config_create (module_t *module, int type) { - assert (module != NULL); - assert (!module->b_submodule); // subsubmodules are not supported + unsigned confsize = module->confsize; + module_config_t *tab = module->p_config; - module_t *submodule = - (module_t *)vlc_custom_create (VLC_OBJECT (module), sizeof (module_t), - VLC_OBJECT_MODULE, "submodule"); - if (submodule == NULL) - return NULL; + if ((confsize & 0xf) == 0) + { + tab = realloc_or_free (tab, (confsize + 17) * sizeof (*tab)); + if (tab == NULL) + return NULL; - vlc_object_attach (submodule, module); - submodule->b_submodule = true; + module->p_config = tab; + } - /* Muahahaha! Heritage! Polymorphism! Ugliness!! */ - memcpy (submodule->pp_shortcuts, module->pp_shortcuts, - sizeof (submodule->pp_shortcuts)); + memset (tab + confsize, 0, sizeof (tab[confsize])); + if (IsConfigIntegerType (type)) + { + tab[confsize].max.i = INT_MAX; + tab[confsize].min.i = INT_MIN; + } + tab[confsize].i_type = type; + + if (CONFIG_ITEM(type)) + { + module->i_config_items++; + if (type == CONFIG_ITEM_BOOL) + module->i_bool_items++; + } - submodule->psz_object_name = strdup( module->psz_object_name ); - submodule->psz_shortname = module->psz_shortname; - submodule->psz_longname = module->psz_longname; - submodule->psz_capability = module->psz_capability; - submodule->i_score = module->i_score; - submodule->i_cpu = module->i_cpu; - return submodule; + module->confsize++; + return tab + confsize; } -int vlc_module_set (module_t *module, int propid, ...) +/** + * Callback for the plugin descriptor functions. + */ +static int vlc_plugin_setter (void *plugin, void *tgt, int propid, ...) { + module_t **pprimary = plugin; + module_t *module = tgt; + module_config_t *item = tgt; va_list ap; - int ret = VLC_SUCCESS; + int ret = 0; va_start (ap, propid); switch (propid) { - case VLC_MODULE_CPU_REQUIREMENT: - assert (!module->b_submodule); - module->i_cpu |= va_arg (ap, int); - break; - - case VLC_MODULE_SHORTCUT: + case VLC_MODULE_CREATE: { - unsigned i; - for (i = 0; module->pp_shortcuts[i] != NULL; i++); - if (i >= (MODULE_SHORTCUT_MAX - 1)) + module = *pprimary; + module_t *submodule = vlc_module_create (module); + if (unlikely(submodule == NULL)) { - ret = VLC_ENOMEM; + ret = -1; break; } - module->pp_shortcuts[i] = va_arg (ap, char *); - break; - } + *(va_arg (ap, module_t **)) = submodule; + if (*pprimary == NULL) + { + *pprimary = submodule; + break; + } + /* Inheritance. Ugly!! */ + submodule->pp_shortcuts = xmalloc (sizeof (char **)); + submodule->pp_shortcuts[0] = strdup_null (module->pp_shortcuts[0]); + submodule->i_shortcuts = 1; /* object name */ - case VLC_MODULE_SHORTNAME_NODOMAIN: - { - const char *name = va_arg (ap, char *); - ret = vlc_module_set (module, VLC_MODULE_SHORTNAME, NULL, name); + submodule->psz_shortname = strdup_null (module->psz_shortname); + submodule->psz_longname = strdup_null (module->psz_longname); + submodule->psz_capability = strdup_null (module->psz_capability); break; } - case VLC_MODULE_DESCRIPTION_NODOMAIN: + case VLC_CONFIG_CREATE: { - const char *desc = va_arg (ap, char *); - ret = vlc_module_set (module, VLC_MODULE_DESCRIPTION, NULL, desc); + int type = va_arg (ap, int); + module_config_t **pp = va_arg (ap, module_config_t **); + + item = vlc_config_create (*pprimary, type); + if (unlikely(item == NULL)) + { + ret = -1; + break; + } + *pp = item; break; } - case VLC_MODULE_HELP_NODOMAIN: + case VLC_MODULE_SHORTCUT: { - const char *help = va_arg (ap, char *); - ret = vlc_module_set (module, VLC_MODULE_HELP, NULL, help); + unsigned i_shortcuts = va_arg (ap, unsigned); + unsigned index = module->i_shortcuts; + /* The cache loader accept only a small number of shortcuts */ + assert(i_shortcuts + index <= MODULE_SHORTCUT_MAX); + + const char *const *tab = va_arg (ap, const char *const *); + char **pp = realloc (module->pp_shortcuts, + sizeof (pp[0]) * (index + i_shortcuts)); + if (unlikely(pp == NULL)) + { + ret = -1; + break; + } + module->pp_shortcuts = pp; + module->i_shortcuts = index + i_shortcuts; + pp += index; + for (unsigned i = 0; i < i_shortcuts; i++) + pp[i] = strdup (tab[i]); break; } case VLC_MODULE_CAPABILITY: - module->psz_capability = va_arg (ap, char *); + free (module->psz_capability); + module->psz_capability = strdup (va_arg (ap, char *)); break; case VLC_MODULE_SCORE: module->i_score = va_arg (ap, int); break; - case VLC_MODULE_PROGRAM: - msg_Warn (module, "deprecated module property %d", propid); - break; - case VLC_MODULE_CB_OPEN: - module->pf_activate = va_arg (ap, int (*) (vlc_object_t *)); + module->pf_activate = va_arg (ap, void *); break; case VLC_MODULE_CB_CLOSE: - module->pf_deactivate = va_arg (ap, void (*) (vlc_object_t *)); + module->pf_deactivate = va_arg (ap, void *); break; case VLC_MODULE_NO_UNLOAD: + assert (module->parent == NULL); module->b_unloadable = false; break; case VLC_MODULE_NAME: { const char *value = va_arg (ap, const char *); - free( module->psz_object_name ); - module->psz_object_name = strdup( value ); - module->pp_shortcuts[0] = value; - if (module->psz_longname == default_name) - module->psz_longname = value; + + assert (module->i_shortcuts == 0); + module->pp_shortcuts = malloc( sizeof( char ** ) ); + module->pp_shortcuts[0] = strdup (value); + module->i_shortcuts = 1; + + assert (module->psz_longname == NULL); + module->psz_longname = strdup (value); break; } case VLC_MODULE_SHORTNAME: - { - const char *domain = va_arg (ap, const char *); - if (domain == NULL) - domain = PACKAGE; - module->psz_shortname = dgettext (domain, va_arg (ap, char *)); + assert (module->psz_shortname == NULL || module->parent != NULL); + free (module->psz_shortname); + module->psz_shortname = strdup (va_arg (ap, char *)); break; - } case VLC_MODULE_DESCRIPTION: - { - const char *domain = va_arg (ap, const char *); - if (domain == NULL) - domain = PACKAGE; - module->psz_longname = dgettext (domain, va_arg (ap, char *)); + // TODO: do not set this in VLC_MODULE_NAME + free (module->psz_longname); + module->psz_longname = strdup (va_arg (ap, char *)); break; - } case VLC_MODULE_HELP: - { - const char *domain = va_arg (ap, const char *); - if (domain == NULL) - domain = PACKAGE; - module->psz_help = dgettext (domain, va_arg (ap, char *)); + assert (module->parent == NULL); + assert (module->psz_help == NULL); + module->psz_help = strdup (va_arg (ap, char *)); break; - } - default: - msg_Err (module, "unknown module property %d", propid); - msg_Err (module, "LibVLC might be too old to use this module."); - ret = VLC_EGENERIC; + case VLC_MODULE_TEXTDOMAIN: + assert (module->parent == NULL); + assert (module->domain == NULL); + module->domain = strdup (va_arg (ap, char *)); break; - } - va_end (ap); - return ret; -} - -module_config_t *vlc_config_create (module_t *module, int type) -{ - unsigned confsize = module->confsize; - module_config_t *tab = module->p_config; - - if ((confsize & 0xf) == 0) - { - tab = realloc (tab, (confsize + 17) * sizeof (*tab)); - if (tab == NULL) - return NULL; - - module->p_config = tab; - } - - memset (tab + confsize, 0, sizeof (tab[confsize])); - tab[confsize].i_type = type; - tab[confsize].p_lock = &module->object_lock; - - if (type & CONFIG_ITEM) - { - module->i_config_items++; - if (type == CONFIG_ITEM_BOOL) - module->i_bool_items++; - } - - module->confsize++; - return tab + confsize; -} - -int vlc_config_set (module_config_t *restrict item, int id, ...) -{ - int ret = -1; - va_list ap; - assert (item != NULL); - va_start (ap, id); - - switch (id) - { case VLC_CONFIG_NAME: { const char *name = va_arg (ap, const char *); - vlc_callback_t cb = va_arg (ap, vlc_callback_t); assert (name != NULL); item->psz_name = strdup (name); - item->pf_callback = cb; - ret = 0; - break; - } - - case VLC_CONFIG_DESC_NODOMAIN: - { - const char *text = va_arg (ap, const char *); - const char *longtext = va_arg (ap, const char *); - ret = vlc_config_set (item, VLC_CONFIG_DESC, NULL, text, longtext); break; } case VLC_CONFIG_VALUE: { - if (IsConfigIntegerType (item->i_type)) + if (IsConfigIntegerType (item->i_type) + || !CONFIG_ITEM(item->i_type)) { - item->orig.i = item->saved.i = - item->value.i = va_arg (ap, int); - ret = 0; + item->orig.i = + item->value.i = va_arg (ap, int64_t); } else if (IsConfigFloatType (item->i_type)) { - item->orig.f = item->saved.f = + item->orig.f = item->value.f = va_arg (ap, double); - ret = 0; } else if (IsConfigStringType (item->i_type)) @@ -281,138 +313,69 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) const char *value = va_arg (ap, const char *); item->value.psz = value ? strdup (value) : NULL; item->orig.psz = value ? strdup (value) : NULL; - item->saved.psz = value ? strdup (value) : NULL; - ret = 0; } break; } case VLC_CONFIG_RANGE: { - if (IsConfigIntegerType (item->i_type)) - { - item->min.i = va_arg (ap, int); - item->max.i = va_arg (ap, int); - ret = 0; - } - else if (IsConfigFloatType (item->i_type)) { item->min.f = va_arg (ap, double); item->max.f = va_arg (ap, double); - ret = 0; + } + else + { + item->min.i = va_arg (ap, int64_t); + item->max.i = va_arg (ap, int64_t); } break; } case VLC_CONFIG_ADVANCED: item->b_advanced = true; - ret = 0; break; case VLC_CONFIG_VOLATILE: item->b_unsaveable = true; - ret = 0; - break; - - case VLC_CONFIG_PERSISTENT: - item->b_autosave = true; - ret = 0; - break; - - case VLC_CONFIG_RESTART: - item->b_restart = true; - ret = 0; break; case VLC_CONFIG_PRIVATE: item->b_internal = true; - ret = 0; break; case VLC_CONFIG_REMOVED: item->b_removed = true; - ret = 0; break; case VLC_CONFIG_CAPABILITY: { const char *cap = va_arg (ap, const char *); item->psz_type = cap ? strdup (cap) : NULL; - ret = 0; break; } case VLC_CONFIG_SHORTCUT: item->i_short = va_arg (ap, int); - ret = 0; - break; - - case VLC_CONFIG_LIST_NODOMAIN: - { - size_t len = va_arg (ap, size_t); - if (IsConfigIntegerType (item->i_type)) - { - const int *src = va_arg (ap, const int *); - const char *const *text = va_arg (ap, const char *const *); - ret = vlc_config_set (item, VLC_CONFIG_LIST, NULL, len, src, - text); - } - else - if (IsConfigStringType (item->i_type)) - { - const char *const *src = va_arg (ap, const char *const *); - const char *const *text = va_arg (ap, const char *const *); - ret = vlc_config_set (item, VLC_CONFIG_LIST, NULL, len, src, - text); - } break; - } - - case VLC_CONFIG_ADD_ACTION_NODOMAIN: - { - vlc_callback_t cb = va_arg (ap, vlc_callback_t); - const char *name = va_arg (ap, const char *); - ret = vlc_config_set (item, VLC_CONFIG_ADD_ACTION, NULL, cb, name); - break; - } - - case VLC_CONFIG_OLDNAME: - { - const char *oldname = va_arg (ap, const char *); - item->psz_oldname = oldname ? strdup (oldname) : NULL; - ret = 0; - break; - } case VLC_CONFIG_SAFE: item->b_safe = true; - ret = 0; break; case VLC_CONFIG_DESC: { - const char *domain = va_arg (ap, const char *); const char *text = va_arg (ap, const char *); const char *longtext = va_arg (ap, const char *); - if (domain == NULL) - domain = PACKAGE; - item->psz_text = text ? strdup (dgettext (domain, text)) : NULL; - item->psz_longtext = - longtext ? strdup (dgettext (domain, longtext)) : NULL; - ret = 0; + item->psz_text = text ? strdup (text) : NULL; + item->psz_longtext = longtext ? strdup (longtext) : NULL; break; } case VLC_CONFIG_LIST: { - const char *domain = va_arg (ap, const char *); size_t len = va_arg (ap, size_t); - char **dtext = malloc (sizeof (char *) * (len + 1)); - - if (dtext == NULL) - break; /* Copy values */ if (IsConfigIntegerType (item->i_type)) @@ -428,21 +391,6 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) item->pi_list = dst; } else -#if 0 - if (IsConfigFloatType (item->i_type)) - { - const float *src = va_arg (ap, const float *); - float *dst = malloc (sizeof (float) * (len + 1)); - - if (dst != NULL) - { - memcpy (dst, src, sizeof (float) * len); - dst[len] = 0.; - } - item->pf_list = dst; - } - else -#endif if (IsConfigStringType (item->i_type)) { const char *const *src = va_arg (ap, const char *const *); @@ -460,34 +408,28 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) break; /* Copy textual descriptions */ - if (domain == NULL) - domain = PACKAGE; - const char *const *text = va_arg (ap, const char *const *); if (text != NULL) { - for (size_t i = 0; i < len; i++) - dtext[i] = - text[i] ? strdup (dgettext (domain, text[i])) : NULL; - - dtext[len] = NULL; + char **dtext = malloc (sizeof (char *) * (len + 1)); + if( dtext != NULL ) + { + for (size_t i = 0; i < len; i++) + dtext[i] = text[i] ? strdup (text[i]) : NULL; + dtext[len] = NULL; + } item->ppsz_list_text = dtext; } else - { - free (dtext); item->ppsz_list_text = NULL; - } item->i_list = len; item->pf_update_list = va_arg (ap, vlc_callback_t); - ret = 0; break; } case VLC_CONFIG_ADD_ACTION: { - const char *domain = va_arg (ap, const char *); vlc_callback_t cb = va_arg (ap, vlc_callback_t), *tabcb; const char *name = va_arg (ap, const char *); char **tabtext; @@ -506,20 +448,39 @@ int vlc_config_set (module_config_t *restrict item, int id, ...) break; item->ppsz_action_text = tabtext; - if (domain == NULL) - domain = PACKAGE; if (name) - tabtext[item->i_action] = strdup (dgettext (domain, name)); + tabtext[item->i_action] = strdup (name); else tabtext[item->i_action] = NULL; tabtext[item->i_action + 1] = NULL; item->i_action++; - ret = 0; break; } + + default: + fprintf (stderr, "LibVLC: unknown module property %d\n", propid); + fprintf (stderr, "LibVLC: too old to use this module?\n"); + ret = -1; + break; } va_end (ap); return ret; } + +/** + * Runs a plug-in descriptor. This loads the plug-in meta-data in memory. + */ +module_t *vlc_plugin_describe (vlc_plugin_cb entry) +{ + module_t *module = NULL; + + if (entry (vlc_plugin_setter, &module) != 0) + { + if (module != NULL) /* partially initialized plug-in... */ + vlc_module_destroy (module); + module = NULL; + } + return module; +}