19#include <nlohmann/json.hpp>
21#include "../core/logger/logger.h"
23#ifdef MANTIS_ENABLE_SCRIPTING
24#include "dukglue/dukvalue.h"
30#if __has_include(<format>)
33#include <spdlog/fmt/bundled/format.h>
40 namespace fs = std::filesystem;
41 using json = nlohmann::json;
53 fs::path
joinPaths(
const std::string &path1,
const std::string &path2);
65 fs::path
resolvePath(
const std::string &input_path);
120 std::string
trim(
const std::string &s);
135 std::optional<json>
tryParseJsonStr(
const std::string &json_str, std::optional<json> default_value = std::nullopt);
146 bool strToBool(
const std::string &value);
206 std::vector<std::string>
splitString(
const std::string &input,
const std::string &delimiter);
214 std::string
getEnvOrDefault(
const std::string &key,
const std::string &defaultValue);
257 std::size_t maxLen = 50,
258 std::size_t idLen = 12,
259 std::string_view idSep =
"_");
283 bool verifyPassword(
const std::string &password,
const std::string &stored_hash);
290 const std::time_t now = std::time(
nullptr);
291 const std::tm* utc = std::gmtime(&now);
294 std::strftime(buffer,
sizeof(buffer),
"%Y-%m-%d %H:%M:%S", utc);
295 return std::string{ buffer };
303 std::string
tmToStr(
const std::tm &t);
310 std::tm
strToTM(
const std::string &value);
336 int safe_stoi(
const std::string &s,
const int default_val);
378#ifdef MANTIS_ENABLE_SCRIPTING
router.h
Definition auth.h:15
bool isValidIPv6(const std::string &ip)
Validates if a string is a valid IPv6 address.
Definition string_utils.cpp:212
std::vector< std::string > splitString(const std::string &input, const std::string &delimiter)
Split given string based on given delimiter.
Definition string_utils.cpp:93
int safe_stoi(const std::string &s, const int default_val)
Safely convert string to integer with default fallback.
Definition string_utils.cpp:191
fs::path resolvePath(const std::string &input_path)
Definition path_utils.cpp:11
bool createDirs(const fs::path &path)
Create directory, given a path.
Definition path_utils.cpp:24
std::string trim(const std::string &s)
Trims leading and trailing whitespaces from a string.
Definition string_utils.cpp:36
void registerUtilsToDuktapeEngine()
Definition dukglue_utils_bindings.cpp:5
std::string dbDateToString(const soci::row &row, int index)
Convert database date value from SOCI row to string.
Definition date_utils.cpp:28
std::string generateTimeBasedId()
Generate a time base UUID.
Definition string_utils.cpp:42
void toLowerCase(std::string &str)
Converts a string to its lowercase variant.
Definition string_utils.cpp:26
bool isValidIP(const std::string &ip)
Validates if a string is a valid IP address (IPv4 or IPv6).
Definition string_utils.cpp:226
std::tm strToTM(const std::string &value)
Convert ISO formatted datetime string to std::tm structure.
Definition date_utils.cpp:16
std::string tmToStr(const std::tm &t)
Convert c++ std::tm date/time value to ISO formatted string.
Definition date_utils.cpp:8
void sanitizeInPlace(std::string &s)
Sanitize a string in-place by removing or replacing invalid characters.
Definition string_utils.cpp:120
std::string getEnvOrDefault(const std::string &key, const std::string &defaultValue)
Retrieves a value from an environment variable or a default value if the env variable was not set.
Definition string_utils.cpp:107
bool verifyPassword(const std::string &password, const std::string &stored_hash)
Verifies user password if it matches the given hashed password.
Definition auth_utils.cpp:14
std::optional< json > tryParseJsonStr(const std::string &json_str, std::optional< json > default_value=std::nullopt)
Attempt to parse a JSON string.
Definition string_utils.cpp:7
bool invalidChar(unsigned char c)
Check if a character is invalid in a filename.
Definition string_utils.cpp:112
std::string getCurrentTimestampUTC()
Definition utils.h:289
std::string sanitizeFilename(std::string_view original, std::size_t maxLen=50, std::size_t idLen=12, std::string_view idSep="_")
Sanitize a filename and ensure uniqueness.
Definition string_utils.cpp:154
std::string hashPassword(const std::string &password)
Digests user password + a generated salt to yield a hashed password.
Definition auth_utils.cpp:8
fs::path joinPaths(const std::string &path1, const std::string &path2)
JSON convenience for the nlomann::json namespace
Definition path_utils.cpp:5
std::string generateShortId(size_t length=16)
Generates a short UUID.
Definition string_utils.cpp:79
void toUpperCase(std::string &str)
Converts a string to its uppercase variant.
Definition string_utils.cpp:31
std::string sanitizeFilename_JSWrapper(const std::string &original)
Definition string_utils.cpp:187
std::string dirFromPath(const std::string &path)
Returns a created/existing directory from a path.
Definition path_utils.cpp:44
bool strToBool(const std::string &value)
Convert given string value to boolean type.
Definition string_utils.cpp:20
bool isValidIPv4(const std::string &ip)
Validates if a string is a valid IPv4 address.
Definition string_utils.cpp:199
std::string generateReadableTimeId()
Generates a readable time-based UUID.
Definition string_utils.cpp:58
nlohmann::json json
Shorten JSON namespace.
Definition context_store.h:18