2017-01-31 6 views
0

libstropheバージョン0.8.9を使用してxmppクライアントを開発しました。ここ openwrtのlibstropheをコンパイルしてTLSをサポートする

は私のxmmpクライアントのxmmp機能は、これらの変数は、このファイル https://github.com/metajack/libstrophe/blob/master/src/common.h

何が間違っに存在するが、私はこれらのエラー

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

を得た

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

サーバーに接続することです私のコードやlibstropheで?

答えて

1

strophe.hで提供されているAPIのみ使用できます。またstrophe.hにはxmpp_conn_t,xmpp_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セッションは自動的に確立されます。

P.S.公式のレポジトリはhttps://github.com/strophe/libstropheに移動しました。

関連する問題