Changeset - 7664202b38dc
[Not reviewed]
0 5 0
Jan Kaluza - 14 years ago 2011-09-07 14:19:10
hanzz.k@gmail.com
Allow compilation without sqlite/mysql
5 files changed with 22 insertions and 3 deletions:
0 comments (0 inline, 0 general)
include/transport/mysqlbackend.h
Show inline comments
 
@@ -11,24 +11,26 @@
 
 * 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
 

	
 
#ifdef WITH_MYSQL
 

	
 
#include <string>
 
#include <map>
 
#include "Swiften/Swiften.h"
 
#include "transport/storagebackend.h"
 
#include "transport/config.h"
 
#include "mysql.h"
 

	
 
namespace Transport {
 

	
 
/// Used to store transport data into SQLite3 database.
 
class MySQLBackend : public StorageBackend
 
{
 
@@ -138,12 +140,14 @@ class MySQLBackend : public StorageBackend
 
		Statement *m_removeUser;
 
		Statement *m_removeUserBuddies;
 
		Statement *m_removeUserSettings;
 
		Statement *m_removeUserBuddiesSettings;
 
		Statement *m_addBuddy;
 
		MYSQL_STMT *m_updateBuddy;
 
		Statement *m_updateBuddySetting;
 
		MYSQL_STMT *m_getBuddies;
 
		MYSQL_STMT *m_getBuddiesSettings;
 
};
 

	
 
}
 

	
 
#endif
include/transport/sqlite3backend.h
Show inline comments
 
@@ -11,24 +11,26 @@
 
 * 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
 

	
 
#ifdef WITH_SQLITE
 

	
 
#include <string>
 
#include <map>
 
#include "Swiften/Swiften.h"
 
#include "transport/storagebackend.h"
 
#include "transport/config.h"
 
#include "sqlite3.h"
 

	
 
namespace Transport {
 

	
 
/// Used to store transport data into SQLite3 database.
 
class SQLite3Backend : public StorageBackend
 
{
 
@@ -106,12 +108,14 @@ class SQLite3Backend : public StorageBackend
 
		sqlite3_stmt *m_removeUser;
 
		sqlite3_stmt *m_removeUserBuddies;
 
		sqlite3_stmt *m_removeUserSettings;
 
		sqlite3_stmt *m_removeUserBuddiesSettings;
 
		sqlite3_stmt *m_addBuddy;
 
		sqlite3_stmt *m_updateBuddy;
 
		sqlite3_stmt *m_updateBuddySetting;
 
		sqlite3_stmt *m_getBuddies;
 
		sqlite3_stmt *m_getBuddiesSettings;
 
};
 

	
 
}
 

	
 
#endif
spectrum/src/main.cpp
Show inline comments
 
@@ -98,40 +98,43 @@ int main(int argc, char **argv)
 
	}
 
 
	Swift::SimpleEventLoop eventLoop;
 
 
	Swift::BoostNetworkFactories *factories = new Swift::BoostNetworkFactories(&eventLoop);
 
	UserRegistry userRegistry(&config, factories);
 
 
	Component transport(&eventLoop, factories, &config, NULL, &userRegistry);
 
// 	Logger logger(&transport);
 
 
	StorageBackend *storageBackend = NULL;
 
 
#ifdef WITH_SQLITE
 
	if (CONFIG_STRING(&config, "database.type") == "sqlite3") {
 
		storageBackend = new SQLite3Backend(&config);
 
		if (!storageBackend->connect()) {
 
			std::cerr << "Can't connect to database.\n";
 
			return -1;
 
		}
 
	}
 
/*
 
	else if (CONFIG_STRING(&config, "database.type") == "mysql") {
 
#endif
 
#ifdef WITH_MYSQL
 
	if (CONFIG_STRING(&config, "database.type") == "mysql") {
 
		storageBackend = new MySQLBackend(&config);
 
		if (!storageBackend->connect()) {
 
			std::cerr << "Can't connect to database.\n";
 
			return -1;
 
		}
 
	}
 
*/
 
#endif
 
 
	UserManager userManager(&transport, &userRegistry, storageBackend);
 
	UserRegistration *userRegistration = NULL;
 
	if (storageBackend) {
 
		userRegistration = new UserRegistration(&transport, &userManager, storageBackend);
 
		userRegistration->start();
 
// 		logger.setUserRegistration(&userRegistration);
 
	}
 
// 	logger.setUserManager(&userManager);
 
 
	NetworkPluginServer plugin(&transport, &config, &userManager);
 
 
	AdminInterface adminInterface(&transport, &userManager, &plugin, storageBackend);
src/mysqlbackend.cpp
Show inline comments
 
@@ -9,24 +9,26 @@
 
 * (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
 
 */
 

	
 
#ifdef WITH_MYSQL
 

	
 
#include "transport/mysqlbackend.h"
 
#include <boost/bind.hpp>
 
#include "log4cxx/logger.h"
 

	
 
using namespace log4cxx;
 

	
 
#define MYSQL_DB_VERSION 2
 
#define CHECK_DB_RESPONSE(stmt) \
 
	if(stmt) { \
 
		sqlite3_exec(m_db, "ROLLBACK;", NULL, NULL, NULL); \
 
		return 0; \
 
	}
 
@@ -459,12 +461,14 @@ void MySQLBackend::updateUserSetting(long id, const std::string &variable, const
 

	
 
}
 

	
 
void MySQLBackend::beginTransaction() {
 
	exec("START TRANSACTION;");
 
}
 

	
 
void MySQLBackend::commitTransaction() {
 
	exec("COMMIT;");
 
}
 

	
 
}
 

	
 
#endif
src/sqlite3backend.cpp
Show inline comments
 
@@ -9,24 +9,26 @@
 
 * (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
 
 */
 

	
 
#ifdef WITH_SQLITE
 

	
 
#include "transport/sqlite3backend.h"
 
#include <boost/bind.hpp>
 
#include "log4cxx/logger.h"
 

	
 
using namespace log4cxx;
 

	
 
#define SQLITE_DB_VERSION 3
 
#define CHECK_DB_RESPONSE(stmt) \
 
	if(stmt) { \
 
		sqlite3_exec(m_db, "ROLLBACK;", NULL, NULL, NULL); \
 
		return 0; \
 
	}
 
@@ -425,12 +427,14 @@ void SQLite3Backend::updateUserSetting(long id, const std::string &variable, con
 
	EXECUTE_STATEMENT(m_updateUserSetting, "m_updateUserSetting");
 
}
 

	
 
void SQLite3Backend::beginTransaction() {
 
	exec("BEGIN TRANSACTION;");
 
}
 

	
 
void SQLite3Backend::commitTransaction() {
 
	exec("COMMIT TRANSACTION;");
 
}
 

	
 
}
 

	
 
#endif
0 comments (0 inline, 0 general)