merge "default" into JSON-28

JSON-28
Roker 6 years ago
commit 538211a141

@ -1,28 +1,47 @@
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
#order does matter, hence I have to split it for static builds:
LIBS1 = -levent -lpEpEngine -lasn1 -luuid -lgpgme -letpan
LIBS2 = -lpthread -lz -ldl
BUILD_ON=$(shell uname)
BUILD_FOR=$(BUILD_ON)
ifeq ($(BUILD_ON),Darwin)
ifeq ($(BUILD_FOR),Darwin)
CXXFLAGS = -I/opt/local/include -I$(HOME)/include -Ijson_spirit
LDFLAGS = -L/opt/local/lib -L$(HOME)/lib -lpthread -levent -lpEpEngine -luuid -lgpgme -letpan -lboost_system-mt -lboost_filesystem-mt -lboost_program_options-mt -lboost_thread-mt
LDFLAGS = -L/opt/local/lib -L$(HOME)/lib $(LIBS1) -lboost_system-mt -lboost_filesystem-mt -lboost_program_options-mt -lboost_thread-mt $(LIBS2)
endif
else
CXXFLAGS = -I$(HOME)/include -I$(HOME)/local/include/ -Ijson_spirit
LDFLAGS = -L$(HOME)/lib -L$(HOME)/local/lib -lpthread -levent -lpEpEngine -luuid -lgpgme-pthread -letpan -lboost_system -lboost_filesystem -lboost_program_options -lboost_thread
LDFLAGS = -L$(HOME)/lib -L$(HOME)/local/lib $(LIBS1) -lboost_system -lboost_filesystem -lboost_program_options -lboost_thread $(LIBS2)
endif
.PHONY: all clean
.PHONY: all clean install
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,16 +55,24 @@ 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 $<
install:
mkdir -v -p $(HTML_DIRECTORY)
cp -v ../html/* $(HTML_DIRECTORY)
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