Subversion Repositories oidplus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
226 daniel-mar 1
<?php
2
 
3
# if (!interface_exists('VolcanoSearchProvider')) throw new Exception('Required interface "VolcanoSearchProvider" not found.');
4
# if (!class_exists('VolcanoDB')) throw new Exception('Required class "VolcanoDB" not found.');
5
 
6
require_once __DIR__ . '/../../core/VolcanoSearchProvider.class.php';
7
require_once __DIR__ . '/../../includes/ipv6_functions.inc.php';
8
 
9
class VolcanoSearchIPv6 implements VolcanoSearchProvider {
10
        public static function checkId($id) {
11
                return self::strEqual($id, 'ipv6', true); // is always case insensitive
12
        }
13
 
14
        public static function calcDistance($candidate, $searchterm) {
15
                return ipv6_distance($searchterm, $candidate); // TODO: richtig rum?
16
        }
17
 
18
        protected static function strEqual($str1, $str2, $caseInsensitive = false) {
19
                if ($caseInsensitive) {
20
                        return strtolower($str1) == strtolower($str2);
21
                } else {
22
                        return $str1 == $str2;
23
                }
24
        }
25
}
26
 
27
require_once __DIR__ . '/../../core/1_VolcanoDB.class.php';
28
VolcanoDB::registerSearchProvider(new VolcanoSearchIPv6());
29
 
30
# --- TEST
31
 
32
/*
33
$x = new VolcanoSearchIPv6();
34
assert($x->calcDistance('2001:1ae0::/27', '2001:1af8::/29') ==  2);
35
assert($x->calcDistance('2001:1af8::/29', '2001:1af8::/29') ==  0);
36
assert($x->calcDistance('2001:1af8::/31', '2001:1af8::/29') == -2);
37
 
38
assert($x->calcDistance('2002:1af8:4100:a061:0001::1335/127', '2001:1af8:4100:a061:0001::1336/127') === false);
39
assert($x->calcDistance('2001:1af8:4100:a061:0001::1337/128', '2001:1af8:4100:a061:0001::1336/128') === false);
40
assert($x->calcDistance('2001:1af8:4100:a061:0001::1337',     '2001:1af8:4100:a061:0001::1336')     === false);
41
*/
42