apr_uri.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * apr_uri.h: External Interface of apr_uri.c
  18. */
  19. /**
  20. * @file apr_uri.h
  21. * @brief APR-UTIL URI Routines
  22. */
  23. #ifndef APR_URI_H
  24. #define APR_URI_H
  25. #include "apu.h"
  26. #include "apr_network_io.h"
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /**
  31. * @defgroup APR_Util_URI URI
  32. * @ingroup APR_Util
  33. * @{
  34. */
  35. #define APR_URI_FTP_DEFAULT_PORT 21 /**< default FTP port */
  36. #define APR_URI_SSH_DEFAULT_PORT 22 /**< default SSH port */
  37. #define APR_URI_TELNET_DEFAULT_PORT 23 /**< default telnet port */
  38. #define APR_URI_GOPHER_DEFAULT_PORT 70 /**< default Gopher port */
  39. #define APR_URI_HTTP_DEFAULT_PORT 80 /**< default HTTP port */
  40. #define APR_URI_POP_DEFAULT_PORT 110 /**< default POP port */
  41. #define APR_URI_NNTP_DEFAULT_PORT 119 /**< default NNTP port */
  42. #define APR_URI_IMAP_DEFAULT_PORT 143 /**< default IMAP port */
  43. #define APR_URI_PROSPERO_DEFAULT_PORT 191 /**< default Prospero port */
  44. #define APR_URI_WAIS_DEFAULT_PORT 210 /**< default WAIS port */
  45. #define APR_URI_LDAP_DEFAULT_PORT 389 /**< default LDAP port */
  46. #define APR_URI_HTTPS_DEFAULT_PORT 443 /**< default HTTPS port */
  47. #define APR_URI_RTSP_DEFAULT_PORT 554 /**< default RTSP port */
  48. #define APR_URI_SNEWS_DEFAULT_PORT 563 /**< default SNEWS port */
  49. #define APR_URI_ACAP_DEFAULT_PORT 674 /**< default ACAP port */
  50. #define APR_URI_NFS_DEFAULT_PORT 2049 /**< default NFS port */
  51. #define APR_URI_TIP_DEFAULT_PORT 3372 /**< default TIP port */
  52. #define APR_URI_SIP_DEFAULT_PORT 5060 /**< default SIP port */
  53. /** Flags passed to unparse_uri_components(): */
  54. /** suppress "scheme://user\@site:port" */
  55. #define APR_URI_UNP_OMITSITEPART (1U<<0)
  56. /** Just omit user */
  57. #define APR_URI_UNP_OMITUSER (1U<<1)
  58. /** Just omit password */
  59. #define APR_URI_UNP_OMITPASSWORD (1U<<2)
  60. /** omit "user:password\@" part */
  61. #define APR_URI_UNP_OMITUSERINFO (APR_URI_UNP_OMITUSER | \
  62. APR_URI_UNP_OMITPASSWORD)
  63. /** Show plain text password (default: show XXXXXXXX) */
  64. #define APR_URI_UNP_REVEALPASSWORD (1U<<3)
  65. /** Show "scheme://user\@site:port" only */
  66. #define APR_URI_UNP_OMITPATHINFO (1U<<4)
  67. /** Omit the "?queryarg" from the path */
  68. #define APR_URI_UNP_OMITQUERY (1U<<5)
  69. /** @see apr_uri_t */
  70. typedef struct apr_uri_t apr_uri_t;
  71. /**
  72. * A structure to encompass all of the fields in a uri
  73. */
  74. struct apr_uri_t {
  75. /** scheme ("http"/"ftp"/...) */
  76. char *scheme;
  77. /** combined [user[:password]\@]host[:port] */
  78. char *hostinfo;
  79. /** user name, as in http://user:passwd\@host:port/ */
  80. char *user;
  81. /** password, as in http://user:passwd\@host:port/ */
  82. char *password;
  83. /** hostname from URI (or from Host: header) */
  84. char *hostname;
  85. /** port string (integer representation is in "port") */
  86. char *port_str;
  87. /** the request path (or NULL if only scheme://host was given) */
  88. char *path;
  89. /** Everything after a '?' in the path, if present */
  90. char *query;
  91. /** Trailing "#fragment" string, if present */
  92. char *fragment;
  93. /** structure returned from gethostbyname() */
  94. struct hostent *hostent;
  95. /** The port number, numeric, valid only if port_str != NULL */
  96. apr_port_t port;
  97. /** has the structure been initialized */
  98. unsigned is_initialized:1;
  99. /** has the DNS been looked up yet */
  100. unsigned dns_looked_up:1;
  101. /** has the dns been resolved yet */
  102. unsigned dns_resolved:1;
  103. };
  104. /* apr_uri.c */
  105. /**
  106. * Return the default port for a given scheme. The schemes recognized are
  107. * http, ftp, https, gopher, wais, nntp, snews, and prospero
  108. * @param scheme_str The string that contains the current scheme
  109. * @return The default port for this scheme
  110. */
  111. APU_DECLARE(apr_port_t) apr_uri_port_of_scheme(const char *scheme_str);
  112. /**
  113. * Unparse a apr_uri_t structure to an URI string. Optionally
  114. * suppress the password for security reasons.
  115. * @param p The pool to allocate out of
  116. * @param uptr All of the parts of the uri
  117. * @param flags How to unparse the uri. One of:
  118. * <PRE>
  119. * APR_URI_UNP_OMITSITEPART Suppress "scheme://user\@site:port"
  120. * APR_URI_UNP_OMITUSER Just omit user
  121. * APR_URI_UNP_OMITPASSWORD Just omit password
  122. * APR_URI_UNP_OMITUSERINFO Omit "user:password\@" part
  123. * APR_URI_UNP_REVEALPASSWORD Show plain text password (default: show XXXXXXXX)
  124. * APR_URI_UNP_OMITPATHINFO Show "scheme://user\@site:port" only
  125. * APR_URI_UNP_OMITQUERY Omit "?queryarg" or "#fragment"
  126. * </PRE>
  127. * @return The uri as a string
  128. */
  129. APU_DECLARE(char *) apr_uri_unparse(apr_pool_t *p,
  130. const apr_uri_t *uptr,
  131. unsigned flags);
  132. /**
  133. * Parse a given URI, fill in all supplied fields of a apr_uri_t
  134. * structure. This eliminates the necessity of extracting host, port,
  135. * path, query info repeatedly in the modules.
  136. * @param p The pool to allocate out of
  137. * @param uri The uri to parse
  138. * @param uptr The apr_uri_t to fill out
  139. * @return APR_SUCCESS for success or error code
  140. */
  141. APU_DECLARE(apr_status_t) apr_uri_parse(apr_pool_t *p, const char *uri,
  142. apr_uri_t *uptr);
  143. /**
  144. * Special case for CONNECT parsing: it comes with the hostinfo part only
  145. * @param p The pool to allocate out of
  146. * @param hostinfo The hostinfo string to parse
  147. * @param uptr The apr_uri_t to fill out
  148. * @return APR_SUCCESS for success or error code
  149. */
  150. APU_DECLARE(apr_status_t) apr_uri_parse_hostinfo(apr_pool_t *p,
  151. const char *hostinfo,
  152. apr_uri_t *uptr);
  153. /** @} */
  154. #ifdef __cplusplus
  155. }
  156. #endif
  157. #endif /* APR_URI_H */