]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
more robust handling of new JIDs
authorEvan Prodromou <evan@controlezvous.ca>
Tue, 24 Jun 2008 01:56:16 +0000 (21:56 -0400)
committerEvan Prodromou <evan@controlezvous.ca>
Tue, 24 Jun 2008 01:56:16 +0000 (21:56 -0400)
darcs-hash:20080624015616-34904-c1ff985257c8c57aacf68439488d628a8b4d2e38.gz

actions/imsettings.php
lib/jabber.php

index 0496aaacd5fb6be74f533413edf4ccdccd435983..d8fc8b87cad3e3af0bded3d6210351c04323ebaa 100644 (file)
@@ -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();
 
index e6529446b9f3bfd508af30f5682d030b9a453c1f..97d02544d668c96f2995f572489de0a24c9cba0a 100644 (file)
@@ -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) {