1 /* $OpenBSD: util_uri.h,v 1.6 2005/03/28 23:26:51 niallo Exp $ */
2 
3 /* ====================================================================
4  * The Apache Software License, Version 1.1
5  *
6  * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
7  * reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in
18  *    the documentation and/or other materials provided with the
19  *    distribution.
20  *
21  * 3. The end-user documentation included with the redistribution,
22  *    if any, must include the following acknowledgment:
23  *       "This product includes software developed by the
24  *        Apache Software Foundation (http://www.apache.org/)."
25  *    Alternately, this acknowledgment may appear in the software itself,
26  *    if and wherever such third-party acknowledgments normally appear.
27  *
28  * 4. The names "Apache" and "Apache Software Foundation" must
29  *    not be used to endorse or promote products derived from this
30  *    software without prior written permission. For written
31  *    permission, please contact apache@apache.org.
32  *
33  * 5. Products derived from this software may not be called "Apache",
34  *    nor may "Apache" appear in their name, without prior written
35  *    permission of the Apache Software Foundation.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals on behalf of the Apache Software Foundation.  For more
53  * information on the Apache Software Foundation, please see
54  * <http://www.apache.org/>.
55  *
56  * Portions of this software are based upon public domain software
57  * originally written at the National Center for Supercomputing Applications,
58  * University of Illinois, Urbana-Champaign.
59  */
60 
61 /*
62  * util_uri.h: External Interface of util_uri.c
63  */
64 
65 #ifndef UTIL_URI_H
66 #define UTIL_URI_H
67 
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 
72 typedef struct {
73 	const char *name;
74 	unsigned short default_port;
75 } schemes_t;
76 
77 #define	DEFAULT_FTP_DATA_PORT	20
78 #define	DEFAULT_FTP_PORT	21
79 #define	DEFAULT_GOPHER_PORT	70
80 #define	DEFAULT_NNTP_PORT	119
81 #define	DEFAULT_WAIS_PORT	210
82 #define	DEFAULT_SNEWS_PORT	563
83 #define	DEFAULT_PROSPERO_PORT	1525	/* WARNING: conflict w/Oracle */
84 
85 #define DEFAULT_URI_SCHEME "http"
86 
87 /* Flags passed to unparse_uri_components(): */
88 
89 /* suppress "scheme://user@site:port" */
90 #define UNP_OMITSITEPART	(1U<<0)
91 /* Just omit user */
92 #define	UNP_OMITUSER		(1U<<1)
93 /* Just omit password */
94 #define	UNP_OMITPASSWORD	(1U<<2)
95 /* omit "user:password@" part */
96 #define	UNP_OMITUSERINFO	(UNP_OMITUSER|UNP_OMITPASSWORD)
97 /* Show plain text password (default: show XXXXXXXX) */
98 #define	UNP_REVEALPASSWORD	(1U<<3)
99 /* Show "scheme://user@site:port" only */
100 #define UNP_OMITPATHINFO	(1U<<4)
101 /* Omit the "?queryarg" from the path */
102 #define UNP_OMITQUERY	        (1U<<5)
103 
104 typedef struct {
105 	char *scheme;		/* scheme ("http"/"ftp"/...) */
106 	char *hostinfo;             /* combined [user[:password]@]host[:port] */
107 	char *user;	/* user name, as in http://user:passwd@host:port/ */
108 	char *password;	/* password, as in http://user:passwd@host:port/ */
109 	char *hostname;	/* hostname from URI (or from Host: header) */
110 	char *port_str;	/* port string (integer representation is in "port") */
111 	char *path;/* request path (or "/" if only scheme://host was given)*/
112 	char *query;	/* Everything after a '?' in the path, if present */
113 	char *fragment;		/* Trailing "#fragment" string, if present */
114 
115 	struct hostent *hostent;
116 
117 	unsigned short port;	/* The port number, numeric, valid only if
118 				 * port_str != NULL
119 				 */
120 
121 	unsigned is_initialized:1;
122 
123 	unsigned dns_looked_up:1;
124 	unsigned dns_resolved:1;
125 
126 } uri_components;
127 
128 /* util_uri.c */
129 API_EXPORT(unsigned short) ap_default_port_for_scheme(const char *scheme_str);
130 API_EXPORT(unsigned short) ap_default_port_for_request(const request_rec *r);
131 API_EXPORT(struct hostent *) ap_pduphostent(pool *p, const struct hostent *hp);
132 API_EXPORT(struct hostent *) ap_pgethostbyname(pool *p, const char *hostname);
133 API_EXPORT(char *) ap_unparse_uri_components(pool *p,
134     const uri_components *uptr, unsigned flags);
135 API_EXPORT(int) ap_parse_uri_components(pool *p, const char *uri,
136     uri_components *uptr);
137 API_EXPORT(int) ap_parse_hostinfo_components(pool *p, const char *hostinfo,
138     uri_components *uptr);
139 /* called by the core in main() */
140 extern void ap_util_uri_init(void);
141 
142 #ifdef __cplusplus
143 }
144 #endif
145 
146 #endif /*UTIL_URI_H*/
147