# HG changeset patch # User David Demelier # Date 1464087635 -7200 # Node ID c1acfacc46bde8f691bfd92f4e86151a49ae915b # Parent 70ed0753ce0d5100128097b7f3756da5877cd7e1 Irccd: dll export and style diff -r 70ed0753ce0d -r c1acfacc46bd cmake/IrccdSystem.cmake --- a/cmake/IrccdSystem.cmake Mon May 23 14:05:41 2016 +0200 +++ b/cmake/IrccdSystem.cmake Tue May 24 13:00:35 2016 +0200 @@ -55,7 +55,7 @@ set(CMAKE_CXX_FLAGS "-Wall -Wextra -std=c++14 ${CMAKE_CXX_FLAGS}") endif () elseif (MSVC14) - set(CMAKE_C_FLAGS "/DWIN32_LEAN_AND_MEAN /DNOMINMAX /wd4267 /wd48000 /D_CRT_SECURE_NO_WARNINGS ${CMAKE_C_FLAGS}") + set(CMAKE_C_FLAGS "/DWIN32_LEAN_AND_MEAN /DNOMINMAX /wd4267 /wd4800 /D_CRT_SECURE_NO_WARNINGS ${CMAKE_C_FLAGS}") set(CMAKE_CXX_FLAGS "/DWIN32_LEAN_AND_MEAN /DNOMINMAX /wd4267 /wd4800 /D_CRT_SECURE_NO_WARNINGS /EHsc ${CMAKE_CXX_FLAGS}") else () message(WARNING "Unsupported ${CMAKE_CXX_COMPILER_ID}, may not build correctly.") diff -r 70ed0753ce0d -r c1acfacc46bd cmake/internal/sysconfig.hpp.in --- a/cmake/internal/sysconfig.hpp.in Mon May 23 14:05:41 2016 +0200 +++ b/cmake/internal/sysconfig.hpp.in Tue May 24 13:00:35 2016 +0200 @@ -94,4 +94,19 @@ #cmakedefine HAVE_STAT_ST_UID #cmakedefine HAVE_SYSLOG +/* + * Export stuff. + * ------------------------------------------------------------------ + */ + +#if defined(_WIN32) +# if defined(IRCCD_BUILDING_DLL) +# define IRCCD_EXPORT __declspec(dllexport) +# else +# define IRCCD_EXPORT __declspec(dllimport) +# endif +#else +# define IRCCD_EXPORT +#endif + #endif // !IRCCD_SYSCONFIG_H diff -r 70ed0753ce0d -r c1acfacc46bd lib/CMakeLists.txt --- a/lib/CMakeLists.txt Mon May 23 14:05:41 2016 +0200 +++ b/lib/CMakeLists.txt Tue May 24 13:00:35 2016 +0200 @@ -34,8 +34,14 @@ ${OPENSSL_INCLUDE_DIR} ) +source_group(irccd FILES ${HEADERS} ${SOURCES}) + if (IRCCD_SYSTEM_WINDOWS) list(APPEND LIBRARIES ws2_32 shlwapi) + + if (BUILD_SHARED_LIBS) + list(APPEND FLAGS IRCCD_BUILDING_DLL) + endif () elseif (IRCCD_SYSTEM_MAC) list(APPEND LIBRARIES resolv) elseif (IRCCD_SYSTEM_LINUX) @@ -43,12 +49,18 @@ endif () target_link_libraries(libirccd extern-duktape extern-ircclient extern-jansson extern-cppformat ${LIBRARIES}) +target_compile_definitions(libirccd PRIVATE ${FLAGS}) set_target_properties( libirccd PROPERTIES PREFIX "" OUTPUT_NAME_DEBUG libirccd2d + RUNTIME_OUTPUT_DIRECTORY ${IRCCD_FAKEROOTDIR}/${WITH_BINDIR} + RUNTIME_OUTPUT_DIRECTORY_DEBUG ${IRCCD_FAKEROOTDIR}/${WITH_BINDIR} + RUNTIME_OUTPUT_DIRECTORY_RELEASE ${IRCCD_FAKEROOTDIR}/${WITH_BINDIR} + RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${IRCCD_FAKEROOTDIR}/${WITH_BINDIR} + RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${IRCCD_FAKEROOTDIR}/${WITH_BINDIR} VERSION ${IRCCD_VERSION} SOVERSION ${IRCCD_VERSION_SHLIB} ) diff -r 70ed0753ce0d -r c1acfacc46bd lib/irccd/alias.cpp --- a/lib/irccd/alias.cpp Mon May 23 14:05:41 2016 +0200 +++ b/lib/irccd/alias.cpp Tue May 24 13:00:35 2016 +0200 @@ -27,11 +27,10 @@ { assert(!value.empty()); - if ((m_isPlaceholder = std::regex_match(value, std::regex("^%\\d+$")))) { + if ((m_isPlaceholder = std::regex_match(value, std::regex("^%\\d+$")))) m_value = value.substr(1); - } else { + else m_value = std::move(value); - } } unsigned AliasArg::index() const noexcept @@ -50,11 +49,10 @@ std::ostream &operator<<(std::ostream &out, const AliasArg &arg) { - if (arg.m_isPlaceholder) { + if (arg.m_isPlaceholder) out << "%" << arg.m_value; - } else { + else out << arg.m_value; - } return out; } diff -r 70ed0753ce0d -r c1acfacc46bd lib/irccd/alias.hpp --- a/lib/irccd/alias.hpp Mon May 23 14:05:41 2016 +0200 +++ b/lib/irccd/alias.hpp Tue May 24 13:00:35 2016 +0200 @@ -28,6 +28,8 @@ #include #include +#include "sysconfig.hpp" + namespace irccd { /** @@ -51,7 +53,7 @@ * \pre value must not be empty * \param value the value */ - AliasArg(std::string value); + IRCCD_EXPORT AliasArg(std::string value); /** * Check if the argument is a placeholder. @@ -69,7 +71,7 @@ * \pre isPlaceholder() must return true * \return the position */ - unsigned index() const noexcept; + IRCCD_EXPORT unsigned index() const noexcept; /** * Get the real value. @@ -77,7 +79,7 @@ * \pre isPlaceholder() must return false * \return the value */ - const std::string &value() const noexcept; + IRCCD_EXPORT const std::string &value() const noexcept; /** * Output the alias to the stream. @@ -85,7 +87,7 @@ * \param out the output stream * \return out */ - friend std::ostream &operator<<(std::ostream &out, const AliasArg &); + IRCCD_EXPORT friend std::ostream &operator<<(std::ostream &out, const AliasArg &); }; /** diff -r 70ed0753ce0d -r c1acfacc46bd lib/irccd/application.cpp --- a/lib/irccd/application.cpp Mon May 23 14:05:41 2016 +0200 +++ b/lib/irccd/application.cpp Tue May 24 13:00:35 2016 +0200 @@ -1,76 +1,76 @@ -/* - * application.cpp -- super base class to create irccd front ends - * - * Copyright (c) 2013-2016 David Demelier - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "application.hpp" -#include "cmd-help.hpp" -#include "cmd-plugin-info.hpp" -#include "cmd-plugin-list.hpp" -#include "cmd-plugin-load.hpp" -#include "cmd-plugin-reload.hpp" -#include "cmd-plugin-unload.hpp" -#include "cmd-server-cmode.hpp" -#include "cmd-server-cnotice.hpp" -#include "cmd-server-connect.hpp" -#include "cmd-server-disconnect.hpp" -#include "cmd-server-info.hpp" -#include "cmd-server-invite.hpp" -#include "cmd-server-join.hpp" -#include "cmd-server-kick.hpp" -#include "cmd-server-list.hpp" -#include "cmd-server-me.hpp" -#include "cmd-server-message.hpp" -#include "cmd-server-mode.hpp" -#include "cmd-server-nick.hpp" -#include "cmd-server-notice.hpp" -#include "cmd-server-part.hpp" -#include "cmd-server-reconnect.hpp" -#include "cmd-server-topic.hpp" -#include "cmd-watch.hpp" - -namespace irccd { - -Application::Application() -{ - /* Register all commands */ - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); - addCommand(std::make_unique()); -} - -} // !irccd +/* + * application.cpp -- super base class to create irccd front ends + * + * Copyright (c) 2013-2016 David Demelier + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "application.hpp" +#include "cmd-help.hpp" +#include "cmd-plugin-info.hpp" +#include "cmd-plugin-list.hpp" +#include "cmd-plugin-load.hpp" +#include "cmd-plugin-reload.hpp" +#include "cmd-plugin-unload.hpp" +#include "cmd-server-cmode.hpp" +#include "cmd-server-cnotice.hpp" +#include "cmd-server-connect.hpp" +#include "cmd-server-disconnect.hpp" +#include "cmd-server-info.hpp" +#include "cmd-server-invite.hpp" +#include "cmd-server-join.hpp" +#include "cmd-server-kick.hpp" +#include "cmd-server-list.hpp" +#include "cmd-server-me.hpp" +#include "cmd-server-message.hpp" +#include "cmd-server-mode.hpp" +#include "cmd-server-nick.hpp" +#include "cmd-server-notice.hpp" +#include "cmd-server-part.hpp" +#include "cmd-server-reconnect.hpp" +#include "cmd-server-topic.hpp" +#include "cmd-watch.hpp" + +namespace irccd { + +Application::Application() +{ + // Register all commands. + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); + addCommand(std::make_unique()); +} + +} // !irccd diff -r 70ed0753ce0d -r c1acfacc46bd lib/irccd/application.hpp --- a/lib/irccd/application.hpp Mon May 23 14:05:41 2016 +0200 +++ b/lib/irccd/application.hpp Tue May 24 13:00:35 2016 +0200 @@ -29,6 +29,7 @@ #include #include "command.hpp" +#include "sysconfig.hpp" namespace irccd { @@ -51,7 +52,7 @@ /** * Create the application and fill the commands with predefined commands. */ - Application(); + IRCCD_EXPORT Application(); /** * Access the remote commands. diff -r 70ed0753ce0d -r c1acfacc46bd lib/irccd/cmd-help.cpp --- a/lib/irccd/cmd-help.cpp Mon May 23 14:05:41 2016 +0200 +++ b/lib/irccd/cmd-help.cpp Tue May 24 13:00:35 2016 +0200 @@ -43,11 +43,10 @@ { auto it = irccdctl.commands().find(args.arg(0U)); - if (it == irccdctl.commands().end()) { + if (it == irccdctl.commands().end()) log::warning() << "there is no command named: " << args.arg(0U) << std::endl; - } else { + else log::warning() << it->second->usage() << std::flush; - } return nullptr; } diff -r 70ed0753ce0d -r c1acfacc46bd lib/irccd/cmd-help.hpp --- a/lib/irccd/cmd-help.hpp Mon May 23 14:05:41 2016 +0200 +++ b/lib/irccd/cmd-help.hpp Tue May 24 13:00:35 2016 +0200 @@ -36,19 +36,19 @@ */ class Help : public RemoteCommand { public: - Help(); + IRCCD_EXPORT Help(); - std::vector args() const override; + IRCCD_EXPORT std::vector args() const override; /** * \copydoc RemoteCommand::help */ - std::string help() const override; + IRCCD_EXPORT std::string help() const override; /** * \copydoc RemoteCommand::request */ - json::Value request(Irccdctl &irccdctl, const RemoteCommandRequest &args) const override; + IRCCD_EXPORT json::Value request(Irccdctl &irccdctl, const RemoteCommandRequest &args) const override; }; } // !command diff -r 70ed0753ce0d -r c1acfacc46bd lib/irccd/cmd-plugin-info.cpp --- a/lib/irccd/cmd-plugin-info.cpp Mon May 23 14:05:41 2016 +0200 +++ b/lib/irccd/cmd-plugin-info.cpp Tue May 24 13:00:35 2016 +0200 @@ -71,7 +71,7 @@ { RemoteCommand::result(irccdctl, result); - /* Plugin information */ + // Plugin information. if (result.valueOr("status", false).toBool()) { std::cout << std::boolalpha; std::cout << "Author : " << result.valueOr("author", "").toString(true) << std::endl; diff -r 70ed0753ce0d -r c1acfacc46bd lib/irccd/cmd-plugin-info.hpp --- a/lib/irccd/cmd-plugin-info.hpp Mon May 23 14:05:41 2016 +0200 +++ b/lib/irccd/cmd-plugin-info.hpp Tue May 24 13:00:35 2016 +0200 @@ -39,32 +39,32 @@ /** * Constructor. */ - PluginInfo(); + IRCCD_EXPORT PluginInfo(); /** * \copydoc RemoteCommand::help */ - std::string help() const override; + IRCCD_EXPORT std::string help() const override; /** * \copydoc RemoteCommand::args */ - std::vector args() const override; + IRCCD_EXPORT std::vector args() const override; /** * \copydoc RemoteCommand::request */ - json::Value request(Irccdctl &irccdctl, const RemoteCommandRequest &args) const override; + IRCCD_EXPORT json::Value request(Irccdctl &irccdctl, const RemoteCommandRequest &args) const override; /** * \copydoc RemoteCommand::exec */ - json::Value exec(Irccd &irccd, const json::Value &request) const override; + IRCCD_EXPORT json::Value exec(Irccd &irccd, const json::Value &request) const override; /** * \copydoc RemoteCommand::result */ - void result(Irccdctl &irccdctl, const json::Value &response) const override; + IRCCD_EXPORT void result(Irccdctl &irccdctl, const json::Value &response) const override; }; } // !command diff -r 70ed0753ce0d -r c1acfacc46bd lib/irccd/cmd-plugin-list.cpp --- a/lib/irccd/cmd-plugin-list.cpp Mon May 23 14:05:41 2016 +0200 +++ b/lib/irccd/cmd-plugin-list.cpp Tue May 24 13:00:35 2016 +0200 @@ -44,9 +44,8 @@ json::Value response = RemoteCommand::exec(irccd, request); json::Value list = json::array({}); - for (const auto &plugin : irccd.pluginService().plugins()) { + for (const auto &plugin : irccd.pluginService().plugins()) list.append(plugin->name()); - } response.insert("list", std::move(list)); @@ -63,9 +62,8 @@ { RemoteCommand::result(irccdctl, object); - for (const auto &n : object.valueOr("list", json::Type::Array, json::array({}))) { + for (const auto &n : object.valueOr("list", json::Type::Array, json::array({}))) std::cout << n.toString() << std::endl; - } } } // !command diff -r 70ed0753ce0d -r c1acfacc46bd lib/irccd/cmd-plugin-list.hpp --- a/lib/irccd/cmd-plugin-list.hpp Mon May 23 14:05:41 2016 +0200 +++ b/lib/irccd/cmd-plugin-list.hpp Tue May 24 13:00:35 2016 +0200 @@ -39,22 +39,22 @@ /** * Constructor. */ - PluginList(); + IRCCD_EXPORT PluginList(); /** * \copydoc RemoteCommand::help */ - std::string help() const override; + IRCCD_EXPORT std::string help() const override; /** * \copydoc RemoteCommand::exec */ - json::Value exec(Irccd &irccd, const json::Value &request) const override; + IRCCD_EXPORT json::Value exec(Irccd &irccd, const json::Value &request) const override; /** * \copydoc RemoteCommand::result */ - void result(Irccdctl &irccdctl, const json::Value &response) const override; + IRCCD_EXPORT void result(Irccdctl &irccdctl, const json::Value &response) const override; }; } // !command diff -r 70ed0753ce0d -r c1acfacc46bd lib/irccd/cmd-plugin-load.hpp --- a/lib/irccd/cmd-plugin-load.hpp Mon May 23 14:05:41 2016 +0200 +++ b/lib/irccd/cmd-plugin-load.hpp Tue May 24 13:00:35 2016 +0200 @@ -39,22 +39,22 @@ /** * Constructor. */ - PluginLoad(); + IRCCD_EXPORT PluginLoad(); /** * \copydoc RemoteCommand::help */ - std::string help() const override; + IRCCD_EXPORT std::string help() const override; /** * \copydoc RemoteCommand::args */ - std::vector args() const override; + IRCCD_EXPORT std::vector args() const override; /** * \copydoc RemoteCommand::exec */ - json::Value exec(Irccd &irccd, const json::Value &request) const override; + IRCCD_EXPORT json::Value exec(Irccd &irccd, const json::Value &request) const override; }; } // !command diff -r 70ed0753ce0d -r c1acfacc46bd lib/irccd/cmd-plugin-reload.hpp --- a/lib/irccd/cmd-plugin-reload.hpp Mon May 23 14:05:41 2016 +0200 +++ b/lib/irccd/cmd-plugin-reload.hpp Tue May 24 13:00:35 2016 +0200 @@ -39,22 +39,22 @@ /** * Constructor. */ - PluginReload(); + IRCCD_EXPORT PluginReload(); /** * \copydoc RemoteCommand::help */ - std::string help() const override; + IRCCD_EXPORT std::string help() const override; /** * \copydoc RemoteCommand::args */ - std::vector args() const override; + IRCCD_EXPORT std::vector args() const override; /** * \copydoc RemoteCommand::exec */ - json::Value exec(Irccd &irccd, const json::Value &request) const override; + IRCCD_EXPORT json::Value exec(Irccd &irccd, const json::Value &request) const override; }; } // !command diff -r 70ed0753ce0d -r c1acfacc46bd lib/irccd/cmd-plugin-unload.hpp --- a/lib/irccd/cmd-plugin-unload.hpp Mon May 23 14:05:41 2016 +0200 +++ b/lib/irccd/cmd-plugin-unload.hpp Tue May 24 13:00:35 2016 +0200 @@ -39,22 +39,22 @@ /** * Constructor. */ - PluginUnload(); + IRCCD_EXPORT PluginUnload(); /** * \copydoc RemoteCommand::help */ - std::string help() const override; + IRCCD_EXPORT std::string help() const override; /** * \copydoc RemoteCommand::args */ - std::vector args() const override; + IRCCD_EXPORT std::vector args() const override; /** * \copydoc RemoteCommand::exec */ - json::Value exec(Irccd &irccd, const json::Value &request) const override; + IRCCD_EXPORT json::Value exec(Irccd &irccd, const json::Value &request) const override; }; } // !command diff -r 70ed0753ce0d -r c1acfacc46bd lib/irccd/cmd-server-cmode.hpp --- a/lib/irccd/cmd-server-cmode.hpp Mon May 23 14:05:41 2016 +0200 +++ b/lib/irccd/cmd-server-cmode.hpp Tue May 24 13:00:35 2016 +0200 @@ -39,22 +39,22 @@ /** * Constructor. */ - ServerChannelMode(); + IRCCD_EXPORT ServerChannelMode(); /** * \copydoc RemoteCommand::help */ - std::string help() const override; + IRCCD_EXPORT std::string help() const override; /** * \copydoc RemoteCommand::args */ - std::vector args() const override; + IRCCD_EXPORT std::vector args() const override; /** * \copydoc RemoteCommand::exec */ - json::Value exec(Irccd &irccd, const json::Value &request) const override; + IRCCD_EXPORT json::Value exec(Irccd &irccd, const json::Value &request) const override; }; } // !command diff -r 70ed0753ce0d -r c1acfacc46bd lib/irccd/cmd-server-cnotice.hpp --- a/lib/irccd/cmd-server-cnotice.hpp Mon May 23 14:05:41 2016 +0200 +++ b/lib/irccd/cmd-server-cnotice.hpp Tue May 24 13:00:35 2016 +0200 @@ -48,22 +48,22 @@ /** * Constructor. */ - ServerChannelNotice(); + IRCCD_EXPORT ServerChannelNotice(); /** * \copydoc RemoteCommand::help */ - std::string help() const override; + IRCCD_EXPORT std::string help() const override; /** * \copydoc RemoteCommand::args */ - std::vector args() const override; + IRCCD_EXPORT std::vector args() const override; /** * \copydoc RemoteCommand::exec */ - json::Value exec(Irccd &irccd, const json::Value &request) const override; + IRCCD_EXPORT json::Value exec(Irccd &irccd, const json::Value &request) const override; }; } // !command diff -r 70ed0753ce0d -r c1acfacc46bd lib/irccd/cmd-server-connect.cpp --- a/lib/irccd/cmd-server-connect.cpp Mon May 23 14:05:41 2016 +0200 +++ b/lib/irccd/cmd-server-connect.cpp Tue May 24 13:00:35 2016 +0200 @@ -38,12 +38,10 @@ { auto it = object.find("name"); - if (it == object.end()) { + if (it == object.end()) throw std::invalid_argument("missing 'name' property"); - } - if (!it->isString() || !util::isIdentifierValid(it->toString())) { + if (!it->isString() || !util::isIdentifierValid(it->toString())) throw std::invalid_argument("invalid server name"); - } return it->toString(); } @@ -52,12 +50,10 @@ { auto it = object.find("host"); - if (it == object.end()) { + if (it == object.end()) throw std::invalid_argument("missing 'host' property"); - } - if (!it->isString()) { + if (!it->isString()) throw std::invalid_argument("invalid host"); - } return it->toString(); } @@ -67,11 +63,9 @@ auto it = object.find("port"); uint16_t port = 6667; - if (it != object.end()) { - if (it->isInt() && it->toInt() >= 0 && it->toInt() <= std::numeric_limits::max()) { + if (it != object.end()) + if (it->isInt() && it->toInt() >= 0 && it->toInt() <= std::numeric_limits::max()) port = static_cast(it->toInt()); - } - } return port; } @@ -90,9 +84,8 @@ throw std::invalid_argument("ssl is disabled"); #endif - if (object.valueOr("sslVerify", json::Type::Boolean, false).toBool()) { + if (object.valueOr("sslVerify", json::Type::Boolean, false).toBool()) info.flags |= ServerInfo::SslVerify; - } return info; } @@ -155,12 +148,10 @@ json::Value ServerConnect::exec(Irccd &irccd, const json::Value &request) const { - auto server = std::make_shared(readInfoName(request), readInfo(request), readIdentity(request), - readSettings(request)); + auto server = std::make_shared(readInfoName(request), readInfo(request), readIdentity(request), readSettings(request)); - if (irccd.serverService().has(server->name())) { + if (irccd.serverService().has(server->name())) throw std::invalid_argument("server '{}' already exists"_format(server->name())); - } irccd.serverService().add(std::move(server)); diff -r 70ed0753ce0d -r c1acfacc46bd lib/irccd/cmd-server-connect.hpp --- a/lib/irccd/cmd-server-connect.hpp Mon May 23 14:05:41 2016 +0200 +++ b/lib/irccd/cmd-server-connect.hpp Tue May 24 13:00:35 2016 +0200 @@ -39,27 +39,27 @@ /** * Constructor. */ - ServerConnect(); + IRCCD_EXPORT ServerConnect(); /** * \copydoc RemoteCommand::help */ - std::string help() const override; + IRCCD_EXPORT std::string help() const override; /** * \copydoc RemoteCommand::options */ - std::vector