summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-08-18 15:58:17 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-08-18 15:58:17 +0200
commitdb5ad2e09a6b38e841463dbe7eb076492b62c948 (patch)
tree5907f6416e35cbd25432a5f1f6dc9664d36aa73c
parent5da7b0847bac2a5abec95b9ac1701b74baae8964 (diff)
downloadmad-db5ad2e09a6b38e841463dbe7eb076492b62c948.tar
mad-db5ad2e09a6b38e841463dbe7eb076492b62c948.zip
Mad funktioniert jetzt unter Windows
-rw-r--r--CMakeLists.txt11
-rw-r--r--src/CMakeLists.txt8
-rw-r--r--src/Client/Application.h4
-rw-r--r--src/Client/CMakeLists.txt14
-rw-r--r--src/Client/CommandParser.h4
-rw-r--r--src/Client/InformationManager.cpp8
-rw-r--r--src/Client/InformationManager.h6
-rw-r--r--src/Client/PasswordReader.cpp70
-rw-r--r--src/Client/PasswordReader.h41
-rw-r--r--src/Client/Requests/CMakeLists.txt8
-rw-r--r--src/Client/Requests/DaemonCommandRequest.h4
-rw-r--r--src/Client/Requests/DaemonFSInfoRequest.h4
-rw-r--r--src/Client/Requests/DaemonListRequest.h2
-rw-r--r--src/Client/Requests/DaemonStatusRequest.h4
-rw-r--r--src/Client/SystemCommands.cpp7
-rw-r--r--src/Client/SystemCommands.h4
-rw-r--r--src/Client/UserCommands.cpp30
-rw-r--r--src/Client/UserCommands.h4
-rw-r--r--src/Client/export.h11
-rw-r--r--src/Common/Application.h4
-rw-r--r--src/Common/Backends/CMakeLists.txt5
-rw-r--r--src/Common/Backends/NetworkUserBackend.h22
-rw-r--r--src/Common/Base64Encoder.h4
-rw-r--r--src/Common/CMakeLists.txt25
-rw-r--r--src/Common/ClientConnection.h4
-rw-r--r--src/Common/Connection.cpp2
-rw-r--r--src/Common/Connection.h12
-rw-r--r--src/Common/GroupInfo.h2
-rw-r--r--src/Common/HostInfo.h2
-rw-r--r--src/Common/Module.h2
-rw-r--r--src/Common/ModuleManager.cpp40
-rw-r--r--src/Common/ModuleManager.h14
-rw-r--r--src/Common/Request.cpp2
-rw-r--r--src/Common/Request.h4
-rw-r--r--src/Common/RequestHandler.h4
-rw-r--r--src/Common/RequestHandlerGroup.h2
-rw-r--r--src/Common/RequestHandlers/CMakeLists.txt13
-rw-r--r--src/Common/RequestHandlers/DisconnectRequestHandler.cpp2
-rw-r--r--src/Common/RequestHandlers/DisconnectRequestHandler.h4
-rw-r--r--src/Common/RequestHandlers/FSInfoRequestHandler.h4
-rw-r--r--src/Common/RequestHandlers/SimpleRequestHandler.cpp2
-rw-r--r--src/Common/RequestHandlers/SimpleRequestHandler.h4
-rw-r--r--src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp2
-rw-r--r--src/Common/RequestHandlers/SimpleRequestHandlerGroup.h6
-rw-r--r--src/Common/RequestHandlers/StatusRequestHandler.h4
-rw-r--r--src/Common/RequestManager.cpp10
-rw-r--r--src/Common/RequestManager.h6
-rw-r--r--src/Common/Requests/CMakeLists.txt10
-rw-r--r--src/Common/Requests/DisconnectRequest.cpp2
-rw-r--r--src/Common/Requests/DisconnectRequest.h4
-rw-r--r--src/Common/Requests/FSInfoRequest.h2
-rw-r--r--src/Common/Requests/IdentifyRequest.h10
-rw-r--r--src/Common/Requests/SimpleRequest.h4
-rw-r--r--src/Common/Requests/StatusRequest.h2
-rw-r--r--src/Common/SystemBackend.h10
-rw-r--r--src/Common/SystemManager.cpp12
-rw-r--r--src/Common/SystemManager.h6
-rw-r--r--src/Common/UserCache.cpp12
-rw-r--r--src/Common/UserCache.h4
-rw-r--r--src/Common/UserConfigBackend.h2
-rw-r--r--src/Common/UserDBBackend.h2
-rw-r--r--src/Common/UserInfo.h2
-rw-r--r--src/Common/UserManager.cpp28
-rw-r--r--src/Common/UserManager.h4
-rw-r--r--src/Common/XmlPacket.cpp38
-rw-r--r--src/Common/XmlPacket.h23
-rw-r--r--src/Common/export.h22
-rw-r--r--src/Core/Application.cpp16
-rw-r--r--src/Core/Application.h10
-rw-r--r--src/Core/CMakeLists.txt4
-rw-r--r--src/Core/ConfigEntry.h10
-rw-r--r--src/Core/ConfigManager.cpp6
-rw-r--r--src/Core/ConfigManager.h6
-rw-r--r--src/Core/Configurable.h2
-rw-r--r--src/Core/Exception.h4
-rw-r--r--src/Core/LogManager.cpp18
-rw-r--r--src/Core/LogManager.h20
-rw-r--r--src/Core/Logger.h6
-rw-r--r--src/Core/LoggerBase.h8
-rw-r--r--src/Core/RemoteLogger.h6
-rw-r--r--src/Core/Signals/Connection.h4
-rw-r--r--src/Core/Signals/GenericSignal.h4
-rw-r--r--src/Core/Signals/Signal0.h2
-rw-r--r--src/Core/Signals/Signal1.h2
-rw-r--r--src/Core/Signals/Signal2.h2
-rw-r--r--src/Core/Signals/SignalBase.h2
-rw-r--r--src/Core/ThreadManager.h4
-rw-r--r--src/Core/Tokenizer.h4
-rw-r--r--src/Core/export.h11
-rw-r--r--src/Daemon/Application.h4
-rw-r--r--src/Daemon/Backends/NetworkLogger.h4
-rw-r--r--src/Daemon/CMakeLists.txt13
-rw-r--r--src/Daemon/RequestHandlers/CMakeLists.txt5
-rw-r--r--src/Daemon/RequestHandlers/CommandRequestHandler.h4
-rw-r--r--src/Daemon/Requests/CMakeLists.txt5
-rw-r--r--src/Daemon/Requests/LogRequest.cpp4
-rw-r--r--src/Daemon/Requests/LogRequest.h10
-rw-r--r--src/Daemon/export.h11
-rw-r--r--src/Net/CMakeLists.txt4
-rw-r--r--src/Net/ClientConnection.cpp4
-rw-r--r--src/Net/ClientConnection.h13
-rw-r--r--src/Net/Connection.cpp39
-rw-r--r--src/Net/Connection.h50
-rw-r--r--src/Net/Listener.cpp34
-rw-r--r--src/Net/Listener.h8
-rw-r--r--src/Net/Packet.cpp8
-rw-r--r--src/Net/Packet.h40
-rw-r--r--src/Net/export.h22
-rw-r--r--src/Server/Application.h4
-rw-r--r--src/Server/CMakeLists.txt16
-rw-r--r--src/Server/ConnectionManager.cpp19
-rw-r--r--src/Server/ConnectionManager.h6
-rw-r--r--src/Server/RequestHandlers/CMakeLists.txt8
-rw-r--r--src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp20
-rw-r--r--src/Server/RequestHandlers/ConnectionRequestHandlerGroup.h4
-rw-r--r--src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp2
-rw-r--r--src/Server/RequestHandlers/DaemonRequestHandlerGroup.h4
-rw-r--r--src/Server/RequestHandlers/UserRequestHandlerGroup.cpp2
-rw-r--r--src/Server/RequestHandlers/UserRequestHandlerGroup.h4
-rw-r--r--src/Server/Requests/CMakeLists.txt6
-rw-r--r--src/Server/Requests/CommandRequest.h4
-rw-r--r--src/Server/Requests/DaemonStateUpdateRequest.h4
-rw-r--r--src/Server/export.h11
-rw-r--r--src/mad-server.cpp11
-rw-r--r--src/mad.cpp4
-rw-r--r--src/madc.cpp2
-rw-r--r--src/modules/CMakeLists.txt11
-rw-r--r--src/modules/FileLogger/CMakeLists.txt1
-rw-r--r--src/modules/FileLogger/FileLogger.h4
-rw-r--r--src/modules/FileLogger/Module.cpp6
-rw-r--r--src/modules/SystemBackendPosix/Module.cpp4
-rw-r--r--src/modules/SystemBackendProc/Module.cpp4
-rw-r--r--src/modules/UserConfigBackendHome/Module.cpp4
-rw-r--r--src/modules/UserConfigBackendHome/UserConfigBackendHome.cpp2
-rw-r--r--src/modules/UserConfigBackendKrb5/Module.cpp4
-rw-r--r--src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.cpp22
-rw-r--r--src/modules/UserDBBackendMysql/CMakeLists.txt1
-rw-r--r--src/modules/UserDBBackendMysql/Module.cpp4
-rw-r--r--src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp4
-rw-r--r--src/modules/export.h11
-rw-r--r--src/modules/modules.cpp.in7
141 files changed, 871 insertions, 432 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bbfb89a..f72352b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,13 +4,22 @@ project(MAD)
set(CMAKE_MODULE_PATH ${MAD_SOURCE_DIR})
find_package(LibXml2 REQUIRED)
-find_package(DL REQUIRED)
find_package(Readline REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(Boost REQUIRED date_time filesystem regex signals system thread)
find_package(MySQL)
find_package(KRB5 COMPONENTS krb5 kadm-client)
+if(WIN32)
+ add_definitions(-DWINVER=0x0501 -D_WIN32_WINNT=0x0501)
+else(WIN32)
+ find_package(DL REQUIRED)
+endif(WIN32)
+
+if(CYGWIN)
+ add_definitions(-D__USE_W32_SOCKETS)
+endif(CYGWIN)
+
configure_file(${MAD_SOURCE_DIR}/config.h.in ${MAD_BINARY_DIR}/config.h)
set(INCLUDES
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index acce966..24affaf 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,5 +1,13 @@
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
+macro(mad_library name)
+ string(TOUPPER ${name} upper_name)
+
+ add_library(${name} ${ARGN})
+
+ set_target_properties(${name} PROPERTIES DEFINE_SYMBOL "MAD_${upper_name}_EXPORTS")
+endmacro(mad_library)
+
add_subdirectory(Core)
add_subdirectory(Net)
add_subdirectory(Common)
diff --git a/src/Client/Application.h b/src/Client/Application.h
index 7ba6370..6a0b14f 100644
--- a/src/Client/Application.h
+++ b/src/Client/Application.h
@@ -20,6 +20,8 @@
#ifndef MAD_CLIENT_APPLICATION_H_
#define MAD_CLIENT_APPLICATION_H_
+#include "export.h"
+
#include <Common/Application.h>
namespace Mad {
@@ -27,7 +29,7 @@ namespace Client {
class InformationManager;
-class Application : public Common::Application {
+class MAD_CLIENT_EXPORT Application : public Common::Application {
private:
InformationManager *informationManager;
diff --git a/src/Client/CMakeLists.txt b/src/Client/CMakeLists.txt
index 6d7ba4c..fcd6f6b 100644
--- a/src/Client/CMakeLists.txt
+++ b/src/Client/CMakeLists.txt
@@ -1,12 +1,18 @@
-add_subdirectory(Requests)
-
include_directories(${INCLUDES})
-add_library(Client
+mad_library(Client
+ export.h
+
+ Requests/DaemonCommandRequest.h Requests/DaemonCommandRequest.cpp
+ Requests/DaemonFSInfoRequest.h Requests/DaemonFSInfoRequest.cpp
+ Requests/DaemonListRequest.h
+ Requests/DaemonStatusRequest.h Requests/DaemonStatusRequest.cpp
+
Application.cpp Application.h
CommandParser.cpp CommandParser.h
InformationManager.cpp InformationManager.h
+ PasswordReader.cpp PasswordReader.h
SystemCommands.cpp SystemCommands.h
UserCommands.cpp UserCommands.h
)
-target_link_libraries(Client ClientRequests Common)
+target_link_libraries(Client Common)
diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h
index 82808c8..ca168f3 100644
--- a/src/Client/CommandParser.h
+++ b/src/Client/CommandParser.h
@@ -20,6 +20,8 @@
#ifndef MAD_CLIENT_COMMANDPARSER_H_
#define MAD_CLIENT_COMMANDPARSER_H_
+#include "export.h"
+
#include <Common/HostInfo.h>
#include <Common/XmlPacket.h>
@@ -42,7 +44,7 @@ class Application;
class SystemCommands;
class UserCommands;
-class CommandParser {
+class MAD_CLIENT_EXPORT CommandParser {
private:
friend class SystemCommands;
friend class UserCommands;
diff --git a/src/Client/InformationManager.cpp b/src/Client/InformationManager.cpp
index 459408b..59d8836 100644
--- a/src/Client/InformationManager.cpp
+++ b/src/Client/InformationManager.cpp
@@ -37,9 +37,9 @@ void InformationManager::DaemonStateUpdateRequestHandler::handleRequest(boost::s
std::map<std::string, Common::HostInfo>::iterator host = informationManager->daemons.find(packet->get<const std::string&>("name"));
if(host != informationManager->daemons.end())
- host->second.setState(packet->get<Common::HostInfo::State>("state"));
+ host->second.setState(static_cast<Common::HostInfo::State>(packet->get<long>("state")));
else
- getApplication()->log(Core::LoggerBase::WARNING, "Received a state update for an unknown host.");
+ getApplication()->log(Core::LoggerBase::LOG_WARNING, "Received a state update for an unknown host.");
}
ret->setType("OK");
@@ -72,7 +72,7 @@ void InformationManager::daemonListRequestFinished(boost::shared_ptr<const Commo
boost::lock_guard<boost::mutex> lock(mutex);
if(!packet || error) {
- application->logf(Core::LoggerBase::CRITICAL, "Host list request failed: %s", error.strerror().c_str());
+ application->logf(Core::LoggerBase::LOG_CRITICAL, "Host list request failed: %s", error.strerror().c_str());
}
else {
const Common::XmlPacket::List *list = packet->getList("hosts");
@@ -84,7 +84,7 @@ void InformationManager::daemonListRequestFinished(boost::shared_ptr<const Commo
Common::HostInfo info;
info.setName(entry->get<const std::string&>("name"));
info.setIP(entry->get<const std::string&>("address"));
- info.setState(entry->get<Common::HostInfo::State>("state"));
+ info.setState(static_cast<Common::HostInfo::State>(entry->get<long>("state")));
daemons.insert(std::make_pair(info.getName(), info));
}
diff --git a/src/Client/InformationManager.h b/src/Client/InformationManager.h
index d0e26a3..5f68bc2 100644
--- a/src/Client/InformationManager.h
+++ b/src/Client/InformationManager.h
@@ -20,6 +20,8 @@
#ifndef MAD_CLIENT_INFORMATIONMANAGER_H_
#define MAD_CLIENT_INFORMATIONMANAGER_H_
+#include "export.h"
+
#include <map>
#include <memory>
@@ -37,9 +39,9 @@ namespace Client {
class Application;
-class InformationManager : private boost::noncopyable {
+class MAD_CLIENT_EXPORT InformationManager : private boost::noncopyable {
private:
- class DaemonStateUpdateRequestHandler : public Common::RequestHandlers::SimpleRequestHandler {
+ class MAD_CLIENT_EXPORT DaemonStateUpdateRequestHandler : public Common::RequestHandlers::SimpleRequestHandler {
private:
void handleRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret);
diff --git a/src/Client/PasswordReader.cpp b/src/Client/PasswordReader.cpp
new file mode 100644
index 0000000..d5c4fe8
--- /dev/null
+++ b/src/Client/PasswordReader.cpp
@@ -0,0 +1,70 @@
+/*
+ * PasswordReader.cpp
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "PasswordReader.h"
+
+#include <iostream>
+
+#ifdef _WIN32
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+#else
+# include <termios.h>
+# include <unistd.h>
+#endif
+
+namespace Mad {
+namespace Client {
+
+std::string PasswordReader::readPassword(const std::string &prompt) {
+ std::string password;
+
+#ifdef _WIN32
+ DWORD mode;
+ HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
+ GetConsoleMode(handle, &mode);
+ SetConsoleMode(handle, mode & ~(ENABLE_ECHO_INPUT));
+
+ std::cout << prompt << std::flush;
+ std::getline(std::cin, password);
+ std::cout << std::endl;
+
+ SetConsoleMode(handle, mode);
+
+#else
+ struct termios termold, termnew;
+
+ tcgetattr(STDIN_FILENO, &termold);
+
+ termnew = termold;
+ termnew.c_lflag &= ~ECHO;
+ tcsetattr(STDIN_FILENO, TCSAFLUSH, &termnew);
+
+ std::cout << prompt << std::flush;
+ std::getline(std::cin, password);
+ std::cout << std::endl;
+
+ tcsetattr(STDIN_FILENO, TCSAFLUSH, &termold);
+#endif
+
+ return password;
+}
+
+}
+}
diff --git a/src/Client/PasswordReader.h b/src/Client/PasswordReader.h
new file mode 100644
index 0000000..35487c4
--- /dev/null
+++ b/src/Client/PasswordReader.h
@@ -0,0 +1,41 @@
+/*
+ * PasswordReader.h
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_CLIENT_PASSWORDREADER_H_
+#define MAD_CLIENT_PASSWORDREADER_H_
+
+#include "export.h"
+
+#include <string>
+
+namespace Mad {
+namespace Client {
+
+class MAD_CLIENT_EXPORT PasswordReader {
+ private:
+ PasswordReader();
+
+ public:
+ static std::string readPassword(const std::string &prompt);
+};
+
+}
+}
+
+#endif /* MAD_CLIENT_PASSWORDREADER_H_ */ \ No newline at end of file
diff --git a/src/Client/Requests/CMakeLists.txt b/src/Client/Requests/CMakeLists.txt
deleted file mode 100644
index 86acaf5..0000000
--- a/src/Client/Requests/CMakeLists.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-include_directories(${INCLUDES})
-
-add_library(ClientRequests STATIC
- DaemonCommandRequest.cpp DaemonCommandRequest.h
- DaemonFSInfoRequest.cpp DaemonFSInfoRequest.h
- DaemonListRequest.h
- DaemonStatusRequest.cpp DaemonStatusRequest.h
-)
diff --git a/src/Client/Requests/DaemonCommandRequest.h b/src/Client/Requests/DaemonCommandRequest.h
index abe9bf7..04e0304 100644
--- a/src/Client/Requests/DaemonCommandRequest.h
+++ b/src/Client/Requests/DaemonCommandRequest.h
@@ -20,6 +20,8 @@
#ifndef MAD_CLIENT_REQUEST_DAEMONCOMMANDREQUEST_H_
#define MAD_CLIENT_REQUEST_DAEMONCOMMANDREQUEST_H_
+#include "../export.h"
+
#include <Common/Request.h>
#include <string>
@@ -27,7 +29,7 @@ namespace Mad {
namespace Client {
namespace Requests {
-class DaemonCommandRequest : public Common::Request {
+class MAD_CLIENT_EXPORT DaemonCommandRequest : public Common::Request {
private:
std::string daemon;
bool reboot;
diff --git a/src/Client/Requests/DaemonFSInfoRequest.h b/src/Client/Requests/DaemonFSInfoRequest.h
index e96cd3f..50c0783 100644
--- a/src/Client/Requests/DaemonFSInfoRequest.h
+++ b/src/Client/Requests/DaemonFSInfoRequest.h
@@ -20,6 +20,8 @@
#ifndef MAD_CLIENT_REQUESTS_DAEMONFSINFOREQUEST_H_
#define MAD_CLIENT_REQUESTS_DAEMONFSINFOREQUEST_H_
+#include "../export.h"
+
#include <Common/Request.h>
#include <string>
@@ -28,7 +30,7 @@ namespace Mad {
namespace Client {
namespace Requests {
-class DaemonFSInfoRequest : public Common::Request {
+class MAD_CLIENT_EXPORT DaemonFSInfoRequest : public Common::Request {
private:
std::string daemon;
diff --git a/src/Client/Requests/DaemonListRequest.h b/src/Client/Requests/DaemonListRequest.h
index 76f85cd..85fc4e1 100644
--- a/src/Client/Requests/DaemonListRequest.h
+++ b/src/Client/Requests/DaemonListRequest.h
@@ -20,6 +20,8 @@
#ifndef MAD_CLIENT_REQUEST_DAEMONLISTREQUEST_H_
#define MAD_CLIENT_REQUEST_DAEMONLISTREQUEST_H_
+#include "../export.h"
+
#include <Common/Requests/SimpleRequest.h>
namespace Mad {
diff --git a/src/Client/Requests/DaemonStatusRequest.h b/src/Client/Requests/DaemonStatusRequest.h
index 262cdb6..1cdc82e 100644
--- a/src/Client/Requests/DaemonStatusRequest.h
+++ b/src/Client/Requests/DaemonStatusRequest.h
@@ -20,6 +20,8 @@
#ifndef MAD_CLIENT_REQUESTS_DAEMONSTATUSREQUEST_H_
#define MAD_CLIENT_REQUESTS_DAEMONSTATUSREQUEST_H_
+#include "../export.h"
+
#include <Common/Request.h>
#include <string>
@@ -28,7 +30,7 @@ namespace Mad {
namespace Client {
namespace Requests {
-class DaemonStatusRequest : public Common::Request {
+class MAD_CLIENT_EXPORT DaemonStatusRequest : public Common::Request {
private:
std::string daemon;
diff --git a/src/Client/SystemCommands.cpp b/src/Client/SystemCommands.cpp
index c26be54..1cc9bc4 100644
--- a/src/Client/SystemCommands.cpp
+++ b/src/Client/SystemCommands.cpp
@@ -30,7 +30,7 @@
#include <Common/Requests/StatusRequest.h>
#include <iostream>
-
+#include <algorithm>
namespace Mad {
namespace Client {
@@ -74,9 +74,12 @@ void SystemCommands::printFSInfo(boost::shared_ptr<const Common::XmlPacket> &pac
nameString += "\n\t";
nameString.resize(nameString.length() + 32, ' ');
}
+
+ float percent = 100*used/(used+available);
+ if(percent > 100) percent = 100;
std::printf("\t%s%.*f%s", nameString.c_str(), (used < 10) ? 2 : 1, used, (usedUnit == totalUnit) ? "" : (" " + units[usedUnit]).c_str());
- std::printf("/%.*f %s (%.1f%%)\n", (total < 10) ? 2 : 1, total, units[totalUnit].c_str(), std::min(100*used/(used+available), 100.0f));
+ std::printf("/%.*f %s (%.1f%%)\n", (total < 10) ? 2 : 1, total, units[totalUnit].c_str(), percent);
}
}
diff --git a/src/Client/SystemCommands.h b/src/Client/SystemCommands.h
index 3d78151..74b1a62 100644
--- a/src/Client/SystemCommands.h
+++ b/src/Client/SystemCommands.h
@@ -20,6 +20,8 @@
#ifndef MAD_CLIENT_SYSTEMCOMMANDS_H_
#define MAD_CLIENT_SYSTEMCOMMANDS_H_
+#include "export.h"
+
#include <Common/XmlPacket.h>
#include <vector>
@@ -31,7 +33,7 @@ namespace Client {
class CommandParser;
-class SystemCommands {
+class MAD_CLIENT_EXPORT SystemCommands {
private:
SystemCommands();
diff --git a/src/Client/UserCommands.cpp b/src/Client/UserCommands.cpp
index 21259d0..166a54d 100644
--- a/src/Client/UserCommands.cpp
+++ b/src/Client/UserCommands.cpp
@@ -20,12 +20,12 @@
#include "UserCommands.h"
#include "Application.h"
#include "CommandParser.h"
+#include "PasswordReader.h"
#include <Common/RequestManager.h>
#include <Common/UserManager.h>
#include <iostream>
-#include <termios.h>
namespace Mad {
@@ -511,32 +511,8 @@ void UserCommands::setPasswordCommand(CommandParser *commandParser, const std::v
return;
}
- // TODO Extract this as a method
- struct termios termold, termnew;
-
- if(tcgetattr(STDIN_FILENO, &termold) != 0) {
- std::cerr << "Unable to set up terminal for password entry." << std::endl;
- return;
- }
-
- termnew = termold;
- termnew.c_lflag &= ~ECHO;
- if(tcsetattr(STDIN_FILENO, TCSAFLUSH, &termnew) != 0) {
- std::cerr << "Unable to set up terminal for password entry." << std::endl;
- return;
- }
-
- std::string password, password2;
-
- std::cout << "Password: " << std::flush;
- std::getline(std::cin, password);
- std::cout << std::endl;
-
- std::cout << "Verify password: " << std::flush;
- std::getline(std::cin, password2);
- std::cout << std::endl;
-
- tcsetattr(STDIN_FILENO, TCSAFLUSH, &termold);
+ std::string password = PasswordReader::readPassword("Password: ");
+ std::string password2 = PasswordReader::readPassword("Verify password: ");
if(password != password2) {
std::cerr << "Passwords do not match." << std::endl;
diff --git a/src/Client/UserCommands.h b/src/Client/UserCommands.h
index d5422da..640b5b4 100644
--- a/src/Client/UserCommands.h
+++ b/src/Client/UserCommands.h
@@ -20,6 +20,8 @@
#ifndef MAD_CLIENT_USERCOMMANDS_H_
#define MAD_CLIENT_USERCOMMANDS_H_
+#include "export.h"
+
#include <string>
#include <vector>
@@ -28,7 +30,7 @@ namespace Client {
class CommandParser;
-class UserCommands {
+class MAD_CLIENT_EXPORT UserCommands {
private:
UserCommands();
diff --git a/src/Client/export.h b/src/Client/export.h
new file mode 100644
index 0000000..c52e49d
--- /dev/null
+++ b/src/Client/export.h
@@ -0,0 +1,11 @@
+#ifndef MAD_CLIENT_EXPORT
+# ifdef _WIN32
+# ifdef MAD_CLIENT_EXPORTS
+# define MAD_CLIENT_EXPORT _declspec(dllexport)
+# else
+# define MAD_CLIENT_EXPORT _declspec(dllimport)
+# endif
+# else
+# define MAD_CLIENT_EXPORT
+# endif
+#endif
diff --git a/src/Common/Application.h b/src/Common/Application.h
index b0aa521..6de3b07 100644
--- a/src/Common/Application.h
+++ b/src/Common/Application.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_APPLICATION_H_
#define MAD_COMMON_APPLICATION_H_
+#include "export.h"
+
#include <Core/Application.h>
namespace Mad {
@@ -30,7 +32,7 @@ class RequestManager;
class SystemManager;
class UserManager;
-class Application : public Core::Application {
+class MAD_COMMON_EXPORT Application : public Core::Application {
private:
ModuleManager *moduleManager;
RequestManager *requestManager;
diff --git a/src/Common/Backends/CMakeLists.txt b/src/Common/Backends/CMakeLists.txt
deleted file mode 100644
index 631af52..0000000
--- a/src/Common/Backends/CMakeLists.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-include_directories(${INCLUDES})
-
-add_library(Backends STATIC
- NetworkUserBackend.cpp NetworkUserBackend.h
-)
diff --git a/src/Common/Backends/NetworkUserBackend.h b/src/Common/Backends/NetworkUserBackend.h
index 1ab0b58..6ae9747 100644
--- a/src/Common/Backends/NetworkUserBackend.h
+++ b/src/Common/Backends/NetworkUserBackend.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_BACKENDS_NETWORKUSERBACKEND_H_
#define MAD_COMMON_BACKENDS_NETWORKUSERBACKEND_H_
+#include "../export.h"
+
#include "../UserDBBackend.h"
#include "../Request.h"
@@ -27,9 +29,9 @@ namespace Mad {
namespace Common {
namespace Backends {
-class NetworkUserBackend : public UserDBBackend {
+class MAD_COMMON_EXPORT NetworkUserBackend : public UserDBBackend {
private:
- class SimpleUserRequest : public Request {
+ class MAD_COMMON_EXPORT SimpleUserRequest : public Request {
private:
std::string type;
boost::posix_time::ptime timestamp;
@@ -42,7 +44,7 @@ class NetworkUserBackend : public UserDBBackend {
: Request(application), type(type0), timestamp(timestamp0 ? *timestamp0 : boost::posix_time::not_a_date_time) {}
};
- class IdUserRequest : public Request {
+ class MAD_COMMON_EXPORT IdUserRequest : public Request {
private:
std::string type;
std::string idType;
@@ -57,7 +59,7 @@ class NetworkUserBackend : public UserDBBackend {
: Request(application), type(type0), idType(idType0), id(id0), timestamp(timestamp0 ? *timestamp0 : boost::posix_time::not_a_date_time) {}
};
- class NameUserRequest : public Request {
+ class MAD_COMMON_EXPORT NameUserRequest : public Request {
private:
std::string type;
std::string name;
@@ -71,7 +73,7 @@ class NetworkUserBackend : public UserDBBackend {
: Request(application), type(type0), name(name0), timestamp(timestamp0 ? *timestamp0 : boost::posix_time::not_a_date_time) {}
};
- class UserAddRequest : public Request {
+ class MAD_COMMON_EXPORT UserAddRequest : public Request {
private:
UserInfo userInfo;
bool check;
@@ -84,7 +86,7 @@ class NetworkUserBackend : public UserDBBackend {
: Request(application), userInfo(userInfo0), check(checkOnly) {}
};
- class UserUpdateRequest : public Request {
+ class MAD_COMMON_EXPORT UserUpdateRequest : public Request {
private:
unsigned long uid;
UserInfo userInfo;
@@ -97,7 +99,7 @@ class NetworkUserBackend : public UserDBBackend {
: Request(application), uid(uid0), userInfo(userInfo0) {}
};
- class GroupAddRequest : public Request {
+ class MAD_COMMON_EXPORT GroupAddRequest : public Request {
private:
GroupInfo groupInfo;
bool check;
@@ -110,7 +112,7 @@ class NetworkUserBackend : public UserDBBackend {
: Request(application), groupInfo(groupInfo0), check(checkOnly) {}
};
- class GroupUpdateRequest : public Request {
+ class MAD_COMMON_EXPORT GroupUpdateRequest : public Request {
private:
unsigned long gid;
GroupInfo groupInfo;
@@ -123,7 +125,7 @@ class NetworkUserBackend : public UserDBBackend {
: Request(application), gid(gid0), groupInfo(groupInfo0) {}
};
- class UserGroupRequest : public Request {
+ class MAD_COMMON_EXPORT UserGroupRequest : public Request {
private:
std::string type;
unsigned long uid;
@@ -137,7 +139,7 @@ class NetworkUserBackend : public UserDBBackend {
: Request(application), type(type0), uid(uid0), gid(gid0) {}
};
- class PasswordRequest : public Request {
+ class MAD_COMMON_EXPORT PasswordRequest : public Request {
private:
unsigned long uid;
std::string password;
diff --git a/src/Common/Base64Encoder.h b/src/Common/Base64Encoder.h
index 2d921d1..5534a62 100644
--- a/src/Common/Base64Encoder.h
+++ b/src/Common/Base64Encoder.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_BASE64ENCODER_H_
#define MAD_COMMON_BASE64ENCODER_H_
+#include "export.h"
+
#include <string>
#include <vector>
@@ -28,7 +30,7 @@
namespace Mad {
namespace Common {
-class Base64Encoder {
+class MAD_COMMON_EXPORT Base64Encoder {
private:
Base64Encoder();
diff --git a/src/Common/CMakeLists.txt b/src/Common/CMakeLists.txt
index e8e3152..016bf78 100644
--- a/src/Common/CMakeLists.txt
+++ b/src/Common/CMakeLists.txt
@@ -1,11 +1,22 @@
-add_subdirectory(Backends)
-add_subdirectory(RequestHandlers)
-add_subdirectory(Requests)
-
-
include_directories(${INCLUDES})
-add_library(Common
+mad_library(Common
+ export.h
+
+ Backends/NetworkUserBackend.cpp Backends/NetworkUserBackend.h
+
+ RequestHandlers/DisconnectRequestHandler.cpp RequestHandlers/DisconnectRequestHandler.h
+ RequestHandlers/FSInfoRequestHandler.cpp RequestHandlers/FSInfoRequestHandler.h
+ RequestHandlers/SimpleRequestHandler.cpp RequestHandlers/SimpleRequestHandler.h
+ RequestHandlers/SimpleRequestHandlerGroup.cpp RequestHandlers/SimpleRequestHandlerGroup.h
+ RequestHandlers/StatusRequestHandler.cpp RequestHandlers/StatusRequestHandler.h
+
+ Requests/DisconnectRequest.cpp Requests/DisconnectRequest.h
+ Requests/FSInfoRequest.h
+ Requests/IdentifyRequest.cpp Requests/IdentifyRequest.h
+ Requests/SimpleRequest.cpp Requests/SimpleRequest.h
+ Requests/StatusRequest.h
+
Application.cpp Application.h
Base64Encoder.cpp Base64Encoder.h
ClientConnection.cpp ClientConnection.h
@@ -27,4 +38,4 @@ add_library(Common
UserManager.cpp UserManager.h
XmlPacket.cpp XmlPacket.h
)
-target_link_libraries(Common Backends RequestHandlers Requests Net modules ${LIBXML2_LIBRARIES} ${DL_LIBRARY})
+target_link_libraries(Common Net modules ${LIBXML2_LIBRARIES} ${DL_LIBRARY})
diff --git a/src/Common/ClientConnection.h b/src/Common/ClientConnection.h
index acdd28a..b50f163 100644
--- a/src/Common/ClientConnection.h
+++ b/src/Common/ClientConnection.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_CLIENTCONNECTION_H_
#define MAD_COMMON_CLIENTCONNECTION_H_
+#include "export.h"
+
#include "Connection.h"
#include <Core/Exception.h>
@@ -33,7 +35,7 @@ class ClientConnection;
namespace Common {
-class ClientConnection : public Connection {
+class MAD_COMMON_EXPORT ClientConnection : public Connection {
private:
Net::ClientConnection *connection;
diff --git a/src/Common/Connection.cpp b/src/Common/Connection.cpp
index 87381f2..b2bb835 100644
--- a/src/Common/Connection.cpp
+++ b/src/Common/Connection.cpp
@@ -27,7 +27,7 @@ void Connection::receive(boost::shared_ptr<Net::Packet> packet) {
signalReceive.emit(boost::shared_ptr<XmlPacket>(new XmlPacket(*packet)), packet->getRequestId());
}
-bool Connection::sendPacket(const XmlPacket &packet, uint16_t requestId) {
+bool Connection::sendPacket(const XmlPacket &packet, boost::uint16_t requestId) {
return send(packet.encode(requestId));
}
diff --git a/src/Common/Connection.h b/src/Common/Connection.h
index 73a4ecc..e0c9ce6 100644
--- a/src/Common/Connection.h
+++ b/src/Common/Connection.h
@@ -20,9 +20,11 @@
#ifndef MAD_COMMON_CONNECTION_H_
#define MAD_COMMON_CONNECTION_H_
+#include "export.h"
+
#include <Core/Signals.h>
-#include <stdint.h>
+#include <boost/cstdint.hpp>
#include <sys/types.h>
namespace Mad {
@@ -35,11 +37,11 @@ namespace Common {
class XmlPacket;
-class Connection : private boost::noncopyable {
+class MAD_COMMON_EXPORT Connection : private boost::noncopyable {
private:
bool authenticated;
- Core::Signals::Signal2<boost::shared_ptr<const XmlPacket>, uint16_t> signalReceive;
+ Core::Signals::Signal2<boost::shared_ptr<const XmlPacket>, boost::uint16_t> signalReceive;
protected:
Connection(Core::Application *application) : authenticated(0), signalReceive(application) {}
@@ -51,9 +53,9 @@ class Connection : private boost::noncopyable {
public:
virtual ~Connection() {}
- bool sendPacket(const XmlPacket &packet, uint16_t requestId);
+ bool sendPacket(const XmlPacket &packet, boost::uint16_t requestId);
- Core::Signals::Connection connectSignalReceive(const Core::Signals::Signal2<boost::shared_ptr<const XmlPacket>, uint16_t>::slot_type &slot) {
+ Core::Signals::Connection connectSignalReceive(const Core::Signals::Signal2<boost::shared_ptr<const XmlPacket>, boost::uint16_t>::slot_type &slot) {
return signalReceive.connect(slot);
}
void disconnectSignalReceive(const Core::Signals::Connection &con) {
diff --git a/src/Common/GroupInfo.h b/src/Common/GroupInfo.h
index c9c4baf..c1a2274 100644
--- a/src/Common/GroupInfo.h
+++ b/src/Common/GroupInfo.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_GROUPINFO_H_
#define MAD_COMMON_GROUPINFO_H_
+#include "export.h"
+
#include <string>
namespace Mad {
diff --git a/src/Common/HostInfo.h b/src/Common/HostInfo.h
index ae25e39..4a6c3f3 100644
--- a/src/Common/HostInfo.h
+++ b/src/Common/HostInfo.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_HOSTINFO_H_
#define MAD_COMMON_HOSTINFO_H_
+#include "export.h"
+
#include <string>
namespace Mad {
diff --git a/src/Common/Module.h b/src/Common/Module.h
index 4bd58d2..fad295b 100644
--- a/src/Common/Module.h
+++ b/src/Common/Module.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_MODULE_H_
#define MAD_COMMON_MODULE_H_
+#include "export.h"
+
namespace Mad {
namespace Common {
diff --git a/src/Common/ModuleManager.cpp b/src/Common/ModuleManager.cpp
index 551229c..057af1f 100644
--- a/src/Common/ModuleManager.cpp
+++ b/src/Common/ModuleManager.cpp
@@ -28,8 +28,11 @@
#include <modules/modules.h>
-#include <dlfcn.h>
+#include <boost/thread/locks.hpp>
+#ifndef _WIN32
+# include <dlfcn.h>
+#endif
namespace Mad {
namespace Common {
@@ -61,7 +64,7 @@ bool ModuleManager::handleConfigEntry(const Core::ConfigEntry &entry, bool handl
if(entry[0].getKey().matches("LoadModule") && entry[1].empty()) {
if(!loadModule(entry[0][0].c_str()))
- application->logf(Core::LoggerBase::ERROR, "Can't load module '%s'.", entry[0][0].c_str());
+ application->logf(Core::LoggerBase::LOG_ERROR, "Can't load module '%s'.", entry[0][0].c_str());
return true;
}
@@ -79,27 +82,43 @@ bool ModuleManager::loadModule(const std::string &name) {
ModuleHandle handle = STATIC_MODULE;
Module *mod = Modules::loadStaticModule(application, name);
+
+ std::string libname = name + MODULE_SUFFIX;
if(!mod) {
- handle = dlopen((name + MODULE_SUFFIX).c_str(), RTLD_NOW | RTLD_GLOBAL);
+#ifdef WIN32
+ handle = LoadLibrary(libname.c_str());
+#else
+ handle = dlopen(libname.c_str(), RTLD_NOW | RTLD_GLOBAL);
+#endif
if(!handle) {
- application->log(Core::LoggerBase::VERBOSE, std::string("loadModule: Can't open module: ") + std::string(dlerror()));
+#ifdef WIN32
+ application->logf(Core::LoggerBase::LOG_VERBOSE, "loadModule: Can't open module: Error %u", GetLastError());
+#else
+ application->log(Core::LoggerBase::LOG_VERBOSE, std::string("loadModule: Can't open module: ") + std::string(dlerror()));
+#endif
return false;
}
ModuleLoadFunc loader;
- *(void**)&loader = dlsym(handle, (name + "_create").c_str());
+ std::string loadername = name + "_create";
+
+#ifdef WIN32
+ loader = (ModuleLoadFunc)GetProcAddress(handle, loadername.c_str());
+#else
+ *(void**)&loader = dlsym(handle, loadername.c_str());
+#endif
if(!loader) {
- application->log(Core::LoggerBase::VERBOSE, "loadModule: Can't open module: Invalid module");
+ application->log(Core::LoggerBase::LOG_VERBOSE, "loadModule: Can't open module: Invalid module");
return false;
}
Module *mod = loader(application);
if(!mod) {
- application->log(Core::LoggerBase::VERBOSE, "loadModule: Can't open module: Internal module error");
+ application->log(Core::LoggerBase::LOG_VERBOSE, "loadModule: Can't open module: Internal module error");
return false;
}
}
@@ -121,8 +140,13 @@ void ModuleManager::unloadModule(const std::string &name) {
delete mod->second.second;
- if(mod->second.first != STATIC_MODULE)
+ if(mod->second.first != STATIC_MODULE) {
+#ifdef WIN32
+ FreeLibrary(mod->second.first);
+#else
dlclose(mod->second.first);
+#endif
+ }
modules.erase(mod);
}
diff --git a/src/Common/ModuleManager.h b/src/Common/ModuleManager.h
index 0f30d3a..1c6a195 100644
--- a/src/Common/ModuleManager.h
+++ b/src/Common/ModuleManager.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_MODULEMANAGER_H_
#define MAD_COMMON_MODULEMANAGER_H_
+#include "export.h"
+
#include "Module.h"
#include <Core/Configurable.h>
@@ -29,16 +31,26 @@
#include <stack>
#include <string>
+#ifdef _WIN32
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+#endif
+
namespace Mad {
namespace Common {
class Application;
-class ModuleManager : public Core::Configurable, private boost::noncopyable {
+class MAD_COMMON_EXPORT ModuleManager : public Core::Configurable, private boost::noncopyable {
private:
friend class Application;
+#ifdef WIN32
+ typedef HMODULE ModuleHandle;
+#else
typedef void *ModuleHandle;
+#endif
+
typedef Module *(*ModuleLoadFunc)(Application*);
static const ModuleHandle STATIC_MODULE;
diff --git a/src/Common/Request.cpp b/src/Common/Request.cpp
index 94734d9..9325d46 100644
--- a/src/Common/Request.cpp
+++ b/src/Common/Request.cpp
@@ -24,7 +24,7 @@ namespace Common {
void Request::handlePacket(boost::shared_ptr<const XmlPacket> packet) {
if(packet->getType() == "Error") {
- signalFinished(Core::Exception(packet->get<const std::string&>("Where"), packet->get<Core::Exception::ErrorCode>("ErrorCode"),
+ signalFinished(Core::Exception(packet->get<const std::string&>("Where"), static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")),
packet->get<long>("SubCode"), packet->get<long>("SubSubCode")));
return;
}
diff --git a/src/Common/Request.h b/src/Common/Request.h
index 381344d..268a196 100644
--- a/src/Common/Request.h
+++ b/src/Common/Request.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_REQUEST_H_
#define MAD_COMMON_REQUEST_H_
+#include "export.h"
+
#include "RequestHandler.h"
#include <Core/Exception.h>
@@ -33,7 +35,7 @@
namespace Mad {
namespace Common {
-class Request : public RequestHandler {
+class MAD_COMMON_EXPORT Request : public RequestHandler {
private:
friend class RequestManager;
diff --git a/src/Common/RequestHandler.h b/src/Common/RequestHandler.h
index 1bd41c2..6d15c09 100644
--- a/src/Common/RequestHandler.h
+++ b/src/Common/RequestHandler.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_REQUESTHANDLER_H_
#define MAD_COMMON_REQUESTHANDLER_H_
+#include "export.h"
+
#include "Application.h"
#include "Connection.h"
#include "XmlPacket.h"
@@ -33,7 +35,7 @@ namespace Common {
class Connection;
-class RequestHandler : private boost::noncopyable {
+class MAD_COMMON_EXPORT RequestHandler : private boost::noncopyable {
private:
friend class RequestManager;
diff --git a/src/Common/RequestHandlerGroup.h b/src/Common/RequestHandlerGroup.h
index a32c327..d1b7b25 100644
--- a/src/Common/RequestHandlerGroup.h
+++ b/src/Common/RequestHandlerGroup.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_REQUESTHANDLERGROUP_H_
#define MAD_COMMON_REQUESTHANDLERGROUP_H_
+#include "export.h"
+
#include "RequestHandler.h"
#include <set>
diff --git a/src/Common/RequestHandlers/CMakeLists.txt b/src/Common/RequestHandlers/CMakeLists.txt
deleted file mode 100644
index 7c5fa8f..0000000
--- a/src/Common/RequestHandlers/CMakeLists.txt
+++ /dev/null
@@ -1,13 +0,0 @@
-include_directories(${INCLUDES})
-
-add_library(RequestHandlers STATIC
- DisconnectRequestHandler.cpp DisconnectRequestHandler.h
- FSInfoRequestHandler.cpp FSInfoRequestHandler.h
- SimpleRequestHandler.cpp SimpleRequestHandler.h
- SimpleRequestHandlerGroup.cpp SimpleRequestHandlerGroup.h
- StatusRequestHandler.cpp StatusRequestHandler.h
-)
-
-if(NOT BUILD_SHARED_LIBS)
- target_link_libraries(RequestHandlers Common)
-endif(NOT BUILD_SHARED_LIBS)
diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp
index 5d90855..a1ecd5a 100644
--- a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp
+++ b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp
@@ -26,7 +26,7 @@ namespace RequestHandlers {
void DisconnectRequestHandler::handlePacket(boost::shared_ptr<const XmlPacket> packet) {
if(packet->getType() != "Disconnect") {
- getApplication()->log(Core::LoggerBase::ERROR, "Received an unexpected packet.");
+ getApplication()->log(Core::LoggerBase::LOG_ERROR, "Received an unexpected packet.");
XmlPacket ret;
ret.setType("Error");
diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.h b/src/Common/RequestHandlers/DisconnectRequestHandler.h
index d0e76c5..f4bc827 100644
--- a/src/Common/RequestHandlers/DisconnectRequestHandler.h
+++ b/src/Common/RequestHandlers/DisconnectRequestHandler.h
@@ -20,13 +20,15 @@
#ifndef MAD_COMMON_REQUESTHANDLERS_DISCONNECTREQUESTHANDLER_H_
#define MAD_COMMON_REQUESTHANDLERS_DISCONNECTREQUESTHANDLER_H_
+#include "../export.h"
+
#include "../RequestHandler.h"
namespace Mad {
namespace Common {
namespace RequestHandlers {
-class DisconnectRequestHandler : public RequestHandler {
+class MAD_COMMON_EXPORT DisconnectRequestHandler : public RequestHandler {
protected:
virtual void handlePacket(boost::shared_ptr<const XmlPacket> packet);
diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.h b/src/Common/RequestHandlers/FSInfoRequestHandler.h
index caaaffa..17c1d8e 100644
--- a/src/Common/RequestHandlers/FSInfoRequestHandler.h
+++ b/src/Common/RequestHandlers/FSInfoRequestHandler.h
@@ -20,13 +20,15 @@
#ifndef MAD_COMMON_REQUESTHANDLERS_FSINFOREQUESTHANDLER_H_
#define MAD_COMMON_REQUESTHANDLERS_FSINFOREQUESTHANDLER_H_
+#include "../export.h"
+
#include "SimpleRequestHandler.h"
namespace Mad {
namespace Common {
namespace RequestHandlers {
-class FSInfoRequestHandler : public SimpleRequestHandler {
+class MAD_COMMON_EXPORT FSInfoRequestHandler : public SimpleRequestHandler {
private:
void handleRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret);
diff --git a/src/Common/RequestHandlers/SimpleRequestHandler.cpp b/src/Common/RequestHandlers/SimpleRequestHandler.cpp
index 1972214..84258a6 100644
--- a/src/Common/RequestHandlers/SimpleRequestHandler.cpp
+++ b/src/Common/RequestHandlers/SimpleRequestHandler.cpp
@@ -27,7 +27,7 @@ namespace RequestHandlers {
void SimpleRequestHandler::handlePacket(boost::shared_ptr<const XmlPacket> packet) {
if(packet->getType() != type) {
- getApplication()->log(Core::LoggerBase::ERROR, "Received an unexpected packet.");
+ getApplication()->log(Core::LoggerBase::LOG_ERROR, "Received an unexpected packet.");
XmlPacket ret;
ret.setType("Error");
diff --git a/src/Common/RequestHandlers/SimpleRequestHandler.h b/src/Common/RequestHandlers/SimpleRequestHandler.h
index faccc6f..3cf0f52 100644
--- a/src/Common/RequestHandlers/SimpleRequestHandler.h
+++ b/src/Common/RequestHandlers/SimpleRequestHandler.h
@@ -20,13 +20,15 @@
#ifndef MAD_COMMON_REQUESTHANDLERS_SIMPLEREQUESTHANDLER_H_
#define MAD_COMMON_REQUESTHANDLERS_SIMPLEREQUESTHANDLER_H_
+#include "../export.h"
+
#include "../RequestHandler.h"
namespace Mad {
namespace Common {
namespace RequestHandlers {
-class SimpleRequestHandler : public RequestHandler {
+class MAD_COMMON_EXPORT SimpleRequestHandler : public RequestHandler {
private:
std::string type;
boost::function2<void, boost::shared_ptr<const XmlPacket>, XmlPacket*> handler;
diff --git a/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp b/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp
index fd8db07..f084ac1 100644
--- a/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp
+++ b/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp
@@ -28,7 +28,7 @@ namespace RequestHandlers {
void SimpleRequestHandlerGroup::GroupRequestHandler::handlePacket(boost::shared_ptr<const XmlPacket> packet) {
if(packet->getType() != type) {
- getApplication()->log(Core::LoggerBase::ERROR, "Received an unexpected packet.");
+ getApplication()->log(Core::LoggerBase::LOG_ERROR, "Received an unexpected packet.");
XmlPacket ret;
ret.setType("Error");
diff --git a/src/Common/RequestHandlers/SimpleRequestHandlerGroup.h b/src/Common/RequestHandlers/SimpleRequestHandlerGroup.h
index 18e5dba..0a702f8 100644
--- a/src/Common/RequestHandlers/SimpleRequestHandlerGroup.h
+++ b/src/Common/RequestHandlers/SimpleRequestHandlerGroup.h
@@ -20,15 +20,17 @@
#ifndef MAD_COMMON_REQUESTHANDLERS_SIMPLEREQUESTHANDLERGROUP_H_
#define MAD_COMMON_REQUESTHANDLERS_SIMPLEREQUESTHANDLERGROUP_H_
+#include "../export.h"
+
#include "../RequestHandlerGroup.h"
namespace Mad {
namespace Common {
namespace RequestHandlers {
-class SimpleRequestHandlerGroup : public RequestHandlerGroup {
+class MAD_COMMON_EXPORT SimpleRequestHandlerGroup : public RequestHandlerGroup {
private:
- class GroupRequestHandler : public RequestHandler {
+ class MAD_COMMON_EXPORT GroupRequestHandler : public RequestHandler {
private:
std::string type;
boost::function3<void, boost::shared_ptr<const XmlPacket>, XmlPacket*, Connection*> handler;
diff --git a/src/Common/RequestHandlers/StatusRequestHandler.h b/src/Common/RequestHandlers/StatusRequestHandler.h
index 2c2f87e..4e79da8 100644
--- a/src/Common/RequestHandlers/StatusRequestHandler.h
+++ b/src/Common/RequestHandlers/StatusRequestHandler.h
@@ -20,13 +20,15 @@
#ifndef MAD_COMMON_REQUESTHANDLERS_STATUSREQUESTHANDLER_H_
#define MAD_COMMON_REQUESTHANDLERS_STATUSREQUESTHANDLER_H_
+#include "../export.h"
+
#include "SimpleRequestHandler.h"
namespace Mad {
namespace Common {
namespace RequestHandlers {
-class StatusRequestHandler : public SimpleRequestHandler {
+class MAD_COMMON_EXPORT StatusRequestHandler : public SimpleRequestHandler {
private:
void handleRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret);
diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp
index 271ab0a..c30ddc2 100644
--- a/src/Common/RequestManager.cpp
+++ b/src/Common/RequestManager.cpp
@@ -99,7 +99,7 @@ void RequestManager::receiveHandler(Connection *connection, boost::shared_ptr<co
if(!requestMap.isConnectionRegistered(connection)) {
// TODO: Error
- application->log(Core::LoggerBase::ERROR, "Received a packet from an unregistered connection.");
+ application->log(Core::LoggerBase::LOG_ERROR, "Received a packet from an unregistered connection.");
return;
}
@@ -126,7 +126,7 @@ void RequestManager::receiveHandler(Connection *connection, boost::shared_ptr<co
lock.unlock();
- application->logf(Core::LoggerBase::ERROR, "Received an unexpected packet with type '%s'.", packet->getType().c_str());
+ application->logf(Core::LoggerBase::LOG_ERROR, "Received an unexpected packet with type '%s'.", packet->getType().c_str());
XmlPacket ret;
ret.setType("Error");
@@ -139,14 +139,14 @@ bool RequestManager::sendRequest(Connection *connection, boost::shared_ptr<Reque
boost::unique_lock<boost::shared_mutex> lock(mutex);
if(!requestMap.isConnectionRegistered(connection)) {
- application->log(Core::LoggerBase::CRITICAL, "Trying to send a request over an unregistered connecion.");
+ application->log(Core::LoggerBase::LOG_CRITICAL, "Trying to send a request over an unregistered connecion.");
return false;
}
- uint16_t requestId = _getUnusedRequestId(connection);
+ boost::uint16_t requestId = _getUnusedRequestId(connection);
if(request->isFinished || !requestMap.addRequest(connection, requestId, request)) {
- application->log(Core::LoggerBase::CRITICAL, "Trying resend a request.");
+ application->log(Core::LoggerBase::LOG_CRITICAL, "Trying resend a request.");
return false;
}
request->connectSignalFinished(boost::bind(&RequestManager::handleRequestFinished, this, connection, requestId));
diff --git a/src/Common/RequestManager.h b/src/Common/RequestManager.h
index 0c50881..3b16ec6 100644
--- a/src/Common/RequestManager.h
+++ b/src/Common/RequestManager.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_REQUESTMANAGER_H_
#define MAD_COMMON_REQUESTMANAGER_H_
+#include "export.h"
+
#include "Request.h"
#include "RequestHandlerGroup.h"
@@ -35,12 +37,12 @@ namespace Common {
class Application;
-class RequestManager : private boost::noncopyable {
+class MAD_COMMON_EXPORT RequestManager : private boost::noncopyable {
private:
friend class Application;
friend class RequestHandler;
- class RequestMap : private boost::noncopyable {
+ class MAD_COMMON_EXPORT RequestMap : private boost::noncopyable {
private:
typedef std::map<boost::uint16_t, boost::shared_ptr<RequestHandler> > IdMap;
typedef std::map<const RequestHandler*, std::pair<Connection*, boost::uint16_t> > HandlerMap;
diff --git a/src/Common/Requests/CMakeLists.txt b/src/Common/Requests/CMakeLists.txt
deleted file mode 100644
index 972a47c..0000000
--- a/src/Common/Requests/CMakeLists.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-include_directories(${INCLUDES})
-
-add_library(Requests STATIC
- DisconnectRequest.cpp DisconnectRequest.h
- FSInfoRequest.h
- IdentifyRequest.cpp IdentifyRequest.h
- SimpleRequest.cpp SimpleRequest.h
- StatusRequest.h
-)
-#target_link_libraries(Requests ${KRB5_LIBRARIES})
diff --git a/src/Common/Requests/DisconnectRequest.cpp b/src/Common/Requests/DisconnectRequest.cpp
index 11786b6..523ef2a 100644
--- a/src/Common/Requests/DisconnectRequest.cpp
+++ b/src/Common/Requests/DisconnectRequest.cpp
@@ -32,7 +32,7 @@ void DisconnectRequest::sendRequest() {
void DisconnectRequest::handlePacket(boost::shared_ptr<const XmlPacket> packet) {
if(packet->getType() == "Error") {
- signalFinished(Core::Exception(packet->get<const std::string&>("Where"), packet->get<Core::Exception::ErrorCode>("ErrorCode"),
+ signalFinished(Core::Exception(packet->get<const std::string&>("Where"), static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")),
packet->get<long>("SubCode"), packet->get<long>("SubSubCode")));
return;
}
diff --git a/src/Common/Requests/DisconnectRequest.h b/src/Common/Requests/DisconnectRequest.h
index 9ba1005..a92c7e7 100644
--- a/src/Common/Requests/DisconnectRequest.h
+++ b/src/Common/Requests/DisconnectRequest.h
@@ -20,13 +20,15 @@
#ifndef MAD_COMMON_REQUESTS_DISCONNECTREQUEST_H_
#define MAD_COMMON_REQUESTS_DISCONNECTREQUEST_H_
+#include "../export.h"
+
#include "../Request.h"
namespace Mad {
namespace Common {
namespace Requests {
-class DisconnectRequest : public Request {
+class MAD_COMMON_EXPORT DisconnectRequest : public Request {
protected:
virtual void sendRequest();
virtual void handlePacket(boost::shared_ptr<const XmlPacket> packet);
diff --git a/src/Common/Requests/FSInfoRequest.h b/src/Common/Requests/FSInfoRequest.h
index 223b7a4..14aff57 100644
--- a/src/Common/Requests/FSInfoRequest.h
+++ b/src/Common/Requests/FSInfoRequest.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_REQUESTS_FSINFOREQUEST_H_
#define MAD_COMMON_REQUESTS_FSINFOREQUEST_H_
+#include "../export.h"
+
#include "SimpleRequest.h"
namespace Mad {
diff --git a/src/Common/Requests/IdentifyRequest.h b/src/Common/Requests/IdentifyRequest.h
index 7c7aaaf..e2e1399 100644
--- a/src/Common/Requests/IdentifyRequest.h
+++ b/src/Common/Requests/IdentifyRequest.h
@@ -17,8 +17,10 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef MAD_DAEMON_REQUESTS_IDENTIFYREQUEST_H_
-#define MAD_DAEMON_REQUESTS_IDENTIFYREQUEST_H_
+#ifndef MAD_COMMON_REQUESTS_IDENTIFYREQUEST_H_
+#define MAD_COMMON_REQUESTS_IDENTIFYREQUEST_H_
+
+#include "../export.h"
#include "../Request.h"
@@ -28,7 +30,7 @@ namespace Mad {
namespace Common {
namespace Requests {
-class IdentifyRequest : public Common::Request {
+class MAD_COMMON_EXPORT IdentifyRequest : public Common::Request {
private:
std::string hostname;
@@ -43,4 +45,4 @@ class IdentifyRequest : public Common::Request {
}
}
-#endif /* MAD_DAEMON_REQUESTS_IDENTIFYREQUEST_H_ */
+#endif /* MAD_COMMON_REQUESTS_IDENTIFYREQUEST_H_ */
diff --git a/src/Common/Requests/SimpleRequest.h b/src/Common/Requests/SimpleRequest.h
index 5cae38c..4bff997 100644
--- a/src/Common/Requests/SimpleRequest.h
+++ b/src/Common/Requests/SimpleRequest.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_REQUESTS_SIMPLEREQUEST_H_
#define MAD_COMMON_REQUESTS_SIMPLEREQUEST_H_
+#include "../export.h"
+
#include "../Request.h"
#include <string>
@@ -28,7 +30,7 @@ namespace Mad {
namespace Common {
namespace Requests {
-class SimpleRequest : public Request {
+class MAD_COMMON_EXPORT SimpleRequest : public Request {
protected:
const std::string type;
diff --git a/src/Common/Requests/StatusRequest.h b/src/Common/Requests/StatusRequest.h
index 09f4d90..0569a72 100644
--- a/src/Common/Requests/StatusRequest.h
+++ b/src/Common/Requests/StatusRequest.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_REQUESTS_STATUSREQUEST_H_
#define MAD_COMMON_REQUESTS_STATUSREQUEST_H_
+#include "../export.h"
+
#include "SimpleRequest.h"
namespace Mad {
diff --git a/src/Common/SystemBackend.h b/src/Common/SystemBackend.h
index aba83f8..673265a 100644
--- a/src/Common/SystemBackend.h
+++ b/src/Common/SystemBackend.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_SYSTEMBACKEND_H_
#define MAD_COMMON_SYSTEMBACKEND_H_
+#include "export.h"
+
#include "SystemManager.h"
namespace Mad {
@@ -29,19 +31,19 @@ class SystemBackend {
protected:
friend class SystemManager;
- virtual void getUptimeInfo(unsigned long */*uptime*/, unsigned long */*idleTime*/) throw(Core::Exception) {
+ virtual void getUptimeInfo(unsigned long* /*uptime*/, unsigned long* /*idleTime*/) throw(Core::Exception) {
throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
}
- virtual void getMemoryInfo(unsigned long */*totalMem*/, unsigned long */*freeMem*/, unsigned long */*totalSwap*/, unsigned long */*freeSwap*/) throw(Core::Exception) {
+ virtual void getMemoryInfo(unsigned long* /*totalMem*/, unsigned long* /*freeMem*/, unsigned long* /*totalSwap*/, unsigned long* /*freeSwap*/) throw(Core::Exception) {
throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
}
- virtual void getLoadInfo(unsigned long */*currentLoad*/, unsigned long */*nProcesses*/, float */*loadAvg1*/, float */*loadAvg5*/, float */*loadAvg15*/) throw(Core::Exception) {
+ virtual void getLoadInfo(unsigned long* /*currentLoad*/, unsigned long* /*nProcesses*/, float* /*loadAvg1*/, float* /*loadAvg5*/, float* /*loadAvg15*/) throw(Core::Exception) {
throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
}
- virtual void getFSInfo(std::vector<SystemManager::FSInfo> */*fsInfo*/) throw(Core::Exception) {
+ virtual void getFSInfo(std::vector<SystemManager::FSInfo>* /*fsInfo*/) throw(Core::Exception) {
throw Core::Exception(Core::Exception::NOT_IMPLEMENTED);
}
diff --git a/src/Common/SystemManager.cpp b/src/Common/SystemManager.cpp
index 02e55cc..572c510 100644
--- a/src/Common/SystemManager.cpp
+++ b/src/Common/SystemManager.cpp
@@ -34,7 +34,7 @@ bool SystemManager::Compare::operator() (boost::shared_ptr<SystemBackend> b1, bo
void SystemManager::getUptimeInfo(unsigned long *uptime, unsigned long *idleTime) throw(Core::Exception) {
Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
- for(std::set<boost::shared_ptr<SystemBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
+ for(std::set<boost::shared_ptr<SystemBackend>, Compare>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
try {
(*backend)->getUptimeInfo(uptime, idleTime);
return;
@@ -51,7 +51,7 @@ void SystemManager::getUptimeInfo(unsigned long *uptime, unsigned long *idleTime
void SystemManager::getMemoryInfo(unsigned long *totalMem, unsigned long *freeMem, unsigned long *totalSwap, unsigned long *freeSwap) throw(Core::Exception) {
Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
- for(std::set<boost::shared_ptr<SystemBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
+ for(std::set<boost::shared_ptr<SystemBackend>, Compare>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
try {
(*backend)->getMemoryInfo(totalMem, freeMem, totalSwap, freeSwap);
return;
@@ -68,7 +68,7 @@ void SystemManager::getMemoryInfo(unsigned long *totalMem, unsigned long *freeMe
void SystemManager::getLoadInfo(unsigned long *currentLoad, unsigned long *nProcesses, float *loadAvg1, float *loadAvg5, float *loadAvg15) throw(Core::Exception) {
Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
- for(std::set<boost::shared_ptr<SystemBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
+ for(std::set<boost::shared_ptr<SystemBackend>, Compare>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
try {
(*backend)->getLoadInfo(currentLoad, nProcesses, loadAvg1, loadAvg5, loadAvg15);
return;
@@ -85,7 +85,7 @@ void SystemManager::getLoadInfo(unsigned long *currentLoad, unsigned long *nProc
void SystemManager::getFSInfo(std::vector<FSInfo> *fsInfo) throw(Core::Exception) {
Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
- for(std::set<boost::shared_ptr<SystemBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
+ for(std::set<boost::shared_ptr<SystemBackend>, Compare>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
try {
(*backend)->getFSInfo(fsInfo);
return;
@@ -102,7 +102,7 @@ void SystemManager::getFSInfo(std::vector<FSInfo> *fsInfo) throw(Core::Exception
void SystemManager::shutdown() throw(Core::Exception) {
Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
- for(std::set<boost::shared_ptr<SystemBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
+ for(std::set<boost::shared_ptr<SystemBackend>, Compare>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
try {
(*backend)->shutdown();
return;
@@ -119,7 +119,7 @@ void SystemManager::shutdown() throw(Core::Exception) {
void SystemManager::reboot() throw(Core::Exception) {
Core::Exception e(Core::Exception::NOT_IMPLEMENTED);
- for(std::set<boost::shared_ptr<SystemBackend> >::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
+ for(std::set<boost::shared_ptr<SystemBackend>, Compare>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
try {
(*backend)->reboot();
return;
diff --git a/src/Common/SystemManager.h b/src/Common/SystemManager.h
index c17642f..4a8472b 100644
--- a/src/Common/SystemManager.h
+++ b/src/Common/SystemManager.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_SYSTEMMANAGER_H_
#define MAD_COMMON_SYSTEMMANAGER_H_
+#include "export.h"
+
#include <set>
#include <string>
#include <vector>
@@ -35,11 +37,11 @@ namespace Common {
class Application;
class SystemBackend;
-class SystemManager : private boost::noncopyable {
+class MAD_COMMON_EXPORT SystemManager : private boost::noncopyable {
private:
friend class Application;
- struct Compare {
+ struct MAD_COMMON_EXPORT Compare {
bool operator() (boost::shared_ptr<SystemBackend> b1, boost::shared_ptr<SystemBackend> b2);
};
diff --git a/src/Common/UserCache.cpp b/src/Common/UserCache.cpp
index 4058c4c..1367041 100644
--- a/src/Common/UserCache.cpp
+++ b/src/Common/UserCache.cpp
@@ -42,9 +42,9 @@ boost::shared_ptr<const std::map<unsigned long, UserInfo> > UserCache::getUserLi
}
else {
if(users)
- application->log(Core::LoggerBase::USER, Core::LoggerBase::DEBUG, "Using cached user list");
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_DEBUG, "Using cached user list");
else
- application->log(Core::LoggerBase::USER, Core::LoggerBase::DEBUG, "Error cached");
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_DEBUG, "Error cached");
}
}
catch(Core::Exception e) {
@@ -133,9 +133,9 @@ boost::shared_ptr<const std::map<unsigned long, GroupInfo> > UserCache::getGroup
}
else {
if(groups)
- application->log(Core::LoggerBase::USER, Core::LoggerBase::DEBUG, "Using cached group list");
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_DEBUG, "Using cached group list");
else
- application->log(Core::LoggerBase::USER, Core::LoggerBase::DEBUG, "Error cached");
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_DEBUG, "Error cached");
}
}
catch(Core::Exception e) {
@@ -223,9 +223,9 @@ boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > UserCache:
}
else {
if(userGroups)
- application->log(Core::LoggerBase::USER, Core::LoggerBase::DEBUG, "Using cached user-group table");
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_DEBUG, "Using cached user-group table");
else
- application->log(Core::LoggerBase::USER, Core::LoggerBase::DEBUG, "Error cached");
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_DEBUG, "Error cached");
}
}
catch(Core::Exception e) {
diff --git a/src/Common/UserCache.h b/src/Common/UserCache.h
index bec3328..c579221 100644
--- a/src/Common/UserCache.h
+++ b/src/Common/UserCache.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_USERCACHE_H_
#define MAD_COMMON_USERCACHE_H_
+#include "export.h"
+
#include "UserDBBackend.h"
#include <limits>
@@ -32,7 +34,7 @@ namespace Common {
class Application;
class UserManager;
-class UserCache : public UserDBBackend, private boost::noncopyable {
+class MAD_COMMON_EXPORT UserCache : public UserDBBackend, private boost::noncopyable {
private:
friend class UserManager;
diff --git a/src/Common/UserConfigBackend.h b/src/Common/UserConfigBackend.h
index 94550eb..e7c6245 100644
--- a/src/Common/UserConfigBackend.h
+++ b/src/Common/UserConfigBackend.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_USERCONFIGBACKEND_H_
#define MAD_COMMON_USERCONFIGBACKEND_H_
+#include "export.h"
+
#include <Core/Exception.h>
#include "UserInfo.h"
diff --git a/src/Common/UserDBBackend.h b/src/Common/UserDBBackend.h
index 664739c..8d4c95a 100644
--- a/src/Common/UserDBBackend.h
+++ b/src/Common/UserDBBackend.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_USERDBBACKEND_H_
#define MAD_COMMON_USERDBBACKEND_H_
+#include "export.h"
+
#include <Core/Exception.h>
#include "UserInfo.h"
diff --git a/src/Common/UserInfo.h b/src/Common/UserInfo.h
index 2d64299..6859904 100644
--- a/src/Common/UserInfo.h
+++ b/src/Common/UserInfo.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_USERINFO_H_
#define MAD_COMMON_USERINFO_H_
+#include "export.h"
+
#include <string>
namespace Mad {
diff --git a/src/Common/UserManager.cpp b/src/Common/UserManager.cpp
index d04a644..d4467ee 100644
--- a/src/Common/UserManager.cpp
+++ b/src/Common/UserManager.cpp
@@ -43,7 +43,7 @@ bool UserManager::handleConfigEntry(const Core::ConfigEntry &entry, bool /*handl
char *endptr;
unsigned long val = std::strtoul(entry[1][0].c_str(), &endptr, 10);
if(entry[1][0].empty() || *endptr) {
- application->logf(Core::LoggerBase::WARNING, "UserBackendHome: Invalid configuration: MinUid '%s'", entry[1][0].c_str());
+ application->logf(Core::LoggerBase::LOG_WARNING, "UserBackendHome: Invalid configuration: MinUid '%s'", entry[1][0].c_str());
}
else {
minUid = val;
@@ -55,7 +55,7 @@ bool UserManager::handleConfigEntry(const Core::ConfigEntry &entry, bool /*handl
char *endptr;
unsigned long val = std::strtoul(entry[1][0].c_str(), &endptr, 10);
if(entry[1][0].empty() || *endptr) {
- application->logf(Core::LoggerBase::WARNING, "UserBackendHome: Invalid configuration: MaxUid '%s'", entry[1][0].c_str());
+ application->logf(Core::LoggerBase::LOG_WARNING, "UserBackendHome: Invalid configuration: MaxUid '%s'", entry[1][0].c_str());
}
else {
maxUid = val;
@@ -67,7 +67,7 @@ bool UserManager::handleConfigEntry(const Core::ConfigEntry &entry, bool /*handl
char *endptr;
unsigned long val = std::strtoul(entry[1][0].c_str(), &endptr, 10);
if(entry[1][0].empty() || *endptr) {
- application->logf(Core::LoggerBase::WARNING, "UserBackendHome: Invalid configuration: MinGid '%s'", entry[1][0].c_str());
+ application->logf(Core::LoggerBase::LOG_WARNING, "UserBackendHome: Invalid configuration: MinGid '%s'", entry[1][0].c_str());
}
else {
minGid = val;
@@ -79,7 +79,7 @@ bool UserManager::handleConfigEntry(const Core::ConfigEntry &entry, bool /*handl
char *endptr;
unsigned long val = std::strtoul(entry[1][0].c_str(), &endptr, 10);
if(entry[1][0].empty() || *endptr) {
- application->logf(Core::LoggerBase::WARNING, "UserBackendHome: Invalid configuration: MaxGid '%s'", entry[1][0].c_str());
+ application->logf(Core::LoggerBase::LOG_WARNING, "UserBackendHome: Invalid configuration: MaxGid '%s'", entry[1][0].c_str());
}
else {
maxGid = val;
@@ -234,7 +234,7 @@ void UserManager::addUser(const UserInfo &userInfo) throw(Core::Exception) {
(*configBackend)->addUser(userInfo);
}
catch(Core::Exception e) {
- application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
}
}
}
@@ -258,7 +258,7 @@ void UserManager::updateUser(unsigned long uid, const UserInfo &userInfo) throw(
(*configBackend)->updateUser(*oldUserInfo, userInfo);
}
catch(Core::Exception e) {
- application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
}
}
}
@@ -280,7 +280,7 @@ void UserManager::deleteUser(unsigned long uid) throw(Core::Exception) {
(*configBackend)->deleteUser(*userInfo);
}
catch(Core::Exception e) {
- application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
}
}
}
@@ -317,7 +317,7 @@ void UserManager::addGroup(const GroupInfo &groupInfo) throw(Core::Exception) {
(*configBackend)->addGroup(groupInfo);
}
catch(Core::Exception e) {
- application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
}
}
}
@@ -341,7 +341,7 @@ void UserManager::updateGroup(unsigned long gid, const GroupInfo &groupInfo) thr
(*configBackend)->updateGroup(*oldGroupInfo, groupInfo);
}
catch(Core::Exception e) {
- application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
}
}
}
@@ -363,7 +363,7 @@ void UserManager::deleteGroup(unsigned long gid) throw(Core::Exception) {
(*configBackend)->deleteGroup(*groupInfo);
}
catch(Core::Exception e) {
- application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
}
}
}
@@ -388,7 +388,7 @@ void UserManager::addUserToGroup(unsigned long uid, unsigned long gid) throw(Cor
(*configBackend)->addUserToGroup(*userInfo, *groupInfo);
}
catch(Core::Exception e) {
- application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
}
}
}
@@ -413,7 +413,7 @@ void UserManager::deleteUserFromGroup(unsigned long uid, unsigned long gid) thro
(*configBackend)->deleteUserFromGroup(*userInfo, *groupInfo);
}
catch(Core::Exception e) {
- application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
}
}
}
@@ -439,7 +439,7 @@ void UserManager::setPassword(unsigned long uid, const std::string &password) th
exception = e;
if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
}
for(std::set<boost::shared_ptr<UserConfigBackend> >::iterator configBackend = configBackends.begin(); configBackend != configBackends.end(); ++configBackend) {
@@ -449,7 +449,7 @@ void UserManager::setPassword(unsigned long uid, const std::string &password) th
}
catch(Core::Exception e) {
if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED)
- application->log(Core::LoggerBase::USER, Core::LoggerBase::WARNING, e.strerror());
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.strerror());
}
}
diff --git a/src/Common/UserManager.h b/src/Common/UserManager.h
index b966662..6da5af4 100644
--- a/src/Common/UserManager.h
+++ b/src/Common/UserManager.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_USERMANAGER_H_
#define MAD_COMMON_USERMANAGER_H_
+#include "export.h"
+
#include "UserInfo.h"
#include "GroupInfo.h"
@@ -40,7 +42,7 @@ class UserConfigBackend;
class UserDBBackend;
class UserCache;
-class UserManager : public Core::Configurable, private boost::noncopyable {
+class MAD_COMMON_EXPORT UserManager : public Core::Configurable, private boost::noncopyable {
private:
friend class Application;
diff --git a/src/Common/XmlPacket.cpp b/src/Common/XmlPacket.cpp
index dbd3fc7..ff8ca6a 100644
--- a/src/Common/XmlPacket.cpp
+++ b/src/Common/XmlPacket.cpp
@@ -101,6 +101,7 @@ XmlPacket::Element::Element(xmlNodePtr node) : elementNode(node), type(NONE) {
}
str = (char*)content;
+ std::istringstream buf(str);
if(!xmlStrcmp(typestr, (xmlChar*)"binary")) {
type = BINARY;
@@ -109,31 +110,52 @@ XmlPacket::Element::Element(xmlNodePtr node) : elementNode(node), type(NONE) {
}
else if(!xmlStrcmp(typestr, (xmlChar*)"int")) {
type = INT;
- value = std::strtol((char*)content, 0, 10);
+
+ long tmp;
+ buf >> tmp;
+ value = tmp;
}
else if(!xmlStrcmp(typestr, (xmlChar*)"uint")) {
type = UINT;
- value = std::strtoul((char*)content, 0, 10);
+
+ unsigned long tmp;
+ buf >> tmp;
+ value = tmp;
}
else if(!xmlStrcmp(typestr, (xmlChar*)"int64")) {
type = INT64;
- value = std::strtoll((char*)content, 0, 10);
+
+ long long tmp;
+ buf >> tmp;
+ value = tmp;
}
else if(!xmlStrcmp(typestr, (xmlChar*)"uint64")) {
type = UINT64;
- value = std::strtoull((char*)content, 0, 10);
+
+ unsigned long long tmp;
+ buf >> tmp;
+ value = tmp;
}
else if(!xmlStrcmp(typestr, (xmlChar*)"float")) {
type = FLOAT;
- value = std::strtof((char*)content, 0);
+
+ float tmp;
+ buf >> tmp;
+ value = tmp;
}
else if(!xmlStrcmp(typestr, (xmlChar*)"double")) {
type = DOUBLE;
- value = std::strtod((char*)content, 0);
+
+ double tmp;
+ buf >> tmp;
+ value = tmp;
}
else if(!xmlStrcmp(typestr, (xmlChar*)"longdouble")) {
type = LONGDOUBLE;
- value = std::strtold((char*)content, 0);
+
+ long double tmp;
+ buf >> tmp;
+ value = tmp;
}
else if(!xmlStrcmp(typestr, (xmlChar*)"string")) {
type = STRING;
@@ -272,7 +294,7 @@ void XmlPacket::setType(const std::string &type) {
xmlSetProp(packetNode, (xmlChar*)"type", (xmlChar*)type.c_str());
}
-Net::Packet XmlPacket::encode(uint16_t requestId) const {
+Net::Packet XmlPacket::encode(boost::uint16_t requestId) const {
xmlChar *buf;
int length;
diff --git a/src/Common/XmlPacket.h b/src/Common/XmlPacket.h
index 546525a..9d63075 100644
--- a/src/Common/XmlPacket.h
+++ b/src/Common/XmlPacket.h
@@ -20,6 +20,8 @@
#ifndef MAD_COMMON_XMLPACKET_H_
#define MAD_COMMON_XMLPACKET_H_
+#include "export.h"
+
#include <Net/Packet.h>
#include <map>
@@ -40,7 +42,7 @@
namespace Mad {
namespace Common {
-class XmlPacket {
+class MAD_COMMON_EXPORT XmlPacket {
public:
class Entry;
class List;
@@ -50,7 +52,7 @@ class XmlPacket {
xmlNodePtr packetNode;
Entry *entry;
- class Element : private boost::noncopyable {
+ class MAD_COMMON_EXPORT Element : private boost::noncopyable {
private:
friend class Entry;
@@ -130,7 +132,7 @@ class XmlPacket {
};
public:
- class Entry : private boost::noncopyable {
+ class MAD_COMMON_EXPORT Entry : private boost::noncopyable {
private:
friend class List;
friend class XmlPacket;
@@ -284,7 +286,7 @@ class XmlPacket {
}
};
- class List : private boost::noncopyable {
+ class MAD_COMMON_EXPORT List : private boost::noncopyable {
private:
friend class Entry;
@@ -302,7 +304,8 @@ class XmlPacket {
typedef value_type &reference;
typedef value_type *pointer;
- typedef ssize_t difference_type;
+ typedef long difference_type;
+
private:
IteratorType it;
@@ -476,14 +479,14 @@ class XmlPacket {
entry->unset(name);
}
- Net::Packet encode(uint16_t requestId) const;
+ Net::Packet encode(boost::uint16_t requestId) const;
};
-template <> std::string XmlPacket::Entry::get<std::string>(const std::string &name) const;
-template <> const std::string& XmlPacket::Entry::get<const std::string&>(const std::string &name) const;
+template <> MAD_COMMON_EXPORT std::string XmlPacket::Entry::get<std::string>(const std::string &name) const;
+template <> MAD_COMMON_EXPORT const std::string& XmlPacket::Entry::get<const std::string&>(const std::string &name) const;
-template <> std::vector<boost::uint8_t> XmlPacket::Entry::get<std::vector<unsigned char> >(const std::string &name) const;
-template <> const std::vector<boost::uint8_t>& XmlPacket::Entry::get<const std::vector<unsigned char>&>(const std::string &name) const;
+template <> MAD_COMMON_EXPORT std::vector<boost::uint8_t> XmlPacket::Entry::get<std::vector<unsigned char> >(const std::string &name) const;
+template <> MAD_COMMON_EXPORT const std::vector<boost::uint8_t>& XmlPacket::Entry::get<const std::vector<unsigned char>&>(const std::string &name) const;
}
}
diff --git a/src/Common/export.h b/src/Common/export.h
new file mode 100644
index 0000000..71207d3
--- /dev/null
+++ b/src/Common/export.h
@@ -0,0 +1,22 @@
+#ifndef MAD_COMMON_EXPORT
+# ifdef _WIN32
+# ifdef MAD_COMMON_EXPORTS
+# define MAD_COMMON_EXPORT _declspec(dllexport)
+# else
+# define MAD_COMMON_EXPORT _declspec(dllimport)
+# endif
+# else
+# define MAD_COMMON_EXPORT
+# endif
+
+# ifdef MAD_COMMON_EXPORTS
+# ifndef MAD_NET_EXPORTS
+# define MAD_NET_EXPORTS
+# endif
+# else
+# undef MAD_NET_EXPORTS
+# endif
+
+# include <Net/export.h>
+
+#endif
diff --git a/src/Core/Application.cpp b/src/Core/Application.cpp
index 5ef1bae..7083be5 100644
--- a/src/Core/Application.cpp
+++ b/src/Core/Application.cpp
@@ -24,6 +24,10 @@
#include <cstdlib>
+#ifndef va_copy
+# define va_copy(d, s) (d) = (s)
+#endif
+
namespace Mad {
namespace Core {
@@ -45,11 +49,11 @@ void Application::logfv(LoggerBase::MessageCategory category, LoggerBase::Messag
va_list ap2;
va_copy(ap2, ap);
- int n = std::vsnprintf(buf, size, format, ap2);
+ int n = vsnprintf(buf, size, format, ap2);
va_end(ap2);
if(n > -1 && n < size) {
- logManager->log(category, level, std::time(0), buf);
+ logManager->log(category, level, boost::posix_time::microsec_clock::universal_time(), buf);
std::free(buf);
return;
}
@@ -65,7 +69,7 @@ void Application::logfv(LoggerBase::MessageCategory category, LoggerBase::Messag
}
void Application::log(LoggerBase::MessageCategory category, LoggerBase::MessageLevel level, const std::string &message) {
- logManager->log(category, level, std::time(0), message);
+ logManager->log(category, level, boost::posix_time::microsec_clock::universal_time(), message);
}
void Application::logf(LoggerBase::MessageCategory category, LoggerBase::MessageLevel level, const char *format, ...) {
@@ -78,21 +82,21 @@ void Application::logf(LoggerBase::MessageCategory category, LoggerBase::Message
void Application::logf(LoggerBase::MessageCategory category, const char *format, ...) {
va_list ap;
va_start(ap, format);
- logfv(category, LoggerBase::DEFAULT, format, ap);
+ logfv(category, LoggerBase::LOG_DEFAULT, format, ap);
va_end(ap);
}
void Application::logf(LoggerBase::MessageLevel level, const char *format, ...) {
va_list ap;
va_start(ap, format);
- logfv(LoggerBase::GENERAL, level, format, ap);
+ logfv(LoggerBase::LOG_GENERAL, level, format, ap);
va_end(ap);
}
void Application::logf(const char *format, ...) {
va_list ap;
va_start(ap, format);
- logfv(LoggerBase::GENERAL, LoggerBase::DEFAULT, format, ap);
+ logfv(LoggerBase::LOG_GENERAL, LoggerBase::LOG_DEFAULT, format, ap);
va_end(ap);
}
diff --git a/src/Core/Application.h b/src/Core/Application.h
index fece1cf..3951b5c 100644
--- a/src/Core/Application.h
+++ b/src/Core/Application.h
@@ -20,6 +20,8 @@
#ifndef MAD_CORE_APPLICATION_H_
#define MAD_CORE_APPLICATION_H_
+#include "export.h"
+
#include "LoggerBase.h"
#include <cstdarg>
@@ -35,7 +37,7 @@ class ConfigManager;
class LogManager;
class ThreadManager;
-class Application : private boost::noncopyable {
+class MAD_CORE_EXPORT Application : private boost::noncopyable {
private:
boost::asio::io_service ioService;
@@ -70,15 +72,15 @@ class Application : private boost::noncopyable {
void log(LoggerBase::MessageCategory category, LoggerBase::MessageLevel level, const std::string &message);
void log(LoggerBase::MessageCategory category, const std::string &message) {
- log(category, LoggerBase::DEFAULT, message);
+ log(category, LoggerBase::LOG_DEFAULT, message);
}
void log(LoggerBase::MessageLevel level, const std::string &message) {
- log(LoggerBase::GENERAL, level, message);
+ log(LoggerBase::LOG_GENERAL, level, message);
}
void log(const std::string &message) {
- log(LoggerBase::GENERAL, LoggerBase::DEFAULT, message);
+ log(LoggerBase::LOG_GENERAL, LoggerBase::LOG_DEFAULT, message);
}
diff --git a/src/Core/CMakeLists.txt b/src/Core/CMakeLists.txt
index 3c0db7a..28c0dd5 100644
--- a/src/Core/CMakeLists.txt
+++ b/src/Core/CMakeLists.txt
@@ -1,7 +1,9 @@
include_directories(${INCLUDES})
link_directories(${Boost_LIBRARY_DIRS})
-add_library(Core STATIC
+mad_library(Core
+ export.h
+
Signals/Connection.h
Signals/GenericSignal.h
Signals/Signal0.h
diff --git a/src/Core/ConfigEntry.h b/src/Core/ConfigEntry.h
index c3bcd1d..fcd8dd4 100644
--- a/src/Core/ConfigEntry.h
+++ b/src/Core/ConfigEntry.h
@@ -20,15 +20,19 @@
#ifndef MAD_CORE_CONFIGENTRY_H_
#define MAD_CORE_CONFIGENTRY_H_
+#include "export.h"
+
#include <stdexcept>
#include <string>
#include <string.h>
#include <vector>
+#include <boost/algorithm/string/case_conv.hpp>
+
namespace Mad {
namespace Core {
-class ConfigEntry {
+class MAD_CORE_EXPORT ConfigEntry {
public:
class String : public std::string {
public:
@@ -36,11 +40,11 @@ class ConfigEntry {
String(const std::string &str) : std::string(str) {}
bool matches(const std::string &str) const {
- return (strcasecmp(c_str(), str.c_str()) == 0);
+ return (boost::algorithm::to_lower_copy(static_cast<const std::string&>(*this)) == boost::algorithm::to_lower_copy(str));
}
};
- class Entry {
+ class MAD_CORE_EXPORT Entry {
private:
String key;
std::vector<String> value;
diff --git a/src/Core/ConfigManager.cpp b/src/Core/ConfigManager.cpp
index eb9b846..83e92db 100644
--- a/src/Core/ConfigManager.cpp
+++ b/src/Core/ConfigManager.cpp
@@ -40,13 +40,13 @@ bool ConfigManager::Compare::operator() (const Configurable *c1, const Configura
void ConfigManager::handleConfigEntry(const ConfigEntry &entry) {
bool handled = false;
- for(std::set<Configurable*>::iterator c = configurables.begin(); c != configurables.end(); ++c) {
+ for(std::set<Configurable*, Compare>::iterator c = configurables.begin(); c != configurables.end(); ++c) {
if((*c)->handleConfigEntry(entry, handled))
handled = true;
}
if(!handled)
- application->logf(LoggerBase::WARNING, "Invalid config option '%s'.", entry[entry.getSize()-1].getKey().c_str());
+ application->logf(LoggerBase::LOG_WARNING, "Invalid config option '%s'.", entry[entry.getSize()-1].getKey().c_str());
}
bool ConfigManager::loadFile(const std::string &filename) {
@@ -119,7 +119,7 @@ void ConfigManager::finish() {
if(finished)
return;
- for(std::set<Configurable*>::iterator c = configurables.begin(); c != configurables.end(); ++c)
+ for(std::set<Configurable*, Compare>::iterator c = configurables.begin(); c != configurables.end(); ++c)
(*c)->configFinished();
finished = true;
diff --git a/src/Core/ConfigManager.h b/src/Core/ConfigManager.h
index f0e25d3..10b378d 100644
--- a/src/Core/ConfigManager.h
+++ b/src/Core/ConfigManager.h
@@ -20,6 +20,8 @@
#ifndef MAD_CORE_CONFIGMANAGER_H_
#define MAD_CORE_CONFIGMANAGER_H_
+#include "export.h"
+
#include <memory>
#include <set>
#include <string>
@@ -31,9 +33,9 @@ class Application;
class ConfigEntry;
class Configurable;
-class ConfigManager {
+class MAD_CORE_EXPORT ConfigManager {
private:
- struct Compare {
+ struct MAD_CORE_EXPORT Compare {
bool operator() (const Configurable *c1, const Configurable *c2);
};
diff --git a/src/Core/Configurable.h b/src/Core/Configurable.h
index c526379..f385e10 100644
--- a/src/Core/Configurable.h
+++ b/src/Core/Configurable.h
@@ -20,6 +20,8 @@
#ifndef MAD_CORE_CONFIGURABLE_H_
#define MAD_CORE_CONFIGURABLE_H_
+#include "export.h"
+
namespace Mad {
namespace Core {
diff --git a/src/Core/Exception.h b/src/Core/Exception.h
index 1824ff6..15ff749 100644
--- a/src/Core/Exception.h
+++ b/src/Core/Exception.h
@@ -20,12 +20,14 @@
#ifndef MAD_CORE_EXCEPTION_H_
#define MAD_CORE_EXCEPTION_H_
+#include "export.h"
+
#include <string>
namespace Mad {
namespace Core {
-class Exception {
+class MAD_CORE_EXPORT Exception {
public:
enum ErrorCode {
SUCCESS = 0x0000, UNEXPECTED_PACKET = 0x0001, INVALID_ACTION = 0x0002, NOT_AVAILABLE = 0x0003, NOT_FINISHED = 0x0004, NOT_IMPLEMENTED = 0x0005,
diff --git a/src/Core/LogManager.cpp b/src/Core/LogManager.cpp
index d5928f9..b255c04 100644
--- a/src/Core/LogManager.cpp
+++ b/src/Core/LogManager.cpp
@@ -27,21 +27,21 @@
namespace Mad {
namespace Core {
-void LogManager::ConsoleLogger::logMessage(MessageCategory /*category*/, MessageLevel level, time_t /*timestamp*/, const std::string &message) {
- if(level != CRITICAL) {// Critical messages are printed to cerr directly, so don't print them a second time
+void LogManager::ConsoleLogger::logMessage(MessageCategory /*category*/, MessageLevel level, boost::posix_time::ptime /*timestamp*/, const std::string &message) {
+ if(level != LOG_CRITICAL) {// Critical messages are printed to cerr directly, so don't print them a second time
cerrLock.lock();
std::cerr << message << std::endl;
cerrLock.unlock();
}
}
-void LogManager::ConsoleLogger::logMessage(MessageCategory /*category*/, MessageLevel /*level*/, time_t /*timestamp*/, const std::string &message, const std::string &messageSource) {
+void LogManager::ConsoleLogger::logMessage(MessageCategory /*category*/, MessageLevel /*level*/, boost::posix_time::ptime /*timestamp*/, const std::string &message, const std::string &messageSource) {
cerrLock.lock();
std::cerr << message << " from " << messageSource << std::endl;
cerrLock.unlock();
}
-void LogManager::ConsoleLogger::logMessageDirect(MessageCategory /*category*/, MessageLevel /*level*/, time_t /*timestamp*/, const std::string &message) {
+void LogManager::ConsoleLogger::logMessageDirect(MessageCategory /*category*/, MessageLevel /*level*/, boost::posix_time::ptime /*timestamp*/, const std::string &message) {
cerrLock.lock();
std::cerr << message << std::endl;
cerrLock.unlock();
@@ -69,7 +69,7 @@ bool LogManager::handleConfigEntry(const ConfigEntry &entry, bool handled) {
}
}
else if(entry[1].empty()) {
- application->logf(Logger::WARNING, "Unknown logger '%s'.", entry[0][0].c_str());
+ application->logf(Logger::LOG_WARNING, "Unknown logger '%s'.", entry[0][0].c_str());
return true;
}
}
@@ -82,7 +82,7 @@ void LogManager::configFinished() {
registerLogger(boost::static_pointer_cast<Logger>(consoleLogger));
// TODO Debug
- consoleLogger->Logger::setLevel(LoggerBase::VERBOSE);
+ consoleLogger->Logger::setLevel(LoggerBase::LOG_VERBOSE);
queueLock.lock();
configured = true;
@@ -90,8 +90,8 @@ void LogManager::configFinished() {
queueCond.notify_one();
}
-void LogManager::log(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message) {
- if(level == LoggerBase::CRITICAL)
+void LogManager::log(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message) {
+ if(level == LoggerBase::LOG_CRITICAL)
consoleLogger->logMessageDirect(category, level, timestamp, message);
queueLock.lock();
@@ -101,7 +101,7 @@ void LogManager::log(MessageCategory category, MessageLevel level, time_t timest
queueCond.notify_one();
}
-void LogManager::log(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message, const std::string &source) {
+void LogManager::log(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source) {
queueLock.lock();
RemoteMessage m = {category, level, timestamp, message, source};
remoteMessageQueue.push(m);
diff --git a/src/Core/LogManager.h b/src/Core/LogManager.h
index d3233f0..3aab49e 100644
--- a/src/Core/LogManager.h
+++ b/src/Core/LogManager.h
@@ -20,6 +20,8 @@
#ifndef MAD_CORE_LOGMANAGER_H_
#define MAD_CORE_LOGMANAGER_H_
+#include "export.h"
+
#include "Configurable.h"
#include "Logger.h"
#include "RemoteLogger.h"
@@ -36,7 +38,7 @@ namespace Core {
class Application;
class ThreadManager;
-class LogManager : public Configurable {
+class MAD_CORE_EXPORT LogManager : public Configurable {
private:
friend class Application;
friend class ThreadManager;
@@ -47,14 +49,14 @@ class LogManager : public Configurable {
struct Message {
MessageCategory category;
MessageLevel level;
- time_t timestamp;
+ boost::posix_time::ptime timestamp;
std::string message;
};
struct RemoteMessage {
MessageCategory category;
MessageLevel level;
- time_t timestamp;
+ boost::posix_time::ptime timestamp;
std::string message;
std::string source;
};
@@ -62,17 +64,17 @@ class LogManager : public Configurable {
class ConsoleLogger : public Logger, public RemoteLogger {
private:
// For long messages, writing to cerr is not atomic
- // -> lock cerr to prevent mixing messages up
+ // -> lock cerr to prevent messages mixing up
boost::mutex cerrLock;
protected:
- virtual void logMessage(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message);
- virtual void logMessage(MessageCategory category, MessageLevel, time_t timestamp, const std::string &message, const std::string &messageSource);
+ virtual void logMessage(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message);
+ virtual void logMessage(MessageCategory category, MessageLevel, boost::posix_time::ptime timestamp, const std::string &message, const std::string &messageSource);
public:
ConsoleLogger() {}
- void logMessageDirect(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message);
+ void logMessageDirect(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message);
};
@@ -109,8 +111,8 @@ class LogManager : public Configurable {
virtual void configFinished();
public:
- void log(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message);
- void log(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message, const std::string &source);
+ void log(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message);
+ void log(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source);
void registerLogger(boost::shared_ptr<Logger> logger) {
loggerLock.lock();
diff --git a/src/Core/Logger.h b/src/Core/Logger.h
index b5a6b43..53ec665 100644
--- a/src/Core/Logger.h
+++ b/src/Core/Logger.h
@@ -20,10 +20,12 @@
#ifndef MAD_CORE_LOGGER_H_
#define MAD_CORE_LOGGER_H_
+#include "export.h"
+
#include "LoggerBase.h"
-#include <ctime>
#include <string>
+#include <boost/date_time/posix_time/ptime.hpp>
namespace Mad {
namespace Core {
@@ -34,7 +36,7 @@ class Logger : public LoggerBase {
protected:
friend class LogManager;
- virtual void logMessage(MessageCategory category, MessageLevel level, time_t timestamp, const std::string &message) = 0;
+ virtual void logMessage(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message) = 0;
};
diff --git a/src/Core/LoggerBase.h b/src/Core/LoggerBase.h
index 50f08b3..a2df969 100644
--- a/src/Core/LoggerBase.h
+++ b/src/Core/LoggerBase.h
@@ -20,6 +20,8 @@
#ifndef MAD_CORE_LOGGERBASE_H_
#define MAD_CORE_LOGGERBASE_H_
+#include "export.h"
+
#include <bitset>
#include <list>
@@ -29,18 +31,18 @@ namespace Core {
class LoggerBase {
public:
enum MessageLevel {
- CRITICAL, ERROR, WARNING, DEFAULT, VERBOSE, DEBUG
+ LOG_CRITICAL, LOG_ERROR, LOG_WARNING, LOG_DEFAULT, LOG_VERBOSE, LOG_DEBUG
};
enum MessageCategory {
- SYSTEM, NETWORK, DAEMON, USER, DISK, PROGRAM, GENERAL
+ LOG_SYSTEM, LOG_NETWORK, LOG_DAEMON, LOG_USER, LOG_DISK, LOG_PROGRAM, LOG_GENERAL
};
protected:
std::bitset<16> categories;
MessageLevel level;
- LoggerBase() : level(DEFAULT) {setAllCategories();}
+ LoggerBase() : level(LOG_DEFAULT) {setAllCategories();}
virtual ~LoggerBase() {}
public:
diff --git a/src/Core/RemoteLogger.h b/src/Core/RemoteLogger.h
index 0507567..8dedb7a 100644
--- a/src/Core/RemoteLogger.h
+++ b/src/Core/RemoteLogger.h
@@ -20,10 +20,12 @@
#ifndef MAD_CORE_REMOTELOGGER_H_
#define MAD_CORE_REMOTELOGGER_H_
+#include "export.h"
+
#include "LoggerBase.h"
-#include <ctime>
#include <string>
+#include <boost/date_time/posix_time/ptime.hpp>
namespace Mad {
namespace Core {
@@ -34,7 +36,7 @@ class RemoteLogger : public LoggerBase {
protected:
friend class LogManager;
- virtual void logMessage(MessageCategory category, MessageLevel level, time_t messageTimestamp, const std::string &message, const std::string &messageSource) = 0;
+ virtual void logMessage(MessageCategory category, MessageLevel level, boost::posix_time::ptime messageTimestamp, const std::string &message, const std::string &messageSource) = 0;
};
}
diff --git a/src/Core/Signals/Connection.h b/src/Core/Signals/Connection.h
index 8a99058..fde959d 100644
--- a/src/Core/Signals/Connection.h
+++ b/src/Core/Signals/Connection.h
@@ -20,13 +20,15 @@
#ifndef MAD_CORE_SIGNALS_CONNECTION_H_
#define MAD_CORE_SIGNALS_CONNECTION_H_
+#include "../export.h"
+
namespace Mad {
namespace Core {
namespace Signals {
class SignalBase;
-class Connection {
+class MAD_CORE_EXPORT Connection {
private:
friend class SignalBase;
diff --git a/src/Core/Signals/GenericSignal.h b/src/Core/Signals/GenericSignal.h
index 2203181..4f783e3 100644
--- a/src/Core/Signals/GenericSignal.h
+++ b/src/Core/Signals/GenericSignal.h
@@ -20,6 +20,8 @@
#ifndef MAD_CORE_SIGNALS_GENERICSIGNAL_H_
#define MAD_CORE_SIGNALS_GENERICSIGNAL_H_
+#include "../export.h"
+
#include "SignalBase.h"
#include <map>
@@ -30,7 +32,7 @@ namespace Core {
namespace Signals {
template <typename FunctionType>
-class GenericSignal : protected SignalBase {
+class MAD_CORE_EXPORT GenericSignal : protected SignalBase {
public:
typedef FunctionType slot_type;
diff --git a/src/Core/Signals/Signal0.h b/src/Core/Signals/Signal0.h
index d751df2..ca1ceed 100644
--- a/src/Core/Signals/Signal0.h
+++ b/src/Core/Signals/Signal0.h
@@ -20,6 +20,8 @@
#ifndef MAD_CORE_SIGNALS_SIGNAL0_H_
#define MAD_CORE_SIGNALS_SIGNAL0_H_
+#include "../export.h"
+
#include "GenericSignal.h"
#include "../Application.h"
#include "../ThreadManager.h"
diff --git a/src/Core/Signals/Signal1.h b/src/Core/Signals/Signal1.h
index 69d7685..2d8acb7 100644
--- a/src/Core/Signals/Signal1.h
+++ b/src/Core/Signals/Signal1.h
@@ -20,6 +20,8 @@
#ifndef MAD_CORE_SIGNALS_SIGNAL1_H_
#define MAD_CORE_SIGNALS_SIGNAL1_H_
+#include "../export.h"
+
#include "GenericSignal.h"
#include "../Application.h"
#include "../ThreadManager.h"
diff --git a/src/Core/Signals/Signal2.h b/src/Core/Signals/Signal2.h
index bab7f5c..e9ed010 100644
--- a/src/Core/Signals/Signal2.h
+++ b/src/Core/Signals/Signal2.h
@@ -20,6 +20,8 @@
#ifndef MAD_CORE_SIGNALS_SIGNAL2_H_
#define MAD_CORE_SIGNALS_SIGNAL2_H_
+#include "../export.h"
+
#include "GenericSignal.h"
#include "../Application.h"
#include "../ThreadManager.h"
diff --git a/src/Core/Signals/SignalBase.h b/src/Core/Signals/SignalBase.h
index 6599285..cf38053 100644
--- a/src/Core/Signals/SignalBase.h
+++ b/src/Core/Signals/SignalBase.h
@@ -20,6 +20,8 @@
#ifndef MAD_CORE_SIGNALS_SIGNALBASE_H_
#define MAD_CORE_SIGNALS_SIGNALBASE_H_
+#include "../export.h"
+
#include "Connection.h"
#include <set>
diff --git a/src/Core/ThreadManager.h b/src/Core/ThreadManager.h
index ab5113c..9cae13c 100644
--- a/src/Core/ThreadManager.h
+++ b/src/Core/ThreadManager.h
@@ -20,6 +20,8 @@
#ifndef MAD_CORE_THREADMANAGER_H_
#define MAD_CORE_THREADMANAGER_H_
+#include "export.h"
+
#include <queue>
#include <map>
@@ -34,7 +36,7 @@ namespace Core {
class Application;
-class ThreadManager : private boost::noncopyable {
+class MAD_CORE_EXPORT ThreadManager : private boost::noncopyable {
private:
friend class Application;
diff --git a/src/Core/Tokenizer.h b/src/Core/Tokenizer.h
index fef04db..637aa05 100644
--- a/src/Core/Tokenizer.h
+++ b/src/Core/Tokenizer.h
@@ -20,13 +20,15 @@
#ifndef MAD_CORE_TOKENIZER_H_
#define MAD_CORE_TOKENIZER_H_
+#include "export.h"
+
#include <string>
#include <vector>
namespace Mad {
namespace Core {
-class Tokenizer {
+class MAD_CORE_EXPORT Tokenizer {
private:
static const std::string delimiters;
diff --git a/src/Core/export.h b/src/Core/export.h
new file mode 100644
index 0000000..2ccd147
--- /dev/null
+++ b/src/Core/export.h
@@ -0,0 +1,11 @@
+#ifndef MAD_CORE_EXPORT
+# ifdef _WIN32
+# ifdef MAD_CORE_EXPORTS
+# define MAD_CORE_EXPORT _declspec(dllexport)
+# else
+# define MAD_CORE_EXPORT _declspec(dllimport)
+# endif
+# else
+# define MAD_CORE_EXPORT
+# endif
+#endif
diff --git a/src/Daemon/Application.h b/src/Daemon/Application.h
index aed7b70..8469bf0 100644
--- a/src/Daemon/Application.h
+++ b/src/Daemon/Application.h
@@ -20,12 +20,14 @@
#ifndef MAD_DAEMON_APPLICATION_H_
#define MAD_DAEMON_APPLICATION_H_
+#include "export.h"
+
#include <Common/Application.h>
namespace Mad {
namespace Daemon {
-class Application : public Common::Application {
+class MAD_DAEMON_EXPORT Application : public Common::Application {
public:
Application();
};
diff --git a/src/Daemon/Backends/NetworkLogger.h b/src/Daemon/Backends/NetworkLogger.h
index 4ef6f60..9965468 100644
--- a/src/Daemon/Backends/NetworkLogger.h
+++ b/src/Daemon/Backends/NetworkLogger.h
@@ -20,6 +20,8 @@
#ifndef MAD_DAEMON_BACKENDS_NETWORKLOGGER_H_
#define MAD_DAEMON_BACKENDS_NETWORKLOGGER_H_
+#include "../export.h"
+
#include <Common/RequestManager.h>
#include <Daemon/Requests/LogRequest.h>
@@ -33,7 +35,7 @@ class NetworkLogger : public Core::Logger {
Common::Connection *connection;
protected:
- virtual void logMessage(Core::Logger::MessageCategory category, Core::Logger::MessageLevel level, time_t messageTimestamp, const std::string &message) {
+ virtual void logMessage(Core::Logger::MessageCategory category, Core::Logger::MessageLevel level, boost::posix_time::ptime messageTimestamp, const std::string &message) {
boost::shared_ptr<Requests::LogRequest> request(new Requests::LogRequest(application, category, level, messageTimestamp, message));
application->getRequestManager()->sendRequest(connection, request);
}
diff --git a/src/Daemon/CMakeLists.txt b/src/Daemon/CMakeLists.txt
index 151c229..3972429 100644
--- a/src/Daemon/CMakeLists.txt
+++ b/src/Daemon/CMakeLists.txt
@@ -1,11 +1,14 @@
-add_subdirectory(RequestHandlers)
-add_subdirectory(Requests)
-
include_directories(${INCLUDES})
-add_library(Daemon
+mad_library(Daemon
+ export.h
+
Backends/NetworkLogger.h
+ RequestHandlers/CommandRequestHandler.cpp RequestHandlers/CommandRequestHandler.h
+
+ Requests/LogRequest.cpp Requests/LogRequest.h
+
Application.cpp Application.h
)
-target_link_libraries(Daemon DaemonRequestHandlers DaemonRequests Common)
+target_link_libraries(Daemon Common)
diff --git a/src/Daemon/RequestHandlers/CMakeLists.txt b/src/Daemon/RequestHandlers/CMakeLists.txt
deleted file mode 100644
index 21a2fbb..0000000
--- a/src/Daemon/RequestHandlers/CMakeLists.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-include_directories(${INCLUDES})
-
-add_library(DaemonRequestHandlers STATIC
- CommandRequestHandler.cpp CommandRequestHandler.h
-)
diff --git a/src/Daemon/RequestHandlers/CommandRequestHandler.h b/src/Daemon/RequestHandlers/CommandRequestHandler.h
index 87b4d1a..188b3d4 100644
--- a/src/Daemon/RequestHandlers/CommandRequestHandler.h
+++ b/src/Daemon/RequestHandlers/CommandRequestHandler.h
@@ -20,13 +20,15 @@
#ifndef MAD_DAEMON_REQUESTHANDLERS_COMMANDREQUESTHANDLER_H_
#define MAD_DAEMON_REQUESTHANDLERS_COMMANDREQUESTHANDLER_H_
+#include "../export.h"
+
#include <Common/RequestHandlers/SimpleRequestHandler.h>
namespace Mad {
namespace Daemon {
namespace RequestHandlers {
-class CommandRequestHandler : public Common::RequestHandlers::SimpleRequestHandler {
+class MAD_DAEMON_EXPORT CommandRequestHandler : public Common::RequestHandlers::SimpleRequestHandler {
private:
void handleRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret);
diff --git a/src/Daemon/Requests/CMakeLists.txt b/src/Daemon/Requests/CMakeLists.txt
deleted file mode 100644
index 90eb542..0000000
--- a/src/Daemon/Requests/CMakeLists.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-include_directories(${INCLUDES})
-
-add_library(DaemonRequests STATIC
- LogRequest.cpp LogRequest.h
-)
diff --git a/src/Daemon/Requests/LogRequest.cpp b/src/Daemon/Requests/LogRequest.cpp
index f1469ca..2d12fc8 100644
--- a/src/Daemon/Requests/LogRequest.cpp
+++ b/src/Daemon/Requests/LogRequest.cpp
@@ -19,6 +19,8 @@
#include "LogRequest.h"
+#include <boost/date_time/posix_time/posix_time.hpp>
+
namespace Mad {
namespace Daemon {
namespace Requests {
@@ -30,7 +32,7 @@ void LogRequest::sendRequest() {
packet.set("category", category);
packet.set("level", level);
- packet.set("timestamp", messageTimestamp);
+ packet.set("timestamp", boost::posix_time::to_iso_string(messageTimestamp));
packet.set("message", message);
sendPacket(packet);
diff --git a/src/Daemon/Requests/LogRequest.h b/src/Daemon/Requests/LogRequest.h
index ecc36fb..49d5c6f 100644
--- a/src/Daemon/Requests/LogRequest.h
+++ b/src/Daemon/Requests/LogRequest.h
@@ -20,25 +20,27 @@
#ifndef MAD_DAEMON_REQUESTS_LOGREQUEST_H_
#define MAD_DAEMON_REQUESTS_LOGREQUEST_H_
+#include "../export.h"
+
#include <Common/Request.h>
-#include <ctime>
+#include <boost/date_time/posix_time/ptime.hpp>
namespace Mad {
namespace Daemon {
namespace Requests {
-class LogRequest : public Common::Request {
+class MAD_DAEMON_EXPORT LogRequest : public Common::Request {
private:
Core::LoggerBase::MessageCategory category;
Core::LoggerBase::MessageLevel level;
- time_t messageTimestamp;
+ boost::posix_time::ptime messageTimestamp;
std::string message;
protected:
virtual void sendRequest();
public:
- LogRequest(Common::Application *application, Core::LoggerBase::MessageCategory category0, Core::LoggerBase::MessageLevel level0, time_t messageTimestamp0, const std::string &message0)
+ LogRequest(Common::Application *application, Core::LoggerBase::MessageCategory category0, Core::LoggerBase::MessageLevel level0, boost::posix_time::ptime messageTimestamp0, const std::string &message0)
: Common::Request(application), category(category0), level(level0), messageTimestamp(messageTimestamp0), message(message0) {}
};
diff --git a/src/Daemon/export.h b/src/Daemon/export.h
new file mode 100644
index 0000000..1c5cf31
--- /dev/null
+++ b/src/Daemon/export.h
@@ -0,0 +1,11 @@
+#ifndef MAD_DAEMON_EXPORT
+# ifdef _WIN32
+# ifdef MAD_DAEMON_EXPORTS
+# define MAD_DAEMON_EXPORT _declspec(dllexport)
+# else
+# define MAD_DAEMON_EXPORT _declspec(dllimport)
+# endif
+# else
+# define MAD_DAEMON_EXPORT
+# endif
+#endif
diff --git a/src/Net/CMakeLists.txt b/src/Net/CMakeLists.txt
index ceaf6bd..7d38d7a 100644
--- a/src/Net/CMakeLists.txt
+++ b/src/Net/CMakeLists.txt
@@ -1,6 +1,8 @@
include_directories(${INCLUDES})
-add_library(Net STATIC
+mad_library(Net
+ export.h
+
ClientConnection.cpp ClientConnection.h
Connection.cpp Connection.h
Listener.cpp Listener.h
diff --git a/src/Net/ClientConnection.cpp b/src/Net/ClientConnection.cpp
index d0c7aa4..2228b7a 100644
--- a/src/Net/ClientConnection.cpp
+++ b/src/Net/ClientConnection.cpp
@@ -31,7 +31,7 @@ void ClientConnection::handleConnect(const boost::system::error_code& error) {
boost::lock_guard<boost::shared_mutex> lock(connectionLock);
- socket.async_handshake(boost::asio::ssl::stream_base::client, boost::bind(&ClientConnection::handleHandshake, this, boost::asio::placeholders::error));
+ socket->async_handshake(boost::asio::ssl::stream_base::client, boost::bind(&ClientConnection::handleHandshake, this, boost::asio::placeholders::error));
}
void ClientConnection::connect(const boost::asio::ip::tcp::endpoint &address) throw(Core::Exception) {
@@ -45,7 +45,7 @@ void ClientConnection::connect(const boost::asio::ip::tcp::endpoint &address) th
peer = address;
_setState(CONNECT);
- socket.lowest_layer().async_connect(address, boost::bind(&ClientConnection::handleConnect, this, boost::asio::placeholders::error));
+ socket->lowest_layer().async_connect(address, boost::bind(&ClientConnection::handleConnect, this, boost::asio::placeholders::error));
}
}
diff --git a/src/Net/ClientConnection.h b/src/Net/ClientConnection.h
index b17c208..d29d6ae 100644
--- a/src/Net/ClientConnection.h
+++ b/src/Net/ClientConnection.h
@@ -20,27 +20,24 @@
#ifndef MAD_NET_CLIENTCONNECTION_H_
#define MAD_NET_CLIENTCONNECTION_H_
+#include "export.h"
+
#include "Connection.h"
#include <Core/Exception.h>
-#include <boost/utility/base_from_member.hpp>
-
namespace Mad {
namespace Net {
class IPAddress;
-class ClientConnection : private boost::base_from_member<boost::asio::ssl::context>, public Connection {
+class MAD_NET_EXPORT ClientConnection : public Connection {
private:
void handleConnect(const boost::system::error_code& error);
public:
- ClientConnection(Core::Application *application)
- : boost::base_from_member<boost::asio::ssl::context>(boost::ref(application->getIOService()), boost::asio::ssl::context::sslv23),
- Connection(application, member)
- {
- member.set_verify_mode(boost::asio::ssl::context::verify_none);
+ ClientConnection(Core::Application *application) : Connection(application) {
+ context.set_verify_mode(boost::asio::ssl::context::verify_none);
}
void connect(const boost::asio::ip::tcp::endpoint &address) throw(Core::Exception);
diff --git a/src/Net/Connection.cpp b/src/Net/Connection.cpp
index 305e1de..036c3d8 100644
--- a/src/Net/Connection.cpp
+++ b/src/Net/Connection.cpp
@@ -61,7 +61,7 @@ void Connection::handleShutdown(const boost::system::error_code& error) {
boost::lock_guard<boost::shared_mutex> lock(connectionLock);
if(error) {
- application->logf(Core::LoggerBase::VERBOSE, "Shutdown error: %s", error.message().c_str());
+ application->logf(Core::LoggerBase::LOG_VERBOSE, "Shutdown error: %s", error.message().c_str());
}
_setState(DISCONNECTED);
@@ -77,14 +77,14 @@ void Connection::enterReceiveLoop() {
return;
}
- rawReceive(sizeof(Packet::Data), boost::bind(&Connection::handleHeaderReceive, this, _1));
+ rawReceive(sizeof(Packet::Header), boost::bind(&Connection::handleHeaderReceive, this, _1));
}
-void Connection::handleHeaderReceive(const std::vector<boost::uint8_t> &data) {
+void Connection::handleHeaderReceive(const boost::shared_array<boost::uint8_t> &data) {
{
boost::lock_guard<boost::shared_mutex> lock(connectionLock);
- header = *reinterpret_cast<const Packet::Data*>(data.data());
+ header = *reinterpret_cast<const Packet::Header*>(data.get());
}
if(header.length == 0) {
@@ -97,35 +97,34 @@ void Connection::handleHeaderReceive(const std::vector<boost::uint8_t> &data) {
}
}
-void Connection::handleDataReceive(const std::vector<boost::uint8_t> &data) {
+void Connection::handleDataReceive(const boost::shared_array<boost::uint8_t> &data) {
{
boost::upgrade_lock<boost::shared_mutex> lock(connectionLock);
- Packet packet();
- receiveSignal.emit(boost::shared_ptr<Packet>(new Packet(ntohs(header.requestId), data.data(), ntohs(header.length))));
+ receiveSignal.emit(boost::shared_ptr<Packet>(new Packet(ntohs(header.requestId), data.get(), ntohs(header.length))));
}
enterReceiveLoop();
}
-void Connection::handleRead(const boost::system::error_code& error, std::size_t bytes_transferred, std::size_t length, const boost::function1<void, const std::vector<boost::uint8_t>& > &notify) {
+void Connection::handleRead(const boost::system::error_code& error, std::size_t bytes_transferred, std::size_t length, const boost::function1<void, const boost::shared_array<boost::uint8_t>& > &notify) {
if(error || (bytes_transferred+received) < length) {
- application->logf(Core::LoggerBase::VERBOSE, "Read error: %s", error.message().c_str());
+ application->logf(Core::LoggerBase::LOG_VERBOSE, "Read error: %s", error.message().c_str());
// TODO Error
doDisconnect();
return;
}
- std::vector<boost::uint8_t> buffer;
+ boost::shared_array<boost::uint8_t> buffer(new boost::uint8_t[length]);
{
boost::shared_lock<boost::shared_mutex> lock(connectionLock);
if(state != CONNECTED || !receiving)
return;
-
- buffer.insert(buffer.end(), receiveBuffer.data(), receiveBuffer.data()+length);
+
+ std::memcpy(buffer.get(), receiveBuffer->data(), length);
}
{
@@ -135,13 +134,13 @@ void Connection::handleRead(const boost::system::error_code& error, std::size_t
received = received + bytes_transferred - length;
if(received)
- std::memmove(receiveBuffer.data(), receiveBuffer.data()+length, received);
+ std::memmove(receiveBuffer->data(), receiveBuffer->data()+length, received);
}
notify(buffer);
}
-void Connection::rawReceive(std::size_t length, const boost::function1<void, const std::vector<boost::uint8_t>& > &notify) {
+void Connection::rawReceive(std::size_t length, const boost::function1<void, const boost::shared_array<boost::uint8_t>& > &notify) {
boost::upgrade_lock<boost::shared_mutex> lock(connectionLock);
if(!_isConnected())
@@ -156,7 +155,7 @@ void Connection::rawReceive(std::size_t length, const boost::function1<void, con
receiving = true;
if(length > received) {
- boost::asio::async_read(socket, boost::asio::buffer(receiveBuffer.data()+received, receiveBuffer.size()-received), boost::asio::transfer_at_least(length),
+ boost::asio::async_read(*socket, boost::asio::buffer(receiveBuffer->data()+received, receiveBuffer->size()-received), boost::asio::transfer_at_least(length),
boost::bind(&Connection::handleRead, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred,
length, notify));
@@ -183,14 +182,14 @@ void Connection::handleWrite(const boost::system::error_code& error, std::size_t
}
if(error) {
- application->logf(Core::LoggerBase::VERBOSE, "Write error: %s", error.message().c_str());
+ application->logf(Core::LoggerBase::LOG_VERBOSE, "Write error: %s", error.message().c_str());
// TODO Error
doDisconnect();
}
}
-void Connection::rawSend(const uint8_t *data, std::size_t length) {
+void Connection::rawSend(const boost::uint8_t *data, std::size_t length) {
boost::upgrade_lock<boost::shared_mutex> lock(connectionLock);
if(!_isConnected())
@@ -200,7 +199,7 @@ void Connection::rawSend(const uint8_t *data, std::size_t length) {
boost::upgrade_to_unique_lock<boost::shared_mutex> upgradeLock(lock);
sending++;
- boost::asio::async_write(socket, Buffer(data, length), boost::bind(&Connection::handleWrite, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
+ boost::asio::async_write(*socket, Buffer(data, length), boost::bind(&Connection::handleWrite, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
}
}
@@ -211,7 +210,7 @@ bool Connection::send(const Packet &packet) {
return false;
}
- rawSend((const uint8_t*)packet.getRawData(), packet.getRawDataLength());
+ rawSend((const boost::uint8_t*)packet.getRawData(), packet.getRawDataLength());
return true;
}
@@ -233,7 +232,7 @@ void Connection::disconnect() {
void Connection::doDisconnect() {
boost::lock_guard<boost::shared_mutex> lock(connectionLock);
- socket.async_shutdown(boost::bind(&Connection::handleShutdown, this, boost::asio::placeholders::error));
+ socket->async_shutdown(boost::bind(&Connection::handleShutdown, this, boost::asio::placeholders::error));
}
}
diff --git a/src/Net/Connection.h b/src/Net/Connection.h
index 3070282..19ee826 100644
--- a/src/Net/Connection.h
+++ b/src/Net/Connection.h
@@ -20,10 +20,15 @@
#ifndef MAD_NET_CONNECTION_H_
#define MAD_NET_CONNECTION_H_
+#include "export.h"
+
#include "Packet.h"
#include <Core/Signals.h>
#include <Core/ThreadManager.h>
+#include <boost/array.hpp>
+#include <boost/shared_array.hpp>
+
#include <boost/asio.hpp>
#include <boost/asio/ssl.hpp>
@@ -35,7 +40,7 @@ namespace Net {
class Listener;
class ThreadManager;
-class Connection : boost::noncopyable {
+class MAD_NET_EXPORT Connection : boost::noncopyable {
protected:
friend class Listener;
friend class ThreadManager;
@@ -45,9 +50,9 @@ class Connection : boost::noncopyable {
};
private:
- class Buffer {
+ class MAD_NET_EXPORT Buffer {
public:
- Buffer(const uint8_t *data0, std::size_t length) : data(new std::vector<uint8_t>(data0, data0+length)), buffer(boost::asio::buffer(*data)) {}
+ Buffer(const boost::uint8_t *data0, std::size_t length) : data(new std::vector<boost::uint8_t>(data0, data0+length)), buffer(boost::asio::buffer(*data)) {}
typedef boost::asio::const_buffer value_type;
typedef const boost::asio::const_buffer* const_iterator;
@@ -56,7 +61,7 @@ class Connection : boost::noncopyable {
const boost::asio::const_buffer* end() const { return &buffer + 1; }
private:
- boost::shared_ptr<std::vector<uint8_t> > data;
+ boost::shared_ptr<std::vector<boost::uint8_t> > data;
boost::asio::const_buffer buffer;
};
@@ -66,10 +71,10 @@ class Connection : boost::noncopyable {
State state;
- std::vector<boost::uint8_t> receiveBuffer;
+ boost::scoped_ptr<boost::array<boost::uint8_t, 1024*1024> > receiveBuffer;
std::size_t received;
- Packet::Data header;
+ Packet::Header header;
Core::Signals::Signal1<boost::shared_ptr<Packet> > receiveSignal;
Core::Signals::Signal0 connectedSignal;
@@ -77,24 +82,29 @@ class Connection : boost::noncopyable {
bool receiving;
unsigned long sending;
-
+
+ void _initSocket() {
+ socket.reset(new boost::asio::ssl::stream<boost::asio::ip::tcp::socket>(application->getIOService(), context));
+ }
+
void enterReceiveLoop();
- void handleHeaderReceive(const std::vector<boost::uint8_t> &data);
- void handleDataReceive(const std::vector<boost::uint8_t> &data);
+ void handleHeaderReceive(const boost::shared_array<boost::uint8_t> &data);
+ void handleDataReceive(const boost::shared_array<boost::uint8_t> &data);
- void handleRead(const boost::system::error_code& error, std::size_t bytes_transferred, std::size_t length, const boost::function1<void, const std::vector<boost::uint8_t>& > &notify);
+ void handleRead(const boost::system::error_code& error, std::size_t bytes_transferred, std::size_t length, const boost::function1<void, const boost::shared_array<boost::uint8_t>& > &notify);
void handleWrite(const boost::system::error_code& error, std::size_t);
void handleShutdown(const boost::system::error_code& error);
- void rawReceive(std::size_t length, const boost::function1<void, const std::vector<boost::uint8_t>& > &notify);
- void rawSend(const uint8_t *data, std::size_t length);
+ void rawReceive(std::size_t length, const boost::function1<void, const boost::shared_array<boost::uint8_t>& > &notify);
+ void rawSend(const boost::uint8_t *data, std::size_t length);
protected:
boost::shared_mutex connectionLock;
-
- boost::asio::ssl::stream<boost::asio::ip::tcp::socket> socket;
+
+ boost::asio::ssl::context context;
+ boost::scoped_ptr<boost::asio::ssl::stream<boost::asio::ip::tcp::socket> > socket;
boost::asio::ip::tcp::endpoint peer;
void handleHandshake(const boost::system::error_code& error);
@@ -110,14 +120,20 @@ class Connection : boost::noncopyable {
void _setState(State newState) {
state = newState;
+
+ if(_isConnected() && !socket.get())
+ _initSocket();
+ else if(!_isConnected() && socket.get())
+ socket.reset();
+
stateChanged.notify_all();
}
void doDisconnect();
- Connection(Core::Application *application0, boost::asio::ssl::context &sslContext) :
- application(application0), state(DISCONNECTED), receiveBuffer(1024*1024), receiveSignal(application), connectedSignal(application),
- disconnectedSignal(application), socket(application->getIOService(), sslContext) {}
+ Connection(Core::Application *application0) :
+ application(application0), state(DISCONNECTED), receiveBuffer(new boost::array<boost::uint8_t, 1024*1024>), receiveSignal(application), connectedSignal(application),
+ disconnectedSignal(application), context(application->getIOService(), boost::asio::ssl::context::sslv23) {}
public:
virtual ~Connection();
diff --git a/src/Net/Listener.cpp b/src/Net/Listener.cpp
index 89ea399..6187a1e 100644
--- a/src/Net/Listener.cpp
+++ b/src/Net/Listener.cpp
@@ -26,6 +26,20 @@
namespace Mad {
namespace Net {
+void Listener::accept() {
+ boost::shared_ptr<Connection> con(new Connection(application));
+
+ con->context.set_options(boost::asio::ssl::context::default_workarounds
+ | boost::asio::ssl::context::no_sslv2
+ | boost::asio::ssl::context::single_dh_use);
+ con->context.use_certificate_chain_file(x905CertFile);
+ con->context.use_private_key_file(x905KeyFile, boost::asio::ssl::context::pem);
+
+ con->_initSocket();
+
+ acceptor.async_accept(con->socket->lowest_layer(), boost::bind(&Listener::handleAccept, this, boost::asio::placeholders::error, con));
+}
+
void Listener::handleAccept(const boost::system::error_code &error, boost::shared_ptr<Connection> con) {
if(error)
return;
@@ -42,11 +56,10 @@ void Listener::handleAccept(const boost::system::error_code &error, boost::share
connections.insert(std::make_pair(con, std::make_pair(con1, con2)));
- con->socket.async_handshake(boost::asio::ssl::stream_base::server, boost::bind(&Connection::handleHandshake, con, boost::asio::placeholders::error));
+ con->socket->async_handshake(boost::asio::ssl::stream_base::server, boost::bind(&Connection::handleHandshake, con, boost::asio::placeholders::error));
}
- con.reset(new Connection(application, sslContext));
- acceptor.async_accept(con->socket.lowest_layer(), boost::bind(&Listener::handleAccept, this, boost::asio::placeholders::error, con));
+ accept();
}
void Listener::handleConnect(boost::shared_ptr<Connection> con) {
@@ -76,19 +89,8 @@ void Listener::handleDisconnect(boost::shared_ptr<Connection> con) {
Listener::Listener(Core::Application *application0, const std::string &x905CertFile0, const std::string &x905KeyFile0,
const boost::asio::ip::tcp::endpoint &address0) throw(Core::Exception)
: application(application0), x905CertFile(x905CertFile0), x905KeyFile(x905KeyFile0), address(address0),
-acceptor(application->getIOService(), address), sslContext(application->getIOService(), boost::asio::ssl::context::sslv23),
-signal(application)
-{
- sslContext.set_options(boost::asio::ssl::context::default_workarounds
- | boost::asio::ssl::context::no_sslv2
- | boost::asio::ssl::context::single_dh_use);
- sslContext.use_certificate_chain_file(x905CertFile0);
- sslContext.use_private_key_file(x905KeyFile0, boost::asio::ssl::context::pem);
-
-
-
- boost::shared_ptr<Connection> con(new Connection(application, sslContext));
- acceptor.async_accept(con->socket.lowest_layer(), boost::bind(&Listener::handleAccept, this, boost::asio::placeholders::error, con));
+acceptor(application->getIOService(), address), signal(application) {
+ accept();
}
Listener::~Listener() {
diff --git a/src/Net/Listener.h b/src/Net/Listener.h
index 2addafd..64572c0 100644
--- a/src/Net/Listener.h
+++ b/src/Net/Listener.h
@@ -20,6 +20,8 @@
#ifndef MAD_NET_LISTENER_H_
#define MAD_NET_LISTENER_H_
+#include "export.h"
+
#include <map>
#include <string>
@@ -29,7 +31,7 @@
namespace Mad {
namespace Net {
-class Listener : private boost::noncopyable {
+class MAD_NET_EXPORT Listener : private boost::noncopyable {
private:
Core::Application *application;
@@ -38,12 +40,12 @@ class Listener : private boost::noncopyable {
std::string x905CertFile, x905KeyFile;
boost::asio::ip::tcp::endpoint address;
boost::asio::ip::tcp::acceptor acceptor;
- boost::asio::ssl::context sslContext;
std::map<boost::shared_ptr<Connection>, std::pair<Core::Signals::Connection, Core::Signals::Connection> > connections;
Core::Signals::Signal1<boost::shared_ptr<Connection> > signal;
-
+
+ void accept();
void handleAccept(const boost::system::error_code &error, boost::shared_ptr<Connection> con);
void handleConnect(boost::shared_ptr<Connection> con);
diff --git a/src/Net/Packet.cpp b/src/Net/Packet.cpp
index d2c2c70..3f32357 100644
--- a/src/Net/Packet.cpp
+++ b/src/Net/Packet.cpp
@@ -22,14 +22,14 @@
namespace Mad {
namespace Net {
-Packet::Packet(uint16_t requestId, const void *data, uint16_t length) {
- rawData = (Data*)std::malloc(sizeof(Data)+length);
+Packet::Packet(boost::uint16_t requestId, const void *data, boost::uint16_t length) {
+ rawData = reinterpret_cast<Header*>(std::malloc(sizeof(Header)+length));
rawData->requestId = htons(requestId);
rawData->length = htons(length);
if(length)
- std::memcpy(rawData->data, data, length);
+ std::memcpy(reinterpret_cast<boost::uint8_t*>(rawData)+sizeof(Header), data, length);
}
Packet& Packet::operator=(const Packet &p) {
@@ -38,7 +38,7 @@ Packet& Packet::operator=(const Packet &p) {
std::free(rawData);
- rawData = (Data*)std::malloc(p.getRawDataLength());
+ rawData = reinterpret_cast<Header*>(std::malloc(p.getRawDataLength()));
std::memcpy(rawData, p.rawData, p.getRawDataLength());
return *this;
diff --git a/src/Net/Packet.h b/src/Net/Packet.h
index dc62cb7..567c9c3 100644
--- a/src/Net/Packet.h
+++ b/src/Net/Packet.h
@@ -20,30 +20,36 @@
#ifndef MAD_NET_PACKET_H_
#define MAD_NET_PACKET_H_
+#include "export.h"
+
#include <cstdlib>
#include <cstring>
-#include <netinet/in.h>
-#include <stdint.h>
+#include <boost/cstdint.hpp>
+
+#ifdef _WIN32
+# include <winsock2.h>
+#else
+# include <netinet/in.h>
+#endif
namespace Mad {
namespace Net {
-class Packet {
+class MAD_NET_EXPORT Packet {
public:
- struct Data {
- uint16_t requestId;
- uint16_t length;
- uint8_t data[0];
+ struct Header {
+ boost::uint16_t requestId;
+ boost::uint16_t length;
};
protected:
- Data *rawData;
+ Header *rawData;
public:
- Packet(uint16_t requestId, const void *data = 0, uint16_t length = 0);
+ Packet(boost::uint16_t requestId, const void *data = 0, boost::uint16_t length = 0);
Packet(const Packet &p) {
- rawData = (Data*)std::malloc(p.getRawDataLength());
+ rawData = reinterpret_cast<Header*>(std::malloc(p.getRawDataLength()));
std::memcpy(rawData, p.rawData, p.getRawDataLength());
}
@@ -53,24 +59,24 @@ class Packet {
Packet& operator=(const Packet &p);
- uint16_t getRequestId() const {
+ boost::uint16_t getRequestId() const {
return ntohs(rawData->requestId);
}
- uint16_t getLength() const {
+ boost::uint16_t getLength() const {
return ntohs(rawData->length);
}
- const uint8_t* getData() const {
- return rawData->data;
+ const boost::uint8_t* getData() const {
+ return reinterpret_cast<boost::uint8_t*>(rawData)+sizeof(Header);
}
- const Data* getRawData() const {
- return rawData;
+ const boost::uint8_t* getRawData() const {
+ return reinterpret_cast<boost::uint8_t*>(rawData);
}
unsigned long getRawDataLength() const {
- return sizeof(Data) + ntohs(rawData->length);
+ return sizeof(Header) + ntohs(rawData->length);
}
};
diff --git a/src/Net/export.h b/src/Net/export.h
new file mode 100644
index 0000000..c0a5f6a
--- /dev/null
+++ b/src/Net/export.h
@@ -0,0 +1,22 @@
+#ifndef MAD_NET_EXPORT
+# ifdef _WIN32
+# ifdef MAD_NET_EXPORTS
+# define MAD_NET_EXPORT _declspec(dllexport)
+# else
+# define MAD_NET_EXPORT _declspec(dllimport)
+# endif
+# else
+# define MAD_NET_EXPORT
+# endif
+
+# ifdef MAD_NET_EXPORTS
+# ifndef MAD_CORE_EXPORTS
+# define MAD_CORE_EXPORTS
+# endif
+# else
+# undef MAD_CORE_EXPORTS
+# endif
+
+#include <Core/export.h>
+
+#endif
diff --git a/src/Server/Application.h b/src/Server/Application.h
index 302d3be..205d398 100644
--- a/src/Server/Application.h
+++ b/src/Server/Application.h
@@ -20,6 +20,8 @@
#ifndef MAD_SERVER_APPLICATION_H_
#define MAD_SERVER_APPLICATION_H_
+#include "export.h"
+
#include <Common/Application.h>
namespace Mad {
@@ -27,7 +29,7 @@ namespace Server {
class ConnectionManager;
-class Application : public Common::Application {
+class MAD_SERVER_EXPORT Application : public Common::Application {
private:
ConnectionManager *connectionManager;
diff --git a/src/Server/CMakeLists.txt b/src/Server/CMakeLists.txt
index 22a7826..b9bffa1 100644
--- a/src/Server/CMakeLists.txt
+++ b/src/Server/CMakeLists.txt
@@ -1,10 +1,16 @@
-add_subdirectory(RequestHandlers)
-add_subdirectory(Requests)
-
include_directories(${INCLUDES})
-add_library(Server
+mad_library(Server
+ export.h
+
+ RequestHandlers/ConnectionRequestHandlerGroup.cpp RequestHandlers/ConnectionRequestHandlerGroup.h
+ RequestHandlers/DaemonRequestHandlerGroup.cpp RequestHandlers/DaemonRequestHandlerGroup.h
+ RequestHandlers/UserRequestHandlerGroup.cpp RequestHandlers/UserRequestHandlerGroup.h
+
+ Requests/CommandRequest.cpp Requests/CommandRequest.h
+ Requests/DaemonStateUpdateRequest.cpp Requests/DaemonStateUpdateRequest.h
+
Application.cpp Application.h
ConnectionManager.cpp ConnectionManager.h
)
-target_link_libraries(Server ServerRequestHandlers ServerRequests Common)
+target_link_libraries(Server Common)
diff --git a/src/Server/ConnectionManager.cpp b/src/Server/ConnectionManager.cpp
index 8fe6408..160f3c3 100644
--- a/src/Server/ConnectionManager.cpp
+++ b/src/Server/ConnectionManager.cpp
@@ -32,7 +32,7 @@
#include <Net/Packet.h>
#include <Net/Listener.h>
-#include <unistd.h>
+//#include <unistd.h>
#include <algorithm>
namespace Mad {
@@ -124,7 +124,7 @@ bool ConnectionManager::handleConfigEntry(const Core::ConfigEntry &entry, bool h
listenerAddresses.push_back(parseAddress(entry[0][0]));
}
catch(Core::Exception &e) {
- application->logf(Core::LoggerBase::WARNING, "ConnectionManager: Invalid listen address '%s'", entry[0][0].c_str());
+ application->logf(Core::LoggerBase::LOG_WARNING, "ConnectionManager: Invalid listen address '%s'", entry[0][0].c_str());
}
return true;
@@ -229,14 +229,13 @@ ConnectionManager::~ConnectionManager() {
}
boost::shared_ptr<Common::Connection> ConnectionManager::getDaemonConnection(const std::string &name) const throw (Core::Exception&) {
- const Common::HostInfo *hostInfo;
-
- try {
- hostInfo = &daemonInfo.at(name);
- }
- catch(std::out_of_range&) {
+
+
+ std::map<std::string, Common::HostInfo>::const_iterator hostIt = daemonInfo.find(name);
+ if(hostIt == daemonInfo.end())
throw Core::Exception(Core::Exception::UNKNOWN_DAEMON);
- }
+
+ const Common::HostInfo *hostInfo = &hostIt->second;
if(hostInfo->getState() != Common::HostInfo::INACTIVE) {
for(std::set<boost::shared_ptr<ServerConnection> >::const_iterator it = connections.begin(); it != connections.end(); ++it) {
@@ -277,7 +276,7 @@ void ConnectionManager::identifyDaemonConnection(Common::Connection *con, const
if(hostInfo->getState() != Common::HostInfo::INACTIVE) {
try {
getDaemonConnection(name)->disconnect();
- application->log(Core::LoggerBase::WARNING, "Disconnecting old connection.");
+ application->log(Core::LoggerBase::LOG_WARNING, "Disconnecting old connection.");
}
catch(Core::Exception&) {}
}
diff --git a/src/Server/ConnectionManager.h b/src/Server/ConnectionManager.h
index 6fc6013..bdf1b4d 100644
--- a/src/Server/ConnectionManager.h
+++ b/src/Server/ConnectionManager.h
@@ -20,6 +20,8 @@
#ifndef MAD_SERVER_CONNECTIONMANAGER_H_
#define MAD_SERVER_CONNECTIONMANAGER_H_
+#include "export.h"
+
#include <Core/Configurable.h>
#include <Core/Exception.h>
#include <Common/Connection.h>
@@ -45,7 +47,7 @@ namespace Server {
class Application;
-class ConnectionManager : public Core::Configurable, private boost::noncopyable {
+class MAD_SERVER_EXPORT ConnectionManager : public Core::Configurable, private boost::noncopyable {
private:
class ServerConnection : public Common::Connection {
public:
@@ -103,7 +105,7 @@ class ConnectionManager : public Core::Configurable, private boost::noncopyable
std::set<boost::shared_ptr<ServerConnection> > connections;
- std::map<std::string,Common::HostInfo> daemonInfo;
+ std::map<std::string, Common::HostInfo> daemonInfo;
boost::shared_ptr<Common::RequestHandlerGroup> connectionRequestHandlerGroup;
boost::shared_ptr<Common::RequestHandlerGroup> daemonRequestHandlerGroup;
diff --git a/src/Server/RequestHandlers/CMakeLists.txt b/src/Server/RequestHandlers/CMakeLists.txt
deleted file mode 100644
index cb44105..0000000
--- a/src/Server/RequestHandlers/CMakeLists.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-include_directories(${INCLUDES})
-
-add_library(ServerRequestHandlers STATIC
- ConnectionRequestHandlerGroup.cpp ConnectionRequestHandlerGroup.h
- DaemonRequestHandlerGroup.cpp DaemonRequestHandlerGroup.h
- UserRequestHandlerGroup.cpp UserRequestHandlerGroup.h
-)
-#target_link_libraries(ServerRequestHandlers ${KRB5_LIBRARIES})
diff --git a/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp
index 0de73f9..e94853f 100644
--- a/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp
+++ b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp
@@ -23,6 +23,8 @@
#include <Core/LogManager.h>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
namespace Mad {
namespace Server {
namespace RequestHandlers {
@@ -56,17 +58,27 @@ void ConnectionRequestHandlerGroup::handleIdentifyRequest(boost::shared_ptr<cons
void ConnectionRequestHandlerGroup::handleLogRequest(boost::shared_ptr<const Common::XmlPacket> packet, Common::XmlPacket *ret, Common::Connection *connection) {
// TODO Require authentication
+
+ boost::posix_time::ptime timestamp(boost::posix_time::not_a_date_time);
+
+ const std::string &timestr = packet->get<const std::string&>("timestamp");
+ if(!timestr.empty()) {
+ try {
+ timestamp = boost::posix_time::from_iso_string(timestr);
+ }
+ catch(...) {}
+ }
try {
application->getLogManager()->log(
- packet->get<Core::LoggerBase::MessageCategory>("category"),
- packet->get<Core::LoggerBase::MessageLevel>("level"),
- packet->get<time_t>("timestamp"),
+ static_cast<Core::LoggerBase::MessageCategory>(packet->get<long>("category")),
+ static_cast<Core::LoggerBase::MessageLevel>(packet->get<long>("level")),
+ timestamp,
packet->get<const std::string&>("message"),
application->getConnectionManager()->getDaemonName(connection));
}
catch(Core::Exception &e) {
- application->logf(Core::LoggerBase::ERROR, "Can't determine daemon name: %s", e.strerror().c_str());
+ application->logf(Core::LoggerBase::LOG_ERROR, "Can't determine daemon name: %s", e.strerror().c_str());
}
ret->setType("OK");
diff --git a/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.h b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.h
index c3deed1..7f6b17c 100644
--- a/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.h
+++ b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.h
@@ -20,6 +20,8 @@
#ifndef MAD_SERVER_REQUESTHANDLERS_CONNECTIONREQUESTHANDLERGROUP_H_
#define MAD_SERVER_REQUESTHANDLERS_CONNECTIONREQUESTHANDLERGROUP_H_
+#include "../export.h"
+
#include <Common/RequestHandlers/SimpleRequestHandlerGroup.h>
namespace Mad {
@@ -29,7 +31,7 @@ class Application;
namespace RequestHandlers {
-class ConnectionRequestHandlerGroup : public Common::RequestHandlers::SimpleRequestHandlerGroup {
+class MAD_SERVER_EXPORT ConnectionRequestHandlerGroup : public Common::RequestHandlers::SimpleRequestHandlerGroup {
private:
Application *application;
diff --git a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp
index 4b2dd0c..0345d7b 100644
--- a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp
+++ b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp
@@ -32,7 +32,7 @@ namespace RequestHandlers {
void DaemonRequestHandlerGroup::DaemonRequestHandler::handlePacket(boost::shared_ptr<const Common::XmlPacket> packet) {
if(packet->getType() != type) {
- getApplication()->log(Core::LoggerBase::ERROR, "Received an unexpected packet.");
+ getApplication()->log(Core::LoggerBase::LOG_ERROR, "Received an unexpected packet.");
Common::XmlPacket ret;
ret.setType("Error");
diff --git a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.h b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.h
index b32005f..086bf16 100644
--- a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.h
+++ b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.h
@@ -20,6 +20,8 @@
#ifndef MAD_SERVER_REQUESTHANDLERS_DAEMONREQUESTHANDLERGROUP_H_
#define MAD_SERVER_REQUESTHANDLERS_DAEMONREQUESTHANDLERGROUP_H_
+#include "../export.h"
+
#include <Common/RequestHandlerGroup.h>
#include <Core/Exception.h>
@@ -29,7 +31,7 @@ class ConnectionManager;
namespace RequestHandlers {
-class DaemonRequestHandlerGroup : public Common::RequestHandlerGroup {
+class MAD_SERVER_EXPORT DaemonRequestHandlerGroup : public Common::RequestHandlerGroup {
private:
class DaemonRequestHandler : public Common::RequestHandler {
private:
diff --git a/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp b/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp
index a1aa829..873815a 100644
--- a/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp
+++ b/src/Server/RequestHandlers/UserRequestHandlerGroup.cpp
@@ -236,7 +236,7 @@ void UserRequestHandlerGroup::handleFullUserGroupListRequest(boost::shared_ptr<c
if(userGroups) {
Common::XmlPacket::List *list = ret->createList("userGroupList");
- for(std::map<unsigned long, unsigned long>::const_iterator userGroup = userGroups->begin(); userGroup != userGroups->end(); ++userGroup) {
+ for(std::multimap<unsigned long, unsigned long>::const_iterator userGroup = userGroups->begin(); userGroup != userGroups->end(); ++userGroup) {
Common::XmlPacket::List::iterator entry = list->addEntry();
entry->set("uid", userGroup->first);
diff --git a/src/Server/RequestHandlers/UserRequestHandlerGroup.h b/src/Server/RequestHandlers/UserRequestHandlerGroup.h
index ee4b7f4..aed585f 100644
--- a/src/Server/RequestHandlers/UserRequestHandlerGroup.h
+++ b/src/Server/RequestHandlers/UserRequestHandlerGroup.h
@@ -20,6 +20,8 @@
#ifndef MAD_SERVER_REQUESTHANDLERS_USERREQUESTHANDLERGROUP_H_
#define MAD_SERVER_REQUESTHANDLERS_USERREQUESTHANDLERGROUP_H_
+#include "../export.h"
+
#include <Common/RequestHandlers/SimpleRequestHandlerGroup.h>
namespace Mad {
@@ -29,7 +31,7 @@ class Application;
namespace RequestHandlers {
-class UserRequestHandlerGroup : public Common::RequestHandlers::SimpleRequestHandlerGroup {
+class MAD_SERVER_EXPORT UserRequestHandlerGroup : public Common::RequestHandlers::SimpleRequestHandlerGroup {
private:
Application *application;
diff --git a/src/Server/Requests/CMakeLists.txt b/src/Server/Requests/CMakeLists.txt
deleted file mode 100644
index 6c5c8c5..0000000
--- a/src/Server/Requests/CMakeLists.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-include_directories(${INCLUDES})
-
-add_library(ServerRequests STATIC
- CommandRequest.cpp CommandRequest.h
- DaemonStateUpdateRequest.cpp DaemonStateUpdateRequest.h
-)
diff --git a/src/Server/Requests/CommandRequest.h b/src/Server/Requests/CommandRequest.h
index 95748fd..40f23fa 100644
--- a/src/Server/Requests/CommandRequest.h
+++ b/src/Server/Requests/CommandRequest.h
@@ -20,13 +20,15 @@
#ifndef MAD_SERVER_REQUESTS_COMMANDREQUEST_H_
#define MAD_SERVER_REQUESTS_COMMANDREQUEST_H_
+#include "../export.h"
+
#include <Common/Request.h>
namespace Mad {
namespace Server {
namespace Requests {
-class CommandRequest : public Common::Request {
+class MAD_SERVER_EXPORT CommandRequest : public Common::Request {
private:
bool reboot;
diff --git a/src/Server/Requests/DaemonStateUpdateRequest.h b/src/Server/Requests/DaemonStateUpdateRequest.h
index fc80920..862e8ac 100644
--- a/src/Server/Requests/DaemonStateUpdateRequest.h
+++ b/src/Server/Requests/DaemonStateUpdateRequest.h
@@ -20,6 +20,8 @@
#ifndef MAD_SERVER_REQUESTS_DAEMONSTATEUPDATEREQUEST_H_
#define MAD_SERVER_REQUESTS_DAEMONSTATEUPDATEREQUEST_H_
+#include "../export.h"
+
#include <Common/Request.h>
#include <Common/HostInfo.h>
@@ -27,7 +29,7 @@ namespace Mad {
namespace Server {
namespace Requests {
-class DaemonStateUpdateRequest : public Common::Request {
+class MAD_SERVER_EXPORT DaemonStateUpdateRequest : public Common::Request {
private:
std::string name;
Common::HostInfo::State state;
diff --git a/src/Server/export.h b/src/Server/export.h
new file mode 100644
index 0000000..6ff9280
--- /dev/null
+++ b/src/Server/export.h
@@ -0,0 +1,11 @@
+#ifndef MAD_SERVER_EXPORT
+# ifdef _WIN32
+# ifdef MAD_SERVER_EXPORTS
+# define MAD_SERVER_EXPORT _declspec(dllexport)
+# else
+# define MAD_SERVER_EXPORT _declspec(dllimport)
+# endif
+# else
+# define MAD_SERVER_EXPORT
+# endif
+#endif
diff --git a/src/mad-server.cpp b/src/mad-server.cpp
index 84ddce3..366ac61 100644
--- a/src/mad-server.cpp
+++ b/src/mad-server.cpp
@@ -20,6 +20,17 @@
#include "Server/Application.h"
#include "Core/ConfigManager.h"
+#ifdef _WIN32
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+static void sleep(int seconds) {
+ Sleep(seconds*1000);
+}
+
+#endif
+
using namespace Mad;
diff --git a/src/mad.cpp b/src/mad.cpp
index 2a6b50a..8a7b7ba 100644
--- a/src/mad.cpp
+++ b/src/mad.cpp
@@ -31,8 +31,6 @@
#include "Daemon/Backends/NetworkLogger.h"
#include "Daemon/RequestHandlers/CommandRequestHandler.h"
-#include <unistd.h>
-
using namespace Mad;
@@ -73,7 +71,7 @@ int main() {
application.getRequestManager()->unregisterConnection(connection);
}
catch(Core::Exception &e) {
- application.logf(Core::LoggerBase::CRITICAL, "Connection error: %s", e.strerror().c_str());
+ application.logf(Core::LoggerBase::LOG_CRITICAL, "Connection error: %s", e.strerror().c_str());
}
delete connection;
diff --git a/src/madc.cpp b/src/madc.cpp
index a1ce58b..0500c0f 100644
--- a/src/madc.cpp
+++ b/src/madc.cpp
@@ -102,7 +102,7 @@ int main(int argc, char *argv[]) {
application.getRequestManager()->unregisterConnection(connection);
}
catch(Core::Exception &e) {
- application.logf(Core::LoggerBase::CRITICAL, "Connection error: %s", e.strerror().c_str());
+ application.logf(Core::LoggerBase::LOG_CRITICAL, "Connection error: %s", e.strerror().c_str());
}
delete connection;
diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt
index 1d036c9..13ad209 100644
--- a/src/modules/CMakeLists.txt
+++ b/src/modules/CMakeLists.txt
@@ -20,6 +20,8 @@ macro(mad_module name)
add_library(${name} MODULE ${ARGN})
set_property(TARGET ${name} PROPERTY PREFIX "")
endif(WITH_STATIC_${upper_name})
+
+ set_target_properties(${name} PROPERTIES DEFINE_SYMBOL "MAD_MODULE_EXPORTS")
endif(WITH_${upper_name})
endmacro(mad_module)
@@ -32,9 +34,12 @@ macro(mad_module_libraries name)
endmacro(mad_module_libraries)
add_subdirectory(FileLogger)
+
+if(UNIX)
add_subdirectory(SystemBackendPosix)
add_subdirectory(SystemBackendProc)
add_subdirectory(UserConfigBackendHome)
+endif(UNIX)
if(MYSQL_FOUND)
add_subdirectory(UserDBBackendMysql)
@@ -49,12 +54,14 @@ SET(STATIC_MODULE_LIST "")
foreach(module ${STATIC_MODULES})
SET(STATIC_MODULE_LOADERS "${STATIC_MODULE_LOADERS}Mad::Common::Module* ${module}_create(Mad::Common::Application *application);\n")
- SET(STATIC_MODULE_LIST "${STATIC_MODULE_LIST}std::make_pair(\"${module}\", &${module}_create),\n")
+ SET(STATIC_MODULE_LIST "${STATIC_MODULE_LIST}std::pair<const std::string, const ModuleLoadFunc>(0, 0)(\"${module}\", &${module}_create),\n")
endforeach(module ${STATIC_MODULES})
configure_file(${MAD_SOURCE_DIR}/src/modules/modules.cpp.in ${MAD_BINARY_DIR}/src/modules/modules.cpp)
add_library(modules STATIC
- modules.cpp modules.h
+ export.h
+
+ ${MAD_BINARY_DIR}/src/modules/modules.cpp modules.h
)
target_link_libraries(modules ${STATIC_MODULES})
diff --git a/src/modules/FileLogger/CMakeLists.txt b/src/modules/FileLogger/CMakeLists.txt
index 2f654e8..ac1deab 100644
--- a/src/modules/FileLogger/CMakeLists.txt
+++ b/src/modules/FileLogger/CMakeLists.txt
@@ -4,3 +4,4 @@ mad_module(FileLogger
FileLogger.h
Module.cpp Module.h
)
+mad_module_libraries(FileLogger Common)
diff --git a/src/modules/FileLogger/FileLogger.h b/src/modules/FileLogger/FileLogger.h
index a32003d..0ee9ad7 100644
--- a/src/modules/FileLogger/FileLogger.h
+++ b/src/modules/FileLogger/FileLogger.h
@@ -34,10 +34,10 @@ class FileLogger : public Core::Logger, public Core::RemoteLogger {
std::ofstream file;
protected:
- virtual void logMessage(MessageCategory, MessageLevel, time_t, const std::string &message) {
+ virtual void logMessage(MessageCategory /*category*/, MessageLevel /*level*/, boost::posix_time::ptime /*timestamp*/, const std::string &message) {
file << message << std::endl;
}
- virtual void logMessage(MessageCategory, MessageLevel, time_t, const std::string &message, const std::string &messageSource) {
+ virtual void logMessage(MessageCategory /*category*/, MessageLevel /*level*/, boost::posix_time::ptime /*timestamp*/, const std::string &message, const std::string &messageSource) {
file << message << " from "<< messageSource << std::endl;
}
diff --git a/src/modules/FileLogger/Module.cpp b/src/modules/FileLogger/Module.cpp
index b8a6954..e715386 100644
--- a/src/modules/FileLogger/Module.cpp
+++ b/src/modules/FileLogger/Module.cpp
@@ -17,6 +17,8 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "../export.h"
+
#include "Module.h"
#include <Core/ConfigEntry.h>
@@ -38,7 +40,7 @@ bool Module::handleConfigEntry(const Core::ConfigEntry &entry, bool handled) {
application->getLogManager()->registerLogger(boost::static_pointer_cast<Core::Logger>(logger));
}
else {
- application->logf(Core::LoggerBase::WARNING, "FileLogger: no filename given.");
+ application->logf(Core::LoggerBase::LOG_WARNING, "FileLogger: no filename given.");
}
return true;
@@ -55,7 +57,7 @@ bool Module::handleConfigEntry(const Core::ConfigEntry &entry, bool handled) {
extern "C" {
-Mad::Common::Module* FileLogger_create(Mad::Common::Application *application) {
+MAD_MODULE_EXPORT Mad::Common::Module* FileLogger_create(Mad::Common::Application *application) {
return new Mad::Modules::FileLogger::Module(application);
}
diff --git a/src/modules/SystemBackendPosix/Module.cpp b/src/modules/SystemBackendPosix/Module.cpp
index 2fd5cfe..c43125c 100644
--- a/src/modules/SystemBackendPosix/Module.cpp
+++ b/src/modules/SystemBackendPosix/Module.cpp
@@ -17,11 +17,13 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "../export.h"
+
#include "Module.h"
extern "C" {
-Mad::Common::Module* SystemBackendPosix_create(Mad::Common::Application *application) {
+MAD_MODULE_EXPORT Mad::Common::Module* SystemBackendPosix_create(Mad::Common::Application *application) {
return new Mad::Modules::SystemBackendPosix::Module(application);
}
diff --git a/src/modules/SystemBackendProc/Module.cpp b/src/modules/SystemBackendProc/Module.cpp
index 6e45cdb..1781e85 100644
--- a/src/modules/SystemBackendProc/Module.cpp
+++ b/src/modules/SystemBackendProc/Module.cpp
@@ -17,11 +17,13 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "../export.h"
+
#include "Module.h"
extern "C" {
-Mad::Common::Module* SystemBackendProc_create(Mad::Common::Application *application) {
+MAD_MODULE_EXPORT Mad::Common::Module* SystemBackendProc_create(Mad::Common::Application *application) {
return new Mad::Modules::SystemBackendProc::Module(application);
}
diff --git a/src/modules/UserConfigBackendHome/Module.cpp b/src/modules/UserConfigBackendHome/Module.cpp
index cab1b80..e431e51 100644
--- a/src/modules/UserConfigBackendHome/Module.cpp
+++ b/src/modules/UserConfigBackendHome/Module.cpp
@@ -17,11 +17,13 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "../export.h"
+
#include "Module.h"
extern "C" {
-Mad::Common::Module* UserConfigBackendHome_create(Mad::Common::Application *application) {
+MAD_MODULE_EXPORT Mad::Common::Module* UserConfigBackendHome_create(Mad::Common::Application *application) {
return new Mad::Modules::UserConfigBackendHome::Module(application);
}
diff --git a/src/modules/UserConfigBackendHome/UserConfigBackendHome.cpp b/src/modules/UserConfigBackendHome/UserConfigBackendHome.cpp
index b68268b..1a2a5c4 100644
--- a/src/modules/UserConfigBackendHome/UserConfigBackendHome.cpp
+++ b/src/modules/UserConfigBackendHome/UserConfigBackendHome.cpp
@@ -50,7 +50,7 @@ bool UserConfigBackendHome::handleConfigEntry(const Core::ConfigEntry &entry, bo
char *endptr;
unsigned long val = std::strtoul(entry[1][0].c_str(), &endptr, 8);
if(*endptr || val > 07777) {
- application->logf(Core::LoggerBase::WARNING, "UserBackendHome: Invalid configuration: DirMode '%s'", entry[1][0].c_str());
+ application->logf(Core::LoggerBase::LOG_WARNING, "UserBackendHome: Invalid configuration: DirMode '%s'", entry[1][0].c_str());
}
else {
dirMode = val;
diff --git a/src/modules/UserConfigBackendKrb5/Module.cpp b/src/modules/UserConfigBackendKrb5/Module.cpp
index ecfec56..3ef9b88 100644
--- a/src/modules/UserConfigBackendKrb5/Module.cpp
+++ b/src/modules/UserConfigBackendKrb5/Module.cpp
@@ -17,11 +17,13 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "../export.h"
+
#include "Module.h"
extern "C" {
-Mad::Common::Module* UserConfigBackendKrb5_create(Mad::Common::Application *application) {
+MAD_MODULE_EXPORT Mad::Common::Module* UserConfigBackendKrb5_create(Mad::Common::Application *application) {
return new Mad::Modules::UserConfigBackendKrb5::Module(application);
}
diff --git a/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.cpp b/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.cpp
index beedbae..35d65ae 100644
--- a/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.cpp
+++ b/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.cpp
@@ -29,12 +29,12 @@ namespace UserConfigBackendKrb5 {
void UserConfigBackendKrb5::connect() {
if(principal.empty()) {
- application->log(Core::LoggerBase::USER, Core::LoggerBase::ERROR, "UserConfigBackendKrb5: no principal given");
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_ERROR, "UserConfigBackendKrb5: no principal given");
return;
}
if(realm.empty()) {
- application->log(Core::LoggerBase::USER, Core::LoggerBase::ERROR, "UserConfigBackendKrb5: no realm given and no default realm available");
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_ERROR, "UserConfigBackendKrb5: no realm given and no default realm available");
return;
}
@@ -64,7 +64,7 @@ void UserConfigBackendKrb5::connect() {
const_cast<char*>(KADM5_ADMIN_SERVICE), &params, KADM5_STRUCT_VERSION, KADM5_API_VERSION_2, 0, &handle);
if(err) {
- application->logf(Core::LoggerBase::USER, Core::LoggerBase::ERROR, "kadm5_init_with_password: %s", krb5_get_error_message(context, err));
+ application->logf(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_ERROR, "kadm5_init_with_password: %s", krb5_get_error_message(context, err));
return;
}
}
@@ -77,12 +77,12 @@ void UserConfigBackendKrb5::connect() {
const_cast<char*>(KADM5_ADMIN_SERVICE), &params, KADM5_STRUCT_VERSION, KADM5_API_VERSION_2, 0, &handle);
if(err) {
- application->logf(Core::LoggerBase::USER, Core::LoggerBase::ERROR, "kadm5_init_with_skey: %s", krb5_get_error_message(context, err));
+ application->logf(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_ERROR, "kadm5_init_with_skey: %s", krb5_get_error_message(context, err));
return;
}
}
- application->log(Core::LoggerBase::USER, Core::LoggerBase::VERBOSE, "Connected to kerberos admin server.");
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_VERBOSE, "Connected to kerberos admin server.");
return;
}
@@ -153,7 +153,7 @@ void UserConfigBackendKrb5::addUser(const Common::UserInfo &userInfo) throw(Core
do {
err = kadm5_create_principal(handle, &princ, KADM5_PRINCIPAL|KADM5_ATTRIBUTES, dummybuf);
if(err == KADM5_RPC_ERROR && retryCount > 0) {
- application->log(Core::LoggerBase::USER, Core::LoggerBase::VERBOSE, "Connection to kerberos admin server lost. Reconnecting...");
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_VERBOSE, "Connection to kerberos admin server lost. Reconnecting...");
connect();
--retryCount;
}
@@ -166,7 +166,7 @@ void UserConfigBackendKrb5::addUser(const Common::UserInfo &userInfo) throw(Core
do {
err = kadm5_randkey_principal(handle, princ.principal, 0, 0);
if(err == KADM5_RPC_ERROR && retryCount > 0) {
- application->log(Core::LoggerBase::USER, Core::LoggerBase::VERBOSE, "Connection to kerberos admin server lost. Reconnecting...");
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_VERBOSE, "Connection to kerberos admin server lost. Reconnecting...");
connect();
--retryCount;
}
@@ -180,7 +180,7 @@ void UserConfigBackendKrb5::addUser(const Common::UserInfo &userInfo) throw(Core
do {
err = kadm5_modify_principal(handle, &princ, KADM5_ATTRIBUTES);
if(err == KADM5_RPC_ERROR && retryCount > 0) {
- application->log(Core::LoggerBase::USER, Core::LoggerBase::VERBOSE, "Connection to kerberos admin server lost. Reconnecting...");
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_VERBOSE, "Connection to kerberos admin server lost. Reconnecting...");
connect();
--retryCount;
}
@@ -222,7 +222,7 @@ void UserConfigBackendKrb5::deleteUser(const Common::UserInfo &userInfo) throw(C
do {
err = kadm5_delete_principal(handle, princ);
if(err == KADM5_RPC_ERROR && retryCount > 0) {
- application->log(Core::LoggerBase::USER, Core::LoggerBase::VERBOSE, "Connection to kerberos admin server lost. Reconnecting...");
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_VERBOSE, "Connection to kerberos admin server lost. Reconnecting...");
connect();
--retryCount;
}
@@ -231,7 +231,7 @@ void UserConfigBackendKrb5::deleteUser(const Common::UserInfo &userInfo) throw(C
krb5_free_principal(context, princ);
if(err)
- application->logf(Core::LoggerBase::USER, Core::LoggerBase::WARNING, "kadm5_delete_principal: %s", krb5_get_error_message(context, err));
+ application->logf(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, "kadm5_delete_principal: %s", krb5_get_error_message(context, err));
}
void UserConfigBackendKrb5::setPassword(const Common::UserInfo &userInfo, const std::string &password) throw(Core::Exception) {
@@ -252,7 +252,7 @@ void UserConfigBackendKrb5::setPassword(const Common::UserInfo &userInfo, const
do {
err = kadm5_chpass_principal(handle, princ, const_cast<char*>(password.c_str()));
if(err == KADM5_RPC_ERROR && retryCount > 0) {
- application->log(Core::LoggerBase::USER, Core::LoggerBase::VERBOSE, "Connection to kerberos admin server lost. Reconnecting...");
+ application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_VERBOSE, "Connection to kerberos admin server lost. Reconnecting...");
connect();
--retryCount;
}
diff --git a/src/modules/UserDBBackendMysql/CMakeLists.txt b/src/modules/UserDBBackendMysql/CMakeLists.txt
index 8c4f079..80b83d1 100644
--- a/src/modules/UserDBBackendMysql/CMakeLists.txt
+++ b/src/modules/UserDBBackendMysql/CMakeLists.txt
@@ -4,5 +4,4 @@ mad_module(UserDBBackendMysql
Module.cpp Module.h
UserDBBackendMysql.cpp UserDBBackendMysql.h
)
-
mad_module_libraries(UserDBBackendMysql ${MYSQL_LIBRARIES}) \ No newline at end of file
diff --git a/src/modules/UserDBBackendMysql/Module.cpp b/src/modules/UserDBBackendMysql/Module.cpp
index a4b51c4..6fcbda2 100644
--- a/src/modules/UserDBBackendMysql/Module.cpp
+++ b/src/modules/UserDBBackendMysql/Module.cpp
@@ -17,11 +17,13 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "../export.h"
+
#include "Module.h"
extern "C" {
-Mad::Common::Module* UserDBBackendMysql_create(Mad::Common::Application *application) {
+MAD_MODULE_EXPORT Mad::Common::Module* UserDBBackendMysql_create(Mad::Common::Application *application) {
return new Mad::Modules::UserDBBackendMysql::Module(application);
}
diff --git a/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp b/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp
index 7ca3db2..bf087f2 100644
--- a/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp
+++ b/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp
@@ -70,7 +70,7 @@ bool UserDBBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool
val = strtol(entry[2][0].c_str(), &endptr, 10);
if(endptr != 0 || val < 0 || val > 65535)
- application->log(Core::LoggerBase::WARNING, "UserDBBackendMysql: Invalid port");
+ application->log(Core::LoggerBase::LOG_WARNING, "UserDBBackendMysql: Invalid port");
else
port = val;
}
@@ -159,7 +159,7 @@ bool UserDBBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool
void UserDBBackendMysql::configFinished() {
if(db.empty()) {
- application->log(Core::LoggerBase::ERROR, "UserDBBackendMysql: No database name given");
+ application->log(Core::LoggerBase::LOG_ERROR, "UserDBBackendMysql: No database name given");
return;
}
diff --git a/src/modules/export.h b/src/modules/export.h
new file mode 100644
index 0000000..8222a36
--- /dev/null
+++ b/src/modules/export.h
@@ -0,0 +1,11 @@
+#ifndef MAD_MODULE_EXPORT
+# ifdef _WIN32
+# ifdef MAD_MODULE_EXPORTS
+# define MAD_MODULE_EXPORT _declspec(dllexport)
+# else
+# define MAD_MODULE_EXPORT
+# endif
+# else
+# define MAD_MODULE_EXPORT
+# endif
+#endif
diff --git a/src/modules/modules.cpp.in b/src/modules/modules.cpp.in
index e3feba1..a6a2147 100644
--- a/src/modules/modules.cpp.in
+++ b/src/modules/modules.cpp.in
@@ -17,7 +17,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "modules.h"
+#include <modules/modules.h>
#include <map>
@@ -30,11 +30,12 @@ namespace Modules {
typedef Common::Module *(*ModuleLoadFunc)(Common::Application*);
-static const std::pair<const char*, const ModuleLoadFunc> modules[] = {
+static const std::pair<const std::string, const ModuleLoadFunc> modules[] = {
@STATIC_MODULE_LIST@
+std::pair<const std::string, const ModuleLoadFunc>("", 0)
};
-static const std::map<const std::string, const ModuleLoadFunc> moduleMap(modules, modules+sizeof(modules));
+static const std::map<const std::string, const ModuleLoadFunc> moduleMap(modules, modules + sizeof(modules)/sizeof(modules[0]));
Common::Module* loadStaticModule(Common::Application *application, const std::string &name) {
std::map<const std::string, const ModuleLoadFunc>::const_iterator it = moduleMap.find(name);