]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Added better error handling to signon method
authorLuke Fitzgerald <lw.fitzgerald@googlemail.com>
Mon, 14 Jun 2010 03:26:41 +0000 (04:26 +0100)
committerLuke Fitzgerald <lw.fitzgerald@googlemail.com>
Mon, 14 Jun 2010 03:26:41 +0000 (04:26 +0100)
plugins/Msn/extlib/phpmsnclass/msn.class.php

index 317acd0d532de3ec84a0b2eca768074cd52f67e7..73f02f6d7318d2c8c3330f087d6aa16c15121f07 100644 (file)
@@ -139,6 +139,7 @@ class MSN {
         }        \r
         $this->debug = isset($Configs['debug']) ? $Configs['debug'] : false;\r
         $this->timeout = $timeout;\r
+        \r
         // check support\r
         if (!function_exists('curl_init')) throw new Exception("We need curl module!\n");\r
         if (!function_exists('preg_match')) throw new Exception("We need pcre module!\n");\r
@@ -1089,54 +1090,56 @@ class MSN {
      */\r
     public function signon() {\r
         $this->log_message("*** try to connect to MSN network");\r
-        while(!$this->connect($this->user, $this->password))\r
-        {\r
-            $this->signonFailed("!!! Can't connect to server: $this->error");\r
-        }\r
-        if(!$this->UpdateContacts()) {\r
-            $this->signonFailed('!!! Could not update contacts');\r
-            return $this->signon();\r
-        }\r
-        $this->LastPing=time();\r
-        $this->log_message("*** connected, wait for command");\r
-        $start_tm = time();\r
-        $ping_tm = time();\r
-        if(($this->aContactList = $this->getMembershipList()) === false) {\r
-            $this->signonFailed('!!! Could not get Membership List');\r
-            return $this->signon();\r
-        }\r
-        if ($this->update_pending) {\r
-            if (is_array($this->aContactList)) {\r
-                $pending = 'Pending';\r
-                foreach ($this->aContactList as $u_domain => $aUserList) {\r
-                    foreach ($aUserList as $u_name => $aNetworks) {\r
-                        foreach ($aNetworks as $network => $aData) {\r
-                            if (isset($aData[$pending])) {\r
-                                // pending list\r
-                                $cnt = 0;\r
-                                foreach (array('Allow', 'Reverse') as $list) {\r
-                                    if (isset($aData[$list]))\r
-                                        $cnt++;\r
-                                    else {\r
-                                        if ($this->addMemberToList($u_name.'@'.$u_domain, $network, $list)) {\r
-                                            $this->aContactList[$u_domain][$u_name][$network][$list] = false;\r
+        \r
+        while(true) {\r
+            while(!$this->connect($this->user, $this->password))\r
+            {\r
+                $this->signonFailure("!!! Can't connect to server: $this->error");\r
+            }\r
+            if($this->UpdateContacts() === false) {\r
+                $this->signonFailure('!!! Update Contacts failed');\r
+                continue;\r
+            }\r
+            $this->LastPing=time();\r
+            $this->log_message("*** connected, wait for command");\r
+            $start_tm = time();\r
+            $ping_tm = time();\r
+            if(($this->aContactList = $this->getMembershipList()) === false) {\r
+                continue;\r
+            }\r
+            if ($this->update_pending) {\r
+                if (is_array($this->aContactList)) {\r
+                    $pending = 'Pending';\r
+                    foreach ($this->aContactList as $u_domain => $aUserList) {\r
+                        foreach ($aUserList as $u_name => $aNetworks) {\r
+                            foreach ($aNetworks as $network => $aData) {\r
+                                if (isset($aData[$pending])) {\r
+                                    // pending list\r
+                                    $cnt = 0;\r
+                                    foreach (array('Allow', 'Reverse') as $list) {\r
+                                        if (isset($aData[$list]))\r
                                             $cnt++;\r
+                                        else {\r
+                                            if ($this->addMemberToList($u_name.'@'.$u_domain, $network, $list)) {\r
+                                                $this->aContactList[$u_domain][$u_name][$network][$list] = false;\r
+                                                $cnt++;\r
+                                            }\r
                                         }\r
                                     }\r
+                                    if ($cnt >= 2) {\r
+                                        $id = $aData[$pending];\r
+                                        // we can delete it from pending now\r
+                                        if ($this->delMemberFromList($id, $u_name.'@'.$u_domain, $network, $pending))\r
+                                            unset($this->aContactList[$u_domain][$u_name][$network][$pending]);\r
+                                    }\r
                                 }\r
-                                if ($cnt >= 2) {\r
-                                    $id = $aData[$pending];\r
-                                    // we can delete it from pending now\r
-                                    if ($this->delMemberFromList($id, $u_name.'@'.$u_domain, $network, $pending))\r
-                                        unset($this->aContactList[$u_domain][$u_name][$network][$pending]);\r
-                                }\r
-                            }\r
-                            else {\r
-                                // sync list\r
-                                foreach (array('Allow', 'Reverse') as $list) {\r
-                                    if (!isset($aData[$list])) {\r
-                                        if ($this->addMemberToList($u_name.'@'.$u_domain, $network, $list))\r
-                                            $this->aContactList[$u_domain][$u_name][$network][$list] = false;\r
+                                else {\r
+                                    // sync list\r
+                                    foreach (array('Allow', 'Reverse') as $list) {\r
+                                        if (!isset($aData[$list])) {\r
+                                            if ($this->addMemberToList($u_name.'@'.$u_domain, $network, $list))\r
+                                                $this->aContactList[$u_domain][$u_name][$network][$list] = false;\r
+                                        }\r
                                     }\r
                                 }\r
                             }\r
@@ -1144,68 +1147,74 @@ class MSN {
                     }\r
                 }\r
             }\r
-        }\r
-        $n = 0;\r
-        $sList = '';\r
-        $len = 0;\r
-        if (is_array($this->aContactList)) {\r
-            foreach ($this->aContactList as $u_domain => $aUserList) {\r
-                $str = '<d n="'.$u_domain.'">';\r
-                $len += strlen($str);\r
-                if ($len > 7400) {\r
-                    $this->aADL[$n] = '<ml l="1">'.$sList.'</ml>';\r
-                    $n++;\r
-                    $sList = '';\r
-                    $len = strlen($str);\r
-                }\r
-                $sList .= $str;\r
-                foreach ($aUserList as $u_name => $aNetworks) {\r
-                    foreach ($aNetworks as $network => $status) {\r
-                        $str = '<c n="'.$u_name.'" l="3" t="'.$network.'" />';\r
-                        $len += strlen($str);\r
-                        // max: 7500, but <ml l="1"></d></ml> is 19,\r
-                        // so we use 7475\r
-                        if ($len > 7475) {\r
-                            $sList .= '</d>';\r
-                            $this->aADL[$n] = '<ml l="1">'.$sList.'</ml>';\r
-                            $n++;\r
-                            $sList = '<d n="'.$u_domain.'">'.$str;\r
-                            $len = strlen($sList);\r
+            $n = 0;\r
+            $sList = '';\r
+            $len = 0;\r
+            if (is_array($this->aContactList)) {\r
+                foreach ($this->aContactList as $u_domain => $aUserList) {\r
+                    $str = '<d n="'.$u_domain.'">';\r
+                    $len += strlen($str);\r
+                    if ($len > 7400) {\r
+                        $this->aADL[$n] = '<ml l="1">'.$sList.'</ml>';\r
+                        $n++;\r
+                        $sList = '';\r
+                        $len = strlen($str);\r
+                    }\r
+                    $sList .= $str;\r
+                    foreach ($aUserList as $u_name => $aNetworks) {\r
+                        foreach ($aNetworks as $network => $status) {\r
+                            $str = '<c n="'.$u_name.'" l="3" t="'.$network.'" />';\r
+                            $len += strlen($str);\r
+                            // max: 7500, but <ml l="1"></d></ml> is 19,\r
+                            // so we use 7475\r
+                            if ($len > 7475) {\r
+                                $sList .= '</d>';\r
+                                $this->aADL[$n] = '<ml l="1">'.$sList.'</ml>';\r
+                                $n++;\r
+                                $sList = '<d n="'.$u_domain.'">'.$str;\r
+                                $len = strlen($sList);\r
+                            }\r
+                            else\r
+                                $sList .= $str;\r
                         }\r
-                        else\r
-                            $sList .= $str;\r
                     }\r
+                    $sList .= '</d>';\r
                 }\r
-                $sList .= '</d>';\r
             }\r
-        }\r
-        $this->aADL[$n] = '<ml l="1">'.$sList.'</ml>';\r
-        // NS: >>> BLP {id} BL\r
-        $this->ns_writeln("BLP $this->id BL");\r
-        foreach ($this->aADL as $str) {\r
+            $this->aADL[$n] = '<ml l="1">'.$sList.'</ml>';\r
+            // NS: >>> BLP {id} BL\r
+            $this->ns_writeln("BLP $this->id BL");\r
+            foreach ($this->aADL as $str) {\r
+                $len = strlen($str);\r
+                // NS: >>> ADL {id} {size}\r
+                $this->ns_writeln("ADL $this->id $len");\r
+                $this->ns_writedata($str);\r
+            }\r
+            // NS: >>> PRP {id} MFN name\r
+            if ($this->alias == '') $this->alias = $user;\r
+            $aliasname = rawurlencode($this->alias);\r
+            $this->ns_writeln("PRP $this->id MFN $aliasname");\r
+            //設定個人大頭貼\r
+            //$MsnObj=$this->PhotoStckObj();\r
+            // NS: >>> CHG {id} {status} {clientid} {msnobj}\r
+            $this->ns_writeln("CHG $this->id NLN $this->clientid");\r
+            if($this->PhotoStickerFile!==false)\r
+                $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile)));\r
+            // NS: >>> UUX {id} length\r
+            $str = '<Data><PSM>'.htmlspecialchars($this->psm).'</PSM><CurrentMedia></CurrentMedia><MachineGuid></MachineGuid></Data>';\r
             $len = strlen($str);\r
-            // NS: >>> ADL {id} {size}\r
-            $this->ns_writeln("ADL $this->id $len");\r
+            $this->ns_writeln("UUX $this->id $len");\r
             $this->ns_writedata($str);\r
+            break;\r
         }\r
-        // NS: >>> PRP {id} MFN name\r
-        if ($this->alias == '') $this->alias = $user;\r
-        $aliasname = rawurlencode($this->alias);\r
-        $this->ns_writeln("PRP $this->id MFN $aliasname");\r
-        //設定個人大頭貼\r
-        //$MsnObj=$this->PhotoStckObj();\r
-        // NS: >>> CHG {id} {status} {clientid} {msnobj}\r
-        $this->ns_writeln("CHG $this->id NLN $this->clientid");\r
-        if($this->PhotoStickerFile!==false)\r
-            $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile)));\r
-        // NS: >>> UUX {id} length\r
-        $str = '<Data><PSM>'.htmlspecialchars($this->psm).'</PSM><CurrentMedia></CurrentMedia><MachineGuid></MachineGuid></Data>';\r
-        $len = strlen($str);\r
-        $this->ns_writeln("UUX $this->id $len");\r
-        $this->ns_writedata($str);\r
     }\r
     \r
-    private function signonFailed($message) {\r
+    /**\r
+    * Called if there is an error during signon\r
+    * \r
+    * @param $message Error message to log\r
+    */\r
+    private function signonFailure($message) {\r
         $this->log_message($message);\r
         $this->callHandler('ConnectFailed', NULL);\r
         $this->NSRetryWait($this->retry_wait);\r