Home | History | Annotate | Line # | Download | only in hpcboot
file_http.h revision 1.2.14.2
      1 /* -*-C++-*-	$NetBSD: file_http.h,v 1.2.14.2 2004/09/18 14:34:39 skrll Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2001, 2002 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 	// Wrapper for absorb Windows CE API difference.
     64 	int (*_wsa_startup)(WORD, LPWSADATA);
     65 	int (*_wsa_cleanup)(void);
     66 
     67 private:
     68 	// IP Socket
     69 	struct WSAData _winsock;
     70 	struct sockaddr_in _sockaddr;
     71 
     72 	enum { TMP_BUFFER_SIZE = 256 };
     73 
     74 	char _server_name[MAX_PATH];
     75 
     76 	// HTTP request
     77 	char _request[MAX_PATH];
     78 	const char *_req_get;
     79 	const char *_req_head;
     80 	const char *_req_host;
     81 	const char *_req_ua;
     82 
     83 	void _set_request(void);
     84 
     85 	// HTTP header.
     86 	size_t _header_size;
     87 	size_t _parse_header(size_t &);
     88 
     89 	// File buffer.
     90 	BOOL _memory_cache;
     91 	BOOL _cached;
     92 	char *_buffer;
     93 	size_t _buffer_size;
     94 	size_t _read_from_cache(void *, size_t, off_t);
     95 	size_t _recv_buffer(SOCKET, char *, size_t);
     96 	void _reset_state(void);
     97 	off_t _cur_pos;
     98 
     99 public:
    100 	HttpFile::HttpFile(Console *&);
    101 	virtual ~HttpFile(void);
    102 
    103 	BOOL setRoot(TCHAR *);
    104 	BOOL open(const TCHAR *, u_int32_t);
    105 	size_t size(void) { size_t hsz; return _parse_header(hsz); }
    106 	BOOL close(void) { return TRUE; }
    107 	size_t read(void *, size_t, off_t = -1);
    108 	size_t write(const void *, size_t, off_t = -1) { return 0; }
    109 	BOOL seek(off_t);
    110 
    111 };
    112 
    113 #endif //_HPCBOOT_FILE_HTTP_H_
    114