00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file HttpCharStream.h 00006 * 00007 * $Id: HttpCharStream.h 80826 2008-03-04 14:51:23Z wotte $ 00008 * 00009 * @author Krishnakumar B <kitty@cs.wustl.edu> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef _ACEXML_HTTPCHARSTREAM_H_ 00014 #define _ACEXML_HTTPCHARSTREAM_H_ 00015 00016 #include /**/ "ace/pre.h" 00017 #include "ACEXML/common/ACEXML_Export.h" 00018 00019 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00020 #pragma once 00021 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00022 00023 #include "ACEXML/common/CharStream.h" 00024 #include "ACEXML/common/URL_Addr.h" 00025 #include "ACEXML/common/Mem_Map_Stream.h" 00026 00027 /** 00028 * @class ACEXML_HttpCharStream HttpCharStream.h "ACEXML/common/HttpCharStream.h" 00029 * 00030 * An implementation of ACEXML_CharStream for reading input from a URL. 00031 */ 00032 class ACEXML_Export ACEXML_HttpCharStream : public ACEXML_CharStream 00033 { 00034 public: 00035 /// Default constructor. 00036 ACEXML_HttpCharStream (void); 00037 00038 /// Destructor 00039 virtual ~ACEXML_HttpCharStream (void); 00040 00041 /// Open an URL. 00042 int open (const ACEXML_Char *url); 00043 00044 /** 00045 * Returns the available ACEXML_Char in the buffer. -1 00046 * if the object is not initialized properly. 00047 */ 00048 virtual int available (void); 00049 00050 /** 00051 * Close this stream and release all resources used by it. 00052 */ 00053 virtual int close (void); 00054 00055 /** 00056 * Read the next ACEXML_Char. Return -1 if we are not able to 00057 * return an ACEXML_Char, 0 if EOS is reached, or 1 if succeed. 00058 */ 00059 virtual int get (ACEXML_Char& ch); 00060 00061 /** 00062 * Read the next batch of ACEXML_Char strings 00063 */ 00064 virtual int read (ACEXML_Char *str, size_t len); 00065 00066 /** 00067 * Peek the next ACEXML_Char in the CharStream. Return the 00068 * character if succeess, -1 if EOS is reached. 00069 */ 00070 virtual int peek (void); 00071 00072 /** 00073 * Resets the file pointer to the beginning of the stream. 00074 */ 00075 virtual void rewind (void); 00076 00077 /** 00078 * Determine the encoding of the file. 00079 */ 00080 virtual int determine_encoding (void); 00081 00082 /** 00083 * Get the encoding of the file 00084 */ 00085 virtual const ACEXML_Char* getEncoding (void); 00086 00087 /* 00088 * Get the systemId for the underlying CharStream 00089 */ 00090 virtual const ACEXML_Char* getSystemId (void); 00091 00092 00093 private: 00094 00095 #if defined (ACE_USES_WCHAR) 00096 /** 00097 * Read the next character from the stream taking into account the 00098 * encoding of the file. 00099 */ 00100 int get_i (ACEXML_Char& ch); 00101 00102 /** 00103 * Read the next character from the stream taking into account the 00104 * encoding of the file. Subsequent call to get() returns this 00105 * character. 00106 */ 00107 int peek_i (void); 00108 00109 #endif /* ACE_USES_WCHAR */ 00110 00111 /** 00112 * Send a HTTP/1.1 request to fetch the contents of the URL. 00113 */ 00114 int send_request (void); 00115 00116 /** 00117 * Fetch the URL and save it in backing store. 00118 */ 00119 int get_url (size_t& len); 00120 00121 ACEXML_Char *url_; 00122 00123 ACEXML_URL_Addr* url_addr_; 00124 00125 ACEXML_Mem_Map_Stream* stream_; 00126 00127 Connector* connector_; 00128 00129 ACE_OFF_T size_; 00130 00131 ACE_OFF_T data_offset_; 00132 00133 ACEXML_Char* encoding_; 00134 00135 }; 00136 00137 00138 #include /**/ "ace/post.h" 00139 00140 #endif /* _ACEXML_HTTPCHARSTREAM_H_ */