From 50610c2611b16aced92539117b9021253dc150f9 Mon Sep 17 00:00:00 2001 From: Luke Fitzgerald Date: Wed, 16 Jun 2010 14:15:08 +0100 Subject: [PATCH] Added some more error handling and commenting --- plugins/Msn/MsnPlugin.php | 5 +++++ plugins/Msn/extlib/phpmsnclass/msn.class.php | 21 ++++++++++---------- plugins/Msn/msnmanager.php | 8 ++++++++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/plugins/Msn/MsnPlugin.php b/plugins/Msn/MsnPlugin.php index f00333d728..acbc6446e0 100644 --- a/plugins/Msn/MsnPlugin.php +++ b/plugins/Msn/MsnPlugin.php @@ -118,6 +118,11 @@ class MsnPlugin extends ImPlugin { } } + /* + * Start manager on daemon start + * + * @return boolean + */ public function onStartImDaemonIoManagers(&$classes) { parent::onStartImDaemonIoManagers(&$classes); $classes[] = new MsnManager($this); // handles sending/receiving diff --git a/plugins/Msn/extlib/phpmsnclass/msn.class.php b/plugins/Msn/extlib/phpmsnclass/msn.class.php index 378a3eb3ce..3d33340b22 100644 --- a/plugins/Msn/extlib/phpmsnclass/msn.class.php +++ b/plugins/Msn/extlib/phpmsnclass/msn.class.php @@ -1455,7 +1455,6 @@ class MSN { private function sendMessageViaSB($to, $message) { $socket = $this->switchBoardSessionLookup[$to]; if (self::socketcheck($socket)) { - $this->endSBSession($socket); return false; } @@ -1469,21 +1468,24 @@ class MSN { $aMessage = $this->getMessage($Message); // CheckEmotion... - $MsnObjDefine=$this->GetMsnObjDefine($aMessage); + $MsnObjDefine = $this->GetMsnObjDefine($aMessage); if ($MsnObjDefine !== '') { $SendString = "MIME-Version: 1.0\r\nContent-Type: text/x-mms-emoticon\r\n\r\n$MsnObjDefine"; $len = strlen($SendString); - // TODO handle failure during write to socket - $this->sb_writeln($socket, $id, "MSG $id N $len"); - $this->sb_writedata($socket, $SendString); + + if ($this->sb_writeln($socket, $id, "MSG $id N $len") === false || + $this->sb_writedata($socket, $SendString) === false) { + return false; + } } $len = strlen($aMessage); - // TODO handle failure during write to socket - $this->sb_writeln($socket, $id, "MSG $id N $len"); - $this->sb_writedata($socket, $aMessage); - // Don't close the SB session, we might as well leave it open + if ($this->sb_writeln($socket, $id, "MSG $id N $len") === false || + $this->sb_writedata($socket, $aMessage) === false) { + return false; + } + // Don't close the SB session, we might as well leave it open return true; } @@ -1995,7 +1997,6 @@ X-OIM-Sequence-Num: 1 $str = ''; $len = strlen($str); // NS: >>> ADL {id} {size} - //TODO introduce error checking $this->ns_writeln("ADL $this->id $len"); $this->ns_writedata($str); } diff --git a/plugins/Msn/msnmanager.php b/plugins/Msn/msnmanager.php index 66152f0d2a..9826608ea6 100644 --- a/plugins/Msn/msnmanager.php +++ b/plugins/Msn/msnmanager.php @@ -134,7 +134,9 @@ class MsnManager extends ImManager { /** * Update the time till the next ping + * * @param $data Time till next ping + * @return void */ private function update_ping_time($data) { $pingInterval = $data; @@ -173,6 +175,12 @@ class MsnManager extends ImManager { common_log(LOG_NOTICE, 'MSN reconnecting'); } + /** + * Send a message using the daemon + * + * @param $data Message + * @return boolean true on success + */ function send_raw_message($data) { $this->connect(); if (!$this->conn) { -- 2.39.5