2002-04-30 22:22:54 +00:00
|
|
|
// The contents of this file are subject to the Mozilla 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://www.mozilla.org/MPL/
|
|
|
|
//
|
|
|
|
// 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):
|
|
|
|
//
|
|
|
|
|
|
|
|
// create_work
|
|
|
|
// -appname name
|
2002-10-03 18:33:46 +00:00
|
|
|
// -download_dir x
|
2002-04-30 22:22:54 +00:00
|
|
|
// -rsc_fpops n
|
|
|
|
// -rsc_iops n
|
|
|
|
// -rsc_memory n
|
|
|
|
// -rsc_disk n
|
|
|
|
// -dynamic_results
|
|
|
|
// -wu_name name
|
|
|
|
// -wu_template filename
|
|
|
|
// -result_template filename
|
|
|
|
// -nresults n
|
2002-07-05 05:33:40 +00:00
|
|
|
// -keyfile path
|
2002-04-30 22:22:54 +00:00
|
|
|
// infile1 infile2 ...
|
|
|
|
//
|
|
|
|
// Create a workunit and results.
|
|
|
|
// Input files must be in the download dir.
|
|
|
|
// template-doc is an XML WU description file, with the following macros:
|
|
|
|
// INFILEn gets replaced by the name of input file n
|
|
|
|
// MD5n gets replaced by the MD5 checksum of input file n
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2002-07-01 19:30:58 +00:00
|
|
|
#include <time.h>
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#include "db.h"
|
2002-07-05 05:33:40 +00:00
|
|
|
#include "crypt.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
#include "backend_lib.h"
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
APP app;
|
|
|
|
WORKUNIT wu;
|
|
|
|
int retval;
|
|
|
|
char wu_template[MAX_BLOB_SIZE];
|
|
|
|
char result_template[MAX_BLOB_SIZE];
|
|
|
|
char wu_template_file[256], result_template_file[256];
|
2002-07-05 05:33:40 +00:00
|
|
|
char keyfile[256];
|
2002-04-30 22:22:54 +00:00
|
|
|
char** infiles;
|
|
|
|
int i, ninfiles, nresults;
|
2002-07-05 05:33:40 +00:00
|
|
|
R_RSA_PRIVATE_KEY key;
|
2002-10-03 18:33:46 +00:00
|
|
|
char download_dir[256], db_name[256], db_passwd[256];
|
|
|
|
char upload_url[256], download_url[256];
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-07-01 19:30:58 +00:00
|
|
|
srand(time(NULL));
|
2002-04-30 22:22:54 +00:00
|
|
|
strcpy(wu_template_file, "");
|
|
|
|
strcpy(result_template_file, "");
|
|
|
|
strcpy(app.name, "");
|
2002-10-03 18:33:46 +00:00
|
|
|
strcpy(db_passwd, "");
|
2002-07-05 05:33:40 +00:00
|
|
|
strcpy(keyfile, "");
|
2002-04-30 22:22:54 +00:00
|
|
|
nresults = 1;
|
|
|
|
i = 1;
|
|
|
|
ninfiles = 0;
|
|
|
|
memset(&wu, 0, sizeof(wu));
|
|
|
|
while (i < argc) {
|
|
|
|
if (!strcmp(argv[i], "-appname")) {
|
|
|
|
i++;
|
|
|
|
strcpy(app.name, argv[i]);
|
2002-10-03 18:33:46 +00:00
|
|
|
} else if (!strcmp(argv[i], "-db_name")) {
|
|
|
|
strcpy(db_name, argv[++i]);
|
|
|
|
} else if (!strcmp(argv[i], "-db_passwd")) {
|
|
|
|
strcpy(db_passwd, argv[++i]);
|
|
|
|
} else if (!strcmp(argv[i], "-upload_url")) {
|
|
|
|
strcpy(upload_url, argv[++i]);
|
|
|
|
} else if (!strcmp(argv[i], "-download_url")) {
|
|
|
|
strcpy(download_url, argv[++i]);
|
|
|
|
} else if (!strcmp(argv[i], "-download_dir")) {
|
|
|
|
strcpy(download_dir, argv[++i]);
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (!strcmp(argv[i], "-wu_name")) {
|
|
|
|
i++;
|
|
|
|
strcpy(wu.name, argv[i]);
|
|
|
|
} else if (!strcmp(argv[i], "-wu_template")) {
|
|
|
|
i++;
|
|
|
|
strcpy(wu_template_file, argv[i]);
|
|
|
|
} else if (!strcmp(argv[i], "-result_template")) {
|
|
|
|
i++;
|
|
|
|
strcpy(result_template_file, argv[i]);
|
|
|
|
} else if (!strcmp(argv[i], "-dynamic_results")) {
|
|
|
|
wu.dynamic_results = true;
|
|
|
|
} else if (!strcmp(argv[i], "-nresults")) {
|
|
|
|
i++;
|
|
|
|
nresults = atoi(argv[i]);
|
|
|
|
} else if (!strcmp(argv[i], "-rsc_fpops")) {
|
|
|
|
i++;
|
2002-07-05 21:17:28 +00:00
|
|
|
wu.rsc_fpops = atof(argv[i]);
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (!strcmp(argv[i], "-rsc_iops")) {
|
|
|
|
i++;
|
2002-07-05 21:17:28 +00:00
|
|
|
wu.rsc_iops = atof(argv[i]);
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (!strcmp(argv[i], "-rsc_memory")) {
|
|
|
|
i++;
|
2002-07-05 21:17:28 +00:00
|
|
|
wu.rsc_memory = atof(argv[i]);
|
2002-04-30 22:22:54 +00:00
|
|
|
} else if (!strcmp(argv[i], "-rsc_disk")) {
|
|
|
|
i++;
|
2002-07-05 05:33:40 +00:00
|
|
|
wu.rsc_disk = atof(argv[i]);
|
|
|
|
} else if (!strcmp(argv[i], "-keyfile")) {
|
|
|
|
i++;
|
|
|
|
strcpy(keyfile, argv[i]);
|
2002-07-01 19:30:58 +00:00
|
|
|
} else if (!strcmp(argv[i], "-wu_name_rand")) {
|
|
|
|
i++;
|
|
|
|
sprintf(wu.name, "%s_%d", argv[i], rand());
|
2002-04-30 22:22:54 +00:00
|
|
|
} else {
|
|
|
|
infiles = argv+i;
|
|
|
|
ninfiles = argc - i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (!strlen(app.name) || !strlen(wu.name) || !strlen(wu_template_file)
|
|
|
|
|| !strlen(result_template_file)
|
|
|
|
) {
|
2002-10-03 18:33:46 +00:00
|
|
|
fprintf(stderr, "create_work: bad cmdline\n");
|
2002-04-30 22:22:54 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2002-10-03 18:33:46 +00:00
|
|
|
if (db_open(db_name, db_passwd)) {
|
|
|
|
fprintf(stderr, "create_work: error opening database.\n" );
|
|
|
|
exit(0);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
retval = db_app_lookup_name(app);
|
|
|
|
if (retval) {
|
2002-10-03 18:33:46 +00:00
|
|
|
fprintf(stderr, "create_work: app not found\n");
|
2002-04-30 22:22:54 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2002-07-12 18:24:58 +00:00
|
|
|
|
|
|
|
//fprintf(stderr, "wu_template = %s\n", wu_template);
|
2002-07-05 05:33:40 +00:00
|
|
|
retval = read_filename(wu_template_file, wu_template);
|
|
|
|
if (retval) {
|
2002-10-03 18:33:46 +00:00
|
|
|
fprintf(stderr, "create_work: can't open WU template\n");
|
2002-07-05 05:33:40 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wu.dynamic_results) {
|
|
|
|
strcpy(app.result_xml_template, result_template);
|
|
|
|
retval = db_app_update(app);
|
2002-10-03 18:33:46 +00:00
|
|
|
if (retval) fprintf(stderr, "create_work: db_app_update: %d\n", retval);
|
2002-07-05 05:33:40 +00:00
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
wu.appid = app.id;
|
2002-07-05 05:33:40 +00:00
|
|
|
|
|
|
|
FILE* fkey = fopen(keyfile, "r");
|
|
|
|
if (!fkey) {
|
2002-10-03 18:33:46 +00:00
|
|
|
fprintf(stderr, "create_work: can't open key file (%s)\n", keyfile);
|
2002-07-05 05:33:40 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2002-10-03 18:33:46 +00:00
|
|
|
rewind(fkey);
|
2002-07-05 05:33:40 +00:00
|
|
|
retval = scan_key_hex(fkey, (KEY*)&key, sizeof(key));
|
|
|
|
fclose(fkey);
|
|
|
|
if (retval) {
|
2002-10-03 18:33:46 +00:00
|
|
|
fprintf(stderr, "create_work: can't parse key\n");
|
2002-07-05 05:33:40 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2002-04-30 22:22:54 +00:00
|
|
|
retval = create_work(
|
|
|
|
wu,
|
|
|
|
wu_template,
|
2002-07-05 05:33:40 +00:00
|
|
|
result_template_file,
|
2002-04-30 22:22:54 +00:00
|
|
|
nresults,
|
2002-10-03 18:33:46 +00:00
|
|
|
download_dir,
|
2002-04-30 22:22:54 +00:00
|
|
|
infiles,
|
2002-07-05 05:33:40 +00:00
|
|
|
ninfiles,
|
2002-10-03 18:33:46 +00:00
|
|
|
key,
|
|
|
|
upload_url,
|
|
|
|
download_url
|
2002-04-30 22:22:54 +00:00
|
|
|
);
|
2002-07-05 05:33:40 +00:00
|
|
|
if (retval) fprintf(stderr, "create_work: %d\n", retval);
|
2002-04-30 22:22:54 +00:00
|
|
|
db_close();
|
|
|
|
}
|