diff options
Diffstat (limited to 'Slimber')
33 files changed, 1508 insertions, 1496 deletions
diff --git a/Slimber/CLI/DummyMenulet.cpp b/Slimber/CLI/DummyMenulet.cpp index 25f28e5..78c6ddf 100644 --- a/Slimber/CLI/DummyMenulet.cpp +++ b/Slimber/CLI/DummyMenulet.cpp @@ -1,8 +1,7 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include "Slimber/CLI/DummyMenulet.h" - +#include <Slimber/CLI/DummyMenulet.h> diff --git a/Slimber/CLI/DummyMenulet.h b/Slimber/CLI/DummyMenulet.h index ec1c7ca..4b37df6 100644 --- a/Slimber/CLI/DummyMenulet.h +++ b/Slimber/CLI/DummyMenulet.h @@ -1,36 +1,36 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include "Slimber/Menulet.h" +#include <Slimber/Menulet.h> class DummyMenulet : public Menulet { - public: - DummyMenulet() { - } + public: + DummyMenulet() { + } - void clear() { - } + void clear() { + } - void addItem(const std::string&, const std::string&) { - } + void addItem(const std::string&, const std::string&) { + } - void addAboutItem() { - } + void addAboutItem() { + } - void addRestartItem() { - } + void addRestartItem() { + } - void addExitItem() { - } + void addExitItem() { + } - void addSeparator() { - } + void addSeparator() { + } - void setIcon(const std::string&) { - } + void setIcon(const std::string&) { + } }; diff --git a/Slimber/CLI/SConscript b/Slimber/CLI/SConscript index e17996d..9dfa174 100644 --- a/Slimber/CLI/SConscript +++ b/Slimber/CLI/SConscript @@ -8,6 +8,6 @@ myenv.UseFlags(env["SWIFTEN_FLAGS"]) myenv.UseFlags(env["SWIFTEN_DEP_FLAGS"]) myenv.Program("slimber", [ - "main.cpp", - "DummyMenulet.cpp", - ]) + "main.cpp", + "DummyMenulet.cpp", + ]) diff --git a/Slimber/CLI/main.cpp b/Slimber/CLI/main.cpp index 6f55301..26f88d0 100644 --- a/Slimber/CLI/main.cpp +++ b/Slimber/CLI/main.cpp @@ -1,21 +1,22 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Swiften/EventLoop/SimpleEventLoop.h> -#include "Slimber/CLI/DummyMenulet.h" -#include "Slimber/MainController.h" + +#include <Slimber/CLI/DummyMenulet.h> +#include <Slimber/MainController.h> using namespace Swift; int main() { - SimpleEventLoop eventLoop; - - DummyMenulet menulet; - MainController controller(&menulet, &eventLoop); + SimpleEventLoop eventLoop; + + DummyMenulet menulet; + MainController controller(&menulet, &eventLoop); - eventLoop.run(); - return 0; + eventLoop.run(); + return 0; } diff --git a/Slimber/Cocoa/CocoaController.mm b/Slimber/Cocoa/CocoaController.mm index da1df98..7d17948 100644 --- a/Slimber/Cocoa/CocoaController.mm +++ b/Slimber/Cocoa/CocoaController.mm @@ -1,29 +1,29 @@ /* - * Copyright (c) 2015 Isode Limited. + * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <Slimber/Cocoa/CocoaController.h> -#include <Slimber/MainController.h> #include <Slimber/Cocoa/CocoaMenulet.h> #include <Slimber/Cocoa/main.h> +#include <Slimber/MainController.h> @implementation CocoaController { - CocoaMenulet* menulet; - MainController* main; + CocoaMenulet* menulet; + MainController* main; } - (void) dealloc { - delete main; - delete menulet; - [super dealloc]; + delete main; + delete menulet; + [super dealloc]; } - (void) awakeFromNib { - menulet = new CocoaMenulet(); - main = new MainController(menulet, eventLoop); + menulet = new CocoaMenulet(); + main = new MainController(menulet, eventLoop); } @end diff --git a/Slimber/Cocoa/CocoaMenulet.h b/Slimber/Cocoa/CocoaMenulet.h index 887fdf9..0dc06f5 100644 --- a/Slimber/Cocoa/CocoaMenulet.h +++ b/Slimber/Cocoa/CocoaMenulet.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -7,26 +7,27 @@ #pragma once #include <Cocoa/Cocoa.h> + #include <Slimber/Menulet.h> #include <SwifTools/Cocoa/CocoaAction.h> class CocoaMenulet : public Menulet { - public: - CocoaMenulet(); - virtual ~CocoaMenulet(); - - private: - virtual void clear(); - virtual void addItem(const std::string& name, const std::string& icon); - virtual void addSeparator(); - void setIcon(const std::string& icon); - virtual void addAboutItem(); - virtual void addRestartItem(); - virtual void addExitItem(); - - private: - NSStatusItem* statusItem; - NSMenu* menu; - CocoaAction* restartAction; + public: + CocoaMenulet(); + virtual ~CocoaMenulet(); + + private: + virtual void clear(); + virtual void addItem(const std::string& name, const std::string& icon); + virtual void addSeparator(); + void setIcon(const std::string& icon); + virtual void addAboutItem(); + virtual void addRestartItem(); + virtual void addExitItem(); + + private: + NSStatusItem* statusItem; + NSMenu* menu; + CocoaAction* restartAction; }; diff --git a/Slimber/Cocoa/CocoaMenulet.mm b/Slimber/Cocoa/CocoaMenulet.mm index 6013b05..a05843e 100644 --- a/Slimber/Cocoa/CocoaMenulet.mm +++ b/Slimber/Cocoa/CocoaMenulet.mm @@ -1,85 +1,82 @@ /* - * Copyright (c) 2012-2013 Isode Limited. + * Copyright (c) 2012-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include "Slimber/Cocoa/CocoaMenulet.h" - -#pragma GCC diagnostic ignored "-Wold-style-cast" +#include <Slimber/Cocoa/CocoaMenulet.h> #include <boost/function.hpp> +#include <SwifTools/Cocoa/CocoaUtil.h> + CocoaMenulet::CocoaMenulet() { - restartAction = [[CocoaAction alloc] initWithFunction: - new boost::function<void()>(boost::ref(onRestartClicked))]; - menu = [[NSMenu alloc] init]; + restartAction = [[CocoaAction alloc] initWithFunction: + new boost::function<void()>(boost::ref(onRestartClicked))]; + menu = [[NSMenu alloc] init]; - statusItem = [[[NSStatusBar systemStatusBar] - statusItemWithLength: NSVariableStatusItemLength] retain]; - [statusItem setHighlightMode: YES]; - [statusItem setEnabled: YES]; - [statusItem setToolTip: @"Slimber"]; - [statusItem setMenu: menu]; + statusItem = [[[NSStatusBar systemStatusBar] + statusItemWithLength: NSVariableStatusItemLength] retain]; + [statusItem setHighlightMode: YES]; + [statusItem setEnabled: YES]; + [statusItem setToolTip: @"Slimber"]; + [statusItem setMenu: menu]; } CocoaMenulet::~CocoaMenulet() { - [statusItem release]; - [menu release]; - [restartAction release]; + [statusItem release]; + [menu release]; + [restartAction release]; } void CocoaMenulet::setIcon(const std::string& icon) { - NSString* path = [[NSBundle mainBundle] pathForResource: - [NSString stringWithUTF8String: icon.c_str()] ofType:@"png"]; - NSImage* image = [[NSImage alloc] initWithContentsOfFile: path]; - [statusItem setImage: image]; - [image release]; + NSString* path = [[NSBundle mainBundle] pathForResource: std2NSString(icon) ofType:@"png"]; + NSImage* image = [[NSImage alloc] initWithContentsOfFile: path]; + [statusItem setImage: image]; + [image release]; } void CocoaMenulet::clear() { - while ([menu numberOfItems] > 0) { - [menu removeItemAtIndex: 0]; - } + while ([menu numberOfItems] > 0) { + [menu removeItemAtIndex: 0]; + } } void CocoaMenulet::addItem(const std::string& name, const std::string& icon) { - NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: - [NSString stringWithUTF8String: name.c_str()] - action: NULL keyEquivalent: @""]; - if (!icon.empty()) { - NSString* path = [[NSBundle mainBundle] pathForResource: - [NSString stringWithUTF8String: icon.c_str()] ofType:@"png"]; - NSImage* image = [[NSImage alloc] initWithContentsOfFile: path]; - [item setImage: image]; - [image release]; - } - [menu addItem: item]; - [item release]; + NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: std2NSString(name) + action: nullptr keyEquivalent: @""]; + if (!icon.empty()) { + NSString* path = [[NSBundle mainBundle] pathForResource: std2NSString(icon) ofType:@"png"]; + NSImage* image = [[NSImage alloc] initWithContentsOfFile: path]; + [item setImage: image]; + [image release]; + } + [menu addItem: item]; + [item release]; } void CocoaMenulet::addAboutItem() { - NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"About Slimber" action: @selector(orderFrontStandardAboutPanel:) keyEquivalent: @""]; - [item setTarget: [NSApplication sharedApplication]]; - [menu addItem: item]; - [item release]; + NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"About Slimber" action: @selector(orderFrontStandardAboutPanel:) keyEquivalent: @""]; + [item setTarget: [NSApplication sharedApplication]]; + [menu addItem: item]; + [item release]; } void CocoaMenulet::addRestartItem() { - NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: - @"Restart" action: @selector(doAction:) keyEquivalent: @""]; - [item setTarget: restartAction]; - [menu addItem: item]; - [item release]; + NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: + @"Restart" action: @selector(doAction:) keyEquivalent: @""]; + [item setTarget: restartAction]; + [menu addItem: item]; + [item release]; } void CocoaMenulet::addExitItem() { - NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"Exit" action: @selector(terminate:) keyEquivalent: @""]; - [item setTarget: [NSApplication sharedApplication]]; - [menu addItem: item]; - [item release]; + NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"Exit" action: @selector(terminate:) keyEquivalent: @""]; + [item setTarget: [NSApplication sharedApplication]]; + [menu addItem: item]; + [item release]; } void CocoaMenulet::addSeparator() { - [menu addItem: [NSMenuItem separatorItem]]; + [menu addItem: [NSMenuItem separatorItem]]; } diff --git a/Slimber/Cocoa/SConscript b/Slimber/Cocoa/SConscript index 441dc27..8f3c104 100644 --- a/Slimber/Cocoa/SConscript +++ b/Slimber/Cocoa/SConscript @@ -8,22 +8,22 @@ myenv.MergeFlags(env["SWIFTEN_FLAGS"]) myenv.MergeFlags(env["SWIFTEN_DEP_FLAGS"]) myenv.Program("Slimber", [ - "main.mm", - "CocoaController.mm", - "CocoaMenulet.mm", - ]) + "main.mm", + "CocoaController.mm", + "CocoaMenulet.mm", + ]) myenv.Nib("MainMenu") myenv.AppBundle("Slimber", resources = { "": [ - "MainMenu.nib", - "../Resources/Slimber.icns", - "../Resources/Credits.html", - "../Resources/Online.png", - "../Resources/Offline.png", - "../Resources/UsersOnline.png", - "../Resources/UsersOffline.png" - ]}, info = { - "NSMainNibFile" : "MainMenu", - "LSUIElement" : "1", - }) + "MainMenu.nib", + "../Resources/Slimber.icns", + "../Resources/Credits.html", + "../Resources/Online.png", + "../Resources/Offline.png", + "../Resources/UsersOnline.png", + "../Resources/UsersOffline.png" + ]}, info = { + "NSMainNibFile" : "MainMenu", + "LSUIElement" : "1", + }) diff --git a/Slimber/Cocoa/main.mm b/Slimber/Cocoa/main.mm index 167c1ab..c5495af 100644 --- a/Slimber/Cocoa/main.mm +++ b/Slimber/Cocoa/main.mm @@ -1,13 +1,20 @@ +/* + * Copyright (c) 2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Slimber/Cocoa/main.h> + #include <Cocoa/Cocoa.h> -#include "Slimber/Cocoa/main.h" #include <Swiften/EventLoop/Cocoa/CocoaEventLoop.h> Swift::CocoaEventLoop* eventLoop; int main(int argc, char *argv[]) { - eventLoop = new Swift::CocoaEventLoop(); - int result = NSApplicationMain(argc, const_cast<const char **>(argv)); - delete eventLoop; - return result; + eventLoop = new Swift::CocoaEventLoop(); + int result = NSApplicationMain(argc, const_cast<const char **>(argv)); + delete eventLoop; + return result; } diff --git a/Slimber/FileVCardCollection.cpp b/Slimber/FileVCardCollection.cpp index f3a6aa3..ff2edc4 100644 --- a/Slimber/FileVCardCollection.cpp +++ b/Slimber/FileVCardCollection.cpp @@ -1,44 +1,45 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include "Slimber/FileVCardCollection.h" +#include <Slimber/FileVCardCollection.h> + +#include <memory> -#include <boost/smart_ptr/make_shared.hpp> #include <boost/filesystem/fstream.hpp> #include <Swiften/Base/ByteArray.h> #include <Swiften/Elements/VCard.h> -#include <Swiften/Serializer/PayloadSerializers/VCardSerializer.h> #include <Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h> #include <Swiften/Parser/PayloadParsers/VCardParser.h> +#include <Swiften/Serializer/PayloadSerializers/VCardSerializer.h> namespace Swift { FileVCardCollection::FileVCardCollection(boost::filesystem::path dir) : vcardsPath(dir) { } -boost::shared_ptr<VCard> FileVCardCollection::getOwnVCard() const { - if (boost::filesystem::exists(vcardsPath / std::string("vcard.xml"))) { - ByteArray data; - readByteArrayFromFile(data, boost::filesystem::path(vcardsPath / std::string("vcard.xml")).string()); - - VCardParser parser; - PayloadParserTester tester(&parser); - tester.parse(byteArrayToString(data)); - return boost::dynamic_pointer_cast<VCard>(parser.getPayload()); - } - else { - return boost::make_shared<VCard>(); - } +std::shared_ptr<VCard> FileVCardCollection::getOwnVCard() const { + if (boost::filesystem::exists(vcardsPath / std::string("vcard.xml"))) { + ByteArray data; + readByteArrayFromFile(data, boost::filesystem::path(vcardsPath / std::string("vcard.xml")).string()); + + VCardParser parser; + PayloadParserTester tester(&parser); + tester.parse(byteArrayToString(data)); + return std::dynamic_pointer_cast<VCard>(parser.getPayload()); + } + else { + return std::make_shared<VCard>(); + } } -void FileVCardCollection::setOwnVCard(boost::shared_ptr<VCard> v) { - boost::filesystem::ofstream file(vcardsPath / std::string("vcard.xml")); - file << VCardSerializer().serializePayload(v); - file.close(); +void FileVCardCollection::setOwnVCard(std::shared_ptr<VCard> v) { + boost::filesystem::ofstream file(vcardsPath / std::string("vcard.xml")); + file << VCardSerializer().serializePayload(v); + file.close(); } } diff --git a/Slimber/FileVCardCollection.h b/Slimber/FileVCardCollection.h index 6d8f5e9..ff4a91b 100644 --- a/Slimber/FileVCardCollection.h +++ b/Slimber/FileVCardCollection.h @@ -1,25 +1,26 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> + #include <boost/filesystem.hpp> -#include "Slimber/VCardCollection.h" +#include <Slimber/VCardCollection.h> namespace Swift { - class FileVCardCollection : public VCardCollection { - public: - FileVCardCollection(boost::filesystem::path dir); + class FileVCardCollection : public VCardCollection { + public: + FileVCardCollection(boost::filesystem::path dir); - boost::shared_ptr<VCard> getOwnVCard() const; - void setOwnVCard(boost::shared_ptr<VCard> vcard); + std::shared_ptr<VCard> getOwnVCard() const; + void setOwnVCard(std::shared_ptr<VCard> vcard); - private: - boost::filesystem::path vcardsPath; - }; + private: + boost::filesystem::path vcardsPath; + }; } diff --git a/Slimber/LinkLocalPresenceManager.cpp b/Slimber/LinkLocalPresenceManager.cpp index 7e75a05..ec5f2cd 100644 --- a/Slimber/LinkLocalPresenceManager.cpp +++ b/Slimber/LinkLocalPresenceManager.cpp @@ -1,109 +1,108 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include "Slimber/LinkLocalPresenceManager.h" +#include <Slimber/LinkLocalPresenceManager.h> #include <boost/bind.hpp> -#include <Swiften/Base/foreach.h> -#include <Swiften/LinkLocal/LinkLocalServiceBrowser.h> -#include <Swiften/Elements/RosterPayload.h> #include <Swiften/Elements/Presence.h> +#include <Swiften/Elements/RosterPayload.h> +#include <Swiften/LinkLocal/LinkLocalServiceBrowser.h> namespace Swift { LinkLocalPresenceManager::LinkLocalPresenceManager(LinkLocalServiceBrowser* browser) : browser(browser) { - browser->onServiceAdded.connect( - boost::bind(&LinkLocalPresenceManager::handleServiceAdded, this, _1)); - browser->onServiceChanged.connect( - boost::bind(&LinkLocalPresenceManager::handleServiceChanged, this, _1)); - browser->onServiceRemoved.connect( - boost::bind(&LinkLocalPresenceManager::handleServiceRemoved, this, _1)); + browser->onServiceAdded.connect( + boost::bind(&LinkLocalPresenceManager::handleServiceAdded, this, _1)); + browser->onServiceChanged.connect( + boost::bind(&LinkLocalPresenceManager::handleServiceChanged, this, _1)); + browser->onServiceRemoved.connect( + boost::bind(&LinkLocalPresenceManager::handleServiceRemoved, this, _1)); } boost::optional<LinkLocalService> LinkLocalPresenceManager::getServiceForJID(const JID& j) const { - foreach(const LinkLocalService& service, browser->getServices()) { - if (service.getJID() == j) { - return service; - } - } - return boost::optional<LinkLocalService>(); + for (const auto& service : browser->getServices()) { + if (service.getJID() == j) { + return service; + } + } + return boost::optional<LinkLocalService>(); } void LinkLocalPresenceManager::handleServiceAdded(const LinkLocalService& service) { - boost::shared_ptr<RosterPayload> roster(new RosterPayload()); - roster->addItem(getRosterItem(service)); - onRosterChanged(roster); - onPresenceChanged(getPresence(service)); + std::shared_ptr<RosterPayload> roster(new RosterPayload()); + roster->addItem(getRosterItem(service)); + onRosterChanged(roster); + onPresenceChanged(getPresence(service)); } void LinkLocalPresenceManager::handleServiceChanged(const LinkLocalService& service) { - onPresenceChanged(getPresence(service)); + onPresenceChanged(getPresence(service)); } void LinkLocalPresenceManager::handleServiceRemoved(const LinkLocalService& service) { - boost::shared_ptr<RosterPayload> roster(new RosterPayload()); - roster->addItem(RosterItemPayload(service.getJID(), "", RosterItemPayload::Remove)); - onRosterChanged(roster); + std::shared_ptr<RosterPayload> roster(new RosterPayload()); + roster->addItem(RosterItemPayload(service.getJID(), "", RosterItemPayload::Remove)); + onRosterChanged(roster); } -boost::shared_ptr<RosterPayload> LinkLocalPresenceManager::getRoster() const { - boost::shared_ptr<RosterPayload> roster(new RosterPayload()); - foreach(const LinkLocalService& service, browser->getServices()) { - roster->addItem(getRosterItem(service)); - } - return roster; +std::shared_ptr<RosterPayload> LinkLocalPresenceManager::getRoster() const { + std::shared_ptr<RosterPayload> roster(new RosterPayload()); + for (const auto& service : browser->getServices()) { + roster->addItem(getRosterItem(service)); + } + return roster; } -std::vector<boost::shared_ptr<Presence> > LinkLocalPresenceManager::getAllPresence() const { - std::vector<boost::shared_ptr<Presence> > result; - foreach(const LinkLocalService& service, browser->getServices()) { - result.push_back(getPresence(service)); - } - return result; +std::vector<std::shared_ptr<Presence> > LinkLocalPresenceManager::getAllPresence() const { + std::vector<std::shared_ptr<Presence> > result; + for (const auto& service : browser->getServices()) { + result.push_back(getPresence(service)); + } + return result; } RosterItemPayload LinkLocalPresenceManager::getRosterItem(const LinkLocalService& service) const { - return RosterItemPayload(service.getJID(), getRosterName(service), RosterItemPayload::Both); + return RosterItemPayload(service.getJID(), getRosterName(service), RosterItemPayload::Both); } std::string LinkLocalPresenceManager::getRosterName(const LinkLocalService& service) const { - LinkLocalServiceInfo info = service.getInfo(); - if (!info.getNick().empty()) { - return info.getNick(); - } - else if (!info.getFirstName().empty()) { - std::string result = info.getFirstName(); - if (!info.getLastName().empty()) { - result += " " + info.getLastName(); - } - return result; - } - else if (!info.getLastName().empty()) { - return info.getLastName(); - } - return ""; + LinkLocalServiceInfo info = service.getInfo(); + if (!info.getNick().empty()) { + return info.getNick(); + } + else if (!info.getFirstName().empty()) { + std::string result = info.getFirstName(); + if (!info.getLastName().empty()) { + result += " " + info.getLastName(); + } + return result; + } + else if (!info.getLastName().empty()) { + return info.getLastName(); + } + return ""; } -boost::shared_ptr<Presence> LinkLocalPresenceManager::getPresence(const LinkLocalService& service) const { - boost::shared_ptr<Presence> presence(new Presence()); - presence->setFrom(service.getJID()); - switch (service.getInfo().getStatus()) { - case LinkLocalServiceInfo::Available: - presence->setShow(StatusShow::Online); - break; - case LinkLocalServiceInfo::Away: - presence->setShow(StatusShow::Away); - break; - case LinkLocalServiceInfo::DND: - presence->setShow(StatusShow::DND); - break; - } - presence->setStatus(service.getInfo().getMessage()); - return presence; +std::shared_ptr<Presence> LinkLocalPresenceManager::getPresence(const LinkLocalService& service) const { + std::shared_ptr<Presence> presence(new Presence()); + presence->setFrom(service.getJID()); + switch (service.getInfo().getStatus()) { + case LinkLocalServiceInfo::Available: + presence->setShow(StatusShow::Online); + break; + case LinkLocalServiceInfo::Away: + presence->setShow(StatusShow::Away); + break; + case LinkLocalServiceInfo::DND: + presence->setShow(StatusShow::DND); + break; + } + presence->setStatus(service.getInfo().getMessage()); + return presence; } } diff --git a/Slimber/LinkLocalPresenceManager.h b/Slimber/LinkLocalPresenceManager.h index 3738319..c3e7ddc 100644 --- a/Slimber/LinkLocalPresenceManager.h +++ b/Slimber/LinkLocalPresenceManager.h @@ -1,46 +1,47 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> -#include <Swiften/Base/boost_bsignals.h> +#include <memory> +#include <string> + +#include <boost/signals2.hpp> #include <Swiften/Elements/RosterItemPayload.h> -#include <string> #include <Swiften/JID/JID.h> namespace Swift { - class LinkLocalService; - class LinkLocalServiceBrowser; - class RosterPayload; - class Presence; + class LinkLocalService; + class LinkLocalServiceBrowser; + class RosterPayload; + class Presence; - class LinkLocalPresenceManager : public boost::bsignals::trackable { - public: - LinkLocalPresenceManager(LinkLocalServiceBrowser*); + class LinkLocalPresenceManager : public boost::signals2::trackable { + public: + LinkLocalPresenceManager(LinkLocalServiceBrowser*); - boost::shared_ptr<RosterPayload> getRoster() const; - std::vector<boost::shared_ptr<Presence> > getAllPresence() const; + std::shared_ptr<RosterPayload> getRoster() const; + std::vector<std::shared_ptr<Presence> > getAllPresence() const; - boost::optional<LinkLocalService> getServiceForJID(const JID&) const; + boost::optional<LinkLocalService> getServiceForJID(const JID&) const; - boost::signal<void (boost::shared_ptr<RosterPayload>)> onRosterChanged; - boost::signal<void (boost::shared_ptr<Presence>)> onPresenceChanged; + boost::signals2::signal<void (std::shared_ptr<RosterPayload>)> onRosterChanged; + boost::signals2::signal<void (std::shared_ptr<Presence>)> onPresenceChanged; - private: - void handleServiceAdded(const LinkLocalService&); - void handleServiceChanged(const LinkLocalService&); - void handleServiceRemoved(const LinkLocalService&); + private: + void handleServiceAdded(const LinkLocalService&); + void handleServiceChanged(const LinkLocalService&); + void handleServiceRemoved(const LinkLocalService&); - RosterItemPayload getRosterItem(const LinkLocalService& service) const; - std::string getRosterName(const LinkLocalService& service) const; - boost::shared_ptr<Presence> getPresence(const LinkLocalService& service) const; + RosterItemPayload getRosterItem(const LinkLocalService& service) const; + std::string getRosterName(const LinkLocalService& service) const; + std::shared_ptr<Presence> getPresence(const LinkLocalService& service) const; - private: - LinkLocalServiceBrowser* browser; - }; + private: + LinkLocalServiceBrowser* browser; + }; } diff --git a/Slimber/MainController.cpp b/Slimber/MainController.cpp index 54ad222..cd36132 100644 --- a/Slimber/MainController.cpp +++ b/Slimber/MainController.cpp @@ -1,127 +1,127 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include "Slimber/MainController.h" +#include <Slimber/MainController.h> #include <boost/bind.hpp> #include <boost/lexical_cast.hpp> -#include <iostream> -#include <Swiften/Base/foreach.h> -#include <SwifTools/Application/PlatformApplicationPathProvider.h> +#include <Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h> #include <Swiften/LinkLocal/LinkLocalService.h> #include <Swiften/LinkLocal/LinkLocalServiceBrowser.h> -#include <Swiften/LinkLocal/DNSSD/PlatformDNSSDQuerierFactory.h> -#include "Slimber/Server.h" -#include "Slimber/FileVCardCollection.h" -#include "Slimber/MenuletController.h" -#include "Slimber/Menulet.h" + +#include <Slimber/FileVCardCollection.h> +#include <Slimber/Menulet.h> +#include <Slimber/MenuletController.h> +#include <Slimber/Server.h> + +#include <SwifTools/Application/PlatformApplicationPathProvider.h> using namespace Swift; MainController::MainController(Menulet* menulet, EventLoop* eventLoop) { - dnsSDQuerier = PlatformDNSSDQuerierFactory(eventLoop).createQuerier(); - assert(dnsSDQuerier); + dnsSDQuerier = PlatformDNSSDQuerierFactory(eventLoop).createQuerier(); + assert(dnsSDQuerier); - linkLocalServiceBrowser = new LinkLocalServiceBrowser(dnsSDQuerier); - linkLocalServiceBrowser->onServiceAdded.connect( - boost::bind(&MainController::handleServicesChanged, this)); - linkLocalServiceBrowser->onServiceRemoved.connect( - boost::bind(&MainController::handleServicesChanged, this)); - linkLocalServiceBrowser->onServiceChanged.connect( - boost::bind(&MainController::handleServicesChanged, this)); + linkLocalServiceBrowser = new LinkLocalServiceBrowser(dnsSDQuerier); + linkLocalServiceBrowser->onServiceAdded.connect( + boost::bind(&MainController::handleServicesChanged, this)); + linkLocalServiceBrowser->onServiceRemoved.connect( + boost::bind(&MainController::handleServicesChanged, this)); + linkLocalServiceBrowser->onServiceChanged.connect( + boost::bind(&MainController::handleServicesChanged, this)); - vCardCollection = new FileVCardCollection( - PlatformApplicationPathProvider("Slimber").getDataDir()); + vCardCollection = new FileVCardCollection( + PlatformApplicationPathProvider("Slimber").getDataDir()); - server = new Server(5222, 5562, linkLocalServiceBrowser, vCardCollection, eventLoop); - server->onStopped.connect( - boost::bind(&MainController::handleServerStopped, this, _1)); - server->onSelfConnected.connect( - boost::bind(&MainController::handleSelfConnected, this, _1)); + server = new Server(5222, 5562, linkLocalServiceBrowser, vCardCollection, eventLoop); + server->onStopped.connect( + boost::bind(&MainController::handleServerStopped, this, _1)); + server->onSelfConnected.connect( + boost::bind(&MainController::handleSelfConnected, this, _1)); - menuletController = new MenuletController(menulet); - menuletController->onRestartRequested.connect(boost::bind( - &MainController::handleRestartRequested, this)); + menuletController = new MenuletController(menulet); + menuletController->onRestartRequested.connect(boost::bind( + &MainController::handleRestartRequested, this)); - start(); + start(); } MainController::~MainController() { - delete server; - delete menuletController; - delete vCardCollection; - linkLocalServiceBrowser->stop(); - delete linkLocalServiceBrowser; - dnsSDQuerier->stop(); + delete server; + delete menuletController; + delete vCardCollection; + linkLocalServiceBrowser->stop(); + delete linkLocalServiceBrowser; + dnsSDQuerier->stop(); } void MainController::start() { - dnsSDQuerier->start(); - linkLocalServiceBrowser->start(); + dnsSDQuerier->start(); + linkLocalServiceBrowser->start(); - handleSelfConnected(false); - handleServicesChanged(); + handleSelfConnected(false); + handleServicesChanged(); - server->start(); + server->start(); } void MainController::stop() { - server->stop(); - linkLocalServiceBrowser->stop(); - dnsSDQuerier->stop(); + server->stop(); + linkLocalServiceBrowser->stop(); + dnsSDQuerier->stop(); } void MainController::handleSelfConnected(bool b) { - if (b) { - menuletController->setXMPPStatus("You are logged in", MenuletController::Online); - } - else { - menuletController->setXMPPStatus("You are not logged in", MenuletController::Offline); - } + if (b) { + menuletController->setXMPPStatus("You are logged in", MenuletController::Online); + } + else { + menuletController->setXMPPStatus("You are not logged in", MenuletController::Offline); + } } void MainController::handleServicesChanged() { - std::vector<std::string> names; - foreach(const LinkLocalService& service, linkLocalServiceBrowser->getServices()) { - std::string description = service.getDescription(); - if (description != service.getName()) { - description += " (" + service.getName() + ")"; - } - names.push_back(description); - } - menuletController->setUserNames(names); + std::vector<std::string> names; + for (const auto& service : linkLocalServiceBrowser->getServices()) { + std::string description = service.getDescription(); + if (description != service.getName()) { + description += " (" + service.getName() + ")"; + } + names.push_back(description); + } + menuletController->setUserNames(names); } void MainController::handleServerStopped(boost::optional<ServerError> error) { - if (error) { - std::string message; - switch (error->getType()) { - case ServerError::C2SPortConflict: - message = std::string("Error: Port ") + boost::lexical_cast<std::string>(server->getClientToServerPort()) + std::string(" in use"); - break; - case ServerError::C2SError: - message = std::string("Local connection server error"); - break; - case ServerError::LinkLocalPortConflict: - message = std::string("Error: Port ") + boost::lexical_cast<std::string>(server->getLinkLocalPort()) + std::string(" in use"); - break; - case ServerError::LinkLocalError: - message = std::string("External connection server error"); - break; - } - menuletController->setXMPPStatus(message, MenuletController::Offline); - } - else { - menuletController->setXMPPStatus("XMPP Server Not Running", MenuletController::Offline); - } + if (error) { + std::string message; + switch (error->getType()) { + case ServerError::C2SPortConflict: + message = std::string("Error: Port ") + boost::lexical_cast<std::string>(server->getClientToServerPort()) + std::string(" in use"); + break; + case ServerError::C2SError: + message = std::string("Local connection server error"); + break; + case ServerError::LinkLocalPortConflict: + message = std::string("Error: Port ") + boost::lexical_cast<std::string>(server->getLinkLocalPort()) + std::string(" in use"); + break; + case ServerError::LinkLocalError: + message = std::string("External connection server error"); + break; + } + menuletController->setXMPPStatus(message, MenuletController::Offline); + } + else { + menuletController->setXMPPStatus("XMPP Server Not Running", MenuletController::Offline); + } } void MainController::handleRestartRequested() { - stop(); - start(); + stop(); + start(); } diff --git a/Slimber/MainController.h b/Slimber/MainController.h index ecb81ba..9989b4d 100644 --- a/Slimber/MainController.h +++ b/Slimber/MainController.h @@ -1,45 +1,46 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> + #include <boost/optional.hpp> -#include "Slimber/ServerError.h" +#include <Slimber/ServerError.h> namespace Swift { - class DNSSDQuerier; - class LinkLocalServiceBrowser; - class VCardCollection; - class Server; - class EventLoop; + class DNSSDQuerier; + class LinkLocalServiceBrowser; + class VCardCollection; + class Server; + class EventLoop; } class MenuletController; class Menulet; class MainController { - public: - MainController(Menulet* menulet, Swift::EventLoop* eventLoop); - virtual ~MainController(); - - private: - void handleSelfConnected(bool b); - void handleServicesChanged(); - void handleServerStopped(boost::optional<Swift::ServerError> error); - void handleRestartRequested(); - - void start(); - void stop(); - - private: - boost::shared_ptr<Swift::DNSSDQuerier> dnsSDQuerier; - Swift::LinkLocalServiceBrowser* linkLocalServiceBrowser; - Swift::VCardCollection* vCardCollection; - Swift::Server* server; - MenuletController* menuletController; + public: + MainController(Menulet* menulet, Swift::EventLoop* eventLoop); + virtual ~MainController(); + + private: + void handleSelfConnected(bool b); + void handleServicesChanged(); + void handleServerStopped(boost::optional<Swift::ServerError> error); + void handleRestartRequested(); + + void start(); + void stop(); + + private: + std::shared_ptr<Swift::DNSSDQuerier> dnsSDQuerier; + Swift::LinkLocalServiceBrowser* linkLocalServiceBrowser; + Swift::VCardCollection* vCardCollection; + Swift::Server* server; + MenuletController* menuletController; }; diff --git a/Slimber/Menulet.cpp b/Slimber/Menulet.cpp index 5ab4273..3e449f8 100644 --- a/Slimber/Menulet.cpp +++ b/Slimber/Menulet.cpp @@ -1,10 +1,10 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include "Slimber/Menulet.h" +#include <Slimber/Menulet.h> Menulet::~Menulet() { } diff --git a/Slimber/Menulet.h b/Slimber/Menulet.h index a5c7bde..4c06754 100644 --- a/Slimber/Menulet.h +++ b/Slimber/Menulet.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -7,19 +7,20 @@ #pragma once #include <string> -#include <Swiften/Base/boost_bsignals.h> + +#include <boost/signals2.hpp> class Menulet { - public: - virtual ~Menulet(); + public: + virtual ~Menulet(); - virtual void clear() = 0; - virtual void addItem(const std::string& name, const std::string& icon = std::string()) = 0; - virtual void addAboutItem() = 0; - virtual void addRestartItem() = 0; - virtual void addExitItem() = 0; - virtual void addSeparator() = 0; - virtual void setIcon(const std::string&) = 0; + virtual void clear() = 0; + virtual void addItem(const std::string& name, const std::string& icon = std::string()) = 0; + virtual void addAboutItem() = 0; + virtual void addRestartItem() = 0; + virtual void addExitItem() = 0; + virtual void addSeparator() = 0; + virtual void setIcon(const std::string&) = 0; - boost::signal<void ()> onRestartClicked; + boost::signals2::signal<void ()> onRestartClicked; }; diff --git a/Slimber/MenuletController.cpp b/Slimber/MenuletController.cpp index 078275b..5ea5bc9 100644 --- a/Slimber/MenuletController.cpp +++ b/Slimber/MenuletController.cpp @@ -1,55 +1,53 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include "Slimber/MenuletController.h" +#include <Slimber/MenuletController.h> -#include <Swiften/Base/foreach.h> #include <string> -#include "Slimber/Menulet.h" -#include <iostream> +#include <Slimber/Menulet.h> -MenuletController::MenuletController(Menulet* menulet) : - menulet(menulet), xmppStatus(Offline) { - menulet->onRestartClicked.connect(boost::ref(onRestartRequested)); - update(); +MenuletController::MenuletController(Menulet* menulet) : + menulet(menulet), xmppStatus(Offline) { + menulet->onRestartClicked.connect(boost::ref(onRestartRequested)); + update(); } MenuletController::~MenuletController() { } void MenuletController::setXMPPStatus(const std::string& message, Status status) { - xmppStatus = status; - xmppStatusMessage = message; - update(); + xmppStatus = status; + xmppStatusMessage = message; + update(); } void MenuletController::setUserNames(const std::vector<std::string>& users) { - linkLocalUsers = users; - update(); + linkLocalUsers = users; + update(); } void MenuletController::update() { - menulet->clear(); - if (linkLocalUsers.empty()) { - menulet->setIcon("UsersOffline"); - menulet->addItem("No online users"); - } - else { - menulet->setIcon("UsersOnline"); - menulet->addItem("Online users:"); - foreach(const std::string& user, linkLocalUsers) { - menulet->addItem(std::string(" ") + user); - } - } - menulet->addSeparator(); - menulet->addItem(xmppStatusMessage, (xmppStatus == Online ? "Online" : "Offline")); - menulet->addSeparator(); - menulet->addAboutItem(); - menulet->addSeparator(); - menulet->addRestartItem(); - menulet->addExitItem(); + menulet->clear(); + if (linkLocalUsers.empty()) { + menulet->setIcon("UsersOffline"); + menulet->addItem("No online users"); + } + else { + menulet->setIcon("UsersOnline"); + menulet->addItem("Online users:"); + for (const auto& user : linkLocalUsers) { + menulet->addItem(std::string(" ") + user); + } + } + menulet->addSeparator(); + menulet->addItem(xmppStatusMessage, (xmppStatus == Online ? "Online" : "Offline")); + menulet->addSeparator(); + menulet->addAboutItem(); + menulet->addSeparator(); + menulet->addRestartItem(); + menulet->addExitItem(); } diff --git a/Slimber/MenuletController.h b/Slimber/MenuletController.h index 7885ad1..3c05ed2 100644 --- a/Slimber/MenuletController.h +++ b/Slimber/MenuletController.h @@ -1,39 +1,39 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once +#include <string> #include <vector> -#include <boost/signal.hpp> -#include <string> +#include <boost/signals2.hpp> class Menulet; class MenuletController { - public: - enum Status { - Online, - Offline - }; - - MenuletController(Menulet*); - virtual ~MenuletController(); - - void setXMPPStatus(const std::string& message, Status status); - void setUserNames(const std::vector<std::string>&); - - boost::signal<void ()> onRestartRequested; - - private: - void update(); - - private: - Menulet* menulet; - Status xmppStatus; - std::string xmppStatusMessage; - std::vector<std::string> linkLocalUsers; + public: + enum Status { + Online, + Offline + }; + + MenuletController(Menulet*); + virtual ~MenuletController(); + + void setXMPPStatus(const std::string& message, Status status); + void setUserNames(const std::vector<std::string>&); + + boost::signals2::signal<void ()> onRestartRequested; + + private: + void update(); + + private: + Menulet* menulet; + Status xmppStatus; + std::string xmppStatusMessage; + std::vector<std::string> linkLocalUsers; }; diff --git a/Slimber/Qt/QtAboutDialog.cpp b/Slimber/Qt/QtAboutDialog.cpp index 27fc803..301661e 100644 --- a/Slimber/Qt/QtAboutDialog.cpp +++ b/Slimber/Qt/QtAboutDialog.cpp @@ -1,37 +1,37 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include "Slimber/Qt/QtAboutDialog.h" +#include <Slimber/Qt/QtAboutDialog.h> #include <QCoreApplication> -#include <QVBoxLayout> #include <QLabel> #include <QPixmap> +#include <QVBoxLayout> QtAboutDialog::QtAboutDialog() { - setAttribute(Qt::WA_DeleteOnClose); - setWindowTitle("About Slimber"); - - QVBoxLayout* layout = new QVBoxLayout(this); - - QLabel* iconLabel = new QLabel(this); - iconLabel->setPixmap(QPixmap(":/icons/Icon-128.png")); - iconLabel->setAlignment(Qt::AlignHCenter); - layout->addWidget(iconLabel); - - QLabel* appNameLabel = new QLabel("<center><font size='+1'><b>" + QCoreApplication::applicationName() + "</b></font></center>", this); - layout->addWidget(appNameLabel); - - QLabel* versionLabel = new QLabel(QString("<center><font size='-1'>Version ") + QCoreApplication::applicationVersion() + "</font></center>", this); - layout->addWidget(versionLabel); - QString buildString = QString("<center><font size='-1'>Built with: Qt version ") + QT_VERSION_STR; - buildString += QString("<br/>Running with Qt version ") + qVersion(); - buildString += "</font></center>"; - QLabel* buildLabel = new QLabel(buildString, this); - layout->addWidget(buildLabel); - - setFixedSize(minimumSizeHint()); + setAttribute(Qt::WA_DeleteOnClose); + setWindowTitle("About Slimber"); + + QVBoxLayout* layout = new QVBoxLayout(this); + + QLabel* iconLabel = new QLabel(this); + iconLabel->setPixmap(QPixmap(":/icons/Icon-128.png")); + iconLabel->setAlignment(Qt::AlignHCenter); + layout->addWidget(iconLabel); + + QLabel* appNameLabel = new QLabel("<center><font size='+1'><b>" + QCoreApplication::applicationName() + "</b></font></center>", this); + layout->addWidget(appNameLabel); + + QLabel* versionLabel = new QLabel(QString("<center><font size='-1'>Version ") + QCoreApplication::applicationVersion() + "</font></center>", this); + layout->addWidget(versionLabel); + QString buildString = QString("<center><font size='-1'>Built with: Qt version ") + QT_VERSION_STR; + buildString += QString("<br/>Running with Qt version ") + qVersion(); + buildString += "</font></center>"; + QLabel* buildLabel = new QLabel(buildString, this); + layout->addWidget(buildLabel); + + setFixedSize(minimumSizeHint()); } diff --git a/Slimber/Qt/QtAboutDialog.h b/Slimber/Qt/QtAboutDialog.h index d19d209..1f14ebe 100644 --- a/Slimber/Qt/QtAboutDialog.h +++ b/Slimber/Qt/QtAboutDialog.h @@ -9,6 +9,6 @@ #include <QDialog> class QtAboutDialog : public QDialog { - public: - QtAboutDialog(); + public: + QtAboutDialog(); }; diff --git a/Slimber/Qt/QtMenulet.cpp b/Slimber/Qt/QtMenulet.cpp index ba3d004..5d0d276 100644 --- a/Slimber/Qt/QtMenulet.cpp +++ b/Slimber/Qt/QtMenulet.cpp @@ -1,8 +1,7 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include "Slimber/Qt/QtMenulet.h" - +#include <Slimber/Qt/QtMenulet.h> diff --git a/Slimber/Qt/QtMenulet.h b/Slimber/Qt/QtMenulet.h index d6a7a4d..fa17d21 100644 --- a/Slimber/Qt/QtMenulet.h +++ b/Slimber/Qt/QtMenulet.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -8,75 +8,75 @@ #include <QCoreApplication> #include <QMenu> -#include <QString> -#include <QSystemTrayIcon> #include <QObject> #include <QPixmap> #include <QPointer> +#include <QString> +#include <QSystemTrayIcon> -#include "Slimber/Menulet.h" -#include "Slimber/Qt/QtAboutDialog.h" +#include <Slimber/Menulet.h> +#include <Slimber/Qt/QtAboutDialog.h> class QtMenulet : public QObject, public Menulet { - Q_OBJECT - public: - QtMenulet() { - trayIcon.setIcon(QPixmap(":/icons/UsersOffline.png")); - trayIcon.setContextMenu(&menu); - trayIcon.show(); - } + Q_OBJECT + public: + QtMenulet() { + trayIcon.setIcon(QPixmap(":/icons/UsersOffline.png")); + trayIcon.setContextMenu(&menu); + trayIcon.show(); + } - void clear() { - menu.clear(); - } + void clear() { + menu.clear(); + } - void addItem(const std::string& name, const std::string& icon) { - menu.addAction(getIcon(icon), QString::fromUtf8(name.c_str())); - } + void addItem(const std::string& name, const std::string& icon) { + menu.addAction(getIcon(icon), QString::fromUtf8(name.c_str())); + } - void addAboutItem() { - menu.addAction("About", this, SLOT(showAboutDialog())); - } + void addAboutItem() { + menu.addAction("About", this, SLOT(showAboutDialog())); + } - void addRestartItem() { - menu.addAction("Restart", this, SLOT(restart())); - } + void addRestartItem() { + menu.addAction("Restart", this, SLOT(restart())); + } - void addExitItem() { - menu.addAction("Exit", qApp, SLOT(quit())); - } + void addExitItem() { + menu.addAction("Exit", qApp, SLOT(quit())); + } - void addSeparator() { - menu.addSeparator(); - } + void addSeparator() { + menu.addSeparator(); + } - void setIcon(const std::string& icon) { - trayIcon.setIcon(getIcon(icon)); - } + void setIcon(const std::string& icon) { + trayIcon.setIcon(getIcon(icon)); + } - private: - QPixmap getIcon(const std::string& name) { - return QPixmap(":/icons/" + QString::fromUtf8(name.c_str()) + ".png"); - } + private: + QPixmap getIcon(const std::string& name) { + return QPixmap(":/icons/" + QString::fromUtf8(name.c_str()) + ".png"); + } - private slots: - void showAboutDialog() { - if (aboutDialog) { - aboutDialog->raise(); - aboutDialog->activateWindow(); - } - else { - aboutDialog = new QtAboutDialog(); - aboutDialog->show(); - } - } + private slots: + void showAboutDialog() { + if (aboutDialog) { + aboutDialog->raise(); + aboutDialog->activateWindow(); + } + else { + aboutDialog = new QtAboutDialog(); + aboutDialog->show(); + } + } - void restart() { - onRestartClicked(); - } + void restart() { + onRestartClicked(); + } - private: - QMenu menu; - QSystemTrayIcon trayIcon; - QPointer<QtAboutDialog> aboutDialog; + private: + QMenu menu; + QSystemTrayIcon trayIcon; + QPointer<QtAboutDialog> aboutDialog; }; diff --git a/Slimber/Qt/SConscript b/Slimber/Qt/SConscript index 0e7bdea..8328f8c 100644 --- a/Slimber/Qt/SConscript +++ b/Slimber/Qt/SConscript @@ -15,11 +15,11 @@ myenv.UseFlags(env.get("AVAHI_FLAGS", "")) myenv.UseFlags(myenv["PLATFORM_FLAGS"]) if myenv.get("HAVE_ICU") : - myenv.MergeFlags(env["ICU_FLAGS"]) - myenv.Append(CPPDEFINES = ["HAVE_ICU"]) + myenv.MergeFlags(env["ICU_FLAGS"]) + myenv.Append(CPPDEFINES = ["HAVE_ICU"]) if myenv.get("HAVE_LIBIDN") : - myenv.MergeFlags(env["LIBIDN_FLAGS"]) - myenv.Append(CPPDEFINES = ["HAVE_LIBIDN"]) + myenv.MergeFlags(env["LIBIDN_FLAGS"]) + myenv.Append(CPPDEFINES = ["HAVE_LIBIDN"]) myenv.Tool("qt4", toolpath = ["#/BuildTools/SCons/Tools"]) myenv.Tool("nsis", toolpath = ["#/BuildTools/SCons/Tools"]) @@ -27,41 +27,39 @@ myenv.Tool("nsis", toolpath = ["#/BuildTools/SCons/Tools"]) qt4modules = ['QtCore', 'QtGui'] if myenv["qt5"] : - qt_version = '5' - qt4modules += ['QtWidgets'] + qt_version = '5' + qt4modules += ['QtWidgets'] else : - qt_version = '4' + qt_version = '4' myenv.EnableQt4Modules(qt4modules, debug = False, version = qt_version) -myenv.Append(CPPPATH = ["."]) - if env["PLATFORM"] == "win32" : - myenv.Append(LINKFLAGS = ["/SUBSYSTEM:WINDOWS"]) - myenv.Append(LIBS = "qtmain") + myenv.Append(LINKFLAGS = ["/SUBSYSTEM:WINDOWS"]) + myenv.Append(LIBS = "qtmain") myenv.BuildVersion("BuildVersion.h", project = "slimber") sources = [ - "main.cpp", - "QtMenulet.cpp", - "QtAboutDialog.cpp", - myenv.Qrc("Slimber.qrc"), - ] + "main.cpp", + "QtMenulet.cpp", + "QtAboutDialog.cpp", + myenv.Qrc("Slimber.qrc"), + ] #if env["PLATFORM"] == "win32" : -# myenv.RES("../resources/Windows/Slimber.rc") -# sources += ["../resources/Windows/Slimber.res"] +# myenv.RES("../resources/Windows/Slimber.rc") +# sources += ["../resources/Windows/Slimber.res"] if env["PLATFORM"] == "win32" : - slimberProgram = myenv.Program("Slimber", sources) + slimberProgram = myenv.Program("Slimber", sources) else : - slimberProgram = myenv.Program("slimber", sources) + slimberProgram = myenv.Program("slimber", sources) if env["PLATFORM"] == "win32" : - if "dist" in COMMAND_LINE_TARGETS or env.GetOption("clean") : - myenv.WindowsBundle("Slimber", resources = {}, qtlibs = ["QtCore4", "QtGui4"]) - myenv.Append(NSIS_OPTIONS = [ - "/DmsvccRedistributableDir=\"" + env["vcredist"] + "\"", - "/DbuildDate=" + datetime.date.today().strftime("%Y%m%d") - ]) - #myenv.Nsis("../Packaging/nsis/slimber.nsi") + if "dist" in COMMAND_LINE_TARGETS or env.GetOption("clean") : + myenv.WindowsBundle("Slimber", resources = {}, qtlibs = ["QtCore4", "QtGui4"]) + myenv.Append(NSIS_OPTIONS = [ + "/DmsvccRedistributableDir=\"" + env["vcredist"] + "\"", + "/DbuildDate=" + datetime.date.today().strftime("%Y%m%d") + ]) + #myenv.Nsis("../Packaging/nsis/slimber.nsi") diff --git a/Slimber/Qt/main.cpp b/Slimber/Qt/main.cpp index 5415d05..8fbfbb6 100644 --- a/Slimber/Qt/main.cpp +++ b/Slimber/Qt/main.cpp @@ -1,35 +1,36 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <QApplication> #include <QCoreApplication> -#include <QSystemTrayIcon> #include <QMessageBox> +#include <QSystemTrayIcon> -#include "QtMenulet.h" -#include "Slimber/MainController.h" #include <Swiften/EventLoop/Qt/QtEventLoop.h> + +#include <Slimber/MainController.h> #include <Slimber/Qt/BuildVersion.h> +#include <Slimber/Qt/QtMenulet.h> int main(int argc, char* argv[]) { - QApplication app(argc, argv); - Swift::QtEventLoop eventLoop; + QApplication app(argc, argv); + Swift::QtEventLoop eventLoop; - QCoreApplication::setApplicationName("Slimber"); - QCoreApplication::setApplicationVersion(QString(buildVersion)); + QCoreApplication::setApplicationName("Slimber"); + QCoreApplication::setApplicationVersion(QString(buildVersion)); - if (!QSystemTrayIcon::isSystemTrayAvailable()) { + if (!QSystemTrayIcon::isSystemTrayAvailable()) { QMessageBox::critical(0, QObject::tr("Systray"), QObject::tr("No system tray")); - return 1; - } + return 1; + } - app.setQuitOnLastWindowClosed(false); + app.setQuitOnLastWindowClosed(false); - QtMenulet menulet; - MainController controller(&menulet, &eventLoop); + QtMenulet menulet; + MainController controller(&menulet, &eventLoop); - return app.exec(); + return app.exec(); } diff --git a/Slimber/SConscript b/Slimber/SConscript index ff4f57d..a41fe0b 100644 --- a/Slimber/SConscript +++ b/Slimber/SConscript @@ -4,18 +4,18 @@ Import("env") env["BUILD_SLIMBER"] = True if env["PLATFORM"] == "win32" : - if not env.get("HAVE_BONJOUR") and "Slimber" in env["PROJECTS"] : - env["PROJECTS"].remove("Slimber") + if not env.get("HAVE_BONJOUR") and "Slimber" in env["PROJECTS"] : + env["PROJECTS"].remove("Slimber") elif env["PLATFORM"] != "darwin" : - if not env.get("HAVE_AVAHI", False) and "Slimber" in env["PROJECTS"] : - env["PROJECTS"].remove("Slimber") + if not env.get("HAVE_AVAHI", False) and "Slimber" in env["PROJECTS"] : + env["PROJECTS"].remove("Slimber") if not "Slimber" in env["PROJECTS"] and env["SCONS_STAGE"] == "flags" : - print "Bonjour missing. Not building Slimber." + print "Bonjour missing. Not building Slimber." if not env.get("HAVE_QT", False) and "Slimber" in env["PROJECTS"] : - print "Qt missing. Not building Slimber." - env["PROJECTS"].remove("Slimber") + print "Qt missing. Not building Slimber." + env["PROJECTS"].remove("Slimber") if "Slimber" in env["PROJECTS"] : @@ -23,42 +23,42 @@ if "Slimber" in env["PROJECTS"] : # Flags ################################################################################ - if env["SCONS_STAGE"] == "flags" : - env["SLIMBER_FLAGS"] = { - "LIBPATH": [Dir(".")], - "LIBS": ["Slimber"] - } + if env["SCONS_STAGE"] == "flags" : + env["SLIMBER_FLAGS"] = { + "LIBPATH": [Dir(".")], + "LIBS": ["Slimber"] + } ################################################################################ # Build ################################################################################ - if env["SCONS_STAGE"] == "build" : - myenv = env.Clone() - myenv.UseFlags(env["LIMBER_FLAGS"]) - myenv.MergeFlags(env["BOOST_FLAGS"]) - myenv.MergeFlags(env["SWIFTEN_FLAGS"]) - myenv.MergeFlags(env["SWIFTEN_DEP_FLAGS"]) - myenv.StaticLibrary("Slimber", [ - "LinkLocalPresenceManager.cpp", - "FileVCardCollection.cpp", - "VCardCollection.cpp", - "Server.cpp", - "MainController.cpp", - "MenuletController.cpp", - "Menulet.cpp" - ]) + if env["SCONS_STAGE"] == "build" : + myenv = env.Clone() + myenv.UseFlags(env["LIMBER_FLAGS"]) + myenv.MergeFlags(env["BOOST_FLAGS"]) + myenv.MergeFlags(env["SWIFTEN_FLAGS"]) + myenv.MergeFlags(env["SWIFTEN_DEP_FLAGS"]) + myenv.StaticLibrary("Slimber", [ + "LinkLocalPresenceManager.cpp", + "FileVCardCollection.cpp", + "VCardCollection.cpp", + "Server.cpp", + "MainController.cpp", + "MenuletController.cpp", + "Menulet.cpp" + ]) - env["SLIMBER_VERSION"] = "0.9.9." + datetime.date.today().strftime("%Y%m%d") + env["SLIMBER_VERSION"] = "0.9.9." + datetime.date.today().strftime("%Y%m%d") - env.Append(UNITTEST_SOURCES = [ - File("UnitTest/LinkLocalPresenceManagerTest.cpp"), - File("UnitTest/MenuletControllerTest.cpp") - ]) + env.Append(UNITTEST_SOURCES = [ + File("UnitTest/LinkLocalPresenceManagerTest.cpp"), + File("UnitTest/MenuletControllerTest.cpp") + ]) - SConscript("CLI/SConscript") - if env["PLATFORM"] == "darwin" : - SConscript("Cocoa/SConscript") - else : - SConscript("Qt/SConscript") + SConscript("CLI/SConscript") + if env["PLATFORM"] == "darwin" : + SConscript("Cocoa/SConscript") + else : + SConscript("Qt/SConscript") diff --git a/Slimber/Server.cpp b/Slimber/Server.cpp index b78e701..3bc3112 100644 --- a/Slimber/Server.cpp +++ b/Slimber/Server.cpp @@ -1,438 +1,439 @@ /* - * Copyright (c) 2010-2014 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include "Slimber/Server.h" +#include <Slimber/Server.h> +#include <cassert> #include <string> + #include <boost/bind.hpp> -#include <iostream> - -#include "Swiften/Base/String.h" -#include "Swiften/LinkLocal/LinkLocalConnector.h" -#include "Swiften/Network/Connection.h" -#include "Swiften/Session/SessionTracer.h" -#include "Swiften/Elements/ToplevelElement.h" -#include "Swiften/Elements/Presence.h" -#include "Swiften/Elements/RosterPayload.h" -#include "Swiften/Network/BoostConnection.h" -#include "Swiften/Network/BoostConnectionServer.h" -#include "Swiften/Session/SessionTracer.h" -#include "Swiften/Elements/IQ.h" -#include "Swiften/Elements/VCard.h" -#include "Limber/Server/UserRegistry.h" -#include "Swiften/Session/Session.h" -#include <Swiften/Base/foreach.h> -#include <string> -#include <Swiften/LinkLocal/LinkLocalServiceInfo.h> -#include <Swiften/LinkLocal/OutgoingLinkLocalSession.h> + +#include <Swiften/Base/Log.h> +#include <Swiften/Base/String.h> +#include <Swiften/Elements/IQ.h> +#include <Swiften/Elements/Presence.h> +#include <Swiften/Elements/RosterPayload.h> +#include <Swiften/Elements/ToplevelElement.h> +#include <Swiften/Elements/VCard.h> #include <Swiften/LinkLocal/IncomingLinkLocalSession.h> +#include <Swiften/LinkLocal/LinkLocalConnector.h> #include <Swiften/LinkLocal/LinkLocalServiceBrowser.h> +#include <Swiften/LinkLocal/LinkLocalServiceInfo.h> +#include <Swiften/LinkLocal/OutgoingLinkLocalSession.h> +#include <Swiften/Network/BoostConnection.h> +#include <Swiften/Network/BoostConnectionServer.h> +#include <Swiften/Network/Connection.h> #include <Swiften/Network/ConnectionServer.h> -#include "Slimber/VCardCollection.h" -#include "Slimber/LinkLocalPresenceManager.h" -#include "Limber/Server/ServerFromClientSession.h" +#include <Swiften/Session/Session.h> +#include <Swiften/Session/SessionTracer.h> + +#include <Limber/Server/ServerFromClientSession.h> +#include <Limber/Server/UserRegistry.h> + +#include <Slimber/LinkLocalPresenceManager.h> +#include <Slimber/VCardCollection.h> namespace Swift { Server::Server( - int clientConnectionPort, - int linkLocalConnectionPort, - LinkLocalServiceBrowser* linkLocalServiceBrowser, - VCardCollection* vCardCollection, - EventLoop* eventLoop) : - linkLocalServiceRegistered(false), - rosterRequested(false), - clientConnectionPort(clientConnectionPort), - linkLocalConnectionPort(linkLocalConnectionPort), - linkLocalServiceBrowser(linkLocalServiceBrowser), - vCardCollection(vCardCollection), - eventLoop(eventLoop), - presenceManager(NULL), - stopping(false) { - linkLocalServiceBrowser->onServiceRegistered.connect( - boost::bind(&Server::handleServiceRegistered, this, _1)); + int clientConnectionPort, + int linkLocalConnectionPort, + LinkLocalServiceBrowser* linkLocalServiceBrowser, + VCardCollection* vCardCollection, + EventLoop* eventLoop) : + linkLocalServiceRegistered(false), + rosterRequested(false), + clientConnectionPort(clientConnectionPort), + linkLocalConnectionPort(linkLocalConnectionPort), + linkLocalServiceBrowser(linkLocalServiceBrowser), + vCardCollection(vCardCollection), + eventLoop(eventLoop), + presenceManager(nullptr), + stopping(false) { + linkLocalServiceBrowser->onServiceRegistered.connect( + boost::bind(&Server::handleServiceRegistered, this, _1)); } Server::~Server() { - stop(); + stop(); } void Server::start() { - assert(!serverFromClientConnectionServer); - serverFromClientConnectionServer = BoostConnectionServer::create( - clientConnectionPort, boostIOServiceThread.getIOService(), eventLoop); - serverFromClientConnectionServerSignalConnections.push_back( - serverFromClientConnectionServer->onNewConnection.connect( - boost::bind(&Server::handleNewClientConnection, this, _1))); - serverFromClientConnectionServerSignalConnections.push_back( - serverFromClientConnectionServer->onStopped.connect( - boost::bind(&Server::handleClientConnectionServerStopped, this, _1))); - - assert(!serverFromNetworkConnectionServer); - serverFromNetworkConnectionServer = BoostConnectionServer::create( - linkLocalConnectionPort, boostIOServiceThread.getIOService(), eventLoop); - serverFromNetworkConnectionServerSignalConnections.push_back( - serverFromNetworkConnectionServer->onNewConnection.connect( - boost::bind(&Server::handleNewLinkLocalConnection, this, _1))); - serverFromNetworkConnectionServerSignalConnections.push_back( - serverFromNetworkConnectionServer->onStopped.connect( - boost::bind(&Server::handleLinkLocalConnectionServerStopped, this, _1))); - - assert(!presenceManager); - presenceManager = new LinkLocalPresenceManager(linkLocalServiceBrowser); - presenceManager->onRosterChanged.connect( - boost::bind(&Server::handleRosterChanged, this, _1)); - presenceManager->onPresenceChanged.connect( - boost::bind(&Server::handlePresenceChanged, this, _1)); - - serverFromClientConnectionServer->start(); - serverFromNetworkConnectionServer->start(); + assert(!serverFromClientConnectionServer); + serverFromClientConnectionServer = BoostConnectionServer::create( + clientConnectionPort, boostIOServiceThread.getIOService(), eventLoop); + serverFromClientConnectionServerSignalConnections.push_back( + serverFromClientConnectionServer->onNewConnection.connect( + boost::bind(&Server::handleNewClientConnection, this, _1))); + serverFromClientConnectionServerSignalConnections.push_back( + serverFromClientConnectionServer->onStopped.connect( + boost::bind(&Server::handleClientConnectionServerStopped, this, _1))); + + assert(!serverFromNetworkConnectionServer); + serverFromNetworkConnectionServer = BoostConnectionServer::create( + linkLocalConnectionPort, boostIOServiceThread.getIOService(), eventLoop); + serverFromNetworkConnectionServerSignalConnections.push_back( + serverFromNetworkConnectionServer->onNewConnection.connect( + boost::bind(&Server::handleNewLinkLocalConnection, this, _1))); + serverFromNetworkConnectionServerSignalConnections.push_back( + serverFromNetworkConnectionServer->onStopped.connect( + boost::bind(&Server::handleLinkLocalConnectionServerStopped, this, _1))); + + assert(!presenceManager); + presenceManager = new LinkLocalPresenceManager(linkLocalServiceBrowser); + presenceManager->onRosterChanged.connect( + boost::bind(&Server::handleRosterChanged, this, _1)); + presenceManager->onPresenceChanged.connect( + boost::bind(&Server::handlePresenceChanged, this, _1)); + + serverFromClientConnectionServer->start(); + serverFromNetworkConnectionServer->start(); } void Server::stop() { - stop(boost::optional<ServerError>()); + stop(boost::optional<ServerError>()); } void Server::stop(boost::optional<ServerError> e) { - if (stopping) { - return; - } - - stopping = true; - - delete presenceManager; - presenceManager = NULL; - - if (serverFromClientSession) { - serverFromClientSession->finishSession(); - } - serverFromClientSession.reset(); - foreach(boost::shared_ptr<Session> session, linkLocalSessions) { - session->finishSession(); - } - linkLocalSessions.clear(); - foreach(boost::shared_ptr<LinkLocalConnector> connector, connectors) { - connector->cancel(); - } - connectors.clear(); - tracers.clear(); - - if (serverFromNetworkConnectionServer) { - serverFromNetworkConnectionServer->stop(); - foreach(boost::bsignals::connection& connection, serverFromNetworkConnectionServerSignalConnections) { - connection.disconnect(); - } - serverFromNetworkConnectionServerSignalConnections.clear(); - serverFromNetworkConnectionServer.reset(); - } - if (serverFromClientConnectionServer) { - serverFromClientConnectionServer->stop(); - foreach(boost::bsignals::connection& connection, serverFromClientConnectionServerSignalConnections) { - connection.disconnect(); - } - serverFromClientConnectionServerSignalConnections.clear(); - serverFromClientConnectionServer.reset(); - } - - stopping = false; - onStopped(e); + if (stopping) { + return; + } + + stopping = true; + + delete presenceManager; + presenceManager = nullptr; + + if (serverFromClientSession) { + serverFromClientSession->finishSession(); + } + serverFromClientSession.reset(); + for (auto&& session : linkLocalSessions) { + session->finishSession(); + } + linkLocalSessions.clear(); + for (auto&& connector : connectors) { + connector->cancel(); + } + connectors.clear(); + tracers.clear(); + + if (serverFromNetworkConnectionServer) { + serverFromNetworkConnectionServer->stop(); + for (auto&& connection : serverFromNetworkConnectionServerSignalConnections) { + connection.disconnect(); + } + serverFromNetworkConnectionServerSignalConnections.clear(); + serverFromNetworkConnectionServer.reset(); + } + if (serverFromClientConnectionServer) { + serverFromClientConnectionServer->stop(); + for (auto&& connection : serverFromClientConnectionServerSignalConnections) { + connection.disconnect(); + } + serverFromClientConnectionServerSignalConnections.clear(); + serverFromClientConnectionServer.reset(); + } + + stopping = false; + onStopped(e); } -void Server::handleNewClientConnection(boost::shared_ptr<Connection> connection) { - if (serverFromClientSession) { - connection->disconnect(); - } - serverFromClientSession = boost::shared_ptr<ServerFromClientSession>( - new ServerFromClientSession(idGenerator.generateID(), connection, - &payloadParserFactories, &payloadSerializers, &xmlParserFactory, &userRegistry)); - serverFromClientSession->setAllowSASLEXTERNAL(); - serverFromClientSession->onSessionStarted.connect( - boost::bind(&Server::handleSessionStarted, this)); - serverFromClientSession->onElementReceived.connect( - boost::bind(&Server::handleElementReceived, this, _1, - serverFromClientSession)); - serverFromClientSession->onSessionFinished.connect( - boost::bind(&Server::handleSessionFinished, this, - serverFromClientSession)); - //tracers.push_back(boost::shared_ptr<SessionTracer>( - // new SessionTracer(serverFromClientSession))); - serverFromClientSession->startSession(); +void Server::handleNewClientConnection(std::shared_ptr<Connection> connection) { + if (serverFromClientSession) { + connection->disconnect(); + } + serverFromClientSession = std::shared_ptr<ServerFromClientSession>( + new ServerFromClientSession(idGenerator.generateID(), connection, + &payloadParserFactories, &payloadSerializers, &xmlParserFactory, &userRegistry)); + serverFromClientSession->setAllowSASLEXTERNAL(); + serverFromClientSession->onSessionStarted.connect( + boost::bind(&Server::handleSessionStarted, this)); + serverFromClientSession->onElementReceived.connect( + boost::bind(&Server::handleElementReceived, this, _1, + serverFromClientSession)); + serverFromClientSession->onSessionFinished.connect( + boost::bind(&Server::handleSessionFinished, this, + serverFromClientSession)); + //tracers.push_back(std::shared_ptr<SessionTracer>( + // new SessionTracer(serverFromClientSession))); + serverFromClientSession->startSession(); } void Server::handleSessionStarted() { - onSelfConnected(true); + onSelfConnected(true); } -void Server::handleSessionFinished(boost::shared_ptr<ServerFromClientSession>) { - serverFromClientSession.reset(); - unregisterService(); - selfJID = JID(); - rosterRequested = false; - onSelfConnected(false); - lastPresence.reset(); +void Server::handleSessionFinished(std::shared_ptr<ServerFromClientSession>) { + serverFromClientSession.reset(); + unregisterService(); + selfJID = JID(); + rosterRequested = false; + onSelfConnected(false); + lastPresence.reset(); } void Server::unregisterService() { - if (linkLocalServiceRegistered) { - linkLocalServiceRegistered = false; - linkLocalServiceBrowser->unregisterService(); - } + if (linkLocalServiceRegistered) { + linkLocalServiceRegistered = false; + linkLocalServiceBrowser->unregisterService(); + } } -void Server::handleElementReceived(boost::shared_ptr<ToplevelElement> element, boost::shared_ptr<ServerFromClientSession> session) { - boost::shared_ptr<Stanza> stanza = boost::dynamic_pointer_cast<Stanza>(element); - if (!stanza) { - return; - } - - stanza->setFrom(session->getRemoteJID()); - if (!stanza->getTo().isValid()) { - stanza->setTo(session->getLocalJID()); - } - - if (boost::shared_ptr<Presence> presence = boost::dynamic_pointer_cast<Presence>(stanza)) { - if (presence->getType() == Presence::Available) { - if (!linkLocalServiceRegistered) { - linkLocalServiceRegistered = true; - linkLocalServiceBrowser->registerService( - session->getRemoteJID().toBare().toString(), - linkLocalConnectionPort, getLinkLocalServiceInfo(presence)); - } - else { - linkLocalServiceBrowser->updateService( - getLinkLocalServiceInfo(presence)); - } - lastPresence = presence; - } - else { - unregisterService(); - } - } - else if (!stanza->getTo().isValid() || stanza->getTo() == session->getLocalJID() || stanza->getTo() == session->getRemoteJID().toBare()) { - if (boost::shared_ptr<IQ> iq = boost::dynamic_pointer_cast<IQ>(stanza)) { - if (iq->getPayload<RosterPayload>()) { - if (iq->getType() == IQ::Get) { - session->sendElement(IQ::createResult(iq->getFrom(), iq->getID(), presenceManager->getRoster())); - rosterRequested = true; - foreach(const boost::shared_ptr<Presence> presence, presenceManager->getAllPresence()) { - session->sendElement(presence); - } - } - else { - session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::Forbidden, ErrorPayload::Cancel)); - } - } - if (boost::shared_ptr<VCard> vcard = iq->getPayload<VCard>()) { - if (iq->getType() == IQ::Get) { - session->sendElement(IQ::createResult(iq->getFrom(), iq->getID(), vCardCollection->getOwnVCard())); - } - else { - vCardCollection->setOwnVCard(vcard); - session->sendElement(IQ::createResult(iq->getFrom(), iq->getID())); - if (lastPresence) { - linkLocalServiceBrowser->updateService(getLinkLocalServiceInfo(lastPresence)); - } - } - } - else { - session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::FeatureNotImplemented, ErrorPayload::Cancel)); - } - } - } - else { - JID toJID = stanza->getTo(); - boost::shared_ptr<Session> outgoingSession = - getLinkLocalSessionForJID(toJID); - if (outgoingSession) { - outgoingSession->sendElement(stanza); - } - else { - boost::optional<LinkLocalService> service = - presenceManager->getServiceForJID(toJID); - if (service) { - boost::shared_ptr<LinkLocalConnector> connector = - getLinkLocalConnectorForJID(toJID); - if (!connector) { - connector = boost::shared_ptr<LinkLocalConnector>( - new LinkLocalConnector( - *service, - linkLocalServiceBrowser->getQuerier(), - BoostConnection::create(boostIOServiceThread.getIOService(), eventLoop))); - connector->onConnectFinished.connect( - boost::bind(&Server::handleConnectFinished, this, connector, _1)); - connectors.push_back(connector); - connector->connect(); - } - connector->queueElement(element); - } - else { - session->sendElement(IQ::createError( - stanza->getFrom(), stanza->getID(), - ErrorPayload::RecipientUnavailable, ErrorPayload::Wait)); - } - } - } +void Server::handleElementReceived(std::shared_ptr<ToplevelElement> element, std::shared_ptr<ServerFromClientSession> session) { + std::shared_ptr<Stanza> stanza = std::dynamic_pointer_cast<Stanza>(element); + if (!stanza) { + return; + } + + stanza->setFrom(session->getRemoteJID()); + if (!stanza->getTo().isValid()) { + stanza->setTo(session->getLocalJID()); + } + + if (std::shared_ptr<Presence> presence = std::dynamic_pointer_cast<Presence>(stanza)) { + if (presence->getType() == Presence::Available) { + if (!linkLocalServiceRegistered) { + linkLocalServiceRegistered = true; + linkLocalServiceBrowser->registerService( + session->getRemoteJID().toBare().toString(), + linkLocalConnectionPort, getLinkLocalServiceInfo(presence)); + } + else { + linkLocalServiceBrowser->updateService( + getLinkLocalServiceInfo(presence)); + } + lastPresence = presence; + } + else { + unregisterService(); + } + } + else if (!stanza->getTo().isValid() || stanza->getTo() == session->getLocalJID() || stanza->getTo() == session->getRemoteJID().toBare()) { + if (std::shared_ptr<IQ> iq = std::dynamic_pointer_cast<IQ>(stanza)) { + if (iq->getPayload<RosterPayload>()) { + if (iq->getType() == IQ::Get) { + session->sendElement(IQ::createResult(iq->getFrom(), iq->getID(), presenceManager->getRoster())); + rosterRequested = true; + for (const auto& presence : presenceManager->getAllPresence()) { + session->sendElement(presence); + } + } + else { + session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::Forbidden, ErrorPayload::Cancel)); + } + } + if (std::shared_ptr<VCard> vcard = iq->getPayload<VCard>()) { + if (iq->getType() == IQ::Get) { + session->sendElement(IQ::createResult(iq->getFrom(), iq->getID(), vCardCollection->getOwnVCard())); + } + else { + vCardCollection->setOwnVCard(vcard); + session->sendElement(IQ::createResult(iq->getFrom(), iq->getID())); + if (lastPresence) { + linkLocalServiceBrowser->updateService(getLinkLocalServiceInfo(lastPresence)); + } + } + } + else { + session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), ErrorPayload::FeatureNotImplemented, ErrorPayload::Cancel)); + } + } + } + else { + JID toJID = stanza->getTo(); + std::shared_ptr<Session> outgoingSession = + getLinkLocalSessionForJID(toJID); + if (outgoingSession) { + outgoingSession->sendElement(stanza); + } + else { + boost::optional<LinkLocalService> service = + presenceManager->getServiceForJID(toJID); + if (service) { + std::shared_ptr<LinkLocalConnector> connector = + getLinkLocalConnectorForJID(toJID); + if (!connector) { + connector = std::shared_ptr<LinkLocalConnector>( + new LinkLocalConnector( + *service, + linkLocalServiceBrowser->getQuerier(), + BoostConnection::create(boostIOServiceThread.getIOService(), eventLoop))); + connector->onConnectFinished.connect( + boost::bind(&Server::handleConnectFinished, this, connector, _1)); + connectors.push_back(connector); + connector->connect(); + } + connector->queueElement(element); + } + else { + session->sendElement(IQ::createError( + stanza->getFrom(), stanza->getID(), + ErrorPayload::RecipientUnavailable, ErrorPayload::Wait)); + } + } + } } -void Server::handleNewLinkLocalConnection(boost::shared_ptr<Connection> connection) { - boost::shared_ptr<IncomingLinkLocalSession> session( - new IncomingLinkLocalSession( - selfJID, connection, - &payloadParserFactories, &payloadSerializers, &xmlParserFactory)); - registerLinkLocalSession(session); +void Server::handleNewLinkLocalConnection(std::shared_ptr<Connection> connection) { + std::shared_ptr<IncomingLinkLocalSession> session( + new IncomingLinkLocalSession( + selfJID, connection, + &payloadParserFactories, &payloadSerializers, &xmlParserFactory)); + registerLinkLocalSession(session); } -void Server::handleLinkLocalSessionFinished(boost::shared_ptr<Session> session) { - //std::cout << "Link local session from " << session->getRemoteJID() << " ended" << std::endl; - linkLocalSessions.erase( - std::remove(linkLocalSessions.begin(), linkLocalSessions.end(), session), - linkLocalSessions.end()); +void Server::handleLinkLocalSessionFinished(std::shared_ptr<Session> session) { + //std::cout << "Link local session from " << session->getRemoteJID() << " ended" << std::endl; + linkLocalSessions.erase( + std::remove(linkLocalSessions.begin(), linkLocalSessions.end(), session), + linkLocalSessions.end()); } -void Server::handleLinkLocalElementReceived(boost::shared_ptr<ToplevelElement> element, boost::shared_ptr<Session> session) { - if (boost::shared_ptr<Stanza> stanza = boost::dynamic_pointer_cast<Stanza>(element)) { - JID fromJID = session->getRemoteJID(); - if (!presenceManager->getServiceForJID(fromJID.toBare())) { - return; // TODO: Send error back - } - stanza->setFrom(fromJID); - serverFromClientSession->sendElement(stanza); - } +void Server::handleLinkLocalElementReceived(std::shared_ptr<ToplevelElement> element, std::shared_ptr<Session> session) { + if (std::shared_ptr<Stanza> stanza = std::dynamic_pointer_cast<Stanza>(element)) { + JID fromJID = session->getRemoteJID(); + if (!presenceManager->getServiceForJID(fromJID.toBare())) { + return; // TODO: Send error back + } + stanza->setFrom(fromJID); + serverFromClientSession->sendElement(stanza); + } } -void Server::handleConnectFinished(boost::shared_ptr<LinkLocalConnector> connector, bool error) { - if (error) { - std::cerr << "Error connecting" << std::endl; - // TODO: Send back queued stanzas - } - else { - boost::shared_ptr<OutgoingLinkLocalSession> outgoingSession( - new OutgoingLinkLocalSession( - selfJID, connector->getService().getJID(), connector->getConnection(), - &payloadParserFactories, &payloadSerializers, &xmlParserFactory)); - foreach(const boost::shared_ptr<ToplevelElement> element, connector->getQueuedElements()) { - outgoingSession->queueElement(element); - } - registerLinkLocalSession(outgoingSession); - } - connectors.erase(std::remove(connectors.begin(), connectors.end(), connector), connectors.end()); +void Server::handleConnectFinished(std::shared_ptr<LinkLocalConnector> connector, bool error) { + if (error) { + SWIFT_LOG(warning) << "Error connecting" << std::endl; + // TODO: Send back queued stanzas + } + else { + std::shared_ptr<OutgoingLinkLocalSession> outgoingSession( + new OutgoingLinkLocalSession( + selfJID, connector->getService().getJID(), connector->getConnection(), + &payloadParserFactories, &payloadSerializers, &xmlParserFactory)); + for (const auto& element : connector->getQueuedElements()) { + outgoingSession->queueElement(element); + } + registerLinkLocalSession(outgoingSession); + } + connectors.erase(std::remove(connectors.begin(), connectors.end(), connector), connectors.end()); } -void Server::registerLinkLocalSession(boost::shared_ptr<Session> session) { - session->onSessionFinished.connect( - boost::bind(&Server::handleLinkLocalSessionFinished, this, session)); - session->onElementReceived.connect( - boost::bind(&Server::handleLinkLocalElementReceived, this, _1, session)); - linkLocalSessions.push_back(session); - //tracers.push_back(boost::make_shared<SessionTracer>(session)); - session->startSession(); +void Server::registerLinkLocalSession(std::shared_ptr<Session> session) { + session->onSessionFinished.connect( + boost::bind(&Server::handleLinkLocalSessionFinished, this, session)); + session->onElementReceived.connect( + boost::bind(&Server::handleLinkLocalElementReceived, this, _1, session)); + linkLocalSessions.push_back(session); + //tracers.push_back(std::make_shared<SessionTracer>(session)); + session->startSession(); } -boost::shared_ptr<Session> Server::getLinkLocalSessionForJID(const JID& jid) { - foreach(const boost::shared_ptr<Session> session, linkLocalSessions) { - if (session->getRemoteJID() == jid) { - return session; - } - } - return boost::shared_ptr<Session>(); +std::shared_ptr<Session> Server::getLinkLocalSessionForJID(const JID& jid) { + for (const auto& session : linkLocalSessions) { + if (session->getRemoteJID() == jid) { + return session; + } + } + return std::shared_ptr<Session>(); } -boost::shared_ptr<LinkLocalConnector> Server::getLinkLocalConnectorForJID(const JID& jid) { - foreach(const boost::shared_ptr<LinkLocalConnector> connector, connectors) { - if (connector->getService().getJID() == jid) { - return connector; - } - } - return boost::shared_ptr<LinkLocalConnector>(); +std::shared_ptr<LinkLocalConnector> Server::getLinkLocalConnectorForJID(const JID& jid) { + for (const auto& connector : connectors) { + if (connector->getService().getJID() == jid) { + return connector; + } + } + return std::shared_ptr<LinkLocalConnector>(); } void Server::handleServiceRegistered(const DNSSDServiceID& service) { - selfJID = JID(service.getName()); + selfJID = JID(service.getName()); } -void Server::handleRosterChanged(boost::shared_ptr<RosterPayload> roster) { - if (rosterRequested) { - assert(serverFromClientSession); - boost::shared_ptr<IQ> iq = IQ::createRequest( - IQ::Set, serverFromClientSession->getRemoteJID(), - idGenerator.generateID(), roster); - iq->setFrom(serverFromClientSession->getRemoteJID().toBare()); - serverFromClientSession->sendElement(iq); - } +void Server::handleRosterChanged(std::shared_ptr<RosterPayload> roster) { + if (rosterRequested) { + assert(serverFromClientSession); + std::shared_ptr<IQ> iq = IQ::createRequest( + IQ::Set, serverFromClientSession->getRemoteJID(), + idGenerator.generateID(), roster); + iq->setFrom(serverFromClientSession->getRemoteJID().toBare()); + serverFromClientSession->sendElement(iq); + } } -void Server::handlePresenceChanged(boost::shared_ptr<Presence> presence) { - if (rosterRequested) { - serverFromClientSession->sendElement(presence); - } +void Server::handlePresenceChanged(std::shared_ptr<Presence> presence) { + if (rosterRequested) { + serverFromClientSession->sendElement(presence); + } } void Server::handleClientConnectionServerStopped(boost::optional<BoostConnectionServer::Error> e) { - if (e) { - if (*e == BoostConnectionServer::Conflict) { - stop(ServerError(ServerError::C2SPortConflict)); - } - else { - stop(ServerError(ServerError::C2SError)); - } - } - else { - stop(); - } + if (e) { + if (*e == BoostConnectionServer::Conflict) { + stop(ServerError(ServerError::C2SPortConflict)); + } + else { + stop(ServerError(ServerError::C2SError)); + } + } + else { + stop(); + } } void Server::handleLinkLocalConnectionServerStopped(boost::optional<BoostConnectionServer::Error> e) { - if (e) { - if (*e == BoostConnectionServer::Conflict) { - stop(ServerError(ServerError::LinkLocalPortConflict)); - } - else { - stop(ServerError(ServerError::LinkLocalError)); - } - } - else { - stop(); - } + if (e) { + if (*e == BoostConnectionServer::Conflict) { + stop(ServerError(ServerError::LinkLocalPortConflict)); + } + else { + stop(ServerError(ServerError::LinkLocalError)); + } + } + else { + stop(); + } } -LinkLocalServiceInfo Server::getLinkLocalServiceInfo(boost::shared_ptr<Presence> presence) { - LinkLocalServiceInfo info; - boost::shared_ptr<VCard> vcard = vCardCollection->getOwnVCard(); - if (!vcard->getFamilyName().empty() || !vcard->getGivenName().empty()) { - info.setFirstName(vcard->getGivenName()); - info.setLastName(vcard->getFamilyName()); - } - else if (!vcard->getFullName().empty()) { - std::pair<std::string,std::string> p = String::getSplittedAtFirst(vcard->getFullName(), ' '); - info.setFirstName(p.first); - info.setLastName(p.second); - } - if (!vcard->getNickname().empty()) { - info.setNick(vcard->getNickname()); - } - if (!vcard->getPreferredEMailAddress().address.empty()) { - info.setEMail(vcard->getPreferredEMailAddress().address); - } - info.setMessage(presence->getStatus()); - switch (presence->getShow()) { - case StatusShow::Online: - case StatusShow::None: - case StatusShow::FFC: - info.setStatus(LinkLocalServiceInfo::Available); - break; - case StatusShow::Away: - case StatusShow::XA: - info.setStatus(LinkLocalServiceInfo::Away); - break; - case StatusShow::DND: - info.setStatus(LinkLocalServiceInfo::DND); - break; - } - info.setPort(linkLocalConnectionPort); - return info; +LinkLocalServiceInfo Server::getLinkLocalServiceInfo(std::shared_ptr<Presence> presence) { + LinkLocalServiceInfo info; + std::shared_ptr<VCard> vcard = vCardCollection->getOwnVCard(); + if (!vcard->getFamilyName().empty() || !vcard->getGivenName().empty()) { + info.setFirstName(vcard->getGivenName()); + info.setLastName(vcard->getFamilyName()); + } + else if (!vcard->getFullName().empty()) { + std::pair<std::string,std::string> p = String::getSplittedAtFirst(vcard->getFullName(), ' '); + info.setFirstName(p.first); + info.setLastName(p.second); + } + if (!vcard->getNickname().empty()) { + info.setNick(vcard->getNickname()); + } + if (!vcard->getPreferredEMailAddress().address.empty()) { + info.setEMail(vcard->getPreferredEMailAddress().address); + } + info.setMessage(presence->getStatus()); + switch (presence->getShow()) { + case StatusShow::Online: + case StatusShow::None: + case StatusShow::FFC: + info.setStatus(LinkLocalServiceInfo::Available); + break; + case StatusShow::Away: + case StatusShow::XA: + info.setStatus(LinkLocalServiceInfo::Away); + break; + case StatusShow::DND: + info.setStatus(LinkLocalServiceInfo::DND); + break; + } + info.setPort(linkLocalConnectionPort); + return info; } } diff --git a/Slimber/Server.h b/Slimber/Server.h index ef3b298..4842cd9 100644 --- a/Slimber/Server.h +++ b/Slimber/Server.h @@ -1,123 +1,126 @@ /* - * Copyright (c) 2010-2014 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> -#include <boost/optional.hpp> +#include <memory> #include <vector> -#include "Swiften/Network/BoostIOServiceThread.h" -#include "Swiften/Network/BoostConnectionServer.h" -#include "Limber/Server/UserRegistry.h" -#include "Swiften/Base/IDGenerator.h" -#include "Swiften/Parser/PlatformXMLParserFactory.h" -#include "Limber/Server/ServerFromClientSession.h" -#include "Swiften/JID/JID.h" -#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h" -#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h" -#include "Swiften/LinkLocal/LinkLocalServiceInfo.h" -#include "Slimber/ServerError.h" +#include <boost/optional.hpp> + +#include <Swiften/Base/IDGenerator.h> +#include <Swiften/JID/JID.h> +#include <Swiften/LinkLocal/LinkLocalServiceInfo.h> +#include <Swiften/Network/BoostConnectionServer.h> +#include <Swiften/Network/BoostIOServiceThread.h> +#include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h> +#include <Swiften/Parser/PlatformXMLParserFactory.h> +#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> + +#include <Limber/Server/ServerFromClientSession.h> +#include <Limber/Server/UserRegistry.h> + +#include <Slimber/ServerError.h> namespace Swift { - class DNSSDServiceID; - - class VCardCollection; - class LinkLocalConnector; - class LinkLocalServiceBrowser; - class LinkLocalPresenceManager; - class BoostConnectionServer; - class SessionTracer; - class RosterPayload; - class Presence; - class EventLoop; - - class Server { - public: - Server( - int clientConnectionPort, - int linkLocalConnectionPort, - LinkLocalServiceBrowser* browser, - VCardCollection* vCardCollection, - EventLoop* eventLoop); - ~Server(); - - void start(); - void stop(); - - int getLinkLocalPort() const { - return linkLocalConnectionPort; - } - - int getClientToServerPort() const { - return clientConnectionPort; - } - - boost::signal<void (bool)> onSelfConnected; - boost::signal<void (boost::optional<ServerError>)> onStopped; - - private: - void stop(boost::optional<ServerError>); - - void handleNewClientConnection(boost::shared_ptr<Connection> c); - void handleSessionStarted(); - void handleSessionFinished(boost::shared_ptr<ServerFromClientSession>); - void handleElementReceived(boost::shared_ptr<ToplevelElement> element, boost::shared_ptr<ServerFromClientSession> session); - void handleRosterChanged(boost::shared_ptr<RosterPayload> roster); - void handlePresenceChanged(boost::shared_ptr<Presence> presence); - void handleServiceRegistered(const DNSSDServiceID& service); - void handleNewLinkLocalConnection(boost::shared_ptr<Connection> connection); - void handleLinkLocalSessionFinished(boost::shared_ptr<Session> session); - void handleLinkLocalElementReceived(boost::shared_ptr<ToplevelElement> element, boost::shared_ptr<Session> session); - void handleConnectFinished(boost::shared_ptr<LinkLocalConnector> connector, bool error); - void handleClientConnectionServerStopped( - boost::optional<BoostConnectionServer::Error>); - void handleLinkLocalConnectionServerStopped( - boost::optional<BoostConnectionServer::Error>); - boost::shared_ptr<Session> getLinkLocalSessionForJID(const JID& jid); - boost::shared_ptr<LinkLocalConnector> getLinkLocalConnectorForJID(const JID& jid); - void registerLinkLocalSession(boost::shared_ptr<Session> session); - void unregisterService(); - LinkLocalServiceInfo getLinkLocalServiceInfo(boost::shared_ptr<Presence> presence); - - private: - class DummyUserRegistry : public UserRegistry { - public: - DummyUserRegistry() {} - - virtual bool isValidUserPassword(const JID&, const SafeByteArray&) const { - return true; - } - }; - - private: - IDGenerator idGenerator; - FullPayloadParserFactoryCollection payloadParserFactories; - FullPayloadSerializerCollection payloadSerializers; - BoostIOServiceThread boostIOServiceThread; - DummyUserRegistry userRegistry; - PlatformXMLParserFactory xmlParserFactory; - bool linkLocalServiceRegistered; - bool rosterRequested; - int clientConnectionPort; - int linkLocalConnectionPort; - LinkLocalServiceBrowser* linkLocalServiceBrowser; - VCardCollection* vCardCollection; - EventLoop* eventLoop; - LinkLocalPresenceManager* presenceManager; - bool stopping; - boost::shared_ptr<BoostConnectionServer> serverFromClientConnectionServer; - std::vector<boost::bsignals::connection> serverFromClientConnectionServerSignalConnections; - boost::shared_ptr<ServerFromClientSession> serverFromClientSession; - boost::shared_ptr<Presence> lastPresence; - JID selfJID; - boost::shared_ptr<BoostConnectionServer> serverFromNetworkConnectionServer; - std::vector<boost::bsignals::connection> serverFromNetworkConnectionServerSignalConnections; - std::vector< boost::shared_ptr<Session> > linkLocalSessions; - std::vector< boost::shared_ptr<LinkLocalConnector> > connectors; - std::vector< boost::shared_ptr<SessionTracer> > tracers; - }; + class DNSSDServiceID; + + class VCardCollection; + class LinkLocalConnector; + class LinkLocalServiceBrowser; + class LinkLocalPresenceManager; + class BoostConnectionServer; + class SessionTracer; + class RosterPayload; + class Presence; + class EventLoop; + + class Server { + public: + Server( + int clientConnectionPort, + int linkLocalConnectionPort, + LinkLocalServiceBrowser* browser, + VCardCollection* vCardCollection, + EventLoop* eventLoop); + ~Server(); + + void start(); + void stop(); + + int getLinkLocalPort() const { + return linkLocalConnectionPort; + } + + int getClientToServerPort() const { + return clientConnectionPort; + } + + boost::signals2::signal<void (bool)> onSelfConnected; + boost::signals2::signal<void (boost::optional<ServerError>)> onStopped; + + private: + void stop(boost::optional<ServerError>); + + void handleNewClientConnection(std::shared_ptr<Connection> c); + void handleSessionStarted(); + void handleSessionFinished(std::shared_ptr<ServerFromClientSession>); + void handleElementReceived(std::shared_ptr<ToplevelElement> element, std::shared_ptr<ServerFromClientSession> session); + void handleRosterChanged(std::shared_ptr<RosterPayload> roster); + void handlePresenceChanged(std::shared_ptr<Presence> presence); + void handleServiceRegistered(const DNSSDServiceID& service); + void handleNewLinkLocalConnection(std::shared_ptr<Connection> connection); + void handleLinkLocalSessionFinished(std::shared_ptr<Session> session); + void handleLinkLocalElementReceived(std::shared_ptr<ToplevelElement> element, std::shared_ptr<Session> session); + void handleConnectFinished(std::shared_ptr<LinkLocalConnector> connector, bool error); + void handleClientConnectionServerStopped( + boost::optional<BoostConnectionServer::Error>); + void handleLinkLocalConnectionServerStopped( + boost::optional<BoostConnectionServer::Error>); + std::shared_ptr<Session> getLinkLocalSessionForJID(const JID& jid); + std::shared_ptr<LinkLocalConnector> getLinkLocalConnectorForJID(const JID& jid); + void registerLinkLocalSession(std::shared_ptr<Session> session); + void unregisterService(); + LinkLocalServiceInfo getLinkLocalServiceInfo(std::shared_ptr<Presence> presence); + + private: + class DummyUserRegistry : public UserRegistry { + public: + DummyUserRegistry() {} + + virtual bool isValidUserPassword(const JID&, const SafeByteArray&) const { + return true; + } + }; + + private: + IDGenerator idGenerator; + FullPayloadParserFactoryCollection payloadParserFactories; + FullPayloadSerializerCollection payloadSerializers; + BoostIOServiceThread boostIOServiceThread; + DummyUserRegistry userRegistry; + PlatformXMLParserFactory xmlParserFactory; + bool linkLocalServiceRegistered; + bool rosterRequested; + int clientConnectionPort; + int linkLocalConnectionPort; + LinkLocalServiceBrowser* linkLocalServiceBrowser; + VCardCollection* vCardCollection; + EventLoop* eventLoop; + LinkLocalPresenceManager* presenceManager; + bool stopping; + std::shared_ptr<BoostConnectionServer> serverFromClientConnectionServer; + std::vector<boost::signals2::connection> serverFromClientConnectionServerSignalConnections; + std::shared_ptr<ServerFromClientSession> serverFromClientSession; + std::shared_ptr<Presence> lastPresence; + JID selfJID; + std::shared_ptr<BoostConnectionServer> serverFromNetworkConnectionServer; + std::vector<boost::signals2::connection> serverFromNetworkConnectionServerSignalConnections; + std::vector< std::shared_ptr<Session> > linkLocalSessions; + std::vector< std::shared_ptr<LinkLocalConnector> > connectors; + std::vector< std::shared_ptr<SessionTracer> > tracers; + }; } diff --git a/Slimber/ServerError.h b/Slimber/ServerError.h index b8cb0a5..93b6a3f 100644 --- a/Slimber/ServerError.h +++ b/Slimber/ServerError.h @@ -9,29 +9,29 @@ #include <string> namespace Swift { - class ServerError { - public: - enum Type { - C2SPortConflict, - C2SError, - LinkLocalPortConflict, - LinkLocalError - }; + class ServerError { + public: + enum Type { + C2SPortConflict, + C2SError, + LinkLocalPortConflict, + LinkLocalError + }; - ServerError(Type type, const std::string& message = std::string()) : - type(type), message(message) { - } + ServerError(Type type, const std::string& message = std::string()) : + type(type), message(message) { + } - Type getType() const { - return type; - } + Type getType() const { + return type; + } - const std::string& getMessage() const { - return message; - } + const std::string& getMessage() const { + return message; + } - private: - Type type; - std::string message; - }; + private: + Type type; + std::string message; + }; } diff --git a/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp b/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp index 9a7adf0..c8e7700 100644 --- a/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp +++ b/Slimber/UnitTest/LinkLocalPresenceManagerTest.cpp @@ -1,261 +1,264 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ +#include <map> + +#include <boost/bind.hpp> + #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include <boost/bind.hpp> -#include <map> #include <Swiften/Elements/Presence.h> -#include <Swiften/Elements/RosterPayload.h> #include <Swiften/Elements/RosterItemPayload.h> -#include "Slimber/LinkLocalPresenceManager.h" -#include <Swiften/LinkLocal/LinkLocalServiceInfo.h> -#include <Swiften/LinkLocal/LinkLocalServiceBrowser.h> -#include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h> +#include <Swiften/Elements/RosterPayload.h> +#include <Swiften/EventLoop/DummyEventLoop.h> #include <Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h> +#include <Swiften/LinkLocal/DNSSD/DNSSDServiceID.h> #include <Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h> -#include <Swiften/EventLoop/DummyEventLoop.h> +#include <Swiften/LinkLocal/LinkLocalServiceBrowser.h> +#include <Swiften/LinkLocal/LinkLocalServiceInfo.h> + +#include <Slimber/LinkLocalPresenceManager.h> using namespace Swift; class LinkLocalPresenceManagerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(LinkLocalPresenceManagerTest); - CPPUNIT_TEST(testConstructor); - CPPUNIT_TEST(testServiceAdded); - CPPUNIT_TEST(testServiceRemoved); - CPPUNIT_TEST(testServiceChanged); - CPPUNIT_TEST(testGetRoster); - CPPUNIT_TEST(testGetAllPresence); - CPPUNIT_TEST(testGetRoster_InfoWithNick); - CPPUNIT_TEST(testGetRoster_InfoWithFirstName); - CPPUNIT_TEST(testGetRoster_InfoWithLastName); - CPPUNIT_TEST(testGetRoster_InfoWithFirstAndLastName); - CPPUNIT_TEST(testGetRoster_NoInfo); - CPPUNIT_TEST(testGetServiceForJID); - CPPUNIT_TEST(testGetServiceForJID_NoMatch); - CPPUNIT_TEST_SUITE_END(); - - public: - void setUp() { - eventLoop = new DummyEventLoop(); - querier = boost::make_shared<FakeDNSSDQuerier>("wonderland.lit", eventLoop); - browser = new LinkLocalServiceBrowser(querier); - browser->start(); - } - - void tearDown() { - browser->stop(); - delete browser; - delete eventLoop; - } - - void testConstructor() { - addService("alice@wonderland"); - addService("rabbit@teaparty"); - boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); - - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(testling->getRoster()->getItems().size())); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(testling->getAllPresence().size())); - } - - void testServiceAdded() { - boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); - - addService("alice@wonderland", "Alice"); - - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(rosterChanges.size())); - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(rosterChanges[0]->getItems().size())); - boost::optional<RosterItemPayload> item = rosterChanges[0]->getItem(JID("alice@wonderland")); - CPPUNIT_ASSERT(item); - CPPUNIT_ASSERT_EQUAL(std::string("Alice"), item->getName()); - CPPUNIT_ASSERT_EQUAL(RosterItemPayload::Both, item->getSubscription()); - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(presenceChanges.size())); - CPPUNIT_ASSERT(StatusShow::Online == presenceChanges[0]->getShow()); - CPPUNIT_ASSERT(JID("alice@wonderland") == presenceChanges[0]->getFrom()); - } - - void testServiceRemoved() { - boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); - - addService("alice@wonderland"); - removeService("alice@wonderland"); - - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(rosterChanges.size())); - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(rosterChanges[1]->getItems().size())); - boost::optional<RosterItemPayload> item = rosterChanges[1]->getItem(JID("alice@wonderland")); - CPPUNIT_ASSERT(item); - CPPUNIT_ASSERT_EQUAL(RosterItemPayload::Remove, item->getSubscription()); - } - - void testServiceChanged() { - boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); - - addService("alice@wonderland"); - updateServicePresence("alice@wonderland", LinkLocalServiceInfo::Away, "I'm Away"); - - CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(rosterChanges.size())); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(presenceChanges.size())); - CPPUNIT_ASSERT(StatusShow::Away == presenceChanges[1]->getShow()); - CPPUNIT_ASSERT(JID("alice@wonderland") == presenceChanges[1]->getFrom()); - CPPUNIT_ASSERT_EQUAL(std::string("I'm Away"), presenceChanges[1]->getStatus()); - } - - void testGetAllPresence() { - boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); - - addService("alice@wonderland"); - addService("rabbit@teaparty"); - updateServicePresence("rabbit@teaparty", LinkLocalServiceInfo::Away, "Partying"); - - std::vector<boost::shared_ptr<Presence> > presences = testling->getAllPresence(); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(presences.size())); - // The order doesn't matter - CPPUNIT_ASSERT(JID("rabbit@teaparty") == presences[0]->getFrom()); - CPPUNIT_ASSERT(StatusShow::Away == presences[0]->getShow()); - CPPUNIT_ASSERT(JID("alice@wonderland") == presences[1]->getFrom()); - CPPUNIT_ASSERT(StatusShow::Online == presences[1]->getShow()); - } - - void testGetRoster() { - boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); - - addService("alice@wonderland", "Alice"); - addService("rabbit@teaparty", "Rabbit"); - - boost::shared_ptr<RosterPayload> roster = testling->getRoster(); - CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(roster->getItems().size())); - boost::optional<RosterItemPayload> item; - item = roster->getItem(JID("alice@wonderland")); - CPPUNIT_ASSERT(item); - CPPUNIT_ASSERT_EQUAL(std::string("Alice"), item->getName()); - CPPUNIT_ASSERT_EQUAL(RosterItemPayload::Both, item->getSubscription()); - item = roster->getItem(JID("rabbit@teaparty")); - CPPUNIT_ASSERT(item); - CPPUNIT_ASSERT_EQUAL(std::string("Rabbit"), item->getName()); - CPPUNIT_ASSERT_EQUAL(RosterItemPayload::Both, item->getSubscription()); - } - - void testGetRoster_InfoWithNick() { - boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); - - addService("alice@wonderland", "Alice", "Alice In", "Wonderland"); - - boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland")); - CPPUNIT_ASSERT_EQUAL(std::string("Alice"), item->getName()); - } - - void testGetRoster_InfoWithFirstName() { - boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); - - addService("alice@wonderland", "", "Alice In", ""); - - boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland")); - CPPUNIT_ASSERT_EQUAL(std::string("Alice In"), item->getName()); - } - - void testGetRoster_InfoWithLastName() { - boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); - - addService("alice@wonderland", "", "", "Wonderland"); - - boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland")); - CPPUNIT_ASSERT_EQUAL(std::string("Wonderland"), item->getName()); - } - - void testGetRoster_InfoWithFirstAndLastName() { - boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); - - addService("alice@wonderland", "", "Alice In", "Wonderland"); - - boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland")); - CPPUNIT_ASSERT_EQUAL(std::string("Alice In Wonderland"), item->getName()); - } - - void testGetRoster_NoInfo() { - boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); - - addService("alice@wonderland"); - - boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland")); - CPPUNIT_ASSERT_EQUAL(std::string(""), item->getName()); - } - - void testGetServiceForJID() { - boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); - - addService("alice@wonderland"); - addService("rabbit@teaparty"); - addService("queen@garden"); - - boost::optional<LinkLocalService> service = testling->getServiceForJID(JID("rabbit@teaparty")); - CPPUNIT_ASSERT(service); - CPPUNIT_ASSERT_EQUAL(std::string("rabbit@teaparty"), service->getID().getName()); - } - - void testGetServiceForJID_NoMatch() { - boost::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); - - addService("alice@wonderland"); - addService("queen@garden"); - - CPPUNIT_ASSERT(!testling->getServiceForJID(JID("rabbit@teaparty"))); - } - - private: - boost::shared_ptr<LinkLocalPresenceManager> createTestling() { - boost::shared_ptr<LinkLocalPresenceManager> testling( - new LinkLocalPresenceManager(browser)); - testling->onRosterChanged.connect(boost::bind( - &LinkLocalPresenceManagerTest::handleRosterChanged, this, _1)); - testling->onPresenceChanged.connect(boost::bind( - &LinkLocalPresenceManagerTest::handlePresenceChanged, this, _1)); - return testling; - } - - void addService(const std::string& name, const std::string& nickName = std::string(), const std::string& firstName = std::string(), const std::string& lastName = std::string()) { - DNSSDServiceID service(name, "local."); - LinkLocalServiceInfo info; - info.setFirstName(firstName); - info.setLastName(lastName); - info.setNick(nickName); - querier->setServiceInfo(service, DNSSDResolveServiceQuery::Result(name + "._presence._tcp.local", "rabbithole.local", 1234, info.toTXTRecord())); - querier->addService(service); - eventLoop->processEvents(); - } - - void removeService(const std::string& name) { - DNSSDServiceID service(name, "local."); - querier->removeService(DNSSDServiceID(name, "local.")); - eventLoop->processEvents(); - } - - void updateServicePresence(const std::string& name, LinkLocalServiceInfo::Status status, const std::string& message) { - DNSSDServiceID service(name, "local."); - LinkLocalServiceInfo info; - info.setStatus(status); - info.setMessage(message); - querier->setServiceInfo(service, DNSSDResolveServiceQuery::Result(name + "._presence._tcp.local", "rabbithole.local", 1234, info.toTXTRecord())); - eventLoop->processEvents(); - } - - void handleRosterChanged(boost::shared_ptr<RosterPayload> payload) { - rosterChanges.push_back(payload); - } - - void handlePresenceChanged(boost::shared_ptr<Presence> presence) { - presenceChanges.push_back(presence); - } - - private: - DummyEventLoop* eventLoop; - boost::shared_ptr<FakeDNSSDQuerier> querier; - LinkLocalServiceBrowser* browser; - std::vector< boost::shared_ptr<RosterPayload> > rosterChanges; - std::vector< boost::shared_ptr<Presence> > presenceChanges; + CPPUNIT_TEST_SUITE(LinkLocalPresenceManagerTest); + CPPUNIT_TEST(testConstructor); + CPPUNIT_TEST(testServiceAdded); + CPPUNIT_TEST(testServiceRemoved); + CPPUNIT_TEST(testServiceChanged); + CPPUNIT_TEST(testGetRoster); + CPPUNIT_TEST(testGetAllPresence); + CPPUNIT_TEST(testGetRoster_InfoWithNick); + CPPUNIT_TEST(testGetRoster_InfoWithFirstName); + CPPUNIT_TEST(testGetRoster_InfoWithLastName); + CPPUNIT_TEST(testGetRoster_InfoWithFirstAndLastName); + CPPUNIT_TEST(testGetRoster_NoInfo); + CPPUNIT_TEST(testGetServiceForJID); + CPPUNIT_TEST(testGetServiceForJID_NoMatch); + CPPUNIT_TEST_SUITE_END(); + + public: + void setUp() { + eventLoop = new DummyEventLoop(); + querier = std::make_shared<FakeDNSSDQuerier>("wonderland.lit", eventLoop); + browser = new LinkLocalServiceBrowser(querier); + browser->start(); + } + + void tearDown() { + browser->stop(); + delete browser; + delete eventLoop; + } + + void testConstructor() { + addService("alice@wonderland"); + addService("rabbit@teaparty"); + std::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); + + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(testling->getRoster()->getItems().size())); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(testling->getAllPresence().size())); + } + + void testServiceAdded() { + std::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); + + addService("alice@wonderland", "Alice"); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(rosterChanges.size())); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(rosterChanges[0]->getItems().size())); + boost::optional<RosterItemPayload> item = rosterChanges[0]->getItem(JID("alice@wonderland")); + CPPUNIT_ASSERT(item); + CPPUNIT_ASSERT_EQUAL(std::string("Alice"), item->getName()); + CPPUNIT_ASSERT_EQUAL(RosterItemPayload::Both, item->getSubscription()); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(presenceChanges.size())); + CPPUNIT_ASSERT(StatusShow::Online == presenceChanges[0]->getShow()); + CPPUNIT_ASSERT(JID("alice@wonderland") == presenceChanges[0]->getFrom()); + } + + void testServiceRemoved() { + std::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); + + addService("alice@wonderland"); + removeService("alice@wonderland"); + + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(rosterChanges.size())); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(rosterChanges[1]->getItems().size())); + boost::optional<RosterItemPayload> item = rosterChanges[1]->getItem(JID("alice@wonderland")); + CPPUNIT_ASSERT(item); + CPPUNIT_ASSERT_EQUAL(RosterItemPayload::Remove, item->getSubscription()); + } + + void testServiceChanged() { + std::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); + + addService("alice@wonderland"); + updateServicePresence("alice@wonderland", LinkLocalServiceInfo::Away, "I'm Away"); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(rosterChanges.size())); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(presenceChanges.size())); + CPPUNIT_ASSERT(StatusShow::Away == presenceChanges[1]->getShow()); + CPPUNIT_ASSERT(JID("alice@wonderland") == presenceChanges[1]->getFrom()); + CPPUNIT_ASSERT_EQUAL(std::string("I'm Away"), presenceChanges[1]->getStatus()); + } + + void testGetAllPresence() { + std::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); + + addService("alice@wonderland"); + addService("rabbit@teaparty"); + updateServicePresence("rabbit@teaparty", LinkLocalServiceInfo::Away, "Partying"); + + std::vector<std::shared_ptr<Presence> > presences = testling->getAllPresence(); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(presences.size())); + // The order doesn't matter + CPPUNIT_ASSERT(JID("rabbit@teaparty") == presences[0]->getFrom()); + CPPUNIT_ASSERT(StatusShow::Away == presences[0]->getShow()); + CPPUNIT_ASSERT(JID("alice@wonderland") == presences[1]->getFrom()); + CPPUNIT_ASSERT(StatusShow::Online == presences[1]->getShow()); + } + + void testGetRoster() { + std::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); + + addService("alice@wonderland", "Alice"); + addService("rabbit@teaparty", "Rabbit"); + + std::shared_ptr<RosterPayload> roster = testling->getRoster(); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(roster->getItems().size())); + boost::optional<RosterItemPayload> item; + item = roster->getItem(JID("alice@wonderland")); + CPPUNIT_ASSERT(item); + CPPUNIT_ASSERT_EQUAL(std::string("Alice"), item->getName()); + CPPUNIT_ASSERT_EQUAL(RosterItemPayload::Both, item->getSubscription()); + item = roster->getItem(JID("rabbit@teaparty")); + CPPUNIT_ASSERT(item); + CPPUNIT_ASSERT_EQUAL(std::string("Rabbit"), item->getName()); + CPPUNIT_ASSERT_EQUAL(RosterItemPayload::Both, item->getSubscription()); + } + + void testGetRoster_InfoWithNick() { + std::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); + + addService("alice@wonderland", "Alice", "Alice In", "Wonderland"); + + boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland")); + CPPUNIT_ASSERT_EQUAL(std::string("Alice"), item->getName()); + } + + void testGetRoster_InfoWithFirstName() { + std::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); + + addService("alice@wonderland", "", "Alice In", ""); + + boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland")); + CPPUNIT_ASSERT_EQUAL(std::string("Alice In"), item->getName()); + } + + void testGetRoster_InfoWithLastName() { + std::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); + + addService("alice@wonderland", "", "", "Wonderland"); + + boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland")); + CPPUNIT_ASSERT_EQUAL(std::string("Wonderland"), item->getName()); + } + + void testGetRoster_InfoWithFirstAndLastName() { + std::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); + + addService("alice@wonderland", "", "Alice In", "Wonderland"); + + boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland")); + CPPUNIT_ASSERT_EQUAL(std::string("Alice In Wonderland"), item->getName()); + } + + void testGetRoster_NoInfo() { + std::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); + + addService("alice@wonderland"); + + boost::optional<RosterItemPayload> item = testling->getRoster()->getItem(JID("alice@wonderland")); + CPPUNIT_ASSERT_EQUAL(std::string(""), item->getName()); + } + + void testGetServiceForJID() { + std::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); + + addService("alice@wonderland"); + addService("rabbit@teaparty"); + addService("queen@garden"); + + boost::optional<LinkLocalService> service = testling->getServiceForJID(JID("rabbit@teaparty")); + CPPUNIT_ASSERT(service); + CPPUNIT_ASSERT_EQUAL(std::string("rabbit@teaparty"), service->getID().getName()); + } + + void testGetServiceForJID_NoMatch() { + std::shared_ptr<LinkLocalPresenceManager> testling(createTestling()); + + addService("alice@wonderland"); + addService("queen@garden"); + + CPPUNIT_ASSERT(!testling->getServiceForJID(JID("rabbit@teaparty"))); + } + + private: + std::shared_ptr<LinkLocalPresenceManager> createTestling() { + std::shared_ptr<LinkLocalPresenceManager> testling( + new LinkLocalPresenceManager(browser)); + testling->onRosterChanged.connect(boost::bind( + &LinkLocalPresenceManagerTest::handleRosterChanged, this, _1)); + testling->onPresenceChanged.connect(boost::bind( + &LinkLocalPresenceManagerTest::handlePresenceChanged, this, _1)); + return testling; + } + + void addService(const std::string& name, const std::string& nickName = std::string(), const std::string& firstName = std::string(), const std::string& lastName = std::string()) { + DNSSDServiceID service(name, "local."); + LinkLocalServiceInfo info; + info.setFirstName(firstName); + info.setLastName(lastName); + info.setNick(nickName); + querier->setServiceInfo(service, DNSSDResolveServiceQuery::Result(name + "._presence._tcp.local", "rabbithole.local", 1234, info.toTXTRecord())); + querier->addService(service); + eventLoop->processEvents(); + } + + void removeService(const std::string& name) { + DNSSDServiceID service(name, "local."); + querier->removeService(DNSSDServiceID(name, "local.")); + eventLoop->processEvents(); + } + + void updateServicePresence(const std::string& name, LinkLocalServiceInfo::Status status, const std::string& message) { + DNSSDServiceID service(name, "local."); + LinkLocalServiceInfo info; + info.setStatus(status); + info.setMessage(message); + querier->setServiceInfo(service, DNSSDResolveServiceQuery::Result(name + "._presence._tcp.local", "rabbithole.local", 1234, info.toTXTRecord())); + eventLoop->processEvents(); + } + + void handleRosterChanged(std::shared_ptr<RosterPayload> payload) { + rosterChanges.push_back(payload); + } + + void handlePresenceChanged(std::shared_ptr<Presence> presence) { + presenceChanges.push_back(presence); + } + + private: + DummyEventLoop* eventLoop; + std::shared_ptr<FakeDNSSDQuerier> querier; + LinkLocalServiceBrowser* browser; + std::vector< std::shared_ptr<RosterPayload> > rosterChanges; + std::vector< std::shared_ptr<Presence> > presenceChanges; }; CPPUNIT_TEST_SUITE_REGISTRATION(LinkLocalPresenceManagerTest); diff --git a/Slimber/UnitTest/MenuletControllerTest.cpp b/Slimber/UnitTest/MenuletControllerTest.cpp index 39e4c07..e3b46ab 100644 --- a/Slimber/UnitTest/MenuletControllerTest.cpp +++ b/Slimber/UnitTest/MenuletControllerTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -7,149 +7,149 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/extensions/TestFactoryRegistry.h> -#include "Slimber/Menulet.h" -#include "Slimber/MenuletController.h" +#include <Slimber/Menulet.h> +#include <Slimber/MenuletController.h> class MenuletControllerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(MenuletControllerTest); - CPPUNIT_TEST(testConstructor); - CPPUNIT_TEST(testUpdate); - CPPUNIT_TEST(testSetXMPPStatus_Online); - CPPUNIT_TEST(testSetXMPPStatus_Offline); - CPPUNIT_TEST(testSetUserNames); - CPPUNIT_TEST(testSetUserNames_NoUsers); - CPPUNIT_TEST_SUITE_END(); - - public: - void setUp() { - menulet = new FakeMenulet(); - } - - void tearDown() { - delete menulet; - } - - void testConstructor() { - MenuletController testling(menulet); - - CPPUNIT_ASSERT_EQUAL(8, static_cast<int>(menulet->items.size())); - size_t i = 0; - CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("[Offline] "), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("*About*"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("*Restart*"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("*Exit*"), menulet->items[i++]); - } - - void testUpdate() { - MenuletController testling(menulet); - - testling.setXMPPStatus("You are connected", MenuletController::Online); - - CPPUNIT_ASSERT_EQUAL(8, static_cast<int>(menulet->items.size())); - size_t i = 0; - CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("[Online] You are connected"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("*About*"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("*Restart*"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("*Exit*"), menulet->items[i++]); - } - - void testSetXMPPStatus_Online() { - MenuletController testling(menulet); - - testling.setXMPPStatus("You are connected", MenuletController::Online); - - size_t i = 0; - CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("[Online] You are connected"), menulet->items[i++]); - } - - - void testSetXMPPStatus_Offline() { - MenuletController testling(menulet); - - testling.setXMPPStatus("You are not connected", MenuletController::Offline); - - size_t i = 0; - CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("[Offline] You are not connected"), menulet->items[i++]); - } - - void testSetUserNames() { - MenuletController testling(menulet); - - std::vector<std::string> users; - users.push_back("Alice In Wonderland"); - users.push_back("The Mad Hatter"); - testling.setUserNames(users); - - size_t i = 0; - CPPUNIT_ASSERT_EQUAL(std::string("Online users:"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string(" Alice In Wonderland"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string(" The Mad Hatter"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); - } - - void testSetUserNames_NoUsers() { - MenuletController testling(menulet); - - std::vector<std::string> users; - testling.setUserNames(users); - - size_t i = 0; - CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]); - CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); - } - - private: - struct FakeMenulet : public Menulet { - virtual void clear() { - items.clear(); - } - - virtual void addItem(const std::string& name, const std::string& icon = std::string()) { - std::string result; - if (!icon.empty()) { - result += "[" + icon + "] "; - } - result += name; - items.push_back(result); - } - - virtual void addAboutItem() { - items.push_back("*About*"); - } - - virtual void addRestartItem() { - items.push_back("*Restart*"); - } - - virtual void addExitItem() { - items.push_back("*Exit*"); - } - - virtual void addSeparator() { - items.push_back("-"); - } - - virtual void setIcon(const std::string& i) { - icon = i; - } - - std::vector<std::string> items; - std::string icon; - }; - - FakeMenulet* menulet; + CPPUNIT_TEST_SUITE(MenuletControllerTest); + CPPUNIT_TEST(testConstructor); + CPPUNIT_TEST(testUpdate); + CPPUNIT_TEST(testSetXMPPStatus_Online); + CPPUNIT_TEST(testSetXMPPStatus_Offline); + CPPUNIT_TEST(testSetUserNames); + CPPUNIT_TEST(testSetUserNames_NoUsers); + CPPUNIT_TEST_SUITE_END(); + + public: + void setUp() { + menulet = new FakeMenulet(); + } + + void tearDown() { + delete menulet; + } + + void testConstructor() { + MenuletController testling(menulet); + + CPPUNIT_ASSERT_EQUAL(8, static_cast<int>(menulet->items.size())); + size_t i = 0; + CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("[Offline] "), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("*About*"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("*Restart*"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("*Exit*"), menulet->items[i++]); + } + + void testUpdate() { + MenuletController testling(menulet); + + testling.setXMPPStatus("You are connected", MenuletController::Online); + + CPPUNIT_ASSERT_EQUAL(8, static_cast<int>(menulet->items.size())); + size_t i = 0; + CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("[Online] You are connected"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("*About*"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("*Restart*"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("*Exit*"), menulet->items[i++]); + } + + void testSetXMPPStatus_Online() { + MenuletController testling(menulet); + + testling.setXMPPStatus("You are connected", MenuletController::Online); + + size_t i = 0; + CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("[Online] You are connected"), menulet->items[i++]); + } + + + void testSetXMPPStatus_Offline() { + MenuletController testling(menulet); + + testling.setXMPPStatus("You are not connected", MenuletController::Offline); + + size_t i = 0; + CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("[Offline] You are not connected"), menulet->items[i++]); + } + + void testSetUserNames() { + MenuletController testling(menulet); + + std::vector<std::string> users; + users.push_back("Alice In Wonderland"); + users.push_back("The Mad Hatter"); + testling.setUserNames(users); + + size_t i = 0; + CPPUNIT_ASSERT_EQUAL(std::string("Online users:"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string(" Alice In Wonderland"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string(" The Mad Hatter"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); + } + + void testSetUserNames_NoUsers() { + MenuletController testling(menulet); + + std::vector<std::string> users; + testling.setUserNames(users); + + size_t i = 0; + CPPUNIT_ASSERT_EQUAL(std::string("No online users"), menulet->items[i++]); + CPPUNIT_ASSERT_EQUAL(std::string("-"), menulet->items[i++]); + } + + private: + struct FakeMenulet : public Menulet { + virtual void clear() { + items.clear(); + } + + virtual void addItem(const std::string& name, const std::string& icon = std::string()) { + std::string result; + if (!icon.empty()) { + result += "[" + icon + "] "; + } + result += name; + items.push_back(result); + } + + virtual void addAboutItem() { + items.push_back("*About*"); + } + + virtual void addRestartItem() { + items.push_back("*Restart*"); + } + + virtual void addExitItem() { + items.push_back("*Exit*"); + } + + virtual void addSeparator() { + items.push_back("-"); + } + + virtual void setIcon(const std::string& i) { + icon = i; + } + + std::vector<std::string> items; + std::string icon; + }; + + FakeMenulet* menulet; }; CPPUNIT_TEST_SUITE_REGISTRATION(MenuletControllerTest); diff --git a/Slimber/VCardCollection.cpp b/Slimber/VCardCollection.cpp index 15c27b6..b2de6c5 100644 --- a/Slimber/VCardCollection.cpp +++ b/Slimber/VCardCollection.cpp @@ -1,10 +1,10 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ -#include "Slimber/VCardCollection.h" +#include <Slimber/VCardCollection.h> namespace Swift { diff --git a/Slimber/VCardCollection.h b/Slimber/VCardCollection.h index 0e7d27f..50147ec 100644 --- a/Slimber/VCardCollection.h +++ b/Slimber/VCardCollection.h @@ -1,21 +1,21 @@ /* - * Copyright (c) 2010 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <boost/shared_ptr.hpp> +#include <memory> #include <Swiften/Elements/VCard.h> namespace Swift { - class VCardCollection { - public: - virtual ~VCardCollection(); + class VCardCollection { + public: + virtual ~VCardCollection(); - virtual boost::shared_ptr<VCard> getOwnVCard() const = 0; - virtual void setOwnVCard(boost::shared_ptr<VCard> vcard) = 0; - }; + virtual std::shared_ptr<VCard> getOwnVCard() const = 0; + virtual void setOwnVCard(std::shared_ptr<VCard> vcard) = 0; + }; } |