Skip to content
Snippets Groups Projects
Commit edfa4fa6 authored by ovari's avatar ovari
Browse files

namedirectory.cpp: cleanup

Change-Id: I02f9cc0e18fdee5a04d1a3c516650821d4d9d248
parent a5eee33e
Branches
No related tags found
No related merge requests found
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
#include <msgpack.hpp> #include <msgpack.hpp>
#include "json_utils.h" #include "json_utils.h"
/* for visual studio */ /* for Visual Studio */
#include <ciso646> #include <ciso646>
#include <sstream> #include <sstream>
#include <regex> #include <regex>
...@@ -55,16 +55,15 @@ constexpr const char DEFAULT_SERVER_HOST[] = "https://ns.jami.net"; ...@@ -55,16 +55,15 @@ constexpr const char DEFAULT_SERVER_HOST[] = "https://ns.jami.net";
const std::string HEX_PREFIX = "0x"; const std::string HEX_PREFIX = "0x";
constexpr std::chrono::seconds SAVE_INTERVAL {5}; constexpr std::chrono::seconds SAVE_INTERVAL {5};
/** /*
Parser for URIs. ( protocol ) ( username ) ( hostname ) * Parser for URIs. ( protocol ) ( username ) ( hostname )
- Requires "@" if a username is present (e.g., "user@domain.com"). * - Requires "@" if a username is present (e.g., "user@domain.com").
- Allows common URL-safe special characters in usernames and domains. * - Allows common URL-safe special characters in usernames and domains.
*
Regex breakdown: * Regex breakdown:
1. `([a-zA-Z]+:(?://)?)?` → Optional scheme ("http://", "ftp://"). * 1. `([a-zA-Z]+:(?://)?)?` → Optional scheme ("http://", "ftp://").
2. `(?:([^\s@]{1,64})@)?` → Optional username (max 64 chars, Unicode allowed). * 2. `(?:([^\s@]{1,64})@)?` → Optional username (max 64 chars, Unicode allowed).
3. `([^\s@]+)` → Domain or standalone name (Unicode allowed, no spaces or "@"). * 3. `([^\s@]+)` → Domain or standalone name (Unicode allowed, no spaces or "@").
*/ */
const std::regex URI_VALIDATOR { const std::regex URI_VALIDATOR {
R"(^([a-zA-Z]+:(?://)?)?(?:([\w\-.~%!$&'()*+,;=]{1,64}|[^\s@]{1,64})@)?([^\s@]+)$)" R"(^([a-zA-Z]+:(?://)?)?(?:([\w\-.~%!$&'()*+,;=]{1,64}|[^\s@]{1,64})@)?([^\s@]+)$)"
...@@ -471,7 +470,7 @@ NameDirectory::saveCache() ...@@ -471,7 +470,7 @@ NameDirectory::saveCache()
std::lock_guard l(cacheLock_); std::lock_guard l(cacheLock_);
msgpack::pack(file, nameCache_); msgpack::pack(file, nameCache_);
} }
JAMI_DEBUG("Saved {:d} name-address mappings to {}", JAMI_DEBUG("Saved {:d} name-address mapping(s) to {}",
nameCache_.size(), cachePath_); nameCache_.size(), cachePath_);
} }
...@@ -510,7 +509,7 @@ NameDirectory::loadCache() ...@@ -510,7 +509,7 @@ NameDirectory::loadCache()
JAMI_ERROR("Error when loading cache: {}", e.what()); JAMI_ERROR("Error when loading cache: {}", e.what());
} }
JAMI_DEBUG("Loaded {:d} name-address mappings from cache", nameCache_.size()); JAMI_DEBUG("Loaded {:d} name-address mapping(s) from cache", nameCache_.size());
} }
} // namespace jami } // namespace jami
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment