diff options
author | Evan Prodromou <evan@controlezvous.ca> | 2008-06-23 21:56:16 -0400 |
---|---|---|
committer | Evan Prodromou <evan@controlezvous.ca> | 2008-06-23 21:56:16 -0400 |
commit | e330eb50d2c36505270375360303083decedee98 (patch) | |
tree | 6161803dd219ade3d3150f1b2c9d988cae91be44 | |
parent | 939a3e48d896f318a40c8ef2e1b13e79d6e7eb94 (diff) |
more robust handling of new JIDs
darcs-hash:20080624015616-34904-c1ff985257c8c57aacf68439488d628a8b4d2e38.gz
-rw-r--r-- | actions/imsettings.php | 25 | ||||
-rw-r--r-- | lib/jabber.php | 13 |
2 files changed, 24 insertions, 14 deletions
diff --git a/actions/imsettings.php b/actions/imsettings.php index 0496aaacd..d8fc8b87c 100644 --- a/actions/imsettings.php +++ b/actions/imsettings.php @@ -62,19 +62,26 @@ class ImsettingsAction extends SettingsAction { function handle_post() { - $jabber = jabber_normalize_jid($this->trimmed('jabber')); + $jabber = $this->trimmed('jabber'); $jabbernotify = $this->boolean('jabbernotify'); $updatefrompresence = $this->boolean('updatefrompresence'); - if (!jabber_valid_base_jid($jabber)) { - $this->show_form(_('Not a valid Jabber ID')); - return; - } else if ($this->jabber_exists($jabber)) { - $this->show_form(_('Not a valid Jabber ID')); - return; - } - # Some validation + + if ($jabber) { + $jabber = jabber_normalize_jid($jabber); + if (!$jabber) { + $this->show_form(_('Cannot normalize that Jabber ID')); + return; + } + if (!jabber_valid_base_jid($jabber)) { + $this->show_form(_('Not a valid Jabber ID')); + return; + } else if ($this->jabber_exists($jabber)) { + $this->show_form(_('Jabber ID already belongs to another user.')); + return; + } + } $user = common_current_user(); diff --git a/lib/jabber.php b/lib/jabber.php index e6529446b..97d02544d 100644 --- a/lib/jabber.php +++ b/lib/jabber.php @@ -27,11 +27,14 @@ function jabber_valid_base_jid($jid) { } function jabber_normalize_jid($jid) { - preg_match("/(?:([^\@]+)\@)?([^\/]+)(?:\/(.*))?$/", $jid, $matches); - $node = $matches[1]; - $server = $matches[2]; - $resource = $matches[3]; - return strtolower($node.'@'.$server); + if (preg_match("/(?:([^\@]+)\@)?([^\/]+)(?:\/(.*))?$/", $jid, $matches)) { + $node = $matches[1]; + $server = $matches[2]; + $resource = $matches[3]; + return strtolower($node.'@'.$server); + } else { + return NULL; + } } function jabber_connect($resource=NULL) { |