Example #1
0
 /**
  * Routes incoming XMPP data to appropriate handlers
  */
 function handler($payload)
 {
     if ($payload == '' && $this->mode == 'cli') {
         return '';
     }
     if ($payload != '' && $this->mode == 'cgi') {
         $this->log("[[XMPPGet]] \n" . $payload, 4);
     }
     $payload = $this->executePlugin('jaxl_pre_handler', $payload);
     $xmls = JAXLUtil::splitXML($payload);
     $pktCnt = count($xmls);
     $this->totalRcvdPkt += $pktCnt;
     $buffer = array();
     foreach ($xmls as $pktNo => $xml) {
         if ($pktNo == $pktCnt - 1) {
             if (substr($xml, -1, 1) != '>') {
                 $this->buffer .= $xml;
                 break;
             }
         }
         if (substr($xml, 0, 7) == '<stream') {
             $arr = $this->xml->xmlize($xml);
         } else {
             $arr = JAXLXml::parse($xml, $this->getSXE);
         }
         if ($arr === false) {
             $this->buffer .= $xml;
             continue;
         }
         switch (true) {
             case isset($arr['stream:stream']):
                 XMPPGet::streamStream($arr['stream:stream'], $this);
                 break;
             case isset($arr['stream:features']):
                 XMPPGet::streamFeatures($arr['stream:features'], $this);
                 break;
             case isset($arr['stream:error']):
                 XMPPGet::streamError($arr['stream:error'], $this);
                 break;
             case isset($arr['failure']):
                 XMPPGet::failure($arr['failure'], $this);
                 break;
             case isset($arr['proceed']):
                 XMPPGet::proceed($arr['proceed'], $this);
                 break;
             case isset($arr['challenge']):
                 XMPPGet::challenge($arr['challenge'], $this);
                 break;
             case isset($arr['success']):
                 XMPPGet::success($arr['success'], $this);
                 break;
             case isset($arr['presence']):
                 $buffer['presence'][] = $arr['presence'];
                 break;
             case isset($arr['message']):
                 $buffer['message'][] = $arr['message'];
                 break;
             case isset($arr['iq']):
                 $this->payloadRaw = $arr['xml'];
                 XMPPGet::iq($arr['iq'], $this);
                 break;
             default:
                 $jaxl->log("[[XMPPGet]] \nUnrecognized payload received from jabber server...");
                 throw new JAXLException("[[XMPPGet]] Unrecognized payload received from jabber server...");
                 break;
         }
     }
     if (isset($buffer['presence'])) {
         XMPPGet::presence($buffer['presence'], $this);
     }
     if (isset($buffer['message'])) {
         XMPPGet::message($buffer['message'], $this);
     }
     unset($buffer);
     $this->executePlugin('jaxl_post_handler', $payload);
     return $payload;
 }
Example #2
0
 public static function handler($payload, &$jaxl)
 {
     JAXLog::log("[[XMPPGet]] \n" . $payload, 4, $jaxl);
     $buffer = array();
     $payload = JAXLPlugin::execute('jaxl_pre_handler', $payload, $jaxl);
     $xmls = JAXLUtil::splitXML($payload);
     $pktCnt = count($xmls);
     foreach ($xmls as $pktNo => $xml) {
         if ($pktNo == $pktCnt - 1) {
             if (substr($xml, -1, 1) != '>') {
                 $jaxl->buffer = $xml;
                 break;
             }
         }
         if (substr($xml, 0, 7) == '<stream') {
             $arr = $jaxl->xml->xmlize($xml);
         } else {
             $arr = JAXLXml::parse($xml);
         }
         switch (true) {
             case isset($arr['stream:stream']):
                 self::streamStream($arr['stream:stream'], $jaxl);
                 break;
             case isset($arr['stream:features']):
                 self::streamFeatures($arr['stream:features'], $jaxl);
                 break;
             case isset($arr['stream:error']):
                 self::streamError($arr['stream:error'], $jaxl);
                 break;
             case isset($arr['failure']):
                 self::failure($arr['failure'], $jaxl);
                 break;
             case isset($arr['proceed']):
                 self::proceed($arr['proceed'], $jaxl);
                 break;
             case isset($arr['challenge']):
                 self::challenge($arr['challenge'], $jaxl);
                 break;
             case isset($arr['success']):
                 self::success($arr['success'], $jaxl);
                 break;
             case isset($arr['presence']):
                 $buffer['presence'][] = $arr['presence'];
                 break;
             case isset($arr['message']):
                 $buffer['message'][] = $arr['message'];
                 break;
             case isset($arr['iq']):
                 self::iq($arr['iq'], $jaxl);
                 break;
             default:
                 print "Unrecognized payload received from jabber server...";
                 break;
         }
     }
     if (isset($buffer['presence'])) {
         self::presence($buffer['presence'], $jaxl);
     }
     if (isset($buffer['message'])) {
         self::message($buffer['message'], $jaxl);
     }
     unset($buffer);
     JAXLPlugin::execute('jaxl_post_handler', $payload, $jaxl);
 }