res_pjsip_presence_xml.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2014, Digium, Inc.
  5. *
  6. * Mark Michelson <mmichelson@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*!
  19. * \brief Length of the XML prolog when printing presence or other XML in PJSIP.
  20. *
  21. * When calling any variant of pj_xml_print(), the documentation
  22. * claims that it will return -1 if the provided buffer is not
  23. * large enough. However, if the XML prolog is requested to be
  24. * printed and the buffer is not large enough, then it will
  25. * return -1 only if the buffer is not large enough to hold the
  26. * XML prolog or return the length of the XML prolog on failure
  27. * instead of -1.
  28. *
  29. * This constant is useful to check against when trying to determine
  30. * if printing XML succeeded or failed.
  31. */
  32. #define AST_PJSIP_XML_PROLOG_LEN 39
  33. /*!
  34. * PIDF state
  35. */
  36. enum ast_sip_pidf_state {
  37. /*! Device is not in use */
  38. NOTIFY_OPEN,
  39. /*! Device is in use or ringing */
  40. NOTIFY_INUSE,
  41. /*! Device is unavailable, on hold, or busy */
  42. NOTIFY_CLOSED
  43. };
  44. /*!
  45. * \brief Replace offensive XML characters with XML entities
  46. *
  47. * " = &quot;
  48. * < = &lt;
  49. * > = &gt;
  50. * ' = &apos;
  51. * & = &amp;
  52. *
  53. * \param input String to sanitize
  54. * \param[out] output Sanitized string
  55. * \param len Size of output buffer
  56. */
  57. void ast_sip_sanitize_xml(const char *input, char *output, size_t len);
  58. /*!
  59. * \brief Convert extension state to relevant PIDF strings
  60. *
  61. * \param state The extension state
  62. * \param[out] statestring
  63. * \param[out] pidfstate
  64. * \param[out] pidfnote
  65. * \param[out] local_state
  66. */
  67. void ast_sip_presence_exten_state_to_str(int state, char **statestring,
  68. char **pidfstate, char **pidfnote, enum ast_sip_pidf_state *local_state,
  69. unsigned int notify_early_inuse_ringing);
  70. /*!
  71. * \brief Create XML attribute
  72. *
  73. * \param pool Allocation pool
  74. * \param node Node to add attribute to
  75. * \param name The attribute name
  76. * \param value The attribute value
  77. *
  78. * \return The created attribute
  79. */
  80. pj_xml_attr *ast_sip_presence_xml_create_attr(pj_pool_t *pool,
  81. pj_xml_node *node, const char *name, const char *value);
  82. /*!
  83. * \brief Create XML node
  84. *
  85. * \param pool Allocation pool
  86. * \param parent Optional node that will be parent to the created node
  87. * \param name The name for the new node
  88. * \return The created node
  89. */
  90. pj_xml_node *ast_sip_presence_xml_create_node(pj_pool_t *pool,
  91. pj_xml_node *parent, const char* name);
  92. /*!
  93. * \brief Find an attribute within a given node
  94. *
  95. * Given a starting node, this will find an attribute that belongs
  96. * to a specific node. If the node does not exist, it will be created
  97. * under the passed-in parent. If the attribute does not exist, then
  98. * it will be created on the node with an empty string as its value.
  99. *
  100. * \param pool Allocation pool
  101. * \param parent Starting node for search
  102. * \param node_name Name of node where to find attribute
  103. * \param attr_name Name of attribute to find
  104. * \param[out] node Node that was found or created
  105. * \param[out] attr Attribute that was found or created
  106. * \return The found attribute
  107. */
  108. void ast_sip_presence_xml_find_node_attr(pj_pool_t* pool,
  109. pj_xml_node *parent, const char *node_name, const char *attr_name,
  110. pj_xml_node **node, pj_xml_attr **attr);