public function connect($socket_path) { $path_parts = explode(":", $socket_path); $this->transport = $path_parts[0]; $this->host = substr($path_parts[1], 2, strlen($path_parts[1])); if (sizeof($path_parts) == 3) { $this->port = $path_parts[2]; } _info("trying " . $socket_path); if ($this->stream_context) { $this->fd = @stream_socket_client($socket_path, $this->errno, $this->errstr, $this->timeout, STREAM_CLIENT_CONNECT, $this->stream_context); } else { $this->fd = @stream_socket_client($socket_path, $this->errno, $this->errstr, $this->timeout); } if ($this->fd) { _debug("connected to " . $socket_path . ""); stream_set_blocking($this->fd, $this->blocking); // watch descriptor for read/write events JAXLLoop::watch($this->fd, array('read' => array(&$this, 'on_read_ready'))); return true; } else { _error("unable to connect " . $socket_path . " with error no: " . $this->errno . ", error str: " . $this->errstr . ""); $this->disconnect(); return false; } }
function upload($request) { if ($request->method == 'GET') { $request->ok(array('Content-Type' => 'text/html'), '<html><head/><body><h1>Jaxl Http Server</h1><form enctype="multipart/form-data" method="POST" action="http://127.0.0.1:9699/upload/"><input type="file" name="file"/><input type="submit" value="upload"/></form></body></html>'); } else { if ($request->method == 'POST') { if ($request->body === null && $request->expect) { $request->recv_body(); } else { // got upload body, save it _info("file upload complete, got " . strlen($request->body) . " bytes of data"); $upload_data = $request->multipart->form_data[0]['body']; $request->ok($upload_data, array('Content-Type' => $request->multipart->form_data[0]['headers']['Content-Type'])); } } } }
env::$ENV_ITEMS_ROOT = realpath($options['r']); } _info('Config file: ' . realpath(env::$ENV_CFG_FILE)); _info('Items root: ' . env::$ENV_ITEMS_ROOT); $env = env::init(); _info('Looking for meta-files in ' . env::$ENV_ITEMS_ROOT); $meta = tubeAPI::getInstance()->searchMeta(); _echo(' > Found ' . count($meta) . ' playlists.'); foreach ($meta as $path) { $info = parse_ini_file($path, false, INI_SCANNER_RAW); if (empty($info['type'])) { continue; } switch ($info['type']) { case 'playlist': _info('Process playlist in `' . dirname($path) . '`'); if (empty($info['id'])) { _echo(' > No playlist ID specified. Skipping'); continue; } if (isset($info['closed']) && trim($info['closed']) != '0') { _echo(' > Playlist closed'); continue; } cli_processPlaylist(dirname($path), $info); break; } } } catch (Exception $e) { echo $e->getMessage(); }
public function retry() { $retry_after = pow(2, $this->retry_attempt) * $this->retry_interval; $this->retry_attempt++; _info("Will try to restart in " . $retry_after . " seconds"); // TODO: use jaxl cron if sigalarms cannnot be used sleep($retry_after); $this->start(); }
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * */ if (!isset($_GET['jid']) || !isset($_GET['pass'])) { echo "invalid input"; exit; } // // initialize JAXL object with initial config // require_once '../jaxl.php'; $client = new JAXL(array('jid' => $_GET['jid'], 'pass' => $_GET['pass'], 'bosh_url' => 'http://localhost:5280/http-bind', 'log_level' => JAXL_DEBUG)); $client->add_cb('on_auth_success', function () { global $client; _info("got on_auth_success cb, jid " . $client->full_jid->to_string()); }); // // finally start configured xmpp stream // $client->start(); echo "done\n";
public function on_request($sock, $raw) { _debug("on_request for client#{$sock}"); $request = $this->requests[$sock]; // 'wait_for_body' state is reached when ever // application calls recv_body() method // on received $request object if ($request->state() == 'wait_for_body') { $request->body($raw); } else { // break on crlf $lines = explode(HTTP_CRLF, $raw); // parse request line if ($request->state() == 'wait_for_request_line') { list($method, $resource, $version) = explode(" ", $lines[0]); $request->line($method, $resource, $version); unset($lines[0]); _info($request->ip . " " . $request->method . " " . $request->resource . " " . $request->version); } // parse headers foreach ($lines as $line) { $line_parts = explode(":", $line); if (sizeof($line_parts) > 1) { if (strlen($line_parts[0]) > 0) { $k = $line_parts[0]; unset($line_parts[0]); $v = implode(":", $line_parts); $request->set_header($k, $v); } } else { if (strlen(trim($line_parts[0])) == 0) { $request->empty_line(); } else { $request->body($line); } } } } // if request has reached 'headers_received' state? if ($request->state() == 'headers_received') { // dispatch to any matching rule found _debug("delegating to dispatcher for further routing"); $dispatched = $this->dispatcher->dispatch($request); // if no dispatch rule matched call generic callback if (!$dispatched && $this->cb) { _debug("no dispatch rule matched, sending to generic callback"); call_user_func($this->cb, $request); } else { if (!$dispatched) { // TODO: send 404 if no callback is registered for this request _debug("dropping request since no matching dispatch rule or generic callback was specified"); $request->not_found('404 Not Found'); } } } else { $this->server->read($sock); } }
} // // add necessary event callbacks here // $client->add_cb('on_stream_features', function ($stanza) { global $client, $argv; $client->xeps['0077']->get_form($argv[1]); return "wait_for_register_form"; }); $client->add_cb('on_disconnect', function () { global $form; _info("registration " . ($form['type'] == 'result' ? 'succeeded' : 'failed')); }); // // finally start configured xmpp stream // $client->start(); // // if registration was successful // try to connect with newly registered account // if ($form['type'] == 'result') { _info("connecting newly registered user account"); $client = new JAXL(array('jid' => $form['username'] . '@' . $argv[1], 'pass' => $form['password'], 'log_level' => JAXL_DEBUG)); $client->add_cb('on_auth_success', function () { global $client; $client->set_status('Available'); }); $client->start(); } echo "done\n";
public function on_response($raw) { _info("got http response"); }
$body = file_get_contents("php://input"); $body = new SimpleXMLElement($body); $attrs = $body->attributes(); if (!@$attrs['to'] && !@$attrs['rid'] && !@$attrs['wait'] && !@$attrs['hold']) { echo "invalid input"; exit; } // // initialize JAXL object with initial config // require_once 'jaxl.php'; $to = $attrs['to']; $rid = $attrs['rid']; $wait = $attrs['wait']; $hold = $attrs['hold']; echo $to . " " . $rid . " " . $wait . " " . $hold; exit; list($host, $port) = JAXLUtil::get_dns_srv($to); $client = new JAXL(array('domain' => $to, 'host' => $host, 'port' => $port, 'bosh_url' => 'http://localhost:5280/http-bind', 'bosh_rid' => $rid, 'bosh_wait' => $wait, 'bosh_hold' => $hold, 'auth_type' => 'ANONYMOUS')); $client->add_cb('on_auth_success', function () { global $client; _info($client->full_jid->to_string()); _info($client->xeps['0206']->sid); _info($client->xeps['0206']->rid); exit; }); // // finally start configured xmpp stream // $client->start(); echo "done\n";
* from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * */ // include and configure logger require_once 'jaxl.php'; JAXLLogger::$level = JAXL_INFO; // include jaxl pipes require_once JAXL_CWD . '/core/jaxl_pipe.php'; // initialize $pipe_name = getmypid(); $pipe = new JAXLPipe($pipe_name); // add read event callback $pipe->set_callback(function ($data) { global $pipe; _info("read " . trim($data) . " from pipe"); }); JAXLLoop::run(); echo "done\n";
function on_disconnect($client) { _info("got on_disconnect cb"); }
public function __destruct() { // delete pid file _info("cleaning up pid and unix sock files"); @unlink($this->get_pid_file_path()); @unlink($this->get_sock_file_path()); parent::__destruct(); }
public function __destruct() { _info("shutting down clock server..."); }
public function __destruct() { _info("shutting down socket server"); }
$attrs = $body->attributes(); if (!@$attrs['to'] && !@$attrs['rid'] && !@$attrs['wait'] && !@$attrs['hold']) { echo "invalid input"; exit; } // // initialize JAXL object with initial config // require_once '../jaxl.php'; $to = (string) $attrs['to']; $rid = (int) $attrs['rid']; $wait = (int) $attrs['wait']; $hold = (int) $attrs['hold']; list($host, $port) = JAXLUtil::get_dns_srv($to); $client = new JAXL(array('domain' => $to, 'host' => $host, 'port' => $port, 'bosh_url' => 'http://localhost:5280/http-bind', 'bosh_rid' => $rid, 'bosh_wait' => $wait, 'bosh_hold' => $hold, 'auth_type' => 'ANONYMOUS', 'log_level' => JAXL_INFO)); $client->add_cb('on_auth_success', function () { global $client; _info("got on_auth_success cb, jid " . $client->full_jid->to_string()); echo '<body xmlns="' . NS_HTTP_BIND . '" sid="' . $client->xeps['0206']->sid . '" rid="' . $client->xeps['0206']->rid . '" jid="' . $client->full_jid->to_string() . '"/>'; exit; }); $client->add_cb('on_auth_failure', function ($reason) { global $client; _info("got on_auth_failure cb with reason {$reason}"); $client->send_end_stream(); }); // // finally start configured xmpp stream // $client->start(); echo "done\n";
$astdb = new AsteriskDB(); $xmpp_client = new JAXL(array('jid' => 'pbx', 'pass' => '123456', 'host' => 'avanpbx:5222')); $xmpp_client->require_xep(array('0199')); $connected = true; $xmpp_client->add_cb('on_auth_failure', function ($reason) { global $xmpp_client; $xmpp_client->send_end_stream(); _info("CALLBACK! got on_auth_failure cb with reason {$reason}"); }); $xmpp_client->add_cb('on_connect_error', function ($reason) { _info("connect error {$reason}"); }); $xmpp_client->add_cb('on_auth_success', function () { _info("connected!!"); global $xmpp_client; $xmpp_client->set_status("available!", "dnd", 10); }); $xmpp_client->add_cb('on_disconnect', function () { _info("disconnected!!"); // _info("reconnecting"); // global $xmpp_client; // $xmpp_client->con(); // global $xmpp_client; // $xmpp_client->set_status("available!", "dnd", 10); }); $xmpp_client->add_cb('on_headline_message', function ($stanza) { global $xmpp_client; // var_dump($stanza); processMessage($stanza); }); $xmpp_client->start(array('--with-unix-sock' => true), $pamiClient);
* POSSIBILITY OF SUCH DAMAGE. * */ // View explanation for this example here: // https://groups.google.com/d/msg/jaxl/QaGjZP4A2gY/n6SYutrBVxsJ if ($argc < 3) { echo "Usage: {$argv['0']} jid pass\n"; exit; } // initialize xmpp client require_once 'jaxl.php'; $xmpp = new JAXL(array('jid' => $argv[1], 'pass' => $argv[2], 'log_level' => JAXL_INFO)); // register callbacks on required xmpp events $xmpp->add_cb('on_auth_success', function () { global $xmpp; _info("got on_auth_success cb, jid " . $xmpp->full_jid->to_string()); }); // initialize http server require_once JAXL_CWD . '/http/http_server.php'; $http = new HTTPServer(); // add generic callback // you can also dispatch REST style callback // Refer: http://jaxl.readthedocs.org/en/latest/users/http_extensions.html#dispatch-rules $http->cb = function ($request) { // For demo purposes we simply return xmpp client full jid global $xmpp; $request->ok($xmpp->full_jid->to_string()); }; // This will start main JAXLLoop, // hence we don't need to call $http->start() explicitly $xmpp->start();
function on_request($client, $raw) { global $server; $server->send($client, $raw); _info("got client callback " . $raw); }
if (($x = $stanza->exists('x', NS_MUC . '#user')) !== false) { if (($status = $x->exists('status', null, array('code' => '110'))) !== false) { $item = $x->exists('item'); _info("xmlns #user exists with x " . $x->ns . " status " . $status->attrs['code'] . ", affiliation:" . $item->attrs['affiliation'] . ", role:" . $item->attrs['role']); } else { _info("xmlns #user have no x child element"); } } else { _warning("=======> odd case 1"); } } else { if (strtolower($from->bare) == strtolower($room_full_jid->bare)) { if (($x = $stanza->exists('x', 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 { _warning("=======> odd case 2"); } } else { _warning("=======> odd case 3"); } } }); $client->add_cb('on_disconnect', function () { _info("got on_disconnect cb"); }); // // finally start configured xmpp stream // $client->start(); echo "done\n";
function delete_event($request, $pk) { _info("got event delete request for {$pk}"); $request->close(); }