summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-21 14:11:16 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-21 14:11:16 (GMT)
commiteed31ed4b074fc5ee7ef29d6a1f488d589251659 (patch)
treec001bcb24c5a1601ea2b7b2541d215e2ee036035 /Slimber
parent358f741f45ac92d07b923afd51aeb39704277374 (diff)
downloadswift-contrib-eed31ed4b074fc5ee7ef29d6a1f488d589251659.zip
swift-contrib-eed31ed4b074fc5ee7ef29d6a1f488d589251659.tar.bz2
Use VCard to set name.
Diffstat (limited to 'Slimber')
-rw-r--r--Slimber/FileVCardCollection.cpp6
-rw-r--r--Slimber/FileVCardCollection.h1
-rw-r--r--Slimber/Server.cpp30
-rw-r--r--Slimber/Server.h1
-rw-r--r--Slimber/main.cpp9
5 files changed, 35 insertions, 12 deletions
diff --git a/Slimber/FileVCardCollection.cpp b/Slimber/FileVCardCollection.cpp
index 60be5c0..1568b33 100644
--- a/Slimber/FileVCardCollection.cpp
+++ b/Slimber/FileVCardCollection.cpp
@@ -1,14 +1,18 @@
#include "Slimber/FileVCardCollection.h"
+#include "Swiften/Elements/VCard.h"
namespace Swift {
FileVCardCollection::FileVCardCollection(boost::filesystem::path dir) : vcardsPath(dir) {
+ vcard = boost::shared_ptr<VCard>(new VCard());
}
boost::shared_ptr<VCard> FileVCardCollection::getOwnVCard() const {
+ return vcard;
}
-void FileVCardCollection::setOwnVCard(boost::shared_ptr<VCard> vcard) {
+void FileVCardCollection::setOwnVCard(boost::shared_ptr<VCard> v) {
+ vcard = v;
}
}
diff --git a/Slimber/FileVCardCollection.h b/Slimber/FileVCardCollection.h
index dde47df..3d805a8 100644
--- a/Slimber/FileVCardCollection.h
+++ b/Slimber/FileVCardCollection.h
@@ -15,5 +15,6 @@ namespace Swift {
private:
boost::filesystem::path vcardsPath;
+ boost::shared_ptr<VCard> vcard;
};
}
diff --git a/Slimber/Server.cpp b/Slimber/Server.cpp
index c331416..b7c7052 100644
--- a/Slimber/Server.cpp
+++ b/Slimber/Server.cpp
@@ -84,6 +84,7 @@ void Server::handleSessionFinished(boost::shared_ptr<ServerFromClientSession>) {
selfJID_ = JID();
rosterRequested_ = false;
onSelfConnected(false);
+ lastPresence_.reset();
}
void Server::handleLinkLocalSessionFinished(boost::shared_ptr<Session> session) {
@@ -129,6 +130,7 @@ void Server::handleElementReceived(boost::shared_ptr<Element> element, boost::sh
else {
dnsSDService_->updateService(getLinkLocalServiceInfo(presence));
}
+ lastPresence_ = presence;
}
else {
unregisterService();
@@ -148,14 +150,16 @@ void Server::handleElementReceived(boost::shared_ptr<Element> element, boost::sh
session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), Error::Forbidden, Error::Cancel));
}
}
- if (iq->getPayload<VCard>()) {
+ if (boost::shared_ptr<VCard> vcard = iq->getPayload<VCard>()) {
if (iq->getType() == IQ::Get) {
- boost::shared_ptr<VCard> vcard(new VCard());
- vcard->setNickname(iq->getFrom().getNode());
- session->sendElement(IQ::createResult(iq->getFrom(), iq->getID(), vcard));
+ session->sendElement(IQ::createResult(iq->getFrom(), iq->getID(), vCardCollection_->getOwnVCard()));
}
else {
- session->sendElement(IQ::createError(iq->getFrom(), iq->getID(), Error::Forbidden, Error::Cancel));
+ vCardCollection_->setOwnVCard(vcard);
+ session->sendElement(IQ::createResult(iq->getFrom(), iq->getID()));
+ if (lastPresence_) {
+ dnsSDService_->updateService(getLinkLocalServiceInfo(lastPresence_));
+ }
}
}
else {
@@ -259,12 +263,18 @@ void Server::handlePresenceChanged(boost::shared_ptr<Presence> presence) {
LinkLocalServiceInfo Server::getLinkLocalServiceInfo(boost::shared_ptr<Presence> presence) {
LinkLocalServiceInfo info;
- info.setFirstName("Remko");
- info.setLastName("Tron\xc3\xa7on");
- info.setEMail("email@example.com");
- info.setJID(JID("jid@example.com"));
+ boost::shared_ptr<VCard> vcard = vCardCollection_->getOwnVCard();
+ if (!vcard->getFamilyName().isEmpty() || !vcard->getGivenName().isEmpty()) {
+ info.setFirstName(vcard->getGivenName());
+ info.setLastName(vcard->getFamilyName());
+ }
+ if (!vcard->getNickname().isEmpty()) {
+ info.setNick(vcard->getNickname());
+ }
+ if (!vcard->getEMail().isEmpty()) {
+ info.setEMail(vcard->getEMail());
+ }
info.setMessage(presence->getStatus());
- info.setNick("Remko");
switch (presence->getShow()) {
case StatusShow::Online:
case StatusShow::None:
diff --git a/Slimber/Server.h b/Slimber/Server.h
index b85aec8..ac80509 100644
--- a/Slimber/Server.h
+++ b/Slimber/Server.h
@@ -69,6 +69,7 @@ namespace Swift {
boost::shared_ptr<LinkLocalRoster> linkLocalRoster_;
boost::shared_ptr<DNSSDService> dnsSDService_;
VCardCollection* vCardCollection_;
+ boost::shared_ptr<Presence> lastPresence_;
boost::shared_ptr<BoostConnectionServer> serverFromClientConnectionServer_;
boost::shared_ptr<ServerFromClientSession> serverFromClientSession_;
boost::shared_ptr<BoostConnectionServer> serverFromNetworkConnectionServer_;
diff --git a/Slimber/main.cpp b/Slimber/main.cpp
index 31ae15a..40f41c8 100644
--- a/Slimber/main.cpp
+++ b/Slimber/main.cpp
@@ -8,7 +8,10 @@
#include "Swiften/LinkLocal/AvahiDNSSDService.h"
#endif
#include "Slimber/Server.h"
+#include "Slimber/FileVCardCollection.h"
+#include "Swiften/LinkLocal/LinkLocalRoster.h"
#include "Swiften/EventLoop/SimpleEventLoop.h"
+#include "Swiften/Application/Platform/PlatformApplication.h"
using namespace Swift;
@@ -24,7 +27,11 @@ int main() {
new AvahiDNSSDService());
#endif
- Server server(5222, 5562, dnsSDService);
+ boost::shared_ptr<LinkLocalRoster> linkLocalRoster = boost::shared_ptr<LinkLocalRoster>(new LinkLocalRoster(dnsSDService));
+
+ FileVCardCollection vCardCollection(PlatformApplication("Slimber").getSettingsDir());
+
+ Server server(5222, 5562, linkLocalRoster, dnsSDService, &vCardCollection);
eventLoop.run();
return 0;
}