2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2003-08-22 00:15:51 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This 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 2.1 of the License, or (at your option) any later version.
|
2003-08-22 00:15:51 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// 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.
|
2002-04-30 22:22:54 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-07-05 05:33:40 +00:00
|
|
|
// HTTP_OP represents an HTTP operation.
|
2004-01-31 23:21:07 +00:00
|
|
|
// There are variants for GET and POST,
|
|
|
|
// and for the data source/sink (see below).
|
2002-07-05 05:33:40 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
#ifndef _HTTP_
|
|
|
|
#define _HTTP_
|
|
|
|
|
2004-03-27 00:45:27 +00:00
|
|
|
#include "proxy.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-08-26 22:57:17 +00:00
|
|
|
// official HTTP status codes
|
|
|
|
#define HTTP_STATUS_OK 200
|
2005-04-07 22:32:04 +00:00
|
|
|
#define HTTP_STATUS_PARTIAL_CONTENT 206
|
2002-08-26 22:57:17 +00:00
|
|
|
#define HTTP_STATUS_RANGE_REQUEST_ERROR 416
|
|
|
|
#define HTTP_STATUS_MOVED_PERM 301
|
|
|
|
#define HTTP_STATUS_MOVED_TEMP 302
|
2003-09-30 18:09:58 +00:00
|
|
|
#define HTTP_STATUS_NOT_FOUND 404
|
2004-06-13 04:47:20 +00:00
|
|
|
#define HTTP_STATUS_PROXY_AUTH_REQ 407
|
2005-06-13 08:47:51 +00:00
|
|
|
#define HTTP_STATUS_INTERNAL_SERVER_ERROR 500
|
|
|
|
#define HTTP_STATUS_SERVICE_UNAVAILABLE 503
|
2002-08-26 22:57:17 +00:00
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
struct HTTP_REPLY_HEADER {
|
2003-09-30 18:09:58 +00:00
|
|
|
int http_status;
|
2002-04-30 22:22:54 +00:00
|
|
|
int content_length;
|
2004-06-30 18:17:21 +00:00
|
|
|
std::string redirect_location;
|
|
|
|
std::string recv_buf;
|
2003-08-22 00:15:51 +00:00
|
|
|
|
2004-07-15 23:58:43 +00:00
|
|
|
HTTP_REPLY_HEADER(){}
|
|
|
|
~HTTP_REPLY_HEADER(){}
|
2003-08-22 00:15:51 +00:00
|
|
|
void init();
|
|
|
|
int read_reply(int socket);
|
|
|
|
void parse();
|
2002-04-30 22:22:54 +00:00
|
|
|
};
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
#define HTTP_OP_NONE 0
|
2002-04-30 22:22:54 +00:00
|
|
|
#define HTTP_OP_GET 1
|
2005-02-18 16:52:46 +00:00
|
|
|
// data sink is a file (used for file download)
|
2002-04-30 22:22:54 +00:00
|
|
|
#define HTTP_OP_POST 2
|
2005-02-18 16:52:46 +00:00
|
|
|
// data source and sink are files (used for scheduler op)
|
2002-06-10 06:14:18 +00:00
|
|
|
#define HTTP_OP_HEAD 4
|
2005-02-18 16:52:46 +00:00
|
|
|
// no data (used for file upload)
|
2002-07-05 05:33:40 +00:00
|
|
|
#define HTTP_OP_POST2 5
|
|
|
|
// a POST operation where the request comes from a combination
|
|
|
|
// of a string and a file w/offset,
|
2005-02-18 16:52:46 +00:00
|
|
|
// and the reply goes into a memory buffer.
|
|
|
|
// Used for file upload
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2004-03-27 00:45:27 +00:00
|
|
|
class HTTP_OP : public PROXY {
|
2002-04-30 22:22:54 +00:00
|
|
|
public:
|
|
|
|
HTTP_OP();
|
|
|
|
~HTTP_OP();
|
|
|
|
|
2002-12-09 03:07:36 +00:00
|
|
|
int port;
|
2002-04-30 22:22:54 +00:00
|
|
|
char filename[256];
|
2004-02-05 22:36:55 +00:00
|
|
|
char url_hostname[256];
|
|
|
|
// the hostname part of the URL.
|
|
|
|
// May not be the host we connect to (if using proxy)
|
2002-07-05 05:33:40 +00:00
|
|
|
char* req1;
|
2002-04-30 22:22:54 +00:00
|
|
|
char infile[256];
|
|
|
|
char outfile[256];
|
|
|
|
int content_length;
|
2002-07-05 05:33:40 +00:00
|
|
|
double file_offset;
|
2004-07-15 23:58:43 +00:00
|
|
|
char request_header[4096];
|
2002-04-30 22:22:54 +00:00
|
|
|
HTTP_REPLY_HEADER hrh;
|
|
|
|
int http_op_state; // values below
|
|
|
|
int http_op_type;
|
|
|
|
int http_op_retval;
|
2003-09-30 18:09:58 +00:00
|
|
|
// zero if success, or a BOINC error code, or an HTTP status code
|
2004-06-13 04:47:20 +00:00
|
|
|
//// bool proxy_auth_done;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-08-22 00:15:51 +00:00
|
|
|
int init_head(const char* url);
|
2005-02-16 23:17:43 +00:00
|
|
|
int init_get(const char* url, const char* outfile, bool del_old_file, double offset=0);
|
|
|
|
int init_post(const char* url, const char* infile, const char* outfile);
|
2002-07-05 05:33:40 +00:00
|
|
|
int init_post2(
|
2004-12-10 04:18:40 +00:00
|
|
|
const char* url,
|
|
|
|
char* req1, // first part of request. ALSO USED FOR REPLY
|
2005-02-16 23:17:43 +00:00
|
|
|
const char* infile, double offset // infile is NULL if no file sent
|
2002-07-05 05:33:40 +00:00
|
|
|
);
|
2002-04-30 22:22:54 +00:00
|
|
|
bool http_op_done();
|
|
|
|
};
|
|
|
|
|
|
|
|
// represents a set of HTTP requests in progress
|
|
|
|
//
|
|
|
|
class HTTP_OP_SET {
|
2005-06-23 00:15:05 +00:00
|
|
|
std::vector<HTTP_OP*> http_ops;
|
2002-04-30 22:22:54 +00:00
|
|
|
NET_XFER_SET* net_xfers;
|
|
|
|
public:
|
|
|
|
HTTP_OP_SET(NET_XFER_SET*);
|
2005-06-07 19:22:50 +00:00
|
|
|
bool poll();
|
2002-04-30 22:22:54 +00:00
|
|
|
int insert(HTTP_OP*);
|
|
|
|
int remove(HTTP_OP*);
|
2005-06-23 00:15:05 +00:00
|
|
|
int nops();
|
2002-04-30 22:22:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define HTTP_STATE_IDLE 0
|
|
|
|
#define HTTP_STATE_CONNECTING 1
|
2004-03-27 00:45:27 +00:00
|
|
|
#define HTTP_STATE_SOCKS_CONNECT 2
|
|
|
|
#define HTTP_STATE_REQUEST_HEADER 3
|
|
|
|
#define HTTP_STATE_REQUEST_BODY1 4
|
2002-08-26 22:57:17 +00:00
|
|
|
// sending the string part of a POST2 operation
|
2004-03-27 00:45:27 +00:00
|
|
|
#define HTTP_STATE_REQUEST_BODY 5
|
|
|
|
#define HTTP_STATE_REPLY_HEADER 6
|
|
|
|
#define HTTP_STATE_REPLY_BODY 7
|
|
|
|
#define HTTP_STATE_DONE 8
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2003-08-22 00:15:51 +00:00
|
|
|
extern void parse_url(const char* url, char* host, int &port, char* file);
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#endif
|