From b16ca3fa64fc1fa83d40d00d0090cc7fd27a9840 Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Tue, 29 Nov 2011 20:15:56 +0100 Subject: initial plugin config framework, can't save multiple entries --- src/common/plugin.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) (limited to 'src/common/plugin.c') diff --git a/src/common/plugin.c b/src/common/plugin.c index b40660a1..ffdc013e 100644 --- a/src/common/plugin.c +++ b/src/common/plugin.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include "xchat.h" #include "fe.h" @@ -262,6 +264,8 @@ plugin_add (session *sess, char *filename, void *handle, void *init_func, pl->xchat_send_modes = xchat_send_modes; pl->xchat_strip = xchat_strip; pl->xchat_free = xchat_free; + pl->xchat_set_plugin_pref = xchat_set_plugin_pref; + pl->xchat_get_plugin_pref = xchat_get_plugin_pref; /* incase new plugins are loaded on older xchat */ pl->xchat_dummy4 = xchat_dummy; @@ -1570,3 +1574,88 @@ xchat_free (xchat_plugin *ph, void *ptr) { g_free (ptr); } + +int +xchat_set_plugin_pref (xchat_plugin *pl, char *var, char *value) +{ + int fh; + char confname[32]; + char *canon; + + canon = g_strdup (pl->name); + canonalize_key (canon); + sprintf (confname, "plugin_%s.conf", canon); + g_free (canon); + + /* partly borrowed from palette.c */ + fh = xchat_open_file (confname, O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE); + if (fh != -1) + { + cfg_put_str (fh, var, value); + close (fh); + + return 1; + } + else + { + return 0; + } +} + +int +xchat_get_plugin_pref (xchat_plugin *pl, char *var, char *dest, int dest_len) +{ + //cfg_get_str (char *cfg, char *var, char *dest, int dest_len) + int fh; + int l; + char confname[32]; + //char *buffer; + char *canon; + char *cfg; + struct stat st; + + canon = g_strdup (pl->name); + canonalize_key (canon); + sprintf (confname, "plugin_%s.conf", canon); + g_free (canon); + + //buffer = (char*) malloc (dest_len); + + /* partly borrowed from palette.c */ + fh = xchat_open_file (confname, O_RDONLY, 0, 0); + + if (fh != -1) + { + fstat (fh, &st); + cfg = malloc (st.st_size + 1); + + if (cfg) + { + cfg[0] = '\0'; + l = read (fh, cfg, st.st_size); + + if (l >= 0) + { + cfg[l] = '\0'; + } + + if (!cfg_get_str (cfg, var, dest, dest_len)) + { + return 0; + } + + free (cfg); + } + else + { + return 0; + } + + close (fh); + return 1; + } + else + { + return 0; + } +} -- cgit 1.4.1