From 0841fa712ec558d283f533690d2db50dfa1da8fc Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 30 Mar 2010 17:35:27 -0700 Subject: Ticket #1281: JID validation now more or less follows spec instead of calling e-mail validator Basic splitting/validation code submitted via http://status.net/wiki/XMPP/JID_validation -- Copyright 2009 Patrick Georgi Licensed under ISC-L, which is compatible with everything else that keeps the copyright notice intact. Added PEAR Net_IDNA package to extlib to handle IDN normalization (also used by Validate's email verifier if present). * added test suite, supplemented my own test cases with JID validation and normalization test cases from libpurple * follows XMPP rules for validation of name part * fixes for normalization with non-ASCII names * will do domain checks if $config['email']['check_domain'] is on, checking for an XMPP-server SRV record or any lookup. (We don't actually need to ping those direct though.) * some more obscure stringprep validation rules aren't quite followed yet, but we err on the side of permissiveness. * we still don't actually let you save your address with a resource on it, as we strip resources when looking up users who've sent us presence or message updates. I would recommend saving the outgoing resource as a separate field if/when we add that..? --- extlib/Net/IDNA.php | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 extlib/Net/IDNA.php (limited to 'extlib/Net/IDNA.php') diff --git a/extlib/Net/IDNA.php b/extlib/Net/IDNA.php new file mode 100644 index 000000000..987a37ef1 --- /dev/null +++ b/extlib/Net/IDNA.php @@ -0,0 +1,100 @@ + + * @author Matthias Sommerfeld + * @package Net + * @version $Id: IDNA.php 284681 2009-07-24 04:24:27Z clockwerx $ + */ + +class Net_IDNA +{ + // {{{ factory + /** + * Attempts to return a concrete IDNA instance for either php4 or php5. + * + * @param array $params Set of paramaters + * @return object IDNA The newly created concrete Log instance, or an + * false on an error. + * @access public + */ + function getInstance($params = array()) + { + $version = explode( '.', phpversion() ); + $handler = ((int)$version[0] > 4) ? 'php5' : 'php4'; + $class = 'Net_IDNA_' . $handler; + $classfile = 'Net/IDNA/' . $handler . '.php'; + + /* + * Attempt to include our version of the named class, but don't treat + * a failure as fatal. The caller may have already included their own + * version of the named class. + */ + @include_once $classfile; + + /* If the class exists, return a new instance of it. */ + if (class_exists($class)) { + return new $class($params); + } + + return false; + } + // }}} + + // {{{ singleton + /** + * Attempts to return a concrete IDNA instance for either php4 or php5, + * only creating a new instance if no IDNA instance with the same + * parameters currently exists. + * + * @param array $params Set of paramaters + * @return object IDNA The newly created concrete Log instance, or an + * false on an error. + * @access public + */ + function singleton($params = array()) + { + static $instances; + if (!isset($instances)) { + $instances = array(); + } + + $signature = serialize($params); + if (!isset($instances[$signature])) { + $instances[$signature] = Net_IDNA::getInstance($params); + } + + return $instances[$signature]; + } + // }}} +} + +?> -- cgit v1.2.3-54-g00ecf