static int load_config(int reload) { const char *cat = NULL; struct ast_config *cfg; struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; struct ast_variable *v; int newenablecel = CEL_AMI_ENABLED_DEFAULT; int new_cel_show_user_def = CEL_SHOW_USERDEF_DEFAULT; cfg = ast_config_load(CONF_FILE, config_flags); if (cfg == CONFIG_STATUS_FILEUNCHANGED) { return 0; } if (cfg == CONFIG_STATUS_FILEINVALID) { ast_log(LOG_WARNING, "Configuration file '%s' is invalid. CEL manager Module not activated.\n", CONF_FILE); enablecel = 0; return -1; } else if (!cfg) { ast_log(LOG_WARNING, "Failed to load configuration file. CEL manager Module not activated.\n"); enablecel = 0; return -1; } while ((cat = ast_category_browse(cfg, cat))) { if (strcasecmp(cat, "manager")) { continue; } for (v = ast_variable_browse(cfg, cat); v; v = v->next) { if (!strcasecmp(v->name, "enabled")) { newenablecel = ast_true(v->value) ? 1 : 0; } else if (!strcasecmp(v->name, "show_user_defined")) { new_cel_show_user_def = ast_true(v->value) ? 1 : 0; } else { ast_log(LOG_NOTICE, "Unknown option '%s' specified " "for cel_manager.\n", v->name); } } } ast_config_destroy(cfg); cel_show_user_def = new_cel_show_user_def; if (enablecel && !newenablecel) { ast_cel_backend_unregister(MANAGER_BACKEND_NAME); } else if (!enablecel && newenablecel) { if (ast_cel_backend_register(MANAGER_BACKEND_NAME, manager_log)) { ast_log(LOG_ERROR, "Unable to register Asterisk Call Manager CEL handling\n"); } } enablecel = newenablecel; return 0; }
static int load_module(void) { struct ast_config *cfg; struct ast_flags config_flags = { 0 }; const char *tmp; if ((cfg = ast_config_load(cel_config, config_flags))) { ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME); if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) { ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg)); } ast_config_destroy(cfg); } else { return AST_MODULE_LOAD_DECLINE; } /* * start logging * * NOTE: Yes this causes a slight memory leak if the module is * unloaded. However, it is better than a crash if cdr_radius * and cel_radius are both loaded. */ tmp = ast_strdup("asterisk"); if (tmp) { rc_openlog((char *) tmp); } /* read radiusclient-ng config file */ if (!(rh = rc_read_config(radiuscfg))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg); return AST_MODULE_LOAD_DECLINE; } /* read radiusclient-ng dictionaries */ if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n"); rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } if (ast_cel_backend_register(RADIUS_BACKEND_NAME, radius_log)) { rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } else { return AST_MODULE_LOAD_SUCCESS; } }
static int load_module(void) { struct ast_config *cfg; struct ast_flags config_flags = { 0 }; const char *tmp; if ((cfg = ast_config_load(cel_config, config_flags))) { ast_set2_flag(&global_flags, ast_true(ast_variable_retrieve(cfg, "radius", "usegmtime")), RADIUS_FLAG_USEGMTIME); if ((tmp = ast_variable_retrieve(cfg, "radius", "radiuscfg"))) { ast_copy_string(radiuscfg, tmp, sizeof(radiuscfg)); } ast_config_destroy(cfg); } else { return AST_MODULE_LOAD_DECLINE; } /* create dir /var/lib/cdr if it does not exist. add by liucl */ if (access(cdr_directory,F_OK) == -1){ ast_log(LOG_DEBUG,"cdr_directory %s is not exist, I will create it.\n",cdr_directory); if(ast_mkdir(cdr_directory, 0755) == -1) { ast_log(LOG_ERROR,"Failed to create %s\n", cdr_directory); }else{ ast_log(LOG_DEBUG,"Create directory %s is OK\n",cdr_directory); } } /* liucl add end*/ /* * start logging * * NOTE: Yes this causes a slight memory leak if the module is * unloaded. However, it is better than a crash if cdr_radius * and cel_radius are both loaded. */ tmp = ast_strdup("asterisk"); if (tmp) { rc_openlog((char *) tmp); } /* read radiusclient-ng config file */ if (!(rh = rc_read_config(radiuscfg))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng configuration file %s.\n", radiuscfg); return AST_MODULE_LOAD_DECLINE; } /* read radiusclient-ng dictionaries */ if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary"))) { ast_log(LOG_NOTICE, "Cannot load radiusclient-ng dictionary file.\n"); rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } if (ast_cel_backend_register(RADIUS_BACKEND_NAME, radius_log)) { rc_destroy(rh); rh = NULL; return AST_MODULE_LOAD_DECLINE; } else { /* * * Create a independent thread to monitoring /var/lib/cdr. * * If there is file in the directory, then send it to radius. * * add by liucl * */ start_monitor(); return AST_MODULE_LOAD_SUCCESS; } }