2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2004-07-13 13:54:09 +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.
|
2004-07-13 13:54:09 +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
|
|
|
|
2003-10-16 19:03:49 +00:00
|
|
|
#include "cpp.h"
|
2002-06-06 18:42:01 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2004-06-16 23:16:08 +00:00
|
|
|
#include "boinc_win.h"
|
2004-09-09 04:22:43 +00:00
|
|
|
#include "win_util.h"
|
2002-06-06 18:42:01 +00:00
|
|
|
#endif
|
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
#ifndef _WIN32
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <sys/stat.h>
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cctype>
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-08-24 00:41:25 +00:00
|
|
|
#include "filesys.h"
|
2002-07-11 01:09:53 +00:00
|
|
|
#include "error_numbers.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "client_msgs.h"
|
2003-03-08 23:48:05 +00:00
|
|
|
#include "util.h"
|
2002-06-21 06:52:47 +00:00
|
|
|
|
2003-07-03 05:01:29 +00:00
|
|
|
#include "file_names.h"
|
|
|
|
|
2002-12-19 00:37:19 +00:00
|
|
|
void escape_project_url(char *in, char* out) {
|
2003-05-20 00:03:39 +00:00
|
|
|
escape_url_readable(in, out);
|
2003-06-24 00:17:36 +00:00
|
|
|
char& last = out[strlen(out)-1];
|
|
|
|
// remove trailing _
|
|
|
|
if (last == '_') {
|
|
|
|
last = '\0';
|
|
|
|
}
|
2002-09-25 18:33:26 +00:00
|
|
|
}
|
|
|
|
|
2004-01-04 06:48:40 +00:00
|
|
|
void get_project_dir(PROJECT* p, char* path) {
|
|
|
|
char buf[256];
|
|
|
|
escape_project_url(p->master_url, buf);
|
|
|
|
sprintf(path, "%s%s%s", PROJECTS_DIR, PATH_SEPARATOR, buf);
|
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Gets the pathname of a file
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
void get_pathname(FILE_INFO* fip, char* path) {
|
|
|
|
PROJECT* p = fip->project;
|
2002-06-21 06:52:47 +00:00
|
|
|
char buf[256];
|
2002-08-05 00:29:34 +00:00
|
|
|
|
2002-07-05 05:33:40 +00:00
|
|
|
// for testing purposes, it's handy to allow a FILE_INFO without
|
|
|
|
// an associated PROJECT.
|
|
|
|
//
|
|
|
|
if (p) {
|
2004-01-04 06:48:40 +00:00
|
|
|
get_project_dir(p, buf);
|
|
|
|
sprintf(path, "%s%s%s", buf, PATH_SEPARATOR, fip->name);
|
2002-07-05 05:33:40 +00:00
|
|
|
} else {
|
2004-01-04 06:48:40 +00:00
|
|
|
strcpy(path, fip->name);
|
2002-07-05 05:33:40 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2004-09-22 22:09:54 +00:00
|
|
|
void get_sched_request_filename(PROJECT& project, char* buf) {
|
|
|
|
char url[256];
|
|
|
|
|
2004-09-22 22:28:25 +00:00
|
|
|
escape_project_url(project.master_url, url);
|
|
|
|
sprintf(buf, "%s%s.xml", SCHED_OP_REQUEST_BASE, url);
|
2004-09-22 22:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void get_sched_reply_filename(PROJECT& project, char* buf) {
|
|
|
|
char url[256];
|
|
|
|
|
2004-09-22 22:28:25 +00:00
|
|
|
escape_project_url(project.master_url, url);
|
|
|
|
sprintf(buf, "%s%s.xml", SCHED_OP_REPLY_BASE, url);
|
2004-09-22 22:09:54 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Returns the location of a numbered slot directory
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
void get_slot_dir(int slot, char* path) {
|
2002-09-25 18:33:26 +00:00
|
|
|
sprintf(path, "%s%s%d", SLOTS_DIR, PATH_SEPARATOR, slot);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Create the directory for the project p
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
int make_project_dir(PROJECT& p) {
|
2004-01-04 06:48:40 +00:00
|
|
|
char buf[256];
|
2004-04-20 23:04:05 +00:00
|
|
|
int retval;
|
2002-06-21 06:52:47 +00:00
|
|
|
|
2003-05-13 18:55:07 +00:00
|
|
|
boinc_mkdir(PROJECTS_DIR);
|
2004-01-04 06:48:40 +00:00
|
|
|
get_project_dir(&p, buf);
|
2004-04-20 23:04:05 +00:00
|
|
|
retval = boinc_mkdir(buf);
|
|
|
|
return retval;
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-12-02 20:52:22 +00:00
|
|
|
int remove_project_dir(PROJECT& p) {
|
2004-01-04 06:48:40 +00:00
|
|
|
char buf[256];
|
2004-05-24 19:00:26 +00:00
|
|
|
int retval;
|
2002-12-02 20:52:22 +00:00
|
|
|
|
2004-01-04 06:48:40 +00:00
|
|
|
get_project_dir(&p, buf);
|
2004-05-24 19:00:26 +00:00
|
|
|
retval = clean_out_dir(buf);
|
|
|
|
if (retval) {
|
|
|
|
msg_printf(&p, MSG_ERROR, "Can't delete file %s\n", boinc_failed_file);
|
|
|
|
return retval;
|
|
|
|
}
|
2004-04-14 23:32:17 +00:00
|
|
|
return boinc_rmdir(buf);
|
2002-12-02 20:52:22 +00:00
|
|
|
}
|
|
|
|
|
2002-07-15 23:21:20 +00:00
|
|
|
// Create the slot directory for the specified slot #
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
int make_slot_dir(int slot) {
|
|
|
|
char buf[256];
|
2004-04-14 23:32:17 +00:00
|
|
|
if (slot<0) {
|
2003-07-03 05:01:29 +00:00
|
|
|
msg_printf(NULL, MSG_ERROR, "make_slot_dir(): negative slot\n");
|
2002-07-11 01:09:53 +00:00
|
|
|
return ERR_NEG;
|
|
|
|
}
|
2003-05-13 18:55:07 +00:00
|
|
|
boinc_mkdir(SLOTS_DIR);
|
2002-04-30 22:22:54 +00:00
|
|
|
get_slot_dir(slot, buf);
|
2004-04-14 23:32:17 +00:00
|
|
|
return boinc_mkdir(buf);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
2002-06-06 18:42:01 +00:00
|
|
|
|
2002-09-26 05:57:10 +00:00
|
|
|
void get_account_filename(char* master_url, char* path) {
|
|
|
|
char buf[256];
|
|
|
|
escape_project_url(master_url, buf);
|
|
|
|
sprintf(path, "account_%s.xml", buf);
|
|
|
|
}
|
|
|
|
|
2005-02-27 20:06:51 +00:00
|
|
|
static bool bad_account_filename(const char* filename) {
|
|
|
|
msg_printf(NULL, MSG_ERROR, "Invalid account file: %s", filename);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// account filenames are of the form
|
|
|
|
// account_URL.xml
|
|
|
|
// where URL is master URL with slashes replaced by underscores
|
|
|
|
//
|
2005-02-16 23:17:43 +00:00
|
|
|
bool is_account_file(const char* filename) {
|
2005-02-27 20:06:51 +00:00
|
|
|
const char* p, *q;
|
|
|
|
p = strstr(filename, "account_");
|
|
|
|
if (p != filename) return false;
|
|
|
|
q = filename + strlen("account_");
|
|
|
|
|
|
|
|
p = strstr(q, ".");
|
|
|
|
if (!p) return bad_account_filename(filename);
|
|
|
|
if (p == q) return bad_account_filename(filename);
|
|
|
|
|
|
|
|
q = p+1;
|
|
|
|
p = strstr(q, ".xml");
|
|
|
|
if (!p) return bad_account_filename(filename);
|
|
|
|
if (p == q) return bad_account_filename(filename);
|
|
|
|
|
|
|
|
q = p + strlen(".xml");
|
|
|
|
if (strlen(q)) return bad_account_filename(filename);
|
|
|
|
return true;
|
2002-09-26 05:57:10 +00:00
|
|
|
}
|
2004-09-06 20:30:22 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_7d362a6a52 = "$Id$";
|