Subversion Repositories oidplus

Compare Revisions

Regard whitespace Rev 1129 → Rev 1130

/trunk/dev/bcrypt_cost_calculator
18,7 → 18,12
* limitations under the License.
*/
 
function bcrypt_rounds($treshold_secs, $verbose=true) {
/**
* @param int $treshold_secs
* @param bool $verbose
* @return int
*/
function bcrypt_rounds(int $treshold_secs, bool $verbose=true): int {
if ($verbose) echo "Searching BCrypt cost (rounds) for <$treshold_secs secs...\n";
$found = 31;
for ($rounds=4; $rounds<=31; $rounds++) { // 4..31 is the valid range of PHP Bcrypt
/trunk/dev/oidinfo_add_missing
41,7 → 41,11
check_oid($oid);
}
 
function check_oid($oid) {
/**
* @param string $oid
* @return void
*/
function check_oid(string $oid) {
 
$res = OIDplus::db()->query("select * from ###objects where id = ?", array("oid:$oid"));
$ok = $res->num_rows() > 0;
56,7 → 60,12
 
# ---
 
function add_oid($oid, $root=DESIRED_ROOT) {
/**
* @param string $oid
* @param string $root
* @return void
*/
function add_oid(string $oid, string $root=DESIRED_ROOT) {
if (VERBOSE) echo "Adding $oid ...\n";
$data = ft_get_oid_data($oid);
 
108,7 → 117,11
array("oid:$oid", "oid:$parent", $title, $description, $ra_email, $created, $updated));
}
 
function ft_get_oid_data($oid) {
/**
* @param string $oid
* @return false|array
*/
function ft_get_oid_data(string $oid) {
$url = OIDplus::baseConfig()->getValue('OIDINFO_API_URL') . '&oid='.urlencode($oid);
$cont_json = @file_get_contents($url);
if (!$cont_json) {
116,12 → 129,15
$cont_json = @file_get_contents($url);
if (!$cont_json) return false;
}
$data = json_decode($cont_json,true);
 
return $data;
return json_decode($cont_json,true);
}
 
function sql_execute($sql, $prep=null) {
/**
* @param string $sql
* @param array|null $prep
* @return void
*/
function sql_execute(string $sql, array $prep=null) {
# echo "$sql\n";
try {
OIDplus::db()->query($sql, $prep);
/trunk/dev/oidinfo_compare
36,7 → 36,11
if (strpos($oid, '1.3.6.1.4.1.37476.30.9.') !== 0) check_oid($oid);
}
 
function check_oid($oid) {
/**
* @param string $oid
* @return void
*/
function check_oid(string $oid) {
 
$res = OIDplus::db()->query("select * from ###objects where id = ?", array("oid:$oid"));
$ok = $res->num_rows() > 0;
/trunk/dev/oidinfo_compare_asn1_iri_identifiers
41,7 → 41,12
check_oid($oid);
}
 
function check_oid($oid, $root=DESIRED_ROOT) {
/**
* @param string $oid
* @param string $root
* @return void
*/
function check_oid(string $oid, string $root=DESIRED_ROOT) {
$data = ft_get_oid_data($oid);
 
// ASN.1 IDs
91,7 → 96,11
 
# ---
 
function ft_get_oid_data($oid) {
/**
* @param string $oid
* @return false|array
*/
function ft_get_oid_data(string $oid) {
$url = OIDplus::baseConfig()->getValue('OIDINFO_API_URL') . '&oid='.urlencode($oid);
$cont_json = @file_get_contents($url);
if (!$cont_json) {
99,7 → 108,5
$cont_json = @file_get_contents($url);
if (!$cont_json) return false;
}
$data = json_decode($cont_json,true);
 
return $data;
return json_decode($cont_json,true);
}
/trunk/dev/oidplus_v1_compare
32,7 → 32,11
check_oid($oid);
}
 
function check_oid($oid) {
/**
* @param string $oid
* @return void
*/
function check_oid(string $oid) {
 
$res = OIDplus::db()->query("select * from ###objects where id = ?", array("oid:$oid"));
$ok = $res->num_rows() > 0;
/trunk/dev/systemid_collider
55,7 → 55,11
if ($cnt%25 == 0) echo "PROCESSING: $cnt \r";
}
 
function smallhash($data) { // get 31 bits from SHA1. Values 0..2147483647
/**
* @param string $data
* @return int
*/
function smallhash(string $data): int { // get 31 bits from SHA1. Values 0..2147483647
return (hexdec(substr(sha1($data),-4*2)) & 0x7FFFFFFF);
}
 
/trunk/dev/test_database_plugins
121,7 → 121,11
 
# ---
 
function dotest($db) {
/**
* @param \ViaThinkSoft\OIDplus\OIDplusDatabaseConnection $db
* @return void
*/
function dotest(\ViaThinkSoft\OIDplus\OIDplusDatabaseConnection $db): string {
echo "Database: " . get_class($db) . "\n";
try {
$db->connect();
366,25 → 370,35
echo "\n";
}
 
function redtext($str) {
/**
* @param string $str
* @return string
*/
function redtext(string $str): string {
global $num_errs;
$num_errs++;
return PHP_SAPI == 'cli' ? "\033[31m$str\033[0m" : '<font color="red">'.$str.'</font>';
}
 
function greentext($str) {
/**
* @param string $str
* @return string
*/
function greentext(string $str): string {
global $num_succ;
$num_succ++;
return PHP_SAPI == 'cli' ? "\033[32m$str\033[0m" : '<font color="green">'.$str.'</font>';
}
 
function is_known_errormsg($msg) {
/**
* @param string $msg
* @return bool
*/
function is_known_errormsg(string $msg): bool {
// Oracle:
//Error-Function after failed direct query:
// ==> OCIStmtExecute: ORA-00942: table or view does not exist (ext\pdo_oci\oci_statement.c:155)
//Error-Function after failed prepared query:
// ==> OCIBindByPos: ORA-01036: illegal variable name/number (ext\pdo_oci\oci_statement.c:346)
if (strpos($msg,'ORA-') !== false) return true;
 
return false;
return strpos($msg,'ORA-') !== false;
}
/trunk/dev/translation/generate_proof_files.phps
94,7 → 94,11
 
# ---
 
function get_js_L_strings($cont) {
/**
* @param string $cont
* @return array
*/
function get_js_L_strings(string $cont): array {
// Works with JavaScript and PHP
$cont = preg_replace('@/\\*.+\\*/@ismU', '', $cont);
$cont = str_replace('\\"', chr(1), $cont);
109,7 → 113,11
return $m[2];
}
 
function get_php_L_strings($cont) {
/**
* @param string $cont
* @return array
*/
function get_php_L_strings(string $cont): array {
// Works only with PHP
$out = array();
$tokens = token_get_all($cont);
/trunk/dev/translation/message_regenerate.phps
158,7 → 158,11
 
# ---
 
function get_js_L_strings($cont) {
/**
* @param string $cont
* @return string[]
*/
function get_js_L_strings(string $cont): array {
// Works with JavaScript and PHP
$cont = preg_replace('@/\\*.+\\*/@ismU', '', $cont);
$cont = str_replace('\\"', chr(1), $cont);
173,7 → 177,11
return $m[3];
}
 
function get_php_L_strings($cont) {
/**
* @param string $cont
* @return string[]
*/
function get_php_L_strings(string $cont): array {
// Works only with PHP
$out = array();
$tokens = token_get_all($cont);
192,7 → 200,11
return $out;
}
 
function test_missing_placeholder($test) {
/**
* @param string $test
* @return void
*/
function test_missing_placeholder(string $test) {
$max = -1;
for ($i=99; $i>=1; $i--) {
if (strpos($test, '%'.$i) !== false) {
217,7 → 229,11
 
# ---
 
function phpRemoveComments($fileStr) {
/**
* @param string $fileStr
* @return string
*/
function phpRemoveComments(string $fileStr): string {
 
// https://stackoverflow.com/questions/503871/best-way-to-automatically-remove-comments-from-php-code
 
/trunk/dev/translation/show_nontranslated_code.phps
125,13 → 125,8
}
 
$x = str_replace('(', chr(4), $x);
$x = str_replace(')', chr(5), $x);
 
/*
if (strpos($x,"\n") !== false) echo 'DEBUG: <pre>'.htmlentities($x)."</pre>\n\n\n\n\n";
*/
 
return $x;
return str_replace(')', chr(5), $x);
}, $cont);
 
$cont = preg_replace('@_L\\((\'|")(.*)\\1@smU', '_L(...', $cont);
208,7 → 203,11
 
# ---
 
function phpRemoveComments($fileStr) {
/**
* @param string $fileStr
* @return string
*/
function phpRemoveComments(string $fileStr): string {
 
// https://stackoverflow.com/questions/503871/best-way-to-automatically-remove-comments-from-php-code