1 // This file is part of BOINC.
2 // http://boinc.berkeley.edu
3 // Copyright (C) 2008 University of California
4 //
5 // BOINC is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Lesser General Public License
7 // as published by the Free Software Foundation,
8 // either version 3 of the License, or (at your option) any later version.
9 //
10 // BOINC is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 // See the GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
17 
18 #ifndef BOINC_BACKEND_LIB_H
19 #define BOINC_BACKEND_LIB_H
20 
21 #include <limits.h>
22 
23 #include "crypt.h"
24 #include "sched_config.h"
25 #include "boinc_db.h"
26 
27 // describes an input file;
28 // either an argument to create_work(),
29 // or a <file_info> in input template
30 //
31 struct INFILE_DESC {
32     bool is_remote;
33 
34     // the following defined if remote (physical name is jf_MD5)
35     //
36     double nbytes;
37     char md5[64];
38     char url[1024];         // make this a vector to support multiple URLs
39 
40     // the following defined if not remote
41     //
42     char name[1024];     // physical name
43 };
44 
45 extern int add_signatures(char*, R_RSA_PRIVATE_KEY&);
46 extern int remove_signatures(char*);
47 
48 extern int process_result_template(
49     char* result_template,
50     R_RSA_PRIVATE_KEY& key,
51     char* base_filename,
52     SCHED_CONFIG&
53 );
54 
55 extern int read_file(FILE*, char* buf);
56 extern int read_filename(const char* path, char* buf, int len);
57 
58 extern void initialize_result(DB_RESULT&, DB_WORKUNIT&);
59 
60 extern int create_result(
61     WORKUNIT&,
62     char* result_template_filename,
63     char* suffix,
64     R_RSA_PRIVATE_KEY& key,
65     SCHED_CONFIG& config,
66     char* query_string=0,
67     int priority_increase=0
68 );
69 
70 extern int create_result_ti(
71     TRANSITIONER_ITEM&,
72     char* result_template_filename,
73     char* suffix,
74     R_RSA_PRIVATE_KEY& key,
75     SCHED_CONFIG& config,
76     char* query_string=0,
77     int priority_increase=0
78 );
79 
80 extern int create_work(
81     DB_WORKUNIT& wu,
82     const char* wu_template,
83     const char* result_template_filename,
84     const char* result_template_filepath,
85     const char** infiles,
86     int ninfiles,
87     SCHED_CONFIG&,
88     const char* command_line = NULL,
89     const char* additional_xml = NULL,
90     char* query_string = 0
91 );
92 
93 extern int create_work2(
94     DB_WORKUNIT& wu,
95     const char* wu_template,
96     const char* result_template_filename,
97     const char* result_template_filepath,
98     vector<INFILE_DESC>&,
99     SCHED_CONFIG&,
100     const char* command_line = NULL,
101     const char* additional_xml = NULL,
102     char* query_string = 0
103 );
104 
105 extern int stage_file(const char*, bool);
106 
107 // the following functions return XML that can be put in
108 // scheduler replies to do file operations
109 //
110 extern int put_file_xml(
111     const char* file_name, vector<const char*> urls,
112     const char* md5, double nbytes, double report_deadline,
113     char* buf
114 );
115 extern int get_file_xml(
116     const char* file_name, vector<const char*> urls,
117     double max_nbytes,
118     double report_deadline,
119     bool generate_upload_certificate,
120     R_RSA_PRIVATE_KEY& key,
121     char* buf
122 );
123 extern int delete_file_xml(
124     const char* file_name,
125     char* buf
126 );
127 
128 // the following 3 functions are for programs other than the scheduler
129 // to do file operations.
130 // They work by creating MSG_TO_HOST records in the DB,
131 // containing the needed XML
132 //
133 extern int create_put_file_msg(
134     int host_id, const char* file_name, vector<const char*> urls,
135     const char* md5, double nbytes, double report_deadline
136 );
137 
138 extern int create_get_file_msg(
139     int host_id, const char* file_name, vector<const char*> urls,
140     double max_nbytes,
141     double report_deadline,
142     bool generate_upload_certificate,
143     R_RSA_PRIVATE_KEY& key
144 );
145 
146 extern int create_delete_file_msg(
147     int host_id,
148     const char* file_name
149 );
150 
151 // cancel jobs from min_id to max_id inclusive
152 //
153 extern int cancel_jobs(int min_id, int max_id);
154 
155 // cancel a particular job
156 //
157 extern int cancel_job(DB_WORKUNIT&);
158 
159 extern int get_total_quota(double&);
160 extern int get_project_flops(double&);
161 extern double user_priority_delta(DB_USER_SUBMIT&, double, double, double);
162 
163 #endif
164