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

Contents of /drupal/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)
Mon Apr 14 17:48:38 2008 UTC (19 months, 1 week ago) by dries
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-6, DRUPAL-7-0-UNSTABLE-7, DRUPAL-7-0-UNSTABLE-10, DRUPAL-7-0-UNSTABLE-1, DRUPAL-7-0-UNSTABLE-2, DRUPAL-7-0-UNSTABLE-3, DRUPAL-7-0-UNSTABLE-4, DRUPAL-7-0-UNSTABLE-5, DRUPAL-7-0-UNSTABLE-8, DRUPAL-7-0-UNSTABLE-9, HEAD
Changes since 1.2: +3 -3 lines
File MIME type: text/x-php
- Patch #245115 by kkaefer, John Morahan, JohnAlbin et al: after a long discussion we've decided to make the concatenation operator consistent with the other operators.
1 <?php
2 // $Id: xrds.inc,v 1.2 2007/10/15 09:40:42 goba 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 case 'XRDS/XRD/SERVICE/LOCALID':
69 $xrds_current_service['localid'] = $data;
70 break;
71 }
72 }
73
74 function _xrds_strip_namespace($name) {
75 // Strip namespacing.
76 $pos = strrpos($name, ':');
77 if ($pos !== FALSE) {
78 $name = substr($name, $pos + 1, strlen($name));
79 }
80
81 return $name;
82 }

  ViewVC Help
Powered by ViewVC 1.1.2