summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sca-cpp/trunk/modules/http/httpd.hpp16
-rw-r--r--sca-cpp/trunk/modules/server/mod-eval.hpp17
2 files changed, 22 insertions, 11 deletions
diff --git a/sca-cpp/trunk/modules/http/httpd.hpp b/sca-cpp/trunk/modules/http/httpd.hpp
index 05403a5897..486bc7fa82 100644
--- a/sca-cpp/trunk/modules/http/httpd.hpp
+++ b/sca-cpp/trunk/modules/http/httpd.hpp
@@ -77,10 +77,10 @@ template<typename C> C& serverConf(const cmd_parms *cmd, const module* mod) {
/**
* Return the name of a server.
*/
-const string serverName(const server_rec* s) {
+const string serverName(const server_rec* s, const string& def = "localhost") {
ostringstream n;
n << (s->server_scheme != NULL? s->server_scheme : "http") << "://"
- << (s->server_hostname != NULL? s->server_hostname : "localhost") << ":"
+ << (s->server_hostname != NULL? s->server_hostname : def) << ":"
<< (s->port != 0? s->port : 80)
<< (s->path != NULL? string(s->path, s->pathlen) : "");
return str(n);
@@ -89,11 +89,11 @@ const string serverName(const server_rec* s) {
/**
* Determine the name of a server from an HTTP request.
*/
-const string serverName(request_rec* r) {
+const string serverName(request_rec* r, const string& def = "localhost") {
ostringstream n;
const char* hn = ap_get_server_name(r);
n << (r->server->server_scheme != NULL? r->server->server_scheme : "http") << "://"
- << (hn != NULL? hn : (r->server->server_hostname != NULL? r->server->server_hostname : "localhost")) << ":"
+ << (hn != NULL? hn : (r->server->server_hostname != NULL? r->server->server_hostname : def)) << ":"
<< (r->server->port != 0? r->server->port : 80)
<< (r->server->path != NULL? string(r->server->path, r->server->pathlen) : "");
return str(n);
@@ -102,16 +102,16 @@ const string serverName(request_rec* r) {
/**
* Return the host name for a server.
*/
-const string hostName(const server_rec* s) {
- return s->server_hostname != NULL? s->server_hostname : "localhost";
+const string hostName(const server_rec* s, const string& def = "localhost") {
+ return s->server_hostname != NULL? s->server_hostname : def;
}
/**
* Return the host name from an HTTP request.
*/
-const string hostName(request_rec* r) {
+const string hostName(request_rec* r, const string& def = "localhost") {
const char* hn = ap_get_server_name(r);
- return hn != NULL? hn : (r->server->server_hostname != NULL? r->server->server_hostname : "localhost");
+ return hn != NULL? hn : (r->server->server_hostname != NULL? r->server->server_hostname : def);
}
/**
diff --git a/sca-cpp/trunk/modules/server/mod-eval.hpp b/sca-cpp/trunk/modules/server/mod-eval.hpp
index ded496a0bf..829edef387 100644
--- a/sca-cpp/trunk/modules/server/mod-eval.hpp
+++ b/sca-cpp/trunk/modules/server/mod-eval.hpp
@@ -275,11 +275,11 @@ const list<value> refProxies(const list<value>& refs, const string& base, const
#ifdef WANT_THREADS
__thread
#endif
-const request_rec* currentRequest = NULL;
+request_rec* currentRequest = NULL;
class ScopedRequest {
public:
- ScopedRequest(const request_rec* r) {
+ ScopedRequest(request_rec* r) {
currentRequest = r;
}
@@ -290,7 +290,7 @@ public:
/**
* Convert a list of component properties to a list of lambda functions that just return
- * the property value. The user and email properties are configured with the values
+ * the property value. The host, user and email properties are configured with the values
* from the HTTP request, if any.
*/
struct propProxy {
@@ -302,6 +302,15 @@ struct propProxy {
}
};
+struct hostPropProxy {
+ const value v;
+ hostPropProxy(const value& v) : v(v) {
+ }
+ const value operator()(unused const list<value>& params) const {
+ return httpd::hostName(currentRequest, v);
+ }
+};
+
struct emailPropProxy {
const value v;
emailPropProxy(const value& v) : v(v) {
@@ -326,6 +335,8 @@ struct userPropProxy {
};
const value mkpropProxy(const value& prop) {
+ if (scdl::name(prop) == "host")
+ return lambda<value(const list<value>&)>(hostPropProxy(elementValue(prop)));
if (scdl::name(prop) == "email")
return lambda<value(const list<value>&)>(emailPropProxy(elementValue(prop)));
if (scdl::name(prop) == "user")