2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-08-09 22:01:28 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2005-08-09 22:01:28 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2005-08-09 22:01:28 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-08-09 22:01:28 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2005-08-09 22:01:28 +00:00
|
|
|
|
|
|
|
// HTTP_OP represents an HTTP operation.
|
|
|
|
// There are variants for GET and POST,
|
|
|
|
// and for the data source/sink (see below).
|
|
|
|
|
2006-06-28 17:46:37 +00:00
|
|
|
// We use libcurl: http://curl.haxx.se/libcurl
|
2005-08-09 22:01:28 +00:00
|
|
|
|
2017-04-08 06:54:49 +00:00
|
|
|
#ifndef BOINC_HTTP_CURL_H
|
|
|
|
#define BOINC_HTTP_CURL_H
|
2005-08-09 22:01:28 +00:00
|
|
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
2006-06-28 16:56:15 +00:00
|
|
|
#include "network.h"
|
2005-08-09 22:01:28 +00:00
|
|
|
#include "proxy_info.h"
|
2006-06-28 16:56:15 +00:00
|
|
|
|
|
|
|
extern int curl_init();
|
|
|
|
extern int curl_cleanup();
|
2005-08-09 22:01:28 +00:00
|
|
|
|
|
|
|
#define HTTP_OP_NONE 0
|
|
|
|
#define HTTP_OP_GET 1
|
|
|
|
// data sink is a file (used for file download)
|
|
|
|
#define HTTP_OP_POST 2
|
|
|
|
// data source and sink are files (used for scheduler op)
|
|
|
|
#define HTTP_OP_POST2 5
|
|
|
|
// a POST operation where the request comes from a combination
|
|
|
|
// of a string and a file w/offset,
|
|
|
|
// and the reply goes into a memory buffer.
|
|
|
|
// Used for file upload
|
|
|
|
|
2006-06-28 16:56:15 +00:00
|
|
|
#define HTTP_STATE_IDLE 0
|
|
|
|
#define HTTP_STATE_CONNECTING 1
|
2006-06-28 17:46:37 +00:00
|
|
|
#define HTTP_STATE_DONE 2
|
2006-06-28 16:56:15 +00:00
|
|
|
|
2011-10-18 04:23:03 +00:00
|
|
|
struct PROJECT;
|
|
|
|
|
2006-06-28 16:56:15 +00:00
|
|
|
class HTTP_OP {
|
2005-08-09 22:01:28 +00:00
|
|
|
public:
|
|
|
|
HTTP_OP();
|
|
|
|
~HTTP_OP();
|
|
|
|
|
|
|
|
PROXY_INFO pi;
|
2011-10-18 04:23:03 +00:00
|
|
|
PROJECT* project; // associated project, if any
|
2005-08-09 22:01:28 +00:00
|
|
|
|
2014-03-14 07:21:15 +00:00
|
|
|
char m_url[1024];
|
2019-11-06 07:25:06 +00:00
|
|
|
char m_curl_user_credentials[1024];
|
2010-04-01 05:54:29 +00:00
|
|
|
// string needed for proxy username/password
|
2005-08-09 22:01:28 +00:00
|
|
|
|
|
|
|
int content_length;
|
2009-11-25 20:45:36 +00:00
|
|
|
unsigned int trace_id;
|
2005-08-09 22:01:28 +00:00
|
|
|
char request_header[4096];
|
|
|
|
|
2006-06-28 16:56:15 +00:00
|
|
|
FILE* fileIn;
|
2013-04-03 00:23:37 +00:00
|
|
|
FILE* fileOut;
|
2012-11-30 04:45:00 +00:00
|
|
|
// output file for POST responses
|
2013-04-03 00:23:37 +00:00
|
|
|
CURL* curlEasy;
|
2010-04-01 05:54:29 +00:00
|
|
|
// the "easy curl" handle for this net_xfer request
|
2013-04-03 00:23:37 +00:00
|
|
|
struct curl_slist *pcurlList;
|
2010-04-01 05:54:29 +00:00
|
|
|
// curl slist for http headers
|
2013-04-03 00:23:37 +00:00
|
|
|
struct curl_httppost *pcurlFormStart;
|
2010-04-01 05:54:29 +00:00
|
|
|
// a pointer to a form item for POST
|
2013-04-03 00:23:37 +00:00
|
|
|
struct curl_httppost *pcurlFormEnd;
|
2010-04-01 05:54:29 +00:00
|
|
|
// a pointer to a form item for POST
|
2013-04-03 00:23:37 +00:00
|
|
|
unsigned char* pByte;
|
2010-04-01 05:54:29 +00:00
|
|
|
// pointer to bytes for reading via libcurl_read function
|
2008-10-04 23:44:24 +00:00
|
|
|
|
2011-09-20 18:49:38 +00:00
|
|
|
// request message stuff
|
|
|
|
//
|
|
|
|
char* req1;
|
|
|
|
// if not NULL, send this string first
|
2006-06-28 21:44:42 +00:00
|
|
|
char infile[256];
|
2011-09-20 18:49:38 +00:00
|
|
|
// then (is nonempty) this file
|
|
|
|
double file_offset;
|
|
|
|
// starting at this offset
|
|
|
|
|
|
|
|
// reply message stuff
|
|
|
|
//
|
|
|
|
// reply is always written to a file
|
2006-06-28 21:44:42 +00:00
|
|
|
char outfile[256];
|
2011-09-20 18:49:38 +00:00
|
|
|
// if specified, it's written to this file w/ optional offset
|
|
|
|
// otherwise it's written to a temp file
|
|
|
|
// if type POST2, copy output to req1 buffer
|
|
|
|
int req1_len;
|
|
|
|
// with this limit
|
|
|
|
|
2013-04-03 00:23:37 +00:00
|
|
|
long lSeek;
|
2011-09-20 18:49:38 +00:00
|
|
|
// offset within the file or memory buffer we're reading,
|
2008-10-04 23:44:24 +00:00
|
|
|
char error_msg[256];
|
2010-04-01 05:54:29 +00:00
|
|
|
// put Curl error message here
|
2013-04-03 00:23:37 +00:00
|
|
|
bool bTempOutfile;
|
2010-04-01 05:54:29 +00:00
|
|
|
// CMC -- flag that outfile is really a tempfile we should delete
|
2013-04-03 00:23:37 +00:00
|
|
|
bool bSentHeader;
|
2010-04-01 05:54:29 +00:00
|
|
|
// CMC -- a flag that I already sent the header
|
2013-04-03 00:23:37 +00:00
|
|
|
CURLcode CurlResult;
|
2010-04-01 05:54:29 +00:00
|
|
|
// CMC -- send up curl result code
|
2006-06-28 16:56:15 +00:00
|
|
|
|
|
|
|
bool want_download; // at most one should be true
|
|
|
|
bool want_upload;
|
2008-10-04 23:44:24 +00:00
|
|
|
long connect_error;
|
2010-04-01 05:54:29 +00:00
|
|
|
// errno from connect() (not used for anything)
|
2013-04-03 00:23:37 +00:00
|
|
|
long response;
|
2010-04-01 05:54:29 +00:00
|
|
|
// HTTP status code from server
|
|
|
|
// the above two MUST be long (not int)
|
|
|
|
// otherwise breaks on 64-bit machines
|
2006-06-28 16:56:15 +00:00
|
|
|
double start_time;
|
2007-08-17 18:05:39 +00:00
|
|
|
double bytes_xferred;
|
2010-04-01 05:54:29 +00:00
|
|
|
// Uncompressed bytes transferred.
|
|
|
|
// In the case of "post2" this includes only the file part
|
|
|
|
// In the case of restartable ops (file upload/download)
|
|
|
|
// this includes previous count (i.e. file offset)
|
2013-04-03 00:23:37 +00:00
|
|
|
double start_bytes_xferred;
|
2010-04-01 05:54:29 +00:00
|
|
|
// bytes_xferred at the start of this operation;
|
|
|
|
// used to compute transfer speed
|
2007-08-17 18:05:39 +00:00
|
|
|
double xfer_speed;
|
2010-04-01 05:54:29 +00:00
|
|
|
// tranfer rate based on elapsed time and bytes_xferred
|
|
|
|
// (hence doesn't reflect compression; used only for GUI)
|
2013-04-03 00:23:37 +00:00
|
|
|
int http_op_state; // values above
|
2008-10-04 23:44:24 +00:00
|
|
|
int http_op_type;
|
2010-04-01 05:54:29 +00:00
|
|
|
// HTTP_OP_* (see above)
|
2006-06-28 16:56:15 +00:00
|
|
|
int http_op_retval;
|
2010-04-01 05:54:29 +00:00
|
|
|
// Either:
|
|
|
|
// 0
|
|
|
|
// ERR_GETHOSTBYNAME (if no such host)
|
|
|
|
// ERR_CONNECT (if server down)
|
2012-02-07 07:58:08 +00:00
|
|
|
// ERR_HTTP_PERMANENT (if 404 or 416)
|
|
|
|
// ERR_HTTP_TRANSIENT (other failures)
|
2010-07-22 19:13:36 +00:00
|
|
|
bool is_background;
|
|
|
|
// this operation shouldn't trigger a reference-site check
|
|
|
|
// and a user alert if it fails.
|
|
|
|
// For example: notice RSS feed fetches
|
2006-06-28 16:56:15 +00:00
|
|
|
|
|
|
|
void reset();
|
2011-10-18 04:23:03 +00:00
|
|
|
void init(PROJECT*);
|
2006-06-28 16:56:15 +00:00
|
|
|
int get_ip_addr(int &ip_addr);
|
|
|
|
void close_socket();
|
|
|
|
void close_file();
|
|
|
|
void update_speed();
|
2006-10-02 16:13:08 +00:00
|
|
|
void set_speed_limit(bool is_upload, double bytes_sec);
|
2008-08-03 22:36:41 +00:00
|
|
|
void handle_messages(CURLMsg*);
|
2006-06-28 16:56:15 +00:00
|
|
|
|
2013-04-03 00:23:37 +00:00
|
|
|
//int init_head(const char* url);
|
2011-10-18 04:23:03 +00:00
|
|
|
int init_get(
|
|
|
|
PROJECT*, const char* url, const char* outfile,
|
2012-11-30 04:45:00 +00:00
|
|
|
bool del_old_file, double offset, double size
|
2011-10-18 04:23:03 +00:00
|
|
|
);
|
|
|
|
int init_post(
|
|
|
|
PROJECT*, const char* url, const char* infile, const char* outfile
|
|
|
|
);
|
2005-08-09 22:01:28 +00:00
|
|
|
int init_post2(
|
2011-10-18 04:23:03 +00:00
|
|
|
PROJECT*,
|
2005-08-09 22:01:28 +00:00
|
|
|
const char* url,
|
|
|
|
char* req1, // first part of request. ALSO USED FOR REPLY
|
2008-08-03 22:36:41 +00:00
|
|
|
int req1_len,
|
2005-08-09 22:01:28 +00:00
|
|
|
const char* infile, double offset // infile is NULL if no file sent
|
|
|
|
);
|
|
|
|
bool http_op_done();
|
2013-04-03 00:23:37 +00:00
|
|
|
void setup_proxy_session(bool no_proxy);
|
|
|
|
bool no_proxy_for_url(const char* url);
|
|
|
|
bool is_active() {
|
|
|
|
return curlEasy!=NULL;
|
|
|
|
}
|
2005-08-09 22:01:28 +00:00
|
|
|
|
|
|
|
private:
|
2013-04-03 00:23:37 +00:00
|
|
|
// take an init_get/post/post2 and turns it into a libcurl request
|
2010-04-01 05:54:29 +00:00
|
|
|
//
|
2013-04-03 00:23:37 +00:00
|
|
|
int libcurl_exec(const char* url, const char* in, const char* out,
|
|
|
|
double offset, double size, bool is_post
|
2006-02-25 00:02:55 +00:00
|
|
|
);
|
2005-08-09 22:01:28 +00:00
|
|
|
};
|
|
|
|
|
2010-04-01 05:54:29 +00:00
|
|
|
// represents a set of HTTP requests in progress
|
2008-10-04 23:44:24 +00:00
|
|
|
|
2005-08-09 22:01:28 +00:00
|
|
|
class HTTP_OP_SET {
|
|
|
|
std::vector<HTTP_OP*> http_ops;
|
|
|
|
public:
|
2006-06-28 16:56:15 +00:00
|
|
|
HTTP_OP_SET();
|
2009-02-10 19:30:59 +00:00
|
|
|
void insert(HTTP_OP*);
|
2005-08-09 22:01:28 +00:00
|
|
|
int remove(HTTP_OP*);
|
|
|
|
int nops();
|
|
|
|
|
2006-06-28 16:56:15 +00:00
|
|
|
double bytes_up, bytes_down;
|
2010-04-01 05:54:29 +00:00
|
|
|
// total bytes transferred
|
2006-06-28 16:56:15 +00:00
|
|
|
|
2013-04-03 00:23:37 +00:00
|
|
|
void get_fdset(FDSET_GROUP&);
|
2006-06-28 16:56:15 +00:00
|
|
|
void got_select(FDSET_GROUP&, double);
|
2008-10-04 23:44:24 +00:00
|
|
|
HTTP_OP* lookup_curl(CURL* pcurl);
|
2010-04-01 05:54:29 +00:00
|
|
|
// lookup by easycurl handle
|
2007-04-11 21:49:57 +00:00
|
|
|
void cleanup_temp_files();
|
2006-06-28 16:56:15 +00:00
|
|
|
|
|
|
|
};
|
2005-08-09 22:01:28 +00:00
|
|
|
|
2017-04-08 06:54:49 +00:00
|
|
|
#endif // BOINC_HTTP_CURL_H
|