xref: /netbsd-src/sys/arch/hpc/stand/hpcboot/file_http.h (revision 3b01aba77a7a698587faaae455bbfe740923c1f5)
1 /* -*-C++-*-	$NetBSD: file_http.h,v 1.1 2001/02/09 18:34:38 uch Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by UCHIYAMA Yasushi.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #ifndef _HPCBOOT_FILE_HTTP_H_
40 #define _HPCBOOT_FILE_HTTP_H_
41 
42 #include <file.h>
43 #include <winsock.h>
44 
45 class Socket {
46 private:
47 	struct sockaddr_in &_sockaddr;
48 	SOCKET _socket;
49 public:
50 	explicit Socket(struct sockaddr_in &);
51 	operator SOCKET() const { return _socket; }
52 	virtual ~Socket(void);
53 };
54 
55 class HttpFile : public File {
56 public:
57 	enum ops {
58 		FILE_CACHE	= 0x00000001,
59 		USE_PROXY	= 0x00000002		// XXX not yet.
60 	};
61 
62 private:
63 	// IP Socket
64 	struct WSAData _winsock;
65 	struct sockaddr_in _sockaddr;
66 
67 	enum { TMP_BUFFER_SIZE = 256 };
68 
69 	char _server_name[MAX_PATH];
70 
71 	// HTTP request
72 	char _request[MAX_PATH];
73 	const char *_req_get;
74 	const char *_req_head;
75 	const char *_req_host;
76 	const char *_req_ua;
77 
78 	void _set_request(void);
79 
80 	// HTTP header.
81 	size_t _header_size;
82 	size_t _parse_header(size_t &);
83 
84 	// File buffer.
85 	BOOL _memory_cache;
86 	BOOL _cached;
87 	char *_buffer;
88 	size_t _buffer_size;
89 	size_t _read_from_cache(void *, size_t, off_t);
90 	size_t _recv_buffer(SOCKET, char *, size_t);
91 	void _reset_state(void);
92 	off_t _cur_pos;
93 
94 public:
95 	HttpFile::HttpFile(Console *&);
96 	virtual ~HttpFile(void);
97 
98 	BOOL setRoot(TCHAR *);
99 	BOOL open(const TCHAR *, u_int32_t);
100 	size_t size(void) { size_t hsz; return _parse_header(hsz); }
101 	BOOL close(void) { return TRUE; }
102 	size_t read(void *, size_t, off_t = -1);
103 	size_t write(const void *, size_t, off_t = -1) { return 0; }
104 	BOOL seek(off_t);
105 
106 };
107 
108 #endif //_HPCBOOT_FILE_HTTP_H_
109