Compare commits
11 Commits
ae1d33a14e
...
2da122f36d
| Author | SHA1 | Date | |
|---|---|---|---|
| 2da122f36d | |||
| 3a22538181 | |||
| 5d66501262 | |||
| f607716bf7 | |||
| e412c16dbb | |||
| fae81f2213 | |||
| 2594442674 | |||
| 0e21d96bd4 | |||
| 0eafdcc8c1 | |||
| ab0a6f1e27 | |||
| 03b2f44744 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -10,3 +10,5 @@ wikiqs*
|
||||
data/*
|
||||
gtest*
|
||||
cgi-bin/*
|
||||
.cache
|
||||
build
|
||||
|
||||
67
Makefile
67
Makefile
@@ -26,7 +26,8 @@ HEADERS+=$(wildcard cache/*.h)
|
||||
HEADERS+=$(wildcard sandbox/*.h)
|
||||
HEADERS+=$(wildcard dynamic/*.h)
|
||||
|
||||
OBJECTS=$(patsubst %.cpp, %.o, $(SOURCES))
|
||||
BUILDDIR = build
|
||||
OBJECTS=$(patsubst %.cpp, $(BUILDDIR)/%.o, $(SOURCES))
|
||||
WIKIOBJECTS=$(filter-out test.o, $(OBJECTS))
|
||||
TESTOBJECTS=$(filter-out qswiki.o, $(OBJECTS))
|
||||
DEPENDS = ${WIKIOBJECTS:.o=.d}
|
||||
@@ -34,7 +35,7 @@ DEPENDS = ${WIKIOBJECTS:.o=.d}
|
||||
|
||||
# Points to the root of Google Test, relative to where this file is.
|
||||
# Remember to tweak this if you move this file.
|
||||
GTEST_DIR = /home/data/SOURCES/gtest/googletest
|
||||
GTEST_DIR = ../../gtest/googletest
|
||||
|
||||
GTESTS_TESTDIR = ./tests/
|
||||
|
||||
@@ -42,6 +43,17 @@ GTEST_CXXFLAGS=-std=$(CPPSTD) -isystem $(GTEST_DIR)/include -I$(GTEST_DIR) -g -O
|
||||
GTEST_LDFLAGS=-lsqlite3 -g -O0 -lpthread -lcrypto -lstdc++fs
|
||||
GTEST_OBJECTS=$(filter-out qswiki.o, $(WIKIOBJECTS))
|
||||
|
||||
RESOURCEDIR ?= template/quitesimple
|
||||
RESOURCEFILES := $(shell find $(RESOURCEDIR) -type f)
|
||||
RESOURCEOUTDIR := $(BUILDDIR)/resources
|
||||
RESOURCEOBJECTS := $(patsubst $(RESOURCEDIR)/%,$(RESOURCEOUTDIR)/%.o,$(RESOURCEFILES))
|
||||
|
||||
GENERATED_PATH = $(BUILDDIR)/generated
|
||||
|
||||
|
||||
OBJCOPY_ARCH := elf64-x86-64
|
||||
OBJCOPY_TARGET := i386:x86-64
|
||||
|
||||
.DEFAULT_GOAL := qswiki
|
||||
|
||||
release: CXXFLAGS=$(RELEASE_CXXFLAGS)
|
||||
@@ -51,25 +63,58 @@ profile: LDFLAGS+= -pg
|
||||
release: qswiki
|
||||
profile: qswiki
|
||||
|
||||
OBJECTDIRS=$(sort $(dir $(OBJECTS)))
|
||||
|
||||
exile.o: submodules/exile.h/exile.c
|
||||
$(CC) -std=c99 -c submodules/exile.h/exile.c -o exile.o
|
||||
|
||||
qswiki: $(WIKIOBJECTS) exile.o
|
||||
$(CXX) $(shell shuf -e $(WIKIOBJECTS) exile.o ) ${LDFLAGS} ${INCLUDEFLAGS} -o qswiki
|
||||
|
||||
$(OBJECTS): | $(OBJECTDIRS)
|
||||
|
||||
$(OBJECTDIRS):
|
||||
mkdir -p $@
|
||||
|
||||
|
||||
$(BUILDDIR)/exile.o: submodules/exile.h/exile.c
|
||||
$(CC) -std=c99 -c submodules/exile.h/exile.c -o $@
|
||||
|
||||
qswiki: $(WIKIOBJECTS) $(BUILDDIR)/exile.o genresources
|
||||
$(CXX) $(shell shuf -e $(WIKIOBJECTS) $(RESOURCEOBJECTS) $(BUILDDIR)/exile.o ) ${LDFLAGS} ${INCLUDEFLAGS} -o $(BUILDDIR)/qswiki
|
||||
|
||||
test: $(TESTOBJECTS)
|
||||
$(CXX) $(TESTOBJECTS) ${LDFLAGS} -o test
|
||||
$(CXX) $(TESTOBJECTS) ${LDFLAGS} -o $(BUILDDIR)/test
|
||||
|
||||
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} ${INCLUDEFLAGS} -c -o $@ $<
|
||||
$(BUILDDIR)/%.o:%.cpp
|
||||
$(CXX) ${CXXFLAGS} ${INCLUDEFLAGS} -c -o $@ $<
|
||||
|
||||
version.o:version.cpp
|
||||
$(BUILDDIR)/version.o:version.cpp
|
||||
$(CXX) ${CXXFLAGS} ${INCLUDEFLAGS} -DGITCOMMIT=\"$(shell git rev-parse --short HEAD)\" -c -o $@ $<
|
||||
|
||||
$(BUILDDIR)/embedded.o:embedded.cpp genresources
|
||||
$(CXX) ${CXXFLAGS} ${INCLUDEFLAGS} -I $(GENERATED_PATH) -c -o $@ $<
|
||||
clean:
|
||||
rm -f exile.o $(OBJECTS) $(DEPENDS)
|
||||
rm -r build
|
||||
|
||||
genresources: resources_gen.sh resources
|
||||
./resources_gen.sh $(GENERATED_PATH) $(RESOURCEDIR)
|
||||
|
||||
$(RESOURCEOUTDIR)/%.o: $(RESOURCEDIR)/% .FORCE
|
||||
@mkdir -p $(dir $@)
|
||||
objcopy -I binary -O $(OBJCOPY_ARCH) -B $(OBJCOPY_TARGET) \
|
||||
--rename-section .data=.rodata,alloc,load,readonly,data,contents \
|
||||
$< $@
|
||||
|
||||
|
||||
|
||||
.PHONY: resources
|
||||
resources: $(RESOURCEOBJECTS)
|
||||
|
||||
.PHONY: clean-resources
|
||||
clean-resources:
|
||||
rm -rf $(RESOURCEOUTDIR)
|
||||
rm -rf $(GENERATED_PATH)
|
||||
|
||||
.PHONY: .FORCE
|
||||
.FORCE:
|
||||
|
||||
|
||||
@@ -75,10 +75,10 @@ Config::Config(const std::map<std::string, std::string> &map)
|
||||
this->handlersConfig.anon_username = optional("anon_username", "anonymouse");
|
||||
this->handlersConfig.wikiname = required("wikiname");
|
||||
this->logfile = required("logfile");
|
||||
this->templatepath = required("templatepath");
|
||||
this->templatepath = optional("templatepath", "");
|
||||
this->urls.linkallcats = required("linkallcats");
|
||||
this->urls.linkallpages = required("linkallpages");
|
||||
this->urls.linkallpagesrendertype = required ("linkallpagesrendertype");
|
||||
this->urls.linkallpagesrendertype = required("linkallpagesrendertype");
|
||||
this->urls.linkcategory = required("linkcategory");
|
||||
this->urls.linkcategoryrendertype = required("linkcategoryrendertype");
|
||||
this->urls.linkdelete = required("linkdelete");
|
||||
|
||||
22
embedded.cpp
Normal file
22
embedded.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <unordered_map>
|
||||
#include <string_view>
|
||||
#include "embedded.h"
|
||||
|
||||
std::unordered_map<std::string_view, std::string_view> text_resources;
|
||||
|
||||
#include "embedded_declarations.inc"
|
||||
|
||||
void utils::embedded_init_text_resources()
|
||||
{
|
||||
#include "init_text_resources.inc"
|
||||
}
|
||||
|
||||
std::string_view utils::embedded_get_text_resource(std::string_view name)
|
||||
{
|
||||
auto it = text_resources.find(name);
|
||||
if(it != text_resources.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
return std::string_view{};
|
||||
}
|
||||
25
embedded.h
Normal file
25
embedded.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef EMBEDDED_H
|
||||
#define EMBEDDED__H
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#define DECLARE_RESOURCE(name) \
|
||||
extern "C" \
|
||||
{ \
|
||||
extern const char _binary_##name##_start[]; \
|
||||
extern const char _binary_##name##_end[]; \
|
||||
}
|
||||
|
||||
#define RESOURCE_START(name) (_binary_##name##_start)
|
||||
#define RESOURCE_END(name) (_binary_##name##_end)
|
||||
#define RESOURCE_SIZE(name) (static_cast<std::size_t>(_binary_##name##_end - _binary_##name##_start))
|
||||
|
||||
#define RESOURCE_STRING_VIEW(name) {std::string_view(RESOURCE_START(name), RESOURCE_SIZE(name))}
|
||||
|
||||
namespace utils
|
||||
{
|
||||
void embedded_init_text_resources();
|
||||
std::string_view embedded_get_text_resource(std::string_view name);
|
||||
}
|
||||
|
||||
#endif
|
||||
11
qswiki.cpp
11
qswiki.cpp
@@ -43,6 +43,7 @@ SOFTWARE.
|
||||
#include "cliconsole.h"
|
||||
#include "cliserver.h"
|
||||
#include "version.h"
|
||||
#include "embedded.h"
|
||||
|
||||
void sigterm_handler([[maybe_unused]] int arg)
|
||||
{
|
||||
@@ -181,7 +182,6 @@ int main(int argc, char **argv)
|
||||
if(!sandbox->enable({
|
||||
config.configVarResolver.getConfig("cache_fs_dir"),
|
||||
config.templatepath,
|
||||
std::filesystem::path(config.logfile).parent_path(),
|
||||
std::filesystem::path(config.connectionstring).parent_path(),
|
||||
}))
|
||||
{
|
||||
@@ -189,6 +189,8 @@ int main(int argc, char **argv)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
utils::embedded_init_text_resources();
|
||||
|
||||
start_background_worker(*database.get(), config);
|
||||
|
||||
CLIServer cliServer{cliHandler};
|
||||
@@ -214,8 +216,11 @@ int main(int argc, char **argv)
|
||||
User::setAnon(anon.value());
|
||||
|
||||
MapCache<TemplatePage> mapCache;
|
||||
Template siteTemplate{config.templateprefix, config.templatepath, config.urls, config.configVarResolver,
|
||||
mapCache};
|
||||
Template siteTemplate{config.templateprefix, config.urls, config.configVarResolver, mapCache};
|
||||
if(!config.templatepath.empty())
|
||||
{
|
||||
siteTemplate.setPath(config.templatepath);
|
||||
}
|
||||
UrlProvider urlProvider{config.urls};
|
||||
|
||||
auto cache = createCache(config.configVarResolver);
|
||||
|
||||
20
resources_gen.sh
Executable file
20
resources_gen.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
set -u
|
||||
GENERATED_EMBEDDED_DECLARATIONS="$1/embedded_declarations.inc"
|
||||
GENERATED_INIT_TEXT_RESOURCES="$1/init_text_resources.inc"
|
||||
|
||||
mkdir -p "$1"
|
||||
rm -f "$GENERATED_EMBEDDED_DECLARATIONS"
|
||||
rm -f "$GENERATED_INIT_TEXT_RESOURCES"
|
||||
|
||||
TEMPLATEPATH="$2"
|
||||
find "$TEMPLATEPATH" -type f | while read line ; do
|
||||
stringvar=$( echo "$line" | sed -e "s;$TEMPLATEPATH/;;g" )
|
||||
name=$(echo "$line" | tr '.-' '_' | tr '/' '_' )
|
||||
|
||||
echo "DECLARE_RESOURCE($name)" >> $GENERATED_EMBEDDED_DECLARATIONS
|
||||
echo "text_resources.insert({\"$stringvar\", RESOURCE_STRING_VIEW($name)});" >> $GENERATED_INIT_TEXT_RESOURCES
|
||||
|
||||
done
|
||||
|
||||
Submodule submodules/cpp-httplib updated: eacc1ca98e...adf58bf474
18
template.cpp
18
template.cpp
@@ -24,11 +24,11 @@ SOFTWARE.
|
||||
#include "urlprovider.h"
|
||||
#include "htmllink.h"
|
||||
#include "logger.h"
|
||||
Template::Template(std::string templateprefix, std::string templatepath, ConfigUrls &configUrls,
|
||||
#include "embedded.h"
|
||||
Template::Template(std::string templateprefix, ConfigUrls &configUrls,
|
||||
ConfigVariableResolver &configVarsResolver, MapCache<TemplatePage> &pageCache)
|
||||
{
|
||||
this->templateprefix = templateprefix;
|
||||
this->templatepath = templatepath;
|
||||
this->configUrls = &configUrls;
|
||||
this->configVarResolver = &configVarsResolver;
|
||||
this->pageCache = &pageCache;
|
||||
@@ -59,9 +59,14 @@ std::string Template::getPartPath(std::string_view partname)
|
||||
|
||||
std::string Template::loadPartContent(std::string_view partname)
|
||||
{
|
||||
std::string partpath = getPartPath(partname);
|
||||
return utils::readCompleteFile(partpath);
|
||||
if(!this->templatepath.empty())
|
||||
{
|
||||
std::string partpath = getPartPath(partname);
|
||||
return utils::readCompleteFile(partpath);
|
||||
}
|
||||
return std::string { utils::embedded_get_text_resource(partname) };
|
||||
}
|
||||
|
||||
std::string Template::loadResolvedPart(std::string_view partname)
|
||||
{
|
||||
return resolveIncludes(loadPartContent(partname));
|
||||
@@ -178,3 +183,8 @@ std::string Template::renderRevisionList(const std::vector<Revision> &revisions,
|
||||
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
void Template::setPath(std::string path)
|
||||
{
|
||||
this->templatepath = path;
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class Template
|
||||
TemplatePage createPage(std::string_view name);
|
||||
|
||||
public:
|
||||
Template(std::string templateprefix, std::string templatepath, ConfigUrls &configUrls,
|
||||
Template(std::string templateprefix, ConfigUrls &configUrls,
|
||||
ConfigVariableResolver &configVarsResolver, MapCache<TemplatePage> &pageCache);
|
||||
|
||||
TemplatePage getPage(const std::string &pagename);
|
||||
@@ -37,6 +37,8 @@ class Template
|
||||
std::string renderSearch(const std::vector<std::string> &results) const;
|
||||
std::string renderSearch(const std::vector<SearchResult> &results) const;
|
||||
std::string renderRevisionList(const std::vector<Revision> &revisions, bool withpage = false) const;
|
||||
|
||||
void setPath(std::string path);
|
||||
};
|
||||
|
||||
#endif // TEMPLATE_H
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
|
||||
Reference in New Issue
Block a user