handleVCardRequired callback
This commit is contained in:
parent
fed0082d50
commit
098f6a995a
6 changed files with 53 additions and 14 deletions
|
@ -37,6 +37,7 @@ class Buddy;
|
|||
class LocalBuddy;
|
||||
class Config;
|
||||
class NetworkConversation;
|
||||
class VCardResponder;
|
||||
|
||||
class NetworkPluginServer {
|
||||
public:
|
||||
|
@ -71,6 +72,8 @@ class NetworkPluginServer {
|
|||
void handleUserReadyToConnect(User *user);
|
||||
void handleUserDestroyed(User *user);
|
||||
|
||||
void handleVCardRequired(User *user, const std::string &name, unsigned int id);
|
||||
|
||||
void send(boost::shared_ptr<Swift::Connection> &, const std::string &data);
|
||||
|
||||
void pingTimeout();
|
||||
|
@ -78,6 +81,7 @@ class NetworkPluginServer {
|
|||
Client *getFreeClient();
|
||||
|
||||
UserManager *m_userManager;
|
||||
VCardResponder *m_vcardResponder;
|
||||
Config *m_config;
|
||||
boost::shared_ptr<Swift::ConnectionServer> m_server;
|
||||
std::list<Client *> m_clients;
|
||||
|
|
|
@ -31,7 +31,6 @@ class Component;
|
|||
class StorageBackend;
|
||||
class StorageResponder;
|
||||
class RosterResponder;
|
||||
class VCardResponder;
|
||||
|
||||
/// Manages online XMPP Users.
|
||||
|
||||
|
@ -85,7 +84,6 @@ class UserManager {
|
|||
StorageBackend *m_storageBackend;
|
||||
StorageResponder *m_storageResponder;
|
||||
RosterResponder *m_rosterResponder;
|
||||
VCardResponder *m_vcardResponder;
|
||||
friend class RosterResponder;
|
||||
};
|
||||
|
||||
|
|
|
@ -29,18 +29,29 @@ namespace Transport {
|
|||
|
||||
class StorageBackend;
|
||||
class UserManager;
|
||||
class User;
|
||||
|
||||
class VCardResponder : public Swift::Responder<Swift::VCard> {
|
||||
public:
|
||||
VCardResponder(Swift::IQRouter *router, StorageBackend *storageBackend, UserManager *userManager);
|
||||
VCardResponder(Swift::IQRouter *router, UserManager *userManager);
|
||||
~VCardResponder();
|
||||
boost::signal<void (const Swift::JID& from, const Swift::JID& to, const std::string& id)> onVCardRequired;
|
||||
|
||||
void sendVCard(unsigned int id, boost::shared_ptr<Swift::VCard> vcard);
|
||||
|
||||
boost::signal<void (User *, const std::string &name, unsigned int id)> onVCardRequired;
|
||||
|
||||
private:
|
||||
struct VCardData {
|
||||
Swift::JID from;
|
||||
Swift::JID to;
|
||||
std::string id;
|
||||
};
|
||||
|
||||
virtual bool handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::VCard> payload);
|
||||
virtual bool handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::VCard> payload);
|
||||
StorageBackend *m_storageBackend;
|
||||
UserManager *m_userManager;
|
||||
std::map<unsigned int, VCardData> m_queries;
|
||||
unsigned int m_id;
|
||||
};
|
||||
|
||||
}
|
|
@ -28,6 +28,7 @@
|
|||
#include "transport/localbuddy.h"
|
||||
#include "transport/config.h"
|
||||
#include "transport/conversation.h"
|
||||
#include "transport/vcardresponder.h"
|
||||
#include "Swiften/Swiften.h"
|
||||
#include "Swiften/Server/ServerStanzaChannel.h"
|
||||
#include "Swiften/Elements/StreamError.h"
|
||||
|
@ -118,6 +119,10 @@ NetworkPluginServer::NetworkPluginServer(Component *component, Config *config, U
|
|||
m_pingTimer = component->getFactories()->getTimerFactory()->createTimer(10000);
|
||||
m_pingTimer->onTick.connect(boost::bind(&NetworkPluginServer::pingTimeout, this));
|
||||
|
||||
m_vcardResponder = new VCardResponder(component->getIQRouter(), userManager);
|
||||
m_vcardResponder->onVCardRequired.connect(boost::bind(&NetworkPluginServer::handleVCardRequired, this, _1, _2, _3));
|
||||
m_vcardResponder->start();
|
||||
|
||||
m_server = component->getFactories()->getConnectionFactory()->createConnectionServer(10000);
|
||||
m_server->onNewConnection.connect(boost::bind(&NetworkPluginServer::handleNewClientConnection, this, _1));
|
||||
m_server->start();
|
||||
|
@ -129,6 +134,7 @@ NetworkPluginServer::NetworkPluginServer(Component *component, Config *config, U
|
|||
|
||||
NetworkPluginServer::~NetworkPluginServer() {
|
||||
m_pingTimer->stop();
|
||||
delete m_vcardResponder;
|
||||
}
|
||||
|
||||
void NetworkPluginServer::handleNewClientConnection(boost::shared_ptr<Swift::Connection> c) {
|
||||
|
@ -480,6 +486,10 @@ void NetworkPluginServer::handleMessageReceived(NetworkConversation *conv, boost
|
|||
send(c->connection, message);
|
||||
}
|
||||
|
||||
void NetworkPluginServer::handleVCardRequired(User *user, const std::string &name, unsigned int id) {
|
||||
|
||||
}
|
||||
|
||||
void NetworkPluginServer::sendPing(Client *c) {
|
||||
|
||||
std::string message;
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include "transport/rostermanager.h"
|
||||
#include "storageresponder.h"
|
||||
#include "rosterresponder.h"
|
||||
#include "vcardresponder.h"
|
||||
|
||||
namespace Transport {
|
||||
|
||||
|
@ -42,9 +41,6 @@ UserManager::UserManager(Component *component, StorageBackend *storageBackend) {
|
|||
m_rosterResponder = new RosterResponder(component->getIQRouter(), m_storageBackend, this);
|
||||
m_rosterResponder->start();
|
||||
|
||||
m_vcardResponder = new VCardResponder(component->getIQRouter(), m_storageBackend, this);
|
||||
m_vcardResponder->start();
|
||||
|
||||
component->onUserPresenceReceived.connect(bind(&UserManager::handlePresence, this, _1));
|
||||
m_component->getStanzaChannel()->onMessageReceived.connect(bind(&UserManager::handleMessageReceived, this, _1));
|
||||
m_component->getStanzaChannel()->onPresenceReceived.connect(bind(&UserManager::handleGeneralPresenceReceived, this, _1));
|
||||
|
@ -55,7 +51,6 @@ UserManager::~UserManager(){
|
|||
m_storageResponder->stop();
|
||||
delete m_storageResponder;
|
||||
delete m_rosterResponder;
|
||||
delete m_vcardResponder;
|
||||
}
|
||||
|
||||
void UserManager::addUser(User *user) {
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
|
||||
*/
|
||||
|
||||
#include "vcardresponder.h"
|
||||
#include "transport/vcardresponder.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/bind.hpp>
|
||||
|
@ -33,18 +33,39 @@ using namespace boost;
|
|||
|
||||
namespace Transport {
|
||||
|
||||
VCardResponder::VCardResponder(Swift::IQRouter *router, StorageBackend *storageBackend, UserManager *userManager) : Swift::Responder<VCard>(router) {
|
||||
m_storageBackend = storageBackend;
|
||||
VCardResponder::VCardResponder(Swift::IQRouter *router, UserManager *userManager) : Swift::Responder<VCard>(router) {
|
||||
m_id = 0;
|
||||
m_userManager = userManager;
|
||||
}
|
||||
|
||||
VCardResponder::~VCardResponder() {
|
||||
}
|
||||
|
||||
void VCardResponder::sendVCard(unsigned int id, boost::shared_ptr<Swift::VCard> vcard) {
|
||||
if (m_queries.find(id) == m_queries.end())
|
||||
return;
|
||||
|
||||
sendResponse(m_queries[id].to, m_queries[id].from, m_queries[id].id, vcard);
|
||||
m_queries.erase(id);
|
||||
}
|
||||
|
||||
bool VCardResponder::handleGetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::VCard> payload) {
|
||||
// Get means we're in server mode and user wants to fetch his roster.
|
||||
// For now we send empty reponse, but TODO: Get buddies from database and send proper stored roster.
|
||||
onVCardRequired(from, to, id);
|
||||
User *user = m_userManager->getUser(from.toBare().toString());
|
||||
if (!user) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string name = to.getUnescapedNode();
|
||||
if (name.find_last_of("%") != std::string::npos) {
|
||||
name.replace(name.find_last_of("%"), 1, "@");
|
||||
}
|
||||
|
||||
m_queries[m_id].from = from;
|
||||
m_queries[m_id].to = to;
|
||||
m_queries[m_id].id = id;
|
||||
onVCardRequired(user, name, m_id++);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue