/[drupal]/contributions/modules/openid/xrds.inc
ViewVC logotype

Contents of /contributions/modules/openid/xrds.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.3 - (show annotations) (download) (as text)
Sun May 13 02:55:40 2007 UTC (2 years, 6 months ago) by walkah
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +12 -2 lines
File MIME type: text/x-php
* Lots of cleanups - specifically to the discovery process
* Properly distinguish between 1.x and 2.0 calls - #143061
* XRI support - #143125 - patch by William Tan / Grugnog2 (changes by me)
1 <?php
2 // $Id: xrds.inc,v 1.2 2007/03/25 06:38:00 walkah Exp $
3
4 // Global variables to track parsing state
5 $xrds_open_elements = array();
6 $xrds_services = array();
7 $xrds_current_service = array();
8
9 /**
10 * Main entry point for parsing XRDS documents
11 */
12 function xrds_parse($xml) {
13 global $xrds_services;
14
15 $parser = xml_parser_create_ns();
16 xml_set_element_handler($parser, '_xrds_element_start', '_xrds_element_end');
17 xml_set_character_data_handler($parser, '_xrds_cdata');
18
19 xml_parse($parser, $xml);
20 xml_parser_free($parser);
21
22 return $xrds_services;
23 }
24
25 /**
26 * Parser callback functions
27 */
28 function _xrds_element_start(&$parser, $name, $attribs) {
29 global $xrds_open_elements;
30
31 $xrds_open_elements[] = _xrds_strip_namespace($name);
32 }
33
34 function _xrds_element_end(&$parser, $name) {
35 global $xrds_open_elements, $xrds_services, $xrds_current_service;
36
37 $name = _xrds_strip_namespace($name);
38 if ($name == 'SERVICE') {
39 if (in_array(OPENID_NS_2_0 .'/signon', $xrds_current_service['types']) ||
40 in_array(OPENID_NS_2_0 .'/server', $xrds_current_service['types'])) {
41 $xrds_current_service['version'] = 2;
42 }
43 elseif (in_array(OPENID_NS_1_1, $xrds_current_service['types']) ||
44 in_array(OPENID_NS_1_0, $xrds_current_service['types'])) {
45 $xrds_current_service['version'] = 1;
46 }
47 if (!empty($xrds_current_service['version'])) {
48 $xrds_services[] = $xrds_current_service;
49 }
50 $xrds_current_service = array();
51 }
52 array_pop($xrds_open_elements);
53 }
54
55 function _xrds_cdata(&$parser, $data) {
56 global $xrds_open_elements, $xrds_services, $xrds_current_service;
57 $path = strtoupper(implode('/', $xrds_open_elements));
58 switch ($path) {
59 case 'XRDS/XRD/SERVICE/TYPE':
60 $xrds_current_service['types'][] = $data;
61 break;
62 case 'XRDS/XRD/SERVICE/URI':
63 $xrds_current_service['uri'] = $data;
64 break;
65 case 'XRDS/XRD/SERVICE/DELEGATE':
66 $xrds_current_service['delegate'] = $data;
67 break;
68 }
69 }
70
71 function _xrds_strip_namespace($name) {
72 // Strip namespacing.
73 $pos = strrpos($name, ':');
74 if ($pos !== FALSE) {
75 $name = substr($name, $pos + 1, strlen($name));
76 }
77
78 return $name;
79 }

  ViewVC Help
Powered by ViewVC 1.1.2