コード例 #1
0
    exit(-1);
}
/* Loop through $GoodDir files */
$FileCount = 0;
$GoodFileCount = 0;
$BadFileCount = 0;
while (($FileName = readdir($DirH)) !== false) {
    if ($FileName[0] == '.') {
        continue;
    }
    $FileCount++;
    /* $FileName is a URL, hit it and save the results. */
    $URL = $WebHost . "/{$FileName}";
    //echo "URL is $URL\n";
    $ch = curl_init($URL);
    SetCurlArgs($ch);
    $contents = curl_exec($ch);
    curl_close($ch);
    /* Save the output in $OutputDir */
    $OutFileName = $OutputDir . "/{$FileName}";
    if (file_put_contents($OutFileName, $contents) === false) {
        echo "Failed to write contents to {$OutFileName}.\n";
    }
    /* Get the good file contents */
    $GoodFileName = $GoodDir . "{$FileName}";
    if (($GoodContents = file_get_contents($GoodFileName)) === false) {
        echo "Failed to read good contents from {$GoodFileName}.\n";
    }
    /* compare good and output file contents */
    if ($GoodContents != $contents) {
        echo "Regression found: Baseline is {$GoodFileName}, new content is {$OutFileName}\n";
コード例 #2
0
ファイル: fo_antelink.php プロジェクト: DanielDobre/fossology
/**
 * @brief Query the Antelink public server and tag the results.
 * @param $ToAntelink array of pfile_fk, pfile_sha1, ufile_name records
 * @param $tag_pk 
 * @param $PrintOnly print the raw antelink data, do not update the db.  Used for debugging.
 * @parma $Verbose   print project name.
 * @return number of tagged files.
 **/
function QueryTag($ToAntelink, $tag_pk, $PrintOnly, $Verbose)
{
    global $PG_CONN;
    global $acmequeryurl;
    $numTagged = 0;
    /* construct array of arrays of name and sha1's */
    $files = array();
    foreach ($ToAntelink as $row) {
        $file['hash'] = $row['pfile_sha1'];
        $file['name'] = $row['ufile_name'];
        $files[] = $file;
    }
    $request['files'] = $files;
    $PostData = json_encode($request);
    $curlch = curl_init($acmequeryurl);
    SetCurlArgs($curlch);
    curl_setopt($curlch, CURLOPT_POST, TRUE);
    curl_setopt($curlch, CURLOPT_POSTFIELDS, $PostData);
    curl_setopt($curlch, CURLOPT_RETURNTRANSFER, TRUE);
    //getting response from server
    $response = curl_exec($curlch);
    if (curl_errno($curlch)) {
        // Fatal: display curl errors
        echo "Error " . curl_errno($curlch) . ": " . curl_error($curlch) . "\n";
        return 0;
        //    exit;
    }
    //closing the curl
    curl_close($curlch);
    $response = json_decode($response);
    //echo "response\n";
    //print_r($response);
    // print any errors
    if ($response->error) {
        echo $response->error . "\n";
    }
    /* Add tag or print */
    if (is_array($response->results)) {
        foreach ($response->results as $result) {
            $row = GetRawRow($result->sha1, $ToAntelink);
            if ($PrintOnly) {
                if (!empty($row)) {
                    print_r($row);
                }
                // echo $row['ufile_name'] . "\n";
                print_r($result);
                continue;
            }
            foreach ($result->projects as $project) {
                /* check if acme_project already exists (check if the url is unique) */
                $url = pg_escape_string($PG_CONN, $project->url);
                $name = pg_escape_string($PG_CONN, $project->name);
                $acme_project_pk = '';
                $sql = "SELECT acme_project_pk from acme_project where url='{$url}' and project_name='{$name}'";
                $sqlresult = pg_query($PG_CONN, $sql);
                DBCheckResult($sqlresult, $sql, __FILE__, __LINE__);
                if (pg_num_rows($sqlresult) > 0) {
                    $projrow = pg_fetch_assoc($sqlresult);
                    $acme_project_pk = $projrow['acme_project_pk'];
                }
                pg_free_result($sqlresult);
                if (empty($acme_project_pk)) {
                    /* this is a new acme_project, so write the acme_project record */
                    $acme_project_pk = writeacme_project($project, $Verbose);
                }
                /* write the acme_pfile record */
                writeacme_pfile($acme_project_pk, $row['pfile_pk']);
                /* Tag the pfile (update tag_file table) */
                /* There is no constraint preventing duplicate tags so do a precheck */
                $sql = "SELECT * from tag_file where pfile_fk='{$row['pfile_pk']}' and tag_fk='{$tag_pk}'";
                $sqlresult = pg_query($PG_CONN, $sql);
                DBCheckResult($sqlresult, $sql, __FILE__, __LINE__);
                if (pg_num_rows($sqlresult) == 0) {
                    $sql = "insert into tag_file (tag_fk, pfile_fk, tag_file_date, tag_file_text) values ({$tag_pk}, '{$row['pfile_pk']}', now(), NULL)";
                    $insresult = pg_query($PG_CONN, $sql);
                    DBCheckResult($insresult, $sql, __FILE__, __LINE__);
                    pg_free_result($insresult);
                    $numTagged++;
                }
                pg_free_result($sqlresult);
            }
        }
    }
    return $numTagged;
}