add HTML_DIRECTORY to Makefile & C++ code

JSON-32
Roker 6 years ago
parent 7bf035f331
commit a859796dd0

@ -1,8 +1,18 @@
BUILD_ON=$(shell uname)
BUILD_FOR=$(BUILD_ON)
#### Configuration Options ####
#------------------------------
# install all stuff into $(PREFIX)/pEp/json-adapter/
PREFIX = /usr/local
HTML_DIRECTORY = $(PREFIX)/share/pEp/json-adapter/html
CXX = c++ -std=c++11 -Wall -O0 -g -fstack-protector-all
# end of configuration options
BUILD_ON=$(shell uname)
BUILD_FOR=$(BUILD_ON)
ifeq ($(BUILD_ON),Darwin)
ifeq ($(BUILD_FOR),Darwin)
@ -22,7 +32,12 @@ endif
all: pep-json-server servertest
pep-json-server: main.o libjson-adapter.a
$(CXX) $(CXXFLAGS) -o $@ $^ ../../pEpEngine/asn.1/libasn1.a $(LDFLAGS)
$(CXX) -o $@ $^ ../../pEpEngine/asn.1/libasn1.a $(LDFLAGS)
pep-json-server-static: main.o libjson-adapter.a
$(CXX) -static -o $@ $^ ../../pEpEngine/asn.1/libasn1.a $(LDFLAGS)
servertest: servertest.o
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
@ -36,9 +51,12 @@ libjson-adapter.a: \
security-token.o \
nfc_sets.o base64.o \
nulllogger.o \
prefix-config.o \
daemonize.o
ar rcs $@ $^
prefix-config.cc: Makefile
echo '// This file is generated by make. Edit the Makefile, not this file!\n#include "prefix-config.hh" \nconst char* const html_directory = "'$(HTML_DIRECTORY)'";\n' > $@
%.o : %.cc %.hh Makefile
$(CXX) $(CXXFLAGS) -c $<
@ -46,6 +64,7 @@ libjson-adapter.a: \
clean:
rm -vf pep-json-server servertest
rm -vf *.o
rm -vf prefix-config.cc
rm -vf json_spirit/*.o
rm -vf *.a

@ -21,6 +21,7 @@
#include "security-token.hh"
#include "pep-utils.hh"
#include "gpg_environment.hh"
#include "prefix-config.hh"
#include <pEp/message_api.h>
#include <pEp/blacklist.h>
@ -47,6 +48,8 @@ In<Context*, false>::In(const js::Value&, Context* ctx)
}
namespace fs = boost::filesystem;
namespace {
using namespace pEp::utility;
@ -281,7 +284,7 @@ void sendReplyString(evhttp_request* req, const char* contentType, const std::st
}
void sendFile( evhttp_request* req, const std::string& mimeType, const std::string& fileName)
void sendFile( evhttp_request* req, const std::string& mimeType, const fs::path& fileName)
{
auto* outBuf = evhttp_request_get_output_buffer(req);
if (!outBuf)
@ -303,10 +306,12 @@ void sendFile( evhttp_request* req, const std::string& mimeType, const std::stri
}
static const boost::filesystem::path path_to_html = fs::path(html_directory);
struct FileRequest
{
std::string mimeType;
std::string fileName;
fs::path fileName;
};
// catch-all callback
@ -314,10 +319,10 @@ void OnOtherRequest(evhttp_request* req, void*)
{
static const std::map<std::string, FileRequest > files =
{
{ "/" , {"text/html" , "../html/index.html" } },
{ "/jquery.js" , {"text/javascript", "../html/jquery-2.2.0.min.js" } },
{ "/interactive.js" , {"text/javascript", "../html/interactive.js" } },
{ "/favicon.ico" , {"image/vnd.microsoft.icon", "../html/json-test.ico"} },
{ "/" , {"text/html" , path_to_html / "index.html" } },
{ "/jquery.js" , {"text/javascript", path_to_html / "jquery-2.2.0.min.js" } },
{ "/interactive.js" , {"text/javascript", path_to_html / "interactive.js" } },
{ "/favicon.ico" , {"image/vnd.microsoft.icon", path_to_html / "json-test.ico"} },
};
const evhttp_uri* uri = evhttp_request_get_evhttp_uri(req);

@ -0,0 +1,2 @@
// variable's value is defined in the Makefile
extern const char* const html_directory;
Loading…
Cancel
Save