Tue Aug 20 16:35:17 2013

Asterisk developer's documentation


xmldoc.c File Reference

XML Documentation API. More...

#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/paths.h"
#include "asterisk/linkedlists.h"
#include "asterisk/strings.h"
#include "asterisk/config.h"
#include "asterisk/term.h"
#include "asterisk/xmldoc.h"

Go to the source code of this file.

Data Structures

struct  documentation_tree
 XML documentation tree. More...
struct  strcolorized_tags
struct  strspecial_tags
struct  strsyntaxtype
 Mapping between type of node and type of syntax to generate. More...
struct  xmldoc_tree
 Container of documentation trees. More...

Defines

#define GOTONEXT(__rev, __a)   (__rev ? ast_xml_node_get_prev(__a) : ast_xml_node_get_next(__a))
#define ISLAST(__rev, __a)   (__rev == 1 ? (ast_xml_node_get_prev(__a) ? 0 : 1) : (ast_xml_node_get_next(__a) ? 0 : 1))
#define MP(__a)   ((multiple ? __a : ""))

Enumerations

enum  syntaxtype { FUNCTION_SYNTAX, MANAGER_SYNTAX, COMMAND_SYNTAX }
 

Types of syntax that we are able to generate.

More...

Functions

char * ast_xmldoc_build_arguments (const char *type, const char *name, const char *module)
 Generate the [arguments] tag based on type of node ('application', 'function' or 'agi') and name.
char * ast_xmldoc_build_description (const char *type, const char *name, const char *module)
 Generate description documentation from XML.
char * ast_xmldoc_build_seealso (const char *type, const char *name, const char *module)
 Parse the <see-also> node content.
char * ast_xmldoc_build_synopsis (const char *type, const char *name, const char *module)
 Generate synopsis documentation from XML.
char * ast_xmldoc_build_syntax (const char *type, const char *name, const char *module)
 Get the syntax for a specified application or function.
char * ast_xmldoc_printable (const char *bwinput, int withcolors)
 Colorize and put delimiters (instead of tags) to the xmldoc output.
static int xmldoc_attribute_match (struct ast_xml_node *node, const char *attr, const char *value)
static char * xmldoc_build_field (const char *type, const char *name, const char *module, const char *var, int raw)
 Get the content of a field (synopsis, description, etc) from an asterisk document tree.
static int xmldoc_foundspace_backward (const char *text, int currentpos, int maxdiff)
static struct ast_strxmldoc_get_formatted (struct ast_xml_node *node, int raw_output, int raw_wrap)
static struct ast_xml_node * xmldoc_get_node (const char *type, const char *name, const char *module, const char *language)
static char * xmldoc_get_syntax_cmd (struct ast_xml_node *fixnode, const char *name, int printname)
static char * xmldoc_get_syntax_fun (struct ast_xml_node *rootnode, const char *rootname, const char *childname, int printparenthesis, int printrootname)
static char * xmldoc_get_syntax_manager (struct ast_xml_node *fixnode, const char *name)
static enum syntaxtype xmldoc_get_syntax_type (const char *type)
static int xmldoc_has_inside (struct ast_xml_node *fixnode, const char *what)
static int xmldoc_has_nodes (struct ast_xml_node *fixnode)
static int xmldoc_has_specialtags (struct ast_xml_node *fixnode)
static int xmldoc_parse_argument (struct ast_xml_node *fixnode, int insideparameter, const char *paramtabs, const char *tabs, struct ast_str **buffer)
static char * xmldoc_parse_cmd_enumlist (struct ast_xml_node *fixnode)
static int xmldoc_parse_enum (struct ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
static int xmldoc_parse_enumlist (struct ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
static int xmldoc_parse_option (struct ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
static void xmldoc_parse_optionlist (struct ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
static int xmldoc_parse_para (struct ast_xml_node *node, const char *tabs, const char *posttabs, struct ast_str **buffer)
static void xmldoc_parse_parameter (struct ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
static int xmldoc_parse_specialtags (struct ast_xml_node *fixnode, const char *tabs, const char *posttabs, struct ast_str **buffer)
static int xmldoc_parse_variable (struct ast_xml_node *node, const char *tabs, struct ast_str **buffer)
static int xmldoc_parse_variablelist (struct ast_xml_node *node, const char *tabs, struct ast_str **buffer)
static int xmldoc_postbrlen (const char *postbr)
static void xmldoc_reverse_helper (int reverse, int *len, char **syntax, const char *fmt,...)
static void xmldoc_setpostbr (char *postbr, size_t len, const char *text)
static void xmldoc_string_cleanup (const char *text, struct ast_str **output, int lastspaces)
static char * xmldoc_string_wrap (const char *text, int columns, int maxdiff)
static int xmldoc_wait_nextspace (const char *text, int currentpos, int maxdiff)

Variables

static struct strcolorized_tags colorized_tags []
static const char default_documentation_language [] = "en_US"
 Default documentation language.
static char documentation_language [6]
 XML documentation language.
static struct strspecial_tags special_tags []
static struct strsyntaxtype stxtype []
 Mapping between type of node and type of syntax to generate.
static const int xmldoc_max_diff = 5
 This is a value that we will use to let the wrapping mechanism move the cursor backward and forward xmldoc_max_diff positions before cutting the middle of a word, trying to find a space or a
.
static const int xmldoc_text_columns = 74
 Number of columns to print when showing the XML documentation with a 'core show application/function *' CLI command. Used in text wrapping.

Detailed Description

XML Documentation API.

Author:
Eliel C. Sardanons (LU1ALY) <eliels@gmail.com>
ExtRef:
libxml2 http://www.xmlsoft.org/

Definition in file xmldoc.c.


Define Documentation

#define GOTONEXT ( __rev,
__a   )     (__rev ? ast_xml_node_get_prev(__a) : ast_xml_node_get_next(__a))

Referenced by xmldoc_get_syntax_fun().

#define ISLAST ( __rev,
__a   )     (__rev == 1 ? (ast_xml_node_get_prev(__a) ? 0 : 1) : (ast_xml_node_get_next(__a) ? 0 : 1))

Referenced by xmldoc_get_syntax_fun().

#define MP ( __a   )     ((multiple ? __a : ""))

Referenced by xmldoc_get_syntax_fun().


Enumeration Type Documentation

enum syntaxtype

Types of syntax that we are able to generate.

Enumerator:
FUNCTION_SYNTAX 
MANAGER_SYNTAX 
COMMAND_SYNTAX 

Definition at line 1118 of file xmldoc.c.

01118                 {
01119    FUNCTION_SYNTAX,
01120    MANAGER_SYNTAX,
01121    COMMAND_SYNTAX
01122 };


Function Documentation

char* ast_xmldoc_build_arguments ( const char *  type,
const char *  name,
const char *  module 
)

Generate the [arguments] tag based on type of node ('application', 'function' or 'agi') and name.

Parameters:
type 'application', 'function' or 'agi' ?
name Name of the application or function to build the 'arguments' tag.
module The module the item is in (optional, can be NULL)
Return values:
NULL on error.
Output buffer with the [arguments] tag content.

Definition at line 1757 of file xmldoc.c.

References ast_free, ast_str_buffer(), ast_str_create(), ast_str_strlen(), ast_str_truncate(), ast_strdup, ast_strlen_zero(), ast_xml_node_get_children(), ast_xml_node_get_name(), ast_xml_node_get_next(), xmldoc_get_node(), and xmldoc_parse_parameter().

Referenced by acf_retrieve_docs(), ast_manager_register2(), and ast_register_application2().

01758 {
01759    struct ast_xml_node *node;
01760    struct ast_str *ret = ast_str_create(128);
01761    char *retstr = NULL;
01762 
01763    if (ast_strlen_zero(type) || ast_strlen_zero(name)) {
01764       ast_free(ret);
01765       return NULL;
01766    }
01767 
01768    node = xmldoc_get_node(type, name, module, documentation_language);
01769 
01770    if (!node || !ast_xml_node_get_children(node)) {
01771       ast_free(ret);
01772       return NULL;
01773    }
01774 
01775    /* Find the syntax field. */
01776    for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
01777       if (!strcasecmp(ast_xml_node_get_name(node), "syntax")) {
01778          break;
01779       }
01780    }
01781 
01782    if (!node || !ast_xml_node_get_children(node)) {
01783       /* We couldn't find the syntax node. */
01784       ast_free(ret);
01785       return NULL;
01786    }
01787 
01788    for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
01789       xmldoc_parse_parameter(node, "", &ret);
01790    }
01791 
01792    if (ast_str_strlen(ret) > 0) {
01793       /* remove last '\n' */
01794       char *buf = ast_str_buffer(ret);
01795       if (buf[ast_str_strlen(ret) - 1] == '\n') {
01796          ast_str_truncate(ret, -1);
01797       }
01798       retstr = ast_strdup(ast_str_buffer(ret));
01799    }
01800    ast_free(ret);
01801 
01802    return retstr;
01803 }

char* ast_xmldoc_build_description ( const char *  type,
const char *  name,
const char *  module 
)

Generate description documentation from XML.

Parameters:
type The source of documentation (application, function, etc).
name The name of the application, function, etc.
module The module the item is in (optional, can be NULL)
Return values:
NULL on error.
A malloc'ed string with the formatted description.

Definition at line 1896 of file xmldoc.c.

References xmldoc_build_field().

Referenced by acf_retrieve_docs(), ast_agi_register(), ast_manager_register2(), and ast_register_application2().

01897 {
01898    return xmldoc_build_field(type, name, module, "description", 0);
01899 }

char* ast_xmldoc_build_seealso ( const char *  type,
const char *  name,
const char *  module 
)

Parse the <see-also> node content.

Parameters:
type 'application', 'function' or 'agi'.
name Application or functions name.
module The module the item is in (optional, can be NULL)
Return values:
NULL on error.
Content of the see-also node.

Definition at line 1457 of file xmldoc.c.

References ast_free, ast_str_append(), ast_str_buffer(), ast_str_create(), ast_strdup, ast_strlen_zero(), ast_xml_free_attr(), ast_xml_free_text(), ast_xml_get_attribute(), ast_xml_get_text(), ast_xml_node_get_children(), ast_xml_node_get_name(), ast_xml_node_get_next(), first, and xmldoc_get_node().

Referenced by acf_retrieve_docs(), ast_agi_register(), ast_manager_register2(), and ast_register_application2().

01458 {
01459    struct ast_str *outputstr;
01460    char *output;
01461    struct ast_xml_node *node;
01462    const char *typename;
01463    const char *content;
01464    int first = 1;
01465 
01466    if (ast_strlen_zero(type) || ast_strlen_zero(name)) {
01467       return NULL;
01468    }
01469 
01470    /* get the application/function root node. */
01471    node = xmldoc_get_node(type, name, module, documentation_language);
01472    if (!node || !ast_xml_node_get_children(node)) {
01473       return NULL;
01474    }
01475 
01476    /* Find the <see-also> node. */
01477    for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
01478       if (!strcasecmp(ast_xml_node_get_name(node), "see-also")) {
01479          break;
01480       }
01481    }
01482 
01483    if (!node || !ast_xml_node_get_children(node)) {
01484       /* we couldnt find a <see-also> node. */
01485       return NULL;
01486    }
01487 
01488    /* prepare the output string. */
01489    outputstr = ast_str_create(128);
01490    if (!outputstr) {
01491       return NULL;
01492    }
01493 
01494    /* get into the <see-also> node. */
01495    for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
01496       if (strcasecmp(ast_xml_node_get_name(node), "ref")) {
01497          continue;
01498       }
01499 
01500       /* parse the <ref> node. 'type' attribute is required. */
01501       typename = ast_xml_get_attribute(node, "type");
01502       if (!typename) {
01503          continue;
01504       }
01505       content = ast_xml_get_text(node);
01506       if (!content) {
01507          ast_xml_free_attr(typename);
01508          continue;
01509       }
01510       if (!strcasecmp(typename, "application")) {
01511          ast_str_append(&outputstr, 0, "%s%s()",   (first ? "" : ", "), content);
01512       } else if (!strcasecmp(typename, "function")) {
01513          ast_str_append(&outputstr, 0, "%s%s", (first ? "" : ", "), content);
01514       } else if (!strcasecmp(typename, "astcli")) {
01515          ast_str_append(&outputstr, 0, "%s<astcli>%s</astcli>", (first ? "" : ", "), content);
01516       } else {
01517          ast_str_append(&outputstr, 0, "%s%s", (first ? "" : ", "), content);
01518       }
01519       first = 0;
01520       ast_xml_free_text(content);
01521       ast_xml_free_attr(typename);
01522    }
01523 
01524    output = ast_strdup(ast_str_buffer(outputstr));
01525    ast_free(outputstr);
01526 
01527    return output;
01528 }

char* ast_xmldoc_build_synopsis ( const char *  type,
const char *  name,
const char *  module 
)

Generate synopsis documentation from XML.

Parameters:
type The source of documentation (application, function, etc).
name The name of the application, function, etc.
module The module the item is in (optional, can be NULL)
Return values:
NULL on error.
A malloc'ed string with the synopsis.

Definition at line 1891 of file xmldoc.c.

References xmldoc_build_field().

Referenced by acf_retrieve_docs(), ast_agi_register(), ast_manager_register2(), and ast_register_application2().

01892 {
01893    return xmldoc_build_field(type, name, module, "synopsis", 1);
01894 }

char* ast_xmldoc_build_syntax ( const char *  type,
const char *  name,
const char *  module 
)

Get the syntax for a specified application or function.

Parameters:
type Application, Function or AGI ?
name Name of the application or function.
module The module the item is in (optional, can be NULL)
Return values:
NULL on error.
The generated syntax in a ast_malloc'ed string.

Definition at line 1152 of file xmldoc.c.

References ast_xml_node_get_children(), ast_xml_node_get_name(), ast_xml_node_get_next(), COMMAND_SYNTAX, FUNCTION_SYNTAX, MANAGER_SYNTAX, xmldoc_get_node(), xmldoc_get_syntax_cmd(), xmldoc_get_syntax_fun(), xmldoc_get_syntax_manager(), and xmldoc_get_syntax_type().

Referenced by acf_retrieve_docs(), ast_agi_register(), ast_manager_register2(), and ast_register_application2().

01153 {
01154    struct ast_xml_node *node;
01155    char *syntax = NULL;
01156 
01157    node = xmldoc_get_node(type, name, module, documentation_language);
01158    if (!node) {
01159       return NULL;
01160    }
01161 
01162    for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
01163       if (!strcasecmp(ast_xml_node_get_name(node), "syntax")) {
01164          break;
01165       }
01166    }
01167 
01168    if (node) {
01169       switch (xmldoc_get_syntax_type(type)) {
01170       case FUNCTION_SYNTAX:
01171          syntax = xmldoc_get_syntax_fun(node, name, "parameter", 1, 1);
01172          break;
01173       case COMMAND_SYNTAX:
01174          syntax = xmldoc_get_syntax_cmd(node, name, 1);
01175          break;
01176       case MANAGER_SYNTAX:
01177          syntax = xmldoc_get_syntax_manager(node, name);
01178          break;
01179       default:
01180          syntax = xmldoc_get_syntax_fun(node, name, "parameter", 1, 1);
01181       }
01182    }
01183    return syntax;
01184 }

char* ast_xmldoc_printable ( const char *  bwinput,
int  withcolors 
)

Colorize and put delimiters (instead of tags) to the xmldoc output.

Parameters:
bwinput Not colorized input with tags.
withcolors Result output with colors.
Return values:
NULL on error.
New malloced buffer colorized and with delimiters.

Definition at line 315 of file xmldoc.c.

References ARRAY_LEN, ast_copy_string(), ast_free, ast_opt_light_background, ast_str_append(), ast_str_buffer(), ast_str_create(), ast_term_color_code(), COLOR_CYAN, colorized_tags, len(), term_end(), and xmldoc_string_wrap().

Referenced by handle_cli_agi_show(), handle_show_function(), handle_showmancmd(), print_app_docs(), and write_htmldump().

00316 {
00317    struct ast_str *colorized;
00318    char *wrapped = NULL;
00319    int i, c, len, colorsection;
00320    char *tmp;
00321    size_t bwinputlen;
00322    static const int base_fg = COLOR_CYAN;
00323 
00324    if (!bwinput) {
00325       return NULL;
00326    }
00327 
00328    bwinputlen = strlen(bwinput);
00329 
00330    if (!(colorized = ast_str_create(256))) {
00331       return NULL;
00332    }
00333 
00334    if (withcolors) {
00335       ast_term_color_code(&colorized, base_fg, 0);
00336       if (!colorized) {
00337          return NULL;
00338       }
00339    }
00340 
00341    for (i = 0; i < bwinputlen; i++) {
00342       colorsection = 0;
00343       /* Check if we are at the beginning of a tag to be colorized. */
00344       for (c = 0; c < ARRAY_LEN(colorized_tags); c++) {
00345          if (strncasecmp(bwinput + i, colorized_tags[c].inittag, strlen(colorized_tags[c].inittag))) {
00346             continue;
00347          }
00348 
00349          if (!(tmp = strcasestr(bwinput + i + strlen(colorized_tags[c].inittag), colorized_tags[c].endtag))) {
00350             continue;
00351          }
00352 
00353          len = tmp - (bwinput + i + strlen(colorized_tags[c].inittag));
00354 
00355          /* Setup color */
00356          if (withcolors) {
00357             if (ast_opt_light_background) {
00358                /* Turn off *bright* colors */
00359                ast_term_color_code(&colorized, colorized_tags[c].colorfg & 0x7f, 0);
00360             } else {
00361                /* Turn on *bright* colors */
00362                ast_term_color_code(&colorized, colorized_tags[c].colorfg | 0x80, 0);
00363             }
00364             if (!colorized) {
00365                return NULL;
00366             }
00367          }
00368 
00369          /* copy initial string replace */
00370          ast_str_append(&colorized, 0, "%s", colorized_tags[c].init);
00371          if (!colorized) {
00372             return NULL;
00373          }
00374          {
00375             char buf[len + 1];
00376             ast_copy_string(buf, bwinput + i + strlen(colorized_tags[c].inittag), sizeof(buf));
00377             ast_str_append(&colorized, 0, "%s", buf);
00378          }
00379          if (!colorized) {
00380             return NULL;
00381          }
00382 
00383          /* copy the ending string replace */
00384          ast_str_append(&colorized, 0, "%s", colorized_tags[c].end);
00385          if (!colorized) {
00386             return NULL;
00387          }
00388 
00389          /* Continue with the last color. */
00390          if (withcolors) {
00391             ast_term_color_code(&colorized, base_fg, 0);
00392             if (!colorized) {
00393                return NULL;
00394             }
00395          }
00396 
00397          i += len + strlen(colorized_tags[c].endtag) + strlen(colorized_tags[c].inittag) - 1;
00398          colorsection = 1;
00399          break;
00400       }
00401 
00402       if (!colorsection) {
00403          ast_str_append(&colorized, 0, "%c", bwinput[i]);
00404          if (!colorized) {
00405             return NULL;
00406          }
00407       }
00408    }
00409 
00410    if (withcolors) {
00411       ast_str_append(&colorized, 0, "%s", term_end());
00412       if (!colorized) {
00413          return NULL;
00414       }
00415    }
00416 
00417    /* Wrap the text, notice that string wrap will avoid cutting an ESC sequence. */
00418    wrapped = xmldoc_string_wrap(ast_str_buffer(colorized), xmldoc_text_columns, xmldoc_max_diff);
00419 
00420    ast_free(colorized);
00421 
00422    return wrapped;
00423 }

static int xmldoc_attribute_match ( struct ast_xml_node *  node,
const char *  attr,
const char *  value 
) [static]

Definition at line 476 of file xmldoc.c.

References ast_xml_free_attr(), ast_xml_get_attribute(), and match().

Referenced by xmldoc_get_node().

00477 {
00478    const char *attr_value = ast_xml_get_attribute(node, attr);
00479    int match = attr_value && !strcmp(attr_value, value);
00480    ast_xml_free_attr(attr_value);
00481    return match;
00482 }

static char* xmldoc_build_field ( const char *  type,
const char *  name,
const char *  module,
const char *  var,
int  raw 
) [static]

Get the content of a field (synopsis, description, etc) from an asterisk document tree.

Parameters:
type Type of element (application, function, ...).
name Name of element (Dial, Echo, Playback, ...).
var Name of field to return (synopsis, description, etc).
raw Field only contains text, no other elements inside it.
Return values:
NULL On error.
Field text content on success.

Definition at line 1857 of file xmldoc.c.

References ast_free, ast_log(), ast_str_buffer(), ast_str_strlen(), ast_strdup, ast_strlen_zero(), ast_xml_find_element(), ast_xml_node_get_children(), LOG_DEBUG, LOG_ERROR, LOG_WARNING, xmldoc_get_formatted(), and xmldoc_get_node().

Referenced by ast_xmldoc_build_description(), and ast_xmldoc_build_synopsis().

01858 {
01859    struct ast_xml_node *node;
01860    char *ret = NULL;
01861    struct ast_str *formatted;
01862 
01863    if (ast_strlen_zero(type) || ast_strlen_zero(name)) {
01864       ast_log(LOG_ERROR, "Tried to look in XML tree with faulty values.\n");
01865       return ret;
01866    }
01867 
01868    node = xmldoc_get_node(type, name, module, documentation_language);
01869 
01870    if (!node) {
01871       ast_log(LOG_WARNING, "Couldn't find %s %s in XML documentation\n", type, name);
01872       return ret;
01873    }
01874 
01875    node = ast_xml_find_element(ast_xml_node_get_children(node), var, NULL, NULL);
01876 
01877    if (!node || !ast_xml_node_get_children(node)) {
01878       ast_log(LOG_DEBUG, "Cannot find variable '%s' in tree '%s'\n", var, name);
01879       return ret;
01880    }
01881 
01882    formatted = xmldoc_get_formatted(node, raw, raw);
01883    if (ast_str_strlen(formatted) > 0) {
01884       ret = ast_strdup(ast_str_buffer(formatted));
01885    }
01886    ast_free(formatted);
01887 
01888    return ret;
01889 }

static int xmldoc_foundspace_backward ( const char *  text,
int  currentpos,
int  maxdiff 
) [static]

Definition at line 209 of file xmldoc.c.

Referenced by xmldoc_string_wrap().

00210 {
00211    int i;
00212 
00213    for (i = currentpos; i > 0; i--) {
00214       if (text[i] == ' ' || text[i] == '\n') {
00215          return (currentpos - i);
00216       } else if (text[i] == 'm' && (text[i - 1] >= '0' || text[i - 1] <= '9')) {
00217          /* give up, we found the end of a possible ESC sequence. */
00218          return 0;
00219       } else if (currentpos - i > maxdiff) {
00220          /* give up, we can't move anymore. */
00221          return 0;
00222       }
00223    }
00224 
00225    /* we found the beginning of the text */
00226 
00227    return 0;
00228 }

static struct ast_str* xmldoc_get_formatted ( struct ast_xml_node *  node,
int  raw_output,
int  raw_wrap 
) [static, read]

Definition at line 1813 of file xmldoc.c.

References ast_skip_blanks(), ast_str_buffer(), ast_str_create(), ast_str_strlen(), ast_str_truncate(), ast_xml_free_text(), ast_xml_get_text(), ast_xml_node_get_children(), ast_xml_node_get_next(), xmldoc_parse_enumlist(), xmldoc_parse_para(), xmldoc_parse_specialtags(), xmldoc_parse_variablelist(), and xmldoc_string_cleanup().

Referenced by xmldoc_build_field().

01814 {
01815    struct ast_xml_node *tmp;
01816    const char *notcleanret, *tmpstr;
01817    struct ast_str *ret;
01818 
01819    if (raw_output) {
01820       /* xmldoc_string_cleanup will allocate the ret object */
01821       notcleanret = ast_xml_get_text(node);
01822       tmpstr = notcleanret;
01823       xmldoc_string_cleanup(ast_skip_blanks(notcleanret), &ret, 0);
01824       ast_xml_free_text(tmpstr);
01825    } else {
01826       ret = ast_str_create(128);
01827       for (tmp = ast_xml_node_get_children(node); tmp; tmp = ast_xml_node_get_next(tmp)) {
01828          /* if found, parse a <para> element. */
01829          if (xmldoc_parse_para(tmp, "", "\n", &ret)) {
01830             continue;
01831          } else if (xmldoc_parse_specialtags(tmp, "", "\n", &ret)) {
01832             continue;
01833          }
01834          /* if found, parse a <variablelist> element. */
01835          xmldoc_parse_variablelist(tmp, "", &ret);
01836          xmldoc_parse_enumlist(tmp, "    ", &ret);
01837       }
01838       /* remove last '\n' */
01839       /* XXX Don't modify ast_str internals manually */
01840       tmpstr = ast_str_buffer(ret);
01841       if (tmpstr[ast_str_strlen(ret) - 1] == '\n') {
01842          ast_str_truncate(ret, -1);
01843       }
01844    }
01845    return ret;
01846 }

static struct ast_xml_node* xmldoc_get_node ( const char *  type,
const char *  name,
const char *  module,
const char *  language 
) [static, read]

Definition at line 495 of file xmldoc.c.

References AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_strlen_zero(), ast_xml_find_element(), ast_xml_get_root(), ast_xml_node_get_children(), ast_xml_node_get_next(), documentation_tree::doc, documentation_tree::entry, and xmldoc_attribute_match().

Referenced by ast_xmldoc_build_arguments(), ast_xmldoc_build_seealso(), ast_xmldoc_build_syntax(), and xmldoc_build_field().

00496 {
00497    struct ast_xml_node *node = NULL;
00498    struct ast_xml_node *first_match = NULL;
00499    struct ast_xml_node *lang_match = NULL;
00500    struct documentation_tree *doctree;
00501 
00502    AST_RWLIST_RDLOCK(&xmldoc_tree);
00503    AST_LIST_TRAVERSE(&xmldoc_tree, doctree, entry) {
00504       /* the core xml documents have priority over thirdparty document. */
00505       node = ast_xml_get_root(doctree->doc);
00506       if (!node) {
00507          break;
00508       }
00509 
00510       node = ast_xml_node_get_children(node);
00511       while ((node = ast_xml_find_element(node, type, "name", name))) {
00512          if (!ast_xml_node_get_children(node)) {
00513             /* ignore empty nodes */
00514             node = ast_xml_node_get_next(node);
00515             continue;
00516          }
00517 
00518          if (!first_match) {
00519             first_match = node;
00520          }
00521 
00522          /* Check language */
00523          if (xmldoc_attribute_match(node, "language", language)) {
00524             if (!lang_match) {
00525                lang_match = node;
00526             }
00527 
00528             /* if module is empty we have a match */
00529             if (ast_strlen_zero(module)) {
00530                break;
00531             }
00532 
00533             /* Check module */
00534             if (xmldoc_attribute_match(node, "module", module)) {
00535                break;
00536             }
00537          }
00538 
00539          node = ast_xml_node_get_next(node);
00540       }
00541 
00542       /* if we matched lang and module return this match */
00543       if (node) {
00544          break;
00545       }
00546 
00547       /* we didn't match lang and module, just return the first
00548        * result with a matching language if we have one */
00549       if (lang_match) {
00550          node = lang_match;
00551          break;
00552       }
00553 
00554       /* we didn't match with only the language, just return the
00555        * first match */
00556       if (first_match) {
00557          node = first_match;
00558          break;
00559       }
00560    }
00561    AST_RWLIST_UNLOCK(&xmldoc_tree);
00562 
00563    return node;
00564 }

static char * xmldoc_get_syntax_cmd ( struct ast_xml_node *  fixnode,
const char *  name,
int  printname 
) [static]

Definition at line 970 of file xmldoc.c.

References ast_free, ast_str_append(), ast_str_buffer(), ast_str_create(), ast_strdup, ast_true(), ast_xml_free_attr(), ast_xml_get_attribute(), ast_xml_node_get_children(), ast_xml_node_get_name(), ast_xml_node_get_next(), first, xmldoc_has_inside(), and xmldoc_parse_cmd_enumlist().

Referenced by ast_xmldoc_build_syntax(), and xmldoc_parse_cmd_enumlist().

00971 {
00972    struct ast_str *syntax;
00973    struct ast_xml_node *tmpnode, *node = fixnode;
00974    char *ret, *paramname;
00975    const char *paramtype, *attrname, *literal;
00976    int required, isenum, first = 1, isliteral;
00977 
00978    syntax = ast_str_create(128);
00979    if (!syntax) {
00980       /* at least try to return something... */
00981       return ast_strdup(name);
00982    }
00983 
00984    /* append name to output string. */
00985    if (printname) {
00986       ast_str_append(&syntax, 0, "%s", name);
00987       first = 0;
00988    }
00989 
00990    for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
00991       if (strcasecmp(ast_xml_node_get_name(node), "parameter")) {
00992          continue;
00993       }
00994 
00995       if (xmldoc_has_inside(node, "parameter")) {
00996          /* is this a recursive parameter. */
00997          paramname = xmldoc_get_syntax_cmd(node, "", 0);
00998          isenum = 1;
00999       } else {
01000          for (tmpnode = ast_xml_node_get_children(node); tmpnode; tmpnode = ast_xml_node_get_next(tmpnode)) {
01001             if (!strcasecmp(ast_xml_node_get_name(tmpnode), "enumlist")) {
01002                break;
01003             }
01004          }
01005          if (tmpnode) {
01006             /* parse enumlist (note that this is a special enumlist
01007             that is used to describe a syntax like {<param1>|<param2>|...} */
01008             paramname = xmldoc_parse_cmd_enumlist(tmpnode);
01009             isenum = 1;
01010          } else {
01011             /* this is a simple parameter. */
01012             attrname = ast_xml_get_attribute(node, "name");
01013             if (!attrname) {
01014                /* ignore this bogus parameter and continue. */
01015                continue;
01016             }
01017             paramname = ast_strdup(attrname);
01018             ast_xml_free_attr(attrname);
01019             isenum = 0;
01020          }
01021       }
01022 
01023       /* Is this parameter required? */
01024       required = 0;
01025       paramtype = ast_xml_get_attribute(node, "required");
01026       if (paramtype) {
01027          required = ast_true(paramtype);
01028          ast_xml_free_attr(paramtype);
01029       }
01030 
01031       /* Is this a replaceable value or a fixed parameter value? */
01032       isliteral = 0;
01033       literal = ast_xml_get_attribute(node, "literal");
01034       if (literal) {
01035          isliteral = ast_true(literal);
01036          ast_xml_free_attr(literal);
01037       }
01038 
01039       /* if required="false" print with [...].
01040        * if literal="true" or is enum print without <..>.
01041        * if not first print a space at the beginning.
01042        */
01043       ast_str_append(&syntax, 0, "%s%s%s%s%s%s",
01044             (first ? "" : " "),
01045             (required ? "" : "["),
01046             (isenum || isliteral ? "" : "<"),
01047             paramname,
01048             (isenum || isliteral ? "" : ">"),
01049             (required ? "" : "]"));
01050       first = 0;
01051       ast_free(paramname);
01052    }
01053 
01054    /* return a common string. */
01055    ret = ast_strdup(ast_str_buffer(syntax));
01056    ast_free(syntax);
01057 
01058    return ret;
01059 }

static char* xmldoc_get_syntax_fun ( struct ast_xml_node *  rootnode,
const char *  rootname,
const char *  childname,
int  printparenthesis,
int  printrootname 
) [static]

Definition at line 682 of file xmldoc.c.

References ast_asprintf, ast_free, ast_log(), ast_strdup, ast_strdupa, ast_strlen_zero(), ast_true(), ast_xml_free_attr(), ast_xml_get_attribute(), ast_xml_node_get_children(), ast_xml_node_get_name(), ast_xml_node_get_next(), GOTONEXT, ISLAST, len(), LOG_WARNING, MP, xmldoc_has_inside(), and xmldoc_reverse_helper().

Referenced by ast_xmldoc_build_syntax(), and xmldoc_parse_optionlist().

00683 {
00684 #define GOTONEXT(__rev, __a) (__rev ? ast_xml_node_get_prev(__a) : ast_xml_node_get_next(__a))
00685 #define ISLAST(__rev, __a)  (__rev == 1 ? (ast_xml_node_get_prev(__a) ? 0 : 1) : (ast_xml_node_get_next(__a) ? 0 : 1))
00686 #define MP(__a) ((multiple ? __a : ""))
00687    struct ast_xml_node *node = NULL, *firstparam = NULL, *lastparam = NULL;
00688    const char *paramtype, *multipletype, *paramnameattr, *attrargsep, *parenthesis, *argname;
00689    int reverse, required, paramcount = 0, openbrackets = 0, len = 0, hasparams=0;
00690    int reqfinode = 0, reqlanode = 0, optmidnode = 0, prnparenthesis, multiple;
00691    char *syntax = NULL, *argsep, *paramname;
00692 
00693    if (ast_strlen_zero(rootname) || ast_strlen_zero(childname)) {
00694       ast_log(LOG_WARNING, "Tried to look in XML tree with faulty rootname or childname while creating a syntax.\n");
00695       return NULL;
00696    }
00697 
00698    if (!rootnode || !ast_xml_node_get_children(rootnode)) {
00699       /* If the rootnode field is not found, at least print name. */
00700       if (ast_asprintf(&syntax, "%s%s", (printrootname ? rootname : ""), (printparenthesis ? "()" : "")) < 0) {
00701          syntax = NULL;
00702       }
00703       return syntax;
00704    }
00705 
00706    /* Get the argument separator from the root node attribute name 'argsep', if not found
00707    defaults to ','. */
00708    attrargsep = ast_xml_get_attribute(rootnode, "argsep");
00709    if (attrargsep) {
00710       argsep = ast_strdupa(attrargsep);
00711       ast_xml_free_attr(attrargsep);
00712    } else {
00713       argsep = ast_strdupa(",");
00714    }
00715 
00716    /* Get order of evaluation. */
00717    for (node = ast_xml_node_get_children(rootnode); node; node = ast_xml_node_get_next(node)) {
00718       if (strcasecmp(ast_xml_node_get_name(node), childname)) {
00719          continue;
00720       }
00721       required = 0;
00722       hasparams = 1;
00723       if ((paramtype = ast_xml_get_attribute(node, "required"))) {
00724          if (ast_true(paramtype)) {
00725             required = 1;
00726          }
00727          ast_xml_free_attr(paramtype);
00728       }
00729 
00730       lastparam = node;
00731       reqlanode = required;
00732 
00733       if (!firstparam) {
00734          /* first parameter node */
00735          firstparam = node;
00736          reqfinode = required;
00737       }
00738    }
00739 
00740    if (!hasparams) {
00741       /* This application, function, option, etc, doesn't have any params. */
00742       if (ast_asprintf(&syntax, "%s%s", (printrootname ? rootname : ""), (printparenthesis ? "()" : "")) < 0) {
00743          syntax = NULL;
00744       }
00745       return syntax;
00746    }
00747 
00748    if (reqfinode && reqlanode) {
00749       /* check midnode */
00750       for (node = ast_xml_node_get_children(rootnode); node; node = ast_xml_node_get_next(node)) {
00751          if (strcasecmp(ast_xml_node_get_name(node), childname)) {
00752             continue;
00753          }
00754          if (node != firstparam && node != lastparam) {
00755             if ((paramtype = ast_xml_get_attribute(node, "required"))) {
00756                if (!ast_true(paramtype)) {
00757                   optmidnode = 1;
00758                   break;
00759                }
00760                ast_xml_free_attr(paramtype);
00761             }
00762          }
00763       }
00764    }
00765 
00766    if ((!reqfinode && reqlanode) || (reqfinode && reqlanode && optmidnode)) {
00767       reverse = 1;
00768       node = lastparam;
00769    } else {
00770       reverse = 0;
00771       node = firstparam;
00772    }
00773 
00774    /* init syntax string. */
00775    if (reverse) {
00776       xmldoc_reverse_helper(reverse, &len, &syntax,
00777          (printrootname ? (printrootname == 2 ? ")]" : ")"): ""));
00778    } else {
00779       xmldoc_reverse_helper(reverse, &len, &syntax, "%s%s", (printrootname ? rootname : ""),
00780          (printrootname ? (printrootname == 2 ? "[(" : "(") : ""));
00781    }
00782 
00783    for (; node; node = GOTONEXT(reverse, node)) {
00784       if (strcasecmp(ast_xml_node_get_name(node), childname)) {
00785          continue;
00786       }
00787 
00788       /* Get the argument name, if it is not the leaf, go inside that parameter. */
00789       if (xmldoc_has_inside(node, "argument")) {
00790          parenthesis = ast_xml_get_attribute(node, "hasparams");
00791          prnparenthesis = 0;
00792          if (parenthesis) {
00793             prnparenthesis = ast_true(parenthesis);
00794             if (!strcasecmp(parenthesis, "optional")) {
00795                prnparenthesis = 2;
00796             }
00797             ast_xml_free_attr(parenthesis);
00798          }
00799          argname = ast_xml_get_attribute(node, "name");
00800          if (argname) {
00801             paramname = xmldoc_get_syntax_fun(node, argname, "argument", prnparenthesis, prnparenthesis);
00802             ast_xml_free_attr(argname);
00803          } else {
00804             /* Malformed XML, print **UNKOWN** */
00805             paramname = ast_strdup("**unknown**");
00806          }
00807       } else {
00808          paramnameattr = ast_xml_get_attribute(node, "name");
00809          if (!paramnameattr) {
00810             ast_log(LOG_WARNING, "Malformed XML %s: no %s name\n", rootname, childname);
00811             if (syntax) {
00812                /* Free already allocated syntax */
00813                ast_free(syntax);
00814             }
00815             /* to give up is ok? */
00816             if (ast_asprintf(&syntax, "%s%s", (printrootname ? rootname : ""), (printparenthesis ? "()" : "")) < 0) {
00817                syntax = NULL;
00818             }
00819             return syntax;
00820          }
00821          paramname = ast_strdup(paramnameattr);
00822          ast_xml_free_attr(paramnameattr);
00823       }
00824 
00825       if (!paramname) {
00826          return NULL;
00827       }
00828 
00829       /* Defaults to 'false'. */
00830       multiple = 0;
00831       if ((multipletype = ast_xml_get_attribute(node, "multiple"))) {
00832          if (ast_true(multipletype)) {
00833             multiple = 1;
00834          }
00835          ast_xml_free_attr(multipletype);
00836       }
00837 
00838       required = 0;  /* Defaults to 'false'. */
00839       if ((paramtype = ast_xml_get_attribute(node, "required"))) {
00840          if (ast_true(paramtype)) {
00841             required = 1;
00842          }
00843          ast_xml_free_attr(paramtype);
00844       }
00845 
00846       /* build syntax core. */
00847 
00848       if (required) {
00849          /* First parameter */
00850          if (!paramcount) {
00851             xmldoc_reverse_helper(reverse, &len, &syntax, "%s%s%s%s", paramname, MP("["), MP(argsep), MP("...]"));
00852          } else {
00853             /* Time to close open brackets. */
00854             while (openbrackets > 0) {
00855                xmldoc_reverse_helper(reverse, &len, &syntax, (reverse ? "[" : "]"));
00856                openbrackets--;
00857             }
00858             if (reverse) {
00859                xmldoc_reverse_helper(reverse, &len, &syntax, "%s%s", paramname, argsep);
00860             } else {
00861                xmldoc_reverse_helper(reverse, &len, &syntax, "%s%s", argsep, paramname);
00862             }
00863             xmldoc_reverse_helper(reverse, &len, &syntax, "%s%s%s", MP("["), MP(argsep), MP("...]"));
00864          }
00865       } else {
00866          /* First parameter */
00867          if (!paramcount) {
00868             xmldoc_reverse_helper(reverse, &len, &syntax, "[%s%s%s%s]", paramname, MP("["), MP(argsep), MP("...]"));
00869          } else {
00870             if (ISLAST(reverse, node)) {
00871                /* This is the last parameter. */
00872                if (reverse) {
00873                   xmldoc_reverse_helper(reverse, &len, &syntax, "[%s%s%s%s]%s", paramname,
00874                            MP("["), MP(argsep), MP("...]"), argsep);
00875                } else {
00876                   xmldoc_reverse_helper(reverse, &len, &syntax, "%s[%s%s%s%s]", argsep, paramname,
00877                            MP("["), MP(argsep), MP("...]"));
00878                }
00879             } else {
00880                if (reverse) {
00881                   xmldoc_reverse_helper(reverse, &len, &syntax, "%s%s%s%s%s]", paramname, argsep,
00882                            MP("["), MP(argsep), MP("...]"));
00883                } else {
00884                   xmldoc_reverse_helper(reverse, &len, &syntax, "[%s%s%s%s%s", argsep, paramname,
00885                            MP("["), MP(argsep), MP("...]"));
00886                }
00887                openbrackets++;
00888             }
00889          }
00890       }
00891       ast_free(paramname);
00892 
00893       paramcount++;
00894    }
00895 
00896    /* Time to close open brackets. */
00897    while (openbrackets > 0) {
00898       xmldoc_reverse_helper(reverse, &len, &syntax, (reverse ? "[" : "]"));
00899       openbrackets--;
00900    }
00901 
00902    /* close syntax string. */
00903    if (reverse) {
00904       xmldoc_reverse_helper(reverse, &len, &syntax, "%s%s", (printrootname ? rootname : ""),
00905          (printrootname ? (printrootname == 2 ? "[(" : "(") : ""));
00906    } else {
00907       xmldoc_reverse_helper(reverse, &len, &syntax, (printrootname ? (printrootname == 2 ? ")]" : ")") : ""));
00908    }
00909 
00910    return syntax;
00911 #undef ISLAST
00912 #undef GOTONEXT
00913 #undef MP
00914 }

static char* xmldoc_get_syntax_manager ( struct ast_xml_node *  fixnode,
const char *  name 
) [static]

Definition at line 1068 of file xmldoc.c.

References ast_free, ast_str_append(), ast_str_buffer(), ast_str_create(), ast_strdup, ast_true(), ast_xml_free_attr(), ast_xml_get_attribute(), ast_xml_node_get_children(), ast_xml_node_get_name(), and ast_xml_node_get_next().

Referenced by ast_xmldoc_build_syntax().

01069 {
01070    struct ast_str *syntax;
01071    struct ast_xml_node *node = fixnode;
01072    const char *paramtype, *attrname;
01073    int required;
01074    char *ret;
01075 
01076    syntax = ast_str_create(128);
01077    if (!syntax) {
01078       return ast_strdup(name);
01079    }
01080 
01081    ast_str_append(&syntax, 0, "Action: %s", name);
01082 
01083    for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
01084       if (strcasecmp(ast_xml_node_get_name(node), "parameter")) {
01085          continue;
01086       }
01087 
01088       /* Is this parameter required? */
01089       required = 0;
01090       paramtype = ast_xml_get_attribute(node, "required");
01091       if (paramtype) {
01092          required = ast_true(paramtype);
01093          ast_xml_free_attr(paramtype);
01094       }
01095 
01096       attrname = ast_xml_get_attribute(node, "name");
01097       if (!attrname) {
01098          /* ignore this bogus parameter and continue. */
01099          continue;
01100       }
01101 
01102       ast_str_append(&syntax, 0, "\n%s%s:%s <value>",
01103          (required ? "" : "["),
01104          attrname,
01105          (required ? "" : "]"));
01106 
01107       ast_xml_free_attr(attrname);
01108    }
01109 
01110    /* return a common string. */
01111    ret = ast_strdup(ast_str_buffer(syntax));
01112    ast_free(syntax);
01113 
01114    return ret;
01115 }

static enum syntaxtype xmldoc_get_syntax_type ( const char *  type  )  [static]

Definition at line 1140 of file xmldoc.c.

References ARRAY_LEN, FUNCTION_SYNTAX, strsyntaxtype::stxtype, and stxtype.

Referenced by ast_xmldoc_build_syntax().

01141 {
01142    int i;
01143    for (i=0; i < ARRAY_LEN(stxtype); i++) {
01144       if (!strcasecmp(stxtype[i].type, type)) {
01145          return stxtype[i].stxtype;
01146       }
01147    }
01148 
01149    return FUNCTION_SYNTAX;
01150 }

static int xmldoc_has_inside ( struct ast_xml_node *  fixnode,
const char *  what 
) [static]

Definition at line 621 of file xmldoc.c.

References ast_xml_node_get_children(), ast_xml_node_get_name(), and ast_xml_node_get_next().

Referenced by xmldoc_get_syntax_cmd(), xmldoc_get_syntax_fun(), xmldoc_parse_argument(), and xmldoc_parse_parameter().

00622 {
00623    struct ast_xml_node *node = fixnode;
00624 
00625    for (node = ast_xml_node_get_children(fixnode); node; node = ast_xml_node_get_next(node)) {
00626       if (!strcasecmp(ast_xml_node_get_name(node), what)) {
00627          return 1;
00628       }
00629    }
00630    return 0;
00631 }

static int xmldoc_has_nodes ( struct ast_xml_node *  fixnode  )  [static]

Definition at line 639 of file xmldoc.c.

References ast_xml_node_get_children(), ast_xml_node_get_name(), and ast_xml_node_get_next().

Referenced by xmldoc_parse_parameter().

00640 {
00641    struct ast_xml_node *node = fixnode;
00642 
00643    for (node = ast_xml_node_get_children(fixnode); node; node = ast_xml_node_get_next(node)) {
00644       if (strcasecmp(ast_xml_node_get_name(node), "text")) {
00645          return 1;
00646       }
00647    }
00648    return 0;
00649 }

static int xmldoc_has_specialtags ( struct ast_xml_node *  fixnode  )  [static]

Definition at line 657 of file xmldoc.c.

References ARRAY_LEN, ast_xml_node_get_children(), ast_xml_node_get_name(), ast_xml_node_get_next(), and special_tags.

Referenced by xmldoc_parse_argument().

00658 {
00659    struct ast_xml_node *node = fixnode;
00660    int i;
00661 
00662    for (node = ast_xml_node_get_children(fixnode); node; node = ast_xml_node_get_next(node)) {
00663       for (i = 0; i < ARRAY_LEN(special_tags); i++) {
00664          if (!strcasecmp(ast_xml_node_get_name(node), special_tags[i].tagname)) {
00665             return 1;
00666          }
00667       }
00668    }
00669    return 0;
00670 }

static int xmldoc_parse_argument ( struct ast_xml_node *  fixnode,
int  insideparameter,
const char *  paramtabs,
const char *  tabs,
struct ast_str **  buffer 
) [static]

Definition at line 1302 of file xmldoc.c.

References ast_str_append(), ast_xml_free_attr(), ast_xml_get_attribute(), ast_xml_node_get_children(), ast_xml_node_get_next(), xmldoc_has_inside(), xmldoc_has_specialtags(), xmldoc_parse_para(), and xmldoc_parse_specialtags().

Referenced by xmldoc_parse_option(), and xmldoc_parse_parameter().

01303 {
01304    struct ast_xml_node *node = fixnode;
01305    const char *argname;
01306    int count = 0, ret = 0;
01307 
01308    if (!node || !ast_xml_node_get_children(node)) {
01309       return ret;
01310    }
01311 
01312    /* Print the argument names */
01313    argname = ast_xml_get_attribute(node, "name");
01314    if (!argname) {
01315       return 0;
01316    }
01317    if (xmldoc_has_inside(node, "para") || xmldoc_has_specialtags(node)) {
01318       ast_str_append(buffer, 0, "%s%s%s", tabs, argname, (insideparameter ? "\n" : ""));
01319       ast_xml_free_attr(argname);
01320    } else {
01321       ast_xml_free_attr(argname);
01322       return 0;
01323    }
01324 
01325    for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
01326       if (xmldoc_parse_para(node, (insideparameter ? paramtabs : (!count ? " - " : tabs)), "\n", buffer) == 2) {
01327          count++;
01328          ret = 1;
01329       } else if (xmldoc_parse_specialtags(node, (insideparameter ? paramtabs : (!count ? " - " : tabs)), "\n", buffer) == 2) {
01330          count++;
01331          ret = 1;
01332       }
01333    }
01334 
01335    return ret;
01336 }

static char* xmldoc_parse_cmd_enumlist ( struct ast_xml_node *  fixnode  )  [static]

Definition at line 923 of file xmldoc.c.

References ast_free, ast_str_append(), ast_str_buffer(), ast_str_create(), ast_strdup, ast_xml_node_get_children(), ast_xml_node_get_name(), ast_xml_node_get_next(), first, and xmldoc_get_syntax_cmd().

Referenced by xmldoc_get_syntax_cmd().

00924 {
00925    struct ast_xml_node *node = fixnode;
00926    struct ast_str *paramname;
00927    char *enumname, *ret;
00928    int first = 1;
00929 
00930    paramname = ast_str_create(128);
00931    if (!paramname) {
00932       return ast_strdup("{<unkown>}");
00933    }
00934 
00935    ast_str_append(&paramname, 0, "{");
00936 
00937    for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
00938       if (strcasecmp(ast_xml_node_get_name(node), "enum")) {
00939          continue;
00940       }
00941 
00942       enumname = xmldoc_get_syntax_cmd(node, "", 0);
00943       if (!enumname) {
00944          continue;
00945       }
00946       if (!first) {
00947          ast_str_append(&paramname, 0, "|");
00948       }
00949       ast_str_append(&paramname, 0, "%s", enumname);
00950       first = 0;
00951       ast_free(enumname);
00952    }
00953 
00954    ast_str_append(&paramname, 0, "}");
00955 
00956    ret = ast_strdup(ast_str_buffer(paramname));
00957    ast_free(paramname);
00958 
00959    return ret;
00960 }

static int xmldoc_parse_enum ( struct ast_xml_node *  fixnode,
const char *  tabs,
struct ast_str **  buffer 
) [static]

Definition at line 1537 of file xmldoc.c.

References ast_asprintf, ast_free, ast_xml_node_get_children(), ast_xml_node_get_next(), xmldoc_parse_enumlist(), xmldoc_parse_para(), and xmldoc_parse_specialtags().

Referenced by xmldoc_parse_enumlist().

01538 {
01539    struct ast_xml_node *node = fixnode;
01540    int ret = 0;
01541    char *optiontabs;
01542 
01543    if (ast_asprintf(&optiontabs, "%s    ", tabs) < 0) {
01544       return ret;
01545    }
01546 
01547    for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
01548       if ((xmldoc_parse_para(node, (ret ? tabs : " - "), "\n", buffer))) {
01549          ret = 1;
01550       } else if ((xmldoc_parse_specialtags(node, (ret ? tabs : " - "), "\n", buffer))) {
01551          ret = 1;
01552       }
01553 
01554       xmldoc_parse_enumlist(node, optiontabs, buffer);
01555    }
01556 
01557    ast_free(optiontabs);
01558 
01559    return ret;
01560 }

static int xmldoc_parse_enumlist ( struct ast_xml_node *  fixnode,
const char *  tabs,
struct ast_str **  buffer 
) [static]

Definition at line 1569 of file xmldoc.c.

References ast_str_append(), ast_xml_free_attr(), ast_xml_get_attribute(), ast_xml_node_get_children(), ast_xml_node_get_name(), ast_xml_node_get_next(), and xmldoc_parse_enum().

Referenced by xmldoc_get_formatted(), xmldoc_parse_enum(), xmldoc_parse_option(), and xmldoc_parse_parameter().

01570 {
01571    struct ast_xml_node *node = fixnode;
01572    const char *enumname;
01573    int ret = 0;
01574 
01575    for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
01576       if (strcasecmp(ast_xml_node_get_name(node), "enum")) {
01577          continue;
01578       }
01579 
01580       enumname = ast_xml_get_attribute(node, "name");
01581       if (enumname) {
01582          ast_str_append(buffer, 0, "%s<enum>%s</enum>", tabs, enumname);
01583          ast_xml_free_attr(enumname);
01584 
01585          /* parse only enum elements inside a enumlist node. */
01586          if ((xmldoc_parse_enum(node, tabs, buffer))) {
01587             ret = 1;
01588          } else {
01589             ast_str_append(buffer, 0, "\n");
01590          }
01591       }
01592    }
01593    return ret;
01594 }

static int xmldoc_parse_option ( struct ast_xml_node *  fixnode,
const char *  tabs,
struct ast_str **  buffer 
) [static]

Definition at line 1605 of file xmldoc.c.

References ast_asprintf, ast_free, ast_str_append(), ast_xml_node_get_children(), ast_xml_node_get_name(), ast_xml_node_get_next(), xmldoc_parse_argument(), xmldoc_parse_enumlist(), xmldoc_parse_para(), xmldoc_parse_specialtags(), and xmldoc_parse_variablelist().

Referenced by xmldoc_parse_optionlist().

01606 {
01607    struct ast_xml_node *node;
01608    int ret = 0;
01609    char *optiontabs;
01610 
01611    if (ast_asprintf(&optiontabs, "%s    ", tabs) < 0) {
01612       return ret;
01613    }
01614    for (node = ast_xml_node_get_children(fixnode); node; node = ast_xml_node_get_next(node)) {
01615       if (!strcasecmp(ast_xml_node_get_name(node), "argument")) {
01616          /* if this is the first data appended to buffer, print a \n*/
01617          if (!ret && ast_xml_node_get_children(node)) {
01618             /* print \n */
01619             ast_str_append(buffer, 0, "\n");
01620          }
01621          if (xmldoc_parse_argument(node, 0, NULL, optiontabs, buffer)) {
01622             ret = 1;
01623          }
01624          continue;
01625       }
01626 
01627       if (xmldoc_parse_para(node, (ret ? tabs :  ""), "\n", buffer)) {
01628          ret = 1;
01629       } else if (xmldoc_parse_specialtags(node, (ret ? tabs :  ""), "\n", buffer)) {
01630          ret = 1;
01631       }
01632 
01633       xmldoc_parse_variablelist(node, optiontabs, buffer);
01634 
01635       xmldoc_parse_enumlist(node, optiontabs, buffer);
01636    }
01637    ast_free(optiontabs);
01638 
01639    return ret;
01640 }

static void xmldoc_parse_optionlist ( struct ast_xml_node *  fixnode,
const char *  tabs,
struct ast_str **  buffer 
) [static]

Definition at line 1649 of file xmldoc.c.

References ast_free, ast_str_append(), ast_xml_free_attr(), ast_xml_get_attribute(), ast_xml_node_get_children(), ast_xml_node_get_name(), ast_xml_node_get_next(), xmldoc_get_syntax_fun(), and xmldoc_parse_option().

Referenced by xmldoc_parse_parameter().

01650 {
01651    struct ast_xml_node *node;
01652    const char *optname, *hasparams;
01653    char *optionsyntax;
01654    int optparams;
01655 
01656    for (node = ast_xml_node_get_children(fixnode); node; node = ast_xml_node_get_next(node)) {
01657       /* Start appending every option tag. */
01658       if (strcasecmp(ast_xml_node_get_name(node), "option")) {
01659          continue;
01660       }
01661 
01662       /* Get the option name. */
01663       optname = ast_xml_get_attribute(node, "name");
01664       if (!optname) {
01665          continue;
01666       }
01667 
01668       optparams = 1;
01669       hasparams = ast_xml_get_attribute(node, "hasparams");
01670       if (hasparams && !strcasecmp(hasparams, "optional")) {
01671          optparams = 2;
01672       }
01673 
01674       optionsyntax = xmldoc_get_syntax_fun(node, optname, "argument", 0, optparams);
01675       if (!optionsyntax) {
01676          ast_xml_free_attr(optname);
01677          ast_xml_free_attr(hasparams);
01678          continue;
01679       }
01680 
01681       ast_str_append(buffer, 0, "%s%s: ", tabs, optionsyntax);
01682 
01683       if (!xmldoc_parse_option(node, tabs, buffer)) {
01684          ast_str_append(buffer, 0, "\n");
01685       }
01686       ast_str_append(buffer, 0, "\n");
01687       ast_xml_free_attr(optname);
01688       ast_xml_free_attr(hasparams);
01689       ast_free(optionsyntax);
01690    }
01691 }

static int xmldoc_parse_para ( struct ast_xml_node *  node,
const char *  tabs,
const char *  posttabs,
struct ast_str **  buffer 
) [static]

Definition at line 1198 of file xmldoc.c.

References ast_free, ast_str_append(), ast_str_buffer(), ast_xml_free_text(), ast_xml_get_text(), ast_xml_node_get_children(), ast_xml_node_get_name(), ast_xml_node_get_next(), and xmldoc_string_cleanup().

Referenced by xmldoc_get_formatted(), xmldoc_parse_argument(), xmldoc_parse_enum(), xmldoc_parse_option(), xmldoc_parse_parameter(), xmldoc_parse_specialtags(), xmldoc_parse_variable(), and xmldoc_parse_variablelist().

01199 {
01200    const char *tmptext;
01201    struct ast_xml_node *tmp;
01202    int ret = 0;
01203    struct ast_str *tmpstr;
01204 
01205    if (!node || !ast_xml_node_get_children(node)) {
01206       return ret;
01207    }
01208 
01209    if (strcasecmp(ast_xml_node_get_name(node), "para")) {
01210       return ret;
01211    }
01212 
01213    ast_str_append(buffer, 0, "%s", tabs);
01214 
01215    ret = 1;
01216 
01217    for (tmp = ast_xml_node_get_children(node); tmp; tmp = ast_xml_node_get_next(tmp)) {
01218       /* Get the text inside the <para> element and append it to buffer. */
01219       tmptext = ast_xml_get_text(tmp);
01220       if (tmptext) {
01221          /* Strip \n etc. */
01222          xmldoc_string_cleanup(tmptext, &tmpstr, 0);
01223          ast_xml_free_text(tmptext);
01224          if (tmpstr) {
01225             if (strcasecmp(ast_xml_node_get_name(tmp), "text")) {
01226                ast_str_append(buffer, 0, "<%s>%s</%s>", ast_xml_node_get_name(tmp),
01227                      ast_str_buffer(tmpstr), ast_xml_node_get_name(tmp));
01228             } else {
01229                ast_str_append(buffer, 0, "%s", ast_str_buffer(tmpstr));
01230             }
01231             ast_free(tmpstr);
01232             ret = 2;
01233          }
01234       }
01235    }
01236 
01237    ast_str_append(buffer, 0, "%s", posttabs);
01238 
01239    return ret;
01240 }

static void xmldoc_parse_parameter ( struct ast_xml_node *  fixnode,
const char *  tabs,
struct ast_str **  buffer 
) [static]

Definition at line 1700 of file xmldoc.c.

References ast_asprintf, ast_free, ast_str_append(), ast_xml_free_attr(), ast_xml_get_attribute(), ast_xml_node_get_children(), ast_xml_node_get_name(), ast_xml_node_get_next(), xmldoc_has_inside(), xmldoc_has_nodes(), xmldoc_parse_argument(), xmldoc_parse_enumlist(), xmldoc_parse_optionlist(), xmldoc_parse_para(), and xmldoc_parse_specialtags().

Referenced by ast_xmldoc_build_arguments().

01701 {
01702    const char *paramname;
01703    struct ast_xml_node *node = fixnode;
01704    int hasarguments, printed = 0;
01705    char *internaltabs;
01706 
01707    if (strcasecmp(ast_xml_node_get_name(node), "parameter")) {
01708       return;
01709    }
01710 
01711    hasarguments = xmldoc_has_inside(node, "argument");
01712    if (!(paramname = ast_xml_get_attribute(node, "name"))) {
01713       /* parameter MUST have an attribute name. */
01714       return;
01715    }
01716 
01717    if (ast_asprintf(&internaltabs, "%s    ", tabs) < 0) {
01718       ast_xml_free_attr(paramname);
01719       return;
01720    }
01721 
01722    if (!hasarguments && xmldoc_has_nodes(node)) {
01723       ast_str_append(buffer, 0, "%s\n", paramname);
01724       ast_xml_free_attr(paramname);
01725       printed = 1;
01726    }
01727 
01728    for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
01729       if (!strcasecmp(ast_xml_node_get_name(node), "optionlist")) {
01730          xmldoc_parse_optionlist(node, internaltabs, buffer);
01731       } else if (!strcasecmp(ast_xml_node_get_name(node), "enumlist")) {
01732          xmldoc_parse_enumlist(node, internaltabs, buffer);
01733       } else if (!strcasecmp(ast_xml_node_get_name(node), "argument")) {
01734          xmldoc_parse_argument(node, 1, internaltabs, (!hasarguments ? "        " : ""), buffer);
01735       } else if (!strcasecmp(ast_xml_node_get_name(node), "para")) {
01736          if (!printed) {
01737             ast_str_append(buffer, 0, "%s\n", paramname);
01738             ast_xml_free_attr(paramname);
01739             printed = 1;
01740          }
01741          if (xmldoc_parse_para(node, internaltabs, "\n", buffer)) {
01742             /* If anything ever goes in below this condition before the continue below,
01743              * we should probably continue immediately. */
01744             continue;
01745          }
01746          continue;
01747       } else if ((xmldoc_parse_specialtags(node, internaltabs, "\n", buffer))) {
01748          continue;
01749       }
01750    }
01751    if (!printed) {
01752       ast_xml_free_attr(paramname);
01753    }
01754    ast_free(internaltabs);
01755 }

static int xmldoc_parse_specialtags ( struct ast_xml_node *  fixnode,
const char *  tabs,
const char *  posttabs,
struct ast_str **  buffer 
) [static]

Definition at line 1252 of file xmldoc.c.

References ARRAY_LEN, ast_str_append(), ast_strlen_zero(), ast_xml_node_get_children(), ast_xml_node_get_name(), ast_xml_node_get_next(), special_tags, and xmldoc_parse_para().

Referenced by xmldoc_get_formatted(), xmldoc_parse_argument(), xmldoc_parse_enum(), xmldoc_parse_option(), xmldoc_parse_parameter(), xmldoc_parse_variable(), and xmldoc_parse_variablelist().

01253 {
01254    struct ast_xml_node *node = fixnode;
01255    int ret = 0, i, count = 0;
01256 
01257    if (!node || !ast_xml_node_get_children(node)) {
01258       return ret;
01259    }
01260 
01261    for (i = 0; i < ARRAY_LEN(special_tags); i++) {
01262       if (strcasecmp(ast_xml_node_get_name(node), special_tags[i].tagname)) {
01263          continue;
01264       }
01265 
01266       ret = 1;
01267       /* This is a special tag. */
01268 
01269       /* concat data */
01270       if (!ast_strlen_zero(special_tags[i].init)) {
01271          ast_str_append(buffer, 0, "%s%s", tabs, special_tags[i].init);
01272       }
01273 
01274       /* parse <para> elements inside special tags. */
01275       for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
01276          /* first <para> just print it without tabs at the begining. */
01277          if (xmldoc_parse_para(node, (!count ? "" : tabs), posttabs, buffer) == 2) {
01278             ret = 2;
01279          }
01280       }
01281 
01282       if (!ast_strlen_zero(special_tags[i].end)) {
01283          ast_str_append(buffer, 0, "%s%s", special_tags[i].end, posttabs);
01284       }
01285 
01286       break;
01287    }
01288 
01289    return ret;
01290 }

static int xmldoc_parse_variable ( struct ast_xml_node *  node,
const char *  tabs,
struct ast_str **  buffer 
) [static]

Definition at line 1349 of file xmldoc.c.

References ast_free, ast_str_append(), ast_str_buffer(), ast_str_strlen(), ast_xml_free_attr(), ast_xml_free_text(), ast_xml_get_attribute(), ast_xml_get_text(), ast_xml_node_get_children(), ast_xml_node_get_name(), ast_xml_node_get_next(), xmldoc_parse_para(), xmldoc_parse_specialtags(), and xmldoc_string_cleanup().

Referenced by xmldoc_parse_variablelist().

01350 {
01351    struct ast_xml_node *tmp;
01352    const char *valname;
01353    const char *tmptext;
01354    struct ast_str *cleanstr;
01355    int ret = 0, printedpara=0;
01356 
01357    for (tmp = ast_xml_node_get_children(node); tmp; tmp = ast_xml_node_get_next(tmp)) {
01358       if (xmldoc_parse_para(tmp, (ret ? tabs : ""), "\n", buffer)) {
01359          printedpara = 1;
01360          continue;
01361       } else if (xmldoc_parse_specialtags(tmp, (ret ? tabs : ""), "\n", buffer)) {
01362          printedpara = 1;
01363          continue;
01364       }
01365 
01366       if (strcasecmp(ast_xml_node_get_name(tmp), "value")) {
01367          continue;
01368       }
01369 
01370       /* Parse a <value> tag only. */
01371       if (!printedpara) {
01372          ast_str_append(buffer, 0, "\n");
01373          printedpara = 1;
01374       }
01375       /* Parse each <value name='valuename'>desciption</value> */
01376       valname = ast_xml_get_attribute(tmp, "name");
01377       if (valname) {
01378          ret = 1;
01379          ast_str_append(buffer, 0, "%s<value>%s</value>", tabs, valname);
01380          ast_xml_free_attr(valname);
01381       }
01382       tmptext = ast_xml_get_text(tmp);
01383       /* Check inside this node for any explanation about its meaning. */
01384       if (tmptext) {
01385          /* Cleanup text. */
01386          xmldoc_string_cleanup(tmptext, &cleanstr, 1);
01387          ast_xml_free_text(tmptext);
01388          if (cleanstr && ast_str_strlen(cleanstr) > 0) {
01389             ast_str_append(buffer, 0, ":%s", ast_str_buffer(cleanstr));
01390          }
01391          ast_free(cleanstr);
01392       }
01393       ast_str_append(buffer, 0, "\n");
01394    }
01395 
01396    return ret;
01397 }

static int xmldoc_parse_variablelist ( struct ast_xml_node *  node,
const char *  tabs,
struct ast_str **  buffer 
) [static]

Definition at line 1410 of file xmldoc.c.

References ast_asprintf, ast_free, ast_str_append(), ast_xml_free_attr(), ast_xml_get_attribute(), ast_xml_node_get_children(), ast_xml_node_get_name(), ast_xml_node_get_next(), xmldoc_parse_para(), xmldoc_parse_specialtags(), and xmldoc_parse_variable().

Referenced by xmldoc_get_formatted(), and xmldoc_parse_option().

01411 {
01412    struct ast_xml_node *tmp;
01413    const char *varname;
01414    char *vartabs;
01415    int ret = 0;
01416 
01417    if (!node || !ast_xml_node_get_children(node)) {
01418       return ret;
01419    }
01420 
01421    if (strcasecmp(ast_xml_node_get_name(node), "variablelist")) {
01422       return ret;
01423    }
01424 
01425    /* use this spacing (add 4 spaces) inside a variablelist node. */
01426    if (ast_asprintf(&vartabs, "%s    ", tabs) < 0) {
01427       return ret;
01428    }
01429    for (tmp = ast_xml_node_get_children(node); tmp; tmp = ast_xml_node_get_next(tmp)) {
01430       /* We can have a <para> element inside the variable list */
01431       if ((xmldoc_parse_para(tmp, (ret ? tabs : ""), "\n", buffer))) {
01432          ret = 1;
01433          continue;
01434       } else if ((xmldoc_parse_specialtags(tmp, (ret ? tabs : ""), "\n", buffer))) {
01435          ret = 1;
01436          continue;
01437       }
01438 
01439       if (!strcasecmp(ast_xml_node_get_name(tmp), "variable")) {
01440          /* Store the variable name in buffer. */
01441          varname = ast_xml_get_attribute(tmp, "name");
01442          if (varname) {
01443             ast_str_append(buffer, 0, "%s<variable>%s</variable>: ", tabs, varname);
01444             ast_xml_free_attr(varname);
01445             /* Parse the <variable> possible values. */
01446             xmldoc_parse_variable(tmp, vartabs, buffer);
01447             ret = 1;
01448          }
01449       }
01450    }
01451 
01452    ast_free(vartabs);
01453 
01454    return ret;
01455 }

static int xmldoc_postbrlen ( const char *  postbr  )  [static]

Definition at line 115 of file xmldoc.c.

Referenced by xmldoc_string_wrap().

00116 {
00117    int postbrreallen = 0, i;
00118    size_t postbrlen;
00119 
00120    if (!postbr) {
00121       return 0;
00122    }
00123    postbrlen = strlen(postbr);
00124    for (i = 0; i < postbrlen; i++) {
00125       if (postbr[i] == '\t') {
00126          postbrreallen += 8 - (postbrreallen % 8);
00127       } else {
00128          postbrreallen++;
00129       }
00130    }
00131    return postbrreallen;
00132 }

static void xmldoc_reverse_helper ( int  reverse,
int *  len,
char **  syntax,
const char *  fmt,
  ... 
) [static]

Definition at line 575 of file xmldoc.c.

References ast_free, ast_realloc, and ast_vasprintf.

Referenced by xmldoc_get_syntax_fun().

00576 {
00577    int totlen, tmpfmtlen;
00578    char *tmpfmt, tmp;
00579    va_list ap;
00580 
00581    va_start(ap, fmt);
00582    if (ast_vasprintf(&tmpfmt, fmt, ap) < 0) {
00583       va_end(ap);
00584       return;
00585    }
00586    va_end(ap);
00587 
00588    tmpfmtlen = strlen(tmpfmt);
00589    totlen = *len + tmpfmtlen + 1;
00590 
00591    *syntax = ast_realloc(*syntax, totlen);
00592 
00593    if (!*syntax) {
00594       ast_free(tmpfmt);
00595       return;
00596    }
00597 
00598    if (reverse) {
00599       memmove(*syntax + tmpfmtlen, *syntax, *len);
00600       /* Save this char, it will be overwritten by the \0 of strcpy. */
00601       tmp = (*syntax)[0];
00602       strcpy(*syntax, tmpfmt);
00603       /* Restore the already saved char. */
00604       (*syntax)[tmpfmtlen] = tmp;
00605       (*syntax)[totlen - 1] = '\0';
00606    } else {
00607       strcpy(*syntax + *len, tmpfmt);
00608    }
00609 
00610    *len = totlen - 1;
00611    ast_free(tmpfmt);
00612 }

static void xmldoc_setpostbr ( char *  postbr,
size_t  len,
const char *  text 
) [static]

Definition at line 141 of file xmldoc.c.

Referenced by xmldoc_string_wrap().

00142 {
00143    int c, postbrlen = 0;
00144 
00145    if (!text) {
00146       return;
00147    }
00148 
00149    for (c = 0; c < len; c++) {
00150       if (text[c] == '\t' || text[c] == ' ') {
00151          postbr[postbrlen++] = text[c];
00152       } else {
00153          break;
00154       }
00155    }
00156    postbr[postbrlen] = '\0';
00157 }

static void xmldoc_string_cleanup ( const char *  text,
struct ast_str **  output,
int  lastspaces 
) [static]

Definition at line 431 of file xmldoc.c.

References ast_log(), ast_str_append(), ast_str_create(), ast_str_trim_blanks(), and LOG_ERROR.

Referenced by xmldoc_get_formatted(), xmldoc_parse_para(), and xmldoc_parse_variable().

00432 {
00433    int i;
00434    size_t textlen;
00435 
00436    if (!text) {
00437       *output = NULL;
00438       return;
00439    }
00440 
00441    textlen = strlen(text);
00442 
00443    *output = ast_str_create(textlen);
00444    if (!(*output)) {
00445       ast_log(LOG_ERROR, "Problem allocating output buffer\n");
00446       return;
00447    }
00448 
00449    for (i = 0; i < textlen; i++) {
00450       if (text[i] == '\n' || text[i] == '\r') {
00451          /* remove spaces/tabs/\n after a \n. */
00452          while (text[i + 1] == '\t' || text[i + 1] == '\r' || text[i + 1] == '\n') {
00453             i++;
00454          }
00455          ast_str_append(output, 0, " ");
00456          continue;
00457       } else {
00458          ast_str_append(output, 0, "%c", text[i]);
00459       }
00460    }
00461 
00462    /* remove last spaces (we don't want always to remove the trailing spaces). */
00463    if (lastspaces) {
00464       ast_str_trim_blanks(*output);
00465    }
00466 }

static char* xmldoc_string_wrap ( const char *  text,
int  columns,
int  maxdiff 
) [static]

Definition at line 238 of file xmldoc.c.

References ast_free, ast_log(), ast_str_append(), ast_str_buffer(), ast_str_create(), ast_str_truncate(), ast_strdup, ESC, LOG_WARNING, xmldoc_foundspace_backward(), xmldoc_postbrlen(), xmldoc_setpostbr(), and xmldoc_wait_nextspace().

Referenced by ast_xmldoc_printable().

00239 {
00240    struct ast_str *tmp;
00241    char *ret, postbr[160];
00242    int count = 1, i, backspace, needtobreak = 0, colmax, textlen;
00243 
00244    /* sanity check */
00245    if (!text || columns <= 0 || maxdiff < 0) {
00246       ast_log(LOG_WARNING, "Passing wrong arguments while trying to wrap the text\n");
00247       return NULL;
00248    }
00249 
00250    tmp = ast_str_create(strlen(text) * 3);
00251 
00252    if (!tmp) {
00253       return NULL;
00254    }
00255 
00256    /* Check for blanks and tabs and put them in postbr. */
00257    xmldoc_setpostbr(postbr, sizeof(postbr), text);
00258    colmax = columns - xmldoc_postbrlen(postbr);
00259 
00260    textlen = strlen(text);
00261    for (i = 0; i < textlen; i++) {
00262       if (needtobreak || !(count % colmax)) {
00263          if (text[i] == ' ') {
00264             ast_str_append(&tmp, 0, "\n%s", postbr);
00265             needtobreak = 0;
00266             count = 1;
00267          } else if (text[i] != '\n') {
00268             needtobreak = 1;
00269             if (xmldoc_wait_nextspace(text, i, maxdiff)) {
00270                /* wait for the next space */
00271                ast_str_append(&tmp, 0, "%c", text[i]);
00272                continue;
00273             }
00274             /* Try to look backwards */
00275             backspace = xmldoc_foundspace_backward(text, i, maxdiff);
00276             if (backspace) {
00277                needtobreak = 1;
00278                ast_str_truncate(tmp, -backspace);
00279                i -= backspace + 1;
00280                continue;
00281             }
00282             ast_str_append(&tmp, 0, "\n%s", postbr);
00283             needtobreak = 0;
00284             count = 1;
00285          }
00286          /* skip blanks after a \n */
00287          while (text[i] == ' ') {
00288             i++;
00289          }
00290       }
00291       if (text[i] == '\n') {
00292          xmldoc_setpostbr(postbr, sizeof(postbr), &text[i] + 1);
00293          colmax = columns - xmldoc_postbrlen(postbr);
00294          needtobreak = 0;
00295          count = 1;
00296       }
00297       if (text[i] == ESC) {
00298          /* Ignore Escape sequences. */
00299          do {
00300             ast_str_append(&tmp, 0, "%c", text[i]);
00301             i++;
00302          } while (i < textlen && text[i] != 'm');
00303       } else {
00304          count++;
00305       }
00306       ast_str_append(&tmp, 0, "%c", text[i]);
00307    }
00308 
00309    ret = ast_strdup(ast_str_buffer(tmp));
00310    ast_free(tmp);
00311 
00312    return ret;
00313 }

static int xmldoc_wait_nextspace ( const char *  text,
int  currentpos,
int  maxdiff 
) [static]

Definition at line 169 of file xmldoc.c.

References ESC.

Referenced by xmldoc_string_wrap().

00170 {
00171    int i, textlen;
00172 
00173    if (!text) {
00174       return 0;
00175    }
00176 
00177    textlen = strlen(text);
00178    for (i = currentpos; i < textlen; i++) {
00179       if (text[i] == ESC) {
00180          /* Move to the end of the escape sequence */
00181          while (i < textlen && text[i] != 'm') {
00182             i++;
00183          }
00184       } else if (text[i] == ' ' || text[i] == '\n') {
00185          /* Found the next space or linefeed */
00186          return 1;
00187       } else if (i - currentpos > maxdiff) {
00188          /* We have looked the max distance and didn't find it */
00189          return 0;
00190       }
00191    }
00192 
00193    /* Reached the end and did not find it */
00194 
00195    return 0;
00196 }


Variable Documentation

struct strcolorized_tags colorized_tags[] [static]

Referenced by ast_xmldoc_printable().

const char default_documentation_language[] = "en_US" [static]

Default documentation language.

Definition at line 45 of file xmldoc.c.

char documentation_language[6] [static]

XML documentation language.

Definition at line 57 of file xmldoc.c.

struct strspecial_tags special_tags[] [static]
struct strsyntaxtype stxtype[] [static]

Mapping between type of node and type of syntax to generate.

Referenced by xmldoc_get_syntax_type().

const int xmldoc_max_diff = 5 [static]

This is a value that we will use to let the wrapping mechanism move the cursor backward and forward xmldoc_max_diff positions before cutting the middle of a word, trying to find a space or a
.

Definition at line 54 of file xmldoc.c.

const int xmldoc_text_columns = 74 [static]

Number of columns to print when showing the XML documentation with a 'core show application/function *' CLI command. Used in text wrapping.

Definition at line 49 of file xmldoc.c.


Generated on 20 Aug 2013 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1