Giter Club home page Giter Club logo

jaxl's Introduction

Jaxl v3.1.0

Jaxl v3.x is a successor of v2.x (and is NOT backward compatible), carrying a lot of code from v2.x while throwing away the ugly parts. A lot of components have been re-written keeping in mind the feedback from the developer community over the last 4 years. Also Jaxl shares a few philosophies from my experience with erlang and python languages.

Jaxl is an asynchronous, non-blocking I/O, event based PHP library for writing custom TCP/IP client and server implementations. From it's previous versions, library inherits a full blown stable support for XMPP protocol stack. In v3.0, support for HTTP protocol stack has also been added.

At the heart of every protocol stack sits the Core stack. It contains all the building blocks for everything that we aim to do with Jaxl library. Both XMPP and HTTP protocol stacks are written on top of the Core stack. Infact the source code of protocol implementations knows nothing about the standard (inbuilt) PHP socket and stream methods.

Examples

Documentation

Group and Mailing List

Create a bug/issue

Author

Installation

php composer.phar require "jaxl/jaxl=^3.1.0"

Contributing

JAXL since v3.0.1 adopt PSR-2. To make it easier to maintain the code contribute your changes after they have passed PHP_CodeSniffer and PHPUnit. If possible, add a unit tests for your changes into the tests folder.

To know current errors and failed tests, run:

./vendor/bin/phpcs
./vendor/bin/phpunit

License

The product licensed under the BSD 3-Clause license. See LICENSE.

jaxl's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jaxl's Issues

Incorrect debug display of obuffer

A small bug. In jaxl_socket_client.php:193 the debug needs to have an substr to prevent that it also displays data that is not yet sent. It was a bit confusing for me to debug.

I have changed the line to _debugt(substr($this->obuffer, 0, $bytes);

XML parser error in PHP7

I traced a mysterious hang-up during authentication to the following problem:

  1. The client successfully negotiates TLS.
  2. On reading <proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>, the client resets the parser.
  3. The next string that is supposed to hit the newly initiated parser is <?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='...' from='...' version='1.0' xml:lang='en'>
  4. Even though nothing else should have been parsed yet (and xml_get_current_byte_index returns 0), the parser will report Reserved XML Name. That error is usually a result of <?xml version='1.0'?> being preceded by any other input. That implies that something is "polluting" the parser in between being reset and receiving that string.

Unfortunately I didn't find out what happens, but I was able to use the following hacky workaround to make sure that a <? string automatically resets the parser again:

diff --git a/core/jaxl_xml_stream.php b/core/jaxl_xml_stream.php
index 1c2a70d..42f2f88 100644
--- a/core/jaxl_xml_stream.php
+++ b/core/jaxl_xml_stream.php
@@ -89,6 +89,7 @@ class JAXLXmlStream {
        }

        public function parse($str) {
+               if (strlen($str) > 2 && $str[0] == '<' && $str[1] == '?') $this->reset_parser();
                xml_parse($this->parser, $str, false);
        }

parsing JAXLxml

I am making an chat app using firebase cloud messaging and easily obtained the response from xmpp server but don't know how to parse JAXLxml stanza in php. plz help

client socket not closed

We're having heavy usage of JAXL in our Facebook App to send chat messages to users by using a slightly modified xfacebook_platform_client.php example.

Thing is after using so many calls, we were noticing some connections are never closed (Stuck on apache as WRITING or GRACEFULLY FINISHING forever).

After a few hours - apache crashes for having to many of those.

The code we're using is:

$DOCUMENT_ROOT = getenv('DOCUMENT_ROOT');

require_once "constants_peopleroulette.php";  

$customText = (isset($_POST["customText"])) ? $_POST["customText"] : "";

$invitation_prefix = "« " . $customText . " »\n";
$invitation_suffix = "";

set_time_limit(10);

$token_dec = base64_decode(trim($_POST["chatSession"]));
if (strpos($token_dec, "_") === false)
    die();
$token_dec = explode("_", $token_dec);
if (sizeof($token_dec) != 2)
    die();

//
// initialize JAXL object with initial config
//
require_once $DOCUMENT_ROOT . '/includes/lib/jaxl/jaxl.php';

$client = new JAXL(array(
    // (required) credentials
    'jid' => trim($token_dec[0]).'@chat.facebook.com',
    'fb_app_key' => APP_ID,
    'fb_access_token' => $_POST["sessionKey"],

    // force tls (facebook require this now)
    'force_tls' => true,
    // (required) force facebook oauth
    'auth_type' => 'X-FACEBOOK-PLATFORM',

    // (optional)
    //'resource' => 'resource',

    'log_level' => JAXL_ERROR
));

//
// add necessary event callbacks here
//
$client->add_cb('on_auth_success', function() {
    global $client;
    global $token_dec;
    global $invitation_prefix;
    global $invitation_suffix;          

    _info("got on_auth_success cb, jid ".$client->full_jid->to_string());
    $client->send_chat_msg("-" . trim($token_dec[1]) . "@chat.facebook.com", $invitation_prefix . $_POST["inviteURL"] . $invitation_suffix);
    $client->send_end_stream();
});

$client->add_cb('on_auth_failure', function($reason) {
    global $client;
    $client->send_end_stream();
    _info("got on_auth_failure cb with reason $reason");
});

$client->add_cb('on_disconnect', function() {
    _info("got on_disconnect cb");
});

//
// finally start configured xmpp stream
//
$client->start();

Any idea on why this is happening? Any way of performing a timeout on the socket and forcefully close it?

Unnecessary loading of the file

i am using jaxl library in my project on mac os and set up all configuration but when i am running that project at that time its continue loading and not connecting to the server so how can i solve my problem?
In my error_log file it's write like this :

27-May-2016 06:34:37 UTC] �[32mjaxl:238 - 2016-05-27 06:34:37 - strict mode enabled, adding exception handlers. Set 'strict'=>TRUE inside JAXL config to disable this�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_exception:66 - 2016-05-27 06:34:38 - error handler called with 8, Undefined index: priv_dir, /Applications/MAMP/htdocs/cslink/JAXL/jaxl.php, 168�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_exception:66 - 2016-05-27 06:34:38 - error handler called with 8, Undefined index: bosh_url, /Applications/MAMP/htdocs/cslink/JAXL/jaxl.php, 207�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_exception:66 - 2016-05-27 06:34:38 - error handler called with 8, Undefined index: stream_context, /Applications/MAMP/htdocs/cslink/JAXL/jaxl.php, 214�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_exception:66 - 2016-05-27 06:34:38 - error handler called with 8, Undefined index: resource, /Applications/MAMP/htdocs/cslink/JAXL/jaxl.php, 223�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_exception:66 - 2016-05-27 06:34:38 - error handler called with 8, Undefined index: force_tls, /Applications/MAMP/htdocs/cslink/JAXL/jaxl.php, 224�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_exception:66 - 2016-05-27 06:34:38 - error handler called with 8, Undefined index: bosh_url, /Applications/MAMP/htdocs/cslink/JAXL/jaxl.php, 373�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_fsm:61 - 2016-05-27 06:34:38 - calling state handler 'setup' for incoming event 'connect'�[0m
[27-May-2016 06:34:38 UTC] �[32mjaxl_socket_client:95 - 2016-05-27 06:34:38 - trying tcp://192.168.1.13:5222�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_socket_client:104 - 2016-05-27 06:34:38 - connected to tcp://192.168.1.13:5222�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_loop:82 - 2016-05-27 06:34:38 - active read fds: 1, write fds: 0�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_fsm:71 - 2016-05-27 06:34:38 - current state 'connected'�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_fsm:61 - 2016-05-27 06:34:38 - calling state handler 'connected' for incoming event 'start_stream'�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_loop:82 - 2016-05-27 06:34:38 - active read fds: 1, write fds: 1�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_fsm:71 - 2016-05-27 06:34:38 - current state 'wait_for_stream_start'�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_exception:66 - 2016-05-27 06:34:38 - error handler called with 8, Undefined index: --with-debug-shell, /Applications/MAMP/htdocs/cslink/JAXL/jaxl.php, 408�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_exception:66 - 2016-05-27 06:34:38 - error handler called with 8, Undefined index: --with-unix-sock, /Applications/MAMP/htdocs/cslink/JAXL/jaxl.php, 409�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_socket_client:201 - 2016-05-27 06:34:38 - sent 177/177 of data�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_socket_client:202 - 2016-05-27 06:34:38 - <stream:stream xmlns:stream="http://etherx.jabber.org/streams" version="1.0" to="etechtest" xmlns="jabber:client" xml:lang="en" xmlns:xml="http://www.w3.org/XML/1998/namespace">�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_loop:104 - 2016-05-27 06:34:38 - active read fds: 1, write fds: 0�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_socket_client:188 - 2016-05-27 06:34:38 - read 257/257 of data�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_socket_client:189 - 2016-05-27 06:34:38 - <stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='1746847457' from='localhost' xml:lang='en'>stream:error/stream:error/stream:stream�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_fsm:61 - 2016-05-27 06:34:38 - calling state handler 'wait_for_stream_start' for incoming event 'start_cb'�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_fsm:71 - 2016-05-27 06:34:38 - current state 'wait_for_stream_features'�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_fsm:61 - 2016-05-27 06:34:38 - calling state handler 'wait_for_stream_features' for incoming event 'stanza_cb'�[0m
[27-May-2016 06:34:38 UTC] �[37mxmpp_stream:468 - 2016-05-27 06:34:38 - no catch�[0m
[27-May-2016 06:34:38 UTC] �[31mxmpp_stream:112 - 2016-05-27 06:34:38 - got invalid return value from state handler 'wait_for_stream_features', sending end stream...�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_loop:82 - 2016-05-27 06:34:38 - active read fds: 1, write fds: 1�[0m
[27-May-2016 06:34:38 UTC] �[33mxmpp_stream:115 - 2016-05-27 06:34:38 - state handler 'logged_out' returned N;, kindly report this to developers�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_fsm:71 - 2016-05-27 06:34:38 - current state 'logged_out'�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_fsm:61 - 2016-05-27 06:34:38 - calling state handler 'logged_out' for incoming event 'end_cb'�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_loop:104 - 2016-05-27 06:34:38 - active read fds: 0, write fds: 0�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_fsm:71 - 2016-05-27 06:34:38 - current state 'disconnected'�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_loop:115 - 2016-05-27 06:34:38 - no more active fd's to select�[0m
[27-May-2016 06:34:38 UTC] �[37msendmessage:28 - 2016-05-27 06:34:38 - got on_disconnect cb�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_exception:83 - 2016-05-27 06:34:38 - got shutdown handler�[0m
[27-May-2016 06:34:38 UTC] �[32mjaxl:230 - 2016-05-27 06:34:38 - cleaning up pid and unix sock files�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_exception:66 - 2016-05-27 06:34:38 - error handler called with 2, unlink(/Applications/MAMP/htdocs/cslink/JAXL/.jaxl/run/jaxl_693.pid): No such file or directory, /Applications/MAMP/htdocs/cslink/JAXL/jaxl.php, 231�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_exception:66 - 2016-05-27 06:34:38 - error handler called with 2, unlink(/Applications/MAMP/htdocs/cslink/JAXL/.jaxl/sock/jaxl_693.sock): No such file or directory, /Applications/MAMP/htdocs/cslink/JAXL/jaxl.php, 232�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_loop:104 - 2016-05-27 06:34:38 - active read fds: 0, write fds: 0�[0m
[27-May-2016 06:34:38 UTC] �[37mjaxl_exception:66 - 2016-05-27 06:34:38 - error handler called with 2, fclose() expects parameter 1 to be resource, null given, /Applications/MAMP/htdocs/cslink/JAXL/core/jaxl_socket_client.php, 126�[0m
[27-May-2016 06:34:38 UTC] �[32mjaxl_clock:55 - 2016-05-27 06:34:38 - shutting down clock server...�[0m

Issue with Group Names in Roster

Hi,
We decided to switch to JAXL v3 and have found an issue with group names processing. The data is received as:

                    [87] => JAXLXml Object
                        (
                            [name] => item
                            [ns] => jabber:iq:roster
                            [attrs] => Array
                                (
                                    [jid] => [email protected]
                                    [name] => Anant Preet Kaur
                                    [subscription] => both
                                )

                            [text] =>
                            [childrens] => Array
                                (
                                    [0] => JAXLXml Object
                                        (
                                            [name] => group
                                            [ns] => jabber:iq:roster
                                            [attrs] => Array
                                                (
                                                )

                                            [text] => Sales
                                            [childrens] => Array
                                                (
                                                )

                                            [parent] => JAXLXml Object
 *RECURSION*
                                            [rover] => JAXLXml Object
 *RECURSION*
                                        )

                                )

                            [parent] => JAXLXml Object
 *RECURSION*
                            [rover] => JAXLXml Object
 *RECURSION*
                        )

However JAXL is attempting to use the "name" attribute when it should be using the "text" attribute. Code is around line 669 and fix is below:

                    $groups = array();
                    foreach($child->childrens as $group) {
                        if($group->name == 'group') {
                            $groups[] = $group->text;
                        }
                    }

Regards,

Varun Shoor

Handling of PID

I believe the handling of PID file is wrong. The filename not consistent, so it makes it hard if not impossible to survey individual CPU and memory use.

To change it, I did the following:

jaxl.php:170

        // touch pid file
        $this->unique_pid = @$this->cfg['pid_name'];
        if($this->mode == "cli") {
            file_put_contents($this->get_pid_file_path(), $this->pid);
            //touch($this->get_pid_file_path());
            _info("created pid file ".$this->get_pid_file_path());
        }

jaxl.php:235

    public function get_pid_file_path() {
        if (!isset($this->unique_pid) || $this->unique_pid == null) $this->unique_pid = $this->pid;
        return $this->pid_dir."/jaxl_".$this->unique_pid.".pid";
    }

Fetch Roster list and Vcard

Hi Abhinav Sir,
I am able to authenticate using this library.

'[email protected]', 'fb_app_key' => 'appkey', 'pass'=>'pwd', 'fb_access_token' => 'token', 'force_tls' => true, 'auth_type' => 'X-FACEBOOK-PLATFORM' )); $client->add_cb('on_auth_success', function() { global $client; _info("got on_auth_success cb, jid ".$client->full_jid->to_string()); $client->set_status("available!", "dnd", 10); $client->send_chat_msg("[email protected]","Hi.......",null,null); ``` $client->get_vcard(); $client->get_roster(); ``` }); $client->add_cb('on_auth_failure', function($reason) { global $client; $client->send_end_stream(); _info("got on_auth_failure cb with reason $reason"); }); $client->add_cb('on_roster_update', function() { global $client; print_r($client->roster); }); /* $client->add_cb('on_chat_message', function($stanza) { global $client; ``` // echo back incoming message stanza $stanza->to = $stanza->from; $stanza->from = $client->full_jid->to_string(); $client->send($stanza); ``` }); */ $client->add_cb('on_presence_stanza', function($stanza) { global $client; ``` $type = ($stanza->type ? $stanza->type : "available"); $show = ($stanza->show ? $stanza->show : "???"); _info($stanza->from." is now ".$type." ($show)"); if($type == "available") { // fetch vcard $client->get_vcard($stanza->from); } ``` }); $client->add_cb('on_disconnect', function() { _info("got on_disconnect cb"); }); $client->start(); echo "done\n"; ?>

Here I am not able to send the msg to the person.
But when I use [email protected], I am able to send the message successfully.
I tried as follows:
send_chat_msg('[email protected]',"Hi.........",null,null);
But i got failure to send the msg.
But when i used send_chat_msg('[email protected]',"Hi.........",null,null);
I successfully sent the msg. (Assume that uname = 'sandy.d' and id='3456356444').
Please tell me what is the problem.

Also how to fetch information retrieved using $client->get_vcard($stanza->from);
Please tell me.

how to register a openfire or ejabberd with jaxl?

hi:
i m a very new for xmpp and openfire on windows server.
I want to konw how to register a openfire or ejabberd with jaxl。
the examples are not work ,
anyone help me ,please .

my codes like this:

class xmpp {

public function register_user($username, $password) {
    require_once './jaxl/jaxl.php';

    $this->client = new JAXL(array(
        'jid' => 'reg',
        'host' => '127.0.0.1',
        'port' => '5222',
        'log_level' => JAXL_DEBUG
    ));
    $this->username = $username;
    $this->password = $password;

    $this->client->require_xep(array(
        '0077'  // InBand Registration  
    ));
    $thisClassObject = & $this;

    $this->client->add_cb('on_stream_features', function($stanza) use(&$thisClassObject) {
        $thisClassObject->client->xeps['0077']->get_form('localhost');
        return array($thisClassObject, 'wait_for_register_form');
    });

    $this->client->start();

    return;
}

public function wait_for_register_response($event, $args) {

    if ($event == 'end_stream') {
        return;
    } else if ($event == 'stanza_cb') {
        $stanza = $args[0];
        echo '<pre>';
        print_r($stanza);
        if ($stanza->name == 'iq') {
            if ($stanza->attrs['type'] == 'result') {
                echo "registration successful" . PHP_EOL . "shutting down..." . PHP_EOL;
                $client->send_end_stream();
                return 'logged_out';
            } else if ($stanza->attrs['type'] == 'error') {
                $error = $stanza->exists('error');
                echo "registration failed with error code: " . $error->attrs['code'] . " and type: " . $error->attrs['type'] . PHP_EOL;
                echo "error text: " . $error->exists('text')->text . PHP_EOL;
                echo "shutting down..." . PHP_EOL;
                $client->send_end_stream();
                return "logged_out";
            }
        }
    }
}

public function wait_for_register_form($event, $args) {

    $stanza = $args[0];
    $query = $stanza->exists('query', NS_INBAND_REGISTER);
    if ($query) {
        $form = array();
        $instructions = $query->exists('instructions');
        if ($instructions) {
            echo $instructions->text . PHP_EOL;
        }

        $this->client->xeps['0077']->set_form($stanza->attrs['from'], array('username' => $this->username, 'password' => $this->password));
        return array($this, "wait_for_register_response");
    } else {
        $client->send_end_stream();
        return "logged_out";
    }
}

}

$xmppObj = new xmpp();
var_dump($xmppObj->register_user('user', 'password') );

but it does not register success,and got a message:
registration failed with error code: 400 and type: modify

thanks!

JAXL undefined variable client running with jaxlctl debug sock_file_name

I am trying to start a JAXL daemon by running JAXL's echo_bot.php.

It's working as I expected. The sock file is generated under .jaxl/sock/.

Then I use jaxl attach the sock file which I got from running echo_bot.php. I tried to run the example given here. But I get below error message when trying jaxlctl debug. It complains undefined variable, client Could you point me where I am wrong? Thanks!

$ ./jaxlctl debug .jaxl/sock/jaxl_3961
jaxl_socket_client:95 - 2014-04-30 10:39:55 - trying unix://.jaxl/sock/jaxl_3961
jaxl 2> global $client;
jaxl 3> $client->send_chat_msg('[email protected]', 'Hello JAXL');
jaxl_socket_client:175 - 2014-04-30 10:40:43 - socket eof, disconnecting

jaxl 1> jaxl_exception:48 - 2014-04-30 10:40:43 - got jaxl exception construct with Undefined variable: client, 8, /to_my_path/JAXL-3.x/jaxl.php(458) : eval()'d code, 1

JAXL keeps running after HTTP disconnect when running using mod_php in apache2

Hi!
I am using JAXL to create XMPP-AJAX bridge using mod_php and apache2 (without secondary HTTP daemon based on JAXL) and i leave JAXL XMPP client running as long as possible (while apache or browser keeps connection open). But when i close connection to webserver JAXL keeps running on server (i am sure that there is no open connection to apache). I have XMPP echo working for test purposes and i've noticed that JAXL is able to echo back one single message when connection apache was closed. After handling this event (echoing message) JAXL ends just like when terminated using SIGTERM when executed from terminal. So my guess is that event machine is left polling somewhere. Is it bug or feature? If it's feature how can i avoid it? I need JAXL to stop blocking other AJAX instance right after the first is disconnected (without need to send last message to XMPP)

More closely:
I want to implement AJAX form to chat with helpdesk without using any persistent daemon that can't be executed directly from apache. I need another customer to be able to chat with helpdesk once first was disconnected (without need of sending message to shut JAXL when AJAX is disconnected).

Even more closely:
I am using two mechanisms:
1.) XMPP2AJAX: JAXL XMPP connection that echoes received messages to HTTP (AJAX streaming comet design)
2.) AJAX2XMPP: PHP script forwarding messages to JAXLPipe whis calss JAXL XMPP send()

Both JAXL and JAXLPipe are long-running in same process streaming to AJAX while sending messages from ajax is second oneshot script that just writes to pipe which is read by JAXL process.

Hope it's clear. THX for JAXL and THX for help :-)

Can't get send_groupchat working with OpenFire, nothing logged

Trying to run this, and it logs nothing, doesn't exist and doesn't work.

$client->xeps['0045']->send_groupchat($room_jid, $messages);

I have tried both having $room_jid as an instance of XMPPJid combined with nickname and room, and also just passing the actual room_jid ([email protected]).

Have anyone got this jabber-implementation working?

How to attach jaxl daemon with jaxlctl tool

I created a jaxl instance by running echo_bot.php
> php echo_bot.php myjid@xxxx pass PLAIN

it seems working well and I got below message

jaxl:188 - 2014-04-23 10:00:11 - created pid file /Volumes/Central/Users/jsun/Sites/JAXL/.jaxl/run/jaxl_74164.pid
jaxl:200 - 2014-04-23 10:00:11 - dns srv lookup for myserver.com
jaxl_socket_client:95 - 2014-04-23 10:00:11 - trying tcp://myserver.com:5222
jaxl 1> jaxl_socket_server:63 - 2014-04-23 10:00:11 - socket ready to accept on path unix:///path/JAXL/.jaxl/sock/jaxl_74164.sock

Next, I start jaxlctl

./jaxlctl debug unix:///Volumes/Central/Users/jsun/Sites/JAXL/.jaxl/sock/jaxl_74164.sock

But response I got is :

jaxl_socket_client:95 - 2014-04-23 10:48:23 - trying unix://unix:///Volumes/Central/Users/jsun/Sites/JAXL/.jaxl/sock/jaxl_74164.sock
jaxl_socket_client:115 - 2014-04-23 10:48:23 - unable to connect unix://unix:///Volumes/Central/Users/jsun/Sites/JAXL/.jaxl/sock/jaxl_74164.sock with error no: 2, error str: No such file or directory

Did I use the wrong command?

XEP0085 chat states

Here's a script to enable chat states (XEP0085). You can get the chat state by calling $chatState = XEP_0085::get_chat_state($stanza);

I used the other XEP as base.

<?php
/**
 * Jaxl (Jabber XMPP Library)
 *
 * Copyright (c) 2009-2012, Abhinav Singh <[email protected]>.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in
 * the documentation and/or other materials provided with the
 * distribution.
 *
 * * Neither the name of Abhinav Singh nor the names of his
 * contributors may be used to endorse or promote products derived
 * 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.
 *
 */

require_once JAXL_CWD.'/xmpp/xmpp_xep.php';

define('NS_CHATSTATES', 'http://jabber.org/protocol/chatstates');

class XEP_0085 extends XMPPXep {

    public static $chatStates = array('composing', 'active', 'inactive', 'paused', 'gone');

    //
    // abstract method
    //

    public function init() {
        return array(
        );
    }

    public static function get_chat_state($stanza)
    {
        $chat_state = false;
        foreach ($stanza->childrens as $child)
        {
            if ($child->ns == NS_CHATSTATES)
            {
                foreach(self::$chatStates as $state) {
                    if($child->name == $state) {
                        $chat_state = $state;
                    }
                }
            }
        }
        return $chat_state;
    }

}

?>

JAXL doesn't emit on_disconnect event if connection was just closed from another side

I'm running script in screen app. Here is part from log:

jaxl_socket_server:63 - 2013-09-14 07:25:24 - socket ready to accept on path unix:///xx...xx/JAXL/.jaxl/sock/jaxl_5479.sock
msg_bot:55 - 2013-09-14 07:25:25 - got on_auth_success cb
jaxl_socket_client:175 - 2013-09-25 17:20:00 - socket eof, disconnecting

After few days i've logged in and pressed Ctrl-C:

^Cmsg_bot:103 - 2013-10-02 08:30:52 - got on_disconnect cb
jaxl_exception:48 - 2013-10-02 08:30:52 - got jaxl exception construct with fclose() expects parameter 1 to be resource, null given, 2, /www/g1/heroeslands/xmpp/JAXL/core/jaxl_socket_client.php, 126
jaxl:211 - 2013-10-02 08:30:52 - cleaning up pid and unix sock files
jaxl_socket_server:75 - 2013-10-02 08:30:52 - shutting down socket server
jaxl_clock:55 - 2013-10-02 08:30:52 - shutting down clock server...

Looking in code reveals that connection just silently closed and no other action was done. And no simple means to emit event or other ways to notify higher levels of app about disconnect.

Develop Method for register user

Hey, Can you create a new method in your library so by simply passing username and password anyone can register to ejjaberd server because i am facing problem to create method for register user so can u do this?

GTalk authentication for google apps.

Hi,

First of all - awesome library.

I'm attempting to create a GTalk chatbot using JAXL, with the following code:

$client = new JAXL(array(
    'jid' => '[email protected]',
    'pass' => 'mypass',
    'host'  => 'talk.google.com',
    'port'  => 5222,
));

But it will not allow me to connect at all, is integration with GTalk for google apps not working with this library?

Thanks,
Dan.

Lack of sanitization in JAXLXML

in JAXLXML the XML tags are sent without sanitization or enclosing em in CDATA. This causes the system to trigger end_cb and end the active stream.

Fix (around line 214, jaxl_xml.php):

        if($this->text) $xml .= '<![CDATA[' . $this->text . ']]>';

Regards,

Varun Shoor

Segmentation Fault when in a class that extends Thread

It seems that JAXL doesn't work well with threads. The following code seg-faults, and we're not even spawning a new thread.

I'm running PHP 5.4.24 (cli) on Red Hat 4.4.6-4.

I compiled PHP with the -enable-maintainer-zts option and then I installed pthreads using pecl.

<?
require("jaxl.php");

class SegFault extends Thread {
    private $client = null;

    public function connect($jid, $password) {
        $this->client = new JAXL(array(
            'jid' => $jid,
            'pass' => $password
        ));

        $this->client->require_xep(array(
            '0199'  // XMPP Ping
        ));

    }

    public function run() {
    }
}

$segFault = new SegFault();
$segFault->connect($argv[1], $argv[2]);

the http-bind example is always disconnect

<?php

require_once 'jaxl.php';
$client = new JAXL(array(
    'jid' => 'bob@admin-pc',
    'pass' => 'bob',
    'bosh_url' => 'http://127.0.0.1:7070/http-bind/',
    'log_level' => JAXL_DEBUG
));
$client->add_cb('on_auth_success', function() {
    global $client;
    echo 12313213;
    _info("got on_auth_success cb, jid ".$client->full_jid->to_string());
});

$client->start();
echo "done\n";

?>

Fatal error: Maximum execution time of 30 seconds exceeded in F:\AppServ\www\test\xmpp\JAXL-3.x\xep\xep_0206.php on line 132"

php parse error

I open the publisher.php in browser and following error display:

Parse error: syntax error, unexpected T_FUNCTION in C:\APMServ5.2.6(image)\www\htdocs\jaxl\publisher.php on line 62

infinite recv loop while making connection with xmpp server

i am trying to connect with openfire server using JAXL XMPP Library for PHP but i am falling into infinite loop, i have used strophe i am able to connect using that but not in PHP

here is my code

$client = new JAXL(array(
    'jid' => '[email protected]',
    'pass' => 'pass@123',
   // 'host'=>'mydomain.in',
    //'port'=>'5222',
    'bosh_url' => 'http://rewire.in/http-bind',
    'log_level'=>JAXL_DEBUG,
    'log_path'=> './log/xmpp.txt',
   // 'auth_type'=>'DIGEST-MD5'
));

here is my log

jaxl:188 - 2014-03-26 16:40:58 - created pid file C:\Apache24\htdocs\mypro\JAXL/.jaxl/run/jaxl_16028.pid
jaxl_exception:66 - 2014-03-26 16:40:58 - error handler called with 8, Undefined index: host, C:\Apache24\htdocs\mypro\JAXL\jaxl.php, 197
jaxl_exception:66 - 2014-03-26 16:40:58 - error handler called with 8, Undefined index: port, C:\Apache24\htdocs\mypro\JAXL\jaxl.php, 197
jaxl:200 - 2014-03-26 16:40:58 - dns srv lookup for mydomain.in
jaxl:208 - 2014-03-26 16:40:58 - including bosh xep
jaxl_exception:66 - 2014-03-26 16:40:58 - error handler called with 8, Undefined index: resource, C:\Apache24\htdocs\mypro\JAXL\jaxl.php, 223
jaxl_exception:66 - 2014-03-26 16:40:58 - error handler called with 8, Undefined index: force_tls, C:\Apache24\htdocs\mypro\JAXL\jaxl.php, 224
jaxl_exception:66 - 2014-03-26 16:40:58 - error handler called with 8, Undefined index: bosh_rid, C:\Apache24\htdocs\mypro\JAXL\xep\xep_0206.php, 193
jaxl_exception:66 - 2014-03-26 16:40:58 - error handler called with 8, Undefined index: bosh_hold, C:\Apache24\htdocs\mypro\JAXL\xep\xep_0206.php, 194
jaxl_exception:66 - 2014-03-26 16:40:58 - error handler called with 8, Undefined index: bosh_wait, C:\Apache24\htdocs\mypro\JAXL\xep\xep_0206.php, 195
jaxl_fsm:61 - 2014-03-26 16:40:58 - calling state handler 'setup' for incoming event 'start_cb'
xep_0114:68 - 2014-03-26 16:40:58 - starting component handshake
jaxl_exception:66 - 2014-03-26 16:40:58 - error handler called with 8, Undefined index: id, C:\Apache24\htdocs\mypro\JAXL\xmpp\xmpp_stanza.php, 81
xep_0206:109 - 2014-03-26 16:40:58 - posting to http://mydomain.in/http-bind body <body sid="" rid="3285" xmlns="http://jabber.org/protocol/httpbind"><handshake>ba97b1cf397425a852d1316d10787b1d97b5bc85</handshake></body>
jaxl_fsm:71 - 2014-03-26 16:40:58 - current state 'wait_for_stream_features'
xep_0206:109 - 2014-03-26 16:40:58 - posting to http://mydomain.in/http-bind body <body xmlns="http://jabber.org/protocol/httpbind" content="text/xml; charset=utf-8" to="mydomain.in" route="xmpp:mydomain.in:5222" secure="true" xml:lang="en" xmpp:version="1.0" xmlns:xmpp="urn:xmpp:xbosh" hold="1" wait="30" rid="3285" ver="1.10" from="[email protected]"></body>
xep_0206:132 - 2014-03-26 16:40:58 - recving for 3285
xep_0206:132 - 2014-03-26 16:40:58 - recving for 3285
xep_0206:132 - 2014-03-26 16:40:58 - recving for 3285
xep_0206:132 - 2014-03-26 16:40:58 - recving for 3285
xep_0206:132 - 2014-03-26 16:40:58 - recving for 3285
xep_0206:132 - 2014-03-26 16:40:58 - recving for 3285
xep_0206:132 - 2014-03-26 16:40:58 - recving for 3285
xep_0206:132 - 2014-03-26 16:40:58 - recving for 3285

JAXL XMPP script works, but never stops loading

I am implementing the Facebook Chat into my site so I used JAXL in order to implement the XMPP. It seems that the script posts the message that I wanted, but whenever I run it, the page just keeps loading and loading and never stops. In order to get back onto that site, I have to clear the cookies for it in my browser. Not sure what the problem could be, I am not seeing any errors in my log. Take a look at the code: Thanks!

$client = new JAXL(array(
'jid' => $user['facebookID']."@chat.facebook.com",
'fb_app_key' => "XXXX",
'fb_access_token' => $user['facebook_access_token'],
'force_tls' => true,
'auth_type' => 'X-FACEBOOK-PLATFORM',
'log_level' => JAXL_INFO,
'priv_dir' => "includes/lib/jaxl/tmp"
));

$client->add_cb('on_auth_success', function() {
    global $client;
    _info("got on_auth_success cb, jid ".$client->full_jid->to_string());
    $client->set_status("available!", "dnd", 10);

    $msg = new XMPPMsg(array('to'=>'[email protected]'), 'test message');
    $client->send($msg);
});

$client->add_cb('on_auth_failure', function($reason) {
    global $client;
    $client->send_end_stream();
    _info("got on_auth_failure cb with reason $reason");
});

$client->add_cb('on_chat_message', function($stanza) {
    global $client;

    // echo back incoming message stanza
    $stanza->to = $stanza->from;
    $stanza->from = $client->full_jid->to_string();
    $client->send($stanza);
});

$client->add_cb('on_disconnect', function() {
    _info("got on_disconnect cb");
});

//
// finally start configured xmpp stream
//
$client->start();

Facebook Chat is replying automatically and it never stops!

Well i'm stuck in a really weird thing:
I've runned the basic example for connecting to the facebook chat but unfortunally i did not delete the event handler that replies to the "on_chat_message".
So basically now, everyone who messages me gets a reply n times the times i've reloaded the script.

It seems like there are n ghost active process on the facebook chat assigned to my user and I DON'T KNOW HOW TO KILL THEM :)

Please anyone knows what's going on?

how to start jalx library with openfire serve for send and recive messages.

i ma very new for xmpp and openfire on windows server. i want to implement instant messaging. my server and website are on different servers. so how can i install jaxl librery on windows server and how can i use user login, send message, recive message, and get roster with jaxl.

please help me and get me out of this.

prebind is not working in localhost

Hi all,

I am using JAXL with converse.js for pre-bind users. Its working on my server with the configuration as PHP 5.3.3/Apache 2.2.15/ Cent OS. and my localhost having a configuration like PHP 5.3.5/Apache 2.2.17/Windows 7 But its not working in localhost. The Http-request simply returns 200 OK with content-length as 0.

Can any one help me with this issue.

My http request on my working environment

Request headers
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36 FirePHP/4Chrome
Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
Content-Type: application/x-www-form-urlencoded
Accept: /
Accept-Encoding: gzip,deflate
Accept-Language: en-US,en;q=0.8,ms;q=0.6,ta;q=0.4
Cookie: PHPSESSID=8v5ro5ru7hqtaq89lg28i4s2t3; JSESSIONID=19rosig5jcl761akadrawbzui; __utma=242230530.1969473282.1412947324.1414489064.1414553786.15; __utmc=242230530; __utmz=242230530.1412947324.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
X-FirePHP-Version: 0.0.6
X-Wf-Max-Combined-Size: 262144

Response headers
Date: Mon, 03 Nov 2014 12:07:46 GMT
Server: Apache/2.2.15 (CentOS)
X-Powered-By: PHP/5.3.3
Cache-Control: no-cache, must-revalidate
Access-Control-Allow-Origin: *
Content-Length: 101
Connection: close
Content-Type: application/json; charset=utf-8

Response content
{"rid":4302,"sid":"ce99f809","jid":"xxx@iz25pkf9c7hz","bosh_url":"http://xxx.xx.xx.xx/http-bind"}

The same HTTP request from my local system (localhost)

Request headers
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36 FirePHP/4Chrome
Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
Content-Type: application/x-www-form-urlencoded
Accept: /
Accept-Encoding: gzip,deflate
Accept-Language: en-US,en;q=0.8,ms;q=0.6,ta;q=0.4
Cookie: PHPSESSID=5nrfetcglg4useu288g8boi2v0
X-FirePHP-Version: 0.0.6
X-Wf-Max-Combined-Size: 262144

Response headers
Date: Mon, 03 Nov 2014 12:13:52 GMT
Server: Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By: PHP/5.3.5
Cache-Control: no-cache, must-revalidate
Access-Control-Allow-Origin: *
Content-Length: 0
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/json; charset=utf-8

Can any one let me know how to debug this one?

Windows shows error argc undefined variable

Hi I am trying to run the examples/echo_bosh_bot.php, but I get the below error, I have uncommented the the field
register_argc_argv
Default Value: On
Development Value: Off
Production Value: Off

in php.ini file what should I do in order to correct this

Notice: Undefined variable: argc in E:\xampp\htdocs\JAXL\examples\echo_bosh_bot.php on line 39

Notice: Undefined variable: argv in E:\xampp\htdocs\JAXL\examples\echo_bosh_bot.php on line 40
Usage: jid pass

BOSH Problem

Can't seem to connect via BOSH , the error returned by JAXL is :

jaxl:219 - 2012-12-06 13:32:07 - strict mode enabled, adding exception handlers. Set 'strict'=>TRUE inside JAXL config to disable this
jaxl_exception:66 - 2012-12-06 13:32:07 - error handler called with 8, Undefined index: priv_dir, /home/david/Downloads/JAXL-3.x/jaxl.php, 146
jaxl:166 - 2012-12-06 13:32:07 - created pid file /home/david/Downloads/JAXL-3.x/.jaxl/run/jaxl_31179.pid
xmpp_stream:112 - 2012-12-06 13:32:07 - got invalid return value from state handler 'wait_for_bind_response', sending end stream...
xmpp_stream:115 - 2012-12-06 13:32:07 - state handler 'logged_out' returned N;, kindly report this to developers
^Cjaxl_exception:48 - 2012-12-06 13:32:08 - got jaxl exception construct with Undefined offset: 0, 8, /home/david/Downloads/JAXL-3.x/jaxl.php, 769

I have tested this with node-xmmp-bosh , and pubjab, both return the same result.

If needed , I can give you the full debugging output from node-xmpp-bosh.

Documentation Problem

Hii abhinav, i want to connect ejjaberd server in my site for the chat purpose but problem is their i haven't found good documentation to develop code, i have used your library and create send message file whenever i run that file it will online the user which i have set in constructor if i run that file ten time than it will show 10 user login but only one user is login for ten time in ejjeberd server so will you please help me how can i figure it out.

multiple scripts connecting to the same socket

Hi there,

I'm wondering if there is a way to have multiple scripts connect to the same socket connection.

To give some background in case you have a better way of doing things. I'm creating a bot (not bosh) that will live in our muc chatroom and perform the following functions:

  1. Respond to queries in chat about certain topics
  2. periodically polling an external service and then sending alerts to the chat room if certain criteria is filled.

I more or less have a bot built that works for part 1 using the on_group_chat event. This is what creates the connection to the chatroom. I'm not too sure how to fulfill the second requirement, I would have thought that I would want to connect to the socket and send out the message only when my external service tells me to. Does this sound right?

I'm also having an issue where the bot seems to time out after some period of time. Is there a way to fix this or find out what is causing this?

Thanks,
Tim

cant specify where to write the tmp, run, log, sock dirs

in the constructor u have this code

    $this->tmp_dir = JAXL_CWD."/.jaxl/tmp";
    $this->pid_dir = JAXL_CWD."/.jaxl/run";
    $this->log_dir = JAXL_CWD."/.jaxl/log";
    $this->sock_dir = JAXL_CWD."/.jaxl/sock";

on the top of the file

           define('JAXL_CWD', dirname(__FILE__));

so thix way u cant specify another base directory ?

BOSH authentication - SASL namespace

I have tried to implement BOSH pre-bind service, similar to this http_pre_bind example.

However, when trying to use it (or implement my own, slightly different), I have encountered the following bug. When the authentication is performed, wait_for_sasl_response() in XMPPStream class does always classifies the response as unhandled.

It is caused by unexpected namespace of success element, which is passed to the handler as $stanza parameter (and by the way, imho not real "stanza", according to XMPP specification). The code expects the namespace to be NS_SASL ('urn:ietf:params:xml:ns:xmpp-sasl'), however I got simple 'jabber:client' namespace. Is this bug in JAXL or does the BOSH server send invalid respond?

I have temporarily "fixed" this by commenting out the namespace check in wait_for_sasl_response method. What's the reason to do the namespace check there? If it's not necessary, just let me know and I'll do the pull request with patch.

By the way, my code is using public https://bind.jappix.com/ BOSH service.

got jaxl exception construct with Undefined offset

Hi!
I got this error message:

jaxl_exception:48 - 2012-09-20 03:16:57 - got jaxl exception construct with Undefined offset: 0, 8, D:\InetSoft\OpenServer\domains\simple\abhinavsingh-JAXL-f42e050\jaxl.php, 766

In 766 line is code

    public function handle_other($event, $args) {
        $stanza = $args[0];

If change this code on code:

    public function handle_other($event, $args) {
        $stanza = isset($args[0])?$args[0]:null;

then the error not happens.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.