Subversion Repositories Applications.annuaire

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
42 aurelien 1
<?php
2
 
3
require_once 'Services/Yadis/XRDS.php';
4
require_once 'Services/Yadis/XRI.php';
5
 
6
class Services_Yadis_ProxyResolver {
7
    function Services_Yadis_ProxyResolver(&$fetcher, $proxy_url = null)
8
    {
9
        $this->fetcher =& $fetcher;
10
        $this->proxy_url = $proxy_url;
11
        if (!$this->proxy_url) {
12
            $this->proxy_url = Services_Yadis_getDefaultProxy();
13
        }
14
    }
15
 
16
    function queryURL($xri, $service_type = null)
17
    {
18
        // trim off the xri:// prefix
19
        $qxri = substr(Services_Yadis_toURINormal($xri), 6);
20
        $hxri = $this->proxy_url . $qxri;
21
        $args = array(
22
                      '_xrd_r' => 'application/xrds+xml'
23
                      );
24
 
25
        if ($service_type) {
26
            $args['_xrd_t'] = $service_type;
27
        } else {
28
            // Don't perform service endpoint selection.
29
            $args['_xrd_r'] .= ';sep=false';
30
        }
31
 
32
        $query = Services_Yadis_XRIAppendArgs($hxri, $args);
33
        return $query;
34
    }
35
 
36
    function query($xri, $service_types, $filters = array())
37
    {
38
        $services = array();
39
        $canonicalID = null;
40
        foreach ($service_types as $service_type) {
41
            $url = $this->queryURL($xri, $service_type);
42
            $response = $this->fetcher->get($url);
43
            if ($response->status != 200) {
44
                continue;
45
            }
46
            $xrds = Services_Yadis_XRDS::parseXRDS($response->body);
47
            if (!$xrds) {
48
                continue;
49
            }
50
            $canonicalID = Services_Yadis_getCanonicalID($xri,
51
                                                         $xrds);
52
 
53
            if ($canonicalID === false) {
54
                return null;
55
            }
56
 
57
            $some_services = $xrds->services($filters);
58
            $services = array_merge($services, $some_services);
59
            // TODO:
60
            //  * If we do get hits for multiple service_types, we're
61
            //    almost certainly going to have duplicated service
62
            //    entries and broken priority ordering.
63
        }
64
        return array($canonicalID, $services);
65
    }
66
}
67
 
68
?>