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