xref: /titanic_50/usr/src/common/net/wanboot/boot_http.h (revision cb4c2b01e39d41afd1414108d5f7f13ba93417fd)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23e00d7246Svh115876  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef	_BOOT_HTTP_H
287c478bd9Sstevel@tonic-gate #define	_BOOT_HTTP_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <sys/errno.h>
357c478bd9Sstevel@tonic-gate #include <parseURL.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
387c478bd9Sstevel@tonic-gate extern "C" {
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /* State information returned by http_conn_info() */
427c478bd9Sstevel@tonic-gate typedef struct {
437c478bd9Sstevel@tonic-gate 	url_t		uri;		/* URI last loaded */
447c478bd9Sstevel@tonic-gate 	url_hport_t	proxy;		/* proxy, if any being used */
457c478bd9Sstevel@tonic-gate 	boolean_t	keepalive;	/* Keepalive setting being used */
467c478bd9Sstevel@tonic-gate 	uint_t		read_timeout;	/* Timeout to use for socket reads */
477c478bd9Sstevel@tonic-gate } http_conninfo_t;
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate /* Structure for version of the http file */
517c478bd9Sstevel@tonic-gate typedef struct {
527c478bd9Sstevel@tonic-gate 	uint_t	maj_ver;	/* Major version */
537c478bd9Sstevel@tonic-gate 	uint_t	min_ver;	/* Minor version */
547c478bd9Sstevel@tonic-gate 	uint_t	micro_ver;	/* Micro version */
557c478bd9Sstevel@tonic-gate } boot_http_ver_t;
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /* Internal Libhttp errors */
587c478bd9Sstevel@tonic-gate #define	EHTTP_BADARG	1	/* Function called with one+ bad arguments */
597c478bd9Sstevel@tonic-gate #define	EHTTP_NOMEM	2	/* Out of memory error detected */
607c478bd9Sstevel@tonic-gate #define	EHTTP_CONCLOSED	3	/* The ssl connection was closed (but not */
617c478bd9Sstevel@tonic-gate 				/* necessarily the underlying transport */
627c478bd9Sstevel@tonic-gate 				/* connection). */
637c478bd9Sstevel@tonic-gate #define	EHTTP_UNEXPECTED 4	/* A SSL I/O request returned an unexpected */
647c478bd9Sstevel@tonic-gate 				/* error. */
657c478bd9Sstevel@tonic-gate #define	EHTTP_EOFERR	5	/* Unexpected/premature EOF */
667c478bd9Sstevel@tonic-gate #define	EHTTP_NOCERT	6	/* No certificate was persented */
677c478bd9Sstevel@tonic-gate #define	EHTTP_NOMATCH	7	/* Peer cert doesn't match hostname or */
687c478bd9Sstevel@tonic-gate 				/* No matching entry */
697c478bd9Sstevel@tonic-gate #define	EHTTP_NODATA	8	/* No data was returned */
707c478bd9Sstevel@tonic-gate #define	EHTTP_NOT_1_1	9	/* This was not a HTTP/1.1 response */
717c478bd9Sstevel@tonic-gate #define	EHTTP_BADHDR	10	/* The header doesn't look to be valid */
727c478bd9Sstevel@tonic-gate #define	EHTTP_OORANGE	11	/* Requests header line is out of range */
737c478bd9Sstevel@tonic-gate #define	EHTTP_NORESP	12	/* No or partial response returned */
747c478bd9Sstevel@tonic-gate #define	EHTTP_BADRESP	13	/* Bad response or error returned */
757c478bd9Sstevel@tonic-gate #define	EHTTP_NOHEADER	14	/* Chunked header expected but not found */
767c478bd9Sstevel@tonic-gate #define	EHTTP_NOBOUNDARY 15	/* Boundary line expected but not found */
777c478bd9Sstevel@tonic-gate #define	EHTTP_NOTMULTI	16	/* This is not a multipart transfer */
787c478bd9Sstevel@tonic-gate #define	EHTTP_BADSIZE	17	/* Could not determine msg body size */
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /* Sources of errors */
837c478bd9Sstevel@tonic-gate #define	ERRSRC_SYSTEM	1	/* System error occurred */
847c478bd9Sstevel@tonic-gate #define	ERRSRC_LIBHTTP	2	/* Internal (libhttp) error */
857c478bd9Sstevel@tonic-gate #define	ERRSRC_RESOLVE	3	/* Libresolv error */
867c478bd9Sstevel@tonic-gate #define	ERRSRC_VERIFERR	4	/* Verify error occurred */
877c478bd9Sstevel@tonic-gate #define	ERRSRC_LIBSSL	5	/* Libssl/libcrypto error */
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate typedef struct {
917c478bd9Sstevel@tonic-gate 	uint_t	code;		/* status code */
927c478bd9Sstevel@tonic-gate 	char	*statusmsg;	/* status message */
937c478bd9Sstevel@tonic-gate 	uint_t	nresphdrs;	/* number of response headers */
947c478bd9Sstevel@tonic-gate } http_respinfo_t;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate typedef void *http_handle_t;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate boot_http_ver_t const *http_get_version(void);
1007c478bd9Sstevel@tonic-gate void http_set_p12_format(int);
1017c478bd9Sstevel@tonic-gate void http_set_verbose(boolean_t);
1027c478bd9Sstevel@tonic-gate int  http_set_cipher_list(const char *);
1037c478bd9Sstevel@tonic-gate http_handle_t http_srv_init(const url_t *);
1047c478bd9Sstevel@tonic-gate int  http_set_proxy(http_handle_t, const url_hport_t *);
1057c478bd9Sstevel@tonic-gate int  http_set_keepalive(http_handle_t, boolean_t);
1067c478bd9Sstevel@tonic-gate int  http_set_socket_read_timeout(http_handle_t, uint_t);
1077c478bd9Sstevel@tonic-gate int  http_set_basic_auth(http_handle_t, const char *, const char *);
1087c478bd9Sstevel@tonic-gate int  http_set_random_file(http_handle_t, const char *);
1097c478bd9Sstevel@tonic-gate int  http_set_certificate_authority_file(const char *);
1107c478bd9Sstevel@tonic-gate int  http_set_client_certificate_file(http_handle_t, const char *);
1117c478bd9Sstevel@tonic-gate int  http_set_password(http_handle_t, const char *);
1127c478bd9Sstevel@tonic-gate int  http_set_key_file_password(http_handle_t, const char *);
1137c478bd9Sstevel@tonic-gate int  http_set_private_key_file(http_handle_t, const char *);
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate int   http_srv_connect(http_handle_t);
1167c478bd9Sstevel@tonic-gate int   http_head_request(http_handle_t, const char *);
1177c478bd9Sstevel@tonic-gate int   http_get_request(http_handle_t, const char *);
118*cb4c2b01Svh115876 int   http_get_range_request(http_handle_t, const char *, offset_t, offset_t);
1197c478bd9Sstevel@tonic-gate void  http_free_respinfo(http_respinfo_t *);
1207c478bd9Sstevel@tonic-gate int   http_process_headers(http_handle_t, http_respinfo_t **);
1217c478bd9Sstevel@tonic-gate int   http_process_part_headers(http_handle_t, http_respinfo_t **);
1227c478bd9Sstevel@tonic-gate char *http_get_header_value(http_handle_t, const char *);
1237c478bd9Sstevel@tonic-gate char *http_get_response_header(http_handle_t, uint_t);
1247c478bd9Sstevel@tonic-gate int   http_read_body(http_handle_t, char *, size_t);
1257c478bd9Sstevel@tonic-gate int   http_srv_disconnect(http_handle_t);
1267c478bd9Sstevel@tonic-gate int   http_srv_close(http_handle_t);
1277c478bd9Sstevel@tonic-gate http_conninfo_t *http_get_conn_info(http_handle_t);
1287c478bd9Sstevel@tonic-gate int   http_conn_is_https(http_handle_t, boolean_t *);
1297c478bd9Sstevel@tonic-gate ulong_t http_get_lasterr(http_handle_t, uint_t *);
1307c478bd9Sstevel@tonic-gate void http_decode_err(ulong_t, int *, int *, int *);
1317c478bd9Sstevel@tonic-gate char const *http_errorstr(uint_t, ulong_t);
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate #endif
1367c478bd9Sstevel@tonic-gate 
1377c478bd9Sstevel@tonic-gate #endif	/* _BOOT_HTTP_H */
138