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;
};
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 */
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)
{
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;
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;
}
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
}