Subversion Repositories oidinfo_api

Rev

Rev 31 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 31 Rev 33
Line 75... Line 75...
75
 
75
 
76
        public function checkOnlineExists($oid) {
76
        public function checkOnlineExists($oid) {
77
                if (!self::strictCheckSyntax($oid)) return false;
77
                if (!self::strictCheckSyntax($oid)) return false;
78
 
78
 
79
                $pingResult = $this->pingOID($oid);
79
                $pingResult = $this->pingOID($oid);
80
                $ret = $pingResult[self::PING_IDX_EXISTS] >= 1;
80
                return $pingResult[self::PING_IDX_EXISTS] >= 1;
81
                return $ret;
-
 
82
        }
81
        }
83
 
82
 
84
        public function checkOnlineAvailable($oid) {
83
        public function checkOnlineAvailable($oid) {
85
                if (!self::strictCheckSyntax($oid)) return false;
84
                if (!self::strictCheckSyntax($oid)) return false;
86
 
85
 
87
                $pingResult = $this->pingOID($oid);
86
                $pingResult = $this->pingOID($oid);
88
                $ret = $pingResult[self::PING_IDX_EXISTS] == 2;
87
                return $pingResult[self::PING_IDX_EXISTS] == 2;
89
                return $ret;
-
 
90
        }
88
        }
91
 
89
 
92
        public function checkOnlineAllowed($oid) {
90
        public function checkOnlineAllowed($oid) {
93
                if (!self::strictCheckSyntax($oid)) return false;
91
                if (!self::strictCheckSyntax($oid)) return false;
94
 
92
 
Line 217... Line 215...
217
                $phone = str_replace(')', ' ', $phone);
215
                $phone = str_replace(')', ' ', $phone);
218
 
216
 
219
                // HL7 registry has included this accidently
217
                // HL7 registry has included this accidently
220
                $phone = str_replace('"', '', $phone);
218
                $phone = str_replace('"', '', $phone);
221
 
219
 
222
                $phone = trim($phone);
-
 
223
 
-
 
224
                return $phone;
220
                return trim($phone);
225
        }
221
        }
226
 
222
 
227
        private static function strip_to_xhtml_light($str, $allow_strong_text=false) {
223
        private static function strip_to_xhtml_light($str, $allow_strong_text=false) {
228
                // <strong> is allowed in the XSD, but not <b>
224
                // <strong> is allowed in the XSD, but not <b>
229
                $str = str_ireplace('<b>', '<strong>', $str);
225
                $str = str_ireplace('<b>', '<strong>', $str);
Line 236... Line 232...
236
                }
232
                }
237
 
233
 
238
                $str = preg_replace('@<\s*script.+<\s*/script.*>@isU', '', $str);
234
                $str = preg_replace('@<\s*script.+<\s*/script.*>@isU', '', $str);
239
                $str = preg_replace('@<\s*style.+<\s*/style.*>@isU', '', $str);
235
                $str = preg_replace('@<\s*style.+<\s*/style.*>@isU', '', $str);
240
 
236
 
241
                $str = preg_replace_callback(
237
                return preg_replace_callback(
242
                        '@<(\s*/{0,1}\d*)([^\s/>]+)(\s*[^>]*)>@i',
238
                        '@<(\s*/{0,1}\d*)([^\s/>]+)(\s*[^>]*)>@i',
243
                        function ($treffer) {
239
                        function ($treffer) {
244
                                // see http://oid-info.com/xhtml-light.xsd
240
                                // see http://oid-info.com/xhtml-light.xsd
245
                                $whitelist = array('a', 'br', 'code', 'em', 'font', 'img', 'li', 'strong', 'sub', 'sup', 'ul');
241
                                $whitelist = array('a', 'br', 'code', 'em', 'font', 'img', 'li', 'strong', 'sub', 'sup', 'ul');
246
 
242
 
Line 251... Line 247...
251
                                        return '<'.$pre.$tag.$attrib.'>';
247
                                        return '<'.$pre.$tag.$attrib.'>';
252
                                } else {
248
                                } else {
253
                                        return '';
249
                                        return '';
254
                                }
250
                                }
255
                        }, $str);
251
                        }, $str);
256
 
-
 
257
                return $str;
-
 
258
        }
252
        }
259
 
253
 
260
        const OIDINFO_CORRECT_DESC_OPTIONAL_ENDING_DOT = 0;
254
        const OIDINFO_CORRECT_DESC_OPTIONAL_ENDING_DOT = 0;
261
        const OIDINFO_CORRECT_DESC_ENFORCE_ENDING_DOT = 1;
255
        const OIDINFO_CORRECT_DESC_ENFORCE_ENDING_DOT = 1;
262
        const OIDINFO_CORRECT_DESC_DISALLOW_ENDING_DOT = 2;
256
        const OIDINFO_CORRECT_DESC_DISALLOW_ENDING_DOT = 2;
Line 407... Line 401...
407
                } else if ($ending_dot_policy == self::OIDINFO_CORRECT_DESC_DISALLOW_ENDING_DOT) {
401
                } else if ($ending_dot_policy == self::OIDINFO_CORRECT_DESC_DISALLOW_ENDING_DOT) {
408
                        $desc = preg_replace('@\\.$@', '', $desc);
402
                        $desc = preg_replace('@\\.$@', '', $desc);
409
                }
403
                }
410
 
404
 
411
                // Required for XML importer of oid-info.com (E-Mail 09.12.2021)
405
                // Required for XML importer of oid-info.com (E-Mail 09.12.2021)
412
                $desc = str_replace('&amp;', '&amp;amp;', $desc);
406
                return str_replace('&amp;', '&amp;amp;', $desc);
413
 
-
 
414
                return $desc;
-
 
415
        }
407
        }
416
 
408
 
417
        public function xmlAddHeader($firstName, $lastName, $email) {
409
        public function xmlAddHeader($firstName, $lastName, $email) {
418
                // TODO: encode
410
                // TODO: encode
419
 
411
 
Line 611... Line 603...
611
                                        // if (!oid_id_is_valid($synid)) $synid = null;
603
                                        // if (!oid_id_is_valid($synid)) $synid = null;
612
                                } else {
604
                                } else {
613
                                        throw new OIDInfoException("Unexpected soft-correction behavior for ASN.1 IDs");
605
                                        throw new OIDInfoException("Unexpected soft-correction behavior for ASN.1 IDs");
614
                                }
606
                                }
615
                        }
607
                        }
-
 
608
                        unset($synid);
616
                }
609
                }
617
 
610
 
618
                // ATTENTION: the XML-generator will always add <dotted-oid> , but what will happen if additionally an
611
                // ATTENTION: the XML-generator will always add <dotted-oid> , but what will happen if additionally an
619
                // asn1-path (<value>) is given? (the resulting OIDs might be inconsistent/mismatch)
612
                // asn1-path (<value>) is given? (the resulting OIDs might be inconsistent/mismatch)
620
                if (isset($elements['value']) && (!asn1_path_valid($elements['value']))) {
613
                if (isset($elements['value']) && (!asn1_path_valid($elements['value']))) {
Line 628... Line 621...
628
                        }
621
                        }
629
                        foreach ($elements['iri'] as &$iri) {
622
                        foreach ($elements['iri'] as &$iri) {
630
                                // Do not allow Numeric-only. It would only be valid in an IRI path, but not in a single identifier
623
                                // Do not allow Numeric-only. It would only be valid in an IRI path, but not in a single identifier
631
                                if (!iri_arc_valid($iri, false)) $iri = null;
624
                                if (!iri_arc_valid($iri, false)) $iri = null;
632
                        }
625
                        }
-
 
626
                        unset($iri);
633
                }
627
                }
634
 
628
 
635
                if (isset($elements['first-registrant']['phone']))
629
                if (isset($elements['first-registrant']['phone']))
636
                $elements['first-registrant']['phone']   = $this->softCorrectPhone($elements['first-registrant']['phone'], $params);
630
                $elements['first-registrant']['phone']   = $this->softCorrectPhone($elements['first-registrant']['phone'], $params);
637
 
631
 
Line 1027... Line 1021...
1027
        protected function spp_reader_init() {
1021
        protected function spp_reader_init() {
1028
                $this->spp_reader_uninit();
1022
                $this->spp_reader_uninit();
1029
 
1023
 
1030
                $ary = explode(':', $this->addr); // TODO: does not work with an IPv6 address
1024
                $ary = explode(':', $this->addr); // TODO: does not work with an IPv6 address
1031
                $host = $ary[0];
1025
                $host = $ary[0];
1032
                $service_port = isset($ary[1]) ? $ary[1] : self::DEFAULT_PORT;
1026
                $service_port = $ary[1] ?? self::DEFAULT_PORT;
1033
 
1027
 
1034
                $is_ip = filter_var($host, FILTER_VALIDATE_IP) !== false;
1028
                $is_ip = filter_var($host, FILTER_VALIDATE_IP) !== false;
1035
                if (!$is_ip) {
1029
                if (!$is_ip) {
1036
                        $address = @gethostbyname($host);
1030
                        $address = @gethostbyname($host);
1037
                        if ($address === $host) {
1031
                        if ($address === $host) {
Line 1061... Line 1055...
1061
 
1055
 
1062
                $this->connected = true;
1056
                $this->connected = true;
1063
        }
1057
        }
1064
 
1058
 
1065
        protected function spp_reader_avail($oid, $failcount=0) {
1059
        protected function spp_reader_avail($oid, $failcount=0) {
1066
                $in = "${oid}\n\0"; // PHP's socket_send() does not send a trailing \n . There needs to be something after the \n ... :(
1060
                $in = "$oid\n\0"; // PHP's socket_send() does not send a trailing \n . There needs to be something after the \n ... :(
1067
 
1061
 
1068
                if ($failcount >= self::SPP_MAX_CONNECTION_ATTEMPTS) {
1062
                if ($failcount >= self::SPP_MAX_CONNECTION_ATTEMPTS) {
1069
                        $msg = "Query $oid: CONNECTION TO SIMPLE PING PROVIDER FAILED!\n";
1063
                        $msg = "Query $oid: CONNECTION TO SIMPLE PING PROVIDER FAILED!\n";
1070
                        throw new Exception($msg);
1064
                        throw new Exception($msg);
1071
                        // echo $msg;
1065
                        // echo $msg;
Line 1107... Line 1101...
1107
                if (trim($oid) === 'bye') return null;
1101
                if (trim($oid) === 'bye') return null;
1108
                return $this->spp_reader_avail($oid);
1102
                return $this->spp_reader_avail($oid);
1109
        }
1103
        }
1110
 
1104
 
1111
        public function disconnect() {
1105
        public function disconnect() {
1112
                return $this->spp_reader_uninit();
1106
                $this->spp_reader_uninit();
1113
        }
1107
        }
1114
 
1108
 
1115
        public function connect() {
1109
        public function connect() {
1116
                return $this->spp_reader_init();
1110
                $this->spp_reader_init();
1117
        }
1111
        }
1118
 
1112
 
1119
        function __construct($addr='localhost:49500') {
1113
        function __construct($addr='localhost:49500') {
1120
                $this->addr = $addr;
1114
                $this->addr = $addr;
1121
        }
1115
        }