Index: text/apidoc/Reference.class.php =================================================================== --- text/apidoc/Reference.class.php (revision 5897) +++ text/apidoc/Reference.class.php (working copy) @@ -85,18 +85,22 @@ * @throws FormatException in case the scheme is'nt recognized */ function fromString($str) { - if (FALSE !== ($p= strpos($str, ' '))) { - $this->link= parse_url(substr($str, 0, $p)); - $this->link['description']= substr($str, $p+ 1); - } else { - $this->link= parse_url($str); - $this->link['description']= NULL; - } + $u= new URL(FALSE !== ($p= strpos($str, ' ')) + ? substr($str, 0, $p) + : $str + ); + $this->link= array( + 'scheme' => $u->getScheme('xp'), // Links without scheme are internal + 'user' => $u->getUser(), + 'pass' => $u->getPassword(), + 'host' => $u->getHost(), + 'port' => $u->getPort(), + 'path' => $u->getPath(), + 'query' => $u->getQuery() + 'fragment' => $u->getFragment() + 'description' => $p !== FALSE ? substr($str, $p+ 1) : NULL + ); - // Links without scheme are internal - if (empty($this->link['scheme'])) { - $this->link['scheme']= 'xp'; - } if (in_array($this->link['scheme'], Reference::getValidSchemes())) return; throw(new FormatException('Scheme '.$this->link['scheme'].' not recognized')); Index: org/webdav/WebdavScriptlet.class.php =================================================================== --- org/webdav/WebdavScriptlet.class.php (revision 5897) +++ org/webdav/WebdavScriptlet.class.php (working copy) @@ -768,19 +768,19 @@ // Select implementation $this->handlingImpl= NULL; foreach (array_keys($this->impl) as $pattern) { - if (0 !== strpos(rtrim($request->uri['path'], '/').'/', $pattern)) continue; + if (0 !== strpos(rtrim($request->uri->getPath(), '/').'/', $pattern)) continue; // Set the root URL (e.g. http://wedav.host.com/dav/) $request->setRootURL($rootURL= &new URL(sprintf( '%s://%s%s', - $request->uri['scheme'], - $request->uri['host'], + $request->uri->getScheme(), + $request->uri->Host(), $pattern ))); // Set request path (e.g. /directory/file) $request->setPath($request->decodePath(substr( - $request->uri['path'], + $request->uri->getPath(), strlen($pattern) ))); @@ -793,7 +793,7 @@ // Implementation not found if (NULL === $this->handlingImpl) { - return throw(new HttpScriptlet('Cannot handle requests to '.$request->uri['path'])); + return throw(new HttpScriptlet('Cannot handle requests to '.$request->uri->getPath())); } // determine Useragent Index: peer/mail/transport/SmtpTransport.class.php =================================================================== --- peer/mail/transport/SmtpTransport.class.php (revision 5897) +++ peer/mail/transport/SmtpTransport.class.php (working copy) @@ -4,7 +4,7 @@ * $Id$ */ - uses('peer.mail.transport.Transport', 'peer.Socket'); + uses('peer.URL', 'peer.mail.transport.Transport', 'peer.Socket'); // Authentication methods define('SMTP_AUTH_PLAIN', 'plain'); @@ -176,13 +176,13 @@ function _parsedsn($dsn) { if (NULL === $dsn) return TRUE; - $u= parse_url($dsn); - if (!isset($u['host'])) { + $u= &new URL($dsn); + if (!$u->getHost()) { return throw(new IllegalArgumentException('DSN parsing failed ["'.$dsn.'"]')); } // Scheme - switch (strtoupper($u['scheme'])) { + switch (strtoupper($u->getScheme())) { case 'ESMTP': $this->ext= TRUE; break; @@ -192,23 +192,20 @@ break; default: - return throw(new IllegalArgumentException('Scheme "'.$u['scheme'].'" not supported')); + return throw(new IllegalArgumentException('Scheme "'.$u->getScheme().'" not supported')); } // Copy host and port - $this->host= $u['host']; - $this->port= isset($u['port']) ? $u['port'] : 25; + $this->host= $u->getHost(); + $this->port= $u->getPort() ? $u->getPort() : 25; // Extra attributes - if (isset($u['query'])) { - parse_str($u['query'], $attr); - $this->auth= isset($attr['auth']) ? $attr['auth'] : SMTP_AUTH_PLAIN; - } + $this->auth= $u->getParam('auth') ? $u->getParam('auth') : SMTP_AUTH_PLAIN; // User & password - if (isset($u['user'])) { - $this->user= $u['user']; - $this->pass= $u['pass']; + if ($u->getUser()) { + $this->user= $u->getUser(); + $this->pass= $u->getPassword(); } } Index: peer/mail/store/Pop3Store.class.php =================================================================== --- peer/mail/store/Pop3Store.class.php (revision 5897) +++ peer/mail/store/Pop3Store.class.php (working copy) @@ -24,14 +24,14 @@ * * * @access protected - * @param array u + * @param peer.URL * @param &array attr * @param &int port * @return bool * @throws IllegalArgumentException */ function _supports($u, &$attr) { - switch (strtolower($u['scheme'])) { + switch (strtolower($u->getScheme())) { case 'pop3': $attr['proto']= 'pop3'; $attr['port']= 110; Index: peer/mail/store/CclientStore.class.php =================================================================== --- peer/mail/store/CclientStore.class.php (revision 5897) +++ peer/mail/store/CclientStore.class.php (working copy) @@ -4,7 +4,7 @@ * $Id$ */ - uses('peer.mail.store.MailStore'); + uses('peer.URL', 'peer.mail.store.MailStore'); /** * Mail store @@ -35,14 +35,14 @@ * Protected method to check whether this DSN is supported * * @access protected - * @param array u + * @param &peer.URL u * @param &array attr * @param &int port * @return bool * @throws IllegalArgumentException */ - function _supports($u, &$attr) { - return throw(new IllegalArgumentException('Scheme "'.$u['scheme'].'" not recognized')); + function _supports(&$u, &$attr) { + return throw(new IllegalArgumentException('Scheme "'.$u->getScheme().'" not recognized')); } /** @@ -60,28 +60,27 @@ $flags= OP_HALFOPEN; // Parse DSN - $u= parse_url($dsn); - if (isset($u['query'])) parse_str($u['query'], $attr); + $u= &new URL($dsn); // DSN supported? - if (FALSE === $this->_supports($u, $attr)) return FALSE; + if (FALSE === $this->_supports($u, $u->getParams())) return FALSE; // Read-only? - if (!empty($attr['open'])) $flags ^= OP_HALFOPEN; - if (!empty($attr['read-only'])) $flags |= OP_READONLY; + if ($u->getParam('open')) $flags ^= OP_HALFOPEN; + if ($u->getParam('read-only')) $flags |= OP_READONLY; - $mbx= isset($attr['mbx']) ? $attr['mbx'] : sprintf( + $mbx= $u->getParam('mbx') ? $u->getParam('mbx') : sprintf( '{%s:%d/%s}', - $u['host'], - isset($u['port']) ? $u['port'] : $attr['port'], - $attr['proto'] + $u->getHost(), + $u->getPort() ? $u->getPort() : $u->getParam('port'), + $u->getParam('proto') ); // Connect - if (FALSE === ($conn= imap_open($mbx, @$u['user'], @$u['pass'], $flags))) { + if (FALSE === ($conn= imap_open($mbx, @$u->getUser(), @$u->getPassword(), $flags))) { return throw(new MessagingException( - 'Connect to "'.$u['user'].'@'.$mbx.'" failed', + 'Connect to "'.$u->getUser().'@'.$mbx.'" failed', $this->_errors() )); } Index: peer/mail/store/MboxStore.class.php =================================================================== --- peer/mail/store/MboxStore.class.php (revision 5897) +++ peer/mail/store/MboxStore.class.php (working copy) @@ -23,14 +23,14 @@ * * * @access protected - * @param array u + * @param peer.URL u * @param &array attr * @param &int port * @return bool * @throws IllegalArgumentException */ - function _supports($u, &$attr) { - switch (strtolower($u['scheme'])) { + function _supports(&$u, &$attr) { + switch (strtolower($u->getScheme())) { case 'mbox': $attr['mbx']= '/'.$u['host'].$u['path']; $attr['open']= TRUE; Index: peer/mail/store/ImapStore.class.php =================================================================== --- peer/mail/store/ImapStore.class.php (revision 5897) +++ peer/mail/store/ImapStore.class.php (working copy) @@ -27,14 +27,14 @@ * * * @access protected - * @param array u + * @param peer.URL u * @param &array attr * @param &int port * @return bool * @throws IllegalArgumentException */ - function _supports($u, &$attr) { - switch (strtolower($u['scheme'])) { + function _supports(&$u, &$attr) { + switch (strtolower($u->getScheme())) { case 'imap': $attr['proto']= 'imap'; $attr['port']= 143; Index: peer/ftp/FtpConnection.class.php =================================================================== --- peer/ftp/FtpConnection.class.php (revision 5897) +++ peer/ftp/FtpConnection.class.php (working copy) @@ -5,6 +5,7 @@ */ uses( + 'peer.URL', 'peer.ftp.FtpDir', 'peer.SocketException', 'peer.ConnectException', @@ -82,12 +83,12 @@ function _dsn($dsn) { // URL and defaults - $this->url= parse_url($dsn); - $this->url['host']= empty($this->url['host']) ? 'localhost' : $this->url['host']; - $this->url['port']= empty($this->url['port']) ? 21 : $this->url['port']; + $this->url= &new URL($dsn); + $this->url->getHost() || $this->url->_info['host']= 'localhost'; + $this->url->getPort() || $this->url->_info['port']= 21; // Options and defaults - if (!empty($this->url['query'])) parse_str($this->url['query'], $this->opt); + $this->opt= $this->url->getParams(); $this->opt['timeout']= empty($this->opt['timeout']) ? 4 : $this->opt['timeout']; } @@ -100,19 +101,19 @@ * @throws peer.AuthenticationException when authentication fails */ function connect() { - switch ($this->url['scheme']) { + switch ($this->url->getScheme()) { case 'ftp': $this->_hdl= ftp_connect( - $this->url['host'], - $this->url['port'], + $this->url->getHost(), + $this->url->getPort(), $this->opt['timeout'] ); break; case 'ftps': $this->_hdl= ftp_ssl_connect( - $this->url['host'], - $this->url['port'], + $this->url->getHost(), + $this->url->getPort(), $this->opt['timeout'] ); break; @@ -121,17 +122,17 @@ if (!is_resource($this->_hdl)) { return throw(new ConnectException(sprintf( 'Could not connect to %s:%d within %d seconds', - $this->url['host'], $this->url['port'], $this->opt['timeout'] + $this->url->getHost(), $this->url->getPort(), $this->opt['timeout'] ))); } // User & password - if (empty($this->url['user'])) return TRUE; + if (!$this->url->getUser()) return TRUE; - if (FALSE === ftp_login($this->_hdl, $this->url['user'], $this->url['pass'])) { + if (FALSE === ftp_login($this->_hdl, $this->url->getUser(), $this->url->getPassword())) { return throw(new AuthenticationException(sprintf( 'Authentication failed for %s@%s (using password: %s)', - $this->url['user'], $this->url['host'], empty($this->url['pass']) ? 'no' : 'yes' + $this->url->getUser(), $this->url->getHost(), $this->url->getPassword() ? 'no' : 'yes' ))); } Index: peer/URL.class.php =================================================================== --- peer/URL.class.php (revision 5897) +++ peer/URL.class.php (working copy) @@ -255,6 +255,8 @@ */ function setURL($str) { $this->_info= parse_url($str); + if (isset($this->_info['user'])) $this->_info['user']= rawurldecode($this->_info['user']); + if (isset($this->_info['pass'])) $this->_info['pass']= rawurldecode($this->_info['pass']); if (isset($this->_info['query'])) { parse_str($this->_info['query'], $this->_info['params']); } else { Index: rdbms/DSN.class.php =================================================================== --- rdbms/DSN.class.php (revision 5897) +++ rdbms/DSN.class.php (working copy) @@ -4,6 +4,8 @@ * $Id$ */ + uses('peer.URL'); + define('DB_STORE_RESULT', 0x0001); define('DB_UNBUFFERED', 0x0002); define('DB_AUTOCONNECT', 0x0004); @@ -21,7 +23,9 @@ */ class DSN extends Object { var - $parts = array(), + $url = NULL, + $dsn = array(), + $flags = 0, $prop = array(); /** @@ -31,17 +35,13 @@ * @param string str */ function __construct($str) { - $this->parts['dsn']= $str; - foreach (parse_url($str) as $key => $value) { - $this->parts[$key]= urldecode($value); - } + $this->url= &new URL($str); + $this->dsn= $str; - $this->parts['flags']= 0; - if (isset($this->parts['query'])) { - parse_str($this->parts['query'], $config); + if ($config= $this->url->getParams()) { foreach ($config as $key => $value) { if (defined('DB_'.strtoupper($key))) { - if ($value) $this->parts['flags']= $this->parts['flags'] | constant('DB_'.strtoupper($key)); + if ($value) $this->flags= $this->flags | constant('DB_'.strtoupper($key)); } else { $this->prop[$key]= $value; } @@ -56,7 +56,7 @@ * @return int flags */ function getFlags() { - return $this->parts['flags']; + return $this->flags; } /** @@ -95,7 +95,7 @@ * @return string driver or default if none is set */ function getDriver($default= NULL) { - return isset($this->parts['scheme']) ? $this->parts['scheme'] : $default; + return $this->url->getScheme() ? $this->url->getScheme() : $default; } /** @@ -106,7 +106,7 @@ * @return string host or default if none is set */ function getHost($default= NULL) { - return isset($this->parts['host']) ? $this->parts['host'] : $default; + return $this->url->getHost() ? $this->url->getHost() : $default; } /** @@ -117,7 +117,7 @@ * @return string host or default if none is set */ function getPort($default= NULL) { - return isset($this->parts['port']) ? $this->parts['port'] : $default; + return $this->url->getPort() ? $this->url->getPort() : $default; } /** @@ -128,7 +128,7 @@ * @return string databse or default if none is set */ function getDatabase($default= NULL) { - return isset($this->parts['path']) ? substr($this->parts['path'], 1) : $default; + return $this->url->getPath() ? substr($this->url->getPath(), 1) : $default; } /** @@ -139,7 +139,7 @@ * @return string user or default if none is set */ function getUser($default= NULL) { - return isset($this->parts['user']) ? $this->parts['user'] : $default; + return $this->url->getUser() ? $this->url->getUser() : $default; } /** @@ -150,7 +150,7 @@ * @return string password or default if none is set */ function getPassword($default= NULL) { - return isset($this->parts['pass']) ? $this->parts['pass'] : $default; + return $this->url->getPassword() ? $this->url->getPassword() : $default; } /** @@ -163,18 +163,18 @@ return sprintf( '%s@(%s://%s%s%s/%s%s)', $this->getClassName(), - $this->parts['scheme'], - (isset($this->parts['user']) - ? $this->parts['user'].(isset($this->parts['pass']) ? ':'.str_repeat('*', strlen($this->parts['pass'])) : '').'@' + $this->url->getScheme(), + ($this->url->getUser() + ? $this->url->getUser().($this->url->getPassword() ? ':'.str_repeat('*', strlen($this->url->getPassword())) : '').'@' : '' ), - $this->parts['host'], - (isset($this->parts['port']) - ? ':'.$this->parts['port'] + $this->url->getHost(), + ($this->url->getPort() + ? ':'.$this->url->getPort() : '' ), $this->getDatabase() ? $this->getDatabase() : '', - $this->parts['query'] ? '?'.$this->parts['query'] : '' + $this->url->getQuery() ? '?'.$this->url->getQuery() : '' ); } } Index: scriptlet/xml/XMLScriptlet.class.php =================================================================== --- scriptlet/xml/XMLScriptlet.class.php (revision 5897) +++ scriptlet/xml/XMLScriptlet.class.php (working copy) @@ -122,7 +122,7 @@ * @return bool */ function doRedirect(&$request, &$response, $sessionId= NULL) { - $uri= $request->getURI(); + $uri= &$request->getURL(); // Get product, language and statename from the environment if // necessary. Their default values are "site" (product), @@ -140,14 +140,14 @@ // Send redirect $response->sendRedirect(sprintf( '%s://%s/xml/%s.%s%s/%s%s%s', - $uri['scheme'], - $uri['host'], + $uri->getScheme(), + $uri->getHost(), $product, $language, empty($sessionId) ? '' : '.psessionid='.$sessionId, $stateName, - empty($uri['query']) ? '' : '?'.$uri['query'], - empty($uri['fraction']) ? '' : '#'.$uri['fraction'] + $uri->getQuery() ? '?'.$uri->getQuery() : '', + $uri->getFragment() ? '#'.$uri->getFragment() : '' )); return FALSE; // Indicate no further processing is to be done Index: scriptlet/HttpScriptlet.class.php =================================================================== --- scriptlet/HttpScriptlet.class.php (revision 5897) +++ scriptlet/HttpScriptlet.class.php (working copy) @@ -287,17 +287,17 @@ * @throws Exception to indicate failure */ function doCreateSession(&$request, &$response) { - $uri= $request->getURI(); + $uri= &$request->getURL(); $response->sendRedirect(sprintf( $this->sessionURIFormat, - $uri['scheme'], - $uri['host'], - $uri['path'], - dirname($uri['path']), - basename($uri['path']), - $uri['query'], + $uri->getScheme(), + $uri->getHost(), + $uri->getPath(), + dirname($uri->getPath()), + basename($uri->getPath()), + $uri->getQuery(), $request->session->getId(), - $uri['fraction'] + $uri->getFragment() )); return FALSE; } @@ -336,7 +336,7 @@ $request->headers= array_change_key_case(getallheaders(), CASE_LOWER); $request->method= getenv('REQUEST_METHOD'); $request->setParams(array_change_key_case($_REQUEST, CASE_LOWER)); - $request->setURI(parse_url( + $request->setURI(new URL( ('on' == getenv('HTTPS') ? 'https' : 'http').'://'. getenv('HTTP_HOST'). getenv('REQUEST_URI') Index: scriptlet/HttpScriptletRequest.class.php =================================================================== --- scriptlet/HttpScriptletRequest.class.php (revision 5897) +++ scriptlet/HttpScriptletRequest.class.php (working copy) @@ -175,22 +175,30 @@ * Sets request's URI * * @access public - * @param uri URI a uri parsed by parse_url() - * @see php://parse_url + * @param peer.URL uri a uri representated by peer.URL */ - function setURI($uri) { - $this->uri= $uri; + function setURI(&$uri) { + $this->uri= &$uri; } /** - * Retrieves the requests absolute URI as an uri (which consists - * of one or more of the following attributes: scheme, host, port, - * user, pass, path, query and fragment). + * Retrieves the requests absolute URI as an URL object * * @access public - * @return uri URI + * @return string */ + #[@deprecated] function getURI() { + return $this->uri->_info; // HACK + } + + /** + * Retrieves the requests absolute URI as an URL object + * + * @access public + * @return peer.URL + */ + function &getURL() { return $this->uri; }