[asterisk-commits] rmudgett: branch 11 r406400 - in /branches/11: ./ main/manager.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Jan 24 15:53:46 CST 2014
Author: rmudgett
Date: Fri Jan 24 15:53:43 2014
New Revision: 406400
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=406400
Log:
manager: Register atexit shutdown routine only once.
* Made register atexit shutdown routine only once in __init_manager().
* Fixed some initial load failure conditions in __init_manager().
* Made reset options to defaults on reload when the reload will actually
happen.
* Removed unnecessary container traversals of the white/black filters
during manager_free_user().
* ast_free() does not need a NULL check before calling.
........
Merged revisions 406359 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Modified:
branches/11/ (props changed)
branches/11/main/manager.c
Propchange: branches/11/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.
Modified: branches/11/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/main/manager.c?view=diff&rev=406400&r1=406399&r2=406400
==============================================================================
--- branches/11/main/manager.c (original)
+++ branches/11/main/manager.c Fri Jan 24 15:53:43 2014
@@ -1501,11 +1501,11 @@
}
if (session->whitefilters) {
- ao2_t_ref(session->whitefilters, -1 , "decrement ref for white container, should be last one");
+ ao2_t_ref(session->whitefilters, -1, "decrement ref for white container, should be last one");
}
if (session->blackfilters) {
- ao2_t_ref(session->blackfilters, -1 , "decrement ref for black container, should be last one");
+ ao2_t_ref(session->blackfilters, -1, "decrement ref for black container, should be last one");
}
}
@@ -6620,12 +6620,8 @@
if (method == AST_HTTP_POST && params) {
ast_variables_destroy(params);
}
- if (http_header) {
- ast_free(http_header);
- }
- if (out) {
- ast_free(out);
- }
+ ast_free(http_header);
+ ast_free(out);
if (session && blastaway) {
session_destroy(session);
@@ -7136,7 +7132,6 @@
.read_max = 12,
};
-static int registered = 0;
static int webregged = 0;
/*! \brief cleanup code called at each iteration of server_root,
@@ -7447,16 +7442,14 @@
/*! \internal \brief Free a user record. Should already be removed from the list */
static void manager_free_user(struct ast_manager_user *user)
{
- if (user->a1_hash) {
- ast_free(user->a1_hash);
- }
- if (user->secret) {
- ast_free(user->secret);
- }
- ao2_t_callback(user->whitefilters, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "unlink all white filters");
- ao2_t_callback(user->blackfilters, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, NULL, NULL, "unlink all black filters");
- ao2_t_ref(user->whitefilters, -1, "decrement ref for white container, should be last one");
- ao2_t_ref(user->blackfilters, -1, "decrement ref for black container, should be last one");
+ ast_free(user->a1_hash);
+ ast_free(user->secret);
+ if (user->whitefilters) {
+ ao2_t_ref(user->whitefilters, -1, "decrement ref for white container, should be last one");
+ }
+ if (user->blackfilters) {
+ ao2_t_ref(user->blackfilters, -1, "decrement ref for black container, should be last one");
+ }
user->acl = ast_free_acl_list(user->acl);
ast_variables_destroy(user->chanvars);
ast_free(user);
@@ -7467,45 +7460,43 @@
{
struct ast_manager_user *user;
- if (registered) {
- ast_manager_unregister("Ping");
- ast_manager_unregister("Events");
- ast_manager_unregister("Logoff");
- ast_manager_unregister("Login");
- ast_manager_unregister("Challenge");
- ast_manager_unregister("Hangup");
- ast_manager_unregister("Status");
- ast_manager_unregister("Setvar");
- ast_manager_unregister("Getvar");
- ast_manager_unregister("GetConfig");
- ast_manager_unregister("GetConfigJSON");
- ast_manager_unregister("UpdateConfig");
- ast_manager_unregister("CreateConfig");
- ast_manager_unregister("ListCategories");
- ast_manager_unregister("Redirect");
- ast_manager_unregister("Atxfer");
- ast_manager_unregister("Originate");
- ast_manager_unregister("Command");
- ast_manager_unregister("ExtensionState");
- ast_manager_unregister("PresenceState");
- ast_manager_unregister("AbsoluteTimeout");
- ast_manager_unregister("MailboxStatus");
- ast_manager_unregister("MailboxCount");
- ast_manager_unregister("ListCommands");
- ast_manager_unregister("SendText");
- ast_manager_unregister("UserEvent");
- ast_manager_unregister("WaitEvent");
- ast_manager_unregister("CoreSettings");
- ast_manager_unregister("CoreStatus");
- ast_manager_unregister("Reload");
- ast_manager_unregister("CoreShowChannels");
- ast_manager_unregister("ModuleLoad");
- ast_manager_unregister("ModuleCheck");
- ast_manager_unregister("AOCMessage");
- ast_manager_unregister("Filter");
- ast_custom_function_unregister(&managerclient_function);
- ast_cli_unregister_multiple(cli_manager, ARRAY_LEN(cli_manager));
- }
+ ast_manager_unregister("Ping");
+ ast_manager_unregister("Events");
+ ast_manager_unregister("Logoff");
+ ast_manager_unregister("Login");
+ ast_manager_unregister("Challenge");
+ ast_manager_unregister("Hangup");
+ ast_manager_unregister("Status");
+ ast_manager_unregister("Setvar");
+ ast_manager_unregister("Getvar");
+ ast_manager_unregister("GetConfig");
+ ast_manager_unregister("GetConfigJSON");
+ ast_manager_unregister("UpdateConfig");
+ ast_manager_unregister("CreateConfig");
+ ast_manager_unregister("ListCategories");
+ ast_manager_unregister("Redirect");
+ ast_manager_unregister("Atxfer");
+ ast_manager_unregister("Originate");
+ ast_manager_unregister("Command");
+ ast_manager_unregister("ExtensionState");
+ ast_manager_unregister("PresenceState");
+ ast_manager_unregister("AbsoluteTimeout");
+ ast_manager_unregister("MailboxStatus");
+ ast_manager_unregister("MailboxCount");
+ ast_manager_unregister("ListCommands");
+ ast_manager_unregister("SendText");
+ ast_manager_unregister("UserEvent");
+ ast_manager_unregister("WaitEvent");
+ ast_manager_unregister("CoreSettings");
+ ast_manager_unregister("CoreStatus");
+ ast_manager_unregister("Reload");
+ ast_manager_unregister("CoreShowChannels");
+ ast_manager_unregister("ModuleLoad");
+ ast_manager_unregister("ModuleCheck");
+ ast_manager_unregister("AOCMessage");
+ ast_manager_unregister("Filter");
+ ast_custom_function_unregister(&managerclient_function);
+ ast_cli_unregister_multiple(cli_manager, ARRAY_LEN(cli_manager));
#ifdef AST_XML_DOCS
ao2_t_global_obj_release(event_docs, "Dispose of event_docs");
@@ -7514,18 +7505,12 @@
ast_tcptls_server_stop(&ami_desc);
ast_tcptls_server_stop(&amis_desc);
- if (ami_tls_cfg.certfile) {
- ast_free(ami_tls_cfg.certfile);
- ami_tls_cfg.certfile = NULL;
- }
- if (ami_tls_cfg.pvtfile) {
- ast_free(ami_tls_cfg.pvtfile);
- ami_tls_cfg.pvtfile = NULL;
- }
- if (ami_tls_cfg.cipher) {
- ast_free(ami_tls_cfg.cipher);
- ami_tls_cfg.cipher = NULL;
- }
+ ast_free(ami_tls_cfg.certfile);
+ ami_tls_cfg.certfile = NULL;
+ ast_free(ami_tls_cfg.pvtfile);
+ ami_tls_cfg.pvtfile = NULL;
+ ast_free(ami_tls_cfg.cipher);
+ ami_tls_cfg.cipher = NULL;
ao2_global_obj_release(mgr_sessions);
@@ -7534,12 +7519,35 @@
}
}
+static void manager_set_defaults(void)
+{
+ manager_enabled = 0;
+ displayconnects = 1;
+ broken_events_action = 0;
+ authtimeout = 30;
+ authlimit = 50;
+ manager_debug = 0; /* Debug disabled by default */
+
+ /* default values */
+ ast_copy_string(global_realm, S_OR(ast_config_AST_SYSTEM_NAME, DEFAULT_REALM),
+ sizeof(global_realm));
+ ast_sockaddr_setnull(&ami_desc.local_address);
+ ast_sockaddr_setnull(&amis_desc.local_address);
+
+ ami_tls_cfg.enabled = 0;
+ ast_free(ami_tls_cfg.certfile);
+ ami_tls_cfg.certfile = ast_strdup(AST_CERTFILE);
+ ast_free(ami_tls_cfg.pvtfile);
+ ami_tls_cfg.pvtfile = ast_strdup("");
+ ast_free(ami_tls_cfg.cipher);
+ ami_tls_cfg.cipher = ast_strdup("");
+
+ free_channelvars();
+}
+
static int __init_manager(int reload, int by_external_config)
{
struct ast_config *ucfg = NULL, *cfg = NULL;
-#ifdef AST_XML_DOCS
- struct ao2_container *temp_event_docs;
-#endif
const char *val;
char *cat = NULL;
int newhttptimeout = 60;
@@ -7553,9 +7561,14 @@
int tls_was_enabled = 0;
int acl_subscription_flag = 0;
- manager_enabled = 0;
-
- if (!registered) {
+ if (!reload) {
+ struct ao2_container *sessions;
+#ifdef AST_XML_DOCS
+ struct ao2_container *temp_event_docs;
+#endif
+
+ ast_register_atexit(manager_shutdown);
+
/* Register default actions */
ast_manager_register_xml_core("Ping", 0, action_ping);
ast_manager_register_xml_core("Events", 0, action_events);
@@ -7596,33 +7609,37 @@
ast_cli_register_multiple(cli_manager, ARRAY_LEN(cli_manager));
__ast_custom_function_register(&managerclient_function, NULL);
ast_extension_state_add(NULL, NULL, manager_state_cb, NULL);
- registered = 1;
+
/* Append placeholder event so master_eventq never runs dry */
- append_event("Event: Placeholder\r\n\r\n", 0);
- }
+ if (append_event("Event: Placeholder\r\n\r\n", 0)) {
+ return -1;
+ }
#ifdef AST_XML_DOCS
- temp_event_docs = ast_xmldoc_build_documentation("managerEvent");
- if (temp_event_docs) {
- ao2_t_global_obj_replace_unref(event_docs, temp_event_docs, "Toss old event docs");
- ao2_t_ref(temp_event_docs, -1, "Remove creation ref - container holds only ref now");
- }
+ temp_event_docs = ast_xmldoc_build_documentation("managerEvent");
+ if (temp_event_docs) {
+ ao2_t_global_obj_replace_unref(event_docs, temp_event_docs, "Toss old event docs");
+ ao2_t_ref(temp_event_docs, -1, "Remove creation ref - container holds only ref now");
+ }
#endif
- ast_register_atexit(manager_shutdown);
-
- if ((cfg = ast_config_load2("manager.conf", "manager", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
+ /* If you have a NULL hash fn, you only need a single bucket */
+ sessions = ao2_container_alloc(1, NULL, mansession_cmp_fn);
+ if (!sessions) {
+ return -1;
+ }
+ ao2_global_obj_replace_unref(mgr_sessions, sessions);
+ ao2_ref(sessions, -1);
+
+ /* Initialize all settings before first configuration load. */
+ manager_set_defaults();
+ }
+
+ cfg = ast_config_load2("manager.conf", "manager", config_flags);
+ if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
return 0;
- }
-
- displayconnects = 1;
- broken_events_action = 0;
- authtimeout = 30;
- authlimit = 50;
- manager_debug = 0; /* Debug disabled by default */
-
- if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) {
- ast_log(LOG_NOTICE, "Unable to open AMI configuration manager.conf, or configuration is invalid. Asterisk management interface (AMI) disabled.\n");
+ } else if (!cfg || cfg == CONFIG_STATUS_FILEINVALID) {
+ ast_log(LOG_NOTICE, "Unable to open AMI configuration manager.conf, or configuration is invalid.\n");
return 0;
}
@@ -7631,31 +7648,14 @@
acl_change_event_unsubscribe();
}
- /* default values */
- ast_copy_string(global_realm, S_OR(ast_config_AST_SYSTEM_NAME, DEFAULT_REALM), sizeof(global_realm));
- ast_sockaddr_setnull(&ami_desc.local_address);
- ast_sockaddr_setnull(&amis_desc.local_address);
+ if (reload) {
+ /* Reset all settings before reloading configuration */
+ tls_was_enabled = ami_tls_cfg.enabled;
+ manager_set_defaults();
+ }
ast_sockaddr_parse(&ami_desc_local_address_tmp, "[::]", 0);
ast_sockaddr_set_port(&ami_desc_local_address_tmp, DEFAULT_MANAGER_PORT);
-
- tls_was_enabled = (reload && ami_tls_cfg.enabled);
-
- ami_tls_cfg.enabled = 0;
- if (ami_tls_cfg.certfile) {
- ast_free(ami_tls_cfg.certfile);
- }
- ami_tls_cfg.certfile = ast_strdup(AST_CERTFILE);
- if (ami_tls_cfg.pvtfile) {
- ast_free(ami_tls_cfg.pvtfile);
- }
- ami_tls_cfg.pvtfile = ast_strdup("");
- if (ami_tls_cfg.cipher) {
- ast_free(ami_tls_cfg.cipher);
- }
- ami_tls_cfg.cipher = ast_strdup("");
-
- free_channelvars();
for (var = ast_variable_browse(cfg, "general"); var; var = var->next) {
val = var->value;
@@ -7815,9 +7815,7 @@
}
if (!ast_strlen_zero(user_secret)) {
- if (user->secret) {
- ast_free(user->secret);
- }
+ ast_free(user->secret);
user->secret = ast_strdup(user_secret);
}
@@ -7868,6 +7866,10 @@
user->writetimeout = 100;
user->whitefilters = ao2_container_alloc(1, NULL, NULL);
user->blackfilters = ao2_container_alloc(1, NULL, NULL);
+ if (!user->whitefilters || !user->blackfilters) {
+ manager_free_user(user);
+ break;
+ }
/* Insert into list */
AST_RWLIST_INSERT_TAIL(&users, user, list);
@@ -7885,9 +7887,7 @@
var = ast_variable_browse(cfg, cat);
for (; var; var = var->next) {
if (!strcasecmp(var->name, "secret")) {
- if (user->secret) {
- ast_free(user->secret);
- }
+ ast_free(user->secret);
user->secret = ast_strdup(var->value);
} else if (!strcasecmp(var->name, "deny") ||
!strcasecmp(var->name, "permit") ||
@@ -7947,9 +7947,7 @@
/* Calculate A1 for Digest auth */
snprintf(a1, sizeof(a1), "%s:%s:%s", user->username, global_realm, user->secret);
ast_md5_hash(a1_hash,a1);
- if (user->a1_hash) {
- ast_free(user->a1_hash);
- }
+ ast_free(user->a1_hash);
user->a1_hash = ast_strdup(a1_hash);
continue;
}
@@ -7962,20 +7960,8 @@
AST_RWLIST_UNLOCK(&users);
- if (!reload) {
- struct ao2_container *sessions;
-
- /* If you have a NULL hash fn, you only need a single bucket */
- sessions = ao2_container_alloc(1, NULL, mansession_cmp_fn);
- if (sessions) {
- ao2_global_obj_replace_unref(mgr_sessions, sessions);
- ao2_ref(sessions, -1);
- }
- }
-
if (webmanager_enabled && manager_enabled) {
if (!webregged) {
-
ast_http_uri_link(&rawmanuri);
ast_http_uri_link(&manageruri);
ast_http_uri_link(&managerxmluri);
@@ -8002,7 +7988,11 @@
httptimeout = newhttptimeout;
}
- manager_event(EVENT_FLAG_SYSTEM, "Reload", "Module: Manager\r\nStatus: %s\r\nMessage: Manager reload Requested\r\n", manager_enabled ? "Enabled" : "Disabled");
+ manager_event(EVENT_FLAG_SYSTEM, "Reload",
+ "Module: Manager\r\n"
+ "Status: %s\r\n"
+ "Message: Manager reload Requested\r\n",
+ manager_enabled ? "Enabled" : "Disabled");
ast_tcptls_server_start(&ami_desc);
if (tls_was_enabled && !ami_tls_cfg.enabled) {
More information about the asterisk-commits
mailing list