Asterisk XML Documentation API. More...
#include "asterisk/xml.h"

Go to the source code of this file.
Enumerations | |
| enum | ast_doc_src { AST_XML_DOC, AST_STATIC_DOC } |
From where the documentation come from, this structure is useful for use it inside application/functions/manager actions structure. 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. | |
Asterisk XML Documentation API.
Definition in file xmldoc.h.
| enum ast_doc_src |
From where the documentation come from, this structure is useful for use it inside application/functions/manager actions structure.
| AST_XML_DOC |
From XML documentation |
| AST_STATIC_DOC |
From application/function registration |
Definition at line 28 of file xmldoc.h.
00028 { 00029 AST_XML_DOC, /*!< From XML documentation */ 00030 AST_STATIC_DOC /*!< From application/function registration */ 00031 };
| 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.
| 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) |
| NULL | on error. | |
| Output | buffer with the [arguments] tag content. |
Definition at line 1741 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().
01742 { 01743 struct ast_xml_node *node; 01744 struct ast_str *ret = ast_str_create(128); 01745 char *retstr = NULL; 01746 01747 if (ast_strlen_zero(type) || ast_strlen_zero(name)) { 01748 ast_free(ret); 01749 return NULL; 01750 } 01751 01752 node = xmldoc_get_node(type, name, module, documentation_language); 01753 01754 if (!node || !ast_xml_node_get_children(node)) { 01755 ast_free(ret); 01756 return NULL; 01757 } 01758 01759 /* Find the syntax field. */ 01760 for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) { 01761 if (!strcasecmp(ast_xml_node_get_name(node), "syntax")) { 01762 break; 01763 } 01764 } 01765 01766 if (!node || !ast_xml_node_get_children(node)) { 01767 /* We couldn't find the syntax node. */ 01768 ast_free(ret); 01769 return NULL; 01770 } 01771 01772 for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) { 01773 xmldoc_parse_parameter(node, "", &ret); 01774 } 01775 01776 if (ast_str_strlen(ret) > 0) { 01777 /* remove last '\n' */ 01778 char *buf = ast_str_buffer(ret); 01779 if (buf[ast_str_strlen(ret) - 1] == '\n') { 01780 ast_str_truncate(ret, -1); 01781 } 01782 retstr = ast_strdup(ast_str_buffer(ret)); 01783 } 01784 ast_free(ret); 01785 01786 return retstr; 01787 }
| char* ast_xmldoc_build_description | ( | const char * | type, | |
| const char * | name, | |||
| const char * | module | |||
| ) |
Generate description documentation from XML.
| 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) |
| NULL | on error. | |
| A | malloc'ed string with the formatted description. |
Definition at line 1878 of file xmldoc.c.
References xmldoc_build_field().
Referenced by acf_retrieve_docs(), ast_agi_register(), ast_manager_register2(), and ast_register_application2().
01879 { 01880 return xmldoc_build_field(type, name, module, "description", 0); 01881 }
| char* ast_xmldoc_build_seealso | ( | const char * | type, | |
| const char * | name, | |||
| const char * | module | |||
| ) |
Parse the <see-also> node content.
| type | 'application', 'function' or 'agi'. | |
| name | Application or functions name. | |
| module | The module the item is in (optional, can be NULL) |
| NULL | on error. | |
| Content | of the see-also node. |
Definition at line 1442 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().
01443 { 01444 struct ast_str *outputstr; 01445 char *output; 01446 struct ast_xml_node *node; 01447 const char *typename; 01448 const char *content; 01449 int first = 1; 01450 01451 if (ast_strlen_zero(type) || ast_strlen_zero(name)) { 01452 return NULL; 01453 } 01454 01455 /* get the application/function root node. */ 01456 node = xmldoc_get_node(type, name, module, documentation_language); 01457 if (!node || !ast_xml_node_get_children(node)) { 01458 return NULL; 01459 } 01460 01461 /* Find the <see-also> node. */ 01462 for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) { 01463 if (!strcasecmp(ast_xml_node_get_name(node), "see-also")) { 01464 break; 01465 } 01466 } 01467 01468 if (!node || !ast_xml_node_get_children(node)) { 01469 /* we couldnt find a <see-also> node. */ 01470 return NULL; 01471 } 01472 01473 /* prepare the output string. */ 01474 outputstr = ast_str_create(128); 01475 if (!outputstr) { 01476 return NULL; 01477 } 01478 01479 /* get into the <see-also> node. */ 01480 for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) { 01481 if (strcasecmp(ast_xml_node_get_name(node), "ref")) { 01482 continue; 01483 } 01484 01485 /* parse the <ref> node. 'type' attribute is required. */ 01486 typename = ast_xml_get_attribute(node, "type"); 01487 if (!typename) { 01488 continue; 01489 } 01490 content = ast_xml_get_text(node); 01491 if (!content) { 01492 ast_xml_free_attr(typename); 01493 continue; 01494 } 01495 if (!strcasecmp(typename, "application")) { 01496 ast_str_append(&outputstr, 0, "%s%s()", (first ? "" : ", "), content); 01497 } else if (!strcasecmp(typename, "function")) { 01498 ast_str_append(&outputstr, 0, "%s%s", (first ? "" : ", "), content); 01499 } else if (!strcasecmp(typename, "astcli")) { 01500 ast_str_append(&outputstr, 0, "%s<astcli>%s</astcli>", (first ? "" : ", "), content); 01501 } else { 01502 ast_str_append(&outputstr, 0, "%s%s", (first ? "" : ", "), content); 01503 } 01504 first = 0; 01505 ast_xml_free_text(content); 01506 ast_xml_free_attr(typename); 01507 } 01508 01509 output = ast_strdup(ast_str_buffer(outputstr)); 01510 ast_free(outputstr); 01511 01512 return output; 01513 }
| char* ast_xmldoc_build_synopsis | ( | const char * | type, | |
| const char * | name, | |||
| const char * | module | |||
| ) |
Generate synopsis documentation from XML.
| 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) |
| NULL | on error. | |
| A | malloc'ed string with the synopsis. |
Definition at line 1873 of file xmldoc.c.
References xmldoc_build_field().
Referenced by acf_retrieve_docs(), ast_agi_register(), ast_manager_register2(), and ast_register_application2().
01874 { 01875 return xmldoc_build_field(type, name, module, "synopsis", 1); 01876 }
| char* ast_xmldoc_build_syntax | ( | const char * | type, | |
| const char * | name, | |||
| const char * | module | |||
| ) |
Get the syntax for a specified application or function.
| type | Application, Function or AGI ? | |
| name | Name of the application or function. | |
| module | The module the item is in (optional, can be NULL) |
| NULL | on error. | |
| The | generated syntax in a ast_malloc'ed string. |
Definition at line 1136 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().
01137 { 01138 struct ast_xml_node *node; 01139 char *syntax = NULL; 01140 01141 node = xmldoc_get_node(type, name, module, documentation_language); 01142 if (!node) { 01143 return NULL; 01144 } 01145 01146 for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) { 01147 if (!strcasecmp(ast_xml_node_get_name(node), "syntax")) { 01148 break; 01149 } 01150 } 01151 01152 if (node) { 01153 switch (xmldoc_get_syntax_type(type)) { 01154 case FUNCTION_SYNTAX: 01155 syntax = xmldoc_get_syntax_fun(node, name, "parameter", 1, 1); 01156 break; 01157 case COMMAND_SYNTAX: 01158 syntax = xmldoc_get_syntax_cmd(node, name, 1); 01159 break; 01160 case MANAGER_SYNTAX: 01161 syntax = xmldoc_get_syntax_manager(node, name); 01162 break; 01163 default: 01164 syntax = xmldoc_get_syntax_fun(node, name, "parameter", 1, 1); 01165 } 01166 } 01167 return syntax; 01168 }
| char* ast_xmldoc_printable | ( | const char * | bwinput, | |
| int | withcolors | |||
| ) |
Colorize and put delimiters (instead of tags) to the xmldoc output.
| bwinput | Not colorized input with tags. | |
| withcolors | Result output with colors. |
| 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_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 ast_term_color_code(&colorized, colorized_tags[c].colorfg, 0); 00358 if (!colorized) { 00359 return NULL; 00360 } 00361 } 00362 00363 /* copy initial string replace */ 00364 ast_str_append(&colorized, 0, "%s", colorized_tags[c].init); 00365 if (!colorized) { 00366 return NULL; 00367 } 00368 { 00369 char buf[len + 1]; 00370 ast_copy_string(buf, bwinput + i + strlen(colorized_tags[c].inittag), sizeof(buf)); 00371 ast_str_append(&colorized, 0, "%s", buf); 00372 } 00373 if (!colorized) { 00374 return NULL; 00375 } 00376 00377 /* copy the ending string replace */ 00378 ast_str_append(&colorized, 0, "%s", colorized_tags[c].end); 00379 if (!colorized) { 00380 return NULL; 00381 } 00382 00383 /* Continue with the last color. */ 00384 if (withcolors) { 00385 ast_term_color_code(&colorized, base_fg, 0); 00386 if (!colorized) { 00387 return NULL; 00388 } 00389 } 00390 00391 i += len + strlen(colorized_tags[c].endtag) + strlen(colorized_tags[c].inittag) - 1; 00392 colorsection = 1; 00393 break; 00394 } 00395 00396 if (!colorsection) { 00397 ast_str_append(&colorized, 0, "%c", bwinput[i]); 00398 if (!colorized) { 00399 return NULL; 00400 } 00401 } 00402 } 00403 00404 if (withcolors) { 00405 ast_str_append(&colorized, 0, "%s", term_end()); 00406 if (!colorized) { 00407 return NULL; 00408 } 00409 } 00410 00411 /* Wrap the text, notice that string wrap will avoid cutting an ESC sequence. */ 00412 wrapped = xmldoc_string_wrap(ast_str_buffer(colorized), xmldoc_text_columns, xmldoc_max_diff); 00413 00414 ast_free(colorized); 00415 00416 return wrapped; 00417 }
1.6.1