42 #define FILENAME "plugin-registry"
54 GList * keys[INPUT_KEYS];
92 [INPUT_KEY_SCHEME] =
"scheme",
93 [INPUT_KEY_EXTENSION] =
"ext",
94 [INPUT_KEY_MIME] =
"mime"};
98 static pthread_mutex_t
mutex = PTHREAD_MUTEX_INITIALIZER;
101 loaded,
int timestamp,
int type, Plugin * header)
119 memset (& plugin->
misc, 0, sizeof (PluginMiscData));
149 g_list_foreach (plugin->
watches, (GFunc) g_free,
NULL);
159 g_list_foreach (plugin->
u.
p.
exts, (GFunc) g_free,
NULL);
160 g_list_free (plugin->
u.
p.
exts);
164 for (
int key = 0; key < INPUT_KEYS; key ++)
166 g_list_foreach (plugin->
u.
i.
keys[key], (GFunc) g_free,
NULL);
167 g_list_free (plugin->
u.
i.
keys[key]);
171 g_free (plugin->
path);
172 g_free (plugin->
name);
180 FILE * file = fopen (path, mode);
187 for (GList * node = plugin->
u.
t.
schemes; node; node = node->next)
188 fprintf (handle,
"scheme %s\n", (
const char *) node->data);
193 for (GList * node = plugin->
u.
p.
exts; node; node = node->next)
194 fprintf (handle,
"ext %s\n", (
const char *) node->data);
199 for (
int key = 0; key < INPUT_KEYS; key ++)
201 for (GList * node = plugin->
u.
i.
keys[key]; node; node = node->next)
206 fprintf (handle,
"images %d\n", plugin->
u.
i.
has_images);
215 fprintf (handle,
"stamp %d\n", plugin->
timestamp);
216 fprintf (handle,
"name %s\n", plugin->
name);
219 fprintf (handle,
"domain %s\n", plugin->
domain);
221 fprintf (handle,
"priority %d\n", plugin->
priority);
222 fprintf (handle,
"about %d\n", plugin->
has_about);
224 fprintf (handle,
"enabled %d\n", plugin->
enabled);
237 g_return_if_fail (handle);
239 fprintf (handle,
"format %d\n",
FORMAT);
297 plugin->
u.
p.
exts = g_list_prepend (plugin->
u.
p.
exts, value);
304 for (
int key = 0; key < INPUT_KEYS; key ++)
309 plugin->
u.
i.
keys[key] = g_list_prepend (plugin->
u.
i.
keys[key],
403 AUDDBG (
"Plugin not found: %s\n", plugin->
path);
434 return strcmp (plugin->
path, path);
439 GList * node = g_list_find_custom (
plugin_list, path, (GCompareFunc)
441 return node ? node->data :
NULL;
446 char * test = g_path_get_basename (plugin->
path);
448 char * dot = strrchr (test,
'.');
452 int ret = strcmp (test, basename);
462 GList * node = g_list_find_custom (
plugin_list, basename, (GCompareFunc)
464 return node ? node->data :
NULL;
472 AUDDBG (
"New plugin: %s\n", path);
478 g_return_if_fail (timestamp >= 0);
480 AUDDBG (
"Register plugin: %s\n", path);
486 AUDDBG (
"Rescan plugin: %s\n", path);
493 AUDDBG (
"Loaded plugin: %s\n", path);
499 g_return_if_fail (plugin->
type == header->type);
512 g_return_if_fail (timestamp >= 0);
515 header->type, header);
519 g_free (plugin->
name);
521 plugin->
name = g_strdup (header->name);
528 TransportPlugin * tp = (TransportPlugin *) header;
529 for (
int i = 0; tp->schemes[i]; i ++)
535 PlaylistPlugin * pp = (PlaylistPlugin *) header;
536 for (
int i = 0; pp->extensions[i]; i ++)
537 plugin->
u.
p.
exts = g_list_prepend (plugin->
u.
p.
exts, g_strdup
538 (pp->extensions[i]));
542 InputPlugin * ip = (InputPlugin *) header;
545 for (
int key = 0; key < INPUT_KEYS; key ++)
547 g_list_foreach (plugin->
u.
i.
keys[key], (GFunc) g_free,
NULL);
548 g_list_free (plugin->
u.
i.
keys[key]);
554 for (
int i = 0; ip->extensions[i]; i ++)
555 plugin->
u.
i.
keys[INPUT_KEY_EXTENSION] = g_list_prepend
556 (plugin->
u.
i.
keys[INPUT_KEY_EXTENSION], g_strdup
557 (ip->extensions[i]));
562 for (
int i = 0; ip->mimes[i]; i ++)
563 plugin->
u.
i.
keys[INPUT_KEY_MIME] = g_list_prepend
564 (plugin->
u.
i.
keys[INPUT_KEY_MIME], g_strdup (ip->mimes[i]));
569 for (
int i = 0; ip->schemes[i]; i ++)
570 plugin->
u.
i.
keys[INPUT_KEY_SCHEME] = g_list_prepend
571 (plugin->
u.
i.
keys[INPUT_KEY_SCHEME], g_strdup (ip->schemes[i]));
581 OutputPlugin * op = (OutputPlugin *) header;
582 plugin->
priority = 10 - op->probe_priority;
586 EffectPlugin * ep = (EffectPlugin *) header;
591 GeneralPlugin * gp = (GeneralPlugin *) header;
593 plugin->
enabled = gp->enabled_by_default;
609 pthread_mutex_lock (&
mutex);
617 pthread_mutex_unlock (&
mutex);
628 return (plugin->
header == header) ? 0 : -1;
633 GList * node = g_list_find_custom (
plugin_list, header, (GCompareFunc)
635 return node ? node->data :
NULL;
640 for (GList * node =
plugin_list; node; node = node->next)
644 if (! func (node->data, data))
651 return dgettext (plugin->
domain, plugin->
name);
671 for (GList * node = plugin->
watches; node; )
673 GList * next = node->next;
676 if (! watch->
func (plugin, watch->
data))
702 return state->
func (plugin, state->
data);
723 for (GList * node = plugin->
watches; node; )
725 GList * next = node->next;
728 if (watch->
func == func && watch->
data == data)
740 return & plugin->
misc;
752 (GCompareFunc) g_ascii_strcasecmp))
775 if (! g_list_find_custom (plugin->
u.
p.
exts, state->
ext,
776 (GCompareFunc) g_ascii_strcasecmp))
801 if (! g_list_find_custom (plugin->
u.
i.
keys[state->
key], state->
value,
802 (GCompareFunc) g_ascii_strcasecmp))
805 return state->
func (plugin, state->
data);