diff options
author | Warren Dukes <warren.dukes@gmail.com> | 2004-05-30 20:25:08 +0000 |
---|---|---|
committer | Warren Dukes <warren.dukes@gmail.com> | 2004-05-30 20:25:08 +0000 |
commit | d7893a3e76d261b33b83fd9333d85892b3308594 (patch) | |
tree | 3102b3c16f68d2824e7cc0921b8e7a56f7ca5026 /src/inputPlugin.c | |
parent | bd41addd9f52d08ee2e992e82c4d746369b10fc0 (diff) | |
download | mpd-d7893a3e76d261b33b83fd9333d85892b3308594.tar.gz mpd-d7893a3e76d261b33b83fd9333d85892b3308594.tar.xz mpd-d7893a3e76d261b33b83fd9333d85892b3308594.zip |
finish implementing inputPlugin interface
git-svn-id: https://svn.musicpd.org/mpd/trunk@1244 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/inputPlugin.c')
-rw-r--r-- | src/inputPlugin.c | 94 |
1 files changed, 83 insertions, 11 deletions
diff --git a/src/inputPlugin.c b/src/inputPlugin.c index e22b27718..2afe17719 100644 --- a/src/inputPlugin.c +++ b/src/inputPlugin.c @@ -1,19 +1,29 @@ -#include "input_plugin.h" +#include "inputPlugin.h" + +#include "list.h" #include <stdlib.h> +#include <string.h> + +static List * inputPlugin_list = NULL; -InputPlugin * newInputPlugin() { +InputPlugin * newInputPlugin(char * name, InputPlugin_streamDecodeFunc + streamDecodeFunc, InputPlugin_fileDecodeFunc fileDecodeFunc, + InputPlugin_tagDupFunc tagDupFunc, unsigned char streamTypes) +{ InputPlugin * ret = malloc(sizeof(InputPlugin)); memset(ret->name,0,INPUT_PLUGIN_NAME_LENGTH); + strncpy(ret->name, name, INPUT_PLUGIN_NAME_LENGTH-1); ret->suffixes = NULL; ret->mimeTypes = NULL; - ret->streamTypes = 0; - ret->streamDecodeFunc = NULL; - ret->fileDeocdeFunc = NULL; - ret->tagDupFunc = NULL; + ret->streamTypes = streamTypes; + + ret->streamDecodeFunc = streamDecodeFunc; + ret->fileDecodeFunc = fileDecodeFunc; + ret->tagDupFunc = tagDupFunc; return ret; } @@ -32,8 +42,6 @@ static void freeStringArray(char ** ptr) { } void freeInputPlugin(InputPlugin * inPlugin) { - char * temp; - freeStringArray(inPlugin->suffixes); freeStringArray(inPlugin->mimeTypes); @@ -45,15 +53,16 @@ static char ** AddStringToArray(char ** array, char * string) { if(array) { char ** tmp = array; - while(*array) { + while(*tmp) { arraySize++; - array++; + tmp++; } } - array = realloc(array, arraySize*sizeof(char *)); + array = realloc(array, (arraySize+1)*sizeof(char *)); array[arraySize-1] = strdup(string); + array[arraySize] = NULL; return array; } @@ -65,3 +74,66 @@ void addSuffixToInputPlugin(InputPlugin * inPlugin, char * suffix) { void addMimeTypeToInputPlugin(InputPlugin * inPlugin, char * mimeType) { inPlugin->mimeTypes = AddStringToArray(inPlugin->mimeTypes, mimeType); } + +void loadInputPlugin(InputPlugin * inputPlugin) { + insertInList(inputPlugin_list, inputPlugin->name, (void *)inputPlugin); +} + +void unloadInputPlugin(InputPlugin * inputPlugin) { + deleteFromList(inputPlugin_list, inputPlugin->name); +} + +static int stringFoundInStringArray(char ** array, char * suffix) { + while(array && *array) { + if(strcmp(*array, suffix) == 0) return 1; + array++; + } + + return 0; +} + +InputPlugin * getInputPluginFromSuffix(char * suffix) { + ListNode * node = inputPlugin_list->firstNode; + InputPlugin * plugin = NULL; + + while(node != NULL) { + plugin = node->data; + if(stringFoundInStringArray(plugin->suffixes, suffix)) { + return plugin; + } + } + + return NULL; +} + +InputPlugin * getInputPluginFromMimeType(char * mimeType) { + ListNode * node = inputPlugin_list->firstNode; + InputPlugin * plugin = NULL; + + while(node != NULL) { + plugin = node->data; + if(stringFoundInStringArray(plugin->mimeTypes, mimeType)) { + return plugin; + } + } + + return NULL; +} + +InputPlugin * getInputPluginFromName(char * name) { + void * plugin = NULL; + + findInList(inputPlugin_list, name, &plugin); + + return (InputPlugin *)plugin; +} + +void initInputPlugins() { + inputPlugin_list = makeList((ListFreeDataFunc *)freeInputPlugin); + + /* load plugins here */ +} + +void finishInputPlugins() { + freeList(inputPlugin_list); +} |