[asterisk-commits] file: branch file/usecnt-cleanup r54712 - in /team/file/usecnt-cleanup: inclu...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Feb 15 17:15:06 MST 2007


Author: file
Date: Thu Feb 15 18:15:05 2007
New Revision: 54712

URL: http://svn.digium.com/view/asterisk?view=rev&rev=54712
Log:
Add support for referencing on manager actions and automatic unregistration.

Modified:
    team/file/usecnt-cleanup/include/asterisk/manager.h
    team/file/usecnt-cleanup/include/asterisk/module.h
    team/file/usecnt-cleanup/main/db.c
    team/file/usecnt-cleanup/main/loader.c
    team/file/usecnt-cleanup/main/manager.c

Modified: team/file/usecnt-cleanup/include/asterisk/manager.h
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/include/asterisk/manager.h?view=diff&rev=54712&r1=54711&r2=54712
==============================================================================
--- team/file/usecnt-cleanup/include/asterisk/manager.h (original)
+++ team/file/usecnt-cleanup/include/asterisk/manager.h Thu Feb 15 18:15:05 2007
@@ -106,6 +106,8 @@
 	int authority;
 	/*! Function to be called */
 	int (*func)(struct mansession *s, const struct message *m);
+	/*! Module this manager action came from */
+	struct ast_module *module;
 	/*! For easy linking */
 	struct manager_action *next;
 };
@@ -122,12 +124,14 @@
 	\param synopsis Help text (one line, up to 30 chars) for CLI manager show commands
 	\param description Help text, several lines
 */
-int ast_manager_register2(
+#define ast_manager_register2(a, b, c, d, e) __ast_manager_register2(a, b, c, d, e, ast_module_info->self)
+int __ast_manager_register2(
 	const char *action,
 	int authority,
 	int (*func)(struct mansession *s, const struct message *m),
 	const char *synopsis,
-	const char *description);
+	const char *description,
+	struct ast_module *mod);
 
 /*! Unregister a registred manager command */
 /*!	\param action Name of registred Action:

Modified: team/file/usecnt-cleanup/include/asterisk/module.h
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/include/asterisk/module.h?view=diff&rev=54712&r1=54711&r2=54712
==============================================================================
--- team/file/usecnt-cleanup/include/asterisk/module.h (original)
+++ team/file/usecnt-cleanup/include/asterisk/module.h Thu Feb 15 18:15:05 2007
@@ -73,6 +73,7 @@
 	AST_MODULE_REGISTERED_FORMAT,          /*!< Module registered a format */
 	AST_MODULE_REGISTERED_CDR,             /*!< Module registered a CDR handler */
 	AST_MODULE_REGISTERED_FUNCTION,        /*!< Module registered a dialplan function */
+	AST_MODULE_REGISTERED_ACTION,          /*!< Module registered a manager action */
 };
 
 /*! 

Modified: team/file/usecnt-cleanup/main/db.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/db.c?view=diff&rev=54712&r1=54711&r2=54712
==============================================================================
--- team/file/usecnt-cleanup/main/db.c (original)
+++ team/file/usecnt-cleanup/main/db.c Thu Feb 15 18:15:05 2007
@@ -641,9 +641,9 @@
 {
 	dbinit();
 	__ast_cli_register_multiple(cli_database, sizeof(cli_database) / sizeof(struct ast_cli_entry), NULL);
-	ast_manager_register("DBGet", EVENT_FLAG_SYSTEM, manager_dbget, "Get DB Entry");
-	ast_manager_register("DBPut", EVENT_FLAG_SYSTEM, manager_dbput, "Put DB Entry");
-	ast_manager_register("DBDel", EVENT_FLAG_SYSTEM, manager_dbdel, "Delete DB Entry");
-	ast_manager_register("DBDelTree", EVENT_FLAG_SYSTEM, manager_dbdeltree, "Delete DB Tree");
-	return 0;
-}
+	__ast_manager_register2("DBGet", EVENT_FLAG_SYSTEM, manager_dbget, "Get DB Entry", NULL, NULL);
+	__ast_manager_register2("DBPut", EVENT_FLAG_SYSTEM, manager_dbput, "Put DB Entry", NULL, NULL);
+	__ast_manager_register2("DBDel", EVENT_FLAG_SYSTEM, manager_dbdel, "Delete DB Entry", NULL, NULL);
+	__ast_manager_register2("DBDelTree", EVENT_FLAG_SYSTEM, manager_dbdeltree, "Delete DB Tree", NULL, NULL);
+	return 0;
+}

Modified: team/file/usecnt-cleanup/main/loader.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/loader.c?view=diff&rev=54712&r1=54711&r2=54712
==============================================================================
--- team/file/usecnt-cleanup/main/loader.c (original)
+++ team/file/usecnt-cleanup/main/loader.c Thu Feb 15 18:15:05 2007
@@ -506,6 +506,8 @@
 					res = ast_format_unregister((const char*)link->data);
 				else if (link->registered == AST_MODULE_REGISTERED_FUNCTION)
 					res = ast_custom_function_unregister((struct ast_custom_function*)link->data);
+				else if (link->registered == AST_MODULE_REGISTERED_ACTION)
+					res = ast_manager_unregister((char*)link->data);
 				free(link);
 				/* Handle error from unregister process */
 				if (res && force <= AST_FORCE_FIRM) {

Modified: team/file/usecnt-cleanup/main/manager.c
URL: http://svn.digium.com/view/asterisk/team/file/usecnt-cleanup/main/manager.c?view=diff&rev=54712&r1=54711&r2=54712
==============================================================================
--- team/file/usecnt-cleanup/main/manager.c (original)
+++ team/file/usecnt-cleanup/main/manager.c Thu Feb 15 18:15:05 2007
@@ -76,6 +76,7 @@
 #include "asterisk/http.h"
 #include "asterisk/threadstorage.h"
 #include "asterisk/linkedlists.h"
+#include "asterisk/module.h"
 
 /*!
  * Linked list of events.
@@ -2092,9 +2093,11 @@
 		if (strcasecmp(action, tmp->action))
 			continue;
 		if ((s->writeperm & tmp->authority) == tmp->authority) {
-			if (tmp->func(s, m)) {	/* error */
-				return -1;
-			}
+			if (tmp->module)
+				ast_module_ref(tmp->module);
+			ret = tmp->func(s, m);
+			if (tmp->module)
+				ast_module_unref(tmp->module);
 		} else
 			astman_send_error(s, m, "Permission denied");
 		break;
@@ -2411,6 +2414,8 @@
 				prev->next = cur->next;
 			else
 				first_action = cur->next;
+			if (cur->module)
+				ast_module_unlink(cur->module, AST_MODULE_REGISTERED_ACTION, (void*)action);
 			free(cur);
 			if (option_verbose > 1)
 				ast_verbose(VERBOSE_PREFIX_2 "Manager unregistered action %s\n", action);
@@ -2458,7 +2463,7 @@
 
 /*! \brief register a new command with manager, including online help. This is
 	the preferred way to register a manager command */
-int ast_manager_register2(const char *action, int auth, int (*func)(struct mansession *s, const struct message *m), const char *synopsis, const char *description)
+int __ast_manager_register2(const char *action, int auth, int (*func)(struct mansession *s, const struct message *m), const char *synopsis, const char *description, struct ast_module *mod)
 {
 	struct manager_action *cur;
 
@@ -2466,6 +2471,10 @@
 	if (!cur)
 		return -1;
 
+	if (mod)
+		ast_module_link(mod, AST_MODULE_REGISTERED_ACTION, (void*)action);
+
+	cur->module = mod;
 	cur->action = action;
 	cur->authority = auth;
 	cur->func = func;
@@ -2955,28 +2964,28 @@
 
 	if (!registered) {
 		/* Register default actions */
-		ast_manager_register2("Ping", 0, action_ping, "Keepalive command", mandescr_ping);
-		ast_manager_register2("Events", 0, action_events, "Control Event Flow", mandescr_events);
-		ast_manager_register2("Logoff", 0, action_logoff, "Logoff Manager", mandescr_logoff);
-		ast_manager_register2("Login", 0, action_login, "Login Manager", NULL);
-		ast_manager_register2("Challenge", 0, action_challenge, "Generate Challenge for MD5 Auth", NULL);
-		ast_manager_register2("Hangup", EVENT_FLAG_CALL, action_hangup, "Hangup Channel", mandescr_hangup);
-		ast_manager_register("Status", EVENT_FLAG_CALL, action_status, "Lists channel status" );
-		ast_manager_register2("Setvar", EVENT_FLAG_CALL, action_setvar, "Set Channel Variable", mandescr_setvar );
-		ast_manager_register2("Getvar", EVENT_FLAG_CALL, action_getvar, "Gets a Channel Variable", mandescr_getvar );
-		ast_manager_register2("GetConfig", EVENT_FLAG_CONFIG, action_getconfig, "Retrieve configuration", mandescr_getconfig);
-		ast_manager_register2("UpdateConfig", EVENT_FLAG_CONFIG, action_updateconfig, "Update basic configuration", mandescr_updateconfig);
-		ast_manager_register2("Redirect", EVENT_FLAG_CALL, action_redirect, "Redirect (transfer) a call", mandescr_redirect );
-		ast_manager_register2("Originate", EVENT_FLAG_CALL, action_originate, "Originate Call", mandescr_originate);
-		ast_manager_register2("Command", EVENT_FLAG_COMMAND, action_command, "Execute Asterisk CLI Command", mandescr_command );
-		ast_manager_register2("ExtensionState", EVENT_FLAG_CALL, action_extensionstate, "Check Extension Status", mandescr_extensionstate );
-		ast_manager_register2("AbsoluteTimeout", EVENT_FLAG_CALL, action_timeout, "Set Absolute Timeout", mandescr_timeout );
-		ast_manager_register2("MailboxStatus", EVENT_FLAG_CALL, action_mailboxstatus, "Check Mailbox", mandescr_mailboxstatus );
-		ast_manager_register2("MailboxCount", EVENT_FLAG_CALL, action_mailboxcount, "Check Mailbox Message Count", mandescr_mailboxcount );
-		ast_manager_register2("ListCommands", 0, action_listcommands, "List available manager commands", mandescr_listcommands);
-		ast_manager_register2("SendText", EVENT_FLAG_CALL, action_sendtext, "Send text message to channel", mandescr_sendtext);
-		ast_manager_register2("UserEvent", EVENT_FLAG_USER, action_userevent, "Send an arbitrary event", mandescr_userevent);
-		ast_manager_register2("WaitEvent", 0, action_waitevent, "Wait for an event to occur", mandescr_waitevent);
+		__ast_manager_register2("Ping", 0, action_ping, "Keepalive command", mandescr_ping, NULL);
+		__ast_manager_register2("Events", 0, action_events, "Control Event Flow", mandescr_events, NULL);
+		__ast_manager_register2("Logoff", 0, action_logoff, "Logoff Manager", mandescr_logoff, NULL);
+		__ast_manager_register2("Login", 0, action_login, "Login Manager", NULL, NULL);
+		__ast_manager_register2("Challenge", 0, action_challenge, "Generate Challenge for MD5 Auth", NULL, NULL);
+		__ast_manager_register2("Hangup", EVENT_FLAG_CALL, action_hangup, "Hangup Channel", mandescr_hangup, NULL);
+		__ast_manager_register2("Status", EVENT_FLAG_CALL, action_status, "Lists channel status", NULL, NULL);
+		__ast_manager_register2("Setvar", EVENT_FLAG_CALL, action_setvar, "Set Channel Variable", mandescr_setvar, NULL);
+		__ast_manager_register2("Getvar", EVENT_FLAG_CALL, action_getvar, "Gets a Channel Variable", mandescr_getvar, NULL);
+		__ast_manager_register2("GetConfig", EVENT_FLAG_CONFIG, action_getconfig, "Retrieve configuration", mandescr_getconfig, NULL);
+		__ast_manager_register2("UpdateConfig", EVENT_FLAG_CONFIG, action_updateconfig, "Update basic configuration", mandescr_updateconfig, NULL);
+		__ast_manager_register2("Redirect", EVENT_FLAG_CALL, action_redirect, "Redirect (transfer) a call", mandescr_redirect, NULL);
+		__ast_manager_register2("Originate", EVENT_FLAG_CALL, action_originate, "Originate Call", mandescr_originate, NULL);
+		__ast_manager_register2("Command", EVENT_FLAG_COMMAND, action_command, "Execute Asterisk CLI Command", mandescr_command, NULL);
+		__ast_manager_register2("ExtensionState", EVENT_FLAG_CALL, action_extensionstate, "Check Extension Status", mandescr_extensionstate, NULL);
+		__ast_manager_register2("AbsoluteTimeout", EVENT_FLAG_CALL, action_timeout, "Set Absolute Timeout", mandescr_timeout, NULL);
+		__ast_manager_register2("MailboxStatus", EVENT_FLAG_CALL, action_mailboxstatus, "Check Mailbox", mandescr_mailboxstatus, NULL);
+		__ast_manager_register2("MailboxCount", EVENT_FLAG_CALL, action_mailboxcount, "Check Mailbox Message Count", mandescr_mailboxcount, NULL);
+		__ast_manager_register2("ListCommands", 0, action_listcommands, "List available manager commands", mandescr_listcommands, NULL);
+		__ast_manager_register2("SendText", EVENT_FLAG_CALL, action_sendtext, "Send text message to channel", mandescr_sendtext, NULL);
+		__ast_manager_register2("UserEvent", EVENT_FLAG_USER, action_userevent, "Send an arbitrary event", mandescr_userevent, NULL);
+		__ast_manager_register2("WaitEvent", 0, action_waitevent, "Wait for an event to occur", mandescr_waitevent, NULL);
 
 		__ast_cli_register_multiple(cli_manager, sizeof(cli_manager) / sizeof(struct ast_cli_entry), NULL);
 		ast_extension_state_add(NULL, NULL, manager_state_cb, NULL);



More information about the asterisk-commits mailing list