Exemple #1
0
/** Main function to parse the incoming xml from ctest */
function ctest_parse($filehandler, $projectid, $expected_md5 = '', $do_checksum = true, $scheduleid = 0)
{
    include 'cdash/config.php';
    require_once 'cdash/common.php';
    require_once 'models/project.php';
    include 'cdash/version.php';
    if ($CDASH_USE_LOCAL_DIRECTORY && file_exists("local/ctestparser.php")) {
        require_once "local/ctestparser.php";
        $localParser = new LocalParser();
        $localParser->SetProjectId($projectid);
        $localParser->BufferSizeMB = 8192 / (1024 * 1024);
    }
    // Check if this is a new style PUT submission.
    if (parse_put_submission($filehandler, $projectid, $expected_md5)) {
        return true;
    }
    $content = fread($filehandler, 8192);
    $handler = null;
    $parser = xml_parser_create();
    $file = "";
    if (preg_match('/<Update/', $content)) {
        $handler = new UpdateHandler($projectid, $scheduleid);
        $file = "Update";
    } else {
        if (preg_match('/<Build/', $content)) {
            $handler = new BuildHandler($projectid, $scheduleid);
            $file = "Build";
        } else {
            if (preg_match('/<Configure/', $content)) {
                $handler = new ConfigureHandler($projectid, $scheduleid);
                $file = "Configure";
            } else {
                if (preg_match('/<Testing/', $content)) {
                    $handler = new TestingHandler($projectid, $scheduleid);
                    $file = "Test";
                } else {
                    if (preg_match('/<CoverageLog/', $content)) {
                        $handler = new CoverageLogHandler($projectid, $scheduleid);
                        $file = "CoverageLog";
                    } else {
                        if (preg_match('/<Coverage/', $content)) {
                            $handler = new CoverageHandler($projectid, $scheduleid);
                            $file = "Coverage";
                        } else {
                            if (preg_match('/<report/', $content)) {
                                $handler = new CoverageJUnitHandler($projectid, $scheduleid);
                                $file = "Coverage";
                            } else {
                                if (preg_match('/<Notes/', $content)) {
                                    $handler = new NoteHandler($projectid, $scheduleid);
                                    $file = "Notes";
                                } else {
                                    if (preg_match('/<DynamicAnalysis/', $content)) {
                                        $handler = new DynamicAnalysisHandler($projectid, $scheduleid);
                                        $file = "DynamicAnalysis";
                                    } else {
                                        if (preg_match('/<Project/', $content)) {
                                            $handler = new ProjectHandler($projectid, $scheduleid);
                                            $file = "Project";
                                        } else {
                                            if (preg_match('/<Upload/', $content)) {
                                                $handler = new UploadHandler($projectid, $scheduleid);
                                                $file = "Upload";
                                            } else {
                                                if (preg_match('/<test-results/', $content)) {
                                                    $handler = new TestingNUnitHandler($projectid, $scheduleid);
                                                    $file = "Test";
                                                } else {
                                                    if (preg_match('/<testsuite/', $content)) {
                                                        $handler = new TestingJUnitHandler($projectid, $scheduleid);
                                                        $file = "Test";
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if ($handler == NULL) {
        echo "no handler found";
        add_log('error: could not create handler based on xml content', 'ctest_parse', LOG_ERR);
        $Project = new Project();
        $Project->Id = $projectid;
        // Try to get the IP of the build
        $ip = $_SERVER['REMOTE_ADDR'];
        $Project->SendEmailToAdmin('Cannot create handler based on XML content', 'An XML submission from ' . $ip . ' to the project ' . get_project_name($projectid) . ' cannot be parsed. The content of the file is as follow: ' . $content);
        return;
    }
    xml_set_element_handler($parser, array($handler, 'startElement'), array($handler, 'endElement'));
    xml_set_character_data_handler($parser, array($handler, 'text'));
    xml_parse($parser, $content, false);
    $projectname = get_project_name($projectid);
    $sitename = "";
    $buildname = "";
    $stamp = "";
    if ($file != "Project") {
        $sitename = $handler->getSiteName();
        $buildname = $handler->getBuildName();
        $stamp = $handler->getBuildStamp();
    }
    // Check if the build is in the block list
    $query = pdo_query("SELECT id FROM blockbuild WHERE projectid=" . qnum($projectid) . "\n                         AND (buildname='' OR buildname='" . $buildname . "')\n                         AND (sitename='' OR sitename='" . $sitename . "')\n                         AND (ipaddress='' OR ipaddress='" . $_SERVER['REMOTE_ADDR'] . "')");
    if (pdo_num_rows($query) > 0) {
        echo $query_array['id'];
        echo "The submission is banned from this CDash server.";
        add_log("Submission is banned from this CDash server", "ctestparser");
        return;
    }
    // Write the file to the backup directory.
    $filename = writeBackupFile($filehandler, $content, $projectname, $buildname, $sitename, $stamp, $file . ".xml");
    if ($filename === false) {
        return $handler;
    }
    $statusarray = array();
    $statusarray['status'] = 'OK';
    $statusarray['message'] = '';
    if ($do_checksum == true) {
        $md5sum = md5_file($filename);
        $md5error = false;
        if ($expected_md5 == '' || $expected_md5 == $md5sum) {
            $statusarray['status'] = 'OK';
        } else {
            $statusarray['status'] = 'ERROR';
            $statusarray['message'] = 'Checksum failed for file. Expected ' . $expected_md5 . ' but got ' . $md5sum;
            $md5error = true;
        }
        $statusarray['md5'] = $md5sum;
        if ($md5error) {
            displayReturnStatus($statusarray);
            add_log("Checksum failure on file: {$filename}", "ctest_parse", LOG_ERR, $projectid);
            return FALSE;
        }
    }
    $parsingerror = '';
    if ($CDASH_USE_LOCAL_DIRECTORY && file_exists("local/ctestparser.php")) {
        $parsingerror = $localParser->StartParsing();
        if ($parsingerror != '') {
            $statusarray['status'] = 'ERROR';
            $statusarray['message'] = $parsingerror;
            displayReturnStatus($statusarray);
            exit;
        }
    }
    if (!($parseHandle = fopen($filename, 'r'))) {
        $statusarray['status'] = 'ERROR';
        $statusarray['message'] = "ERROR: Cannot open file ({$filename})";
        displayReturnStatus($statusarray);
        add_log("Cannot open file ({$filename})", "parse_xml_file", LOG_ERR);
        return $handler;
    }
    //burn the first 8192 since we have already parsed it
    $content = fread($parseHandle, 8192);
    while (!feof($parseHandle)) {
        $content = fread($parseHandle, 8192);
        if ($CDASH_USE_LOCAL_DIRECTORY && file_exists("local/ctestparser.php")) {
            $parsingerror = $localParser->ParseFile();
            if ($parsingerror != '') {
                $statusarray['status'] = 'ERROR';
                $statusarray['message'] = $parsingerror;
                displayReturnStatus($statusarray);
                exit;
            }
        }
        xml_parse($parser, $content, false);
    }
    xml_parse($parser, null, true);
    xml_parser_free($parser);
    fclose($parseHandle);
    unset($parseHandle);
    if ($CDASH_USE_LOCAL_DIRECTORY && file_exists("local/ctestparser.php")) {
        $parsingerror = $localParser->EndParsingFile();
    }
    displayReturnStatus($statusarray);
    return $handler;
}
Exemple #2
0
/** Main function to parse the incoming xml from ctest */
function ctest_parse($filehandler, $projectid, $expected_md5 = '', $do_checksum = true, $scheduleid = 0)
{
    include 'config/config.php';
    require_once 'include/common.php';
    require_once 'models/project.php';
    include 'include/version.php';
    global $CDASH_USE_LOCAL_DIRECTORY;
    if ($CDASH_USE_LOCAL_DIRECTORY && file_exists('local/ctestparser.php')) {
        require_once 'local/ctestparser.php';
        $localParser = new LocalParser();
        $localParser->SetProjectId($projectid);
        $localParser->BufferSizeMB = 8192 / (1024 * 1024);
    }
    // Check if this is a new style PUT submission.
    if (parse_put_submission($filehandler, $projectid, $expected_md5)) {
        return true;
    }
    $content = fread($filehandler, 8192);
    $handler = null;
    $parser = xml_parser_create();
    $file = '';
    if (preg_match('/<Update/', $content)) {
        // Should be first otherwise confused with Build
        $handler = new UpdateHandler($projectid, $scheduleid);
        $file = 'Update';
    } elseif (preg_match('/<Build/', $content)) {
        $handler = new BuildHandler($projectid, $scheduleid);
        $file = 'Build';
    } elseif (preg_match('/<Configure/', $content)) {
        $handler = new ConfigureHandler($projectid, $scheduleid);
        $file = 'Configure';
    } elseif (preg_match('/<Testing/', $content)) {
        $handler = new TestingHandler($projectid, $scheduleid);
        $file = 'Test';
    } elseif (preg_match('/<CoverageLog/', $content)) {
        // Should be before coverage
        $handler = new CoverageLogHandler($projectid, $scheduleid);
        $file = 'CoverageLog';
    } elseif (preg_match('/<Coverage/', $content)) {
        $handler = new CoverageHandler($projectid, $scheduleid);
        $file = 'Coverage';
    } elseif (preg_match('/<report/', $content)) {
        $handler = new CoverageJUnitHandler($projectid, $scheduleid);
        $file = 'Coverage';
    } elseif (preg_match('/<Notes/', $content)) {
        $handler = new NoteHandler($projectid, $scheduleid);
        $file = 'Notes';
    } elseif (preg_match('/<DynamicAnalysis/', $content)) {
        $handler = new DynamicAnalysisHandler($projectid, $scheduleid);
        $file = 'DynamicAnalysis';
    } elseif (preg_match('/<Project/', $content)) {
        $handler = new ProjectHandler($projectid, $scheduleid);
        $file = 'Project';
    } elseif (preg_match('/<Upload/', $content)) {
        $handler = new UploadHandler($projectid, $scheduleid);
        $file = 'Upload';
    } elseif (preg_match('/<test-results/', $content)) {
        $handler = new TestingNUnitHandler($projectid, $scheduleid);
        $file = 'Test';
    } elseif (preg_match('/<testsuite/', $content)) {
        $handler = new TestingJUnitHandler($projectid, $scheduleid);
        $file = 'Test';
    }
    // Try to get the IP of the build
    global $CDASH_REMOTE_ADDR;
    $ip = $CDASH_REMOTE_ADDR ? $CDASH_REMOTE_ADDR : $_SERVER['REMOTE_ADDR'];
    if ($handler == null) {
        echo 'no handler found';
        add_log('error: could not create handler based on xml content', 'ctest_parse', LOG_ERR);
        $Project = new Project();
        $Project->Id = $projectid;
        $Project->SendEmailToAdmin('Cannot create handler based on XML content', 'An XML submission from ' . $ip . ' to the project ' . get_project_name($projectid) . ' cannot be parsed. The content of the file is as follow: ' . $content);
        return false;
    }
    xml_set_element_handler($parser, array($handler, 'startElement'), array($handler, 'endElement'));
    xml_set_character_data_handler($parser, array($handler, 'text'));
    xml_parse($parser, $content, false);
    $projectname = get_project_name($projectid);
    $sitename = '';
    $buildname = '';
    $stamp = '';
    if ($file != 'Project') {
        // projects don't have some of these fields.
        $sitename = $handler->getSiteName();
        $buildname = $handler->getBuildName();
        $stamp = $handler->getBuildStamp();
    }
    // Check if the build is in the block list
    $query = pdo_query('SELECT id FROM blockbuild WHERE projectid=' . qnum($projectid) . "\n            AND (buildname='' OR buildname='" . $buildname . "')\n            AND (sitename='' OR sitename='" . $sitename . "')\n            AND (ipaddress='' OR ipaddress='" . $ip . "')");
    if (pdo_num_rows($query) > 0) {
        echo 'The submission is banned from this CDash server.';
        add_log('Submission is banned from this CDash server', 'ctestparser');
        return false;
    }
    // If backups are disabled, switch the filename to that of the existing handle
    // Otherwise, create a backup file and process from that
    global $CDASH_BACKUP_TIMEFRAME;
    if ($CDASH_BACKUP_TIMEFRAME == '0') {
        $meta_data = stream_get_meta_data($filehandler);
        $filename = $meta_data['uri'];
    } else {
        $filename = writeBackupFile($filehandler, $content, $projectname, $buildname, $sitename, $stamp, $file . '.xml');
        if ($filename === false) {
            return $handler;
        }
    }
    $statusarray = array();
    $statusarray['status'] = 'OK';
    $statusarray['message'] = '';
    if ($do_checksum == true) {
        $md5sum = md5_file($filename);
        $md5error = false;
        if ($expected_md5 == '' || $expected_md5 == $md5sum) {
            $statusarray['status'] = 'OK';
        } else {
            $statusarray['status'] = 'ERROR';
            $statusarray['message'] = 'Checksum failed for file. Expected ' . $expected_md5 . ' but got ' . $md5sum;
            $md5error = true;
        }
        $statusarray['md5'] = $md5sum;
        if ($md5error) {
            displayReturnStatus($statusarray);
            add_log("Checksum failure on file: {$filename}", 'ctest_parse', LOG_ERR, $projectid);
            return false;
        }
    }
    $parsingerror = '';
    if ($CDASH_USE_LOCAL_DIRECTORY && file_exists('local/ctestparser.php')) {
        $parsingerror = $localParser->StartParsing();
        if ($parsingerror != '') {
            $statusarray['status'] = 'ERROR';
            $statusarray['message'] = $parsingerror;
            displayReturnStatus($statusarray);
            exit;
        }
    }
    if (!($parseHandle = fopen($filename, 'r'))) {
        $statusarray['status'] = 'ERROR';
        $statusarray['message'] = "ERROR: Cannot open file ({$filename})";
        displayReturnStatus($statusarray);
        add_log("Cannot open file ({$filename})", 'parse_xml_file', LOG_ERR);
        return $handler;
    }
    //burn the first 8192 since we have already parsed it
    $content = fread($parseHandle, 8192);
    while (!feof($parseHandle)) {
        $content = fread($parseHandle, 8192);
        if ($CDASH_USE_LOCAL_DIRECTORY && file_exists('local/ctestparser.php')) {
            $parsingerror = $localParser->ParseFile();
            if ($parsingerror != '') {
                $statusarray['status'] = 'ERROR';
                $statusarray['message'] = $parsingerror;
                displayReturnStatus($statusarray);
                exit;
            }
        }
        xml_parse($parser, $content, false);
    }
    xml_parse($parser, null, true);
    xml_parser_free($parser);
    fclose($parseHandle);
    unset($parseHandle);
    if ($CDASH_USE_LOCAL_DIRECTORY && file_exists('local/ctestparser.php')) {
        $parsingerror = $localParser->EndParsingFile();
    }
    check_for_immediate_deletion($filename);
    displayReturnStatus($statusarray);
    return $handler;
}