]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
another step towards multi-profile file logger.
authorMichael Jerris <mike@jerris.com>
Wed, 5 Dec 2007 12:52:37 +0000 (12:52 +0000)
committerMichael Jerris <mike@jerris.com>
Wed, 5 Dec 2007 12:52:37 +0000 (12:52 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6515 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/loggers/mod_logfile/mod_logfile.c

index c75d3c5d80dd52809202e2a90d8adc0deb967843..8160d448fe697549f0f76d85c51eaf55c3dd9d99 100644 (file)
@@ -42,6 +42,9 @@ SWITCH_MODULE_DEFINITION(mod_logfile, mod_logfile_load, mod_logfile_shutdown, NU
 static const uint8_t STATIC_LEVELS[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
 
 static switch_memory_pool_t *module_pool = NULL;
+static switch_hash_t *log_hash = NULL;\r
+static switch_hash_t *name_hash = NULL;
+static switch_hash_t *profile_hash = NULL;
 
 static struct {
        int rotate;
@@ -54,6 +57,7 @@ struct level_set {
 };
 
 struct logfile_profile {
+       char *name;
        unsigned int log_fd;
        switch_size_t log_size;   /* keep the log size in check for rotation */
        switch_size_t roll_size;  /* the size that we want to rotate the file at */
@@ -66,7 +70,25 @@ typedef struct logfile_profile logfile_profile_t;
 
 static logfile_profile_t *default_profile;
 
-static switch_status_t load_config(logfile_profile_t *profile, switch_xml_t xml);
+static switch_status_t load_profile(logfile_profile_t *profile, switch_xml_t xml);
+
+static void del_mapping(char *var)\r
+{\r
+       switch_core_hash_insert(log_hash, var, NULL);\r
+}\r
+\r
+static void add_mapping(char *var, logfile_profile_t *profile)\r
+{\r
+       char *name;\r
+\r
+       if (!(name = switch_core_hash_find(name_hash, var))) {\r
+               name = switch_core_strdup(module_pool, var);\r
+               switch_core_hash_insert(name_hash, name, name);\r
+       }\r
+\r
+       del_mapping(name);\r
+       switch_core_hash_insert(log_hash, name, (void *) profile);\r
+}\r
 
 void process_levels(logfile_profile_t *profile, char *p)
 {
@@ -244,7 +266,7 @@ static switch_status_t mod_logfile_logger(const switch_log_node_t *node, switch_
        return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t load_config(logfile_profile_t *profile, switch_xml_t xml)
+static switch_status_t load_profile(logfile_profile_t *profile, switch_xml_t xml)
 {
        switch_xml_t param;
 
@@ -301,6 +323,19 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_logfile_load)
        memset(&globals, 0, sizeof(globals));
        switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool);
 
+       if (log_hash) {\r
+               switch_core_hash_destroy(&log_hash);\r
+       }\r
+       if (name_hash) {\r
+               switch_core_hash_destroy(&name_hash);\r
+       }\r
+       if (profile_hash) {\r
+               switch_core_hash_destroy(&profile_hash);\r
+       }\r
+       switch_core_hash_init(&log_hash, module_pool);\r
+       switch_core_hash_init(&name_hash, module_pool);\r
+       switch_core_hash_init(&profile_hash, module_pool);\r
+
        if (switch_event_bind((char *) modname, SWITCH_EVENT_TRAP, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
                return SWITCH_STATUS_GENERR;
@@ -323,13 +358,18 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_logfile_load)
                }
                if ((profiles = switch_xml_child(cfg, "profiles"))) {
                        for (xprofile = switch_xml_child(profiles, "profile"); xprofile; xprofile = xprofile->next) {\r
+                               char *name = (char *) switch_xml_attr_soft(xprofile, "name");\r
                                if (!(settings = switch_xml_child(xprofile, "settings"))) {\r
                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Settings, check the new config!\n");\r
                                } else {\r
-                                       /* TODO: handle alloc of profile for multiple profiles*/\r
-                                       default_profile = switch_core_alloc(module_pool, sizeof(*default_profile));
-                                       memset(default_profile, 0, sizeof(*default_profile));
-                                       load_config(default_profile, settings);\r
+                                       logfile_profile_t *profile;\r
+                                       profile = switch_core_alloc(module_pool, sizeof(*default_profile));
+                                       memset(profile, 0, sizeof(*profile));
+                                       profile->name = switch_core_strdup(module_pool, switch_str_nil(name));
+                                       load_profile(profile, settings);\r
+                                       switch_core_hash_insert(profile_hash, profile->name, (void *) profile);\r
+                                       /* TODO: remove default_profile */\r
+                                       default_profile = profile;\r
                                }\r
                        }\r
                }