Slack frontend stub

This commit is contained in:
Jan Kaluza 2015-11-19 16:51:12 +01:00
parent 8f1f90064c
commit f2a6ba12fc
13 changed files with 652 additions and 10 deletions

View file

@ -158,9 +158,9 @@ else()
endif()
# Reconfigure final output directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Binaries)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Binaries)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Binaries)
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Binaries)
# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Binaries)
# set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Binaries)
# These settings can be used by the test targets
set(Casablanca_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)

View file

@ -0,0 +1,111 @@
/**
* Spectrum 2 Slack Frontend
*
* Copyright (C) 2015, Jan Kaluza <hanzz.k@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#include "SlackFrontend.h"
#include "SlackRosterManager.h"
#include "SlackUser.h"
#include "SlackUserManager.h"
#include "transport/StorageBackend.h"
#include "transport/Factory.h"
#include "transport/UserRegistry.h"
#include "transport/Logging.h"
#include "transport/Config.h"
#include "transport/Transport.h"
#include <boost/bind.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/algorithm/string/predicate.hpp>
using namespace boost;
namespace Transport {
DEFINE_LOGGER(logger, "SlackFrontend");
SlackFrontend::SlackFrontend() {
}
void SlackFrontend::init(Component *transport, Swift::EventLoop *loop, Swift::NetworkFactories *factories, Config *config, Transport::UserRegistry *userRegistry) {
m_transport = transport;
m_config = transport->getConfig();
m_jid = Swift::JID(CONFIG_STRING(m_config, "service.jid"));
}
SlackFrontend::~SlackFrontend() {
}
void SlackFrontend::clearRoomList() {
}
void SlackFrontend::addRoomToRoomList(const std::string &handle, const std::string &name) {
}
void SlackFrontend::sendPresence(Swift::Presence::ref presence) {
}
void SlackFrontend::sendVCard(Swift::VCard::ref vcard, Swift::JID to) {
}
void SlackFrontend::sendRosterRequest(Swift::RosterPayload::ref payload, Swift::JID to) {
}
void SlackFrontend::sendMessage(boost::shared_ptr<Swift::Message> message) {
}
void SlackFrontend::sendIQ(boost::shared_ptr<Swift::IQ> iq) {
}
boost::shared_ptr<Swift::DiscoInfo> SlackFrontend::sendCapabilitiesRequest(Swift::JID to) {
return Swift::DiscoInfo::ref();
}
void SlackFrontend::reconnectUser(const std::string &user) {
}
RosterManager *SlackFrontend::createRosterManager(User *user, Component *component) {
return new SlackRosterManager(user, component);
}
User *SlackFrontend::createUser(const Swift::JID &jid, UserInfo &userInfo, Component *component, UserManager *userManager) {
return new SlackUser(jid, userInfo, component, userManager);
}
UserManager *SlackFrontend::createUserManager(Component *component, UserRegistry *userRegistry, StorageBackend *storageBackend) {
return new SlackUserManager(component, userRegistry, storageBackend);
}
void SlackFrontend::connectToServer() {
}
void SlackFrontend::disconnectFromServer() {
}
}

View file

@ -0,0 +1,73 @@
/**
* Spectrum 2 Slack Frontend
*
* Copyright (C) 2015, Jan Kaluza <hanzz.k@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#pragma once
#include "transport/Frontend.h"
#include <vector>
#include <boost/bind.hpp>
namespace Transport {
class UserRegistry;
class Frontend;
class Config;
class DiscoItemsResponder;
class VCardResponder;
class SlackFrontend : public Frontend {
public:
SlackFrontend();
virtual ~SlackFrontend();
virtual void init(Component *component, Swift::EventLoop *loop, Swift::NetworkFactories *factories, Config *config, UserRegistry *userRegistry);
virtual void connectToServer();
virtual void disconnectFromServer();
virtual void sendPresence(Swift::Presence::ref presence);
virtual void sendVCard(Swift::VCard::ref vcard, Swift::JID to);
virtual void sendRosterRequest(Swift::RosterPayload::ref, Swift::JID to);
virtual void sendMessage(boost::shared_ptr<Swift::Message> message);
virtual void sendIQ(boost::shared_ptr<Swift::IQ>);
virtual void reconnectUser(const std::string &user);
virtual RosterManager *createRosterManager(User *user, Component *component);
virtual User *createUser(const Swift::JID &jid, UserInfo &userInfo, Component *component, UserManager *userManager);
virtual UserManager *createUserManager(Component *component, UserRegistry *userRegistry, StorageBackend *storageBackend = NULL);
virtual boost::shared_ptr<Swift::DiscoInfo> sendCapabilitiesRequest(Swift::JID to);
virtual void clearRoomList();
virtual void addRoomToRoomList(const std::string &handle, const std::string &name);
void handleMessage(boost::shared_ptr<Swift::Message> message);
private:
Config* m_config;
Swift::JID m_jid;
Component *m_transport;
};
}

View file

@ -0,0 +1,63 @@
/**
* XMPP - libpurple transport
*
* Copyright (C) 2009, Jan Kaluza <hanzz@soc.pidgin.im>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#include "SlackRosterManager.h"
#include "SlackFrontend.h"
#include "SlackUser.h"
#include "transport/Buddy.h"
#include "transport/User.h"
#include "transport/Logging.h"
#include "transport/Factory.h"
#include "transport/PresenceOracle.h"
#include "transport/Transport.h"
#include <boost/foreach.hpp>
#include <boost/make_shared.hpp>
#include <map>
#include <iterator>
namespace Transport {
DEFINE_LOGGER(logger, "SlackRosterManager");
SlackRosterManager::SlackRosterManager(User *user, Component *component) : RosterManager(user, component){
m_user = user;
m_transport = component;
}
SlackRosterManager::~SlackRosterManager() {
}
void SlackRosterManager::doRemoveBuddy(Buddy *buddy) {
}
void SlackRosterManager::doAddBuddy(Buddy *buddy) {
}
void SlackRosterManager::doUpdateBuddy(Buddy *buddy) {
}
}

View file

@ -0,0 +1,54 @@
/**
* Spectrum 2 Slack Frontend
*
* Copyright (C) 2015, Jan Kaluza <hanzz.k@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#pragma once
#include "transport/RosterManager.h"
#include <string>
#include <algorithm>
#include <map>
namespace Transport {
class Buddy;
class User;
class Component;
class StorageBackend;
class RosterStorage;
class SlackRosterManager : public RosterManager {
public:
SlackRosterManager(User *user, Component *component);
virtual ~SlackRosterManager();
virtual void doRemoveBuddy(Buddy *buddy);
virtual void doAddBuddy(Buddy *buddy);
virtual void doUpdateBuddy(Buddy *buddy);
private:
RosterStorage *m_rosterStorage;
User *m_user;
Component *m_transport;
};
}

View file

@ -0,0 +1,54 @@
/**
* libtransport -- C++ library for easy XMPP Transports development
*
* Copyright (C) 2011, Jan Kaluza <hanzz.k@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#include "SlackUser.h"
#include "SlackFrontend.h"
#include "transport/Transport.h"
#include "transport/UserManager.h"
#include "transport/Logging.h"
#include <boost/foreach.hpp>
#include <stdio.h>
#include <stdlib.h>
using namespace boost;
namespace Transport {
DEFINE_LOGGER(logger, "SlackUser");
SlackUser::SlackUser(const Swift::JID &jid, UserInfo &userInfo, Component *component, UserManager *userManager) : User(jid, userInfo, component, userManager) {
m_jid = jid.toBare();
m_component = component;
m_userManager = userManager;
m_userInfo = userInfo;
}
SlackUser::~SlackUser(){
}
void SlackUser::disconnectUser(const std::string &error, Swift::SpectrumErrorPayload::Error e) {
}
}

View file

@ -0,0 +1,51 @@
/**
* libtransport -- C++ library for easy XMPP Transports development
*
* Copyright (C) 2011, Jan Kaluza <hanzz.k@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#pragma once
#include "transport/User.h"
#include <time.h>
namespace Transport {
class Component;
class RosterManager;
class ConversationManager;
class UserManager;
class PresenceOracle;
struct UserInfo;
class SlackUser : public User {
public:
SlackUser(const Swift::JID &jid, UserInfo &userInfo, Component * component, UserManager *userManager);
virtual ~SlackUser();
void disconnectUser(const std::string &error, Swift::SpectrumErrorPayload::Error e);
private:
Swift::JID m_jid;
Component *m_component;
UserManager *m_userManager;
UserInfo m_userInfo;
};
}

View file

@ -0,0 +1,52 @@
/**
* libtransport -- C++ library for easy XMPP Transports development
*
* Copyright (C) 2011, Jan Kaluza <hanzz.k@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#include "SlackUserManager.h"
#include "SlackUserRegistration.h"
#include "SlackFrontend.h"
#include "transport/User.h"
#include "transport/Transport.h"
#include "transport/StorageBackend.h"
#include "transport/Logging.h"
namespace Transport {
DEFINE_LOGGER(logger, "SlackUserManager");
SlackUserManager::SlackUserManager(Component *component, UserRegistry *userRegistry, StorageBackend *storageBackend) : UserManager(component, userRegistry, storageBackend) {
m_component = component;
m_userRegistration = new SlackUserRegistration(component, this, storageBackend);
}
SlackUserManager::~SlackUserManager() {
delete m_userRegistration;
}
void SlackUserManager::sendVCard(unsigned int id, Swift::VCard::ref vcard) {
}
UserRegistration *SlackUserManager::getUserRegistration() {
return m_userRegistration;
}
}

View file

@ -0,0 +1,58 @@
/**
* libtransport -- C++ library for easy XMPP Transports development
*
* Copyright (C) 2011, Jan Kaluza <hanzz.k@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#pragma once
#include "transport/UserManager.h"
#include "Swiften/Elements/Message.h"
#include "Swiften/Elements/Presence.h"
#include "Swiften/Elements/DiscoInfo.h"
#include <string>
#include <map>
namespace Transport {
class Component;
class StorageBackend;
class StorageResponder;
class VCardResponder;
class XMPPUserRegistration;
class GatewayResponder;
class AdHocManager;
class SettingsAdHocCommandFactory;
class SlackUserManager : public UserManager {
public:
SlackUserManager(Component *component, UserRegistry *userRegistry, StorageBackend *storageBackend = NULL);
virtual ~SlackUserManager();
virtual void sendVCard(unsigned int id, Swift::VCard::ref vcard);
UserRegistration *getUserRegistration();
private:
Component *m_component;
UserRegistration *m_userRegistration;
};
}

View file

@ -0,0 +1,67 @@
/**
* libtransport -- C++ library for easy XMPP Transports development
*
* Copyright (C) 2011, Jan Kaluza <hanzz.k@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#include "SlackUserRegistration.h"
#include "SlackRosterManager.h"
#include "SlackFrontend.h"
#include "transport/UserManager.h"
#include "transport/StorageBackend.h"
#include "transport/Transport.h"
#include "transport/RosterManager.h"
#include "transport/User.h"
#include "transport/Logging.h"
#include "transport/Buddy.h"
#include "transport/Config.h"
#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/regex.hpp>
using namespace Swift;
namespace Transport {
DEFINE_LOGGER(logger, "SlackUserRegistration");
SlackUserRegistration::SlackUserRegistration(Component *component, UserManager *userManager,
StorageBackend *storageBackend)
: UserRegistration(component, userManager, storageBackend) {
m_component = component;
m_config = m_component->getConfig();
m_storageBackend = storageBackend;
m_userManager = userManager;
}
SlackUserRegistration::~SlackUserRegistration(){
}
bool SlackUserRegistration::doUserRegistration(const UserInfo &row) {
return true;
}
bool SlackUserRegistration::doUserUnregistration(const UserInfo &row) {
return true;
}
}

View file

@ -0,0 +1,53 @@
/**
* libtransport -- C++ library for easy XMPP Transports development
*
* Copyright (C) 2011, Jan Kaluza <hanzz.k@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#pragma once
#include "transport/UserRegistration.h"
#include <boost/signal.hpp>
namespace Transport {
struct UserInfo;
class Component;
class StorageBackend;
class UserManager;
class Config;
class SlackUserRegistration : public UserRegistration {
public:
SlackUserRegistration(Component *component, UserManager *userManager, StorageBackend *storageBackend);
~SlackUserRegistration();
virtual bool doUserRegistration(const UserInfo &userInfo);
virtual bool doUserUnregistration(const UserInfo &userInfo);
private:
Component *m_component;
StorageBackend *m_storageBackend;
UserManager *m_userManager;
Config *m_config;
};
}

View file

@ -73,10 +73,6 @@ class XMPPRosterManager : public RosterManager {
return m_supportRemoteRoster;
}
boost::signal<void (Buddy *buddy)> onBuddyAdded;
boost::signal<void (Buddy *buddy)> onBuddyRemoved;
void handleBuddyChanged(Buddy *buddy);
void sendBuddyRosterPush(Buddy *buddy);

View file

@ -14,6 +14,7 @@
#include "transport/Util.h"
#include "transport/Logging.h"
#include "frontends/xmpp/XMPPFrontend.h"
#include "frontends/slack/SlackFrontend.h"
#include "Swiften/EventLoop/SimpleEventLoop.h"
#include "Swiften/Network/BoostNetworkFactories.h"
#include <boost/filesystem.hpp>
@ -210,9 +211,18 @@ int mainloop() {
Swift::BoostNetworkFactories *factories = new Swift::BoostNetworkFactories(&eventLoop);
UserRegistry userRegistry(config_, factories);
XMPPFrontend frontend;
Frontend *frontend = NULL;
std::string frontend_name = CONFIG_STRING_DEFAULTED(config_, "service.frontend", "xmpp");
if (frontend_name == "xmpp") {
frontend = new XMPPFrontend();
}
else if (frontend_name == "slack") {
frontend = new SlackFrontend();
}
Component transport(&frontend, &eventLoop, factories, config_, NULL, &userRegistry);
Component transport(frontend, &eventLoop, factories, config_, NULL, &userRegistry);
component_ = &transport;
std::string error;
@ -230,7 +240,7 @@ int mainloop() {
Logging::redirect_stderr();
userManager = frontend.createUserManager(&transport, &userRegistry, storageBackend);;
userManager = frontend->createUserManager(&transport, &userRegistry, storageBackend);;
UserRegistration *userRegistration = userManager->getUserRegistration();
UsersReconnecter *usersReconnecter = NULL;