Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc Cleanup #10602

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -726,13 +726,13 @@ browser/node_modules: browser/package.json browser/archived-packages
@cd browser && npm install

eslint: browser/node_modules
@make -C browser eslint
@$(MAKE) -C browser eslint

prettier: browser/node_modules
@make -C browser prettier
@$(MAKE) -C browser prettier

prettier-write: browser/node_modules
@make -C browser prettier-write
@$(MAKE) -C browser prettier-write

install-exec-hook:
cd $(DESTDIR)$(bindir) && \
Expand Down
1 change: 1 addition & 0 deletions common/Anonymizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <atomic>
#include <mutex>
#include <string>
#include <string_view>
#include <unordered_map>

extern std::unordered_map<std::string, std::string> AnonymizedStrings;
Expand Down
8 changes: 4 additions & 4 deletions common/FileUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace FileUtil
{
/// Used for anonymizing URLs
void setUrlAnonymization(bool anonymize, const std::uint64_t salt);
void setUrlAnonymization(bool anonymize, std::uint64_t salt);

/// Anonymize the basename of filenames, preserving the path and extension.
std::string anonymizeUrl(const std::string& url);
Expand Down Expand Up @@ -56,7 +56,7 @@ namespace FileUtil
// Perform the check. If the free space on any of the registered file systems is below 5%, call
// 'alertAllUsers("internal", "diskfull")'. The check will be made no more often than once a
// minute if cacheLastCheck is set to true.
std::string checkDiskSpaceOnRegisteredFileSystems(const bool cacheLastCheck = true);
std::string checkDiskSpaceOnRegisteredFileSystems(bool cacheLastCheck = true);

// Check disk space on a specific file system, the one where 'path' is located. This does not
// add that file system to the list used by 'registerFileSystemForDiskSpaceChecks'. If the free
Expand All @@ -68,7 +68,7 @@ namespace FileUtil
/// Suppresses exception when the file is already removed.
/// This can happen when there is a race (unavoidable) or when
/// we don't care to check before we remove (when no race exists).
void removeFile(const std::string& path, const bool recursive = false);
void removeFile(const std::string& path, bool recursive = false);

inline void removeFile(const Poco::Path& path, const bool recursive = false)
{
Expand Down Expand Up @@ -293,7 +293,7 @@ namespace FileUtil
const int _stat_errno;
};

std::vector<std::string> getDirEntries(const std::string dirPath);
std::vector<std::string> getDirEntries(std::string dirPath);

void lslr(const std::string& dir);

Expand Down
4 changes: 2 additions & 2 deletions common/Log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ namespace Log
/// Initialize the logging system.
void initialize(const std::string& name,
const std::string& logLevel,
const bool withColor,
const bool logToFile,
bool withColor,
bool logToFile,
const std::map<std::string, std::string>& config);

/// Shutdown and release the logging system.
Expand Down
10 changes: 0 additions & 10 deletions common/Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,6 @@ namespace COOLProtocol
return false;
}

bool getTokenInteger(const StringVector& tokens, const std::string_view name, int& value)
{
for (size_t i = 0; i < tokens.size(); i++)
{
if (getTokenInteger(tokens[i], name, value))
return true;
}
return false;
}

bool getTokenKeyword(const StringVector& tokens, const std::string_view name, const std::map<std::string, int>& map, int& value)
{
for (size_t i = 0; i < tokens.size(); i++)
Expand Down
11 changes: 10 additions & 1 deletion common/Protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,16 @@ namespace COOLProtocol

bool getTokenKeyword(const StringVector& tokens, const std::string_view name, const std::map<std::string, int>& map, int& value);

bool getTokenInteger(const StringVector& tokens, const std::string_view name, int& value);
inline bool getTokenInteger(const StringVector& tokens, const std::string_view name,
int& value)
{
for (size_t i = 0; i < tokens.size(); i++)
{
if (getTokenInteger(tokens[i], name, value))
return true;
}
return false;
}

/// Literal-string token names.
template <std::size_t N>
Expand Down
28 changes: 0 additions & 28 deletions common/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,34 +408,6 @@ namespace Util
return json;
}

bool isValidURIScheme(const std::string& scheme)
{
if (scheme.empty())
return false;

for (char c : scheme)
{
if (!isalpha(c))
return false;
}

return true;
}

bool isValidURIHost(const std::string& host)
{
if (host.empty())
return false;

for (char c : host)
{
if (!isalnum(c) && c != '_' && c != '-' && c != '.' && c !=':' && c != '[' && c != ']')
return false;
}

return true;
}

std::string trimURI(const std::string &uriStr)
{
Poco::URI uri(uriStr);
Expand Down
55 changes: 11 additions & 44 deletions common/Util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
#include <cstdint>
#include <cstring>
#include <algorithm>
#include <atomic>
#include <limits>
#include <mutex>
#include <set>
#include <sstream>
#include <string>
#include <map>
#include <string_view>
#include <utility>
#include <inttypes.h>
#include <cctype>

#include <memory.h>
Expand Down Expand Up @@ -94,14 +93,14 @@ namespace Util
unsigned getNext();

/// Generate an array of random characters.
std::vector<char> getBytes(const size_t length);
std::vector<char> getBytes(size_t length);

/// Generate a string of random characters.
std::string getHexString(const size_t length);
std::string getHexString(size_t length);

/// Generates a random string suitable for
/// file/directory names.
std::string getFilename(const size_t length);
std::string getFilename(size_t length);
}

/// A utility class to track relative time from some arbitrary
Expand Down Expand Up @@ -342,10 +341,10 @@ namespace Util
std::size_t getCGroupMemSoftLimit();

/// Returns the process PSS in KB (works only when we have perms for /proc/pid/smaps).
size_t getMemoryUsagePSS(const pid_t pid);
size_t getMemoryUsagePSS(pid_t pid);

/// Returns the process RSS in KB.
size_t getMemoryUsageRSS(const pid_t pid);
size_t getMemoryUsageRSS(pid_t pid);

/// Returns the number of current threads, or zero on error
size_t getCurrentThreadCount();
Expand All @@ -358,12 +357,12 @@ namespace Util
/// returns them as a pair in the same order
std::pair<size_t, size_t> getPssAndDirtyFromSMaps(FILE* file);

size_t getCpuUsage(const pid_t pid);
size_t getCpuUsage(pid_t pid);

size_t getStatFromPid(const pid_t pid, int ind);
size_t getStatFromPid(pid_t pid, int ind);

/// Sets priorities for a given pid & the current thread
void setProcessAndThreadPriorities(const pid_t pid, int prio);
void setProcessAndThreadPriorities(pid_t pid, int prio);

/// Replace substring @a in string @s with string @b.
std::string replace(std::string s, const std::string& a, const std::string& b);
Expand Down Expand Up @@ -606,30 +605,6 @@ namespace Util

size_t findInVector(const std::vector<char>& tokens, const char *cstring, std::size_t offset = 0);

/// Trim spaces from the left. Just spaces.
inline std::string& ltrim(std::string& s)
{
const size_t pos = s.find_first_not_of(' ');
if (pos != std::string::npos)
{
s = s.substr(pos);
}

return s;
}

/// Trim spaces from the left and copy. Just spaces.
inline std::string ltrimmed(const std::string& s)
{
const size_t pos = s.find_first_not_of(' ');
if (pos != std::string::npos)
{
return s.substr(pos);
}

return s;
}

inline std::string& trim(std::string& s, const char ch)
{
const size_t last = s.find_last_not_of(ch);
Expand Down Expand Up @@ -1148,14 +1123,6 @@ int main(int argc, char**argv)
/// All components are optional, depending on what the URL represents (can be a unix path).
std::tuple<std::string, std::string, std::string, std::string> splitUrl(const std::string& url);

/// Check for the URI scheme validity.
/// For now just a basic sanity check, can be extended if necessary.
bool isValidURIScheme(const std::string& scheme);

/// Check for the URI host validity.
/// For now just a basic sanity check, can be extended if necessary.
bool isValidURIHost(const std::string& host);

/// Remove all but scheme://hostname:port/ from a URI.
std::string trimURI(const std::string& uri);

Expand Down Expand Up @@ -1278,7 +1245,7 @@ int main(int argc, char**argv)

public:
/// Produces a backtrace instance from current stack position
Backtrace(const int maxFrames = 50, const int skip = 1);
Backtrace(int maxFrames = 50, int skip = 1);

/// Produces a backtrace instance from current stack position
static Backtrace get(const int maxFrames = 50, const int skip = 2)
Expand Down Expand Up @@ -1419,7 +1386,7 @@ int main(int argc, char**argv)
* Converts vector of strings to map. Strings should have formed like this: key + delimiter + value.
* In case of a misformed string or zero length vector, passes that item and warns the developer.
*/
std::map<std::string, std::string> stringVectorToMap(const std::vector<std::string>& strvector, const char delimiter);
std::map<std::string, std::string> stringVectorToMap(const std::vector<std::string>& strvector, char delimiter);

// If OS is not mobile, it must be Linux.
std::string getLinuxVersion();
Expand Down
7 changes: 4 additions & 3 deletions kit/ForKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <map>
#include <thread>
#include <chrono>
#include <utility>

#include <Poco/Path.h>
#include <Poco/URI.h>
Expand Down Expand Up @@ -112,9 +113,9 @@ class ServerWSHandler final : public WebSocketHandler
std::string _socketName;

public:
ServerWSHandler(const std::string& socketName) :
WebSocketHandler(/* isClient = */ true, /* isMasking */ false),
_socketName(socketName)
explicit ServerWSHandler(std::string socketName)
: WebSocketHandler(/* isClient = */ true, /* isMasking */ false)
, _socketName(std::move(socketName))
{
}

Expand Down
Loading