You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2010/07/12 17:19:12 UTC
svn commit: r963318 - in /tuscany/sca-cpp/trunk/modules: http/httpd.hpp
server/mod-eval.hpp
Author: jsdelfino
Date: Mon Jul 12 15:19:11 2010
New Revision: 963318
URL: http://svn.apache.org/viewvc?rev=963318&view=rev
Log:
Add a host component property reporting the current virtual host name.
Modified:
tuscany/sca-cpp/trunk/modules/http/httpd.hpp
tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp
Modified: tuscany/sca-cpp/trunk/modules/http/httpd.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/httpd.hpp?rev=963318&r1=963317&r2=963318&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/httpd.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/http/httpd.hpp Mon Jul 12 15:19:11 2010
@@ -77,10 +77,10 @@ template<typename C> C& serverConf(const
/**
* 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
/**
* 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);
}
/**
Modified: tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp?rev=963318&r1=963317&r2=963318&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp Mon Jul 12 15:19:11 2010
@@ -275,11 +275,11 @@ const list<value> refProxies(const list<
#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")