xmldoc.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2008, Eliel C. Sardanons (LU1ALY) <eliels@gmail.com>
  5. *
  6. * See http://www.asterisk.org for more information about
  7. * the Asterisk project. Please do not directly contact
  8. * any of the maintainers of this project for assistance;
  9. * the project provides a web site, mailing lists and IRC
  10. * channels for your use.
  11. *
  12. * This program is free software, distributed under the terms of
  13. * the GNU General Public License Version 2. See the LICENSE file
  14. * at the top of the source tree.
  15. */
  16. #ifndef _ASTERISK_XMLDOC_H
  17. #define _ASTERISK_XMLDOC_H
  18. /*! \file
  19. * \brief Asterisk XML Documentation API
  20. */
  21. #include "asterisk/xml.h"
  22. #include "asterisk/stringfields.h"
  23. #include "asterisk/strings.h"
  24. /*! \brief From where the documentation come from, this structure is useful for
  25. * use it inside application/functions/manager actions structure. */
  26. enum ast_doc_src {
  27. AST_XML_DOC, /*!< From XML documentation */
  28. AST_STATIC_DOC /*!< From application/function registration */
  29. };
  30. #ifdef AST_XML_DOCS
  31. struct ao2_container;
  32. struct ast_xml_node;
  33. /*!
  34. * \brief The struct to be used as the head of an ast_xml_doc_item list
  35. * when being manipulated
  36. * \since 13.0.0
  37. */
  38. AST_LIST_HEAD(ast_xml_doc_item_list, ast_xml_doc_item);
  39. /*! \brief Struct that contains the XML documentation for a particular item. Note
  40. * that this is an ao2 ref counted object.
  41. *
  42. * \note
  43. * Each of the ast_str objects are built from the corresponding ast_xmldoc_build_*
  44. * calls
  45. *
  46. * \since 11
  47. */
  48. struct ast_xml_doc_item {
  49. /*! The syntax of the item */
  50. struct ast_str *syntax;
  51. /*! Seealso tagged information, if it exists */
  52. struct ast_str *seealso;
  53. /*! The arguments to the item */
  54. struct ast_str *arguments;
  55. /*! A synopsis of the item */
  56. struct ast_str *synopsis;
  57. /*! A description of the item */
  58. struct ast_str *description;
  59. AST_DECLARE_STRING_FIELDS(
  60. /*! The name of the item */
  61. AST_STRING_FIELD(name);
  62. /*! The type of the item */
  63. AST_STRING_FIELD(type);
  64. /*! Reference to another field */
  65. AST_STRING_FIELD(ref);
  66. );
  67. /*! The node that this item was created from. Note that the life time of
  68. * the node is not tied to the lifetime of this object.
  69. */
  70. struct ast_xml_node *node;
  71. /*! The next XML documentation item that matches the same name/item type */
  72. AST_LIST_ENTRY(ast_xml_doc_item) next;
  73. };
  74. /*! \brief Execute an XPath query on the loaded XML documentation
  75. * \param query The XPath query string to execute
  76. * \param ... Variable printf style format arguments
  77. * \retval An XPath results object on success
  78. * \retval NULL if no match found
  79. *
  80. * \since 12
  81. */
  82. struct ast_xml_xpath_results *__attribute__((format(printf, 1, 2))) ast_xmldoc_query(const char *fmt, ...);
  83. /*!
  84. * \brief Get the syntax for a specified application or function.
  85. * \param type Application, Function or AGI ?
  86. * \param name Name of the application or function.
  87. * \param module The module the item is in (optional, can be NULL)
  88. * \retval NULL on error.
  89. * \retval The generated syntax in a ast_malloc'ed string.
  90. */
  91. char *ast_xmldoc_build_syntax(const char *type, const char *name, const char *module);
  92. /*!
  93. * \brief Parse the <see-also> node content.
  94. * \param type 'application', 'function' or 'agi'.
  95. * \param name Application or functions name.
  96. * \param module The module the item is in (optional, can be NULL)
  97. * \retval NULL on error.
  98. * \retval Content of the see-also node.
  99. */
  100. char *ast_xmldoc_build_seealso(const char *type, const char *name, const char *module);
  101. /*!
  102. * \brief Generate the [arguments] tag based on type of node ('application',
  103. * 'function' or 'agi') and name.
  104. * \param type 'application', 'function' or 'agi' ?
  105. * \param name Name of the application or function to build the 'arguments' tag.
  106. * \param module The module the item is in (optional, can be NULL)
  107. * \retval NULL on error.
  108. * \retval Output buffer with the [arguments] tag content.
  109. */
  110. char *ast_xmldoc_build_arguments(const char *type, const char *name, const char *module);
  111. /*!
  112. * \brief Generate the [final response] tag based on type of node ('application',
  113. * 'function' or 'agi') and name.
  114. *
  115. * \param type 'application', 'function' or 'agi'
  116. * \param name Name of the application or function to build the 'responses' tag.
  117. * \param module The module the item is in (optional, can be NULL)
  118. *
  119. * \return An XMLDoc item list with the [final response] tag content.
  120. *
  121. * \since 13.0.0
  122. */
  123. struct ast_xml_doc_item *ast_xmldoc_build_final_response(const char *type, const char *name, const char *module);
  124. /*!
  125. * \brief Generate the [list responses] tag based on type of node ('application',
  126. * 'function' or 'agi') and name.
  127. *
  128. * \param type 'application', 'function' or 'agi'
  129. * \param name Name of the application or function to build the 'responses' tag.
  130. * \param module The module the item is in (optional, can be NULL)
  131. *
  132. * \return An XMLDoc item list with the [list responses] tag content.
  133. *
  134. * \since 13.0.0
  135. */
  136. struct ast_xml_doc_item *ast_xmldoc_build_list_responses(const char *type, const char *name, const char *module);
  137. /*!
  138. * \brief Colorize and put delimiters (instead of tags) to the xmldoc output.
  139. * \param bwinput Not colorized input with tags.
  140. * \param withcolors Result output with colors.
  141. * \retval NULL on error.
  142. * \retval New malloced buffer colorized and with delimiters.
  143. */
  144. char *ast_xmldoc_printable(const char *bwinput, int withcolors);
  145. /*!
  146. * \brief Generate synopsis documentation from XML.
  147. * \param type The source of documentation (application, function, etc).
  148. * \param name The name of the application, function, etc.
  149. * \param module The module the item is in (optional, can be NULL)
  150. * \retval NULL on error.
  151. * \retval A malloc'ed string with the synopsis.
  152. */
  153. char *ast_xmldoc_build_synopsis(const char *type, const char *name, const char *module);
  154. /*!
  155. * \brief Generate description documentation from XML.
  156. * \param type The source of documentation (application, function, etc).
  157. * \param name The name of the application, function, etc.
  158. * \param module The module the item is in (optional, can be NULL)
  159. * \retval NULL on error.
  160. * \retval A malloc'ed string with the formatted description.
  161. */
  162. char *ast_xmldoc_build_description(const char *type, const char *name, const char *module);
  163. /*!
  164. * \brief Build the documentation for a particular source type
  165. * \param type The source of the documentation items (application, function, etc.)
  166. *
  167. * \retval NULL on error
  168. * \retval An ao2_container populated with ast_xml_doc instances for each item
  169. * that exists for the specified source type
  170. *
  171. * \since 11
  172. */
  173. struct ao2_container *ast_xmldoc_build_documentation(const char *type);
  174. /*!
  175. * \brief Regenerate the documentation for a particular item
  176. * \param item The documentation item to regenerate
  177. *
  178. * \retval -1 on error
  179. * \retval 0 on success
  180. *
  181. * \since 12
  182. */
  183. int ast_xmldoc_regenerate_doc_item(struct ast_xml_doc_item *item);
  184. #endif /* AST_XML_DOCS */
  185. #endif /* _ASTERISK_XMLDOC_H */