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
parent358f741f45ac92d07b923afd51aeb39704277374 (diff)
downloadswift-contrib-eed31ed4b074fc5ee7ef29d6a1f488d589251659.zip
swift-contrib-eed31ed4b074fc5ee7ef29d6a1f488d589251659.tar.bz2
Use VCard to set name.
-rw-r--r--Makefile.config.in1
-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
-rw-r--r--Swiften/Application/Unix/UnixApplication.h1
-rw-r--r--configure.in2
8 files changed, 38 insertions, 13 deletions
diff --git a/Makefile.config.in b/Makefile.config.in
index ddb409b..f9f3252 100644
--- a/Makefile.config.in
+++ b/Makefile.config.in
@@ -22,6 +22,7 @@ HAVE_EXPAT=@HAVE_EXPAT@
USE_BUNDLED_EXPAT=@USE_BUNDLED_EXPAT@
HAVE_LIBXML=@CONFIG_HAVE_LIBXML@
HAVE_OPENSSL=@CONFIG_HAVE_OPENSSL@
+HAVE_AVAHI=@CONFIG_HAVE_AVAHI@
WIN32=@CONFIG_WIN32@
MACOSX=@CONFIG_MACOSX@
BUILD_SWIFT=@BUILD_SWIFT@
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;
}
diff --git a/Swiften/Application/Unix/UnixApplication.h b/Swiften/Application/Unix/UnixApplication.h
index d087bd8..c2671d8 100644
--- a/Swiften/Application/Unix/UnixApplication.h
+++ b/Swiften/Application/Unix/UnixApplication.h
@@ -10,7 +10,6 @@ namespace Swift {
UnixApplication(const String& name) : Application(name) {
}
- private:
virtual ApplicationMessageDisplay* getApplicationMessageDisplay() {
return &messageDisplay_;
}
diff --git a/configure.in b/configure.in
index 7fa6c26..30eef85 100644
--- a/configure.in
+++ b/configure.in
@@ -13,6 +13,7 @@ AC_CANONICAL_HOST
AH_TEMPLATE(HAVE_OPENSSL, [OpenSSL library available])
AH_TEMPLATE(HAVE_LIBXML, [LibXML library available])
AH_TEMPLATE(HAVE_EXPAT, [Expat library available])
+AH_TEMPLATE(HAVE_AVAHI, [Avahi library available])
################################################################################
# Default flags
@@ -215,6 +216,7 @@ echo
AC_SUBST(SET_MAKE)
AC_SUBST(HAVE_EXPAT)
+AC_SUBST(HAVE_AVAHI)
AC_SUBST(CONFIG_CXX)
AC_SUBST(CONFIG_CXXFLAGS)
AC_SUBST(CONFIG_CC)