I use the libstrophe version 0.8.9 to develop my xmpp client.
here is the xmmp function of my xmmp client to connect to the server
#include <strophe.h>
int xmpp_connect(void)
{
xmpp_ctx_t *ctx;
xmpp_conn_t *conn;
xmpp_log_t *log;
int sta;
static int retry = 0;
xmpp_initialize();
log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG);
ctx = xmpp_ctx_new(NULL, log);
conn = xmpp_conn_new(ctx);
xmpp_conn_set_jid(conn, cur_xmmp_con.jid);
xmpp_conn_set_pass(conn, cur_xmmp_con.password);
#if 1
if (!tls_start(conn->tls))
{
xmpp_debug(conn->ctx, "xmpp", "Couldn't start TLS! error %d", tls_error(conn->tls));
tls_free(conn->tls);
conn->tls = NULL;
conn->tls_failed = 1;
/* failed tls spoils the connection, so disconnect */
xmpp_disconnect(conn);
}
else
{
conn->secured = 1;
conn_prepare_reset(conn, NULL);
conn_open_stream(conn);
}
#endif
//
sta = xmpp_connect_client(conn, NULL, 0, conn_handler, ctx);
xmpp_run(ctx);
return 0;
}
I got these error
./src/test_xmpp.c:62:21: error: dereferencing pointer to incomplete type
if (!tls_start(conn->tls))
^
../src/test_xmpp.c:64:18: error: dereferencing pointer to incomplete type
xmpp_debug(conn->ctx, "xmpp", "Couldn't start TLS! error %d", tls_error(conn->tls));
^
../src/test_xmpp.c:64:79: error: dereferencing pointer to incomplete type
xmpp_debug(conn->ctx, "xmpp", "Couldn't start TLS! error %d", tls_error(conn->tls));
^
../src/test_xmpp.c:65:16: error: dereferencing pointer to incomplete type
tls_free(conn->tls);
^
../src/test_xmpp.c:66:7: error: dereferencing pointer to incomplete type
conn->tls = NULL;
^
../src/test_xmpp.c:67:7: error: dereferencing pointer to incomplete type
conn->tls_failed = 1;
^
../src/test_xmpp.c:73:7: error: dereferencing pointer to incomplete type
conn->secured = 1;
although these variables exist in this file https://github.com/metajack/libstrophe/blob/master/src/common.h
what wrong with my code or the libstrophe ?
You can use only API provided by
strophe.h
. Alsostrophe.h
doesn't contain definitions forxmpp_conn_t
,xmpp_ctx_t
, etc. Therefore, you cannot access their fields in your program.If libstrophe is built with TLS support (openssl by default), TLS session is established when xmpp server supports it. This is done implicitly. In
conn_handler()
you can check whether connection is secured or not withxmpp_conn_is_secured()
. Or you can accept only secured connections by calling the next function beforexmpp_connect_client()
:See https://github.com/strophe/libstrophe/blob/master/examples/basic.c for more details.
In conclusion, you need to remove
#if-#endif
section. TLS session will be established automatically if libstrophe is built properly and xmpp server supports it.P.S. Official repository is moved to https://github.com/strophe/libstrophe.