uri.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2014, Digium, Inc.
  5. *
  6. * Kevin Harwell <kharwell@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. #ifndef _ASTERISK_URI_H
  19. #define _ASTERISK_URI_H
  20. /*! \brief Opaque structure that stores uri information. */
  21. struct ast_uri;
  22. /*!
  23. * \brief Create a uri with the given parameters
  24. *
  25. * \param scheme the uri scheme (ex: http)
  26. * \param user_info user credentials (ex: <name>@<pass>)
  27. * \param host host name or ip address
  28. * \param port the port
  29. * \param path the path
  30. * \param query query parameters
  31. * \return a structure containing parsed uri data.
  32. * \return \c NULL on error
  33. * \since 13
  34. */
  35. struct ast_uri *ast_uri_create(const char *scheme, const char *user_info,
  36. const char *host, const char *port,
  37. const char *path, const char *query);
  38. /*!
  39. * \brief Copy the given uri replacing any value in the new uri with
  40. * any given.
  41. *
  42. * \param uri the uri object to copy
  43. * \param scheme the uri scheme (ex: http)
  44. * \param user_info user credentials (ex: <name>@<pass>)
  45. * \param host host name or ip address
  46. * \param port the port
  47. * \param path the path
  48. * \param query query parameters
  49. * \return a copy of the given uri with specified values replaced.
  50. * \return \c NULL on error
  51. * \since 13
  52. */
  53. struct ast_uri *ast_uri_copy_replace(const struct ast_uri *uri, const char *scheme,
  54. const char *user_info, const char *host,
  55. const char *port, const char *path,
  56. const char *query);
  57. /*!
  58. * \brief Retrieve the uri scheme.
  59. *
  60. * \return the uri scheme.
  61. * \since 13
  62. */
  63. const char *ast_uri_scheme(const struct ast_uri *uri);
  64. /*!
  65. * \brief Retrieve the uri user information.
  66. *
  67. * \return the uri user information.
  68. * \since 13
  69. */
  70. const char *ast_uri_user_info(const struct ast_uri *uri);
  71. /*!
  72. * \brief Retrieve the uri host.
  73. *
  74. * \return the uri host.
  75. * \since 13
  76. */
  77. const char *ast_uri_host(const struct ast_uri *uri);
  78. /*!
  79. * \brief Retrieve the uri port
  80. *
  81. * \return the uri port.
  82. * \since 13
  83. */
  84. const char *ast_uri_port(const struct ast_uri *uri);
  85. /*!
  86. * \brief Retrieve the uri path.
  87. *
  88. * \return the uri path.
  89. * \since 13
  90. */
  91. const char *ast_uri_path(const struct ast_uri *uri);
  92. /*!
  93. * \brief Retrieve the uri query parameters.
  94. *
  95. * \return the uri query parameters.
  96. * \since 13
  97. */
  98. const char *ast_uri_query(const struct ast_uri *uri);
  99. /*!
  100. * \brief Retrieve if the uri is of a secure type
  101. *
  102. * \note Secure types are recognized by an 's' at the end
  103. * of the scheme.
  104. *
  105. * \return True if secure, False otherwise.
  106. * \since 13
  107. */
  108. int attribute_pure ast_uri_is_secure(const struct ast_uri *uri);
  109. /*!
  110. * \brief Parse the given uri into a structure.
  111. *
  112. * \note Expects the following form:
  113. * <scheme>://[user:pass@]<host>[:port][/<path>]
  114. *
  115. * \param uri a string uri to parse
  116. * \return a structure containing parsed uri data.
  117. * \return \c NULL on error
  118. * \since 13
  119. */
  120. struct ast_uri *ast_uri_parse(const char *uri);
  121. /*!
  122. * \brief Parse the given http uri into a structure.
  123. *
  124. * \note Expects the following form:
  125. * [http[s]://][user:pass@]<host>[:port][/<path>]
  126. *
  127. * \note If no scheme is given it defaults to 'http' and if
  128. * no port is specified it will default to 443 if marked
  129. * secure, otherwise to 80.
  130. *
  131. * \param uri an http string uri to parse
  132. * \return a structure containing parsed http uri data.
  133. * \return \c NULL on error
  134. * \since 13
  135. */
  136. struct ast_uri *ast_uri_parse_http(const char *uri);
  137. /*!
  138. * \brief Parse the given websocket uri into a structure.
  139. *
  140. * \note Expects the following form:
  141. * [ws[s]://][user:pass@]<host>[:port][/<path>]
  142. *
  143. * \note If no scheme is given it defaults to 'ws' and if
  144. * no port is specified it will default to 443 if marked
  145. * secure, otherwise to 80.
  146. *
  147. * \param uri a websocket string uri to parse
  148. * \return a structure containing parsed http uri data.
  149. * \return \c NULL on error
  150. * \since 13
  151. */
  152. struct ast_uri *ast_uri_parse_websocket(const char *uri);
  153. /*!
  154. * \brief Retrieve a string of the host and port.
  155. *
  156. * \detail Combine the host and port (<host>:<port>) if the port
  157. * is available, otherwise just return the host.
  158. *
  159. * \note Caller is responsible for release the returned string.
  160. *
  161. * \param uri the uri object
  162. * \return a string value of the host and optional port.
  163. * \since 13
  164. */
  165. char *ast_uri_make_host_with_port(const struct ast_uri *uri);
  166. #endif /* _ASTERISK_URI_H */