1 /*
2  *  Copyright (c) 2004-2019 by Jakob Schröter <js@camaya.net>
3  *  This file is part of the gloox library. http://camaya.net/gloox
4  *
5  *  This software is distributed under a license. The full license
6  *  agreement can be found in the file LICENSE in this distribution.
7  *  This software may not be copied, modified, sold or distributed
8  *  other than expressed in the named license agreement.
9  *
10  *  This software is distributed without any warranty.
11  */
12 
13 #include "../component.h"
14 #include "../connectionlistener.h"
15 #include "../loghandler.h"
16 #include "../discohandler.h"
17 #include "../disco.h"
18 using namespace gloox;
19 
20 #include <ctime>
21 #include <clocale>
22 #include <string>
23 
24 #include <cstdio> // [s]print[f]
25 
26 class ComponentTest : public DiscoHandler, ConnectionListener, LogHandler
27 {
28   public:
ComponentTest()29     ComponentTest() {}
~ComponentTest()30     virtual ~ComponentTest() {}
31 
start()32     void start()
33     {
34 
35       j = new Component( XMLNS_COMPONENT_ACCEPT, "example.org",
36                          "component.example.org", "secret", 5000 );
37       j->disco()->setVersion( "componentTest", GLOOX_VERSION );
38 
39       j->registerConnectionListener( this );
40       j->logInstance().registerLogHandler( LogLevelDebug, LogAreaAll, this );
41 
42       j->connect();
43 
44       delete( j );
45     }
46 
onConnect()47     virtual void onConnect()
48     {
49       printf( "connected -- disconnecting...\n" );
50 //       j->disconnect( STATE_DISCONNECTED );
51     }
52 
onDisconnect(ConnectionError)53     virtual void onDisconnect( ConnectionError /*e*/ ) { printf( "component: disconnected\n" ); }
54 
onTLSConnect(const CertInfo & info)55     virtual bool onTLSConnect( const CertInfo& info )
56     {
57       time_t from( info.date_from );
58       time_t to( info.date_to );
59 
60       printf( "status: %d\nissuer: %s\npeer: %s\nprotocol: %s\nmac: %s\ncipher: %s\ncompression: %s\n",
61               info.status, info.issuer.c_str(), info.server.c_str(),
62               info.protocol.c_str(), info.mac.c_str(), info.cipher.c_str(),
63               info.compression.c_str() );
64       printf( "from: %s", ctime( &from ) );
65       printf( "to:   %s", ctime( &to ) );
66       return true;
67     }
68 
handleDiscoInfo(const JID &,const Disco::Info &,int)69     virtual void handleDiscoInfo( const JID& /*iq*/, const Disco::Info&, int /*context*/ )
70     {
71       printf( "handleDiscoInfoResult}\n" );
72     }
73 
handleDiscoItems(const JID &,const Disco::Items &,int)74     virtual void handleDiscoItems( const JID& /*iq*/, const Disco::Items&, int /*context*/ )
75     {
76       printf( "handleDiscoItemsResult\n" );
77     }
78 
handleDiscoError(const JID &,const Error *,int)79     virtual void handleDiscoError( const JID& /*iq*/, const Error*, int /*context*/ )
80     {
81       printf( "handleDiscoError\n" );
82     }
83 
handleLog(LogLevel level,LogArea area,const std::string & message)84     virtual void handleLog( LogLevel level, LogArea area, const std::string& message )
85     {
86       printf("log: level: %d, area: %d, %s\n", level, area, message.c_str() );
87     }
88 
89   private:
90     Component *j;
91 };
92 
main(int,char **)93 int main( int /*argc*/, char** /*argv*/ )
94 {
95   ComponentTest *r = new ComponentTest();
96   r->start();
97   delete( r );
98   return 0;
99 }
100