Author: abhinavsingh Access to common xml attributes:
Inheritance: extends JAXLXmlAccess
 function test_xmpp_stanza_from_jaxl_xml()
 {
     // xml to stanza test
     $xml = new JAXLXml('message', NS_JABBER_CLIENT, array('to' => '*****@*****.**', 'from' => '4@r.p/q'));
     $stanza = new XMPPStanza($xml);
     $stanza->c('body')->t('hello world');
     echo $stanza->to . "\n";
     echo $stanza->to_string() . "\n";
 }
Example #2
0
 public function test_xmpp_stanza_from_jaxl_xml()
 {
     // xml to stanza test
     $xml = new JAXLXml('message', XMPP::NS_JABBER_CLIENT, array('to' => '*****@*****.**', 'from' => '4@r.p/q'));
     $stanza = new XMPPStanza($xml);
     $stanza->c('body')->t('hello world');
     $this->assertEquals('XMPPStanza', get_class($stanza));
     $this->assertEquals('JAXLXml', get_class($stanza->exists('body')));
     $this->assertEquals('*****@*****.**', $stanza->to);
     $this->assertEquals('<message xmlns="jabber:client" to="*****@*****.**" from="4@r.p/q">' . '<body>hello world</body></message>', $stanza->to_string());
 }
Example #3
0
 public function __construct($attrs, $status = null, $show = null, $priority = null)
 {
     parent::__construct('presence', $attrs);
     if ($status) {
         $this->c('status')->t($status)->up();
     }
     if ($show) {
         $this->c('show')->t($show)->up();
     }
     if ($priority) {
         $this->c('priority')->t($priority)->up();
     }
 }
Example #4
0
 public function __construct($attrs, $body = null, $thread = null, $subject = null)
 {
     parent::__construct('message', $attrs);
     if ($body) {
         $this->c('body')->t($body)->up();
     }
     if ($thread) {
         $this->c('thread')->t($thread)->up();
     }
     if ($subject) {
         $this->c('subject')->t($subject)->up();
     }
 }
Example #5
0
 function ingest(\XMPPStanza $stanza)
 {
     global $config;
     $xml = '<?xml version="1.0"?>' . $stanza->to_string();
     $from = new \XMPPJid($stanza->from);
     $room = $from->bare;
     $nick = $from->resource;
     $type = \qp($xml)->attr('type');
     if ($room == $config['jaxl']['jid']) {
         return true;
     }
     // Initialize the room roster if it doesn't exist yet.
     if (!array_key_exists($room, $this->roster)) {
         $this->roster[$room] = array();
     }
     if ($type == 'error') {
         return true;
     }
     // Find the status codes.
     $item = \qp($xml)->find('item');
     global $codes;
     $codes = array();
     \qp($xml, 'status')->map(function ($index, $item) {
         global $codes;
         $c = (int) qp($item)->attr('code');
         if (!array_key_exists($c, $codes)) {
             $codes[$c] = 0;
         }
         $codes[(int) qp($item)->attr('code')]++;
     });
     if ($type == 'unavailable') {
         $this->eventPresenceUnavailable($room, $nick, $codes, $item);
     } else {
         $this->eventPresenceDefault($room, $nick, $item, $xml);
     }
     return true;
 }
Example #6
0
 public function handle_iq($stanza)
 {
     $stanza = new XMPPStanza($stanza);
     // emit callback registered on stanza id's
     $emited = false;
     if ($stanza->id && $this->ev->exists('on_stanza_id_' . $stanza->id)) {
         //_debug("on stanza id callbackd");
         $emited = true;
         $this->ev->emit('on_stanza_id_' . $stanza->id, array($stanza));
     }
     // catch roster list
     if ($stanza->type == 'result' && ($query = $stanza->exists('query', 'jabber:iq:roster'))) {
         foreach ($query->childrens as $child) {
             if ($child->name == 'item') {
                 $jid = $child->attrs['jid'];
                 $subscription = $child->attrs['subscription'];
                 $groups = array();
                 foreach ($child->childrens as $group) {
                     if ($group->name == 'group') {
                         $groups[] = $group->text;
                     }
                 }
                 $this->roster[$jid] = new RosterItem($jid, $subscription, $groups);
             }
         }
         // emit this event if not emited above
         if (!$emited) {
             $this->ev->emit('on_roster_update');
         }
     }
     // if managing roster
     // catch contact vcard results
     if ($this->manage_roster && $stanza->type == 'result' && ($query = $stanza->exists('vCard', 'vcard-temp'))) {
         if (@$this->roster[$stanza->from]) {
             $this->roster[$stanza->from]->vcard = $query;
         }
     }
     // on_get_iq, on_result_iq, and other events are only
     // emitted if on_stanza_id_{id} wasn't emitted above
     // TODO: can we add more checks here before calling back
     // e.g. checks on existence of an attribute, check on 1st level child ns and so on
     if (!$emited) {
         $this->ev->emit('on_' . $stanza->type . '_iq', array($stanza));
     }
 }
 public function __construct($attrs)
 {
     parent::__construct('iq', $attrs);
 }