天天看點

gloox不能注冊新使用者的問題

經過測試,發現gloox 0.8版自帶的測試程式register_test.cpp,是沒有辦法注冊新使用者的

前面的三步是這樣沒錯

Client->Server 001

<?xml version='1.0' ?>

<stream:stream to='jabber.org

xmlns='jabber:client'

xmlns:stream='http://etherx.jabber.org/streams'

xml:

version='1.0'>

用戶端向伺服器建立連接配接,version='1.0'代表用戶端的所用的XMPP的版本,沒有表示是0.x版,o.x版與1.0版的驗證方式不同

S->C 002

<?xml version='1.0'?>

<stream:stream xmlns:stream='http://etherx.jabber.org/streams'

xmlns='jabber:client'from='jabber.org'

version='1.0'

id='7mh6bxa8x95js1ubvkxyupysze2xpz6jhxtrzzpq'>

伺服器響應連接配接

S->C 003

<stream:features xmlns:stream='http://etherx.jabber.org/streams'>

<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>

    <mechanism>DIGEST-MD5</mechanism>

    <mechanism>PLAIN</mechanism>

</mechanisms>

</stream:features>

伺服器傳回支援的驗證方式

第四步應該就是發送注冊新使用者的請求了,但應際上,它還是發登入驗證,未注冊的當然就驗證不通過,連接配接也就斷開了

我改了一些代碼,讓注冊可以實作

1. 繼承Client類,重載了handleNormalNode函數

class RegisterClient : public Client

{

    public:

    RegisterClient( const JID& jid, const std::string& password, int port = -1 ):

    Client(jid,password,port)

    {

    }

  bool RegisterClient::handleNormalNode( Stanza *stanza )

  {

    if( stanza->name() == "stream:features" )

    {

        //fastxyf modify

        notifyOnConnect();

        return true;

    };

    return false;

  };

};

2. 将RegTest類中star函數中的

  j = new Client( jid, szPassword );

改為:

  j = new RegisterClient( jid, szPassword );

這樣就可以注試通過了

新注冊的使用者名,密碼是在handleRegistrationFields函數中指定的