Browse Source

make ev_server the real server class.

new_session_management
Roker 2 years ago
parent
commit
fe5f5842ce
3 changed files with 20 additions and 26 deletions
  1. +12
    -0
      server/ev_server.cc
  2. +3
    -1
      server/ev_server.hh
  3. +5
    -25
      server/json-adapter.cc

+ 12
- 0
server/ev_server.cc View File

@ -161,6 +161,18 @@ const FunctionMap functions = {
} // end of anonymous namespace
ev_server::ev_server(const std::string& address, unsigned short start_port, unsigned short end_port, bool deliver_html, const std::string& base_url)
: pEp::Webserver(pEp::net::ip::address::from_string(address), start_port, end_port)
{
this->add_url_handler(base_url + "callFunction", ev_server::OnApiRequest);
if(deliver_html)
{
this->add_url_handler("/pEp_functions.js", ev_server::OnGetFunctions);
this->add_generic_url_handler(ev_server::OnOtherRequest);
}
}
pEp::Webserver::response ev_server::sendReplyString(const pEp::Webserver::request& req, const char* contentType, std::string&& outputText)
{
Log() << Logger::Debug << "sendReplyString(): "


+ 3
- 1
server/ev_server.hh View File

@ -10,9 +10,11 @@
class Logger;
class ev_server
class ev_server : public pEp::Webserver
{
public:
ev_server(const std::string& address, unsigned short start_port, unsigned short end_port, bool deliver_html, const std::string& base_url);
static
pEp::Webserver::response sendReplyString(const pEp::Webserver::request& req, const char* contentType, std::string&& outputText);


+ 5
- 25
server/json-adapter.cc View File

@ -42,11 +42,7 @@ namespace {
using namespace pEp::utility;
std::string BaseUrl = "/ja/0.1/";
const std::string CreateSessionUrl = BaseUrl + "createSession";
const std::string GetAllSessionsUrl = BaseUrl + "getAllSessions";
const std::string ApiRequestUrl = BaseUrl + "callFunction";
const std::string BaseUrl = "/ja/0.1/";
const uint64_t Guard_0 = 123456789;
const uint64_t Guard_1 = 987654321;
@ -74,14 +70,10 @@ JsonAdapter* JsonAdapter::singleton = nullptr;
struct JsonAdapter::Internal
{
std::unique_ptr<SessionRegistry> session_registry{};
std::string address;
std::string token;
std::map<std::thread::id, EventListenerValue> eventListener;
Logger Log;
unsigned start_port = 0;
unsigned end_port = 0;
unsigned port = 0;
std::unique_ptr<pEp::Webserver> webserver;
inject_sync_event_t inject_sync_event = nullptr;
@ -100,6 +92,7 @@ struct JsonAdapter::Internal
~Internal()
{
Log << Logger::Debug << "~JAI";
}
void makeAndDeliverRequest(const char* function_name, const js::Array& params)
@ -214,24 +207,11 @@ void JsonAdapter::prepare_run(const std::string& address, unsigned start_port, u
check_guard();
// delayed after constructor, so virtual functions are working:
i->session_registry.reset(new SessionRegistry(this->getMessageToSend(), this->getInjectSyncEvent()));
i->address = address;
i->start_port = start_port;
i->end_port = end_port;
// pEp::Webserver does not support port probing, yet.
i->webserver = std::make_unique<pEp::Webserver>(pEp::net::ip::address::from_string(address), start_port, "");
i->webserver->add_url_handler(ApiRequestUrl, ev_server::OnApiRequest);
if(i->deliver_html)
{
i->webserver->add_url_handler("/pEp_functions.js", ev_server::OnGetFunctions);
i->webserver->add_generic_url_handler(ev_server::OnOtherRequest);
}
i->port = i->start_port;
i->token = create_security_token(i->address, i->port, BaseUrl);
i->webserver = std::make_unique<ev_server>(address, start_port, end_port, i->deliver_html, BaseUrl);
i->token = create_security_token(address, i->webserver->port(), BaseUrl);
Log() << "Bound to port " << i->port << ", sec_token=\"" << i->token << "\".";
Log() << "Bound to port " << i->webserver->port() << ", sec_token=\"" << i->token << "\".";
}


Loading…
Cancel
Save