changeset 691:c2626336a93e

Irccd: seek symbol name from plugin filename, close #795 @10m
author David Demelier <markand@malikania.fr>
date Tue, 17 Apr 2018 12:49:32 +0200
parents 849c4337c18e
children 84c0b723100d
files libirccd/irccd/daemon/dynlib_plugin.cpp
diffstat 1 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libirccd/irccd/daemon/dynlib_plugin.cpp	Tue Apr 17 12:22:15 2018 +0200
+++ b/libirccd/irccd/daemon/dynlib_plugin.cpp	Tue Apr 17 12:49:32 2018 +0200
@@ -19,6 +19,7 @@
 #include <algorithm>
 
 #include <boost/dll.hpp>
+#include <boost/filesystem.hpp>
 
 #include <irccd/string_util.hpp>
 
@@ -36,8 +37,16 @@
 
 namespace {
 
-std::string symbol(std::string id) noexcept
+std::string symbol(const std::string& path) noexcept
 {
+    auto id = boost::filesystem::path(path).stem().string();
+
+    // Remove forbidden characters.
+    id.erase(std::remove_if(id.begin(), id.end(), [] (auto c) {
+        return !isalnum(c) && c != '-' && c != '_';
+    }), id.end());
+
+    // Transform - to _.
     std::transform(id.begin(), id.end(), id.begin(), [] (auto c) noexcept {
         return c == '-' ? '_' : c;
     });