[Asterisk-cvs] asterisk pbx.c,1.204,1.205

markster at lists.digium.com markster at lists.digium.com
Mon Feb 21 00:32:25 CST 2005


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv29538

Modified Files:
	pbx.c 
Log Message:
Add "show hints" to CLI (bug #3631)


Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.204
retrieving revision 1.205
diff -u -d -r1.204 -r1.205
--- pbx.c	17 Feb 2005 19:41:23 -0000	1.204
+++ pbx.c	21 Feb 2005 06:31:01 -0000	1.205
@@ -1393,6 +1393,7 @@
 
 }
 
+/*--- ast_hint_extension: Find hint for given extension in context */
 static struct ast_exten *ast_hint_extension(struct ast_channel *c, const char *context, const char *exten)
 {
 	struct ast_exten *e;
@@ -1730,6 +1731,7 @@
 	return -1;
 }
 
+/*--- ast_add_hint: Add hint to hint list, check initial extension state */
 static int ast_add_hint(struct ast_exten *e)
 {
 	struct ast_hint *list;
@@ -1744,17 +1746,24 @@
 	while (list) {
 		if (list->exten == e) {
 			ast_mutex_unlock(&hintlock);
+			if (option_debug > 1)
+				ast_log(LOG_DEBUG, "HINTS: Not re-adding existing hint %s: %s\n", ast_get_extension_name(e), ast_get_extension_app(e));
 			return -1;
 		}
 		list = list->next;    
     	}
 
+	if (option_debug > 1)
+		ast_log(LOG_DEBUG, "HINTS: Adding hint %s: %s\n", ast_get_extension_name(e), ast_get_extension_app(e));
+
 	list = malloc(sizeof(struct ast_hint));
 	if (!list) {
 		ast_mutex_unlock(&hintlock);
+		if (option_debug > 1)
+			ast_log(LOG_DEBUG, "HINTS: Out of memory...\n");
 		return -1;
 	}
-	/* Initialize and insert new item */
+	/* Initialize and insert new item at the top */
 	memset(list, 0, sizeof(struct ast_hint));
 	list->exten = e;
 	list->laststate = ast_extension_state2(e);
@@ -1765,6 +1774,7 @@
 	return 0;
 }
 
+/*--- ast_change_hint: Change hint for an extension */
 static int ast_change_hint(struct ast_exten *oe, struct ast_exten *ne)
 { 
 	struct ast_hint *list;
@@ -1785,6 +1795,7 @@
 	return -1;
 }
 
+/*--- ast_remove_hint: Remove hint from extension */
 static int ast_remove_hint(struct ast_exten *e)
 {
 	/* Cleanup the Notifys if hint is removed */
@@ -1829,6 +1840,7 @@
 }
 
 
+/*--- ast_get_hint: Get hint for channel */
 int ast_get_hint(char *hint, int hintsize, char *name, int namesize, struct ast_channel *c, const char *context, const char *exten)
 {
 	struct ast_exten *e;
@@ -2567,6 +2579,11 @@
 "Usage: show switches\n"
 "       Show registered switches\n";
 
+static char show_hints_help[] = 
+"Usage: show hints\n"
+"       Show registered hints\n";
+
+
 /*
  * IMPLEMENTATION OF CLI FUNCTIONS IS IN THE SAME ORDER AS COMMANDS HELPS
  *
@@ -2690,6 +2707,35 @@
 	return RESULT_SUCCESS;
 }
 
+/*--- handle_show_hints: CLI support for listing registred dial plan hints */
+static int handle_show_hints(int fd, int argc, char *argv[])
+{
+	struct ast_hint *hint;
+	int num = 0;
+
+	if (!hints) {
+		ast_cli(fd, "There are no registered dialplan hints\n");
+		return RESULT_SUCCESS;
+	}
+	/* ... we have hints ... */
+	ast_cli(fd, "\n    -= Registered Asterisk Dial Plan Hints =-\n");
+	if (ast_mutex_lock(&hintlock)) {
+		ast_log(LOG_ERROR, "Unable to lock hints\n");
+		return -1;
+	}
+	hint = hints;
+	while (hint) {
+		ast_cli(fd, "   %-20.20s: %-20.20s  State %2d\n", ast_get_extension_name(hint->exten), ast_get_extension_app(hint->exten), hint->laststate );
+		num++;
+		hint = hint->next;
+	}
+	ast_cli(fd, "----------------\n");
+	ast_cli(fd, "- %d hints registred\n", num);
+	ast_mutex_unlock(&hintlock);
+	return RESULT_SUCCESS;
+}
+
+/*--- handle_show_switches: CLI support for listing registred dial plan switches */
 static int handle_show_switches(int fd, int argc, char *argv[])
 {
 	struct ast_switch *sw;
@@ -3118,6 +3164,12 @@
 		handle_show_switches, "Show alternative switches",
 		show_switches_help, NULL };
 
+static struct ast_cli_entry show_hints_cli =
+	{ { "show", "hints", NULL },
+		handle_show_hints, "Show dial plan hints",
+		show_hints_help, NULL };
+
+
 int ast_unregister_application(const char *app) {
 	struct ast_app *tmp, *tmpl = NULL;
 	if (ast_mutex_lock(&applock)) {
@@ -4220,9 +4272,10 @@
 						con->root = tmp;
 					}
 					ast_mutex_unlock(&con->lock);
+
 					/* And immediately return success. */
 					if (tmp->priority == PRIORITY_HINT)
-					    ast_add_hint(tmp);
+						 ast_add_hint(tmp);
 					
 					LOG;
 					return 0;
@@ -5366,6 +5419,7 @@
 	ast_cli_register(&show_application_cli);
 	ast_cli_register(&show_dialplan_cli);
 	ast_cli_register(&show_switches_cli);
+	ast_cli_register(&show_hints_cli);
 
 	/* Register builtin applications */
 	for (x=0; x<sizeof(builtins) / sizeof(struct pbx_builtin); x++) {




More information about the svn-commits mailing list