[svn-commits] bkruse: branch group/appdocsxml r134860 - in /team/group/appdocsxml: ./ main/
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Thu Jul 31 12:39:30 CDT 2008
Author: bkruse
Date: Thu Jul 31 12:39:30 2008
New Revision: 134860
URL: http://svn.digium.com/view/asterisk?view=rev&rev=134860
Log:
Fixes:
- Memory was being overwritten when creating the path string, you didn't count the '/'.
- It it not necessary to fclose(NULL), when fopen() failed to open 'xmldoc'.
- ast_config_destroy() when not using anymore the allocated config structure.
Changes:
- The Makefile should install doc/core-*.xml (and not only core-en.xml) to /var/lib/asterisk (if more languages are created their will be put there).
- When opening the documentation file, open core-<language>.xml.
- language was setted as en_US, es_SP, etc, so, the main filename was changed to core-en_US.xml.
- finish adding 'XML_DOCUMENTATION' preprocesor checks to avoid compiling code that refers to xml_documentation.
- Minor syntax changes:
Instead of using a looooong for(init;cond;inc) with a biiig 'init' and a biiig 'inc' use:
init;
while(cond) { ; inc;}
making code more readable.
(closes issue #13203)
(patch by elliel)
Modified:
team/group/appdocsxml/Makefile
team/group/appdocsxml/main/pbx.c
Modified: team/group/appdocsxml/Makefile
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/Makefile?view=diff&rev=134860&r1=134859&r2=134860
==============================================================================
--- team/group/appdocsxml/Makefile (original)
+++ team/group/appdocsxml/Makefile Thu Jul 31 12:39:30 2008
@@ -488,16 +488,16 @@
documentation:
@echo -n "Building Documentation For: "
- @echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > doc/core-en.xml
- @echo "<docs>" >> doc/core-en.xml
+ @echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > doc/core-en_US.xml
+ @echo "<docs>" >> doc/core-en_US.xml
@for x in $(MOD_SUBDIRS); do \
echo -n "$$x " ; \
for i in $$x/*.c; do \
- $(AWK) -f build_tools/get_documentation $$i >> doc/core-en.xml ; \
+ $(AWK) -f build_tools/get_documentation $$i >> doc/core-en_US.xml ; \
done ; \
done
- @echo "</docs>" >> doc/core-en.xml
- @echo -e "\ndoc/core-en.xml --> $(ASTVARLIBDIR)/core-en.xml"
+ @echo "</docs>" >> doc/core-en_US.xml
+ @echo -e "\ndoc/core-en_US.xml --> $(ASTVARLIBDIR)/core-en_US.xml"
update:
@if [ -d .svn ]; then \
@@ -553,7 +553,7 @@
mkdir -p $(DESTDIR)$(ASTDATADIR)/firmware
mkdir -p $(DESTDIR)$(ASTDATADIR)/firmware/iax
mkdir -p $(DESTDIR)$(ASTMANDIR)/man8
- $(INSTALL) -m 644 doc/core-en.xml $(ASTVARLIBDIR)
+ $(INSTALL) -m 644 doc/core-*.xml $(ASTVARLIBDIR)
$(INSTALL) -m 644 keys/iaxtel.pub $(DESTDIR)$(ASTDATADIR)/keys
$(INSTALL) -m 644 keys/freeworlddialup.pub $(DESTDIR)$(ASTDATADIR)/keys
$(INSTALL) -m 644 doc/asterisk.8 $(DESTDIR)$(ASTMANDIR)/man8
Modified: team/group/appdocsxml/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/group/appdocsxml/main/pbx.c?view=diff&rev=134860&r1=134859&r2=134860
==============================================================================
--- team/group/appdocsxml/main/pbx.c (original)
+++ team/group/appdocsxml/main/pbx.c Thu Jul 31 12:39:30 2008
@@ -27,7 +27,9 @@
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+#ifdef XML_DOCUMENTATION
#include "../menuselect/mxml/mxml.h"
+#endif
#include "asterisk/_private.h"
#include "asterisk/paths.h" /* use ast_config_AST_SYSTEM_NAME */
@@ -110,10 +112,6 @@
#define BACKGROUND_MATCHEXTEN (1 << 2)
#define BACKGROUND_PLAYBACK (1 << 3)
-/* Don't know what this should be. */
-/* XXX: make this configurable */
-#define FILE_XML_DOC "core-en.xml"
-
AST_APP_OPTIONS(background_opts, {
AST_APP_OPTION('s', BACKGROUND_SKIP),
AST_APP_OPTION('n', BACKGROUND_NOANSWER),
@@ -290,6 +288,7 @@
};
#ifdef XML_DOCUMENTATION
+#define DEFAULT_DOCUMENTATION_LANGUAGE "en_US"
char documentation_language[80];
#endif
@@ -2785,31 +2784,32 @@
return cur ? 0 : -1;
}
+#ifdef XML_DOCUMENTATION
static char *ast_mxml_build_syntax(const char *type, const char *name) {
const char *tmp = NULL;
int req_found = 1;
- mxml_node_t *node, *ret, *req;
-
- node = ret = NULL;
-
- if(ast_strlen_zero(type) || ast_strlen_zero(name)) {
+ mxml_node_t *node = NULL, *ret = NULL, *req;
+
+ 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) {
+ if (!documentation_tree) {
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)) {
+ node = mxmlFindElement(documentation_tree, documentation_tree, type, "name", name, MXML_DESCEND);
+ while (node && node->child) {
tmp = mxmlElementGetAttr(node, "language");
if (!strcmp(tmp, documentation_language)) {
ret = mxmlFindElement(node, documentation_tree, NULL, NULL, NULL, MXML_DESCEND_FIRST);
break;
}
+ node = mxmlFindElement(node, documentation_tree, type, "name", name, MXML_DESCEND);
}
/* If we still could not find the language, chose the first one found (english) */
@@ -2817,16 +2817,17 @@
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)) {
+ ret = mxmlFindElement(node, documentation_tree, "option", NULL, NULL, MXML_DESCEND);
+ while (ret) {
if (!req_found) {
tmp = mxmlElementGetAttr(ret, "required");
- if (tmp && (!ast_strlen_zero(tmp))) {
+ if (tmp && !ast_strlen_zero(tmp)) {
/* We found the "required=true" node. Set the req pointer to ret (current node) */
req = ret;
req_found = 0;
- }
- }
-
+ }
+ }
+ ret = mxmlFindElement(ret, documentation_tree, "option", NULL, NULL, MXML_DESCEND);
}
if (!ret || !ret->child) {
@@ -2844,23 +2845,25 @@
node = ret = NULL;
- if(ast_strlen_zero(type) || ast_strlen_zero(name)) {
+ 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) {
+ 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)) {
+ node = mxmlFindElement(documentation_tree, documentation_tree, type, "name", name, MXML_DESCEND);
+ while (node && node->child) {
tmp = mxmlElementGetAttr(node, "language");
if (!strcmp(tmp, documentation_language)) {
ret = mxmlFindElement(node, documentation_tree, var, NULL, NULL, MXML_DESCEND_FIRST);
break;
}
+ node = mxmlFindElement(node, documentation_tree, type, "name", name, MXML_DESCEND);
}
/* If we still could not find the language, chose the first one found (english) */
@@ -2876,6 +2879,7 @@
return ret->child->value.opaque;
}
+#endif /* XML_DOCUMENTATION */
int __ast_custom_function_register(struct ast_custom_function *acf, struct ast_module *mod)
{
@@ -2887,13 +2891,13 @@
acf->mod = mod;
+#ifdef XML_DOCUMENTATION
/* Let's try to find it in the Documentation XML */
if (ast_strlen_zero(acf->desc) && ast_strlen_zero(acf->synopsis)) {
-
acf->synopsis = ast_mxml_get_field("function", acf->name, "synopsis");
acf->desc = ast_mxml_get_field("function", acf->name, "description");
-
- }
+ }
+#endif
AST_RWLIST_WRLOCK(&acf_root);
@@ -4597,6 +4601,7 @@
return -1;
}
+#ifdef XML_DOCUMENTATION
/* Try to lookup the docs in our XML documentation database */
if (ast_strlen_zero(synopsis) && ast_strlen_zero(description)) {
tmp->synopsis = ast_mxml_get_field("application", app, "synopsis");
@@ -4604,7 +4609,8 @@
} else {
tmp->synopsis = synopsis;
tmp->description = description;
- }
+ }
+#endif
strcpy(tmp->name, app);
tmp->execute = execute;
@@ -4628,20 +4634,21 @@
return 0;
}
+#ifdef XML_DOCUMENTATION
void _mxml_error(const char *cb) {
ast_log(LOG_ERROR, "Loading XML Problem: '%s'\n", cb);
documentation_tree = NULL;
}
/*! \brief Load XML Document into buffer for parsing into a list */
-static int ast_load_documentation(void) {
-
+static int ast_load_documentation(void)
+{
FILE *xmldoc;
char *path;
/* This memory is automagically freed */
- path = alloca(strlen(ast_config_AST_DATA_DIR) + strlen(FILE_XML_DOC));
- sprintf(path, "%s/%s", ast_config_AST_DATA_DIR, FILE_XML_DOC);
+ path = alloca(strlen(ast_config_AST_DATA_DIR) + strlen(documentation_language) + strlen("/core-.xml") + 1);
+ sprintf(path, "%s/core-%s.xml", ast_config_AST_DATA_DIR, documentation_language);
/* For now, I just throw away cdata */
xmldoc = fopen(path, "r");
@@ -4650,8 +4657,8 @@
if (!xmldoc) {
ast_log(LOG_ERROR, "Could not open XML Doc at '%s'\n", path);
+ /* try to load default language */
documentation_tree = NULL;
- fclose(xmldoc);
return 1;
}
@@ -4667,6 +4674,7 @@
return 0;
}
+#endif /* XML_DOCUMENTATION */
/*
* Append to the list. We don't have a tail pointer because we need
@@ -4804,6 +4812,7 @@
return CLI_SUCCESS;
}
+#ifdef XML_DOCUMENTATION
/*
* Help for CLI commands ...
*/
@@ -4917,6 +4926,7 @@
return CLI_SUCCESS;
}
+#endif /* XML_DOCUMENTATION */
/*! \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)
@@ -5874,7 +5884,9 @@
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"),
+#ifdef XML_DOCUMENTATION
AST_CLI_DEFINE(handle_show_syntax, "Show syntax"),
+#endif
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"),
@@ -8676,7 +8688,9 @@
#endif
#ifdef XML_DOCUMENTATION
- snprintf(documentation_language, sizeof(documentation_language), "en_US");
+ /* setup default language */
+ snprintf(documentation_language, sizeof(documentation_language), DEFAULT_DOCUMENTATION_LANGUAGE);
+
if (!(cfg = ast_config_load("asterisk.conf", cnfflags))) {
ast_log(LOG_ERROR, "No asterisk.conf? That cannot be good.\n");
}
@@ -8688,6 +8702,8 @@
}
}
}
+ ast_config_destroy(cfg);
+
/* Load Documentation XML Blob */
ast_load_documentation();
#endif
More information about the svn-commits
mailing list