gloox1.0中注册账号不成功的问题
前段时间研究gloox1.0版的注册,用官方自带的example,注册应该是很简单的例子,代码如下:
但是我用自带的register_example编程成功后运行,在最后一步提交注册信息后返回如下的结果:1: j = new Client( "pc-20110409pvwc" );2: j->disableRoster();3: j->registerConnectionListener( this );
4:5: m_reg = new Registration( j );
6: m_reg->registerRegistrationHandler( this );
7:8: j->logInstance().registerLogHandler( LogLevelDebug, LogAreaAll, this );
9:10: j->connect();11:12: delete( m_reg );
13: delete( j );
“bad-request”。。。仔细看返回的结果,在gloox1.0版本,在register_example运行时候,有Sasl验证过程,跟代码发现进行的是匿名验证。但是我记得在之前0.99版本都不会有验证的过程呀!于是我考虑在注册的时候像之前的版本那样禁用掉Sasl验证,禁用过程用Client::setForceNonSasl函数,代码如下:
修改后运行发现居然还要进行Sasl验证过程,单步调试发现setForceNonSasl没有起作用,找到匿名验证验证的代码处,在Client::handleNormalNode函数中,截取代码段:1: j = new Client( "pc-20110409pvwc" );2: j->disableRoster();3: j->setForceNonSasl();4: j->registerConnectionListener( this );
5:6: m_reg = new Registration( j );
7: m_reg->registerRegistrationHandler( this );
8:9: j->logInstance().registerLogHandler( LogLevelDebug, LogAreaAll, this );
10:11: j->connect();12:13: delete( m_reg );
14: delete( j );
匿名验证是在倒数第二段,于是在它的if判断语句加上检测是否禁止验证如下1: else if( !m_clientCerts.empty() && !m_clientKey.empty()2: && m_streamFeatures & SaslMechExternal && m_availableSaslMechs & SaslMechExternal )3: {4: notifyStreamEvent( StreamEventAuthentication );5: startSASL( SaslMechExternal );6: }7: #if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
8: else if( m_streamFeatures & SaslMechGssapi && m_availableSaslMechs & SaslMechGssapi )9: {10: notifyStreamEvent( StreamEventAuthentication );11: startSASL( SaslMechGssapi );12: }13: else if( m_streamFeatures & SaslMechNTLM && m_availableSaslMechs & SaslMechNTLM )14: {15: notifyStreamEvent( StreamEventAuthentication );16: startSASL( SaslMechNTLM );17: }18: #endif19: else if( m_streamFeatures & SaslMechAnonymous20: && m_availableSaslMechs & SaslMechAnonymous )21: {22: notifyStreamEvent( StreamEventAuthentication );23: startSASL( SaslMechAnonymous );24: }25: else
26: {27: notifyStreamEvent( StreamEventFinished );28: connected();29: }
else if( !m_forceNonSasl && m_streamFeatures & SaslMechAnonymous
&& m_availableSaslMechs & SaslMechAnonymous )
保存重新编译,这样就可以不用进行匿名验证,实现正常的注册了。
我对gloox1.0理解还很浅,如果哪位知道register_example为什么会运行失败的真正原因,麻烦说明一下!