plugin configuration parsing
authorMichal Voců <michal@ruk.cuni.cz>
Tue, 9 Feb 2010 13:11:03 +0000 (13:11 +0000)
committerMichal Voců <michal@ruk.cuni.cz>
Tue, 9 Feb 2010 13:11:03 +0000 (13:11 +0000)
org.glite.lb.logger/src/activemq_cpp_plugin.cpp
org.glite.lb.logger/src/interlogd.c
org.glite.lb.logger/src/interlogd.h
org.glite.lb.logger/src/plugin_mgr.c

index 104dd50..19a324c 100644 (file)
@@ -29,7 +29,7 @@
 #include <assert.h>
 #include <string.h>
 #include <errno.h>
-
+#include <sys/param.h>
 
 class OutputPlugin : public cms::ExceptionListener {
 
@@ -311,10 +311,39 @@ event_queue_close(struct event_queue *eq)
 
 extern "C"
 int
-plugin_init(const char *config)
+plugin_init(char *config)
 {
+       char *s, *p;
+       char key[MAXPATHLEN], val[MAXPATHLEN];
+       int ret;
        std::string brokerURI;
 
+       s = strstr(config, "[msg]");
+       if(s == NULL) {
+               set_error(IL_DL, ENOENT, "plugin_init: missing required configuration section [msg]\n");
+               return -1;
+       }
+       s = strchr(s, '\n');
+       if(s) s++;
+       while(s) {
+               if(*s == 0 || *s == '[')
+                       break;
+               p = strchr(s, '\n');
+               if(p) *p = 0;
+               ret = sscanf(s, " %s =%s", key, val);
+               if(p) *p = '\n';
+               if(ret == 2) {
+                       if(strcmp(key, "broker") == 0) {
+                               brokerURI.assign(val);
+                       }
+               }
+               s = p;
+       }
+       if(brokerURI.length() == 0) {
+               set_error(IL_DL, ENOENT, "plugin_init: broker uri not configured\n");
+               return -1;
+       }
+
        try {
                activemq::library::ActiveMQCPP::initializeLibrary();
 
@@ -332,8 +361,8 @@ plugin_init(const char *config)
                                OutputPlugin::connectionFactory = NULL;
                        }
                } catch(cms::CMSException &e) {
-
                }
+               set_error(IL_DL, 0, (char*)e.what());
                return -1;
        }
 
index ce63029..d364693 100644 (file)
@@ -535,7 +535,7 @@ main (int argc, char **argv)
                  if(p) *p = '\n';
                  if(ret > 0) {
                          glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "  loading plugin %s\n", name);
-                         if(plugin_init(name, config) < 0) {
+                         if(plugin_mgr_init(name, config) < 0) {
                                  glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_ERROR, "Failed to load plugin %s: %s\n", name, error_get_msg());
                          }
                  }
index e35f727..43bc527 100644 (file)
@@ -206,7 +206,7 @@ struct il_output_plugin {
        int     (*event_queue_connect)(struct event_queue *);
        int     (*event_queue_send)(struct event_queue *);
        int     (*event_queue_close)(struct event_queue *);
-       int             (*plugin_init)(const char *);
+       int             (*plugin_init)(char *);
        int             (*plugin_supports_scheme)(const char *);
 };
 
@@ -290,7 +290,7 @@ int receive_http(void *, int (*)(void *, char *, const int), il_http_message_t *
 #endif
 
 /* plugin functions */
-int plugin_init(const char *, const char *);
+int plugin_mgr_init(const char *, char *);
 struct il_output_plugin *plugin_get(const char *);
 
 /* master main loop */
index 49bb075..9d32a58 100644 (file)
@@ -23,7 +23,7 @@ static struct plugin_list *plugins = NULL;
                return -1; \
        }
 
-int plugin_init(const char *plugin_name, const char *cfg)
+int plugin_mgr_init(const char *plugin_name, char *cfg)
 {
        char err[256];
        void *dl_handle;