summaryrefslogtreecommitdiff
path: root/modules/openid/xrds.inc
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2007-06-18 16:09:39 +0000
committerDries Buytaert <dries@buytaert.net>2007-06-18 16:09:39 +0000
commitaa308028aa570d15d3abf9c7679d7de16019b78b (patch)
treec7f87e5423007f088feb99149ebf2d16752631be /modules/openid/xrds.inc
parent8f9298577e7db9af6d34c3d69bd633a5c7e3de74 (diff)
downloadbrdo-aa308028aa570d15d3abf9c7679d7de16019b78b.tar.gz
brdo-aa308028aa570d15d3abf9c7679d7de16019b78b.tar.bz2
- Patch #131026 by James et al: OpenID client support for Drupal!
Let this be the day where we help revolutionize the online society, and the way websites and web services interoperate. Or something.
Diffstat (limited to 'modules/openid/xrds.inc')
-rw-r--r--modules/openid/xrds.inc79
1 files changed, 79 insertions, 0 deletions
diff --git a/modules/openid/xrds.inc b/modules/openid/xrds.inc
new file mode 100644
index 000000000..28fc979c4
--- /dev/null
+++ b/modules/openid/xrds.inc
@@ -0,0 +1,79 @@
+<?php
+// $Id$
+
+// Global variables to track parsing state
+$xrds_open_elements = array();
+$xrds_services = array();
+$xrds_current_service = array();
+
+/**
+ * Main entry point for parsing XRDS documents
+ */
+function xrds_parse($xml) {
+ global $xrds_services;
+
+ $parser = xml_parser_create_ns();
+ xml_set_element_handler($parser, '_xrds_element_start', '_xrds_element_end');
+ xml_set_character_data_handler($parser, '_xrds_cdata');
+
+ xml_parse($parser, $xml);
+ xml_parser_free($parser);
+
+ return $xrds_services;
+}
+
+/**
+ * Parser callback functions
+ */
+function _xrds_element_start(&$parser, $name, $attribs) {
+ global $xrds_open_elements;
+
+ $xrds_open_elements[] = _xrds_strip_namespace($name);
+}
+
+function _xrds_element_end(&$parser, $name) {
+ global $xrds_open_elements, $xrds_services, $xrds_current_service;
+
+ $name = _xrds_strip_namespace($name);
+ if ($name == 'SERVICE') {
+ if (in_array(OPENID_NS_2_0 .'/signon', $xrds_current_service['types']) ||
+ in_array(OPENID_NS_2_0 .'/server', $xrds_current_service['types'])) {
+ $xrds_current_service['version'] = 2;
+ }
+ elseif (in_array(OPENID_NS_1_1, $xrds_current_service['types']) ||
+ in_array(OPENID_NS_1_0, $xrds_current_service['types'])) {
+ $xrds_current_service['version'] = 1;
+ }
+ if (!empty($xrds_current_service['version'])) {
+ $xrds_services[] = $xrds_current_service;
+ }
+ $xrds_current_service = array();
+ }
+ array_pop($xrds_open_elements);
+}
+
+function _xrds_cdata(&$parser, $data) {
+ global $xrds_open_elements, $xrds_services, $xrds_current_service;
+ $path = strtoupper(implode('/', $xrds_open_elements));
+ switch ($path) {
+ case 'XRDS/XRD/SERVICE/TYPE':
+ $xrds_current_service['types'][] = $data;
+ break;
+ case 'XRDS/XRD/SERVICE/URI':
+ $xrds_current_service['uri'] = $data;
+ break;
+ case 'XRDS/XRD/SERVICE/DELEGATE':
+ $xrds_current_service['delegate'] = $data;
+ break;
+ }
+}
+
+function _xrds_strip_namespace($name) {
+ // Strip namespacing.
+ $pos = strrpos($name, ':');
+ if ($pos !== FALSE) {
+ $name = substr($name, $pos + 1, strlen($name));
+ }
+
+ return $name;
+} \ No newline at end of file