summaryrefslogtreecommitdiff
path: root/plugin/plugin.c
diff options
context:
space:
mode:
authorSamuel Lidén Borell <samuel@slbdata.se>2009-06-08 12:39:20 +0200
committerSamuel Lidén Borell <samuel@slbdata.se>2010-01-02 21:42:03 +0100
commit162b7545ba53f52bd5ea1d0a31e33ed7cb3045d3 (patch)
tree7e236346f84ebf4676a267982112e0cf14e98485 /plugin/plugin.c
parent6d725eb52ca68c443706c7f0bc34bec60d1ff8e9 (diff)
downloadfribid-162b7545ba53f52bd5ea1d0a31e33ed7cb3045d3.tar.gz
fribid-162b7545ba53f52bd5ea1d0a31e33ed7cb3045d3.tar.bz2
fribid-162b7545ba53f52bd5ea1d0a31e33ed7cb3045d3.zip
Made most of the code run in a separate process
This was done to avoid interference with the browser and some libraries.
Diffstat (limited to 'plugin/plugin.c')
-rw-r--r--plugin/plugin.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/plugin/plugin.c b/plugin/plugin.c
new file mode 100644
index 0000000..716ebc5
--- /dev/null
+++ b/plugin/plugin.c
@@ -0,0 +1,73 @@
+#define _BSD_SOURCE 1
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+
+#include "plugin.h"
+
+Plugin *plugin_new(PluginType pluginType, const char *url,
+ const char *hostname, const char *ip) {
+ Plugin *plugin = calloc(1, sizeof(Plugin));
+ plugin->type = pluginType;
+ plugin->url = strdup(url);
+ plugin->hostname = strdup(hostname);
+ plugin->ip = strdup(ip);
+ return plugin;
+}
+
+void plugin_free(Plugin *plugin) {
+ switch (plugin->type) {
+ case PT_Version:
+ break;
+ case PT_Authentication:
+ free(plugin->info.auth.challenge);
+ free(plugin->info.auth.policys);
+ free(plugin->info.auth.signature);
+ break;
+ }
+ free(plugin->url);
+ free(plugin->hostname);
+ free(plugin->ip);
+ free(plugin);
+}
+
+
+static char **getParamPointer(Plugin *plugin, const char *name) {
+ if (!strcmp(name, "Challenge")) return &plugin->info.auth.challenge;
+ if (!strcmp(name, "Policys")) return &plugin->info.auth.policys;
+ if (!strcmp(name, "Signature")) return &plugin->info.auth.signature;
+ return NULL;
+}
+
+char *auth_getParam(Plugin *plugin, const char *name) {
+ char **valuePtr = getParamPointer(plugin, name);
+
+ char *value = NULL;
+ if (*valuePtr) value = strdup(*valuePtr);
+
+ return (value != NULL ? value : strdup(""));
+}
+
+bool auth_setParam(Plugin *plugin, const char *name, const char *value) {
+ char **valuePtr = getParamPointer(plugin, name);
+
+ if (valuePtr == NULL) return false;
+
+ free(*valuePtr);
+ *valuePtr = strdup(value);
+ return true;
+}
+
+int auth_performAction(Plugin *plugin, const char *action) {
+ if (!strcmp(action, "Authenticate")) {
+ return auth_performAction_Authenticate(plugin);
+ } else {
+ return 1;
+ }
+}
+
+int auth_getLastError(Plugin *plugin) {
+ return plugin->lastError;
+}
+
+