[svn-commits] branch oej/managerstuff - r7894 in /team/oej/managerstuff: ./ include/asterisk/

svn-commits at lists.digium.com svn-commits at lists.digium.com
Mon Jan 9 10:59:38 CST 2006


Author: oej
Date: Mon Jan  9 10:59:35 2006
New Revision: 7894

URL: http://svn.digium.com/view/asterisk?rev=7894&view=rev
Log:
Manager list dialplan command

Modified:
    team/oej/managerstuff/include/asterisk/manager.h
    team/oej/managerstuff/manager.c
    team/oej/managerstuff/pbx.c

Modified: team/oej/managerstuff/include/asterisk/manager.h
URL: http://svn.digium.com/view/asterisk/team/oej/managerstuff/include/asterisk/manager.h?rev=7894&r1=7893&r2=7894&view=diff
==============================================================================
--- team/oej/managerstuff/include/asterisk/manager.h (original)
+++ team/oej/managerstuff/include/asterisk/manager.h Mon Jan  9 10:59:35 2006
@@ -162,7 +162,9 @@
 /*! Send error in manager transaction */
 extern void astman_send_error(struct mansession *s, struct message *m, char *error);
 extern void astman_send_response(struct mansession *s, struct message *m, char *resp, char *msg);
+extern void astman_send_response_full(struct mansession *s, struct message *m, char *resp, char *msg, char *listflag);
 extern void astman_send_ack(struct mansession *s, struct message *m, char *msg);
+extern void astman_send_listack(struct mansession *s, struct message *m, char *msg, char *listflag);
 
 /*! Called by Asterisk initialization */
 extern int init_manager(void);

Modified: team/oej/managerstuff/manager.c
URL: http://svn.digium.com/view/asterisk/team/oej/managerstuff/manager.c?rev=7894&r1=7893&r2=7894&view=diff
==============================================================================
--- team/oej/managerstuff/manager.c (original)
+++ team/oej/managerstuff/manager.c Mon Jan  9 10:59:35 2006
@@ -371,7 +371,7 @@
 	ast_cli(s->fd, "Message: %s\r\n\r\n", error);
 }
 
-void astman_send_response(struct mansession *s, struct message *m, char *resp, char *msg)
+void astman_send_response_full(struct mansession *s, struct message *m, char *resp, char *msg, char *listflag)
 {
 	char *id = astman_get_header(m,"ActionID");
 
@@ -379,14 +379,25 @@
 	if (!ast_strlen_zero(id))
 		ast_cli(s->fd, "ActionID: %s\r\n",id);
 	if (msg)
-		ast_cli(s->fd, "Message: %s\r\n\r\n", msg);
-	else
-		ast_cli(s->fd, "\r\n");
+		ast_cli(s->fd, "Message: %s\r\n", msg);
+	if (listflag)
+		ast_cli(s->fd, "Eventlist: %s\r\n", listflag);		/* Start, complete, cancelled */
+	ast_cli(s->fd, "\r\n");
 }
 
 void astman_send_ack(struct mansession *s, struct message *m, char *msg)
 {
-	astman_send_response(s, m, "Success", msg);
+	astman_send_response_full(s, m, "Success", msg, NULL);
+}
+
+void astman_send_listack(struct mansession *s, struct message *m, char *msg, char *listflag)
+{
+	astman_send_response_full(s, m, "Success", msg, listflag);
+}
+
+void astman_send_response(struct mansession *s, struct message *m, char *resp, char *msg)
+{
+	astman_send_response_full(s, m, resp, msg, NULL);
 }
 
 /*! Tells you if smallstr exists inside bigstr
@@ -587,7 +598,7 @@
 
 static int action_ping(struct mansession *s, struct message *m)
 {
-	astman_send_response(s, m, "Pong", NULL);
+	astman_send_response_full(s, m, "Pong", NULL, NULL);
 	return 0;
 }
 
@@ -604,7 +615,7 @@
 	char *id = astman_get_header(m,"ActionID");
 
 	if (!ast_strlen_zero(id))
-		snprintf(idText,256,"ActionID: %s\r\n",id);
+		snprintf(idText, 256, "ActionID: %s\r\n", id);
 	ast_cli(s->fd, "Response: Success\r\n%s", idText);
 	ast_mutex_lock(&actionlock);
 	while (cur) { /* Walk the list of actions */
@@ -633,7 +644,7 @@
 
 	res = set_eventmask(s, mask);
 	if (res > 0)
-		astman_send_response(s, m, "Events On", NULL);
+		astman_send_response_full(s, m, "Events On", NULL, NULL);
 	else if (res == 0)
 		astman_send_response(s, m, "Events Off", NULL);
 
@@ -771,8 +782,9 @@
 	struct timeval now = ast_tvnow();
 	long elapsed_seconds=0;
 	int all = ast_strlen_zero(name); /* set if we want all channels */
-
-	astman_send_ack(s, m, "Channel status will follow");
+	int count = 0;
+
+	astman_send_listack(s, m, "Channel status will follow", "start");
         if (!ast_strlen_zero(id))
                 snprintf(idText,256,"ActionID: %s\r\n",id);
 	if (all)
@@ -791,6 +803,7 @@
 		else
 			bridge[0] = '\0';
 		if (c->pbx) {
+			count++;
 			if (c->cdr) {
 				elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
 			}
@@ -841,9 +854,10 @@
 		c = ast_channel_walk_locked(c);
 	}
 	ast_cli(s->fd,
-	"Event: StatusComplete\r\n"
+	"EventList: Complete\r\n"
+	"ListItems: %d\r\n"
 	"%s"
-	"\r\n",idText);
+	"\r\n", count, idText);
 	return 0;
 }
 
@@ -977,7 +991,7 @@
 "Description: Generates an outgoing call to a Extension/Context/Priority or\n"
 "  Application/Data\n"
 "Variables: (Names marked with * are required)\n"
-"	*Channel: Channel name to call\n"
+"	*Channel: Dial string to call\n"
 "	Exten: Extension to use (requires 'Context' and 'Priority')\n"
 "	Context: Context to use (requires 'Exten' and 'Priority')\n"
 "	Priority: Priority to use (requires 'Exten' and 'Context')\n"
@@ -1503,7 +1517,7 @@
 	return -1;
 }
 
-/*! \brief  manager_event: Send AMI event to client */
+/*! \brief  Send AMI event to client */
 int manager_event(int category, const char *event, const char *fmt, ...)
 {
 	struct mansession *s;

Modified: team/oej/managerstuff/pbx.c
URL: http://svn.digium.com/view/asterisk/team/oej/managerstuff/pbx.c?rev=7894&r1=7893&r2=7894&view=diff
==============================================================================
--- team/oej/managerstuff/pbx.c (original)
+++ team/oej/managerstuff/pbx.c Mon Jan  9 10:59:35 2006
@@ -3262,6 +3262,7 @@
 	int total_context;
 	int total_exten;
 	int total_prio;
+	int total_items;
 	int context_existence;
 	int extension_existence;
 };
@@ -5660,6 +5661,242 @@
 	return res;
 }
 
+/*--- manager_dpsendack: Send ack once */
+static void manager_dpsendack(struct mansession *s, struct message *m, int *sentack)
+{
+ 	if (*sentack)
+		return;
+	astman_send_listack(s, m, "DialPlan list will follow", "start");
+	*sentack = 1;
+	return;
+}
+
+/*--- manager_show_dialplan_helper: Show dialplan extensions */
+static int manager_show_dialplan_helper(struct mansession *s, struct message *m, char *actionidtext, char *context, char *exten, struct dialplan_counters *dpc, struct ast_include *rinclude)
+{
+	struct ast_context *c;
+	int res=0, old_total_exten = dpc->total_exten;
+	int sentpositivemanagerack = 0;
+
+	if (ast_strlen_zero(exten))
+		exten = NULL;
+	if (ast_strlen_zero(context))
+		context = NULL;
+
+	if (option_debug > 2)
+		ast_log(LOG_DEBUG, "manager_show_dialplan: Context: -%s- Extension: -%s-\n", context, exten);
+
+	/* try to lock contexts */
+	if (ast_lock_contexts()) {
+		astman_send_error(s, m, "Failed to lock contexts\r\n");
+		ast_log(LOG_WARNING, "Failed to lock contexts list for manager: listdialplan\n");
+		return -1;
+	}
+
+	/* walk all contexts ... */
+	for (c = ast_walk_contexts(NULL); c ; c = ast_walk_contexts(c)) {
+		/* show this context? */
+		if (!context ||
+			!strcmp(ast_get_context_name(c), context)) {
+			dpc->context_existence = 1;
+
+			if (option_debug > 2)
+				ast_log(LOG_DEBUG, "manager_show_dialplan: Found Context: %s \n", ast_get_context_name(c));
+
+			/* try to lock context before walking in ... */
+			if (!ast_lock_context(c)) {
+				struct ast_exten *e;
+				struct ast_include *i;
+				struct ast_ignorepat *ip;
+				struct ast_sw *sw;
+				char buf[256], buf2[256];
+
+				/* walk extensions in context  */
+				for (e = ast_walk_context_extensions(c, NULL); e; e = ast_walk_context_extensions(c, e)) {
+					struct ast_exten *p;
+					int prio;
+
+					/* looking for extension? is this our extension? */
+					if (exten &&
+						!ast_extension_match(ast_get_extension_name(e), exten))
+					{
+						if (option_debug > 2)
+							ast_log(LOG_DEBUG, "manager_show_dialplan: Skipping extension %s\n", ast_get_extension_name(e));
+						/* we are looking for extension and it's not our
+ 						 * extension, so skip to next extension */
+						continue;
+					}
+					if (option_debug > 2)
+						ast_log(LOG_DEBUG, "manager_show_dialplan: Found Extension: %s \n", ast_get_extension_name(e));
+
+					dpc->extension_existence = 1;
+
+					/* may we print context info? */	
+					dpc->total_context++;
+					dpc->total_prio++;
+
+					/* write extension name and first peer */	
+					bzero(buf, sizeof(buf));		
+				
+					dpc->total_items++;
+					manager_dpsendack(s, m, &sentpositivemanagerack);
+					ast_cli(s->fd, "Event: ListDialplan\r\n%s", actionidtext);
+					ast_cli(s->fd, "Context: %s\r\nExtension: %s\r\n", ast_get_context_name(c), ast_get_extension_name(e) );
+
+					prio = ast_get_extension_priority(e);
+					if (prio == PRIORITY_HINT) {
+						ast_cli(s->fd, "Priority: hint\r\nApplication: %s\r\n", ast_get_extension_app(e));
+					} else {
+						ast_cli(s->fd, "Priority: %d\r\nApplication: %s\r\nAppData: %s\r\n", prio, ast_get_extension_app(e), (char *) ast_get_extension_app_data(e));
+					}
+					ast_cli(s->fd, "Registrar: %s\r\n\r\n", ast_get_extension_registrar(e));
+
+					dpc->total_exten++;
+
+					/* walk next extension peers */
+					for (p=ast_walk_extension_priorities(e, e); p; p=ast_walk_extension_priorities(e, p)) {
+						dpc->total_prio++;
+						bzero((void *)buf2, sizeof(buf2));
+						bzero((void *)buf, sizeof(buf));
+						dpc->total_items++;
+						manager_dpsendack(s, m, &sentpositivemanagerack);
+						ast_cli(s->fd, "Event: ListDialplan\r\n%s", actionidtext);
+						ast_cli(s->fd, "Context: %s\r\nExtension: %s\r\n", ast_get_context_name(c), ast_get_extension_name(e) );
+
+						if (ast_get_extension_label(p))
+							ast_cli(s->fd, "ExtensionLabel: %s\r\n", ast_get_extension_label(p));
+						prio = ast_get_extension_priority(p);
+						if (prio == PRIORITY_HINT) {
+							ast_cli(s->fd, "Priority: hint\r\nApplication: %s\r\n", ast_get_extension_app(p));
+						} else {
+							ast_cli(s->fd, "Priority: %d\r\nApplication: %s\r\nAppData: %s\r\n", prio, ast_get_extension_app(p), (char *) ast_get_extension_app_data(p));
+						}
+						ast_cli(s->fd, "Registrar: %s\r\n\r\n", ast_get_extension_registrar(e));
+					}
+				}
+
+				/* walk included and write info ... */
+				for (i = ast_walk_context_includes(c, NULL); i; i = ast_walk_context_includes(c, i)) {
+					if (exten) {
+						/* Check all includes for the requested extension */
+						manager_show_dialplan_helper(s, m, actionidtext, (char *)ast_get_include_name(i), exten, dpc, i);
+					} else {
+						dpc->total_items++;
+						manager_dpsendack(s, m, &sentpositivemanagerack);
+						ast_cli(s->fd, "Event: ListDialplan\r\n%s", actionidtext);
+						ast_cli(s->fd, "Context: %s\r\nIncludeContext: %s\r\nRegistrar: %s\r\n", ast_get_context_name(c), ast_get_include_name(i), ast_get_include_registrar(i));
+						ast_cli(s->fd, "\r\n");
+	if (option_debug > 2)
+		ast_log(LOG_DEBUG, "manager_show_dialplan: Found Included context: %s \n", buf);
+					}
+				}
+
+				/* walk ignore patterns and write info ... */
+				for (ip=ast_walk_context_ignorepats(c, NULL); ip; ip=ast_walk_context_ignorepats(c, ip)) {
+					const char *ipname = ast_get_ignorepat_name(ip);
+					char ignorepat[AST_MAX_EXTENSION];
+					snprintf(ignorepat, sizeof(ignorepat), "_%s.", ipname);
+					if ((!exten) || ast_extension_match(ignorepat, exten)) {
+						dpc->total_items++;
+						manager_dpsendack(s, m, &sentpositivemanagerack);
+						ast_cli(s->fd, "Event: ListDialplan\r\n%s", actionidtext);
+						ast_cli(s->fd, "Context: %s\r\nIgnorePattern: %s\r\nRegistrar: %s\r\n", ast_get_context_name(c), ipname, ast_get_ignorepat_registrar(ip));
+						ast_cli(s->fd, "\r\n");
+					}
+				}
+				if (!rinclude) {
+					for (sw = ast_walk_context_switches(c, NULL); sw; sw = ast_walk_context_switches(c, sw)) {
+						dpc->total_items++;
+						manager_dpsendack(s, m, &sentpositivemanagerack);
+						ast_cli(s->fd, "Event: ListDialplan\r\n%s", actionidtext);
+						ast_cli(s->fd, "Context: %s\r\nSwitch: %s/%s\r\nRegistrar: %s\r\n", ast_get_context_name(c), ast_get_switch_name(sw), ast_get_switch_data(sw), ast_get_switch_registrar(sw));	
+						ast_cli(s->fd, "\r\n");
+						if (option_debug > 2)
+							ast_log(LOG_DEBUG, "manager_show_dialplan: Found Switch : %s \n", buf);
+					}
+				}
+	
+				ast_unlock_context(c);
+
+			} else if (option_debug > 2) {
+				ast_log(LOG_DEBUG, "manager_show_dialplan: Failed to lock context\n");
+			}
+		}
+	} 
+	ast_unlock_contexts();
+
+	if (dpc->total_exten == old_total_exten) {
+		if (option_debug > 2)
+			ast_log(LOG_DEBUG, "manager_show_dialplan: Found nothing new\n");
+		/* Nothing new under the sun */
+		return -1;
+	} else {
+		return res;
+	}
+}
+
+/* manager_show_dialplan: Manager listing of dial plan */
+static int manager_show_dialplan(struct mansession *s, struct message *m)
+{
+	char *exten = NULL, *context = NULL;
+	char *id = astman_get_header(m, "ActionID");
+	char idtext[256];
+	int res;
+
+	/* Variables used for different counters */
+	struct dialplan_counters counters;
+
+	if (id && !ast_strlen_zero(id))
+		snprintf(idtext, sizeof(idtext), "ActionID: %s\r\n", id);
+
+
+	memset(&counters, 0, sizeof(counters));
+
+	exten = astman_get_header(m, "Extension");
+	context = astman_get_header(m, "Context");
+	
+	res = manager_show_dialplan_helper(s, m, idtext, context, exten, &counters, NULL);
+
+	if (context && !counters.context_existence) {
+		char errorbuf[BUFSIZ];
+	
+		snprintf(errorbuf, sizeof(errorbuf), "Did not find context %s\r\n", context);
+		astman_send_error(s, m, errorbuf);
+		return 0;
+	}
+	if (exten && !counters.extension_existence) {
+		char errorbuf[BUFSIZ];
+
+		if (context)
+			snprintf(errorbuf, sizeof(errorbuf), "Did not find extension %s@%s\r\n", exten, context);
+		else
+			snprintf(errorbuf, sizeof(errorbuf), "Did not find extension %s in any context\r\n", exten);
+		astman_send_error(s, m, errorbuf);
+		return 0;
+	}
+
+	ast_cli(s->fd, "Event: ShowDialPlanComplete\r\n"
+		"EventList: Complete\r\n"
+		"ListItems: %d\r\n"
+		"ListExtensions: %d\r\n"
+		"ListPrios: %d\r\n"	
+		"ListContexts: %d\r\n"	
+		"%s"
+		"\r\n", counters.total_items, counters.total_exten, counters.total_prio, counters.total_context, idtext);
+
+	/* everything ok */
+	return 0;
+}
+
+static char mandescr_show_dialplan[] =
+"Description: Show dialplan contexts and extensions.\n"
+"Variables: \n"
+" ActionID: <id>		Action ID for this AMI transaction (optional)\n"
+" Extension: <extension>	Extension (Optional)\n"
+" Context: <context>		Context (Optional)\n"
+"\n";
+
+
 
 int pbx_builtin_serialize_variables(struct ast_channel *chan, char *buf, size_t size) 
 {



More information about the svn-commits mailing list