Index: pbx/pbx_realtime.c =================================================================== --- pbx/pbx_realtime.c (revision 166953) +++ pbx/pbx_realtime.c (working copy) @@ -280,6 +280,51 @@ matchmore: realtime_matchmore, }; +static int reload_module(void) +{ + struct ast_flags flags = { 0 }; + struct ast_config *cfg; + struct ast_context *local_contexts = NULL, *con; + struct ast_hashtab *local_table = NULL; + const char *cxt, *prev = "", *registrar = "pbx_realtime"; + char *register_contexts, *table; + + if (!(cfg = ast_config_load("pbx_realtime.conf", flags))) { + ast_merge_contexts_and_delete(&local_contexts, NULL, registrar); + return 0; + } + + if (!(register_contexts = ast_strdupa(ast_variable_retrieve(cfg, "general", "register")))) { + ast_config_destroy(cfg); + return 0; + } + + ast_config_destroy(cfg); + + if (!ast_strlen_zero(register_contexts)) { + while ((table = strsep(®ister_contexts, ","))) { + if (!(cfg = ast_load_realtime_multientry(ast_strip(table), "context LIKE", "%", "priority", "1", SENTINEL))) { + continue; + } + + for (cxt = ast_category_browse(cfg, NULL); cxt; prev = cxt, cxt = ast_category_browse(cfg, cxt)) { + /* Skip duplicates */ + if (!strcmp(cxt, prev)) { + continue; + } + if (!(con = ast_context_find_or_create(&local_contexts, local_table, cxt, registrar))) { + continue; + } + ast_context_add_switch2(con, "Realtime", "", 0, registrar); + } + + ast_config_destroy(cfg); + } + ast_merge_contexts_and_delete(&local_contexts, local_table, registrar); + } + return 0; +} + static int unload_module(void) { ast_unregister_switch(&realtime_switch); @@ -290,7 +335,12 @@ { if (ast_register_switch(&realtime_switch)) return AST_MODULE_LOAD_FAILURE; + reload_module(); return AST_MODULE_LOAD_SUCCESS; } -AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Realtime Switch"); +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Realtime Switch", + .load = load_module, + .unload = unload_module, + .reload = reload_module, + );