From 03905bcf1bcfd9e7932fcac4283c5817058a25ce Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 14 Nov 2015 16:29:22 +0200 Subject: Invent root path web interface configuration option --- web/apache/service | 2 +- web/apache/service.cxx | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'web/apache') diff --git a/web/apache/service b/web/apache/service index 7ac01a2..33d5a0a 100644 --- a/web/apache/service +++ b/web/apache/service @@ -112,7 +112,7 @@ namespace web init_worker (log& l) noexcept; static const char* - add_option (cmd_parms *parms, void *mconfig, const char *value) noexcept; + add_option (cmd_parms* parms, void* mconfig, const char* args) noexcept; template int handle (request& r, log& l) noexcept; diff --git a/web/apache/service.cxx b/web/apache/service.cxx index 782e09b..42a31bd 100644 --- a/web/apache/service.cxx +++ b/web/apache/service.cxx @@ -10,8 +10,10 @@ #include #include -#include // unique_ptr +#include // unique_ptr #include +#include +#include // strlen() #include using namespace std; @@ -47,7 +49,10 @@ namespace web reinterpret_cast (add_option), this, RSRC_CONF, - TAKE1, + // Move away from TAKE1 to be able to handle empty string and + // no-value. + // + RAW_ARGS, nullptr }; } @@ -58,19 +63,31 @@ namespace web } const char* service:: - add_option (cmd_parms* parms, void*, const char* value) noexcept + add_option (cmd_parms* parms, void*, const char* args) noexcept { service& srv (*reinterpret_cast (parms->cmd->cmd_data)); string name (parms->cmd->name + srv.name_.length () + 1); + optional value; + + // 'args' is an optionally double-quoted string. Use double quotes to + // distinguish empty string from no-value case. + // + assert (args != nullptr); + if (auto l = strlen (args)) + value = l >= 2 && args[0] == '"' && args[l - 1] == '"' + ? string (args + 1, l - 2) + : args; for (auto& v: srv.options_) + { if (v.name == name) { v.value = value; return 0; } + } - srv.options_.emplace_back (name, string (value)); + srv.options_.emplace_back (name, value); return 0; } -- cgit v1.1