Changeset - a0e0c8e75b6a
[Not reviewed]
Merge
0 9 0
HanzZ - 13 years ago 2013-01-11 22:35:42
hanzz.k@gmail.com
Merge remote-tracking branch 'jadestorm/master'
6 files changed with 51 insertions and 16 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -89,49 +89,49 @@ else(WIN32)
 
		message(STATUS "Using non-multithreaded boost")
 
		set(Boost_USE_MULTITHREADED 0)
 
	endif(contains)
 
	set(Boost_FIND_QUIETLY ON)
 
	find_package(Boost COMPONENTS program_options date_time system filesystem regex thread-mt signals)
 
	if (NOT Boost_FOUND)
 
		set(Boost_FIND_QUIETLY OFF)
 
		find_package(Boost COMPONENTS program_options date_time system filesystem regex thread signals REQUIRED)
 
	endif()
 
endif(WIN32)
 

	
 
message( STATUS "Found Boost: ${Boost_LIBRARIES}, ${Boost_INCLUDE_DIR}")
 

	
 
# FIND POPT
 
if (NOT WIN32)
 
	set(popt_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
	find_package(popt REQUIRED)
 
endif()
 

	
 
###### Database ######
 

	
 
# FIND SQLITE3
 
if (ENABLE_SQLITE3)
 
	if (NOT CMAKE_COMPILER_IS_GNUCXX)
 
		ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/msvc-deps/sqlite3)
 
		ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/msvc-deps)
 
	else()
 
		if (WIN32)
 
			ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/msvc-deps/sqlite3)
 
		else()
 
			set(sqlite3_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
			find_package(sqlite3)
 
		endif()
 
	endif()
 
endif()
 

	
 
# FIND MYSQL
 
if(ENABLE_MYSQL)
 
	set(mysql_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
	find_package(mysql)
 
endif()
 

	
 
# FIND PQXX
 
if(ENABLE_PQXX)
 
	set(pqxx_DIR "${CMAKE_SOURCE_DIR}/cmake_modules")
 
	find_package(pqxx)
 
endif()
 

	
 
###### Plugins ######
 

	
backends/twitter/CMakeLists.txt
Show inline comments
 
include_directories (${libtransport_SOURCE_DIR}/backends/twitter/libtwitcurl) 
 
FILE(GLOB SRC *.cpp libtwitcurl/*.cpp Requests/*.cpp)
 
add_executable(spectrum2_twitter_backend ${SRC})
 

	
 
if (NOT WIN32)
 
target_link_libraries(spectrum2_twitter_backend curl transport pthread ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
else ()
 
include_directories("${CMAKE_SOURCE_DIR}/msvc-deps/curl/include")
 
target_link_libraries(spectrum2_twitter_backend libcurl_imp transport ${Boost_LIBRARIES} ${SWIFTEN_LIBRARY} ${LOG4CXX_LIBRARIES})
 
endif()
 

	
 
INSTALL(TARGETS spectrum2_twitter_backend RUNTIME DESTINATION bin)
docs/guide/postgresql.textile
Show inline comments
 

	
 
h2. 1. Editing the configuration file
 

	
 
To configure Spectrum 2 to use PostgreSQL database, you have to edit following options in database section:
 
To configure Spectrum 2 to use PostgreSQL database, you have to edit some or more of the following options in database section.  Please note that connectionstring overrides everything else (aside from type).
 

	
 
|_. Section |_. Key |_. Type |_. Change to value |_. Description |
 
| database| type | string | pqxx | Database type - "none", "mysql", "sqlite3", "pqxx". |
 
| database| database | string | Name of the already create empty database | Database used to store data. |
 
| database| server | string | Database server | Database server. |
 
| database| port | string | Database port | Database port. |
 
| database| user | string | PostgreSQL user. | PostgreSQL user. |
 
| database| password | string | PostgreSQL Password. | PostgreSQL Password. |
 
| database| prefix | string | | Prefix of tables in database. |
 
| database| connectionstring | string | Postgres connection string | If you set this, it will ignore all other options above aside from type and prefix.  This allows you to set any typical postgres connection string option, separated by spaces (no semicolons). |
 

	
 
h2. 2. Creating the database
 

	
 
Spectrum 2 will create the database on the first execution. Once the database is created, you can remove the CREATE TABLE permissions to the PostgreSQL database user you use to connect the SQL.
 
\ No newline at end of file
 
Spectrum 2 will create the database on the first execution. Once the database is created, you can remove the CREATE TABLE permissions to the PostgreSQL database user you use to connect the SQL.
 

	
 
h2. 3. Some examples
 

	
 
Using connectionstring:
 
[database]
 
type=pqxx
 
connectionstring=host=localhost database=spectrum2 user=myuser password=whatever
 

	
 
Using traditional options:
 
[database]
 
type=pqxx
 
server=localhost
 
database=spectrum2
 
user=myuser
 
password=whatever
packaging/fedora/spectrum2.spec
Show inline comments
 
@@ -4,49 +4,49 @@
 
Summary: XMPP transport
 
Name: spectrum2
 
Version: 2.0
 
Release: 1%{?dist}
 
Group: Applications/Internet
 
License: GPLv3
 
Source0: spectrum2.tar.gz
 
URL: http://swift.im/
 
BuildRequires: cmake
 
BuildRequires: boost-devel
 
BuildRequires: mysql-devel
 
BuildRequires: cppunit-devel
 
%if 0%{?rhel} > 0 && 0%{?rhel} <= 6
 
BuildRequires: sqlite-devel
 
%else
 
BuildRequires: libsqlite3x-devel
 
%endif
 
BuildRequires: protobuf-devel
 
BuildRequires: protobuf-compiler
 
BuildRequires: popt-devel
 
BuildRequires: libidn-devel
 
BuildRequires: expat-devel
 
BuildRequires: avahi-devel
 
BuildRequires: log4cxx-devel
 
BuildRequires: swiften-devel
 
#BuildRequires: swiften-devel
 
BuildRequires: libcommuni-devel
 
Requires:      libtransport%{?_isa} = %{version}-%{release}
 

	
 
%description
 
Spectrum 2 is an XMPP transport/gateway and also simple XMPP server.
 

	
 
%prep
 
%setup -q -n spectrum2
 

	
 
%build
 
%cmake . -DCMAKE_BUILD_TYPE=Debug
 
make VERBOSE=1 %{?_smp_mflags}
 

	
 
%install
 
rm -rf %{buildroot}
 
make install DESTDIR=%{buildroot}
 
install -d %{buildroot}%{_localstatedir}/{lib,run,log}/spectrum2
 
install -p -D -m 755 packaging/fedora/spectrum2.init \
 
    %{buildroot}%{_initddir}/spectrum2
 

	
 
ln -s /usr/bin/spectrum2_libpurple_backend %{buildroot}/usr/bin/spectrum_libpurple_backend
 

	
 
%pre
 
getent group %{groupname} >/dev/null || groupadd -r %{groupname}
spectrum/src/sample2.cfg
Show inline comments
 
@@ -75,40 +75,44 @@ backend_config = /etc/spectrum2/backend-logging.cfg
 
# Database backend type
 
# "sqlite3", "mysql", "pqxx", or "none" without database backend
 
type = none
 

	
 
# For SQLite3: Full path to database
 
# For MySQL and PostgreSQL: name of database
 
# default database = /var/lib/spectrum2/$jid/database.sql
 
#database = jabber_transport
 

	
 
# Server.
 
#server = localhost
 

	
 
# Port.
 
#port = 0
 

	
 
# User.
 
#user = spectrum
 

	
 
# Paasword.
 
#password = secret
 

	
 
# Prefix used for tables
 
#prefix = jabber_
 

	
 
# Connection string (for pqxx only!)
 
# If you set this, it ignores every other database option except for type and prefix.
 
#connectionstring = host=localhost user=specturm password=secret
 

	
 
[registration]
 
# Enable public registrations
 
enable_public_registration=1
 

	
 
# Text to display upon user registration form
 
#username_label=Jabber JID (e.g. user@server.tld):
 
#instructions=Enter your remote jabber JID and password as well as your local username and password
 

	
 
# If True a local jabber account on <local_account_server> is needed 
 
# for transport registration, the idea is to enable public registration
 
# from other servers, but only for users, who have already local accounts
 
#require_local_account=1
 
#local_username_label=Local username (without @server.tld):
 
#local_account_server=localhost
 
#local_account_server_timeout=10000
 

	
src/pqxxbackend.cpp
Show inline comments
 
@@ -27,63 +27,76 @@
 

	
 
using namespace log4cxx;
 
using namespace boost;
 

	
 
namespace Transport {
 

	
 
static LoggerPtr logger = Logger::getLogger("PQXXBackend");
 

	
 
PQXXBackend::PQXXBackend(Config *config) {
 
	m_config = config;
 
	m_prefix = CONFIG_STRING(m_config, "database.prefix");
 
}
 

	
 
PQXXBackend::~PQXXBackend(){
 
	disconnect();
 
}
 

	
 
void PQXXBackend::disconnect() {
 
	LOG4CXX_INFO(logger, "Disconnecting");
 

	
 
	delete m_conn;
 
}
 

	
 
bool PQXXBackend::connect() {
 
	LOG4CXX_INFO(logger, "Connecting PostgreSQL server " << CONFIG_STRING(m_config, "database.server") << ", user " <<
 
		CONFIG_STRING(m_config, "database.user") << ", database " << CONFIG_STRING(m_config, "database.database") <<
 
		", port " << CONFIG_INT(m_config, "database.port")
 
	);
 
	
 
	std::string str = "dbname=";
 
	str += CONFIG_STRING(m_config, "database.database") + " ";
 

	
 
	str += "user=" + CONFIG_STRING(m_config, "database.user") + " ";
 
	if (!CONFIG_STRING(m_config, "database.password").empty()) {
 
		str += "password=" + CONFIG_STRING(m_config, "database.password") + " ";
 
	std::string connection_str;
 
	connection_str = CONFIG_STRING(m_config, "database.connectionstring");
 
	if (connection_str.empty()) {
 
		LOG4CXX_INFO(logger, "Connecting PostgreSQL server " << CONFIG_STRING(m_config, "database.server") << ", user " <<
 
			CONFIG_STRING(m_config, "database.user") << ", database " << CONFIG_STRING(m_config, "database.database") <<
 
			", port " << CONFIG_INT(m_config, "database.port")
 
		);
 
		connection_str = "dbname=";
 
		connection_str += CONFIG_STRING(m_config, "database.database");
 
		if (!CONFIG_STRING(m_config, "database.server").empty()) {
 
			connection_str += " host=" + CONFIG_STRING(m_config, "database.server");
 
		}
 
		if (!CONFIG_STRING(m_config, "database.user").empty()) {
 
			connection_str += " user=" + CONFIG_STRING(m_config, "database.user");
 
		}
 
		if (!CONFIG_STRING(m_config, "database.password").empty()) {
 
			connection_str += " password=" + CONFIG_STRING(m_config, "database.password");
 
		}
 
		if (!CONFIG_STRING(m_config, "database.port").empty()) {
 
			connection_str += " port=" + CONFIG_STRING(m_config, "database.password");
 
		}
 
	}
 
	else {
 
		LOG4CXX_INFO(logger, "Connecting PostgreSQL server via provided connection string.");
 
	}
 

	
 
	try {
 
		m_conn = new pqxx::connection(str);
 
		m_conn = new pqxx::connection(connection_str);
 
	}
 
	catch (std::exception& e) {
 
		LOG4CXX_ERROR(logger, e.what());
 
		return false;
 
	}
 

	
 
	createDatabase();
 

	
 
	return true;
 
}
 

	
 
bool PQXXBackend::createDatabase() {
 
	
 
	int exist = exec("SELECT * FROM " + m_prefix + "buddies_settings LIMIT 1;", false);
 

	
 
	if (!exist) {
 
		exec("CREATE TABLE " + m_prefix + "buddies_settings ("
 
				"user_id integer NOT NULL,"
 
				"buddy_id integer NOT NULL,"
 
				"var varchar(50) NOT NULL,"
 
				"type smallint NOT NULL,"
 
				"value varchar(255) NOT NULL,"
 
				"PRIMARY KEY (buddy_id,var)"
 
			");");
0 comments (0 inline, 0 general)