xref: /onnv-gate/usr/src/common/net/wanboot/boot_http.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2002-2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef	_BOOT_HTTP_H
28*0Sstevel@tonic-gate #define	_BOOT_HTTP_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate #include <sys/types.h>
34*0Sstevel@tonic-gate #include <sys/errno.h>
35*0Sstevel@tonic-gate #include <parseURL.h>
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate #ifdef	__cplusplus
38*0Sstevel@tonic-gate extern "C" {
39*0Sstevel@tonic-gate #endif
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate /* State information returned by http_conn_info() */
42*0Sstevel@tonic-gate typedef struct {
43*0Sstevel@tonic-gate 	url_t		uri;		/* URI last loaded */
44*0Sstevel@tonic-gate 	url_hport_t	proxy;		/* proxy, if any being used */
45*0Sstevel@tonic-gate 	boolean_t	keepalive;	/* Keepalive setting being used */
46*0Sstevel@tonic-gate 	uint_t		read_timeout;	/* Timeout to use for socket reads */
47*0Sstevel@tonic-gate } http_conninfo_t;
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate /* Structure for version of the http file */
51*0Sstevel@tonic-gate typedef struct {
52*0Sstevel@tonic-gate 	uint_t	maj_ver;	/* Major version */
53*0Sstevel@tonic-gate 	uint_t	min_ver;	/* Minor version */
54*0Sstevel@tonic-gate 	uint_t	micro_ver;	/* Micro version */
55*0Sstevel@tonic-gate } boot_http_ver_t;
56*0Sstevel@tonic-gate 
57*0Sstevel@tonic-gate /* Internal Libhttp errors */
58*0Sstevel@tonic-gate #define	EHTTP_BADARG	1	/* Function called with one+ bad arguments */
59*0Sstevel@tonic-gate #define	EHTTP_NOMEM	2	/* Out of memory error detected */
60*0Sstevel@tonic-gate #define	EHTTP_CONCLOSED	3	/* The ssl connection was closed (but not */
61*0Sstevel@tonic-gate 				/* necessarily the underlying transport */
62*0Sstevel@tonic-gate 				/* connection). */
63*0Sstevel@tonic-gate #define	EHTTP_UNEXPECTED 4	/* A SSL I/O request returned an unexpected */
64*0Sstevel@tonic-gate 				/* error. */
65*0Sstevel@tonic-gate #define	EHTTP_EOFERR	5	/* Unexpected/premature EOF */
66*0Sstevel@tonic-gate #define	EHTTP_NOCERT	6	/* No certificate was persented */
67*0Sstevel@tonic-gate #define	EHTTP_NOMATCH	7	/* Peer cert doesn't match hostname or */
68*0Sstevel@tonic-gate 				/* No matching entry */
69*0Sstevel@tonic-gate #define	EHTTP_NODATA	8	/* No data was returned */
70*0Sstevel@tonic-gate #define	EHTTP_NOT_1_1	9	/* This was not a HTTP/1.1 response */
71*0Sstevel@tonic-gate #define	EHTTP_BADHDR	10	/* The header doesn't look to be valid */
72*0Sstevel@tonic-gate #define	EHTTP_OORANGE	11	/* Requests header line is out of range */
73*0Sstevel@tonic-gate #define	EHTTP_NORESP	12	/* No or partial response returned */
74*0Sstevel@tonic-gate #define	EHTTP_BADRESP	13	/* Bad response or error returned */
75*0Sstevel@tonic-gate #define	EHTTP_NOHEADER	14	/* Chunked header expected but not found */
76*0Sstevel@tonic-gate #define	EHTTP_NOBOUNDARY 15	/* Boundary line expected but not found */
77*0Sstevel@tonic-gate #define	EHTTP_NOTMULTI	16	/* This is not a multipart transfer */
78*0Sstevel@tonic-gate #define	EHTTP_BADSIZE	17	/* Could not determine msg body size */
79*0Sstevel@tonic-gate 
80*0Sstevel@tonic-gate 
81*0Sstevel@tonic-gate 
82*0Sstevel@tonic-gate /* Sources of errors */
83*0Sstevel@tonic-gate #define	ERRSRC_SYSTEM	1	/* System error occurred */
84*0Sstevel@tonic-gate #define	ERRSRC_LIBHTTP	2	/* Internal (libhttp) error */
85*0Sstevel@tonic-gate #define	ERRSRC_RESOLVE	3	/* Libresolv error */
86*0Sstevel@tonic-gate #define	ERRSRC_VERIFERR	4	/* Verify error occurred */
87*0Sstevel@tonic-gate #define	ERRSRC_LIBSSL	5	/* Libssl/libcrypto error */
88*0Sstevel@tonic-gate 
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate typedef struct {
91*0Sstevel@tonic-gate 	uint_t	code;		/* status code */
92*0Sstevel@tonic-gate 	char	*statusmsg;	/* status message */
93*0Sstevel@tonic-gate 	uint_t	nresphdrs;	/* number of response headers */
94*0Sstevel@tonic-gate } http_respinfo_t;
95*0Sstevel@tonic-gate 
96*0Sstevel@tonic-gate 
97*0Sstevel@tonic-gate typedef void *http_handle_t;
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate boot_http_ver_t const *http_get_version(void);
100*0Sstevel@tonic-gate void http_set_p12_format(int);
101*0Sstevel@tonic-gate void http_set_verbose(boolean_t);
102*0Sstevel@tonic-gate int  http_set_cipher_list(const char *);
103*0Sstevel@tonic-gate http_handle_t http_srv_init(const url_t *);
104*0Sstevel@tonic-gate int  http_set_proxy(http_handle_t, const url_hport_t *);
105*0Sstevel@tonic-gate int  http_set_keepalive(http_handle_t, boolean_t);
106*0Sstevel@tonic-gate int  http_set_socket_read_timeout(http_handle_t, uint_t);
107*0Sstevel@tonic-gate int  http_set_basic_auth(http_handle_t, const char *, const char *);
108*0Sstevel@tonic-gate int  http_set_random_file(http_handle_t, const char *);
109*0Sstevel@tonic-gate int  http_set_certificate_authority_file(const char *);
110*0Sstevel@tonic-gate int  http_set_client_certificate_file(http_handle_t, const char *);
111*0Sstevel@tonic-gate int  http_set_password(http_handle_t, const char *);
112*0Sstevel@tonic-gate int  http_set_key_file_password(http_handle_t, const char *);
113*0Sstevel@tonic-gate int  http_set_private_key_file(http_handle_t, const char *);
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate int   http_srv_connect(http_handle_t);
116*0Sstevel@tonic-gate int   http_head_request(http_handle_t, const char *);
117*0Sstevel@tonic-gate int   http_get_request(http_handle_t, const char *);
118*0Sstevel@tonic-gate int   http_get_range_request(http_handle_t, const char *, off_t, size_t);
119*0Sstevel@tonic-gate void  http_free_respinfo(http_respinfo_t *);
120*0Sstevel@tonic-gate int   http_process_headers(http_handle_t, http_respinfo_t **);
121*0Sstevel@tonic-gate int   http_process_part_headers(http_handle_t, http_respinfo_t **);
122*0Sstevel@tonic-gate char *http_get_header_value(http_handle_t, const char *);
123*0Sstevel@tonic-gate char *http_get_response_header(http_handle_t, uint_t);
124*0Sstevel@tonic-gate int   http_read_body(http_handle_t, char *, size_t);
125*0Sstevel@tonic-gate int   http_srv_disconnect(http_handle_t);
126*0Sstevel@tonic-gate int   http_srv_close(http_handle_t);
127*0Sstevel@tonic-gate http_conninfo_t *http_get_conn_info(http_handle_t);
128*0Sstevel@tonic-gate int   http_conn_is_https(http_handle_t, boolean_t *);
129*0Sstevel@tonic-gate ulong_t http_get_lasterr(http_handle_t, uint_t *);
130*0Sstevel@tonic-gate void http_decode_err(ulong_t, int *, int *, int *);
131*0Sstevel@tonic-gate char const *http_errorstr(uint_t, ulong_t);
132*0Sstevel@tonic-gate 
133*0Sstevel@tonic-gate #ifdef	__cplusplus
134*0Sstevel@tonic-gate }
135*0Sstevel@tonic-gate #endif
136*0Sstevel@tonic-gate 
137*0Sstevel@tonic-gate #endif	/* _BOOT_HTTP_H */
138