usage of libstrophe library for xmpp

user3129824

I am trying to create a chat client in C using Libstrophe. I have referred to the following code example given at https://github.com/metajack/libstrophe/blob/master/examples/active.c The code has a call to xmpp_connect_client(...) to establish a connection with the xmpp server.

 int main(int argc, char **argv)
 {
xmpp_ctx_t *ctx;
xmpp_conn_t *conn;

if (argc != 3) {
    fprintf(stderr, "Usage: active <jid> <pass>\n\n");
    return 1;
}

/* initialize lib */
xmpp_initialize();

/* create a context */
ctx = xmpp_ctx_new(NULL, NULL);

/* create a connection */
conn = xmpp_conn_new(ctx);

/* setup authentication information */
xmpp_conn_set_jid(conn, argv[1]);
xmpp_conn_set_pass(conn, argv[2]);

/* initiate connection */
xmpp_connect_client(conn, "talk.google.com", 0, conn_handler, ctx);

/* start the event loop */
xmpp_run(ctx);

/* release our connection and context */
xmpp_conn_release(conn);
xmpp_ctx_free(ctx);

/* shutdown lib */
xmpp_shutdown();

return 0;

} But where does the authentication take place? I looked up the source code for libstrophe and found C file auth.c https://github.com/metajack/libstrophe/blob/master/src/auth.c that has a function called _auth(..). I tried using _auth(..) in my code but it does not perform authentication properly. i.e. it does not notify me of wrong user-name or password. Can any one suggest me the right way to authenticate my entity.

MattJ

libstrophe authenticates automatically when necessary. This happens inside xmpp_run(). The credentials it uses are set using these lines:

/* setup authentication information */
xmpp_conn_set_jid(conn, argv[1]);
xmpp_conn_set_pass(conn, argv[2]);

The jid is your address (such as "[email protected]", "[email protected]", "[email protected]", etc.), and pass is your password.

Your example is missing your conn_handler function, which is where authentication errors will be delivered to.

Your conn_handler function should have a signature like this:

void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status, 
                  const int error, xmpp_stream_error_t * const stream_error,
                  void * const userdata)

The parameters are:

conn - Your connection object.

status - One of XMPP_CONN_CONNECT, XMPP_CONN_DISCONNECT or XMPP_CONN_FAIL. When your connection handler function is called, this parameter tells you why it was called.

error - when disconnected (XMPP_CONN_FAIL), this contains the socket-level error code from the OS (otherwise it is 0).

stream_error - one of the possible stream errors, listed at strophe.h:171, and their meaning documented in RFC6120 section 4.9.3.

userdata - This contains whatever you passed as the userdata parameter to xmpp_connect_client(). It is useful if you have some per-connection state to keep, and you don't want to use global variables or have multiple connections.

Finally, you shouldn't have to specify "talk.google.com" in xmpp_connect_client(), I recommend passing NULL instead.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

usage of libstrophe library for xmpp

From Dev

Nodejs XMPP Component Usage

From Dev

Xamarin XMPP client library

From Dev

Is there an Android native library for XMPP client?

From Dev

Library for developing XMPP server in c++ or delphi?

From Dev

XMPP library working with Boost.ASIO

From Dev

Listening on a port for an XMPP connection using Smack library

From Dev

Perl library usage

From Dev

External library usage in eclipse

From Dev

External library usage in xcode

From Dev

usage of + in Posix Regex library

From Dev

android static library usage

From Dev

Mosquitto library usage with iOS

From Dev

How to connect XMPP bosh server using java smack library?

From Dev

Android XMPP connection is not persistant - asmack library even running in a separate thread

From Dev

XMPP connection hanging on "Resource Binding" process using xmedianet library

From Dev

Send PUSH notification to Google Firebase by Gloox XMPP library

From Dev

Best usage of SuppressWarnings Unused in library

From Dev

String Library Usage in Yacc File

From Dev

clojure retry library perseverance usage

From Dev

Android NDK prebuild shared library usage

From Dev

Task Parallel Library - Task.Delay() usage

From Dev

What is wrong with this usage of boost regex library?

From Dev

Android iBeacon library usage outside activity

From Dev

What's wrong with this C library function usage?

From Dev

Estimating memory footprint and CPU usage for a C library

From Dev

What is correct usage of DataSource with torch/dp library

From Dev

Spring Boot library usage in plain Java project

From Dev

What's wrong with this C library function usage?

Related Related

HotTag

Archive