// 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):
//
// db_dump: dump database views in XML format
//
// usage: [-d n] db_dump -dump_spec file
// -d debug level (1,2,3)
//
// dump_spec file:
//
// x
// x
//
//
// x
// x x = id, total_credit, expavg_credit
//
// ...
//
// ...
//
#include
#include
#include
#include
#include
#include
#include
#include
#include "boinc_db.h"
#include "util.h"
#include "error_numbers.h"
#include "md5_file.h"
#include "parse.h"
#include "sched_config.h"
#include "sched_util.h"
#include "sched_msgs.h"
using std::string;
using std::vector;
#define LOCKFILE "db_dump.out"
#define COMPRESSION_NONE 0
#define COMPRESSION_GZIP 1
#define COMPRESSION_ZIP 2
#define SORT_NONE 0
#define SORT_ID 1
#define SORT_TOTAL_CREDIT 2
#define SORT_EXPAVG_CREDIT 3
#define TABLE_USER 0
#define TABLE_TEAM 1
#define TABLE_HOST 2
// must match the above
char* table_name[3] = {"user", "team", "host"};
char* tag_name[3] = {"users", "teams", "hosts"};
struct OUTPUT {
int recs_per_file;
bool detail;
int compression;
class ZFILE* zfile;
class NUMBERED_ZFILE* nzfile;
int parse(FILE*);
};
struct ENUMERATION {
int table;
int sort;
char filename[256];
vector")) return 0;
if (parse_int(buf, "", recs_per_file)) continue;
if (match_tag(buf, "")) {
detail = true;
continue;
}
if (parse_str(buf, "", buf2, sizeof(buf2))) {
if (!strcmp(buf2, "gzip")) {
compression = COMPRESSION_GZIP;
} else if (!strcmp(buf2, "zip")) {
compression = COMPRESSION_ZIP;
} else {
log_messages.printf(
SCHED_MSG_LOG::CRITICAL,
"unrecognized compression type: %s", buf
);
}
continue;
}
log_messages.printf(
SCHED_MSG_LOG::CRITICAL,
"OUTPUT::parse: unrecognized: %s", buf
);
}
return ERR_XML_PARSE;
}
int ENUMERATION::parse(FILE* in) {
char buf[256], buf2[256];
int retval, i;
table = -1;
sort = SORT_NONE;
strcpy(filename, "");
while (fgets(buf, 256, in)) {
if (match_tag(buf, "")) {
if (table == -1) return ERR_XML_PARSE;
if (sort == -1) return ERR_XML_PARSE;
if (!strlen(filename)) return ERR_XML_PARSE;
return 0;
}
if (match_tag(buf, "