Initial revision 6759
[qball-mpd.git] / src / inputPlugin.c
blobec5624bf277b021ae91947576c4d73ddbf24f98d
1 /* the Music Player Daemon (MPD)
2 * Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
3 * This project's homepage is: http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "inputPlugin.h"
21 #include "list.h"
22 #include "myfprintf.h"
24 #include <stdlib.h>
25 #include <string.h>
27 static List *inputPlugin_list;
29 void loadInputPlugin(InputPlugin * inputPlugin)
31 if (!inputPlugin)
32 return;
33 if (!inputPlugin->name)
34 return;
36 if (inputPlugin->initFunc && inputPlugin->initFunc() < 0)
37 return;
39 insertInList(inputPlugin_list, inputPlugin->name, (void *)inputPlugin);
42 void unloadInputPlugin(InputPlugin * inputPlugin)
44 if (inputPlugin->finishFunc)
45 inputPlugin->finishFunc();
46 deleteFromList(inputPlugin_list, inputPlugin->name);
49 static int stringFoundInStringArray(char **array, char *suffix)
51 while (array && *array) {
52 if (strcasecmp(*array, suffix) == 0)
53 return 1;
54 array++;
57 return 0;
60 InputPlugin *getInputPluginFromSuffix(char *suffix, unsigned int next)
62 static ListNode *pos;
63 ListNode *node;
64 InputPlugin *plugin;
66 if (suffix == NULL)
67 return NULL;
69 if (next) {
70 if (pos)
71 node = pos;
72 else
73 return NULL;
74 } else
75 node = inputPlugin_list->firstNode;
77 while (node != NULL) {
78 plugin = node->data;
79 if (stringFoundInStringArray(plugin->suffixes, suffix)) {
80 pos = node->nextNode;
81 return plugin;
83 node = node->nextNode;
86 return NULL;
89 InputPlugin *getInputPluginFromMimeType(char *mimeType, unsigned int next)
91 static ListNode *pos;
92 ListNode *node;
93 InputPlugin *plugin;
95 if (mimeType == NULL)
96 return NULL;
98 node = (next && pos) ? pos : inputPlugin_list->firstNode;
100 while (node != NULL) {
101 plugin = node->data;
102 if (stringFoundInStringArray(plugin->mimeTypes, mimeType)) {
103 pos = node->nextNode;
104 return plugin;
106 node = node->nextNode;
109 return NULL;
112 InputPlugin *getInputPluginFromName(char *name)
114 void *plugin = NULL;
116 findInList(inputPlugin_list, name, &plugin);
118 return (InputPlugin *) plugin;
121 void printAllInputPluginSuffixes(FILE * fp)
123 ListNode *node = inputPlugin_list->firstNode;
124 InputPlugin *plugin;
125 char **suffixes;
127 while (node) {
128 plugin = (InputPlugin *) node->data;
129 suffixes = plugin->suffixes;
130 while (suffixes && *suffixes) {
131 fprintf(fp, "%s ", *suffixes);
132 suffixes++;
134 node = node->nextNode;
136 fprintf(fp, "\n");
137 fflush(fp);
140 void initInputPlugins(void)
142 inputPlugin_list = makeList(NULL, 1);
144 /* load plugins here */
145 loadInputPlugin(&mp3Plugin);
146 loadInputPlugin(&oggvorbisPlugin);
147 loadInputPlugin(&oggflacPlugin);
148 loadInputPlugin(&flacPlugin);
149 loadInputPlugin(&audiofilePlugin);
150 loadInputPlugin(&mp4Plugin);
151 loadInputPlugin(&aacPlugin);
152 loadInputPlugin(&mpcPlugin);
153 loadInputPlugin(&wavpackPlugin);
154 loadInputPlugin(&modPlugin);
157 void finishInputPlugins(void)
159 freeList(inputPlugin_list);