Re: register users with jaxl and ejabberd

609 views
Skip to first unread message

Abhinav Singh

unread,
Sep 12, 2012, 7:04:21 PM9/12/12
to ja...@googlegroups.com
Hi Alex,

A few things will get this right for you.
$ php examples/register_user.php
Usage: examples/register_user.php domain
So as you can see in the usage section, register_user.php requires domain name as first parameter and not a jid.

Second problem was that, push done on 10th Aug. (oh yeah abt 1 month back) silently broke register_user.php example.
I have reverted that and pushed the same changes with another fix that will make register_user.php work now.

It's time to roll out our test suites, otherwise such stupid mistakes might happen again from my (human ;)) end.
I will soon push the test suites along with travis powered continuous integration (CI) which can tell us about these broken issues automagically.

Meanwhile you can checkout the latest code from github and try again.
If you still face any unexpected issue, kindly let me know.

--
Abhinav

On Wednesday, September 12, 2012 9:10:17 PM UTC+5:30, Alex Margarit wrote:
Hi, I'm trying to make register_user.php example to work but it seems to throw me this error: 


jaxl:198 - 2012-09-12 15:07:40 - dns srv lookup for localhost
jaxl_fsm:56 - 2012-09-12 15:07:40 - calling state handler 'setup' for incoming event 'connect'
jaxl_socket_client:91 - 2012-09-12 15:07:40 - trying tcp://localhost:5222
jaxl_socket_client:96 - 2012-09-12 15:07:40 - connected to tcp://localhost:5222
jaxl_loop:82 - 2012-09-12 15:07:40 - active read fds: 1, write fds: 0
jaxl_fsm:73 - 2012-09-12 15:07:40 - current state 'connected'
jaxl_fsm:56 - 2012-09-12 15:07:40 - calling state handler 'connected' for incoming event 'start_stream'
jaxl_loop:82 - 2012-09-12 15:07:40 - active read fds: 1, write fds: 1
jaxl_fsm:73 - 2012-09-12 15:07:40 - current state 'wait_for_stream_start'
jaxl_socket_client:188 - 2012-09-12 15:07:40 - sent 202/202 of data
jaxl_socket_client:189 - 2012-09-12 15:07:40 - <stream:stream xmlns:stream="http://etherx.jabber.org/streams" version="1.0" from="alez009@localhost" to="localhost" xmlns="jabber:client" xml:lang="en" xmlns:xml="http://www.w3.org/XML/1998/namespace">
jaxl_loop:100 - 2012-09-12 15:07:40 - active read fds: 1, write fds: 0
jaxl_socket_client:175 - 2012-09-12 15:07:40 - read 577/577 of data
jaxl_socket_client:176 - 2012-09-12 15:07:40 - <?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='1026448716' from='localhost' version='1.0' xml:lang='en'><stream:features><starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism></mechanisms><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.process-one.net/en/ejabberd/' ver='TQ2JFyRoSa70h2G1bpgjzuXb2sU='/><register xmlns='http://jabber.org/features/iq-register'/></stream:features>
jaxl_fsm:56 - 2012-09-12 15:07:40 - calling state handler 'wait_for_stream_start' for incoming event 'start_cb'
jaxl_fsm:73 - 2012-09-12 15:07:40 - current state 'wait_for_stream_features'
jaxl_fsm:56 - 2012-09-12 15:07:40 - calling state handler 'wait_for_stream_features' for incoming event 'stanza_cb'
jaxl_loop:82 - 2012-09-12 15:07:40 - active read fds: 1, write fds: 1
jaxl_exception:48 - 2012-09-12 15:07:40 - got jaxl exception construct with Object of class JAXLXml could not be converted to string, 4096, ..../JAXL/core/jaxl_fsm.php, 73
jaxl_exception:75 - 2012-09-12 15:07:40 - exception handler catched {}
jaxl:228 - 2012-09-12 15:07:40 - cleaning up pid and unix sock files
jaxl_clock:55 - 2012-09-12 15:07:40 - shutting down clock server...


The way I'm starting executing the file is this: php register_user.php alez009@localhost . 

Is there something I'm doing wrong ? The xmpp server is ejabberd.

Thanks

Alex Margarit

unread,
Sep 13, 2012, 3:46:28 AM9/13/12
to ja...@googlegroups.com
Hi Abhinav,

Thanks for your reply that seemed to work but not completely. Right now I think I'm in an infinite loop with this response: 

jaxl_socket_client:176 - 2012-09-13 07:42:34 - <iq type="result" id="1" from="localhost"><query xmlns="jabber:iq:register"><username/><password/><email/><name/><x xmlns="jabber:x:data" type="form"><title>XMPP Client Registration</title><instructions>Please provide the following information</instructions><field var="FORM_TYPE" type="hidden"><value>jabber:iq:register</value></field><field var="username" type="text-single" label="Username"><required/></field><field var="name" type="text-single" label="Full name"/><field var="email" type="text-single" label="Email"/><field var="password" type="text-private" label="Password"><required/></field></x></query></iq>
jaxl_fsm:56 - 2012-09-13 07:42:34 - calling state handler 'wait_for_sasl_response' for incoming event 'stanza_cb'
xmpp_stream:543 - 2012-09-13 07:42:34 - got unhandled sasl response
jaxl_fsm:78 - 2012-09-13 07:42:34 - current state 'wait_for_sasl_response'

After digging more about this in "wait_for_sasl_response" method, I see that there is not handled a $stanza->name == 'iq' and $stanza->ns == NS_JABBER_CLIENT and this is what we are getting from that response. What's the best approach top fix this ? Did I understand everything correctly ? 

Best,
Alex

Abhinav Singh

unread,
Sep 13, 2012, 7:21:58 AM9/13/12
to ja...@googlegroups.com
Hi Alex,

The problem was with my fix. I have updated the fix which should definitely work now.

Regarding your understanding of the flow, the client FSM shouldn't have reached till 'wait_for_sasl_response' state since we aren't doing any authentication inside register_user.php, our intension is just to register the user and exit the script.

Kindly checkout the v3.x branch again to get the latest updates and try again.
Lemme know if you still face any issue.

--
Abhinav

Alex Margarit

unread,
Sep 14, 2012, 8:38:35 AM9/14/12
to ja...@googlegroups.com
Hi Abhinav,

Thank you for your help. We're going to use JAXL v3 in a large project and I'll bring to your attention every problem I find. I am grateful you guys respond fast to questions and keep up the good work :)

Alex

Ying sun

unread,
Jun 11, 2014, 12:29:20 AM6/11/14
to ja...@googlegroups.com
hi Abhinav
how does register_user.php work? 
I just want to register a new user for openfire or ejabberd,
there is no tutorials about this 
please hlep me
thanks

mycodes here

class xmpp {

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

        $this->client = new JAXL(array(
            'jid' => 'localhost',
            'host' => '127.0.0.1',
            'port' => '5222',
            'log_level' => JAXL_ERROR
        ));
        $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];

            if ($stanza->name == 'iq') {
                if ($stanza->attrs['type'] == 'result') {
                    echo "registration successful" . PHP_EOL . "shutting down..." . PHP_EOL;
                    $this->$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;
                    $this->$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 {
            $this->$client->send_end_stream();
            return "logged_out";
        }
    }

}

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


but I got a massage like this:
registration failed with error code: 400 and type: modify
Reply all
Reply to author
Forward
0 new messages