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

Go to the source code of this file.
Functions | |
| char * | ast_xmldoc_build_arguments (const char *type, const char *name) |
| 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) |
| Generate description documentation from XML. | |
| char * | ast_xmldoc_build_seealso (const char *type, const char *name) |
| Parse the <see-also> node content. | |
| char * | ast_xmldoc_build_synopsis (const char *type, const char *name) |
| Generate synopsis documentation from XML. | |
| char * | ast_xmldoc_build_syntax (const char *type, const char *name) |
| 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.
| char* ast_xmldoc_build_arguments | ( | const char * | type, | |
| const char * | name | |||
| ) |
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. |
| NULL | on error. | |
| Output | buffer with the [arguments] tag content. |
Definition at line 1611 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(), buf, xmldoc_get_node(), and xmldoc_parse_parameter().
Referenced by acf_retrieve_docs(), and ast_register_application2().
01612 { 01613 struct ast_xml_node *node; 01614 struct ast_str *ret = ast_str_create(128); 01615 char *retstr = NULL; 01616 01617 if (ast_strlen_zero(type) || ast_strlen_zero(name)) { 01618 return NULL; 01619 } 01620 01621 node = xmldoc_get_node(type, name, documentation_language); 01622 01623 if (!node || !ast_xml_node_get_children(node)) { 01624 return NULL; 01625 } 01626 01627 /* Find the syntax field. */ 01628 for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) { 01629 if (!strcasecmp(ast_xml_node_get_name(node), "syntax")) { 01630 break; 01631 } 01632 } 01633 01634 if (!node || !ast_xml_node_get_children(node)) { 01635 /* We couldn't find the syntax node. */ 01636 return NULL; 01637 } 01638 01639 for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) { 01640 xmldoc_parse_parameter(node, "", &ret); 01641 } 01642 01643 if (ast_str_strlen(ret) > 0) { 01644 /* remove last '\n' */ 01645 char *buf = ast_str_buffer(ret); 01646 if (buf[ast_str_strlen(ret) - 1] == '\n') { 01647 ast_str_truncate(ret, -1); 01648 } 01649 retstr = ast_strdup(ast_str_buffer(ret)); 01650 } 01651 ast_free(ret); 01652 01653 return retstr; 01654 }
| char* ast_xmldoc_build_description | ( | const char * | type, | |
| const char * | name | |||
| ) |
Generate description documentation from XML.
| type | The source of documentation (application, function, etc). | |
| name | The name of the application, function, etc. |
| NULL | on error. | |
| A | malloc'ed string with the formatted description. |
Definition at line 1745 of file xmldoc.c.
References xmldoc_build_field().
Referenced by acf_retrieve_docs(), ast_agi_register(), and ast_register_application2().
01746 { 01747 return xmldoc_build_field(type, name, "description", 0); 01748 }
| char* ast_xmldoc_build_seealso | ( | const char * | type, | |
| const char * | name | |||
| ) |
Parse the <see-also> node content.
| type | 'application', 'function' or 'agi'. | |
| name | Application or functions name. |
| NULL | on error. | |
| Content | of the see-also node. |
Definition at line 1318 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(), and ast_register_application2().
01319 { 01320 struct ast_str *outputstr; 01321 char *output; 01322 struct ast_xml_node *node; 01323 const char *typename; 01324 const char *content; 01325 int first = 1; 01326 01327 if (ast_strlen_zero(type) || ast_strlen_zero(name)) { 01328 return NULL; 01329 } 01330 01331 /* get the application/function root node. */ 01332 node = xmldoc_get_node(type, name, documentation_language); 01333 if (!node || !ast_xml_node_get_children(node)) { 01334 return NULL; 01335 } 01336 01337 /* Find the <see-also> node. */ 01338 for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) { 01339 if (!strcasecmp(ast_xml_node_get_name(node), "see-also")) { 01340 break; 01341 } 01342 } 01343 01344 if (!node || !ast_xml_node_get_children(node)) { 01345 /* we couldnt find a <see-also> node. */ 01346 return NULL; 01347 } 01348 01349 /* prepare the output string. */ 01350 outputstr = ast_str_create(128); 01351 if (!outputstr) { 01352 return NULL; 01353 } 01354 01355 /* get into the <see-also> node. */ 01356 for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) { 01357 if (strcasecmp(ast_xml_node_get_name(node), "ref")) { 01358 continue; 01359 } 01360 01361 /* parse the <ref> node. 'type' attribute is required. */ 01362 typename = ast_xml_get_attribute(node, "type"); 01363 if (!typename) { 01364 continue; 01365 } 01366 content = ast_xml_get_text(node); 01367 if (!content) { 01368 ast_xml_free_attr(typename); 01369 continue; 01370 } 01371 if (!strcasecmp(typename, "application")) { 01372 ast_str_append(&outputstr, 0, "%s%s()", (first ? "" : ", "), content); 01373 } else if (!strcasecmp(typename, "function")) { 01374 ast_str_append(&outputstr, 0, "%s%s", (first ? "" : ", "), content); 01375 } else if (!strcasecmp(typename, "astcli")) { 01376 ast_str_append(&outputstr, 0, "%s<astcli>%s</astcli>", (first ? "" : ", "), content); 01377 } else { 01378 ast_str_append(&outputstr, 0, "%s%s", (first ? "" : ", "), content); 01379 } 01380 first = 0; 01381 ast_xml_free_text(content); 01382 ast_xml_free_attr(typename); 01383 } 01384 01385 output = ast_strdup(ast_str_buffer(outputstr)); 01386 ast_free(outputstr); 01387 01388 return output; 01389 }
| char* ast_xmldoc_build_synopsis | ( | const char * | type, | |
| const char * | name | |||
| ) |
Generate synopsis documentation from XML.
| type | The source of documentation (application, function, etc). | |
| name | The name of the application, function, etc. |
| NULL | on error. | |
| A | malloc'ed string with the synopsis. |
Definition at line 1740 of file xmldoc.c.
References xmldoc_build_field().
Referenced by acf_retrieve_docs(), ast_agi_register(), and ast_register_application2().
01741 { 01742 return xmldoc_build_field(type, name, "synopsis", 1); 01743 }
| char* ast_xmldoc_build_syntax | ( | const char * | type, | |
| const char * | name | |||
| ) |
Get the syntax for a specified application or function.
| type | Application, Function or AGI ? | |
| name | Name of the application or function. |
| NULL | on error. | |
| The | generated syntax in a ast_malloc'ed string. |
Definition at line 1020 of file xmldoc.c.
References ast_xml_node_get_children(), ast_xml_node_get_name(), ast_xml_node_get_next(), FUNCTION_SYNTAX, xmldoc_get_node(), xmldoc_get_syntax_cmd(), xmldoc_get_syntax_fun(), and xmldoc_get_syntax_type().
Referenced by acf_retrieve_docs(), ast_agi_register(), and ast_register_application2().
01021 { 01022 struct ast_xml_node *node; 01023 char *syntax = NULL; 01024 01025 node = xmldoc_get_node(type, name, documentation_language); 01026 if (!node) { 01027 return NULL; 01028 } 01029 01030 for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) { 01031 if (!strcasecmp(ast_xml_node_get_name(node), "syntax")) { 01032 break; 01033 } 01034 } 01035 01036 if (node) { 01037 if (xmldoc_get_syntax_type(type) == FUNCTION_SYNTAX) { 01038 syntax = xmldoc_get_syntax_fun(node, name, "parameter", 1, 1); 01039 } else { 01040 syntax = xmldoc_get_syntax_cmd(node, name, 1); 01041 } 01042 } 01043 return syntax; 01044 }
| 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 309 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(), buf, COLOR_CYAN, colorized_tags, len(), term_end(), and xmldoc_string_wrap().
Referenced by handle_cli_agi_show(), handle_show_function(), print_app_docs(), and write_htmldump().
00310 { 00311 struct ast_str *colorized; 00312 char *wrapped = NULL; 00313 int i, c, len, colorsection; 00314 char *tmp; 00315 size_t bwinputlen; 00316 static const int base_fg = COLOR_CYAN; 00317 00318 if (!bwinput) { 00319 return NULL; 00320 } 00321 00322 bwinputlen = strlen(bwinput); 00323 00324 if (!(colorized = ast_str_create(256))) { 00325 return NULL; 00326 } 00327 00328 if (withcolors) { 00329 ast_term_color_code(&colorized, base_fg, 0); 00330 if (!colorized) { 00331 return NULL; 00332 } 00333 } 00334 00335 for (i = 0; i < bwinputlen; i++) { 00336 colorsection = 0; 00337 /* Check if we are at the beginning of a tag to be colorized. */ 00338 for (c = 0; c < ARRAY_LEN(colorized_tags); c++) { 00339 if (strncasecmp(bwinput + i, colorized_tags[c].inittag, strlen(colorized_tags[c].inittag))) { 00340 continue; 00341 } 00342 00343 if (!(tmp = strcasestr(bwinput + i + strlen(colorized_tags[c].inittag), colorized_tags[c].endtag))) { 00344 continue; 00345 } 00346 00347 len = tmp - (bwinput + i + strlen(colorized_tags[c].inittag)); 00348 00349 /* Setup color */ 00350 if (withcolors) { 00351 ast_term_color_code(&colorized, colorized_tags[c].colorfg, 0); 00352 if (!colorized) { 00353 return NULL; 00354 } 00355 } 00356 00357 /* copy initial string replace */ 00358 ast_str_append(&colorized, 0, "%s", colorized_tags[c].init); 00359 if (!colorized) { 00360 return NULL; 00361 } 00362 { 00363 char buf[len + 1]; 00364 ast_copy_string(buf, bwinput + i + strlen(colorized_tags[c].inittag), sizeof(buf)); 00365 ast_str_append(&colorized, 0, "%s", buf); 00366 } 00367 if (!colorized) { 00368 return NULL; 00369 } 00370 00371 /* copy the ending string replace */ 00372 ast_str_append(&colorized, 0, "%s", colorized_tags[c].end); 00373 if (!colorized) { 00374 return NULL; 00375 } 00376 00377 /* Continue with the last color. */ 00378 if (withcolors) { 00379 ast_term_color_code(&colorized, base_fg, 0); 00380 if (!colorized) { 00381 return NULL; 00382 } 00383 } 00384 00385 i += len + strlen(colorized_tags[c].endtag) + strlen(colorized_tags[c].inittag) - 1; 00386 colorsection = 1; 00387 break; 00388 } 00389 00390 if (!colorsection) { 00391 ast_str_append(&colorized, 0, "%c", bwinput[i]); 00392 if (!colorized) { 00393 return NULL; 00394 } 00395 } 00396 } 00397 00398 if (withcolors) { 00399 ast_str_append(&colorized, 0, "%s", term_end()); 00400 if (!colorized) { 00401 return NULL; 00402 } 00403 } 00404 00405 /* Wrap the text, notice that string wrap will avoid cutting an ESC sequence. */ 00406 wrapped = xmldoc_string_wrap(ast_str_buffer(colorized), xmldoc_text_columns, xmldoc_max_diff); 00407 00408 ast_free(colorized); 00409 00410 return wrapped; 00411 }
1.6.2