1 // This file is part of BOINC.
2 // http://boinc.berkeley.edu
3 // Copyright (C) 2008 University of California
4 //
5 // BOINC is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Lesser General Public License
7 // as published by the Free Software Foundation,
8 // either version 3 of the License, or (at your option) any later version.
9 //
10 // BOINC is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 // See the GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
17 
18 #ifndef BOINC_ACCT_MGR_H
19 #define BOINC_ACCT_MGR_H
20 
21 #include <string>
22 #include <vector>
23 
24 #include "str_replace.h"
25 #include "miofile.h"
26 #include "parse.h"
27 #include "gui_http.h"
28 #include "client_types.h"
29 
30 // represents info stored in acct_mgr_url.xml and acct_mgr_login.xml
31 
32 struct ACCT_MGR_INFO : PROJ_AM {
33     // the following used to be std::string but there
34     // were mysterious bugs where setting it to "" didn't work
35     //
36     char login_name[256];   // unique name (could be email addr)
37     char user_name[256];    // non-unique name
38     char password_hash[256];
39         // md5 of password.lowercase(login_name)
40     char opaque[256];
41         // opaque data, from the AM, to be included in future AM requests
42     std::string sched_req_opaque;
43         // opaque data to be sent in scheduler requests, in CDATA
44     char signing_key[MAX_KEY_LEN];
45     char previous_host_cpid[64];
46         // the host CPID sent in last RPC
47     double next_rpc_time;
48     int nfailures;
49     bool send_gui_rpc_info;
50         // whether to include GUI RPC port and password hash
51         // in AM RPCs (used for "farm management")
52     bool no_project_notices;
53         // if set, don't show notices from projects
54     bool cookie_required;
55         // use of cookies are required during initial signup
56         // NOTE: This bool gets dropped after the client has
57         //   successfully attached to an account manager
58     char cookie_failure_url[256];
59         // if the cookies could not be detected, provide a
60         // link to a website to go to so the user can find
61         // what login name and password they have been assigned
62     bool password_error;
63     bool send_rec;
64 
using_amACCT_MGR_INFO65     inline bool using_am() {
66         if (!strlen(master_url)) return false;
67         if (!strlen(login_name)) return false;
68         if (!strlen(password_hash)) return false;
69         return true;
70     }
same_amACCT_MGR_INFO71     inline bool same_am(const char* mu, const char* ln, const char* ph) {
72         if (strcmp(mu, master_url)) return false;
73         if (strcmp(ln, login_name)) return false;
74         if (strcmp(ph, password_hash)) return false;
75         return true;
76     }
get_no_project_noticesACCT_MGR_INFO77     inline bool get_no_project_notices() {
78         if (!using_am()) return false;
79         return no_project_notices;
80     }
81 
82     ACCT_MGR_INFO();
83     int parse_login_file(FILE*);
84     int write_info();
85     int init();
86     void clear();
87     bool poll();
88 };
89 
90 // stuff after here related to RPCs to account managers
91 
92 struct OPTIONAL_BOOL {
93     bool present;
94     bool value;
initOPTIONAL_BOOL95     inline void init() {present=false;}
setOPTIONAL_BOOL96     inline void set(bool v) {value=v; present=true;}
97 };
98 
99 struct OPTIONAL_DOUBLE {
100     bool present;
101     double value;
initOPTIONAL_DOUBLE102     inline void init() {present=false;}
setOPTIONAL_DOUBLE103     inline void set(double v) {value=v; present=true;}
104 };
105 
106 // an account entry in reply message
107 //
108 struct AM_ACCOUNT {
109     std::string url;
110     std::string authenticator;
111     std::string sci_keywords;
112     std::string loc_keywords;
113     char url_signature[MAX_SIGNATURE_LEN];
114     bool detach;
115     bool update;
116     bool no_rsc[MAX_RSC];
117         // instructions from AM not to use various resources
118     OPTIONAL_BOOL dont_request_more_work;
119     OPTIONAL_BOOL detach_when_done;
120     OPTIONAL_DOUBLE resource_share;
121     OPTIONAL_BOOL suspend;
122     OPTIONAL_BOOL abort_not_started;
123 
124     void handle_no_rsc(const char*, bool);
125     int parse(XML_PARSER&);
AM_ACCOUNTAM_ACCOUNT126     AM_ACCOUNT() {
127         safe_strcpy(url_signature, "");
128         detach = false;
129         update = false;
130         dont_request_more_work.init();
131         detach_when_done.init();
132         resource_share.init();
133         suspend.init();
134         abort_not_started.init();
135     }
~AM_ACCOUNTAM_ACCOUNT136     ~AM_ACCOUNT() {}
137 };
138 
139 struct ACCT_MGR_OP: public GUI_HTTP_OP {
140     bool via_gui;
141     int error_num;
142     ACCT_MGR_INFO ami;
143         // a temporary copy while doing RPC.
144         // CLIENT_STATE::acct_mgr_info is authoratative
145     std::string error_str;
146     std::vector<AM_ACCOUNT> accounts;
147     double repeat_sec;
148     char* global_prefs_xml;
149     char host_venue[256];
150     bool got_rss_feeds;
151     std::vector<RSS_FEED>rss_feeds;
152 
153     int do_rpc(
154         std::string url, std::string name, std::string password,
155         bool via_gui
156     );
157     int parse(FILE*);
158     virtual void handle_reply(int http_op_retval);
159 
ACCT_MGR_OPACCT_MGR_OP160     ACCT_MGR_OP(GUI_HTTP* p) {
161         gui_http = p;
162         via_gui = false;
163         error_num = BOINC_SUCCESS;
164         repeat_sec = 60.0;
165         global_prefs_xml = 0;
166         safe_strcpy(host_venue, "");
167         got_rss_feeds = false;
168     }
~ACCT_MGR_OPACCT_MGR_OP169     virtual ~ACCT_MGR_OP(){}
170 };
171 
172 #endif
173