Added basic IRC backend support

This commit is contained in:
HanzZ 2011-05-14 22:52:58 +02:00
parent c80a2843f9
commit d2502858d6
6 changed files with 139 additions and 9 deletions

View file

@ -27,8 +27,15 @@ find_package(Boost COMPONENTS date_time system filesystem program_options regex
set(Protobuf_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
find_package(Protobuf REQUIRED)
set(IRCClientQt_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
find_package(IRCClientQt)
find_package(Doxygen)
INCLUDE(FindQt4)
FIND_PACKAGE(Qt4 COMPONENTS QtCore)
message(" Supported features")
message("-----------------------")
if (SQLITE3_FOUND)
@ -44,14 +51,24 @@ if (PROTOBUF_FOUND)
ADD_DEFINITIONS(-DWITH_PROTOBUF)
include_directories(${PROTOBUF_INCLUDE_DIRS})
message("Network plugins : yes")
if(PURPLE_LIBRARY AND PURPLE_INCLUDE_DIR)
message("Libpurple plugin : yes")
else()
message("Libpurple plugin : no (install libpurple)")
endif()
if(IRC_FOUND)
ADD_DEFINITIONS(-DIRC_SHARED)
message("IRC plugin : yes")
else()
message("IRC plugin : no (install libircclient-qt and Google Protocol Buffers)")
endif()
else()
message("Network plugins : no (install Google Protocol Buffers)")
endif()
if(PURPLE_LIBRARY AND PURPLE_INCLUDE_DIR AND PROTOBUF_FOUND)
message("Libpurple backend : yes")
else()
message("Libpurple backend : no (install libpurple and Google Protocol Buffers)")
message("Libpurple plugin : no (install libpurple and Google Protocol Buffers)")
message("IRC plugin : no (install libircclient-qt and Google Protocol Buffers)")
endif()
if(CMAKE_BUILD_TYPE MATCHES Debug)
@ -70,7 +87,7 @@ if(CMAKE_BUILD_TYPE MATCHES Debug)
ADD_DEFINITIONS(-Wundef -Wunused)
message("Debug : yes")
else(CMAKE_BUILD_TYPE MATCHES Debug)
message("Debug : no")
message("Debug : no (run \"cmake . -DCMAKE_BUILD_TYPE=Debug\")")
endif(CMAKE_BUILD_TYPE MATCHES Debug)
@ -83,6 +100,8 @@ include_directories(${EVENT_INCLUDE_DIRS})
include_directories(${GLIB2_INCLUDE_DIR})
include_directories(${SWIFTEN_INCLUDE_DIR})
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${IRC_INCLUDE_DIR})
include(${QT_USE_FILE})
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(include)
@ -94,7 +113,7 @@ if(DOXYGEN_FOUND)
message("Docs : yes")
ADD_SUBDIRECTORY(docs)
else(DOXYGEN_FOUND)
message("Docs : no")
message("Docs : no (install doxygen)")
endif(DOXYGEN_FOUND)
message("----------------------")

View file

@ -1,3 +1,8 @@
if (PROTOBUF_FOUND)
ADD_SUBDIRECTORY(libpurple)
if (IRC_FOUND)
ADD_SUBDIRECTORY(libircclient-qt)
endif()
endif()

View file

@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.6)
FILE(GLOB SRC *.cpp)
ADD_EXECUTABLE(libircclient-qt_backend ${SRC})
target_link_libraries(libircclient-qt_backend ${IRC_LIBRARIES} ${QT_LIBRARIES} transport)

View file

@ -0,0 +1,97 @@
/*
* Copyright (C) 2008-2009 J-P Nurmi jpnurmi@gmail.com
*
* This example is free, and not covered by LGPL license. There is no
* restriction applied to their modification, redistribution, using and so on.
* You can study them, modify them, use them in your own program - either
* completely or partially. By using it you may give me some credits in your
* program, but you don't have to.
*/
#include "transport/config.h"
#include "transport/networkplugin.h"
#include "ircsession.h"
#include <QtCore>
#include "Swiften/EventLoop/Qt/QtEventLoop.h"
using namespace boost::program_options;
using namespace Transport;
class IRCNetworkPlugin;
IRCNetworkPlugin * np = NULL;
class IRCNetworkPlugin : public NetworkPlugin {
public:
IRCNetworkPlugin(Config *config, Swift::QtEventLoop *loop, const std::string &host, int port) : NetworkPlugin(loop, host, port) {
this->config = config;
}
void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) {
}
void handleLogoutRequest(const std::string &user, const std::string &legacyName) {
}
void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message) {
}
private:
Config *config;
};
int main (int argc, char* argv[]) {
std::string host;
int port;
boost::program_options::options_description desc("Usage: spectrum [OPTIONS] <config_file.cfg>\nAllowed options");
desc.add_options()
("host,h", value<std::string>(&host), "host")
("port,p", value<int>(&port), "port")
;
try
{
boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
boost::program_options::notify(vm);
}
catch (std::runtime_error& e)
{
std::cout << desc << "\n";
exit(1);
}
catch (...)
{
std::cout << desc << "\n";
exit(1);
}
if (argc < 5) {
qDebug("Usage: %s <config>", argv[0]);
return 1;
}
// QStringList channels;
// for (int i = 3; i < argc; ++i)
// {
// channels.append(argv[i]);
// }
//
// MyIrcSession session;
// session.setNick(argv[2]);
// session.setAutoJoinChannels(channels);
// session.connectToServer(argv[1], 6667);
Config config;
if (!config.load(argv[5])) {
std::cerr << "Can't open " << argv[1] << " configuration file.\n";
return 1;
}
QCoreApplication app(argc, argv);
Swift::QtEventLoop eventLoop;
np = new IRCNetworkPlugin(&config, &eventLoop, host, port);
return app.exec();
}

View file

@ -4,6 +4,7 @@ FILE(GLOB SRC *.cpp)
ADD_EXECUTABLE(spectrum ${SRC})
ADD_DEPENDENCIES(spectrum libpurple_backend)
ADD_DEPENDENCIES(spectrum libircclient-qt_backend)
target_link_libraries(spectrum ${PURPLE_LIBRARY} ${GLIB2_LIBRARIES} ${EVENT_LIBRARIES} transport)

View file

@ -4,7 +4,8 @@ password = secret
server = 127.0.0.1
port = 5222
server_mode = 1
backend=../../backends/libpurple/libpurple_backend
#backend=../../backends/libpurple/libpurple_backend
backend=../../backends/libircclient-qt/libircclient-qt_backend
protocol=prpl-jabber
[database]