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 "../client.h"
14 #include "../connectionlistener.h"
15 #include "../bookmarkhandler.h"
16 #include "../disco.h"
17 #include "../bookmarkstorage.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 BookmarkStorageTest : public BookmarkHandler, ConnectionListener
27 {
28 public:
BookmarkStorageTest()29 BookmarkStorageTest() {}
~BookmarkStorageTest()30 virtual ~BookmarkStorageTest() {}
31
start()32 void start()
33 {
34
35 JID jid( "hurkhurk@example.org/gloox" );
36 j = new Client( jid, "hurkhurks" );
37
38 j->registerConnectionListener(this );
39 j->disco()->setVersion( "bookmarkTest", GLOOX_VERSION );
40 j->disco()->setIdentity( "client", "bot" );
41
42 b = new BookmarkStorage( j );
43 b->registerBookmarkHandler( this );
44
45 j->connect();
46
47 delete( b );
48 delete( j );
49 }
50
onConnect()51 virtual void onConnect()
52 {
53 b->requestBookmarks();
54 }
55
onDisconnect(ConnectionError)56 virtual void onDisconnect( ConnectionError /*e*/ ) { printf( "disco_test: disconnected\n" ); }
57
onTLSConnect(const CertInfo & info)58 virtual bool onTLSConnect( const CertInfo& info )
59 {
60 time_t from( info.date_from );
61 time_t to( info.date_to );
62
63 printf( "status: %d\nissuer: %s\npeer: %s\nprotocol: %s\nmac: %s\ncipher: %s\ncompression: %s\n",
64 info.status, info.issuer.c_str(), info.server.c_str(),
65 info.protocol.c_str(), info.mac.c_str(), info.cipher.c_str(),
66 info.compression.c_str() );
67 printf( "from: %s", ctime( &from ) );
68 printf( "to: %s", ctime( &to ) );
69 return true;
70 }
71
handleBookmarks(const BookmarkList & bList,const ConferenceList & cList)72 virtual void handleBookmarks( const BookmarkList &bList, const ConferenceList &cList )
73 {
74 printf( "received bookmarks...\n" );
75
76 BookmarkList::const_iterator it_b = bList.begin();
77 for( ; it_b != bList.end(); it_b++ )
78 {
79 printf( "url: %s, name: %s\n", (*it_b).url.c_str(), (*it_b).name.c_str() );
80 }
81 ConferenceList::const_iterator it_c = cList.begin();
82 for( ; it_c != cList.end(); it_c++ )
83 {
84 printf( "jid: %s, name: %s, nick: %s, pwd: %s\n", (*it_c).jid.c_str(), (*it_c).name.c_str(),
85 (*it_c).nick.c_str(), (*it_c).password.c_str() );
86 }
87
88 BookmarkList mybList;
89 ConferenceList mycList;
90
91 BookmarkListItem bItem;
92 bItem.url = "http://camaya.net/gloox";
93 bItem.name = "gloox";
94 mybList.push_back( bItem );
95
96 bItem.url = "http://jabber.cc";
97 bItem.name = "public jabber services";
98 mybList.push_back( bItem );
99
100 ConferenceListItem cItem;
101 cItem.jid = "jdev@conference.jabber.org";
102 cItem.name = "jabber development";
103 cItem.nick = "myNick";
104 cItem.autojoin = false;
105 mycList.push_back( cItem );
106
107 cItem.jid = "jabberd@conference.jabber.org";
108 cItem.name = "jabberd development";
109 cItem.nick = "myOtherNick";
110 cItem.password = "my password";
111 cItem.autojoin = true;
112 mycList.push_back( cItem );
113
114 b->storeBookmarks( mybList, mycList );
115 }
116
117 private:
118 Client *j;
119 BookmarkStorage *b;
120 };
121
main(int,char **)122 int main( int /*argc*/, char** /*argv*/ )
123 {
124 BookmarkStorageTest *t = new BookmarkStorageTest();
125 t->start();
126 delete( t );
127 return 0;
128 }
129