34 #include "asterisk/_private.h"
62 struct ast_xml_doc *
doc;
85 {
"<",
">",
COLOR_GREEN,
"<replaceable>",
"</replaceable>" },
86 {
"\'",
"\'",
COLOR_BLUE,
"<literal>",
"</literal>" },
87 {
"*",
"*",
COLOR_RED,
"<emphasis>",
"</emphasis>" },
88 {
"\"",
"\"",
COLOR_YELLOW,
"<filename>",
"</filename>" },
89 {
"\"",
"\"",
COLOR_CYAN,
"<directory>",
"</directory>" },
90 {
"${",
"}",
COLOR_GREEN,
"<variable>",
"</variable>" },
93 {
"\'",
"\'",
COLOR_GRAY,
"<astcli>",
"</astcli>" },
97 {
"",
"",
COLOR_RED,
"<warning>",
"</warning>" }
105 {
"note",
"<note>NOTE:</note> ",
"" },
106 {
"warning",
"<warning>WARNING!!!:</warning> ",
"" }
117 int postbrreallen = 0, i;
123 postbrlen = strlen(postbr);
124 for (i = 0; i < postbrlen; i++) {
125 if (postbr[i] ==
'\t') {
126 postbrreallen += 8 - (postbrreallen % 8);
131 return postbrreallen;
143 int c, postbrlen = 0;
149 for (c = 0; c <
len; c++) {
150 if (text[c] ==
'\t' || text[c] ==
' ') {
151 postbr[postbrlen++] = text[c];
156 postbr[postbrlen] =
'\0';
177 textlen = strlen(text);
178 for (i = currentpos; i < textlen; i++) {
179 if (text[i] ==
ESC) {
181 while (i < textlen && text[i] !=
'm') {
184 }
else if (text[i] ==
' ' || text[i] ==
'\n') {
187 }
else if (i - currentpos > maxdiff) {
213 for (i = currentpos; i > 0; i--) {
214 if (text[i] ==
' ' || text[i] ==
'\n') {
215 return (currentpos - i);
216 }
else if (text[i] ==
'm' && (text[i - 1] >=
'0' || text[i - 1] <=
'9')) {
219 }
else if (currentpos - i > maxdiff) {
241 char *ret, postbr[160];
242 int count = 1, i, backspace, needtobreak = 0, colmax, textlen;
245 if (!text || columns <= 0 || maxdiff < 0) {
260 textlen = strlen(text);
261 for (i = 0; i < textlen; i++) {
262 if (needtobreak || !(count % colmax)) {
263 if (text[i] ==
' ') {
267 }
else if (text[i] !=
'\n') {
287 while (text[i] ==
' ') {
291 if (text[i] ==
'\n') {
297 if (text[i] ==
ESC) {
302 }
while (i < textlen && text[i] !=
'm');
318 char *wrapped = NULL;
319 int i, c,
len, colorsection;
328 bwinputlen = strlen(bwinput);
341 for (i = 0; i < bwinputlen; i++) {
441 textlen = strlen(text);
449 for (i = 0; i < textlen; i++) {
450 if (text[i] ==
'\n' || text[i] ==
'\r') {
452 while (text[i + 1] ==
'\t' || text[i + 1] ==
'\r' || text[i + 1] ==
'\n') {
479 int match = attr_value && !strcmp(attr_value, value);
497 struct ast_xml_node *node = NULL;
498 struct ast_xml_node *first_match = NULL;
499 struct ast_xml_node *lang_match = NULL;
591 tmpfmtlen = strlen(tmpfmt);
592 totlen = *len + tmpfmtlen + 1;
599 *syntax = new_syntax;
602 memmove(*syntax + tmpfmtlen, *syntax, *len);
605 strcpy(*syntax, tmpfmt);
607 (*syntax)[tmpfmtlen] = tmp;
608 (*syntax)[totlen - 1] =
'\0';
610 strcpy(*syntax + *len, tmpfmt);
626 struct ast_xml_node *node = fixnode;
644 struct ast_xml_node *node = fixnode;
662 struct ast_xml_node *node = fixnode;
685 static char *
xmldoc_get_syntax_fun(
struct ast_xml_node *rootnode,
const char *rootname,
const char *childname,
int printparenthesis,
int printrootname)
687 #define GOTONEXT(__rev, __a) (__rev ? ast_xml_node_get_prev(__a) : ast_xml_node_get_next(__a))
688 #define ISLAST(__rev, __a) (__rev == 1 ? (ast_xml_node_get_prev(__a) ? 0 : 1) : (ast_xml_node_get_next(__a) ? 0 : 1))
689 #define MP(__a) ((multiple ? __a : ""))
690 struct ast_xml_node *node = NULL, *firstparam = NULL, *lastparam = NULL;
691 const char *paramtype, *multipletype, *paramnameattr, *attrargsep, *parenthesis, *argname;
692 int reverse, required, paramcount = 0, openbrackets = 0,
len = 0, hasparams=0;
693 int reqfinode = 0, reqlanode = 0, optmidnode = 0, prnparenthesis, multiple;
694 char *syntax = NULL, *argsep, *paramname;
697 ast_log(
LOG_WARNING,
"Tried to look in XML tree with faulty rootname or childname while creating a syntax.\n");
703 if (
ast_asprintf(&syntax,
"%s%s", (printrootname ? rootname :
""), (printparenthesis ?
"()" :
"")) < 0) {
734 reqlanode = required;
739 reqfinode = required;
745 if (
ast_asprintf(&syntax,
"%s%s", (printrootname ? rootname :
""), (printparenthesis ?
"()" :
"")) < 0) {
751 if (reqfinode && reqlanode) {
757 if (node != firstparam && node != lastparam) {
770 if ((!reqfinode && reqlanode) || (reqfinode && reqlanode && optmidnode)) {
781 (printrootname ? (printrootname == 2 ?
")]" :
")"):
""));
784 (printrootname ? (printrootname == 2 ?
"[(" :
"(") :
""));
787 for (; node; node =
GOTONEXT(reverse, node)) {
797 prnparenthesis =
ast_true(parenthesis);
798 if (!strcasecmp(parenthesis,
"optional")) {
813 if (!paramnameattr) {
820 if (
ast_asprintf(&syntax,
"%s%s", (printrootname ? rootname :
""), (printparenthesis ?
"()" :
"")) < 0) {
858 while (openbrackets > 0) {
874 if (
ISLAST(reverse, node)) {
878 MP(
"["),
MP(argsep),
MP(
"...]"), argsep);
881 MP(
"["),
MP(argsep),
MP(
"...]"));
886 MP(
"["),
MP(argsep),
MP(
"...]"));
889 MP(
"["),
MP(argsep),
MP(
"...]"));
901 while (openbrackets > 0) {
909 (printrootname ? (printrootname == 2 ?
"[(" :
"(") :
""));
929 struct ast_xml_node *node = fixnode;
931 char *enumname, *ret;
977 struct ast_xml_node *tmpnode, *node = fixnode;
978 char *ret, *paramname;
979 const char *paramtype, *attrname, *literal;
980 int required, isenum,
first = 1, isliteral;
1049 (required ?
"" :
"["),
1050 (isenum || isliteral ?
"" :
"<"),
1052 (isenum || isliteral ?
"" :
">"),
1053 (required ?
"" :
"]"));
1075 struct ast_xml_node *node = fixnode;
1076 const char *paramtype, *attrname;
1107 (required ?
"" :
"["),
1109 (required ?
"" :
"]"));
1148 if (!strcasecmp(
stxtype[i].type, type)) {
1158 struct ast_xml_node *node;
1159 char *syntax = NULL;
1204 const char *tmptext;
1205 struct ast_xml_node *tmp;
1258 struct ast_xml_node *node = fixnode;
1259 int ret = 0, i, count = 0;
1308 struct ast_xml_node *node = fixnode;
1309 const char *argname;
1310 int count = 0, ret = 0;
1322 ast_str_append(buffer, 0,
"%s%s%s", tabs, argname, (insideparameter ?
"\n" :
""));
1330 if (
xmldoc_parse_para(node, (insideparameter ? paramtabs : (!count ?
" - " : tabs)),
"\n", buffer) == 2) {
1333 }
else if (
xmldoc_parse_specialtags(node, (insideparameter ? paramtabs : (!count ?
" - " : tabs)),
"\n", buffer) == 2) {
1355 struct ast_xml_node *tmp;
1356 const char *valname;
1357 const char *tmptext;
1359 int ret = 0, printedpara=0;
1416 struct ast_xml_node *tmp;
1417 const char *varname;
1447 ast_str_append(buffer, 0,
"%s<variable>%s</variable>: ", tabs, varname);
1465 struct ast_xml_node *node;
1466 const char *
typename;
1467 const char *content;
1514 if (!strcasecmp(
typename,
"application")) {
1515 ast_str_append(&outputstr, 0,
"%s%s()", (first ?
"" :
", "), content);
1516 }
else if (!strcasecmp(
typename,
"function")) {
1517 ast_str_append(&outputstr, 0,
"%s%s", (first ?
"" :
", "), content);
1518 }
else if (!strcasecmp(
typename,
"astcli")) {
1519 ast_str_append(&outputstr, 0,
"%s<astcli>%s</astcli>", (first ?
"" :
", "), content);
1521 ast_str_append(&outputstr, 0,
"%s%s", (first ?
"" :
", "), content);
1543 struct ast_xml_node *node = fixnode;
1575 struct ast_xml_node *node = fixnode;
1576 const char *enumname;
1611 struct ast_xml_node *node;
1655 struct ast_xml_node *node;
1656 const char *optname, *hasparams;
1674 if (hasparams && !strcasecmp(hasparams,
"optional")) {
1679 if (!optionsyntax) {
1706 const char *paramname;
1707 struct ast_xml_node *node = fixnode;
1708 int hasarguments, printed = 0;
1763 struct ast_xml_node *node;
1765 char *retstr = NULL;
1819 struct ast_xml_node *tmp;
1820 const char *notcleanret, *tmpstr;
1826 tmpstr = notcleanret;
1863 struct ast_xml_node *node;
1904 #if !defined(HAVE_GLOB_NOMAGIC) || !defined(HAVE_GLOB_BRACE) || defined(DEBUG_NONGNU)
1905 static int xml_pathmatch(
char *xmlpattern,
int xmlpattern_maxlen, glob_t *globbuf)
1909 snprintf(xmlpattern, xmlpattern_maxlen,
"%s/documentation/thirdparty/*-%s.xml",
1911 if((globret = glob(xmlpattern, GLOB_NOCHECK, NULL, globbuf))) {
1915 snprintf(xmlpattern, xmlpattern_maxlen,
"%s/documentation/thirdparty/*-%.2s_??.xml",
1917 if((globret = glob(xmlpattern, GLOB_APPEND | GLOB_NOCHECK, NULL, globbuf))) {
1921 snprintf(xmlpattern, xmlpattern_maxlen,
"%s/documentation/thirdparty/*-%s.xml",
1923 if((globret = glob(xmlpattern, GLOB_APPEND | GLOB_NOCHECK, NULL, globbuf))) {
1927 snprintf(xmlpattern, xmlpattern_maxlen,
"%s/documentation/*-%s.xml",
1929 if((globret = glob(xmlpattern, GLOB_APPEND | GLOB_NOCHECK, NULL, globbuf))) {
1933 snprintf(xmlpattern, xmlpattern_maxlen,
"%s/documentation/*-%.2s_??.xml",
1935 if((globret = glob(xmlpattern, GLOB_APPEND | GLOB_NOCHECK, NULL, globbuf))) {
1939 snprintf(xmlpattern, xmlpattern_maxlen,
"%s/documentation/*-%s.xml",
1941 globret = glob(xmlpattern, GLOB_APPEND | GLOB_NOCHECK, NULL, globbuf);
1965 struct ast_xml_node *root_node;
1966 struct ast_xml_doc *tmpdoc;
1972 int globret, i, dup, duplicate;
1974 #if !defined(HAVE_GLOB_NOMAGIC) || !defined(HAVE_GLOB_BRACE) || defined(DEBUG_NONGNU)
1975 int xmlpattern_maxlen;
1979 snprintf(documentation_language,
sizeof(documentation_language), default_documentation_language);
1983 if (!strcasecmp(var->
name,
"documentation_language")) {
1985 snprintf(documentation_language,
sizeof(documentation_language),
"%s", var->
value);
1998 globbuf.gl_offs = 0;
2000 #if !defined(HAVE_GLOB_NOMAGIC) || !defined(HAVE_GLOB_BRACE) || defined(DEBUG_NONGNU)
2001 xmlpattern_maxlen = strlen(
ast_config_AST_DATA_DIR) + strlen(
"/documentation/thirdparty") + strlen(
"/*-??_??.xml") + 1;
2003 globret = xml_pathmatch(xmlpattern, xmlpattern_maxlen, &globbuf);
2007 documentation_language, documentation_language, default_documentation_language) < 0) {
2013 ast_debug(3,
"gl_pathc %zu\n", globbuf.gl_pathc);
2014 if (globret == GLOB_NOSPACE) {
2015 ast_log(
LOG_WARNING,
"XML load failure, glob expansion of pattern '%s' failed: Not enough memory\n", xmlpattern);
2019 ast_log(
LOG_WARNING,
"XML load failure, glob expansion of pattern '%s' failed: Read error\n", xmlpattern);
2027 for (i = 0; i < globbuf.gl_pathc; i++) {
2030 for (dup = 0; dup < i; dup++) {
2031 if (!strcmp(globbuf.gl_pathv[i], globbuf.gl_pathv[dup])) {
2036 if (duplicate || strchr(globbuf.gl_pathv[i],
'*')) {
2044 ast_log(
LOG_ERROR,
"Could not open XML documentation at '%s'\n", globbuf.gl_pathv[i]);
2066 doc_tree->
doc = tmpdoc;
static int xmldoc_parse_option(struct ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
Asterisk main include file. File version handling, generic pbx functions.
int ast_xml_init(void)
Initialize the XML library implementation. This function is used to setup everything needed to start ...
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized...
String manipulation functions.
#define ast_vasprintf(a, b, c)
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 void xmldoc_parse_optionlist(struct ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
static int xmldoc_foundspace_backward(const char *text, int currentpos, int maxdiff)
static int xmldoc_attribute_match(struct ast_xml_node *node, const char *attr, const char *value)
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
struct ast_xml_doc * ast_xml_open(char *filename)
Open an XML document.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
char * ast_xmldoc_build_description(const char *type, const char *name, const char *module)
Generate description documentation from XML.
static struct ast_str * xmldoc_get_formatted(struct ast_xml_node *node, int raw_output, int raw_wrap)
Mapping between type of node and type of syntax to generate.
Structure for variables, used for configurations and for channel variables.
int ast_term_color_code(struct ast_str **str, int fgcolor, int bgcolor)
Append a color sequence to an ast_str.
static int xmldoc_wait_nextspace(const char *text, int currentpos, int maxdiff)
static void xmldoc_reverse_helper(int reverse, int *len, char **syntax, const char *fmt,...)
Configuration File Parser.
static char * xmldoc_get_syntax_cmd(struct ast_xml_node *fixnode, const char *name, int printname)
int ast_xmldoc_load_documentation(void)
Load XML documentation. Provided by xmldoc.c.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
static int xmldoc_parse_enum(struct ast_xml_node *fixnode, const char *tabs, struct ast_str **buffer)
struct ast_str * ast_str_create(size_t init_len)
Create a malloc'ed dynamic length string.
struct ast_xml_node * ast_xml_get_root(struct ast_xml_doc *doc)
Get the document root node.
char * ast_xmldoc_build_synopsis(const char *type, const char *name, const char *module)
Generate synopsis documentation from XML.
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...
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
void ast_config_destroy(struct ast_config *config)
Destroys a config.
static char * xmldoc_string_wrap(const char *text, int columns, int maxdiff)
char * ast_str_truncate(struct ast_str *buf, ssize_t len)
Truncates the enclosed string to the given length.
static int xmldoc_has_specialtags(struct ast_xml_node *fixnode)
static struct strsyntaxtype stxtype[]
static int xmldoc_has_nodes(struct ast_xml_node *fixnode)
const char * ast_xml_get_attribute(struct ast_xml_node *node, const char *attrname)
Get a node attribute by name.
void ast_xml_free_attr(const char *attribute)
Free an attribute returned by ast_xml_get_attribute()
syntaxtype
Types of syntax that we are able to generate.
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
#define ast_asprintf(a, b, c...)
#define ast_debug(level,...)
Log a DEBUG message.
static struct strspecial_tags special_tags[]
Asterisk file paths, configured in asterisk.conf.
static const char default_documentation_language[]
Default documentation language.
#define ISLAST(__rev, __a)
static force_inline int attribute_pure ast_strlen_zero(const char *s)
static char * xmldoc_get_syntax_manager(struct ast_xml_node *fixnode, const char *name)
int ast_register_atexit(void(*func)(void))
Register a function to be executed before Asterisk exits.
struct ast_xml_node * ast_xml_find_element(struct ast_xml_node *root_node, const char *name, const char *attrname, const char *attrvalue)
Find a node element by name.
A set of macros to manage forward-linked lists.
static char language[MAX_LANGUAGE]
static const int xmldoc_max_diff
This is a value that we will use to let the wrapping mechanism move the cursor backward and forward x...
static int xmldoc_parse_specialtags(struct ast_xml_node *fixnode, const char *tabs, const char *posttabs, struct ast_str **buffer)
static struct strcolorized_tags colorized_tags[]
static char documentation_language[6]
XML documentation language.
const char * ast_config_AST_DATA_DIR
#define ast_strdupa(s)
duplicate a string in memory from the stack
static void xmldoc_parse_parameter(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)
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
static enum syntaxtype xmldoc_get_syntax_type(const char *type)
static const int xmldoc_text_columns
Number of columns to print when showing the XML documentation with a 'core show application/function ...
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
struct sla_ringing_trunk * first
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
static void xmldoc_unload_documentation(void)
Close and unload XML documentation.
static int xmldoc_parse_argument(struct ast_xml_node *fixnode, int insideparameter, const char *paramtabs, const char *tabs, struct ast_str **buffer)
#define GOTONEXT(__rev, __a)
static void xmldoc_string_cleanup(const char *text, struct ast_str **output, int lastspaces)
static char * xmldoc_parse_cmd_enumlist(struct ast_xml_node *fixnode)
static int xmldoc_has_inside(struct ast_xml_node *fixnode, const char *what)
Asterisk XML Documentation API.
#define AST_RWLIST_REMOVE_HEAD
char * ast_xmldoc_printable(const char *bwinput, int withcolors)
Colorize and put delimiters (instead of tags) to the xmldoc output.
#define ast_opt_light_background
void ast_xml_close(struct ast_xml_doc *doc)
Close an already open document and free the used structure.
Structure used to handle boolean flags.
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_build_seealso(const char *type, const char *name, const char *module)
Parse the <see-also> node content.
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
#define AST_RWLIST_INSERT_TAIL
static void xmldoc_setpostbr(char *postbr, size_t len, const char *text)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
#define ast_realloc(a, b)
const char * ast_xml_get_text(struct ast_xml_node *node)
Get an element content string.
Handy terminal functions for vt* terms.
struct ast_variable * next
static int xmldoc_parse_para(struct ast_xml_node *node, const char *tabs, const char *posttabs, struct ast_str **buffer)
Container of documentation trees.
void ast_str_trim_blanks(struct ast_str *buf)
Trims trailing whitespace characters from an ast_str string.
#define CONFIG_STATUS_FILEINVALID
struct ast_xml_node * ast_xml_node_get_next(struct ast_xml_node *node)
Get the next node in the same level.
char * strcasestr(const char *, const char *)
static struct ast_xml_node * xmldoc_get_node(const char *type, const char *name, const char *module, const char *language)
static snd_pcm_format_t format
int ast_xml_finish(void)
Cleanup library allocated global data.
static int match(struct sockaddr_in *sin, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
static int xmldoc_parse_variablelist(struct ast_xml_node *node, const char *tabs, struct ast_str **buffer)
static int xmldoc_parse_variable(struct ast_xml_node *node, const char *tabs, struct ast_str **buffer)
struct ast_xml_node * ast_xml_node_get_children(struct ast_xml_node *node)
Get the node's children.
const char * ast_xml_node_get_name(struct ast_xml_node *node)
Get the name of a node.
void ast_xml_free_text(const char *text)
Free a content element that was returned by ast_xml_get_text()
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
static char * xmldoc_get_syntax_fun(struct ast_xml_node *rootnode, const char *rootname, const char *childname, int printparenthesis, int printrootname)
static int xmldoc_postbrlen(const char *postbr)