function on_headline_message_callback($stanza) { global $client; if ($event = $stanza->exists('event', XEP0060::NS_PUBSUB . '#event')) { JAXLLogger::info("got pubsub event"); } else { JAXLLogger::warning("unknown headline message rcvd"); } }
public function on_client_write_ready($client) { $client_id = (int) $client; JAXLLogger::debug("client#{$client_id} is write ready"); try { // send in chunks $total = $this->clients[$client_id]['obuffer']; $written = @fwrite($client, substr($total, 0, $this->send_chunk_size)); if ($written === false) { // fwrite failed JAXLLogger::warning("====> fwrite failed"); $this->clients[$client_id]['obuffer'] = $total; } elseif ($written == strlen($total) || $written == $this->send_chunk_size) { // full chunk written //JAXLLogger::debug("full chunk written"); $this->clients[$client_id]['obuffer'] = substr($total, $this->send_chunk_size); } else { // partial chunk written //JAXLLogger::debug("partial chunk $written written"); $this->clients[$client_id]['obuffer'] = substr($total, $written); } // if no more stuff to write, remove write handler if (strlen($this->clients[$client_id]['obuffer']) === 0) { $this->del_write_cb($client_id); // if scheduled for close and not closed do it and clean up if ($this->clients[$client_id]['close'] && !$this->clients[$client_id]['closed']) { if (is_resource($client)) { fclose($client); } $this->clients[$client_id]['closed'] = true; unset($this->clients[$client_id]); JAXLLogger::debug("closed client#" . $client_id); } } } catch (JAXLException $e) { JAXLLogger::debug("====> got fwrite exception"); } }
public function done($event, $data) { JAXLLogger::warning("got unhandled event {$event} with data {$data['0']}"); return array('done', false); }
function on_presence_stanza_callback($stanza) { global $client, $room_full_jid; $from = new XMPPJid($stanza->from); // self-stanza received, we now have complete room roster if (strtolower($from->to_string()) == strtolower($room_full_jid->to_string())) { if (($x = $stanza->exists('x', XEP0045::NS_MUC . '#user')) !== false) { if (($status = $x->exists('status', null, array('code' => '110'))) !== false) { $item = $x->exists('item'); JAXLLogger::info("xmlns #user exists with x " . $x->ns . " status " . $status->attrs['code'] . ", affiliation:" . $item->attrs['affiliation'] . ", role:" . $item->attrs['role']); } else { JAXLLogger::info("xmlns #user have no x child element"); } } else { JAXLLogger::warning("=======> odd case 1"); } } elseif (strtolower($from->bare) == strtolower($room_full_jid->bare)) { // stanza from other users received if (($x = $stanza->exists('x', XEP0045::NS_MUC . '#user')) !== false) { $item = $x->exists('item'); echo "presence stanza of type " . ($stanza->type ? $stanza->type : "available") . " received from " . $from->resource . ", affiliation:" . $item->attrs['affiliation'] . ", role:" . $item->attrs['role'] . PHP_EOL; } else { JAXLLogger::warning("=======> odd case 2"); } } else { JAXLLogger::warning("=======> odd case 3"); } }
public function handle_other($event, $args) { $stanza = isset($args[0]) ? $args[0] : null; $stanza = new XMPPStanza($stanza); $ev = 'on_' . $stanza->name . '_stanza'; if ($this->ev->exists($ev)) { return $this->ev->emit($ev, array($stanza)); } else { JAXLLogger::warning("event '" . $event . "' catched in handle_other with stanza name " . $stanza->name); } }
public function on_read_ready($fd) { //JAXLLogger::debug("on read ready called"); $raw = @fread($fd, $this->recv_chunk_size); $bytes = strlen($raw); if ($bytes === 0) { $meta = stream_get_meta_data($fd); if ($meta['eof'] === true) { JAXLLogger::warning("socket eof, disconnecting"); JAXLLoop::unwatch($fd, array('read' => true)); $this->disconnect(); return; } } $this->recv_bytes += $bytes; $total = $this->ibuffer . $raw; $this->ibuffer = ""; JAXLLogger::debug("read " . $bytes . "/" . $this->recv_bytes . " of data"); if ($bytes > 0) { JAXLLogger::debug($raw); } // callback if ($this->recv_cb) { call_user_func($this->recv_cb, $raw); } }
public function closed($event, $args) { JAXLLogger::warning("uncatched {$event}"); }