xref: /openssl/doc/man3/OSSL_HTTP_parse_url.pod (revision ac91bd88)
1=pod
2
3=head1 NAME
4
5OSSL_HTTP_adapt_proxy,
6OSSL_parse_url,
7OSSL_HTTP_parse_url,
8OCSP_parse_url
9- http utility functions
10
11=head1 SYNOPSIS
12
13 #include <openssl/http.h>
14
15 const char *OSSL_HTTP_adapt_proxy(const char *proxy, const char *no_proxy,
16                                   const char *server, int use_ssl);
17
18 int OSSL_parse_url(const char *url, char **pscheme, char **puser, char **phost,
19                    char **pport, int *pport_num,
20                    char **ppath, char **pquery, char **pfrag);
21 int OSSL_HTTP_parse_url(const char *url,
22                         int *pssl, char **puser, char **phost,
23                         char **pport, int *pport_num,
24                         char **ppath, char **pquery, char **pfrag);
25
26The following functions have been deprecated since OpenSSL 3.0, and can be
27hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
28see L<openssl_user_macros(7)>:
29
30 int OCSP_parse_url(const char *url, char **phost, char **pport, char **ppath,
31                    int *pssl);
32
33=head1 DESCRIPTION
34
35OSSL_HTTP_adapt_proxy() takes an optional proxy hostname I<proxy>
36and returns it transformed according to the optional I<no_proxy> parameter,
37I<server>, I<use_ssl>, and the applicable environment variable, as follows.
38If I<proxy> is NULL, take any default value from the C<http_proxy>
39environment variable, or from C<https_proxy> if I<use_ssl> is nonzero.
40If this still does not yield a proxy hostname,
41take any further default value from the C<HTTP_PROXY>
42environment variable, or from C<HTTPS_PROXY> if I<use_ssl> is nonzero.
43If I<no_proxy> is NULL, take any default exclusion value from the C<no_proxy>
44environment variable, or else from C<NO_PROXY>.
45Return the determined proxy host unless the exclusion value,
46which is a list of proxy hosts separated by C<,> and/or whitespace,
47contains I<server>.
48Otherwise return NULL.
49When I<server> is a string delimited by C<[> and C<]>, which are used for IPv6
50addresses, the enclosing C<[> and C<]> are stripped prior to comparison.
51
52OSSL_parse_url() parses its input string I<url> as a URL of the form
53C<[scheme://][userinfo@]host[:port][/path][?query][#fragment]> and splits it up
54into scheme, userinfo, host, port, path, query, and fragment components.
55The host (or server) component may be a DNS name or an IP address
56where IPv6 addresses must be enclosed in square brackets C<[> and C<]>.
57The port component is optional and defaults to C<0>.
58If given, it must be in decimal form.  If the I<pport_num> argument is not NULL
59the integer value of the port number is assigned to I<*pport_num> on success.
60The path component is also optional and defaults to C</>.
61Each non-NULL result pointer argument I<pscheme>, I<puser>, I<phost>, I<pport>,
62I<ppath>, I<pquery>, and I<pfrag>, is assigned the respective url component.
63Any IPv6 address in I<*phost> is enclosed in C<[> and C<]>.
64On success, they are guaranteed to contain non-NULL string pointers, else NULL.
65It is the responsibility of the caller to free them using L<OPENSSL_free(3)>.
66If I<pquery> is NULL, any given query component is handled as part of the path.
67A string returned via I<*ppath> is guaranteed to begin with a C</> character.
68For absent scheme, userinfo, port, query, and fragment components
69an empty string is provided.
70
71OSSL_HTTP_parse_url() is a special form of OSSL_parse_url()
72where the scheme, if given, must be C<http> or C<https>.
73If I<pssl> is not NULL, I<*pssl> is assigned 1 in case parsing was successful
74and the scheme is C<https>, else 0.
75The port component is optional and defaults to C<443> if the scheme is C<https>,
76else C<80>.
77Note that relative paths must be given with a leading C</>,
78otherwise the first path element is interpreted as the host.
79
80Calling the deprecated function OCSP_parse_url(url, host, port, path, ssl)
81is equivalent to
82OSSL_HTTP_parse_url(url, ssl, NULL, host, port, NULL, path, NULL, NULL).
83
84=head1 RETURN VALUES
85
86OSSL_HTTP_adapt_proxy() returns NULL if no proxy is to be used,
87otherwise a constant proxy hostname string,
88which is either the proxy name handed in or an environment variable value.
89
90OSSL_parse_url(), OSSL_HTTP_parse_url(), and OCSP_parse_url()
91return 1 on success, 0 on error.
92
93=head1 SEE ALSO
94
95L<OSSL_HTTP_transfer(3)>
96
97=head1 HISTORY
98
99OSSL_HTTP_adapt_proxy(),
100OSSL_parse_url() and OSSL_HTTP_parse_url() were added in OpenSSL 3.0.
101OCSP_parse_url() was deprecated in OpenSSL 3.0.
102
103=head1 COPYRIGHT
104
105Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
106
107Licensed under the Apache License 2.0 (the "License").  You may not use
108this file except in compliance with the License.  You can obtain a copy
109in the file LICENSE in the source distribution or at
110L<https://www.openssl.org/source/license.html>.
111
112=cut
113