Subversion Repositories oidplus

Compare Revisions

Regard whitespace Rev 782 → Rev 783

/trunk/dev/generate_wellknown_country_oracle
0,0 → 1,61
#!/usr/bin/env php
<?php
 
/*
* OIDplus 2.0
* Copyright 2019 - 2022 Daniel Marschall, ViaThinkSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
// This script generates a part of ../setup/sql/wellknown_country_oracle.sql , based on Country OIDs at oid-info.com
// If new countries are added to the ISO / ITU arcs, please re-run this script and update ../setup/sql/wellknown_country_oracle.sql accordingly
 
require_once __DIR__ . '/../includes/oidplus.inc.php';
 
OIDplus::init(true);
 
// Generates countries for wellknown OIDs
 
$options = array('http' => array('user_agent' => 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36'));
$context = stream_context_create($options);
$cont = file_get_contents('http://oid-info.com/get/1.2', false, $context).
file_get_contents('http://oid-info.com/get/2.16', false, $context).
file_get_contents('http://oid-info.com/get/2.49.0.0', false, $context);
 
preg_match_all('@<option value="/get/([^"]+)">(..)\(.+\)</option>@ismU', $cont, $m, PREG_SET_ORDER);
 
echo "-- Country OIDs\n";
echo "-- Use the tool dev/generate_wellknown_country_oracle to generate this file\n";
echo "\n";
 
$check_sum = '';
foreach ($m as $n) {
$check_sum .= $n[1].'='.$n[2].'/';
 
if (strpos($n[1], '2.49.0.0') === 0) {
// WMO Country OIDs (does not assign Unicode labels), 2.49.0.0
echo "INSERT INTO \"ASN1ID\" (oid, name, standardized, well_known) VALUES ('oid:$n[1]', '$n[2]', '0', '1');\n";
 
// Country-Msg, 2.49.0.1
$n[1] = str_replace('2.49.0.0', '2.49.0.1', $n[1]);
echo "INSERT INTO \"ASN1ID\" (oid, name, standardized, well_known) VALUES ('oid:$n[1]', '$n[2]', '0', '1');\n";
} else {
// ISO or Joint-ISO-ITU-T OID Countries (1.2 and 2.16)
echo "INSERT INTO \"ASN1ID\" (oid, name, standardized, well_known) VALUES ('oid:$n[1]', '$n[2]', '0', '1');\n";
echo "INSERT INTO \"IRI\" (oid, name, longarc, well_known) VALUES ('oid:$n[1]', '".strtoupper($n[2])."', '0', '1');\n";
}
}
 
echo "\n";
echo '-- Generator "generate_wellknown_country_oracle" checksum '.dechex(crc32($check_sum))."\n";