0

我使用 libstrophe 版本 0.8.9 来开发我的 xmpp 客户端。

这是我的 xmmp 客户端连接到服务器的 xmmp 功能

#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;
    }

我收到了这些错误

./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;

虽然这些变量存在于这个文件中https://github.com/metajack/libstrophe/blob/master/src/common.h

我的代码或 libstrophe 有什么问题?

4

1 回答 1

1

您只能使用由strophe.h. strophe.h也不包含 , 等的定义xmpp_conn_txmpp_ctx_t因此,您无法在程序中访问它们的字段。

如果 libstrophe 构建时支持 TLS(默认为 openssl),则在 xmpp 服务器支持时建立 TLS 会话。这是隐式完成的。您可以使用.conn_handler()检查连接是否安全xmpp_conn_is_secured()。或者,您可以通过在之前调用下一个函数来仅接受安全连接xmpp_connect_client()

    xmpp_conn_set_flags(conn, XMPP_CONN_FLAG_MANDATORY_TLS);

有关更多详细信息,请参阅https://github.com/strophe/libstrophe/blob/master/examples/basic.c

总之,您需要删除#if-#endif部分。如果正确构建了 libstrophe 并且 xmpp 服务器支持它,则将自动建立 TLS 会话。

PS 官方仓库移至https://github.com/strophe/libstrophe

于 2017-02-01T18:41:12.377 回答