aboutsummaryrefslogtreecommitdiffstats
path: root/src/inputPlugin.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/inputPlugin.c')
-rw-r--r--src/inputPlugin.c94
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);
+}