41 #define FILENAME "plugin-registry"
53 GList * keys[INPUT_KEYS];
91 [INPUT_KEY_SCHEME] =
"scheme",
92 [INPUT_KEY_EXTENSION] =
"ext",
93 [INPUT_KEY_MIME] =
"mime"};
97 static pthread_mutex_t
mutex = PTHREAD_MUTEX_INITIALIZER;
100 loaded,
int timestamp,
int type, Plugin * header)
118 memset (& plugin->
misc, 0, sizeof (PluginMiscData));
148 g_list_free_full (plugin->
watches, g_free);
151 g_list_free_full (plugin->
u.
t.
schemes, g_free);
153 g_list_free_full (plugin->
u.
p.
exts, g_free);
156 for (
int key = 0; key < INPUT_KEYS; key ++)
157 g_list_free_full (plugin->
u.
i.
keys[key], g_free);
160 g_free (plugin->
path);
161 g_free (plugin->
name);
169 FILE * file = fopen (path, mode);
176 for (GList * node = plugin->
u.
t.
schemes; node; node = node->next)
177 fprintf (handle,
"scheme %s\n", (
const char *) node->data);
182 for (GList * node = plugin->
u.
p.
exts; node; node = node->next)
183 fprintf (handle,
"ext %s\n", (
const char *) node->data);
188 for (
int key = 0; key < INPUT_KEYS; key ++)
190 for (GList * node = plugin->
u.
i.
keys[key]; node; node = node->next)
195 fprintf (handle,
"images %d\n", plugin->
u.
i.
has_images);
204 fprintf (handle,
"stamp %d\n", plugin->
timestamp);
205 fprintf (handle,
"name %s\n", plugin->
name);
208 fprintf (handle,
"domain %s\n", plugin->
domain);
210 fprintf (handle,
"priority %d\n", plugin->
priority);
211 fprintf (handle,
"about %d\n", plugin->
has_about);
213 fprintf (handle,
"enabled %d\n", plugin->
enabled);
226 g_return_if_fail (handle);
228 fprintf (handle,
"format %d\n",
FORMAT);
286 plugin->
u.
p.
exts = g_list_prepend (plugin->
u.
p.
exts, value);
293 for (
int key = 0; key < INPUT_KEYS; key ++)
298 plugin->
u.
i.
keys[key] = g_list_prepend (plugin->
u.
i.
keys[key],
392 AUDDBG (
"Plugin not found: %s\n", plugin->
path);
423 return strcmp (plugin->
path, path);
428 GList * node = g_list_find_custom (
plugin_list, path, (GCompareFunc)
430 return node ? node->data :
NULL;
435 char * test = g_path_get_basename (plugin->
path);
437 char * dot = strrchr (test,
'.');
441 int ret = strcmp (test, basename);
451 GList * node = g_list_find_custom (
plugin_list, basename, (GCompareFunc)
453 return node ? node->data :
NULL;
458 Plugin * header = plugin->
header;
460 g_free (plugin->
name);
462 plugin->
name = g_strdup (header->name);
469 TransportPlugin * tp = (TransportPlugin *) header;
471 g_list_free_full (plugin->
u.
t.
schemes, g_free);
474 for (
int i = 0; tp->schemes[i]; i ++)
480 PlaylistPlugin * pp = (PlaylistPlugin *) header;
482 g_list_free_full (plugin->
u.
p.
exts, g_free);
485 for (
int i = 0; pp->extensions[i]; i ++)
486 plugin->
u.
p.
exts = g_list_prepend (plugin->
u.
p.
exts, g_strdup
487 (pp->extensions[i]));
491 InputPlugin * ip = (InputPlugin *) header;
494 for (
int key = 0; key < INPUT_KEYS; key ++)
496 g_list_free_full (plugin->
u.
i.
keys[key], g_free);
502 for (
int i = 0; ip->extensions[i]; i ++)
503 plugin->
u.
i.
keys[INPUT_KEY_EXTENSION] = g_list_prepend
504 (plugin->
u.
i.
keys[INPUT_KEY_EXTENSION], g_strdup
505 (ip->extensions[i]));
510 for (
int i = 0; ip->mimes[i]; i ++)
511 plugin->
u.
i.
keys[INPUT_KEY_MIME] = g_list_prepend
512 (plugin->
u.
i.
keys[INPUT_KEY_MIME], g_strdup (ip->mimes[i]));
517 for (
int i = 0; ip->schemes[i]; i ++)
518 plugin->
u.
i.
keys[INPUT_KEY_SCHEME] = g_list_prepend
519 (plugin->
u.
i.
keys[INPUT_KEY_SCHEME], g_strdup (ip->schemes[i]));
529 OutputPlugin * op = (OutputPlugin *) header;
530 plugin->
priority = 10 - op->probe_priority;
534 EffectPlugin * ep = (EffectPlugin *) header;
539 GeneralPlugin * gp = (GeneralPlugin *) header;
541 plugin->
enabled = gp->enabled_by_default;
551 AUDDBG (
"Register plugin: %s\n", path);
556 AUDDBG (
"Rescan plugin: %s\n", path);
558 if (! header || header->type != plugin->
type)
570 AUDDBG (
"New plugin: %s\n", path);
576 header->type, header);
594 pthread_mutex_lock (&
mutex);
599 if (! header || header->type != plugin->
type)
607 pthread_mutex_unlock (&
mutex);
613 return (plugin->
header == header) ? 0 : -1;
618 GList * node = g_list_find_custom (
plugin_list, header, (GCompareFunc)
620 return node ? node->data :
NULL;
625 for (GList * node =
plugin_list; node; node = node->next)
629 if (! func (node->data, data))
636 return dgettext (plugin->
domain, plugin->
name);
656 for (GList * node = plugin->
watches; node; )
658 GList * next = node->next;
661 if (! watch->
func (plugin, watch->
data))
687 return state->
func (plugin, state->
data);
708 for (GList * node = plugin->
watches; node; )
710 GList * next = node->next;
713 if (watch->
func == func && watch->
data == data)
725 return & plugin->
misc;
737 (GCompareFunc) g_ascii_strcasecmp))
760 if (! g_list_find_custom (plugin->
u.
p.
exts, state->
ext,
761 (GCompareFunc) g_ascii_strcasecmp))
786 if (! g_list_find_custom (plugin->
u.
i.
keys[state->
key], state->
value,
787 (GCompareFunc) g_ascii_strcasecmp))
790 return state->
func (plugin, state->
data);