2003-06-11 23:36:48 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
2002-04-30 22:22:54 +00:00
|
|
|
// 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
|
2003-06-11 23:36:48 +00:00
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// 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
|
2004-07-13 13:54:09 +00:00
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
2004-07-13 13:54:09 +00:00
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
2002-04-30 22:22:54 +00:00
|
|
|
// Contributor(s):
|
|
|
|
//
|
|
|
|
|
2003-10-16 19:03:49 +00:00
|
|
|
#include "cpp.h"
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
2002-04-30 22:22:54 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "http.h"
|
|
|
|
#include "file_xfer.h"
|
2002-06-06 22:49:07 +00:00
|
|
|
#include "util.h"
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
#define DOWNLOAD_URL "http://localhost.localdomain/download/input"
|
2002-07-05 05:33:40 +00:00
|
|
|
#define UPLOAD_URL "http://localhost.localdomain/boinc-cgi/file_upload_handler"
|
|
|
|
|
2002-08-07 22:52:10 +00:00
|
|
|
// Skeleton class to force compilation
|
|
|
|
class PERS_FILE_XFER {
|
|
|
|
public:
|
|
|
|
int write(FILE* fout);
|
|
|
|
int parse(FILE* fin);
|
2003-02-05 19:16:33 +00:00
|
|
|
PERS_FILE_XFER();
|
2002-08-07 22:52:10 +00:00
|
|
|
};
|
|
|
|
|
2003-02-05 19:16:33 +00:00
|
|
|
PERS_FILE_XFER::PERS_FILE_XFER() {
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
|
|
|
|
int main() {
|
|
|
|
NET_XFER_SET nxs;
|
|
|
|
HTTP_OP_SET hos(&nxs);
|
|
|
|
FILE_XFER_SET fxs(&hos);
|
2003-02-26 00:47:57 +00:00
|
|
|
int retval;
|
2002-07-05 05:33:40 +00:00
|
|
|
FILE_XFER* fx1=0, *fx2 = 0;
|
|
|
|
bool do_upload = true;
|
|
|
|
bool do_download = false;
|
|
|
|
FILE_INFO fi1, fi2;
|
|
|
|
STRING256 str;
|
2002-04-30 22:22:54 +00:00
|
|
|
|
2002-07-05 05:33:40 +00:00
|
|
|
if (do_download) {
|
|
|
|
fx1 = new FILE_XFER;
|
|
|
|
memset(&fi1, 0, sizeof(fi1));
|
|
|
|
strcpy(fi1.name, "test_fx_out");
|
|
|
|
strcpy(str.text, DOWNLOAD_URL);
|
|
|
|
fi1.urls.push_back(str);
|
|
|
|
retval = fx1->init_download(fi1);
|
|
|
|
if (retval) {
|
|
|
|
printf("init_download failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
retval = fxs.insert(fx1);
|
|
|
|
if (retval) {
|
|
|
|
printf("insert failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
2002-07-05 05:33:40 +00:00
|
|
|
if (do_upload) {
|
|
|
|
fx2= new FILE_XFER;
|
|
|
|
memset(&fi2, 0, sizeof(fi1));
|
|
|
|
strcpy(fi2.name, "test_fx_in");
|
|
|
|
strcpy(str.text, UPLOAD_URL);
|
|
|
|
fi2.urls.push_back(str);
|
2003-02-11 00:52:44 +00:00
|
|
|
strcpy(fi2.signed_xml,
|
2002-07-05 05:33:40 +00:00
|
|
|
" <name>uc_wu_1_0</name>\n"
|
|
|
|
" <generated_locally/>\n"
|
|
|
|
" <upload_when_present/>\n"
|
|
|
|
" <max_nbytes>10000</max_nbytes>\n"
|
2003-02-11 00:52:44 +00:00
|
|
|
" <url>http://localhost/upload/uc_wu_1_0</url>\n"
|
|
|
|
);
|
|
|
|
strcpy(fi2.xml_signature,
|
2002-07-05 05:33:40 +00:00
|
|
|
"9d1f8152371c67af1d26b25db104014dbf7e9ad3b61fc8334ee06e01c7529b1a\n"
|
|
|
|
"7681c3e7c7828525361a01040d1197147286085231ee5d2554e59ecb40b3e6a5\n"
|
|
|
|
"afbaf00ff15bc5b1acf5aa6318bc84f2671a9502ada9c2ce37a9c45480a0e3b7\n"
|
|
|
|
"b3dcb6c3bf09feaebc81b76063ef12b0031cf041eaef811166839533067b74f6\n"
|
2003-02-11 00:52:44 +00:00
|
|
|
".\n"
|
|
|
|
);
|
2002-07-05 05:33:40 +00:00
|
|
|
retval = fx2->init_upload(fi2);
|
|
|
|
if (retval) {
|
|
|
|
printf("init_upload failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
retval = fxs.insert(fx2);
|
|
|
|
if (retval) {
|
|
|
|
printf("insert failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
2003-02-26 00:47:57 +00:00
|
|
|
nxs.poll();
|
2002-04-30 22:22:54 +00:00
|
|
|
hos.poll();
|
|
|
|
fxs.poll();
|
|
|
|
if (fx1 && fx1->file_xfer_done) {
|
|
|
|
printf("download done; status %d\n", fx1->file_xfer_retval);
|
|
|
|
fxs.remove(fx1);
|
|
|
|
fx1 = 0;
|
|
|
|
}
|
|
|
|
if (fx2 && fx2->file_xfer_done) {
|
|
|
|
printf("upload done; status %d\n", fx2->file_xfer_retval);
|
|
|
|
fxs.remove(fx2);
|
|
|
|
fx2 = 0;
|
|
|
|
}
|
|
|
|
if (!fx1 && !fx2) break;
|
2003-03-11 22:18:01 +00:00
|
|
|
boinc_sleep(1.);
|
2002-04-30 22:22:54 +00:00
|
|
|
}
|
|
|
|
printf("all done\n");
|
|
|
|
}
|
2002-08-07 22:52:10 +00:00
|
|
|
|
|
|
|
// Skeleton function to force compilation
|
|
|
|
int PERS_FILE_XFER::parse(FILE* fin) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skeleton function to force compilation
|
|
|
|
int PERS_FILE_XFER::write(FILE* fout) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-12-08 00:40:19 +00:00
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
static volatile const char __attribute__((unused)) *BOINCrcsid="$Id$";
|
|
|
|
#else
|
|
|
|
static volatile const char *BOINCrcsid="$Id$";
|
|
|
|
#endif
|