Esempio n. 1
0
 public static function sendBody($xml, $jaxl)
 {
     $xml = JAXLPlugin::execute('jaxl_pre_curl', $xml, $jaxl);
     if ($xml != false) {
         JAXLog::log("[[XMPPSend]] body\n" . $xml, 4, $jaxl);
         $payload = JAXLUtil::curl($jaxl->bosh['url'], 'POST', $jaxl->bosh['headers'], $xml);
         $payload = $payload['content'];
         XMPPGet::handler($payload, $jaxl);
     }
     return $xml;
 }
Esempio n. 2
0
 function getXML($nap = TRUE)
 {
     // sleep between two reads
     if ($nap) {
         sleep(JAXL_XMPP_GET_SLEEP);
     }
     // initialize empty lines read
     $emptyLine = 0;
     // read previous buffer
     $payload = $this->buffer;
     $this->buffer = '';
     // read socket data
     for ($i = 0; $i < JAXL_XMPP_GET_PCKTS; $i++) {
         if ($this->stream) {
             $line = fread($this->stream, JAXL_XMPP_GET_PCKT_SIZE);
             if (strlen($line) == 0) {
                 $emptyLine++;
                 if ($emptyLine > JAXL_XMPP_GET_EMPTY_LINES) {
                     break;
                 }
             } else {
                 $payload .= $line;
             }
         }
     }
     // trim read data
     $payload = trim($payload);
     $payload = JAXLPlugin::execute('jaxl_get_xml', $payload, $this);
     if ($payload != '') {
         XMPPGet::handler($payload, $this);
     }
 }
Esempio n. 3
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;
 }
Esempio n. 4
0
 /**
  * Routes incoming XMPP data to appropriate handlers
  */
 function handler($payload)
 {
     $this->log("[[XMPPGet]] \n" . $payload, 4);
     $buffer = array();
     $payload = JAXLPlugin::execute('jaxl_pre_handler', $payload, $this);
     $xmls = JAXLUtil::splitXML($payload);
     $pktCnt = count($xmls);
     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);
         }
         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']):
                 XMPPGet::iq($arr['iq'], $this);
                 break;
             default:
                 $jaxl->log("Unrecognized payload received from jabber server...", 1);
                 break;
         }
     }
     if (isset($buffer['presence'])) {
         XMPPGet::presence($buffer['presence'], $this);
     }
     if (isset($buffer['message'])) {
         XMPPGet::message($buffer['message'], $this);
     }
     unset($buffer);
     JAXLPlugin::execute('jaxl_post_handler', $payload, $this);
 }