Subversion Repositories oidplus

Rev

Rev 247 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 247 Rev 250
Line 44... Line 44...
44
        public function __construct($oid) {
44
        public function __construct($oid) {
45
                $bak_oid = $oid;
45
                $bak_oid = $oid;
46
 
46
 
47
                $oid = sanitizeOID($oid, 'auto');
47
                $oid = sanitizeOID($oid, 'auto');
48
                if ($oid === false) {
48
                if ($oid === false) {
49
                        throw new Exception("Invalid OID '$bak_oid'");
49
                        throw new OIDplusException("Invalid OID '$bak_oid'");
50
                }
50
                }
51
 
51
 
52
                if (($oid != '') && (!oid_valid_dotnotation($oid, false, true, 0))) {
52
                if (($oid != '') && (!oid_valid_dotnotation($oid, false, true, 0))) {
53
                        // avoid OIDs like 3.0
53
                        // avoid OIDs like 3.0
54
                        throw new Exception("Invalid OID '$bak_oid'");
54
                        throw new OIDplusException("Invalid OID '$bak_oid'");
55
                }
55
                }
56
 
56
 
57
                $this->oid = $oid;
57
                $this->oid = $oid;
58
        }
58
        }
59
 
59
 
Line 87... Line 87...
87
                return $with_ns ? 'oid:'.$this->oid : $this->oid;
87
                return $with_ns ? 'oid:'.$this->oid : $this->oid;
88
        }
88
        }
89
 
89
 
90
        public function addString($str) {
90
        public function addString($str) {
91
                if (!$this->isRoot()) {
91
                if (!$this->isRoot()) {
92
                        if (strpos($str,'.') !== false) throw new Exception("Please only submit one arc (not an absolute OID or multiple arcs).");
92
                        if (strpos($str,'.') !== false) throw new OIDplusException("Please only submit one arc (not an absolute OID or multiple arcs).");
93
                }
93
                }
94
 
94
 
95
                return $this->appendArcs($str)->nodeId();
95
                return $this->appendArcs($str)->nodeId();
96
        }
96
        }
97
 
97
 
Line 217... Line 217...
217
                        $out->oid .= '.' . $arcs;
217
                        $out->oid .= '.' . $arcs;
218
                }
218
                }
219
 
219
 
220
                $bak_oid = $out->oid;
220
                $bak_oid = $out->oid;
221
                $out->oid = sanitizeOID($out->oid);
221
                $out->oid = sanitizeOID($out->oid);
222
                if ($out->oid === false) throw new Exception("$bak_oid is not a valid OID!");
222
                if ($out->oid === false) throw new OIDplusException("$bak_oid is not a valid OID!");
223
               
223
               
224
                if (strlen($out->oid) > OIDPLUS_MAX_ID_LENGTH-strlen('oid:')) {
224
                if (strlen($out->oid) > OIDPLUS_MAX_ID_LENGTH-strlen('oid:')) {
225
                        throw new Exception("The resulting OID '".$out->oid."' is too long (max allowed: ".(OIDPLUS_MAX_ID_LENGTH-strlen('oid:')).").");
225
                        throw new OIDplusException("The resulting OID '".$out->oid."' is too long (max allowed: ".(OIDPLUS_MAX_ID_LENGTH-strlen('oid:')).").");
226
                }
226
                }
227
               
227
               
228
                $depth = 0;
228
                $depth = 0;
229
                foreach (explode('.',$out->oid) as $arc) {
229
                foreach (explode('.',$out->oid) as $arc) {
230
                        if (strlen($arc) > OIDPLUS_MAX_OID_ARC_SIZE) {
230
                        if (strlen($arc) > OIDPLUS_MAX_OID_ARC_SIZE) {
231
                                throw new Exception("Arc '$arc' is too long and therefore cannot be appended to the OID '".$this->oid."' (max allowed arc size is ".OIDPLUS_MAX_OID_ARC_SIZE.")");
231
                                throw new OIDplusException("Arc '$arc' is too long and therefore cannot be appended to the OID '".$this->oid."' (max allowed arc size is ".OIDPLUS_MAX_OID_ARC_SIZE.")");
232
                        }
232
                        }
233
                        $depth++;
233
                        $depth++;
234
                }
234
                }
235
                if ($depth > OIDPLUS_MAX_OID_DEPTH) {
235
                if ($depth > OIDPLUS_MAX_OID_DEPTH) {
236
                        throw new Exception("OID '".$out->oid."' has too many arcs (current depth $depth, max depth ".OIDPLUS_MAX_OID_DEPTH.")");
236
                        throw new OIDplusException("OID '".$out->oid."' has too many arcs (current depth $depth, max depth ".OIDPLUS_MAX_OID_DEPTH.")");
237
                }
237
                }
238
 
238
 
239
                return $out;
239
                return $out;
240
        }
240
        }
241
 
241
 
Line 356... Line 356...
356
                return false;
356
                return false;
357
        }
357
        }
358
 
358
 
359
        public function replaceAsn1Ids($demandedASN1s=array(), $simulate=false) {
359
        public function replaceAsn1Ids($demandedASN1s=array(), $simulate=false) {
360
                if ($this->isWellKnown()) {
360
                if ($this->isWellKnown()) {
361
                        throw new Exception("OID ".$this->oid." is a 'well-known' OID. Its identifiers cannot be changed.");
361
                        throw new OIDplusException("OID ".$this->oid." is a 'well-known' OID. Its identifiers cannot be changed.");
362
                }
362
                }
363
 
363
 
364
                // First do a few checks
364
                // First do a few checks
365
                foreach ($demandedASN1s as &$asn1) {
365
                foreach ($demandedASN1s as &$asn1) {
366
                        $asn1 = trim($asn1);
366
                        $asn1 = trim($asn1);
367
 
367
 
368
                        if (strlen($asn1) > OIDPLUS_MAX_OID_ASN1_ID_LEN) {
368
                        if (strlen($asn1) > OIDPLUS_MAX_OID_ASN1_ID_LEN) {
369
                                throw new Exception("ASN.1 alphanumeric identifier '$asn1' is too long (max allowed length ".OIDPLUS_MAX_OID_ASN1_ID_LEN.")");
369
                                throw new OIDplusException("ASN.1 alphanumeric identifier '$asn1' is too long (max allowed length ".OIDPLUS_MAX_OID_ASN1_ID_LEN.")");
370
                        }
370
                        }
371
 
371
 
372
                        // Validate identifier
372
                        // Validate identifier
373
                        if (!oid_id_is_valid($asn1)) throw new Exception("'$asn1' is not a valid ASN.1 identifier!");
373
                        if (!oid_id_is_valid($asn1)) throw new OIDplusException("'$asn1' is not a valid ASN.1 identifier!");
374
 
374
 
375
                        // Check if the (real) parent has any conflict
375
                        // Check if the (real) parent has any conflict
376
                        // Unlike IRI identifiers, ASN.1 identifiers may be used multiple times (not recommended), except if one of them is standardized
376
                        // Unlike IRI identifiers, ASN.1 identifiers may be used multiple times (not recommended), except if one of them is standardized
377
                        $res = OIDplus::db()->query("select oid from ".OIDPLUS_TABLENAME_PREFIX."asn1id where name = ? and standardized = ?", array($asn1,true));
377
                        $res = OIDplus::db()->query("select oid from ".OIDPLUS_TABLENAME_PREFIX."asn1id where name = ? and standardized = ?", array($asn1,true));
378
                        while ($row = $res->fetch_array()) {
378
                        while ($row = $res->fetch_array()) {
379
                                $check_oid = OIDplusOid::parse($row['oid'])->oid;
379
                                $check_oid = OIDplusOid::parse($row['oid'])->oid;
380
                                if ((oid_up($check_oid) === oid_up($this->oid)) && // same parent
380
                                if ((oid_up($check_oid) === oid_up($this->oid)) && // same parent
381
                                   ($check_oid !== $this->oid))                    // different OID
381
                                   ($check_oid !== $this->oid))                    // different OID
382
                                {
382
                                {
383
                                        throw new Exception("ASN.1 identifier '$asn1' is a standardized identifier belonging to OID ($check_oid)");
383
                                        throw new OIDplusException("ASN.1 identifier '$asn1' is a standardized identifier belonging to OID ($check_oid)");
384
                                }
384
                                }
385
                        }
385
                        }
386
                }
386
                }
387
 
387
 
388
                // Now do the real replacement
388
                // Now do the real replacement
Line 394... Line 394...
394
                }
394
                }
395
        }
395
        }
396
 
396
 
397
        public function replaceIris($demandedIris=array(), $simulate=false) {
397
        public function replaceIris($demandedIris=array(), $simulate=false) {
398
                if ($this->isWellKnown()) {
398
                if ($this->isWellKnown()) {
399
                        throw new Exception("OID ".$this->oid." is a 'well-known' OID. Its identifiers cannot be changed.");
399
                        throw new OIDplusException("OID ".$this->oid." is a 'well-known' OID. Its identifiers cannot be changed.");
400
                }
400
                }
401
 
401
 
402
                // First do a few checks
402
                // First do a few checks
403
                foreach ($demandedIris as &$iri) {
403
                foreach ($demandedIris as &$iri) {
404
                        $iri = trim($iri);
404
                        $iri = trim($iri);
405
 
405
 
406
                        if (strlen($iri) > OIDPLUS_MAX_OID_UNICODE_LABEL_LEN) {
406
                        if (strlen($iri) > OIDPLUS_MAX_OID_UNICODE_LABEL_LEN) {
407
                                throw new Exception("Unicode label '$iri' is too long (max allowed length ".OIDPLUS_MAX_OID_UNICODE_LABEL_LEN.")");
407
                                throw new OIDplusException("Unicode label '$iri' is too long (max allowed length ".OIDPLUS_MAX_OID_UNICODE_LABEL_LEN.")");
408
                        }
408
                        }
409
 
409
 
410
                        // Validate identifier
410
                        // Validate identifier
411
                        if (!iri_arc_valid($iri, false)) throw new Exception("'$iri' is not a valid IRI!");
411
                        if (!iri_arc_valid($iri, false)) throw new OIDplusException("'$iri' is not a valid IRI!");
412
 
412
 
413
                        // Check if the (real) parent has any conflict
413
                        // Check if the (real) parent has any conflict
414
                        $res = OIDplus::db()->query("select oid from ".OIDPLUS_TABLENAME_PREFIX."iri where name = ?", array($iri));
414
                        $res = OIDplus::db()->query("select oid from ".OIDPLUS_TABLENAME_PREFIX."iri where name = ?", array($iri));
415
                        while ($row = $res->fetch_array()) {
415
                        while ($row = $res->fetch_array()) {
416
                                $check_oid = OIDplusOid::parse($row['oid'])->oid;
416
                                $check_oid = OIDplusOid::parse($row['oid'])->oid;
417
                                if ((oid_up($check_oid) === oid_up($this->oid)) && // same parent
417
                                if ((oid_up($check_oid) === oid_up($this->oid)) && // same parent
418
                                   ($check_oid !== $this->oid))                    // different OID
418
                                   ($check_oid !== $this->oid))                    // different OID
419
                                {
419
                                {
420
                                        throw new Exception("IRI '$iri' is already used by another OID ($check_oid)");
420
                                        throw new OIDplusException("IRI '$iri' is already used by another OID ($check_oid)");
421
                                }
421
                                }
422
                        }
422
                        }
423
                }
423
                }
424
 
424
 
425
                // Now do the real replacement
425
                // Now do the real replacement