HTTP fix and code cleanup

svn path=/trunk/boinc/; revision=9551
This commit is contained in:
David Anderson 2006-02-25 00:02:55 +00:00
parent 05eef8e120
commit 79bedb43ec
6 changed files with 35 additions and 112 deletions

View File

@ -2319,3 +2319,24 @@ Rom 23 Feb 2006
Rom 24 Feb 2006 (HEAD)
- Tag for 5.3.21 release, all platforms
boinc_core_release_5_3_21
David 24 Feb 2006
- remove "gzip" from list of encodings accepted by Curl;
having it in the list breaks existing projects
that use .gz files and decompress them in the app
(e.g. Einstein and CPDN).
We can fix this by adding a <gzip/> element in <file_info>;
I'll do this later.
- Remove old HTTP code and data that's deprecated by Curl
(e.g. timeout, blocksize stuff; stuff related
to parsing URL into host/port/file/)
remove commented-out code.
- GUI RPC: a <file_xfer> elements now includes
a <url> rather than a <hostname>.
This change doesn't affect the BOINC Manager,
which I believe is the only client of this RPC
client/
http_curl.C,h
net_xfer_curl.C,h
pers_file_xfer.C

View File

@ -135,9 +135,7 @@ void get_user_agent_string() {
}
HTTP_OP::HTTP_OP() {
strcpy(m_url, ""); // CMC added this to "preserve" the url for libcurl
strcpy(url_hostname, "");
strcpy(filename, "");
strcpy(m_url, "");
content_length = 0;
file_offset = 0;
strcpy(request_header, "");
@ -161,9 +159,7 @@ int HTTP_OP::init_get(
}
req1 = NULL; // not using req1, but init_post2 uses it
file_offset = off;
safe_strcpy(m_url, url);
parse_url(url, url_hostname, port, filename);
NET_XFER::init(url_hostname, port, HTTP_BLOCKSIZE);
NET_XFER::init();
// usually have an outfile on a get
if (off != 0) {
bytes_xferred = off;
@ -184,9 +180,6 @@ int HTTP_OP::init_post(
SCOPE_MSG_LOG scope_messages(log_messages, CLIENT_MSG_LOG::DEBUG_HTTP);
req1 = NULL; // not using req1, but init_post2 uses it
strcpy(m_url, url);
parse_url(url, url_hostname, port, filename);
if (in) {
// we should pretty much always have an in file for _post, optional in _post2
strcpy(infile, in);
@ -194,8 +187,7 @@ int HTTP_OP::init_post(
if (retval) return retval; // this will return 0 or ERR_NOT_FOUND
content_length = (int)size;
}
//PROXY::init(url_hostname, port);
NET_XFER::init(url_hostname,port, HTTP_BLOCKSIZE);
NET_XFER::init();
http_op_type = HTTP_OP_POST;
http_op_state = HTTP_STATE_CONNECTING;
scope_messages.printf("HTTP_OP::init_post(): %p io_done %d\n", this, io_done);
@ -206,14 +198,14 @@ int HTTP_OP::init_post(
// polling at the net_xfer level
//
int HTTP_OP::libcurl_exec(
const char* , const char* in, const char* out, double offset, bool bPost
const char* url, const char* in, const char* out, double offset, bool bPost
) {
CURLMcode curlMErr;
CURLcode curlErr;
//char proxy_buf[256];
char strTmp[128];
// get user agent string
safe_strcpy(m_url, url);
if (g_user_agent_string[0] == 0x00) {
get_user_agent_string();
}
@ -296,33 +288,6 @@ The checking this option controls is of the identity that the server claims. The
// set the user agent as this boinc client & version
curlErr = curl_easy_setopt(curlEasy, CURLOPT_USERAGENT, g_user_agent_string);
// note: custom headers here means EVERYTHING needs to be set here,
// including form content types. Probably best just to set the user agent above
// and let libcurl handle the headers.
// create custom header for BOINC
#if 0
pcurlList = curl_slist_append(pcurlList, "Pragma: no-cache");
pcurlList = curl_slist_append(pcurlList, "Cache-Control: no-cache");
pcurlList = curl_slist_append(pcurlList, g_user_agent_string);
//sprintf(strTmp, "Host: %s:%d", url_hostname, port);
//pcurlList = curl_slist_append(pcurlList, strTmp);
if (offset>0.0f) {
file_offset = offset;
sprintf(strTmp, "Range: bytes=%.0f-", offset);
pcurlList = curl_slist_append(pcurlList, strTmp);
}
pcurlList = curl_slist_append(pcurlList, "Connection: close");
pcurlList = curl_slist_append(pcurlList, "Accept: *\/*");
// "Proxy-Authorization: Basic %s\015\012"
if (pcurlList) { // send custom headers if required
curlErr = curl_easy_setopt(curlEasy, CURLOPT_HTTPHEADER, pcurlList);
}
#endif
// bypass any signal handlers that curl may want to install
curlErr = curl_easy_setopt(curlEasy, CURLOPT_NOSIGNAL, 1L);
// bypass progress meter
@ -339,7 +304,7 @@ The checking this option controls is of the identity that the server claims. The
curlErr = curl_easy_setopt(curlEasy, CURLOPT_MAXREDIRS, 5L);
curlErr = curl_easy_setopt(curlEasy, CURLOPT_AUTOREFERER, 1L);
curlErr = curl_easy_setopt(curlEasy, CURLOPT_FOLLOWLOCATION, 1L);
curlErr = curl_easy_setopt(curlEasy, CURLOPT_ENCODING, "");
curlErr = curl_easy_setopt(curlEasy, CURLOPT_ENCODING, "deflate");
// setup any proxy they may need
setupProxyCurl();
@ -477,11 +442,7 @@ int HTTP_OP::init_post2(
double size;
//char proxy_buf[256];
strcpy(m_url, url);
parse_url(url, url_hostname, port, filename);
//PROXY::init(url_hostname, port);
//NET_XFER::init(get_proxy_server_name(url_hostname),get_proxy_port(port), HTTP_BLOCKSIZE);
NET_XFER::init(url_hostname,port, HTTP_BLOCKSIZE);
NET_XFER::init();
req1 = r1;
if (in) {
safe_strcpy(infile, in);

View File

@ -69,32 +69,14 @@ public:
HTTP_OP();
~HTTP_OP();
// proxy info
PROXY_INFO pi;
int port;
char filename[256];
char url_hostname[256];
// CMC added this to "preserve" the url for libcurl use,
// as we don't really need to do all the parsing stuff
char m_url[256];
char szCurlProxyUserPwd[128]; // string needed for proxy username/password
// the hostname part of the URL.
// May not be the host we connect to (if using proxy)
int content_length;
double file_offset;
char request_header[4096];
//HTTP_REPLY_HEADER hrh;
// move these to net_xfer
/*
int http_op_state; // values below
int http_op_type;
int http_op_retval;
*/
// zero if success, or a BOINC error code, or an HTTP status code
//// bool proxy_auth_done;
//int init_head(const char* url);
int init_get(const char* url, const char* outfile, bool del_old_file, double offset=0);
@ -112,8 +94,8 @@ private:
// internal use in the class -- takes an init_get/post/post2 and turns it into
// an appropriate libcurl request
int libcurl_exec(const char* url, const char* in = NULL, const char* out = NULL,
double offset = 0.0f, bool bPost = true);
double offset = 0.0f, bool bPost = true
);
};
// global function used by libcurl to write http replies to disk

View File

@ -157,33 +157,9 @@ void NET_XFER::close_file() {
}
}
void NET_XFER::init(char* host, int p, int b) {
void NET_XFER::init() {
reset();
safe_strcpy(hostname, host);
port = p;
blocksize = (b > MAX_BLOCKSIZE ? MAX_BLOCKSIZE : b);
start_time = gstate.now;
reset_timeout();
}
bool NET_XFER::check_timeout(bool time_passed) {
if (seconds_until_timeout == 0) {
io_done = true;
error = ERR_TIMEOUT;
return true;
}
if (time_passed) {
seconds_until_timeout--;
}
return false;
}
void NET_XFER::reset_timeout() {
seconds_until_timeout = NET_XFER_TIMEOUT;
}
char* NET_XFER::get_hostname() {
return hostname;
}
NET_XFER_SET::NET_XFER_SET() {

View File

@ -39,8 +39,6 @@ extern CURLM* g_curlMulti; // the global libcurl multi handle
// The following classes implement polling (non-blocking) I/O
// between a disk file (or memory block) and a socket
#define MAX_BLOCKSIZE 16384
// global functions for starting & stopping libcurl
extern int curl_init();
extern int curl_cleanup();
@ -74,8 +72,6 @@ public:
bool bSentHeader; // CMC -- a flag that I already sent the header
CURLcode CurlResult; // CMC -- send up curl result code
// int socket; // CMC -- deprecated, net_xfer's via curlEasy handle above
char hostname[256]; // The host we're connecting to (possibly a proxy)
bool is_connected;
bool want_download; // at most one should be true
bool want_upload;
@ -97,13 +93,10 @@ public:
// (used if !do_file_io)
long error;
long response;
int port;
int blocksize;
double start_time;
double xfer_speed;
double bytes_xferred; // bytes transferred in this session
double content_length;
int seconds_until_timeout;
// CMC - moved from http_op
int http_op_state; // values below
@ -113,17 +106,12 @@ public:
NET_XFER();
~NET_XFER();
void reset();
void init(char* host, int port, int blocksize);
void init();
int get_ip_addr(int &ip_addr);
//int open_server();
void close_socket();
void close_file();
// int do_xfer(int&); // CMC not needed for libcurl
void update_speed();
void got_error();
char* get_hostname();
bool check_timeout(bool);
void reset_timeout();
};
// bandwidth limitation is implemented at this level, as follows:
@ -147,11 +135,6 @@ public:
void get_fdset(FDSET_GROUP&);
void got_select(FDSET_GROUP&, double);
#if 0
bool poll();
int net_sleep(double);
int do_select(double& bytes_transferred, double timeout);
#endif
NET_XFER* lookup_curl(CURL* pcurl); // lookup by easycurl handle
};

View File

@ -427,12 +427,12 @@ int PERS_FILE_XFER::write(MIOFILE& fout) {
" <bytes_xferred>%f</bytes_xferred>\n"
" <file_offset>%f</file_offset>\n"
" <xfer_speed>%f</xfer_speed>\n"
" <hostname>%s</hostname>\n"
" <url>%s</url>\n"
" </file_xfer>\n",
fxp->bytes_xferred,
fxp->file_offset,
fxp->xfer_speed,
fxp->get_hostname()
fxp->m_url
);
}
return 0;