Browse Source

...

pull/1/head
Volker Birk 2 years ago
parent
commit
59d7baff52
3 changed files with 19 additions and 7 deletions
  1. +2
    -3
      Makefile
  2. +1
    -0
      test_webserver.cc
  3. +16
    -4
      webserver.hh

+ 2
- 3
Makefile View File

@ -12,8 +12,7 @@ CC?=cc
CXX?=c++
CFLAGS+=-std=c11
CXXFLAGS+=-I$(BOOST_INCLUDE) -std=c++11
LDFLAGS+=-L$(BOOST_LIB) -lboost_regex-mt -L$(CRYPTOPP_LIB) -lcryptopp -lobjc -lssl -lcrypto -framework Foundation
LDFLAGS+=-L$(DOWNLOADCLIENT) -ldownloadclient
LDFLAGS+=-L$(BOOST_LIB)
ifdef NDEBUG
CFLAGS+=-O3 -DNDEBUG
@ -53,7 +52,7 @@ $(TARGET): $(ALL_OBJECTS)
$(CXX) $(CXXFLAGS) -c -o $@ $^
test_%: test_%.o $(TARGET)
$(CXX) $(CXXFLAGS) $(TARGET) -o $@ $<
$(CXX) $(LDFLAGS) $(TARGET) -o $@ $<
test: $(TESTS)
for i in $(TESTS) ; do ./$$i ; done


+ 1
- 0
test_webserver.cc View File

@ -1,4 +1,5 @@
#include <iostream>
#include "webserver.hh"
int main()
{


+ 16
- 4
webserver.hh View File

@ -1,13 +1,24 @@
#pragma once
#include <string>
#include <vector>
#include <boost/asio/ip/tcp.hpp>
#include <boost/regex.hpp>
namespace net = boost::asio;
using namespace std;
using tcp = boost::asio::ip::tcp;
namespace pEp {
class Webserver {
net::io_context _ioc;
tcp::acceptor _acceptor;
std::string _doc_root;
public:
typedef boost::regex url_t;
typedef std::function< void(boost::cmatch) > handler_t;
private:
net::io_context _ioc;
tcp::acceptor _acceptor;
std::string _doc_root;
std::vector< std::pair< url_t, handler_t > > _urls;
public:
Webserver(net::ip::address addr, unsigned short port, std::string doc_root);
@ -15,6 +26,7 @@ namespace pEp {
Webserver& operator=(const Webserver&) = delete;
~Webserver() { }
void add_url_handler(url_t url, handler_t handler);
void run();
protected:


Loading…
Cancel
Save