00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _terimber_miscxml_h_
00029 #define _terimber_miscxml_h_
00030
00031 #include "xml/storexml.h"
00032 #include "xml/socket.h"
00033
00034 BEGIN_TERIMBER_NAMESPACE
00035 #pragma pack(4)
00036
00039 enum xml_stream_protocol
00040 {
00041 STREAM_UNKNOWN,
00042 STREAM_LOCAL,
00043 STREAM_RELATIVE,
00044 STREAM_HTTP,
00045 STREAM_FTP,
00046 STREAM_FILE
00047 };
00048
00051 class xml_stream_attribute
00052 {
00053 public:
00055 xml_stream_attribute();
00057 xml_stream_attribute(const char* url,
00058 bool full
00059 );
00061 bool
00062 crack_xml_request(const char* url,
00063 bool full
00064 );
00066 bool
00067 complete_to_full(const xml_stream_attribute& full_url
00068 );
00070 bool
00071 combine_url( string_t& url
00072 ) const;
00074 void
00075 prepare_socket_request(string_t& url
00076 ) const;
00078 void
00079 prepare_http_request(const char* agent,
00080 string_t& url
00081 ) const;
00083 bool
00084 complete_to_full(const char* location,
00085 const char* full_path,
00086 string_t& res
00087 );
00088 private:
00090 void
00091 clear();
00092 public:
00093 xml_stream_protocol _protocol;
00094 string_t _host;
00095 ub2_t _port;
00096 string_t _user;
00097 string_t _password;
00098 string_t _path;
00099 string_t _file;
00100 string_t _extra;
00101 bool _query;
00102 };
00103
00106 class stream_input_memory : public byte_source
00107 {
00108 public:
00110 stream_input_memory(const ub1_t* buffer,
00111 size_t size,
00112 mem_pool_t& small_pool,
00113 mem_pool_t& big_pool,
00114 size_t xml_size,
00115 bool subset
00116 );
00117
00118 protected:
00120 virtual
00121 bool
00122 data_request( ub1_t* buf,
00123 size_t& len
00124 );
00125
00126 private:
00127 const ub1_t* _external_buffer;
00128 size_t _external_size;
00129 size_t _external_pos;
00130 };
00131
00135 class stream_input_common : public byte_source,
00136 public terimber_socket
00137 {
00138 public:
00140 stream_input_common(mem_pool_t& small_pool,
00141 mem_pool_t& big_pool,
00142 size_t xml_size,
00143 bool subset,
00144 size_t timeout = 10000
00145 );
00147 bool
00148 open( const xml_stream_attribute& location
00149 );
00151 void
00152 close();
00154 virtual
00155 ~stream_input_common();
00156
00157 protected:
00159 virtual
00160 bool
00161 data_request( ub1_t* buf,
00162 size_t& len
00163 );
00164 private:
00165 xml_stream_protocol _protocol;
00166 FILE* _desc;
00167 size_t _timeout;
00168 ub4_t _file_length;
00169 };
00170
00174 class memory_output_stream : public byte_consumer
00175 {
00176 public:
00178 memory_output_stream(mem_pool_t& small_pool,
00179 mem_pool_t& big_pool,
00180 size_t xml_size,
00181 ub1_t* buf,
00182 size_t buf_size
00183 );
00185 size_t
00186 get_required_size() const;
00188 bool
00189 is_overflow() const;
00190 protected:
00192 virtual
00193 bool
00194 data_persist( const ub1_t* buf,
00195 size_t len
00196 );
00197 private:
00198 ub1_t* _buf;
00199 size_t _buf_size;
00200 size_t _filled_size;
00201 size_t _required_size;
00202 };
00203
00207 class stream_output_file : public byte_consumer
00208 {
00209 public:
00211 stream_output_file(mem_pool_t& small_pool,
00212 mem_pool_t& big_pool,
00213 size_t xml_size
00214 );
00216 bool
00217 open( const char* location
00218 );
00220 void
00221 close();
00223 virtual
00224 ~stream_output_file();
00225
00226 protected:
00228 virtual
00229 bool
00230 data_persist( const ub1_t* buf,
00231 size_t len
00232 );
00233 private:
00234 FILE* _desc;
00235 };
00236
00240 class buffer_loader
00241 {
00242 public:
00246 static
00247 void
00248 load( const char* url,
00249 const char* location,
00250 mem_pool_t& small_pool,
00251 mem_pool_t& big_pool,
00252 paged_buffer& buffer,
00253 bool subset
00254 );
00255 };
00256
00257 #pragma pack()
00258 END_TERIMBER_NAMESPACE
00259
00260 #endif // _terimber_miscxml_h_