Compare commits
8 次程式碼提交
61e84a98c7
...
master
作者 | SHA1 | 提交日期 | |
---|---|---|---|
22e3941f2c | |||
168d24c545 | |||
d1358f7e77 | |||
79d69f4b65 | |||
bfeacb0510 | |||
c6013338a9 | |||
dab0b94ec4 | |||
2ebdbd0b6d |
50
cache/mapcache.h
vendored
50
cache/mapcache.h
vendored
@ -5,12 +5,13 @@
|
||||
#include <shared_mutex>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include "icache.h"
|
||||
|
||||
/* Thread-Safe Key-Value store */
|
||||
template <class T> class MapCache
|
||||
{
|
||||
private:
|
||||
std::map<std::string, T> cache;
|
||||
std::unordered_map<std::string, T> cache;
|
||||
mutable std::shared_mutex sharedMutex;
|
||||
|
||||
public:
|
||||
@ -34,6 +35,53 @@ template <class T> class MapCache
|
||||
std::lock_guard<std::shared_mutex> lock{sharedMutex};
|
||||
this->cache.clear();
|
||||
}
|
||||
|
||||
void remove(const std::string &key)
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lock{sharedMutex};
|
||||
this->cache.erase(key);
|
||||
}
|
||||
|
||||
void removePrefix(const std::string &key)
|
||||
{
|
||||
std::lock_guard<std::shared_mutex> lock{sharedMutex};
|
||||
std::erase_if(this->cache, [key](const auto &item)
|
||||
{
|
||||
auto const& [k, v] = item;
|
||||
return k.starts_with(std::string_view(key));
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
class StringCache : public MapCache<std::string>, public ICache
|
||||
{
|
||||
virtual std::optional<std::string> get(std::string_view key) const override
|
||||
{
|
||||
return MapCache<std::string>::find(std::string(key));
|
||||
}
|
||||
|
||||
virtual void put(std::string_view key, std::string val) override
|
||||
{
|
||||
MapCache<std::string>::set(std::string(key), val);
|
||||
}
|
||||
|
||||
virtual void remove(std::string_view key) override
|
||||
{
|
||||
MapCache<std::string>::remove(std::string(key));
|
||||
}
|
||||
|
||||
virtual void removePrefix(std::string_view prefix)
|
||||
{
|
||||
MapCache<std::string>::removePrefix(std::string(prefix));
|
||||
}
|
||||
|
||||
virtual void clear() override
|
||||
{
|
||||
MapCache<std::string>::clear();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // MAPCACHE_H
|
||||
|
@ -89,7 +89,6 @@ std::string HandlerFeedGenerator::generateAtom(const std::vector<HandlerFeedGene
|
||||
newestPublished = initialRevision.timestamp;
|
||||
}
|
||||
std::string entryPublished = utils::formatLocalDate(initialRevision.timestamp, dateformat) + "Z";
|
||||
std::string entryUpdated = utils::formatLocalDate(current.timestamp, dateformat) + "Z";
|
||||
std::string entryurl =
|
||||
this->urlProvider->combine({this->urlProvider->rootUrl(), this->urlProvider->page(page.name)});
|
||||
TemplatePage atomentry = this->templ->getPage("feeds/atomentry");
|
||||
@ -97,7 +96,7 @@ std::string HandlerFeedGenerator::generateAtom(const std::vector<HandlerFeedGene
|
||||
atomentry.setVar("entryurl", utils::html_xss(entryurl));
|
||||
atomentry.setVar("entryid", utils::html_xss(entryurl));
|
||||
atomentry.setVar("entrypublished", entryPublished);
|
||||
atomentry.setVar("entryupdated", entryUpdated);
|
||||
atomentry.setVar("entryupdated", entryPublished);
|
||||
atomentry.setVar("entrycontent", utils::html_xss(revisionRenderer.renderContent(current, page.title)));
|
||||
stream << atomentry.render();
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ std::string HandlerPageView::createIndexContent(IParser &parser, std::string con
|
||||
}
|
||||
previous = h.level;
|
||||
HtmlLink link;
|
||||
link.href = "#" + h.title;
|
||||
link.href = "#" + utils::strreplace(h.title, " ", "");
|
||||
link.innervalue = h.title;
|
||||
link.cssclass = "indexlink";
|
||||
indexcontent += "<li>" + link.render() + "</li>";
|
||||
|
30
parser.cpp
30
parser.cpp
@ -175,14 +175,26 @@ std::string Parser::parse(const PageDao &pagedao, UrlProvider &provider, const s
|
||||
std::string result;
|
||||
// we don't care about commands, but we nevertheless replace them with empty strings
|
||||
std::regex tagfinder(
|
||||
R"(\[(b|i|u|s|li||ul|ol|code|blockquote|img|link|wikilink|h\d|cmd:visible|cmd:listed|cmd:feedlisted|cmd:rename|cmd:redirect|cmd:pagetitle|cmd:allowinclude|cmd:permissions|cmd:parentpage|content|category|dynamic:postlist|dynamic:includepage|dynamic:getvar|dynamic:setvar)*?\]((\s|\S)*?)\[/\1])");
|
||||
R"(\[(b|i|u|s|li|p|br|ul|ol|code|blockquote|img|link|wikilink|h\d|cmd:visible|cmd:listed|cmd:feedlisted|cmd:rename|cmd:redirect|cmd:pagetitle|cmd:allowinclude|cmd:permissions|cmd:parentpage|content|category|dynamic:postlist|dynamic:includepage|dynamic:getvar|dynamic:setvar)*?\]((\s|\S)*?)\[/\1](\r\n)*)");
|
||||
|
||||
const std::string justreplace[] = {"b", "i", "u", "p", "br", "ul", "li", "ol"};
|
||||
|
||||
result = utils::regex_callback_replacer(
|
||||
tagfinder, content,
|
||||
[&](std::smatch &match)
|
||||
{
|
||||
std::string tag = match.str(1);
|
||||
std::string content = match.str(2);
|
||||
std::string justreplace[] = {"b", "i", "u", "ul", "li", "ol", "s"};
|
||||
|
||||
std::string newlines = match.str(4);
|
||||
if(newlines == "\r\n")
|
||||
{
|
||||
newlines = "<br>";
|
||||
}
|
||||
if(tag == "br")
|
||||
{
|
||||
return std::string("<br>");
|
||||
}
|
||||
if(tag != "code" && tag != "blockquote")
|
||||
{
|
||||
content = parse(pagedao, provider, content, callback);
|
||||
@ -194,13 +206,17 @@ std::string Parser::parse(const PageDao &pagedao, UrlProvider &provider, const s
|
||||
}
|
||||
if(std::find(std::begin(justreplace), std::end(justreplace), tag) != std::end(justreplace))
|
||||
{
|
||||
return "<" + tag + ">" + content + "</" + tag + ">";
|
||||
if(tag == "p" || tag == "br")
|
||||
{
|
||||
newlines = "";
|
||||
}
|
||||
return "<" + tag + ">" + content + "</" + tag + ">" + newlines;
|
||||
}
|
||||
if(tag == "link" || tag == "wikilink")
|
||||
{
|
||||
return this->processLink(
|
||||
pagedao, provider,
|
||||
match); // TODO: recreate this so we don't check inside the function stuff again
|
||||
return this->processLink(pagedao, provider,
|
||||
match) +
|
||||
newlines; // TODO: recreate this so we don't check inside the function stuff again
|
||||
}
|
||||
if(tag == "img")
|
||||
{
|
||||
@ -208,7 +224,7 @@ std::string Parser::parse(const PageDao &pagedao, UrlProvider &provider, const s
|
||||
}
|
||||
if(tag[0] == 'h')
|
||||
{
|
||||
return "<" + tag + " id='" + content + "'>" + content + "</" + tag + ">";
|
||||
return "<" + tag + " id='" + utils::strreplace(content, " ", "") + "'>" + content + "</" + tag + ">";
|
||||
}
|
||||
if(tag == "code" || tag == "blockquote")
|
||||
{
|
||||
|
@ -72,7 +72,7 @@ std::unique_ptr<ICache> createCache(const ConfigVariableResolver &resolver)
|
||||
std::string path = resolver.getConfig("cache_fs_dir");
|
||||
if(path == "")
|
||||
{
|
||||
return std::make_unique<NoCache>(path);
|
||||
return std::make_unique<StringCache>();
|
||||
}
|
||||
return std::make_unique<FsCache>(path);
|
||||
}
|
||||
|
@ -49,7 +49,11 @@ bool SandboxLinux::enable(std::vector<std::string> fsPaths)
|
||||
}
|
||||
for(unsigned int i = 0; i < fsPaths.size(); i++)
|
||||
{
|
||||
exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE, fsPaths[i].c_str());
|
||||
std::string &path = fsPaths[i];
|
||||
if(path.size() > 0)
|
||||
{
|
||||
exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE, path.c_str());
|
||||
}
|
||||
}
|
||||
policy->drop_caps = 1;
|
||||
policy->not_dumpable = 1;
|
||||
|
Submodule submodules/cpp-httplib updated: c7ed1796a7...3af7f2c161
Reference in New Issue
Block a user