2004-01-30 22:19:19 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2004-02-28 19:11:40 +00:00
|
|
|
#ifdef _WIN32
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "boinc_win.h"
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
#include <stdio.h>
|
2004-01-21 07:07:16 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
2004-01-21 22:54:35 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <string.h>
|
2004-04-15 20:42:15 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/tcp.h>
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
2004-01-21 07:07:16 +00:00
|
|
|
|
2004-04-07 06:51:42 +00:00
|
|
|
#include "util.h"
|
2004-05-05 21:15:34 +00:00
|
|
|
#include "error_numbers.h"
|
2004-01-21 07:07:16 +00:00
|
|
|
#include "parse.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
|
|
|
|
#include "client_msgs.h"
|
2004-01-21 07:07:16 +00:00
|
|
|
#include "client_state.h"
|
|
|
|
|
|
|
|
GUI_RPC_CONN::GUI_RPC_CONN(int s) {
|
|
|
|
sock = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
GUI_RPC_CONN::~GUI_RPC_CONN() {
|
2004-02-28 19:11:40 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
closesocket(sock);
|
|
|
|
#else
|
2004-01-21 07:07:16 +00:00
|
|
|
close(sock);
|
2004-01-21 22:54:35 +00:00
|
|
|
#endif
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
static PROJECT* get_project(char* buf, MIOFILE& fout) {
|
2004-02-28 19:11:40 +00:00
|
|
|
string url;
|
|
|
|
if (!parse_str(buf, "<project_url>", url)) {
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<error>Missing project URL</error>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
PROJECT* p = gstate.lookup_project(url.c_str());
|
|
|
|
if (!p) {
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<error>No such project</error>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
return 0 ;
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
static void handle_result_show_graphics(char* buf, MIOFILE& fout) {
|
2004-02-28 19:11:40 +00:00
|
|
|
string result_name;
|
|
|
|
PROJECT* p = get_project(buf, fout);
|
|
|
|
if (!p) return;
|
|
|
|
|
|
|
|
if (!parse_str(buf, "<result_name>", result_name)) {
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<error>Missing result name</error>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
RESULT* rp = gstate.lookup_result(p, result_name.c_str());
|
|
|
|
if (!rp) {
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<error>No such result</error>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ACTIVE_TASK* atp = gstate.lookup_active_task_by_result(rp);
|
|
|
|
if (!atp) {
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<error>Result not active</error>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
atp->request_graphics_mode(MODE_WINDOW);
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<success/>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
static void handle_project_reset(char* buf, MIOFILE& fout) {
|
2004-02-28 19:11:40 +00:00
|
|
|
PROJECT* p = get_project(buf, fout);
|
|
|
|
if (p) {
|
|
|
|
gstate.reset_project(p);
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<success/>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
static void handle_project_attach(char* buf, MIOFILE& fout) {
|
2004-02-28 19:11:40 +00:00
|
|
|
string url, authenticator;
|
|
|
|
if (!parse_str(buf, "<url>", url)) {
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<error>Missing URL</error>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!parse_str(buf, "<authenticator>", authenticator)) {
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<error>Missing authenticator</error>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
gstate.add_project(url.c_str(), authenticator.c_str());
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<success/>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
}
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
static void handle_project_detach(char* buf, MIOFILE& fout) {
|
2004-02-28 19:11:40 +00:00
|
|
|
PROJECT* p = get_project(buf, fout);
|
|
|
|
if (p) {
|
|
|
|
gstate.detach_project(p);
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<success/>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
static void handle_project_update(char* buf, MIOFILE& fout) {
|
2004-02-28 19:11:40 +00:00
|
|
|
PROJECT* p = get_project(buf, fout);
|
|
|
|
if (p) {
|
|
|
|
p->sched_rpc_pending = true;
|
|
|
|
p->min_rpc_time = 0;
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<success/>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
static void handle_set_run_mode(char* buf, MIOFILE& fout) {
|
2004-02-28 19:11:40 +00:00
|
|
|
if (match_tag(buf, "<always>")) {
|
|
|
|
gstate.user_run_request = USER_RUN_REQUEST_ALWAYS;
|
|
|
|
} else if (match_tag(buf, "<never>")) {
|
|
|
|
gstate.user_run_request = USER_RUN_REQUEST_NEVER;
|
|
|
|
} else if (match_tag(buf, "<auto>")) {
|
|
|
|
gstate.user_run_request = USER_RUN_REQUEST_AUTO;
|
|
|
|
} else {
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<error>Missing mode</error>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<success/>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
}
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
static void handle_run_benchmarks(char* buf, MIOFILE& fout) {
|
2004-02-28 19:11:40 +00:00
|
|
|
// TODO: suspend activities; make sure run at right priority
|
|
|
|
//
|
2004-03-21 00:10:15 +00:00
|
|
|
gstate.start_cpu_benchmarks();
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<success/>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
}
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
static void handle_set_proxy_settings(char* buf, MIOFILE& fout) {
|
2004-03-27 00:45:27 +00:00
|
|
|
string socks_proxy_server_name,http_proxy_server_name;
|
|
|
|
int socks_proxy_server_port,http_proxy_server_port;
|
|
|
|
if (!parse_str(buf, "<socks_proxy_server_name>", socks_proxy_server_name)) {
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<error>SOCKS proxy server name missing</error>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-03-27 00:45:27 +00:00
|
|
|
if (!parse_int(buf, "<socks_proxy_server_port>", socks_proxy_server_port)) {
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<error>SOCKS proxy server port missing</error>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-03-27 00:45:27 +00:00
|
|
|
if (!parse_str(buf, "<http_proxy_server_name>", http_proxy_server_name)) {
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<error>HTTP proxy server name missing</error>\n");
|
2004-03-27 00:45:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!parse_int(buf, "<http_proxy_server_port>", http_proxy_server_port)) {
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<error>HTTP proxy server port missing</error>\n");
|
2004-03-27 00:45:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
safe_strcpy(gstate.pi.socks_server_name, socks_proxy_server_name.c_str());
|
|
|
|
gstate.pi.socks_server_port = socks_proxy_server_port;
|
|
|
|
safe_strcpy(gstate.pi.http_server_name, http_proxy_server_name.c_str());
|
|
|
|
gstate.pi.http_server_port = http_proxy_server_port;
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<success/>\n");
|
2004-02-28 19:11:40 +00:00
|
|
|
}
|
|
|
|
|
2004-04-01 23:19:13 +00:00
|
|
|
// params:
|
|
|
|
// <nmessages>x</nmessages>
|
|
|
|
// return at most this many messages
|
|
|
|
// <offset>n</offset>
|
|
|
|
// start at message n.
|
|
|
|
// if no offset is given, return last n messages
|
|
|
|
//
|
2004-06-12 04:45:36 +00:00
|
|
|
void handle_get_messages(char* buf, MIOFILE& fout) {
|
2004-06-17 04:49:34 +00:00
|
|
|
int nmessages=-1, seqno=-1, j;
|
2004-04-01 23:19:13 +00:00
|
|
|
|
|
|
|
parse_int(buf, "<nmessages>", nmessages);
|
2004-06-17 04:49:34 +00:00
|
|
|
parse_int(buf, "<seqno>", seqno);
|
2004-04-01 23:19:13 +00:00
|
|
|
if (nmessages < 0) {
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<error>No nmessages given</error>\n");
|
2004-04-01 23:19:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("<msgs>\n");
|
2004-06-17 04:49:34 +00:00
|
|
|
list<MESSAGE_DESC*>::const_iterator iter;
|
|
|
|
for (iter=message_descs.begin(), j=0;
|
|
|
|
iter != message_descs.end() && j<nmessages;
|
|
|
|
iter++, j++
|
|
|
|
) {
|
|
|
|
MESSAGE_DESC* mdp = *iter;
|
|
|
|
if (seqno && mdp->seqno < seqno) break;
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf(
|
2004-04-01 23:19:13 +00:00
|
|
|
"<msg>\n"
|
|
|
|
" <pri>%d</pri>\n"
|
2004-06-17 04:49:34 +00:00
|
|
|
" <seqno>%d</seqno>\n"
|
2004-06-12 05:44:28 +00:00
|
|
|
" <body>\n%s\n</body>\n"
|
2004-04-01 23:19:13 +00:00
|
|
|
" <time>%d</time>\n",
|
2004-06-17 04:49:34 +00:00
|
|
|
mdp->priority,
|
|
|
|
mdp->seqno,
|
|
|
|
mdp->message.c_str(),
|
|
|
|
mdp->timestamp
|
2004-04-01 23:19:13 +00:00
|
|
|
);
|
2004-06-17 04:49:34 +00:00
|
|
|
if (mdp->project) {
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf(
|
2004-04-02 00:32:10 +00:00
|
|
|
" <project>%s</project>\n",
|
2004-06-17 04:49:34 +00:00
|
|
|
mdp->project->get_project_name()
|
2004-04-01 23:19:13 +00:00
|
|
|
);
|
|
|
|
}
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("</msg>\n");
|
2004-04-01 23:19:13 +00:00
|
|
|
}
|
2004-06-12 04:45:36 +00:00
|
|
|
fout.printf("</msgs>\n");
|
2004-04-01 23:19:13 +00:00
|
|
|
}
|
|
|
|
|
2004-01-21 07:07:16 +00:00
|
|
|
int GUI_RPC_CONN::handle_rpc() {
|
2004-06-12 04:45:36 +00:00
|
|
|
char request_msg[1024];
|
2004-01-21 07:07:16 +00:00
|
|
|
int n;
|
2004-06-12 04:45:36 +00:00
|
|
|
MIOFILE mf;
|
|
|
|
MFILE m;
|
|
|
|
char* p;
|
|
|
|
mf.init_mfile(&m);
|
2004-01-21 07:07:16 +00:00
|
|
|
|
2004-06-11 20:52:27 +00:00
|
|
|
SCOPE_MSG_LOG scope_messages(log_messages, CLIENT_MSG_LOG::DEBUG_GUIRPC);
|
|
|
|
|
|
|
|
// read the request message in one read()
|
2004-01-30 22:19:19 +00:00
|
|
|
// so that the core client won't hang because
|
|
|
|
// of malformed request msgs
|
|
|
|
//
|
2004-06-10 21:58:57 +00:00
|
|
|
#ifdef _WIN32
|
2004-06-12 04:45:36 +00:00
|
|
|
n = recv(sock, request_msg, 1024, 0);
|
2004-06-10 21:58:57 +00:00
|
|
|
#else
|
2004-06-12 04:45:36 +00:00
|
|
|
n = read(sock, request_msg, 1024);
|
2004-06-10 21:58:57 +00:00
|
|
|
#endif
|
2004-01-21 07:07:16 +00:00
|
|
|
if (n <= 0) return -1;
|
2004-06-12 04:45:36 +00:00
|
|
|
request_msg[n] = 0;
|
2004-06-14 18:37:46 +00:00
|
|
|
|
2004-06-14 23:03:49 +00:00
|
|
|
scope_messages.printf("GUI RPC Command = '%s'\n", request_msg);
|
2004-06-14 18:37:46 +00:00
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
if (match_tag(request_msg, "<get_state")) {
|
|
|
|
gstate.write_state(mf);
|
|
|
|
} else if (match_tag(request_msg, "<result_show_graphics>")) {
|
|
|
|
handle_result_show_graphics(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<project_reset>")) {
|
|
|
|
handle_project_reset(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<project_attach>")) {
|
|
|
|
handle_project_attach(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<project_detach>")) {
|
|
|
|
handle_project_detach(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<project_update>")) {
|
|
|
|
handle_project_update(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<set_run_mode>")) {
|
|
|
|
handle_set_run_mode(request_msg, mf);
|
2004-06-12 18:44:53 +00:00
|
|
|
} else if (match_tag(request_msg, "<run_benchmarks")) {
|
2004-06-12 04:45:36 +00:00
|
|
|
handle_run_benchmarks(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<set_proxy_settings>")) {
|
|
|
|
handle_set_proxy_settings(request_msg, mf);
|
|
|
|
} else if (match_tag(request_msg, "<get_messages>")) {
|
|
|
|
handle_get_messages(request_msg, mf);
|
2004-01-21 07:07:16 +00:00
|
|
|
} else {
|
2004-06-12 04:45:36 +00:00
|
|
|
mf.printf("<unrecognized/>\n");
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
2004-06-10 21:58:57 +00:00
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
mf.printf("\003");
|
|
|
|
m.get_buf(p, n);
|
|
|
|
send(sock, p, n, 0);
|
2004-06-10 21:58:57 +00:00
|
|
|
|
2004-04-01 23:19:13 +00:00
|
|
|
return 0;
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int GUI_RPC_CONN_SET::insert(GUI_RPC_CONN* p) {
|
|
|
|
gui_rpcs.push_back(p);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-05-05 21:15:34 +00:00
|
|
|
int GUI_RPC_CONN_SET::init() {
|
2004-04-15 20:42:15 +00:00
|
|
|
sockaddr_in addr;
|
2004-01-21 07:07:16 +00:00
|
|
|
int retval;
|
|
|
|
|
2004-04-15 20:42:15 +00:00
|
|
|
lsock = socket(AF_INET, SOCK_STREAM, 0);
|
2004-06-12 04:45:36 +00:00
|
|
|
if (lsock < 0) {
|
|
|
|
msg_printf(NULL, MSG_ERROR,
|
|
|
|
"GUI RPC failed to initialize socket (retval = '%d')\n",
|
|
|
|
lsock
|
|
|
|
);
|
2004-05-05 21:15:34 +00:00
|
|
|
return ERR_SOCKET;
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
2004-04-15 20:42:15 +00:00
|
|
|
|
|
|
|
addr.sin_family = AF_INET;
|
|
|
|
addr.sin_port = htons(GUI_RPC_PORT);
|
|
|
|
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
|
|
|
2004-06-12 04:45:36 +00:00
|
|
|
int one = 1;
|
|
|
|
setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, (char*)&one, 4);
|
|
|
|
|
2004-01-21 07:07:16 +00:00
|
|
|
retval = bind(lsock, (const sockaddr*)(&addr), sizeof(addr));
|
|
|
|
if (retval) {
|
2004-06-12 04:45:36 +00:00
|
|
|
msg_printf(NULL, MSG_ERROR,
|
|
|
|
"GUI RPC bind failed (retval = '%d')\n", retval
|
|
|
|
);
|
2004-05-05 21:15:34 +00:00
|
|
|
return ERR_BIND;
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
|
|
|
retval = listen(lsock, 999);
|
|
|
|
if (retval) {
|
2004-06-12 04:45:36 +00:00
|
|
|
msg_printf(NULL, MSG_ERROR,
|
|
|
|
"GUI RPC listen failed (retval = '%d')\n",
|
|
|
|
retval
|
|
|
|
);
|
2004-05-05 21:15:34 +00:00
|
|
|
return ERR_LISTEN;
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
2004-05-12 21:21:09 +00:00
|
|
|
return 0;
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GUI_RPC_CONN_SET::poll() {
|
2004-06-09 18:17:25 +00:00
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
if (lsock >= 0) {
|
|
|
|
unsigned int i;
|
|
|
|
fd_set read_fds, error_fds;
|
|
|
|
int sock, retval;
|
|
|
|
vector<GUI_RPC_CONN*>::iterator iter;
|
|
|
|
GUI_RPC_CONN* gr;
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
FD_ZERO(&read_fds);
|
|
|
|
FD_ZERO(&error_fds);
|
|
|
|
FD_SET(lsock, &read_fds);
|
|
|
|
for (i=0; i<gui_rpcs.size(); i++) {
|
|
|
|
gr = gui_rpcs[i];
|
|
|
|
FD_SET(gr->sock, &read_fds);
|
|
|
|
FD_SET(gr->sock, &error_fds);
|
|
|
|
}
|
2004-01-21 07:07:16 +00:00
|
|
|
|
2004-06-09 18:17:25 +00:00
|
|
|
memset(&tv, 0, sizeof(tv));
|
|
|
|
n = select(FD_SETSIZE, &read_fds, 0, &error_fds, &tv);
|
|
|
|
if (FD_ISSET(lsock, &read_fds)) {
|
|
|
|
struct sockaddr_in addr;
|
2004-04-15 20:52:54 +00:00
|
|
|
#ifdef _WIN32
|
2004-06-09 18:17:25 +00:00
|
|
|
int addr_len = sizeof(addr);
|
|
|
|
sock = accept(lsock, (struct sockaddr*)&addr, &addr_len);
|
2004-04-15 20:52:54 +00:00
|
|
|
#else
|
2004-06-16 22:36:10 +00:00
|
|
|
socklen_t addr_len = sizeof(addr);
|
2004-06-09 18:17:25 +00:00
|
|
|
sock = accept(lsock, (struct sockaddr*)&addr, &addr_len);
|
2004-04-15 20:52:54 +00:00
|
|
|
#endif
|
2004-06-09 18:17:25 +00:00
|
|
|
int peer_ip = (int) ntohl(addr.sin_addr.s_addr);
|
2004-06-11 20:52:27 +00:00
|
|
|
if ((!gstate.allow_remote_gui_rpc) && (peer_ip != 0x7f000001)) {
|
2004-06-09 18:17:25 +00:00
|
|
|
msg_printf(
|
|
|
|
NULL, MSG_ERROR,
|
|
|
|
"GUI RPC request from non-local address 0x%x\n",
|
|
|
|
peer_ip
|
|
|
|
);
|
2004-06-13 19:47:03 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
closesocket(sock);
|
|
|
|
#else
|
|
|
|
close(sock);
|
|
|
|
#endif
|
2004-06-09 18:17:25 +00:00
|
|
|
} else {
|
|
|
|
GUI_RPC_CONN* gr = new GUI_RPC_CONN(sock);
|
|
|
|
insert(gr);
|
|
|
|
}
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
2004-06-09 18:17:25 +00:00
|
|
|
iter = gui_rpcs.begin();
|
|
|
|
while (iter != gui_rpcs.end()) {
|
|
|
|
gr = *iter;
|
|
|
|
if (FD_ISSET(gr->sock, &error_fds)) {
|
2004-01-21 07:07:16 +00:00
|
|
|
delete gr;
|
|
|
|
gui_rpcs.erase(iter);
|
2004-06-09 18:17:25 +00:00
|
|
|
} else {
|
|
|
|
iter++;
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
|
|
|
}
|
2004-06-09 18:17:25 +00:00
|
|
|
iter = gui_rpcs.begin();
|
|
|
|
while (iter != gui_rpcs.end()) {
|
|
|
|
gr = *iter;
|
|
|
|
if (FD_ISSET(gr->sock, &read_fds)) {
|
|
|
|
retval = gr->handle_rpc();
|
|
|
|
if (retval) {
|
|
|
|
delete gr;
|
|
|
|
gui_rpcs.erase(iter);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
iter++;
|
|
|
|
}
|
2004-01-21 07:07:16 +00:00
|
|
|
}
|
|
|
|
return (n != 0);
|
|
|
|
}
|