2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-08-05 18:41:46 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2005-08-05 18:41:46 +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-05 18:41:46 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-08-05 18:41:46 +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-11-22 02:11:35 +00:00
|
|
|
|
2010-05-11 19:10:29 +00:00
|
|
|
#include "cpp.h"
|
|
|
|
|
2005-11-22 02:11:35 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "boinc_win.h"
|
2006-03-29 21:41:35 +00:00
|
|
|
#else
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2010-05-11 19:10:29 +00:00
|
|
|
#include <cstring>
|
2005-11-22 02:11:35 +00:00
|
|
|
#endif
|
|
|
|
|
2005-08-05 18:41:46 +00:00
|
|
|
#include "client_state.h"
|
|
|
|
#include "filesys.h"
|
|
|
|
#include "error_numbers.h"
|
|
|
|
|
|
|
|
#include "gui_http.h"
|
|
|
|
|
2010-07-22 19:13:36 +00:00
|
|
|
int GUI_HTTP::do_rpc(
|
2011-06-12 20:58:43 +00:00
|
|
|
GUI_HTTP_OP* op, const char* url, const char* output_file, bool is_bkgd
|
2010-07-22 19:13:36 +00:00
|
|
|
) {
|
2005-08-05 18:41:46 +00:00
|
|
|
int retval;
|
|
|
|
|
2009-12-22 03:56:24 +00:00
|
|
|
// this check should be done at a higher level.
|
|
|
|
// Do it here too just in case
|
|
|
|
//
|
|
|
|
if (gui_http_state != GUI_HTTP_STATE_IDLE) {
|
2005-08-05 18:41:46 +00:00
|
|
|
return ERR_RETRY;
|
|
|
|
}
|
|
|
|
|
2009-12-22 03:56:24 +00:00
|
|
|
boinc_delete_file(output_file);
|
2011-10-18 04:23:03 +00:00
|
|
|
retval = http_op.init_get(0, url, output_file, true);
|
2009-02-10 19:30:59 +00:00
|
|
|
if (retval) return retval;
|
|
|
|
gstate.http_ops->insert(&http_op);
|
|
|
|
gui_http_op = op;
|
2009-12-22 03:56:24 +00:00
|
|
|
gui_http_state = GUI_HTTP_STATE_BUSY;
|
2010-07-22 19:13:36 +00:00
|
|
|
http_op.is_background = is_bkgd;
|
2009-02-10 19:30:59 +00:00
|
|
|
return 0;
|
2005-08-05 18:41:46 +00:00
|
|
|
}
|
|
|
|
|
2010-03-25 23:48:58 +00:00
|
|
|
int GUI_HTTP::do_rpc_post(
|
|
|
|
GUI_HTTP_OP* op, char* url,
|
2010-07-22 19:13:36 +00:00
|
|
|
const char* input_file, const char* output_file,
|
|
|
|
bool is_bkgd
|
2010-03-25 23:48:58 +00:00
|
|
|
) {
|
2005-12-09 22:29:21 +00:00
|
|
|
int retval;
|
|
|
|
|
2009-12-22 03:56:24 +00:00
|
|
|
if (gui_http_state != GUI_HTTP_STATE_IDLE) {
|
2005-12-09 22:29:21 +00:00
|
|
|
return ERR_RETRY;
|
|
|
|
}
|
|
|
|
|
2009-12-22 03:56:24 +00:00
|
|
|
boinc_delete_file(output_file);
|
2011-10-18 04:23:03 +00:00
|
|
|
retval = http_op.init_post(0, url, input_file, output_file);
|
2009-02-10 19:30:59 +00:00
|
|
|
if (retval) return retval;
|
|
|
|
gstate.http_ops->insert(&http_op);
|
|
|
|
gui_http_op = op;
|
2009-12-22 03:56:24 +00:00
|
|
|
gui_http_state = GUI_HTTP_STATE_BUSY;
|
2010-07-22 19:13:36 +00:00
|
|
|
http_op.is_background = is_bkgd;
|
2009-02-10 19:30:59 +00:00
|
|
|
return 0;
|
2005-12-09 22:29:21 +00:00
|
|
|
}
|
2006-10-02 16:13:08 +00:00
|
|
|
|
2011-09-22 18:52:21 +00:00
|
|
|
int GUI_HTTP::do_rpc_post_str(GUI_HTTP_OP* op, char* url, char* req_buf, int len) {
|
2011-09-20 18:49:38 +00:00
|
|
|
if (gui_http_state != GUI_HTTP_STATE_IDLE) {
|
|
|
|
return ERR_RETRY;
|
|
|
|
}
|
2011-10-18 04:23:03 +00:00
|
|
|
int retval = http_op.init_post2(0, url, req_buf, len, NULL, 0);
|
2011-09-20 18:49:38 +00:00
|
|
|
if (retval) return retval;
|
|
|
|
gstate.http_ops->insert(&http_op);
|
|
|
|
gui_http_op = op;
|
|
|
|
gui_http_state = GUI_HTTP_STATE_BUSY;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-08-05 18:41:46 +00:00
|
|
|
bool GUI_HTTP::poll() {
|
2009-12-22 03:56:24 +00:00
|
|
|
if (gui_http_state == GUI_HTTP_STATE_IDLE) return false;
|
2005-08-05 18:41:46 +00:00
|
|
|
static double last_time=0;
|
2009-02-26 03:24:39 +00:00
|
|
|
if (gstate.now-last_time < GUI_HTTP_POLL_PERIOD) return false;
|
2005-08-05 18:41:46 +00:00
|
|
|
last_time = gstate.now;
|
|
|
|
|
|
|
|
if (http_op.http_op_state == HTTP_STATE_DONE) {
|
|
|
|
gstate.http_ops->remove(&http_op);
|
2006-02-14 21:20:43 +00:00
|
|
|
gui_http_op->handle_reply(http_op.http_op_retval);
|
2005-08-05 18:41:46 +00:00
|
|
|
gui_http_op = NULL;
|
2009-12-22 03:56:24 +00:00
|
|
|
gui_http_state = GUI_HTTP_STATE_IDLE;
|
2005-08-05 18:41:46 +00:00
|
|
|
}
|
|
|
|
return true;
|
2005-08-07 01:33:15 +00:00
|
|
|
}
|