Merged in changes to phpmsnclass

This commit is contained in:
Luke Fitzgerald 2010-06-12 21:19:08 +01:00
parent 89808a86d5
commit 52cfc0866c

View File

@ -60,6 +60,7 @@ class MSN {
private $ABAuthHeader; private $ABAuthHeader;
private $ABService; private $ABService;
private $Contacts; private $Contacts;
private $IgnoreList;
public $server = 'messenger.hotmail.com'; public $server = 'messenger.hotmail.com';
public $port = 1863; public $port = 1863;
@ -108,18 +109,6 @@ class MSN {
public $max_msn_message_len = 1664; public $max_msn_message_len = 1664;
public $max_yahoo_message_len = 518; public $max_yahoo_message_len = 518;
// Begin added for StatusNet
private $aContactList = array();
private $switchBoardSessions = array();
/**
* Event Handler Functions
*/
private $myEventHandlers = array();
// End added for StatusNet
private function Array2SoapVar($Array,$ReturnSoapVarObj=true,$TypeName=null,$TypeNameSpace=null) private function Array2SoapVar($Array,$ReturnSoapVarObj=true,$TypeName=null,$TypeNameSpace=null)
{ {
$ArrayString=''; $ArrayString='';
@ -158,6 +147,15 @@ class MSN {
$this->log_message("*** someone kill me ***"); $this->log_message("*** someone kill me ***");
$this->kill_me=true; $this->kill_me=true;
} }
private function IsIgnoreMail($Email)
{
if($this->IgnoreList==false) return false;
foreach($this->IgnoreList as $Pattern)
{
if(preg_match($Pattern,$Email)) return true;
}
return false;
}
public function __construct ($Configs=array(), $timeout = 15, $client_id = 0x7000800C) public function __construct ($Configs=array(), $timeout = 15, $client_id = 0x7000800C)
{ {
$this->user = $Configs['user']; $this->user = $Configs['user'];
@ -171,6 +169,7 @@ class MSN {
$this->backup_file = isset($Configs['backup_file']) ? $Configs['backup_file'] : true; $this->backup_file = isset($Configs['backup_file']) ? $Configs['backup_file'] : true;
$this->update_pending = isset($Configs['update_pending']) ? $Configs['update_pending'] : true; $this->update_pending = isset($Configs['update_pending']) ? $Configs['update_pending'] : true;
$this->PhotoStickerFile=$Configs['PhotoSticker']; $this->PhotoStickerFile=$Configs['PhotoSticker'];
$this->IgnoreList=isset($Configs['IgnoreList'])?$Configs['IgnoreList']:false;
if($this->Emotions = isset($Configs['Emotions']) ? $Configs['Emotions']:false) if($this->Emotions = isset($Configs['Emotions']) ? $Configs['Emotions']:false)
{ {
foreach($this->Emotions as $EmotionFilePath) foreach($this->Emotions as $EmotionFilePath)
@ -532,99 +531,6 @@ class MSN {
} }
$this->UpdateContacts(); $this->UpdateContacts();
return true; return true;
$ABContactAdd=new SoapParam($this->Array2SoapVar($ABContactAddArray),'ABContactAdd');
// add contact for WLM
$ticket = htmlspecialchars($this->ticket['contact_ticket']);
$displayName = htmlspecialchars($display);
$user = $email;
$XML = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Header>
<ABApplicationHeader xmlns="http://www.msn.com/webservices/AddressBook">
<ApplicationId>CFE80F9D-180F-4399-82AB-413F33A1FA11</ApplicationId>
<IsMigration>false</IsMigration>
<PartnerScenario>ContactSave</PartnerScenario>
</ABApplicationHeader>
<ABAuthHeader xmlns="http://www.msn.com/webservices/AddressBook">
<ManagedGroupRequest>false</ManagedGroupRequest>
<TicketToken>'.$ticket.'</TicketToken>
</ABAuthHeader>
</soap:Header>
<soap:Body>
<ABContactAdd xmlns="http://www.msn.com/webservices/AddressBook">
<abId>00000000-0000-0000-0000-000000000000</abId>
<contacts>
<Contact xmlns="http://www.msn.com/webservices/AddressBook">
<contactInfo>
<contactType>LivePending</contactType>
<passportName>'.$user.'</passportName>
<isMessengerUser>true</isMessengerUser>
<MessengerMemberInfo>
<DisplayName>'.$displayName.'</DisplayName>
</MessengerMemberInfo>
</contactInfo>
</Contact>
</contacts>
<options>
<EnableAllowListManagement>true</EnableAllowListManagement>
</options>
</ABContactAdd>
</soap:Body>
</soap:Envelope>';
$header_array = array(
'SOAPAction: '.$this->addcontact_soap,
'Content-Type: text/xml; charset=utf-8',
'User-Agent: MSN Explorer/9.0 (MSN 8.0; TmstmpExt)'
);
$this->debug_message("*** URL: $this->addcontact_url");
$this->debug_message("*** Sending SOAP:\n$XML");
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->addcontact_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header_array);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
if ($this->debug) curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $XML);
$data = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
$this->debug_message("*** Get Result:\n$data");
if ($http_code != 200) {
preg_match('#<faultcode>(.*)</faultcode><faultstring>(.*)</faultstring>#', $data, $matches);
if (count($matches) == 0) {
$this->log_message("*** can't add contact (network: $network) $email");
return false;
}
$faultcode = trim($matches[1]);
$faultstring = trim($matches[2]);
$this->log_message("*** can't add contact (network: $network) $email, error code: $faultcode, $faultstring");
return false;
}
$this->log_message("*** add contact (network: $network) $email");
if ($sendADL && !feof($this->NSfp)) {
@list($u_name, $u_domain) = @explode('@', $email);
foreach (array('1', '2') as $l) {
$str = '<ml l="1"><d n="'.$u_domain.'"><c n="'.$u_name.'" l="'.$l.'" t="'.$network.'" /></d></ml>';
$len = strlen($str);
// NS: >>> ADL {id} {size}
$this->ns_writeln("ADL $this->id $len");
$this->ns_writedata($str);
}
}
$this->UpdateContacts();
return true;
} }
function delMemberFromList($memberID, $email, $network, $list) { function delMemberFromList($memberID, $email, $network, $list) {
@ -934,7 +840,7 @@ class MSN {
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl); curl_close($curl);
$this->debug_message("*** Get Result:\n$data"); $this->debug_message("*** Get Result:\n$data");
if(($http_code != 200)||(!$returnData)) return array(); if($http_code != 200) return array();
$p = $data; $p = $data;
$aMemberships = array(); $aMemberships = array();
while (1) { while (1) {
@ -1562,7 +1468,7 @@ class MSN {
$start_tm = time(); $start_tm = time();
$ping_tm = time(); $ping_tm = time();
stream_set_timeout($this->NSfp, $this->NSStreamTimeout); stream_set_timeout($this->NSfp, $this->NSStreamTimeout);
$aContactList = $this->getMembershipList(true); $aContactList = $this->getMembershipList();
if ($this->update_pending) { if ($this->update_pending) {
if (is_array($aContactList)) { if (is_array($aContactList)) {
$pending = 'Pending'; $pending = 'Pending';
@ -2102,6 +2008,11 @@ class MSN {
$this->log_message("NS: <<< RNG $data"); $this->log_message("NS: <<< RNG $data");
@list(/* RNG */, $sid, $server, /* auth_type */, $ticket, $email, $name, ) = @explode(' ', $data); @list(/* RNG */, $sid, $server, /* auth_type */, $ticket, $email, $name, ) = @explode(' ', $data);
@list($sb_ip, $sb_port) = @explode(':', $server); @list($sb_ip, $sb_port) = @explode(':', $server);
if($this->IsIgnoreMail($email))
{
$this->log_message("*** Ignore RNG from $email");
break;
}
$this->log_message("*** RING from $email, $sb_ip:$sb_port"); $this->log_message("*** RING from $email, $sb_ip:$sb_port");
$this->addContact($email,1,$email, true); $this->addContact($email,1,$email, true);
$pid=pcntl_fork(); $pid=pcntl_fork();
@ -2329,7 +2240,7 @@ class MSN {
$this->SB_writedata($aMessage); $this->SB_writedata($aMessage);
} }
$this->SwitchBoardMessageQueue=array(); $this->SwitchBoardMessageQueue=array();
$LastActive=time(); if(!$this->IsIgnoreMail($user)) $LastActive = time();
continue; continue;
} }
$code = substr($data, 0, 3); $code = substr($data, 0, 3);
@ -2725,7 +2636,7 @@ class MSN {
} }
break; break;
} }
$LastActive = time(); if(!$this->IsIgnoreMail($user)) $LastActive = time();
} }
if (feof($this->SBFp)) if (feof($this->SBFp))
{ {
@ -3089,7 +3000,7 @@ X-OIM-Sequence-Num: 1
$start_tm = time(); $start_tm = time();
$ping_tm = time(); $ping_tm = time();
stream_set_timeout($this->NSfp, $this->NSStreamTimeout); stream_set_timeout($this->NSfp, $this->NSStreamTimeout);
$this->aContactList = $this->getMembershipList(true); $this->aContactList = $this->getMembershipList();
if ($this->update_pending) { if ($this->update_pending) {
if (is_array($this->aContactList)) { if (is_array($this->aContactList)) {
$pending = 'Pending'; $pending = 'Pending';
@ -3201,28 +3112,10 @@ X-OIM-Sequence-Num: 1
} }
$data = $this->ns_readln(); $data = $this->ns_readln();
/*if($data===false) if($data === false) {
{ // There was no data / an error when reading from the socket so reconnect
if(count($this->ChildProcess)<$this->MAXChildProcess) $this->signon();
{ } else {
$Index=0;
foreach($this->MessageQueue as $User => $Message)
{
if(!trim($User)) continue;
if($Inxdex>=$this->MAXChildProcess-count($this->ChildProcess)) break;
if((!$Message['XFRSent'])||($Message['XFRSent']&&(time()-$this->MessageQueue[$User]['ReqTime']>$this->ReqSBXFRTimeout)))
{
$this->MessageQueue[$User]['XFRSent']=true;
$this->MessageQueue[$User]['ReqTime']=time();
$this->log_message("*** Request SB for $User");
$this->ns_writeln("XFR $this->id SB");
$Index++;
}
}
}
if($this->ProcessSendMessageFileQueue()) continue;
break;
}*/
switch (substr($data,0,3)) switch (substr($data,0,3))
{ {
case 'SBS': case 'SBS':
@ -3635,6 +3528,11 @@ X-OIM-Sequence-Num: 1
$this->log_message("NS: <<< RNG $data"); $this->log_message("NS: <<< RNG $data");
@list(/* RNG */, $sid, $server, /* auth_type */, $ticket, $email, $name, ) = @explode(' ', $data); @list(/* RNG */, $sid, $server, /* auth_type */, $ticket, $email, $name, ) = @explode(' ', $data);
@list($sb_ip, $sb_port) = @explode(':', $server); @list($sb_ip, $sb_port) = @explode(':', $server);
if($this->IsIgnoreMail($email))
{
$this->log_message("*** Ignore RNG from $email");
break;
}
$this->log_message("*** RING from $email, $sb_ip:$sb_port"); $this->log_message("*** RING from $email, $sb_ip:$sb_port");
$this->addContact($email,1,$email, true); $this->addContact($email,1,$email, true);
$pid=pcntl_fork(); $pid=pcntl_fork();
@ -3674,13 +3572,14 @@ X-OIM-Sequence-Num: 1
break; break;
} }
} }
}
public function sendMessageViaSB($message, $to) { public function sendMessageViaSB($message, $to) {
$socket = $this->switchBoardSessions[$to]['socket']; $socket = $this->switchBoardSessions[$to]['socket'];
$lastActive = $this->switchBoardSessions[$to]['lastActive']; $lastActive = $this->switchBoardSessions[$to]['lastActive'];
$joined = $this->switchBoardSessions[$to]['joined']; $joined = $this->switchBoardSessions[$to]['joined'];
//TODO Probably not needed (we're not running in a loop anymore) //FIXME Probably not needed (we're not running in a loop anymore)
/*if($this->kill_me) /*if($this->kill_me)
{ {
$this->log_message("*** SB Okay, kill me now!"); $this->log_message("*** SB Okay, kill me now!");
@ -3725,7 +3624,7 @@ X-OIM-Sequence-Num: 1
return true; return true;
} }
//TODO Not sure if this is needed? //FIXME Not sure if this is needed?
private function endSBSession($socket) { private function endSBSession($socket) {
if (feof($this->SBFp)) if (feof($this->SBFp))
{ {
@ -3746,12 +3645,13 @@ X-OIM-Sequence-Num: 1
if($network === 1 && isset($this->switchBoardSessions[$to])) { if($network === 1 && isset($this->switchBoardSessions[$to])) {
$recipient = $name . $host; $recipient = $name . $host;
$this->debug_message("*** Sending Message to $recipient using existing SB session"); $this->debug_message("*** Sending Message to $recipient using existing SB session");
$this->sendMessageViaSB($message, $recipient); return $this->sendMessageViaSB($message, $recipient);
} else { } else {
$this->debug_message("*** Not MSN network or no existing SB session"); $this->debug_message("*** Not MSN network or no existing SB session");
//TODO implement creation of SB session etc
} }
} }
return true;
} }
/** /**