Fri Aug 17 00:17:50 2018

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 1122 of file xmldoc.c.

01122                 {
01123    FUNCTION_SYNTAX,
01124    MANAGER_SYNTAX,
01125    COMMAND_SYNTAX
01126 };


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 1761 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().

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

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 1899 of file xmldoc.c.

References xmldoc_build_field().

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

01900 {
01901    return xmldoc_build_field(type, name, module, "description", 0);
01902 }

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 1461 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().

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

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 1894 of file xmldoc.c.

References xmldoc_build_field().

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

01895 {
01896    return xmldoc_build_field(type, name, module, "synopsis", 1);
01897 }

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 1156 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().

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

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 1861 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_ERROR, LOG_WARNING, xmldoc_get_formatted(), and xmldoc_get_node().

Referenced by ast_xmldoc_build_description(), and ast_xmldoc_build_synopsis().

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

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 1817 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().

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

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 974 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().

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

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 685 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().

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

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

Definition at line 1072 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().

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

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

Definition at line 1144 of file xmldoc.c.

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

Referenced by ast_xmldoc_build_syntax().

01145 {
01146    int i;
01147    for (i=0; i < ARRAY_LEN(stxtype); i++) {
01148       if (!strcasecmp(stxtype[i].type, type)) {
01149          return stxtype[i].stxtype;
01150       }
01151    }
01152 
01153    return FUNCTION_SYNTAX;
01154 }

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

Definition at line 624 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().

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

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

Definition at line 642 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().

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

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

Definition at line 660 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().

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

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 1306 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().

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

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

Definition at line 927 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().

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

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

Definition at line 1541 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().

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

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

Definition at line 1573 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().

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

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

Definition at line 1609 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().

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

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

Definition at line 1653 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().

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

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

Definition at line 1202 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().

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

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

Definition at line 1704 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().

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

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

Definition at line 1256 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().

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

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

Definition at line 1353 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().

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

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

Definition at line 1414 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().

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

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

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 17 Aug 2018 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1