Added some more error handling and commenting

This commit is contained in:
Luke Fitzgerald 2010-06-16 14:15:08 +01:00
parent a665739283
commit 50610c2611
3 changed files with 24 additions and 10 deletions

View File

@ -118,6 +118,11 @@ class MsnPlugin extends ImPlugin {
} }
} }
/*
* Start manager on daemon start
*
* @return boolean
*/
public function onStartImDaemonIoManagers(&$classes) { public function onStartImDaemonIoManagers(&$classes) {
parent::onStartImDaemonIoManagers(&$classes); parent::onStartImDaemonIoManagers(&$classes);
$classes[] = new MsnManager($this); // handles sending/receiving $classes[] = new MsnManager($this); // handles sending/receiving

View File

@ -1455,7 +1455,6 @@ class MSN {
private function sendMessageViaSB($to, $message) { private function sendMessageViaSB($to, $message) {
$socket = $this->switchBoardSessionLookup[$to]; $socket = $this->switchBoardSessionLookup[$to];
if (self::socketcheck($socket)) { if (self::socketcheck($socket)) {
$this->endSBSession($socket);
return false; return false;
} }
@ -1469,21 +1468,24 @@ class MSN {
$aMessage = $this->getMessage($Message); $aMessage = $this->getMessage($Message);
// CheckEmotion... // CheckEmotion...
$MsnObjDefine=$this->GetMsnObjDefine($aMessage); $MsnObjDefine = $this->GetMsnObjDefine($aMessage);
if ($MsnObjDefine !== '') { if ($MsnObjDefine !== '') {
$SendString = "MIME-Version: 1.0\r\nContent-Type: text/x-mms-emoticon\r\n\r\n$MsnObjDefine"; $SendString = "MIME-Version: 1.0\r\nContent-Type: text/x-mms-emoticon\r\n\r\n$MsnObjDefine";
$len = strlen($SendString); $len = strlen($SendString);
// TODO handle failure during write to socket
$this->sb_writeln($socket, $id, "MSG $id N $len"); if ($this->sb_writeln($socket, $id, "MSG $id N $len") === false ||
$this->sb_writedata($socket, $SendString); $this->sb_writedata($socket, $SendString) === false) {
return false;
}
} }
$len = strlen($aMessage); $len = strlen($aMessage);
// TODO handle failure during write to socket
$this->sb_writeln($socket, $id, "MSG $id N $len"); if ($this->sb_writeln($socket, $id, "MSG $id N $len") === false ||
$this->sb_writedata($socket, $aMessage); $this->sb_writedata($socket, $aMessage) === false) {
return false;
}
// Don't close the SB session, we might as well leave it open // Don't close the SB session, we might as well leave it open
return true; return true;
} }
@ -1995,7 +1997,6 @@ X-OIM-Sequence-Num: 1
$str = '<ml l="1"><d n="'.$u_domain.'"><c n="'.$u_name.'" l="'.$l.'" t="'.$network.'" /></d></ml>'; $str = '<ml l="1"><d n="'.$u_domain.'"><c n="'.$u_name.'" l="'.$l.'" t="'.$network.'" /></d></ml>';
$len = strlen($str); $len = strlen($str);
// NS: >>> ADL {id} {size} // NS: >>> ADL {id} {size}
//TODO introduce error checking
$this->ns_writeln("ADL $this->id $len"); $this->ns_writeln("ADL $this->id $len");
$this->ns_writedata($str); $this->ns_writedata($str);
} }

View File

@ -134,7 +134,9 @@ class MsnManager extends ImManager {
/** /**
* Update the time till the next ping * Update the time till the next ping
*
* @param $data Time till next ping * @param $data Time till next ping
* @return void
*/ */
private function update_ping_time($data) { private function update_ping_time($data) {
$pingInterval = $data; $pingInterval = $data;
@ -173,6 +175,12 @@ class MsnManager extends ImManager {
common_log(LOG_NOTICE, 'MSN reconnecting'); 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) { function send_raw_message($data) {
$this->connect(); $this->connect();
if (!$this->conn) { if (!$this->conn) {