[asterisk-commits] bkruse: branch group/appdocsxml r132168 - /team/group/appdocsxml/main/pbx.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Jul 18 14:42:27 CDT 2008
Author: bkruse
Date: Fri Jul 18 14:42:27 2008
New Revision: 132168
URL: http://svn.digium.com/view/asterisk?view=rev&rev=132168
Log:
Eventually I want to be able to have the syntax
line in "core show application" but I am seperating
the two for testing
Modified:
team/group/appdocsxml/main/pbx.c
Modified: team/group/appdocsxml/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/main/pbx.c?view=diff&rev=132168&r1=132167&r2=132168
==============================================================================
--- team/group/appdocsxml/main/pbx.c (original)
+++ team/group/appdocsxml/main/pbx.c Fri Jul 18 14:42:27 2008
@@ -341,6 +341,7 @@
#ifdef XML_DOCUMENTATION
mxml_node_t *documentation_tree = NULL;
static char *ast_mxml_get_field(const char *type, const char *name, const char *var);
+static char *ast_mxml_build_syntax(const char *type, const char *name, const char *var);
void _mxml_error(const char *cb);
#endif
@@ -2782,6 +2783,60 @@
return cur ? 0 : -1;
}
+static char *ast_mxml_build_syntax(const char *type, const char *name, const char *var) {
+
+ const char *tmp = NULL;
+ char *val = NULL;
+ char *req = NULL;
+ int req_found = 1;
+ mxml_node_t *node, *ret;
+
+ node = ret = NULL;
+
+ if(ast_strlen_zero(type) || ast_strlen_zero(name)) {
+ ast_log(LOG_WARNING, "Tried to look in XML tree with faulty values.\n");
+ return NULL;
+ }
+
+ /* not fully initted yet */
+ if(documentation_tree == NULL) {
+ ast_log(LOG_DEBUG, "Parsing XML Tree Error\n");
+ return NULL;
+ }
+
+ for (node = mxmlFindElement(documentation_tree, documentation_tree, type, "name", name, MXML_DESCEND); node != NULL && node->child != NULL; node = mxmlFindElement(node, documentation_tree, type, "name", name, MXML_DESCEND)) {
+ tmp = mxmlElementGetAttr(node, "language");
+ if (!strcmp(tmp, documentation_language)) {
+ ret = mxmlFindElement(node, documentation_tree, var, NULL, NULL, MXML_DESCEND_FIRST);
+ break;
+ }
+ }
+
+ /* If we still could not find the language, chose the first one found (english) */
+ if (!ret) {
+ node = mxmlFindElement(documentation_tree, documentation_tree, type, "name", name, MXML_DESCEND);
+ }
+
+ for (ret = mxmlFindElement(node, documentation_tree, "option", NULL, NULL, MXML_DESCEND); ret != NULL; ret = mxmlFindElement(ret, documentation_tree, "option", NULL, NULL, MXML_DESCEND)) {
+ if (!req_found) {
+ req = mxmlElementGetAttr(ret, "required");
+ if (req && (!ast_strlen_zero(req))) {
+ /* We found the "required=true" node. Set the req pointer to ret (current node) */
+ req = ret;
+ req_found = 0;
+ }
+ }
+
+ }
+
+ if (!ret || !ret->child) {
+ ast_log(LOG_WARNING, "Cannot find varible '%s' in tree '%s'\n", name, var);
+ return NULL;
+ }
+
+ return ret->child->value.opaque;
+}
+
static char *ast_mxml_get_field(const char *type, const char *name, const char *var) {
const char *tmp = NULL;
@@ -4752,6 +4807,114 @@
return CLI_SUCCESS;
}
+/*
+ * Help for CLI commands ...
+ */
+
+/* XXX This can eventually just be added to handle_show_application */
+
+/*
+ * \brief 'show syntax' CLI command implementation function...
+ */
+static char *handle_show_syntax(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ struct ast_app *aa;
+ int app, no_registered_app = 1;
+ char *ret = NULL;
+ int which = 0;
+ int wordlen;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "core show syntax";
+ e->usage =
+ "Usage: core show syntax <application>\n"
+ " Dumps out a syntactical respresentation of the Application.\n";
+ return NULL;
+ case CLI_GENERATE:
+ /* return the n-th [partial] matching entry */
+ AST_RWLIST_RDLOCK(&apps);
+ AST_RWLIST_TRAVERSE(&apps, aa, list) {
+ if (!strncasecmp(a->word, aa->name, wordlen) && ++which > a->n) {
+ ret = ast_strdup(aa->name);
+ break;
+ }
+ }
+ AST_RWLIST_UNLOCK(&apps);
+
+ return ret;
+ }
+
+ if (a->argc < 4)
+ return CLI_SHOWUSAGE;
+
+ /* ... go through all applications ... */
+ AST_RWLIST_RDLOCK(&apps);
+ AST_RWLIST_TRAVERSE(&apps, aa, list) {
+ /* ... compare this application name with all arguments given
+ * to 'show application' command ... */
+ for (app = 3; app < a->argc; app++) {
+ if (!strcasecmp(aa->name, a->argv[app])) {
+ /* Maximum number of characters added by terminal coloring is 22 */
+ char infotitle[64 + AST_MAX_APP + 22], syntitle[40], destitle[40], taxtitle[40];
+ char info[64 + AST_MAX_APP], *synopsis = NULL, *description = NULL, *syntax = NULL;
+ int synopsis_size, description_size, syntax_size;
+
+ no_registered_app = 0;
+
+ if (aa->synopsis)
+ synopsis_size = strlen(aa->synopsis) + 23;
+ else
+ synopsis_size = strlen("Not available") + 23;
+ synopsis = alloca(synopsis_size);
+
+ if (aa->description)
+ description_size = strlen(aa->description) + 23;
+ else
+ description_size = strlen("Not available") + 23;
+ description = alloca(description_size);
+
+ if (synopsis && description) {
+ snprintf(info, 64 + AST_MAX_APP, "\n -= Syntax representation of App: '%s' =- \n\n", aa->name);
+ term_color(infotitle, info, COLOR_MAGENTA, 0, 64 + AST_MAX_APP + 22);
+ term_color(syntitle, "[Synopsis]\n", COLOR_MAGENTA, 0, 40);
+ term_color(destitle, "[Description]\n", COLOR_MAGENTA, 0, 40);
+ term_color(taxtitle, "[Syntax]\n", COLOR_MAGENTA, 0, 40);
+ term_color(synopsis,
+ aa->synopsis ? aa->synopsis : "Not available",
+ COLOR_CYAN, 0, synopsis_size);
+ term_color(description,
+ aa->description ? aa->description : "Not available",
+ COLOR_CYAN, 0, description_size);
+ term_color(syntax,
+ aa->description ? aa->description : "Not available",
+ COLOR_CYAN, 0, syntax_size);
+
+
+ ast_cli(a->fd,"%s%s%s\n%s%s\n\n%s%s\n", infotitle, syntitle, synopsis, taxtitle, syntax, destitle, description);
+ } else {
+ /* ... one of our applications, show info ...*/
+ ast_cli(a->fd,"\n -= Info about application '%s' =- \n\n"
+ "[Synopsis]\n %s\n\n"
+ "[Description]\n%s\n",
+ aa->name,
+ aa->synopsis ? aa->synopsis : "Not available",
+ aa->description ? aa->description : "Not available");
+ }
+ }
+ }
+ }
+ AST_RWLIST_UNLOCK(&apps);
+
+ /* we found at least one app? no? */
+ if (no_registered_app) {
+ ast_cli(a->fd, "Your application(s) is (are) not registered\n");
+ return CLI_FAILURE;
+ }
+
+ return CLI_SUCCESS;
+}
+
/*! \brief handle_show_hints: CLI support for listing registered dial plan hints */
static char *handle_show_hints(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
@@ -5708,6 +5871,7 @@
AST_CLI_DEFINE(handle_show_chanvar, "Show channel variables"),
AST_CLI_DEFINE(handle_show_function, "Describe a specific dialplan function"),
AST_CLI_DEFINE(handle_show_application, "Describe a specific dialplan application"),
+ AST_CLI_DEFINE(handle_show_syntax, "Show syntax"),
AST_CLI_DEFINE(handle_set_global, "Set global dialplan variable", .deprecate_cmd = &cli_set_global_deprecated),
AST_CLI_DEFINE(handle_set_chanvar, "Set a channel variable", .deprecate_cmd = &cli_set_chanvar_deprecated),
AST_CLI_DEFINE(handle_show_dialplan, "Show dialplan"),
More information about the asterisk-commits
mailing list