Porównaj commity
10 Commity
828d827c3d
...
92be470545
Autor | SHA1 | Data | |
---|---|---|---|
92be470545 | |||
d5485a833f | |||
0bdb22c170 | |||
eb49b013a7 | |||
9593429f95 | |||
86ac86b83f | |||
92e7390056 | |||
b1a8572eb6 | |||
44ade88cae | |||
aadb623bf7 |
9
Makefile
9
Makefile
@ -42,7 +42,12 @@ GTEST_OBJECTS=$(filter-out qswiki.o, $(WIKIOBJECTS))
|
||||
.DEFAULT_GOAL := qswiki
|
||||
|
||||
release: CXXFLAGS=$(RELEASE_CXXFLAGS)
|
||||
profile: CXXFLAGS=$(RELEASE_CXXFLAGS) -pg
|
||||
profile: LDFLAGS+= -pg
|
||||
|
||||
release: qswiki
|
||||
profile: qswiki
|
||||
|
||||
qswiki: $(WIKIOBJECTS)
|
||||
$(CXX) $(WIKIOBJECTS) ${LDFLAGS} ${INCLUDEFLAGS} -o qswiki
|
||||
|
||||
@ -53,10 +58,10 @@ gtest: $(GTESTS_TESTDIR)/*.cpp $(GTEST_OBJECTS)
|
||||
$(CXX) -o gtest $(GTESTS_TESTDIR)/*.cpp $(GTEST_OBJECTS) $(GTEST_CXXFLAGS) $(GTEST_DIR)/src/gtest_main.cc $(GTEST_DIR)/src/gtest-all.cc $(GTEST_LDFLAGS)
|
||||
|
||||
%.o:%.cpp
|
||||
$(CXX) ${CXXFLAGS} ${LDFLAGS} ${INCLUDEFLAGS} -c -o $@ $<
|
||||
$(CXX) ${CXXFLAGS} ${INCLUDEFLAGS} -c -o $@ $<
|
||||
|
||||
version.o:version.cpp
|
||||
$(CXX) ${CXXFLAGS} ${LDFLAGS} ${INCLUDEFLAGS} -DGITCOMMIT=\"$(shell git rev-parse --short HEAD)\" -c -o $@ $<
|
||||
$(CXX) ${CXXFLAGS} ${INCLUDEFLAGS} -DGITCOMMIT=\"$(shell git rev-parse --short HEAD)\" -c -o $@ $<
|
||||
clean:
|
||||
rm -f $(OBJECTS) $(DEPENDS)
|
||||
|
||||
|
@ -104,7 +104,17 @@ void CLIConsole::startInteractive()
|
||||
auto pair = CLIHandler::splitCommand(input);
|
||||
if(pair.first == "exit")
|
||||
{
|
||||
std::cout << "Exiting CLI";
|
||||
if(attached)
|
||||
{
|
||||
std::cout << "You are attached. Quit attached instance too (y) or only this one(n)" << std::endl;
|
||||
char response;
|
||||
std::cin >> response;
|
||||
if(response == 'y')
|
||||
{
|
||||
this->send("exit");
|
||||
}
|
||||
}
|
||||
std::cout << "Exiting CLI" << std::endl;
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
if(pair.first == "attach")
|
||||
|
@ -48,7 +48,7 @@ std::optional<User> UserDaoSqlite::find(std::string username)
|
||||
stmt >> std::tie(user.login, user.password, user.salt, perms, user.enabled);
|
||||
user.permissions = Permissions{perms};
|
||||
|
||||
return std::move(user);
|
||||
return user;
|
||||
}
|
||||
catch(const sqlite::errors::no_rows &e)
|
||||
{
|
||||
@ -71,7 +71,7 @@ std::optional<User> UserDaoSqlite::find(int id)
|
||||
stmt >> std::tie(user.login, user.password, user.salt, perms, user.enabled);
|
||||
user.permissions = Permissions{perms};
|
||||
|
||||
return std::move(user);
|
||||
return user;
|
||||
}
|
||||
catch(const sqlite::errors::no_rows &e)
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ Request HttpGateway::convertRequest(httplib::Request request)
|
||||
// TODO: this eats resources, where perhaps it does not need to. move it to request?
|
||||
for(auto &it : request.params)
|
||||
{
|
||||
it.second = utils::html_xss(std::string{it.second});
|
||||
it.second = utils::html_xss(it.second);
|
||||
}
|
||||
if(request.method == "GET")
|
||||
{
|
||||
@ -83,7 +83,8 @@ void HttpGateway::work(RequestWorker &worker)
|
||||
{
|
||||
httplib::Server server;
|
||||
server.set_payload_max_length(this->maxPayloadLength);
|
||||
auto handler = [&](const httplib::Request &req, httplib::Response &res) {
|
||||
auto handler = [&](const httplib::Request &req, httplib::Response &res)
|
||||
{
|
||||
Request wikiRequest = convertRequest(req);
|
||||
Logger::debug() << "httpgateway: received request " << wikiRequest;
|
||||
Response wikiresponse = worker.processRequest(wikiRequest);
|
||||
|
@ -32,12 +32,12 @@ Response::Response(int http_status_code, std::string html)
|
||||
this->html = std::move(html);
|
||||
}
|
||||
|
||||
void Response::addHeader(const std::string &key, const std::string &value)
|
||||
void Response::addHeader(std::string key, std::string value)
|
||||
{
|
||||
this->responseHeaders.insert(std::make_pair(key, value));
|
||||
}
|
||||
|
||||
Response Response::redirectTemporarily(const std::string &url)
|
||||
Response Response::redirectTemporarily(std::string url)
|
||||
{
|
||||
Response result;
|
||||
result.addHeader("Location", url);
|
||||
|
@ -27,8 +27,8 @@ class Response
|
||||
return this->html;
|
||||
}
|
||||
|
||||
void addHeader(const std::string &key, const std::string &value);
|
||||
static Response redirectTemporarily(const std::string &url);
|
||||
void addHeader(std::string key, std::string value);
|
||||
static Response redirectTemporarily(std::string url);
|
||||
|
||||
void setStatus(int status)
|
||||
{
|
||||
|
@ -67,7 +67,7 @@ std::string Template::resolveIncludes(std::string_view content)
|
||||
return replacer.parse(content);
|
||||
}
|
||||
|
||||
TemplatePage Template::createPage(std::string name)
|
||||
TemplatePage Template::createPage(std::string_view name)
|
||||
{
|
||||
std::string content = loadResolvedPart(name);
|
||||
Varreplacer replacer(this->templateprefix);
|
||||
|
@ -24,7 +24,7 @@ class Template
|
||||
std::string getPartPath(std::string_view partname);
|
||||
std::string loadResolvedPart(std::string_view partname);
|
||||
std::string loadPartContent(std::string_view partname);
|
||||
TemplatePage createPage(std::string name);
|
||||
TemplatePage createPage(std::string_view name);
|
||||
|
||||
public:
|
||||
Template(std::string templateprefix, std::string templatepath, ConfigUrls &configUrls,
|
||||
|
@ -84,7 +84,7 @@ std::string utils::urldecode(std::string_view str)
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> utils::split(const std::string &str, char delim)
|
||||
std::vector<std::string> utils::split(std::string str, char delim)
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
std::stringstream stream(str);
|
||||
@ -97,7 +97,7 @@ std::vector<std::string> utils::split(const std::string &str, char delim)
|
||||
}
|
||||
|
||||
// TODO: can easily break if we pass a regex here
|
||||
std::vector<std::string> utils::split(const std::string &str, const std::string &delim)
|
||||
std::vector<std::string> utils::split(std::string str, const std::string &delim)
|
||||
{
|
||||
std::regex regex{delim + "+"};
|
||||
return split(str, regex);
|
||||
@ -112,7 +112,7 @@ std::vector<std::string> utils::split(const std::string &str, std::regex ®ex)
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string utils::strreplace(const std::string &str, const std::string &search, const std::string &replace)
|
||||
std::string utils::strreplace(std::string str, const std::string &search, const std::string &replace)
|
||||
{
|
||||
std::string result = str;
|
||||
auto searchlength = search.length();
|
||||
@ -182,10 +182,9 @@ std::string utils::toISODate(time_t t)
|
||||
return std::string{result};
|
||||
}
|
||||
|
||||
std::string utils::trim(const std::string &str)
|
||||
std::string utils::trim(std::string_view view)
|
||||
{
|
||||
std::string_view chars = " \t\n\r";
|
||||
std::string_view view = str;
|
||||
auto n = view.find_first_not_of(chars);
|
||||
if(n != std::string_view::npos)
|
||||
{
|
||||
|
16
utils.h
16
utils.h
@ -11,22 +11,22 @@
|
||||
namespace utils
|
||||
{
|
||||
|
||||
std::vector<std::string> split(const std::string &str, char delim);
|
||||
std::vector<std::string> split(const std::string &str, const std::string &delim);
|
||||
std::vector<std::string> split(std::string str, char delim);
|
||||
std::vector<std::string> split(std::string str, const std::string &delim);
|
||||
std::vector<std::string> split(const std::string &str, std::regex ®ex);
|
||||
std::string urldecode(std::string_view str);
|
||||
std::string strreplace(const std::string &str, const std::string &search, const std::string &replace);
|
||||
std::string strreplace(std::string str, const std::string &search, const std::string &replace);
|
||||
|
||||
std::string html_xss(std::string_view str);
|
||||
std::string getenv(const std::string &key);
|
||||
|
||||
template <class T, class U> bool hasKey(const std::map<T, U> &map, T key)
|
||||
template <class T, class U> bool hasKey(const std::map<T, U> &map, const T &key)
|
||||
{
|
||||
auto k = map.find(key);
|
||||
return k != map.end();
|
||||
}
|
||||
|
||||
template <class T, class U> U getKeyOrEmpty(const std::map<T, U> &map, T key)
|
||||
template <class T, class U> U getKeyOrEmpty(const std::map<T, U> &map, const T &key)
|
||||
{
|
||||
auto k = map.find(key);
|
||||
if(k != map.end())
|
||||
@ -36,7 +36,7 @@ template <class T, class U> U getKeyOrEmpty(const std::map<T, U> &map, T key)
|
||||
return U();
|
||||
}
|
||||
|
||||
template <class T, class U> U getKeyOrEmpty(std::multimap<T, U> map, T key)
|
||||
template <class T, class U> U getKeyOrEmpty(const std::multimap<T, U> &map, const T &key)
|
||||
{
|
||||
auto k = map.find(key);
|
||||
if(k != map.end())
|
||||
@ -46,7 +46,7 @@ template <class T, class U> U getKeyOrEmpty(std::multimap<T, U> map, T key)
|
||||
return U();
|
||||
}
|
||||
|
||||
template <class T, class U> std::vector<U> getAll(std::multimap<T, U> map, T key)
|
||||
template <class T, class U> std::vector<U> getAll(const std::multimap<T, U> &map, const T &key)
|
||||
{
|
||||
std::vector<U> result;
|
||||
auto range = map.equal_range(key);
|
||||
@ -93,7 +93,7 @@ template <class T> inline std::string toString(const T &v)
|
||||
return std::string(v.begin(), v.end());
|
||||
}
|
||||
|
||||
std::string trim(const std::string &str);
|
||||
std::string trim(std::string_view view);
|
||||
|
||||
} // namespace utils
|
||||
#endif
|
||||
|
Ładowanie…
Reference in New Issue
Block a user