00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _HTTP_
00025 #define _HTTP_
00026
00027
00028 #define SOCKS_VERSION_4 0x04
00029 #define SOCKS_VERSION_5 0x05
00030
00031 #include <curl/curl.h>
00032
00033 #include "network.h"
00034 #include "proxy_info.h"
00035
00036 extern int curl_init();
00037 extern int curl_cleanup();
00038
00039 #define HTTP_OP_NONE 0
00040 #define HTTP_OP_GET 1
00041
00042 #define HTTP_OP_POST 2
00043
00044 #define HTTP_OP_HEAD 4
00045
00046 #define HTTP_OP_POST2 5
00047
00048
00049
00050
00051
00052 #define HTTP_STATE_IDLE 0
00053 #define HTTP_STATE_CONNECTING 1
00054 #define HTTP_STATE_DONE 2
00055
00056 class HTTP_OP {
00057 public:
00058 HTTP_OP();
00059 ~HTTP_OP();
00060
00061 PROXY_INFO pi;
00062
00063 char m_url[256];
00065 char m_curl_ca_bundle_location[256];
00067 char szCurlProxyUserPwd[128];
00068
00069 int content_length;
00070 double file_offset;
00071 int trace_id;
00072 char request_header[4096];
00073
00074 FILE* fileIn;
00076 FILE* fileOut;
00078 CURL* curlEasy;
00080 struct curl_slist *pcurlList;
00082 struct curl_httppost *pcurlFormStart;
00084 struct curl_httppost *pcurlFormEnd;
00086 unsigned char* pByte;
00087
00089 long lSeek;
00090 char infile[256];
00091 char outfile[256];
00093 char error_msg[256];
00095 bool bTempOutfile;
00096 char* req1;
00097 int req1_len;
00099 bool bSentHeader;
00101 CURLcode CurlResult;
00102
00103 bool want_download;
00104 bool want_upload;
00106 long connect_error;
00110 long response;
00111 double start_time;
00113
00117 double bytes_xferred;
00120 double start_bytes_xferred;
00123 double xfer_speed;
00124 int http_op_state;
00126 int http_op_type;
00133 int http_op_retval;
00134
00135 void reset();
00136 void init();
00137 int get_ip_addr(int &ip_addr);
00138 void close_socket();
00139 void close_file();
00140 void update_speed();
00141 void set_speed_limit(bool is_upload, double bytes_sec);
00142 void handle_messages(CURLMsg*);
00143
00144
00145 int init_get(const char* url, const char* outfile, bool del_old_file, double offset=0);
00146 int init_post(const char* url, const char* infile, const char* outfile);
00147 int init_post2(
00148 const char* url,
00149 char* req1,
00150 int req1_len,
00151 const char* infile, double offset
00152 );
00153 bool http_op_done();
00154 int set_proxy(PROXY_INFO *new_pi);
00155 void setupProxyCurl(bool no_proxy);
00156 bool no_proxy_for_url(const char* url);
00157 bool is_active() {
00158 return curlEasy!=NULL;
00159 }
00160
00161 private:
00162
00163
00164 int libcurl_exec(const char* url, const char* in, const char* out,
00165 double offset, bool bPost
00166 );
00167 };
00168
00169
00170
00171 size_t libcurl_write(void *ptr, size_t size, size_t nmemb, HTTP_OP* phop);
00172 size_t libcurl_read( void *ptr, size_t size, size_t nmemb, HTTP_OP* phop);
00173 curlioerr libcurl_ioctl(CURL *handle, curliocmd cmd, HTTP_OP* phop);
00174 int libcurl_debugfunction(CURL *handle, curl_infotype type,
00175 unsigned char *data, size_t size, HTTP_OP* phop
00176 );
00177
00179
00180 class HTTP_OP_SET {
00181 std::vector<HTTP_OP*> http_ops;
00182 public:
00183 HTTP_OP_SET();
00184 int insert(HTTP_OP*);
00185 int remove(HTTP_OP*);
00186 int nops();
00187
00189 double bytes_up, bytes_down;
00190
00191 void get_fdset(FDSET_GROUP&);
00192 void got_select(FDSET_GROUP&, double);
00194 HTTP_OP* lookup_curl(CURL* pcurl);
00195 void cleanup_temp_files();
00196
00197 };
00198
00199 extern void parse_url(const char* url, char* host, int &port, char* file);
00200
00201 #endif //__HTTP_H