Changeset - d2502858d6c0
[Not reviewed]
0 4 2
HanzZ - 14 years ago 2011-05-14 22:52:58
hanzz.k@gmail.com
Added basic IRC backend support
6 files changed with 139 insertions and 9 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -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")
 
else()
 
	message("Network plugins   : no (install Google Protocol Buffers)")
 
endif()
 

	
 
if(PURPLE_LIBRARY AND PURPLE_INCLUDE_DIR AND PROTOBUF_FOUND)
 
	message("Libpurple backend : 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("Libpurple backend : no (install libpurple and Google Protocol Buffers)")
 
	message("Network plugins   : no (install 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("----------------------")
backends/CMakeLists.txt
Show inline comments
 
if (PROTOBUF_FOUND)
 
	ADD_SUBDIRECTORY(libpurple)
 

	
 
	if (IRC_FOUND)
 
		ADD_SUBDIRECTORY(libircclient-qt)
 
	endif()
 

	
 
endif()
backends/libircclient-qt/CMakeLists.txt
Show inline comments
 
new file 100644
 
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)
 
backends/libircclient-qt/main.cpp
Show inline comments
 
new file 100644
 
/*
 
 * 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();
 
}
spectrum/src/CMakeLists.txt
Show inline comments
 
@@ -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)
 
spectrum/src/sample.cfg
Show inline comments
 
@@ -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]
0 comments (0 inline, 0 general)