00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef zz_http_h
00010 #define zz_http_h
00011
00012 #include <zz_socket.h>
00013 #include <zz_mime_body.h>
00014 #include <map>
00015 #include <zz_export.h>
00016
00017 #ifdef _WIN32
00018 using namespace std;
00019 #pragma warning(disable: 4786)
00020 #endif
00021
00022
00023 typedef map<short, CzzString > CzzResponseHeaders;
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 class ZZ_API CzzHTTP
00039 {
00040 public:
00041
00042
00043
00044
00045
00046
00047
00048
00049 CzzHTTP( const char* host,
00050 const char* port,
00051 const char* user_agent,
00052 unsigned short s_timeout,
00053 unsigned short r_timeout );
00054
00055
00056 virtual ~CzzHTTP();
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 void get( const char* uri,
00067 const char* response_file
00068 );
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 void post( const char* uri,
00081 const char* query,
00082 const char* response_file
00083 );
00084
00085
00086 void post( const char* uri,
00087 CzzMIMEBody& body,
00088 const char* response_file
00089 );
00090
00091
00092
00093
00094
00095
00096
00097
00098 void head( const char* uri
00099 );
00100
00101
00102
00103
00104
00105
00106
00107
00108 void put( const char* uri,
00109 const char* data,
00110 unsigned long size
00111 );
00112
00113
00114
00115
00116
00117
00118
00119
00120 void del( const char* uri
00121 );
00122
00123
00124
00125
00126
00127 CzzResponseHeaders& getResponseHeaders( void ) { return m_ResponseHeaders; };
00128
00129
00130
00131 unsigned long getFileSize( void ) { return m_FileSize; };
00132
00133
00134
00135 long reply( void );
00136
00137 protected:
00138
00139
00140
00141 void send( void );
00142
00143
00144
00145 void parseReply( unsigned long size
00146 );
00147
00148
00149
00150 virtual void writeToFile( long from,
00151 long size
00152 );
00153
00154
00155
00156 void addRequest( const char* method,
00157 const char* uri
00158 );
00159
00160
00161
00162 void addHeader( const char* format_header,
00163 ...
00164 );
00165
00166
00167
00168 void addEntityData( const char* data,
00169 unsigned long size
00170 );
00171
00172
00173
00174 void addEndMarker( void );
00175
00176
00177 unsigned long m_FileSize;
00178 CzzBuffer* m_SendBuffer;
00179 char* m_ReplyBuffer;
00180 CzzString m_Host;
00181 CzzString m_LocalHost;
00182 CzzString m_Port;
00183 CzzString m_UserAgent;
00184 CzzString m_ResponseFile;
00185 CzzSocket* m_Socket;
00186 unsigned short m_SendTimeout;
00187 unsigned short m_RecTimeout;
00188 CzzResponseHeaders m_ResponseHeaders;
00189
00190 private:
00191
00192 CzzString copyReadFromStart( long from, long to );
00193 };
00194
00195 #endif // zz_http_h
00196