mirror of https://github.com/BOINC/boinc.git
Improve error reporting for XML RPCs
- If handling an XML RPC, use set_error_handler() to output PHP warnings as XML. Otherwise they appear as strings in the XML reply, making them not parse. - suppress warnings from PHP function calls where we're already checking errors
This commit is contained in:
parent
7a431cc54f
commit
e11b62adab
|
@ -16,7 +16,7 @@
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
// PHP versions of functions in sched/sched_util.C
|
// PHP versions of functions in sched/sched_util.cpp
|
||||||
|
|
||||||
function filename_hash($filename, $fanout) {
|
function filename_hash($filename, $fanout) {
|
||||||
$m = md5($filename);
|
$m = md5($filename);
|
||||||
|
|
|
@ -44,7 +44,7 @@ function show_page($x, $y) {
|
||||||
";
|
";
|
||||||
}
|
}
|
||||||
|
|
||||||
function xml_error($num, $msg=null) {
|
function xml_error($num, $msg=null, $file=null, $line=null) {
|
||||||
if (!$msg) {
|
if (!$msg) {
|
||||||
switch($num) {
|
switch($num) {
|
||||||
case -112: $msg = "Invalid XML"; break;
|
case -112: $msg = "Invalid XML"; break;
|
||||||
|
@ -64,8 +64,14 @@ function xml_error($num, $msg=null) {
|
||||||
echo "<error>
|
echo "<error>
|
||||||
<error_num>$num</error_num>
|
<error_num>$num</error_num>
|
||||||
<error_msg>$msg</error_msg>
|
<error_msg>$msg</error_msg>
|
||||||
</error>
|
|
||||||
";
|
";
|
||||||
|
if ($file) {
|
||||||
|
echo " <file>$file</file>\n";
|
||||||
|
}
|
||||||
|
if ($line) {
|
||||||
|
echo " <line>$line</line>\n";
|
||||||
|
}
|
||||||
|
echo "</error>\n";
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,19 @@ function db_init_xml() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handler($errno, $errstr, $errfile, $errline) {
|
||||||
|
echo "<error>
|
||||||
|
<error_msg>$errstr</error_msg>
|
||||||
|
<file>$errfile</file>
|
||||||
|
<line>$errline</line>
|
||||||
|
</error>
|
||||||
|
";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function xml_header() {
|
function xml_header() {
|
||||||
global $generating_xml;
|
global $generating_xml;
|
||||||
|
set_error_handler('handler', E_ALL);
|
||||||
header('Content-type: text/xml');
|
header('Content-type: text/xml');
|
||||||
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
|
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
|
||||||
$generating_xml = true;
|
$generating_xml = true;
|
||||||
|
|
|
@ -192,7 +192,7 @@ if (0) {
|
||||||
xml_header();
|
xml_header();
|
||||||
$r = simplexml_load_string($_POST['request']);
|
$r = simplexml_load_string($_POST['request']);
|
||||||
if (!$r) {
|
if (!$r) {
|
||||||
xml_error(-1, "can't parse request message");
|
xml_error(-1, "can't parse request message", __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch($r->getName()) {
|
switch($r->getName()) {
|
||||||
|
|
|
@ -117,8 +117,6 @@ function handle_edit_form() {
|
||||||
}
|
}
|
||||||
$q = (string) $usub->quota;
|
$q = (string) $usub->quota;
|
||||||
$mj = $usub->max_jobs_in_progress;
|
$mj = $usub->max_jobs_in_progress;
|
||||||
$sav = $usub->create_app_versions?"checked":"";
|
|
||||||
$sa = $usub->create_apps?"checked":"";
|
|
||||||
echo "
|
echo "
|
||||||
<p>
|
<p>
|
||||||
Quota: <input name=quota value=$q>
|
Quota: <input name=quota value=$q>
|
||||||
|
|
|
@ -132,28 +132,28 @@ function stage_file($file) {
|
||||||
// read the file (from disk or network) to get MD5.
|
// read the file (from disk or network) to get MD5.
|
||||||
// Copy to download hier, using a physical name based on MD5
|
// Copy to download hier, using a physical name based on MD5
|
||||||
//
|
//
|
||||||
$md5 = md5_file($file->source);
|
$md5 = @md5_file($file->source);
|
||||||
if (!$md5) {
|
if (!$md5) {
|
||||||
xml_error(-1, "BOINC server: Can't get MD5 of file $file->source");
|
xml_error(-1, "BOINC server: Can't get MD5 of file $file->source");
|
||||||
}
|
}
|
||||||
$name = "jf_$md5";
|
$name = "jf_$md5";
|
||||||
$path = dir_hier_path($name, $download_dir, $fanout);
|
$path = dir_hier_path($name, $download_dir, $fanout);
|
||||||
if (file_exists($path)) return $name;
|
if (file_exists($path)) return $name;
|
||||||
if (!copy($file->source, $path)) {
|
if (!@copy($file->source, $path)) {
|
||||||
xml_error(-1, "BOINC server: can't copy file from $file->source to $path");
|
xml_error(-1, "BOINC server: can't copy file from $file->source to $path");
|
||||||
}
|
}
|
||||||
return $name;
|
return $name;
|
||||||
case "local_staged":
|
case "local_staged":
|
||||||
return $file->source;
|
return $file->source;
|
||||||
case "inline":
|
case "inline":
|
||||||
$md5 = md5($file->source);
|
$md5 = @md5($file->source);
|
||||||
if (!$md5) {
|
if (!$md5) {
|
||||||
xml_error(-1, "BOINC server: Can't get MD5 of inline data");
|
xml_error(-1, "BOINC server: Can't get MD5 of inline data");
|
||||||
}
|
}
|
||||||
$name = "jf_$md5";
|
$name = "jf_$md5";
|
||||||
$path = dir_hier_path($name, $download_dir, $fanout);
|
$path = dir_hier_path($name, $download_dir, $fanout);
|
||||||
if (file_exists($path)) return $name;
|
if (file_exists($path)) return $name;
|
||||||
if (!file_put_contents($path, $file->source)) {
|
if (!@file_put_contents($path, $file->source)) {
|
||||||
xml_error(-1, "BOINC server: can't write to file $path");
|
xml_error(-1, "BOINC server: can't write to file $path");
|
||||||
}
|
}
|
||||||
return $name;
|
return $name;
|
||||||
|
|
Loading…
Reference in New Issue