~ubuntu-branches/ubuntu/precise/boinc/precise

« back to all changes in this revision

Viewing changes to client/acct_setup.cpp

Tags: 6.12.8+dfsg-1
* New upstream release.
* Simplified debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
// You should have received a copy of the GNU Lesser General Public License
16
16
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
17
17
 
 
18
#include "cpp.h"
 
19
 
18
20
#ifdef _WIN32
19
21
#include "boinc_win.h"
20
 
#endif
21
 
 
22
 
#ifndef _WIN32
 
22
#else
23
23
#include "config.h"
24
 
#endif
25
 
 
26
24
#include <cstring>
 
25
#endif
 
26
 
27
27
#include "client_state.h"
28
28
#include "file_names.h"
29
29
#include "parse.h"
30
30
#include "filesys.h"
31
31
#include "str_util.h"
 
32
#include "url.h"
32
33
#include "util.h"
33
34
#include "client_msgs.h"
34
35
#include "log_flags.h"
39
40
    strcpy(url, "");
40
41
    strcpy(name, "");
41
42
    strcpy(account_key, "");
 
43
    strcpy(team_name, "");
42
44
}
43
45
 
44
46
PROJECT_INIT::PROJECT_INIT() {
57
59
        while(mf.fgets(buf, sizeof(buf))) {
58
60
            if (match_tag(buf, "</project_init>")) break;
59
61
            else if (parse_str(buf, "<name>", name, 256)) continue;
 
62
            else if (parse_str(buf, "<team_name>", team_name, 256)) continue;
60
63
            else if (parse_str(buf, "<url>", url, 256)) {
61
64
                canonicalize_master_url(url);
62
65
                continue;
65
68
            }
66
69
        }
67
70
        fclose(p);
 
71
        msg_printf(0, MSG_INFO, "Found project_init.xml for %s", url);
68
72
    }
69
73
    return 0;
70
74
}
84
88
    parse_str(buf, "<email_addr>", email_addr);
85
89
    parse_str(buf, "<passwd_hash>", passwd_hash);
86
90
    parse_str(buf, "<user_name>", user_name);
 
91
    parse_str(buf, "<team_name>", team_name);
87
92
    canonicalize_master_url(url);
88
93
}
89
94
 
100
105
        "Fetching configuration file from %s", url.c_str()
101
106
    );
102
107
 
103
 
    retval = gui_http->do_rpc(this, url, GET_PROJECT_CONFIG_FILENAME);
 
108
    retval = gui_http->do_rpc(
 
109
        this, (char*)url.c_str(), GET_PROJECT_CONFIG_FILENAME, false
 
110
    );
104
111
    if (retval) {
105
112
        error_num = retval;
106
113
    } else {
135
142
    escape_url(parameter);
136
143
    url += parameter;
137
144
 
138
 
    retval = gui_http->do_rpc(this, url, LOOKUP_ACCOUNT_FILENAME);
 
145
    retval = gui_http->do_rpc(
 
146
        this, (char*)url.c_str(), LOOKUP_ACCOUNT_FILENAME, false
 
147
    );
139
148
    if (retval) {
140
149
        error_num = retval;
141
150
    } else {
175
184
    escape_url(parameter);
176
185
    url += parameter;
177
186
 
178
 
    retval = gui_http->do_rpc(this, url, CREATE_ACCOUNT_FILENAME);
 
187
    if (!ai.team_name.empty()) {
 
188
        url += "&team_name=";
 
189
        parameter = ai.team_name;
 
190
        escape_url(parameter);
 
191
        url += parameter;
 
192
    }
 
193
    retval = gui_http->do_rpc(
 
194
        this, (char*)url.c_str(), CREATE_ACCOUNT_FILENAME, false
 
195
    );
179
196
    if (retval) {
180
197
        error_num = retval;
181
198
    } else {
192
209
    }
193
210
}
194
211
 
195
 
int GET_CURRENT_VERSION_OP::do_rpc() {
196
 
    int retval;
197
 
 
198
 
    retval = gui_http->do_rpc(
199
 
        this, config.client_version_check_url, GET_CURRENT_VERSION_FILENAME
200
 
    );
201
 
    if (retval) {
202
 
        error_num = retval;
203
 
    } else {
204
 
        error_num = ERR_IN_PROGRESS;
205
 
    }
206
 
    return retval;
207
 
}
208
 
 
209
 
static bool is_version_newer(char* p) {
210
 
    int maj=0, min=0, rel=0;
211
 
 
212
 
    sscanf(p, "%d.%d.%d", &maj, &min, &rel);
213
 
    if (maj > gstate.core_client_version.major) return true;
214
 
    if (maj < gstate.core_client_version.major) return false;
215
 
    if (min > gstate.core_client_version.minor) return true;
216
 
    if (min < gstate.core_client_version.minor) return false;
217
 
    if (rel > gstate.core_client_version.release) return true;
218
 
    return false;
219
 
}
220
 
 
221
 
static bool parse_version(FILE* f, char* new_version) {
222
 
    char buf[256], buf2[256];
223
 
    bool same_platform = false, newer_version = false;
224
 
    while (fgets(buf, 256, f)) {
225
 
        if (match_tag(buf, "</version>")) {
226
 
            return (same_platform && newer_version);
227
 
        }
228
 
        if (parse_str(buf, "<dbplatform>", buf2, sizeof(buf2))) {
229
 
            same_platform = (strcmp(buf2, gstate.get_primary_platform())==0);
230
 
        }
231
 
        if (parse_str(buf, "<version_num>", buf2, sizeof(buf2))) {
232
 
            newer_version = is_version_newer(buf2);
233
 
            strcpy(new_version, buf2);
234
 
        }
235
 
    }
236
 
    return false;
237
 
}
238
 
 
239
 
void GET_CURRENT_VERSION_OP::handle_reply(int http_op_retval) {
240
 
    char buf[256], new_version[256];
241
 
    if (http_op_retval) {
242
 
        error_num = http_op_retval;
243
 
        return;
244
 
    }
245
 
    gstate.new_version_check_time = gstate.now;
246
 
    FILE* f = boinc_fopen(GET_CURRENT_VERSION_FILENAME, "r");
247
 
    if (f) {
248
 
        while (fgets(buf, 256, f)) {
249
 
            if (match_tag(buf, "<version>")) {
250
 
                if (parse_version(f, new_version)) {
251
 
                    msg_printf(0, MSG_USER_ERROR,
252
 
                        "A new version of BOINC (%s) is available for your computer",
253
 
                        new_version
254
 
                    );
255
 
 
256
 
                    msg_printf(0, MSG_USER_ERROR,
257
 
                        "Visit %s to get it.",
258
 
                                                config.client_download_url.c_str()
259
 
                    );
260
 
                    gstate.newer_version = string(new_version);
261
 
                    break;
262
 
                }
263
 
            }
264
 
        }
265
 
        fclose(f);
266
 
    }
267
 
}
268
 
 
269
 
#define NEW_VERSION_CHECK_PERIOD (14*86400)
270
 
 
271
 
void CLIENT_STATE::new_version_check() {
272
 
    if (( new_version_check_time == 0) ||
273
 
        (now - new_version_check_time > NEW_VERSION_CHECK_PERIOD)) {
274
 
            // get_current_version_op.handle_reply() will update new_version_check_time
275
 
            get_current_version_op.do_rpc();
276
 
        }
277
 
}
278
 
 
279
212
int GET_PROJECT_LIST_OP::do_rpc() {
280
213
    int retval;
281
214
    char buf[256];
282
215
 
283
216
    sprintf(buf, "http://boinc.berkeley.edu/project_list.php");
284
217
    retval = gui_http->do_rpc(
285
 
        this, string(buf), ALL_PROJECTS_LIST_FILENAME_TEMP
 
218
        this, buf, ALL_PROJECTS_LIST_FILENAME_TEMP, true
286
219
    );
287
220
    if (retval) {
288
221
        error_num = retval;
295
228
#define ALL_PROJECTS_LIST_CHECK_PERIOD (14*86400)
296
229
 
297
230
void GET_PROJECT_LIST_OP::handle_reply(int http_op_retval) {
 
231
    bool error = false;
298
232
    if (http_op_retval) {
299
233
        error_num = http_op_retval;
300
 
        // if error, try again in a day
301
 
        //
 
234
        error = true;
 
235
    } else {
 
236
        string s;
 
237
        read_file_string(ALL_PROJECTS_LIST_FILENAME_TEMP, s);
 
238
        if (strstr(s.c_str(), "</projects>")) {
 
239
            boinc_rename(
 
240
                ALL_PROJECTS_LIST_FILENAME_TEMP, ALL_PROJECTS_LIST_FILENAME
 
241
            );
 
242
            gstate.all_projects_list_check_time = gstate.now;
 
243
        } else {
 
244
            error = true;
 
245
        }
 
246
    }
 
247
    // if error, try again in a day
 
248
    //
 
249
    if (error) {
302
250
        gstate.all_projects_list_check_time =
303
251
            gstate.now - ALL_PROJECTS_LIST_CHECK_PERIOD + SECONDS_PER_DAY;
304
 
    } else {
305
 
        boinc_rename(ALL_PROJECTS_LIST_FILENAME_TEMP, ALL_PROJECTS_LIST_FILENAME);
306
 
        gstate.all_projects_list_check_time = gstate.now;
307
252
    }
308
253
}
309
254
 
317
262
    get_project_list_op.do_rpc();
318
263
}
319
264
 
320
 
const char *BOINC_RCSID_84df3fc17e="$Id: acct_setup.cpp 16208 2008-10-14 23:07:40Z davea $";