disco_example.cpp

来自「Jabber code library, developed with c」· C++ 代码 · 共 86 行

CPP
86
字号
#include "../client.h"#include "../connectionlistener.h"#include "../discohandler.h"#include "../disco.h"#include "../stanza.h"#include "../gloox.h"#include "../loghandler.h"using namespace gloox;#include <stdio.h>#include <locale.h>#include <string>class DiscoTest : public DiscoHandler, ConnectionListener, LogHandler{  public:    DiscoTest() {}    virtual ~DiscoTest() {}    void start()    {      JID jid( "hurkhurk@example.org/gloox" );      j = new Client( jid, "hurkhurks" );      j->disableRoster();      j->registerConnectionListener( this );      j->disco()->registerDiscoHandler( this );      j->disco()->setVersion( "discoTest", GLOOX_VERSION, "linux" );      j->disco()->setIdentity( "client", "bot" );      StringList ca;      ca.push_back( "/path/to/cacert.crt" );      j->setCACerts( ca );      j->logInstance().registerLogHandler( LogLevelDebug, LogAreaAll, this );      j->connect();      delete( j );    }    virtual void onConnect()    {    }    virtual void onDisconnect( ConnectionError e ) { printf( "disco_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 handleDiscoInfoResult( Stanza */*stanza*/, int /*context*/ )    {      printf( "handleDiscoInfoResult}\n" );    }    virtual void handleDiscoItemsResult( Stanza */*stanza*/, int /*context*/ )    {      printf( "handleDiscoItemsResult\n" );    }    virtual void handleDiscoError( Stanza */*stanza*/, int /*context*/ )    {      printf( "handleDiscoError\n" );    }    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:    Client *j;};int main( int /*argc*/, char** /*argv*/ ){  DiscoTest *r = new DiscoTest();  r->start();  delete( r );  return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?