diff --git a/XMPPHP/XMPP.php b/XMPPHP/XMPP.php index 1ee9375..ce1417f 100644 --- a/XMPPHP/XMPP.php +++ b/XMPPHP/XMPP.php @@ -27,7 +27,9 @@ class XMPPHP_XMPP extends XMPPHP_XMLStream { protected $password; protected $resource; protected $fulljid; + protected $basejid; protected $authed; + public $auto_subscribe = False; /** * Constructor @@ -48,7 +50,8 @@ class XMPPHP_XMPP extends XMPPHP_XMLStream { $this->password = $password; $this->resource = $resource; if(!$server) $server = $host; - + $this->basejid = $this->user . '@' . $this->host; + $this->stream_start = ''; $this->stream_end = ''; $this->addHandler('features', 'http://etherx.jabber.org/streams', 'features_handler'); @@ -63,6 +66,13 @@ class XMPPHP_XMPP extends XMPPHP_XMLStream { $this->use_encryption = true; } + /** + * Turn on auto-authorization of subscription requests. + */ + public function autoSubscribe() { + $this->auto_subscribe = true; + } + /** * Send XMPP Message * @@ -139,7 +149,14 @@ class XMPPHP_XMPP extends XMPPHP_XMLStream { $payload['from'] = $xml->attrs['from']; $payload['status'] = (isset($xml->sub('status')->data)) ? $xml->sub('status')->data : ''; $this->log->log("Presence: {$payload['from']} [{$payload['show']}] {$payload['status']}", XMPPHP_Log::LEVEL_DEBUG); - $this->event('presence', $payload); + if($xml->attrs['type'] == 'subscribe') { + if($this->auto_subscribe) $this->send(""); + $this->event('subscription_requested', $payload); + } elseif($xml->attrs['type'] == 'subscribed') { + $this->event('subscription_accepted', $payload); + } else { + $this->event('presence', $payload); + } } /**