0

サーバー上の他のクライアントと通信する必要があるC++XMPPクライアントを作成するタスクがあります。サーバーに新しいユーザーを登録するために、Glooxライブラリを使用して単純なC++XMPPクライアントを作成しました。私が使用しているサーバーはOpenfireで、IDEはVC++2008です。

// register_example.cpp

class RegTest : public RegistrationHandler, ConnectionListener, LogHandler

{

public:
RegTest() {}
virtual ~RegTest() {}

void start()
{
  j = new Client( "localhost" );
  j->disableRoster();
  j->registerConnectionListener( this );
  m_reg = new Registration( j );
  m_reg->registerRegistrationHandler( this );
  j->logInstance().registerLogHandler( LogLevelDebug, LogAreaAll, this );
  j->connect();
  delete( m_reg );
  delete( j );
}

virtual void onConnect()
{
 m_reg->fetchRegistrationFields();
}

virtual void onDisconnect( ConnectionError e ){ 
printf( "register_test: disconnected: %d\n", e );    }

virtual bool onTLSConnect( const CertInfo& info )
{
  printf( "status: %d\nissuer: %s\npeer: %s\nprotocol: %s\nmac: %s\ncipher: %s\ncompression: %s\n",
  info.status, info.issuer.c_str(), info.server.c_str(),
  info.protocol.c_str(), info.mac.c_str(), info.cipher.c_str(),
  info.compression.c_str() );
  return true;
}

virtual void handleRegistrationFields( const JID& /*from*/, int fields, std::string  instructions )
{
  printf( "fields: %d\ninstructions: %s\n", fields, instructions.c_str() );
  RegistrationFields vals;
  vals.username = "testuser";
  vals.password = "testpwd";
  m_reg->createAccount( fields, vals );
}

virtual void handleRegistrationResult( const JID& /*from*/, RegistrationResult result )
{
  printf( "result: %d\n", result );
  j->disconnect();
}

virtual void handleAlreadyRegistered( const JID& /*from*/ )
{
  printf( "the account already exists.\n" );
}

virtual void handleDataForm( const JID& /*from*/, const DataForm& /*form*/ )
{
  printf( "datForm received\n" );
}

virtual void handleOOB( const JID& /*from*/, const OOB& oob )
{
  printf( "OOB registration requested. %s: %s\n", oob.desc().c_str(), oob.url().c_str() );
}

virtual void handleLog( LogLevel level, LogArea area, const std::string& message )
{
  printf("log: level: %d, area: %d, %s\n", level, area, message.c_str() );
}
 private:
 Registration *m_reg;
 Client *j;
};

int _tmain(int argc, _TCHAR* argv[])
{
  RegTest *r = new RegTest();
  r->start();
  return 0;
}

コードは正常にビルドされますが、コードを実行すると、次のエラーコード400 ---BadRequestが表示されます。何が問題になっているのか教えてください。ログ-

    **log: level: 0, area: 8, This is gloox 1.0, connecting to localhost:-1...

log: level: 1, area: 32, DnsQuery_UTF8() failed: 9003
log: level: 1, area: 32, Notice: no SRV record found for localhost, using defaul
t port.
log: level: 0, area: 32, Connecting to localhost (127.0.0.1:5222)
log: level: 0, area: 32, Connected to localhost (127.0.0.1:5222)
log: level: 0, area: 262144, <?xml version='1.0' ?><stream:stream to='localhost'
 xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'  xml:lang
='en' version='1.0'>
log: level: 0, area: 131072, <stream:stream xmlns:stream='http://etherx.jabber.o
rg/streams' xmlns='jabber:client' from='ds-001d92dde38d' id='ab49a54c' xml:lang=
'en' version='1.0'/>
log: level: 0, area: 131072, <stream:features xmlns:stream='http://etherx.jabber
.org/streams'><starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/><mechanisms xml
ns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>DIGEST-MD5</mechanism><mechanis
m>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>CRAM-MD5</mechanis
m></mechanisms><compression xmlns='http://jabber.org/features/compress'><method>
zlib</method></compression><auth xmlns='http://jabber.org/features/iq-auth'/><re
gister xmlns='http://jabber.org/features/iq-register'/></stream:features>
log: level: 0, area: 262144, <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
log: level: 0, area: 131072, <proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
log: level: 0, area: 4, starting TLS handshake...
status: -842150451
issuer: CN=ds-001d92dde38d
peer: CN=ds-001d92dde38d
protocol: TLSv1
mac: SHA
cipher: AES_128
compression:
log: level: 0, area: 8, connection encryption active
log: level: 0, area: 262144, <?xml version='1.0' ?><stream:stream to='localhost'
 xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'  xml:lang
='en' version='1.0'>
log: level: 0, area: 131072, <stream:stream xmlns:stream='http://etherx.jabber.o
rg/streams' xmlns='jabber:client' from='ds-001d92dde38d' id='ab49a54c' xml:lang=
'en' version='1.0'/>
log: level: 0, area: 131072, <stream:features xmlns:stream='http://etherx.jabber
.org/streams'><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>DI
GEST-MD5</mechanism><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism>
<mechanism>CRAM-MD5</mechanism></mechanisms><compression xmlns='http://jabber.or
g/features/compress'><method>zlib</method></compression><auth xmlns='http://jabb
er.org/features/iq-auth'/><register xmlns='http://jabber.org/features/iq-registe
r'/></stream:features>
log: level: 0, area: 262144, <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mech
anism='ANONYMOUS'/>
log: level: 0, area: 131072, <success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>
log: level: 0, area: 4, SASL authentication successful
log: level: 0, area: 262144, <?xml version='1.0' ?><stream:stream to='localhost'
 xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'  xml:lang
='en' version='1.0'>
log: level: 0, area: 131072, <stream:stream xmlns:stream='http://etherx.jabber.o
rg/streams' xmlns='jabber:client' from='ds-001d92dde38d' id='ab49a54c' xml:lang=
'en' version='1.0'/>
log: level: 0, area: 131072, <stream:features xmlns:stream='http://etherx.jabber
.org/streams'><compression xmlns='http://jabber.org/features/compress'><method>z
lib</method></compression><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/><sessi
on xmlns='urn:ietf:params:xml:ns:xmpp-session'/></stream:features>
log: level: 0, area: 262144, <iq id='uid:501a3ee9:00000029' type='set' from='loc
alhost' xmlns='jabber:client'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><re
source/></bind></iq>
log: level: 0, area: 131072, <iq type='result' id='uid:501a3ee9:00000029' to='ds
-001d92dde38d/ab49a54c'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><jid>ab49
a54c@ds-001d92dde38d/ab49a54c</jid></bind></iq>
log: level: 0, area: 262144, <iq id='uid:501a3ee9:00004823' type='set' from='ab4
9a54c@ds-001d92dde38d/ab49a54c' xmlns='jabber:client'><session xmlns='urn:ietf:p
arams:xml:ns:xmpp-session'/></iq>
log: level: 0, area: 131072, <iq type='result' id='uid:501a3ee9:00004823' to='ab
49a54c@ds-001d92dde38d/ab49a54c'/>
log: level: 0, area: 262144, <presence from='ab49a54c@ds-001d92dde38d/ab49a54c'
xmlns='jabber:client'><priority>0</priority><c xmlns='http://jabber.org/protocol
/caps' hash='sha-1' node='http://camaya.net/gloox' ver='1LpOuB49QCQE6BcZoAF5tBoA
Ldg='/></presence>
log: level: 0, area: 262144, <iq id='uid:501a3ee9:000018be' type='get' from='ab4
9a54c@ds-001d92dde38d/ab49a54c' xmlns='jabber:client'><query xmlns='jabber:iq:re
gister'/></iq>
log: level: 0, area: 131072, <iq type='result' id='uid:501a3ee9:000018be' to='ab
49a54c@ds-001d92dde38d/ab49a54c'><query xmlns='jabber:iq:register'><username/><p
assword/><email/><name/><x xmlns='jabber:x:data' type='form'><title>XMPP Client
Registration</title><instructions>Please provide the following information</inst
ructions><field var='FORM_TYPE' type='hidden'><value>jabber:iq:register</value><
/field><field var='username' type='text-single' label='Username'><required/></fi
eld><field var='name' type='text-single' label='Full name'/><field var='email' t
ype='text-single' label='Email'/><field var='password' type='text-private' label
='Password'><required/></field></x></query></iq>
datForm received
fields: 77
instructions:
log: level: 0, area: 262144, <iq id='uid:501a3ee9:00006784' type='set' from='ab4
9a54c@ds-001d92dde38d/ab49a54c' xmlns='jabber:client'><query xmlns='jabber:iq:re
gister'><username>testuser</username><password>testpwd</password><name/><email/>
</query></iq>
log: level: 0, area: 131072, <iq type='error' id='uid:501a3ee9:00006784' to='ab4
9a54c@ds-001d92dde38d/ab49a54c'><query xmlns='jabber:iq:register'><username>test
user</username><password>testpwd</password><name/><email/></query><error code='4
00' type='modify'><bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></er
ror></iq>
result: 4
log: level: 0, area: 262144, </stream:stream>
register_test: disconnected: 17**
4

1 に答える 1

0

サーバーは、「jabber:iq:register」名前空間のスキーマでサポートされているよりも多くの情報を必要とするため、サーバーからデータ フォームが送信されました。「jabber:iq:register」のフィールドよりも優先される入力済みのデータ フォームを返す必要があります。これは、XEP-0077 (インバンド登録)の拡張性セクションで定義されています。

于 2012-08-03T14:06:42.310 に答える