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