Rev 1050 | Rev 1064 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1050 | Rev 1053 | ||
---|---|---|---|
Line 44... | Line 44... | ||
44 | } |
44 | } |
45 | 45 | ||
46 | $dos_ids = array(); |
46 | $dos_ids = array(); |
47 | $parent_oids = array(); |
47 | $parent_oids = array(); |
48 | $i = 0; |
48 | $i = 0; |
49 | $dos_ids[''] = '00000000'; |
- | |
50 | $parent_oids[''] = ''; |
- | |
51 | 49 | ||
- | 50 | // Root node |
|
52 | $dos_ids[''] = str_pad(strval($i++), 8, '0', STR_PAD_LEFT); |
51 | $dos_ids[''] = str_pad(strval($i++), 8, '0', STR_PAD_LEFT); |
- | 52 | $parent_oids[''] = ''; |
|
- | 53 | $iri[''] = array(); |
|
- | 54 | $asn1[''] = array(); |
|
- | 55 | $title[''] = 'OID Root'; |
|
- | 56 | $description[''] = 'Exported by OIDplus 2.0'; |
|
- | 57 | ||
- | 58 | // Now check all OIDs |
|
53 | $res = OIDplus::db()->query("select * from ###objects where id like 'oid:%' order by ".OIDplus::db()->natOrder('id')); |
59 | $res = OIDplus::db()->query("select * from ###objects where id like 'oid:%' order by ".OIDplus::db()->natOrder('id')); |
54 | while ($row = $res->fetch_object()) { |
60 | while ($row = $res->fetch_object()) { |
55 | $oid = substr($row->id, strlen('oid:')); |
61 | $oid = substr($row->id, strlen('oid:')); |
56 | $parent_oid = substr($row->parent, strlen('oid:')); |
62 | $parent_oid = substr($row->parent, strlen('oid:')); |
- | 63 | ||
57 | $dos_ids[$oid] = str_pad(strval($i++), 8, '0', STR_PAD_LEFT); |
64 | $dos_ids[$oid] = str_pad(strval($i++), 8, '0', STR_PAD_LEFT); |
- | 65 | fill_asn1($oid, $asn1); |
|
- | 66 | fill_iri($oid, $iri); |
|
- | 67 | $title[$oid] = $row->title; |
|
- | 68 | $description[$oid] = $row->description; |
|
- | 69 | ||
58 | if ($parent_oid == '') { |
70 | if ((oid_len($oid) > 1) && ($parent_oid == '')) { |
- | 71 | do { |
|
- | 72 | $real_parent = oid_len($oid) > 1 ? oid_up($oid) : ''; |
|
59 | $parent_oids[$oid] = ''; |
73 | $parent_oids[$oid] = $real_parent; |
- | 74 | ||
- | 75 | if (isset($dos_ids[$real_parent])) break; // did we already handle this parent node? |
|
- | 76 | ||
- | 77 | $dos_ids[$real_parent] = str_pad(strval($i++), 8, '0', STR_PAD_LEFT); |
|
- | 78 | fill_asn1($real_parent, $asn1); // well-known OIDs? |
|
- | 79 | fill_iri($real_parent, $iri); // well-known OIDs? |
|
- | 80 | $title[$real_parent] = ''; |
|
- | 81 | $description[$real_parent] = ''; |
|
- | 82 | $res2 = OIDplus::db()->query("select * from ###objects where id = 'oid:$real_parent'"); |
|
- | 83 | while ($row2 = $res2->fetch_object()) { |
|
- | 84 | $title[$real_parent] = $row2->title; |
|
- | 85 | $description[$real_parent] = $row2->description; |
|
- | 86 | } |
|
- | 87 | ||
- | 88 | // next |
|
- | 89 | if ($real_parent == '') break; |
|
- | 90 | $oid = $real_parent; |
|
- | 91 | } while (true); |
|
60 | } else { |
92 | } else { |
61 | $parent_oids[$oid] = $parent_oid; |
93 | $parent_oids[$oid] = $parent_oid; |
62 | } |
94 | } |
63 | } |
95 | } |
64 | 96 | ||
Line 99... | Line 131... | ||
99 | $child_id = $dos_ids[$child_oid]; |
131 | $child_id = $dos_ids[$child_oid]; |
100 | $cont .= make_line(CMD_CHILD, $child_id.$child_oid); |
132 | $cont .= make_line(CMD_CHILD, $child_id.$child_oid); |
101 | } |
133 | } |
102 | } |
134 | } |
103 | 135 | ||
104 | $res = OIDplus::db()->query("select * from ###asn1id where oid = 'oid:$oid'"); |
- | |
105 | while ($row = $res->fetch_object()) { |
- | |
106 | $asn1 = $row->name; |
136 | foreach ($asn1[$oid] as $name) { |
107 | $cont .= make_line(CMD_ASN1_IDENTIFIER, $asn1); |
137 | $cont .= make_line(CMD_ASN1_IDENTIFIER, $name); |
108 | } |
138 | } |
109 | 139 | ||
110 | $res = OIDplus::db()->query("select * from ###iri where oid = 'oid:$oid'"); |
- | |
111 | while ($row = $res->fetch_object()) { |
- | |
112 | $iri = $row->name; |
140 | foreach ($iri[$oid] as $name) { |
113 | $cont .= make_line(CMD_UNICODE_LABEL, $iri); |
141 | $cont .= make_line(CMD_UNICODE_LABEL, $name); |
114 | } |
142 | } |
115 | 143 | ||
116 | if ($oid == '') { |
- | |
117 | // TODO: Split our OIDplus root OIDs into the real OID tree (1, 1.3, 1.3.6, ...) |
- | |
118 | $cont .= make_line(CMD_DESCRIPTION, 'Here, you can find the root OIDs'); |
- | |
119 | } else { |
- | |
120 | $res = OIDplus::db()->query("select * from ###objects where id = 'oid:$oid';"); |
- | |
121 | $row = $res->fetch_object(); |
- | |
122 | $desc_ary1 = handleDesc($row->title); |
144 | $desc_ary1 = handleDesc($title[$oid]); |
123 | $desc_ary2 = handleDesc($row->description); |
145 | $desc_ary2 = handleDesc($description[$oid]); |
124 | $desc_ary = array_merge($desc_ary1, $desc_ary2); |
146 | $desc_ary = array_merge($desc_ary1, $desc_ary2); |
125 | $prev_line = ''; |
147 | $prev_line = ''; |
126 | foreach ($desc_ary as $line_idx => $line) { |
148 | foreach ($desc_ary as $line_idx => $line) { |
127 | if ($line == $prev_line) continue; |
149 | if ($line == $prev_line) continue; |
128 | if ($line_idx >= 10/*DESCEDIT_LINES*/) break; |
150 | if ($line_idx >= 10/*DESCEDIT_LINES*/) break; |
129 | $cont .= make_line(CMD_DESCRIPTION, $line); |
151 | $cont .= make_line(CMD_DESCRIPTION, $line); |
130 | $prev_line = $line; |
152 | $prev_line = $line; |
131 | } |
153 | } |
132 | } |
- | |
133 | 154 | ||
134 | //echo "****$dos_id.OID\r\n"; |
155 | //echo "****$dos_id.OID\r\n"; |
135 | //echo "$cont\r\n"; |
156 | //echo "$cont\r\n"; |
136 | 157 | ||
137 | $zip->addFromString("$dos_id.OID", $cont); |
158 | $zip->addFromString("$dos_id.OID", $cont); |
Line 156... | Line 177... | ||
156 | 177 | ||
157 | OIDplus::invoke_shutdown(); |
178 | OIDplus::invoke_shutdown(); |
158 | 179 | ||
159 | # --- |
180 | # --- |
160 | 181 | ||
- | 182 | function fill_asn1($oid, &$asn1) { |
|
- | 183 | if (!isset($asn1[$oid])) $asn1[$oid] = array(); |
|
- | 184 | $res = OIDplus::db()->query("select * from ###asn1id where oid = 'oid:$oid'"); |
|
- | 185 | while ($row = $res->fetch_object()) { |
|
- | 186 | $asn1[$oid][] = $row->name; |
|
- | 187 | } |
|
- | 188 | } |
|
- | 189 | ||
- | 190 | function fill_iri($oid, &$iri) { |
|
- | 191 | if (!isset($iri[$oid])) $iri[$oid] = array(); |
|
- | 192 | $res = OIDplus::db()->query("select * from ###iri where oid = 'oid:$oid'"); |
|
- | 193 | while ($row = $res->fetch_object()) { |
|
- | 194 | $iri[$oid][] = $row->name; |
|
- | 195 | } |
|
- | 196 | } |
|
- | 197 | ||
161 | function handleDesc($desc) { |
198 | function handleDesc($desc) { |
162 | $desc = preg_replace('/\<br(\s*)?\/?\>/i', "\n", $desc); // br2nl |
199 | $desc = preg_replace('/\<br(\s*)?\/?\>/i', "\n", $desc); // br2nl |
163 | $desc = strip_tags($desc); |
200 | $desc = strip_tags($desc); |
164 | $desc = str_replace(' ', ' ', $desc); |
201 | $desc = str_replace(' ', ' ', $desc); |
165 | $desc = html_entity_decode($desc); |
202 | $desc = html_entity_decode($desc); |