tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsdelf...@apache.org
Subject svn commit: r1419987 [2/5] - in /tuscany/sca-cpp/trunk/modules: http/ java/ oauth/ opencl/ python/ server/ server/htdocs/test/ wsgi/
Date Tue, 11 Dec 2012 04:03:35 GMT
Modified: tuscany/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp Tue Dec 11 04:03:29 2012
@@ -53,17 +53,17 @@ namespace modssltunnel {
  */
 class ServerConf {
 public:
-    ServerConf(apr_pool_t* p, server_rec* s) : p(p), server(s) {
+    ServerConf(apr_pool_t* const p, server_rec* const s) : p(p), server(s) {
     }
 
     const gc_pool p;
-    server_rec* server;
-    string pass;
-    string host;
-    string path;
-    string ca;
-    string cert;
-    string key;
+    server_rec* const server;
+    gc_mutable_ref<string> pass;
+    gc_mutable_ref<string> host;
+    gc_mutable_ref<string> path;
+    gc_mutable_ref<string> ca;
+    gc_mutable_ref<string> cert;
+    gc_mutable_ref<string> key;
 };
 
 extern "C" {
@@ -74,7 +74,7 @@ extern module AP_DECLARE_DATA core_modul
  * Process the module configuration.
  */
 int M_SSLTUNNEL;
-int postConfigMerge(ServerConf& mainsc, apr_pool_t* p, server_rec* s) {
+int postConfigMerge(const ServerConf& mainsc, apr_pool_t* const p, server_rec* const s) {
     if (s == NULL)
         return OK;
     ServerConf& sc = httpd::serverConf<ServerConf>(s, &mod_tuscany_ssltunnel);
@@ -102,10 +102,10 @@ int postConfigMerge(ServerConf& mainsc, 
     return postConfigMerge(mainsc, p, s->next);
 }
 
-int postConfig(apr_pool_t* p, unused apr_pool_t* plog, unused apr_pool_t* ptemp, server_rec* s) {
-    gc_scoped_pool pool(p);
+int postConfig(apr_pool_t* const p, unused apr_pool_t* const plog, unused apr_pool_t* const ptemp, server_rec* const s) {
+    const gc_scoped_pool sp(p);
 
-    ServerConf& sc = httpd::serverConf<ServerConf>(s, &mod_tuscany_ssltunnel);
+    const ServerConf& sc = httpd::serverConf<ServerConf>(s, &mod_tuscany_ssltunnel);
     debug(httpd::serverName(s), "modssltunnel::postConfig::serverName");
 
     // Register the SSLTUNNEL method
@@ -118,7 +118,7 @@ int postConfig(apr_pool_t* p, unused apr
 /**
  * Close a connection.
  */
-const int close(conn_rec* conn, apr_socket_t* csock) {
+const int close(conn_rec* const conn, apr_socket_t* const csock) {
     debug("modssltunnel::close");
     apr_socket_close(csock);
     conn->aborted = 1;
@@ -128,7 +128,7 @@ const int close(conn_rec* conn, apr_sock
 /**
  * Abort a connection.
  */
-const int abort(conn_rec* conn, apr_socket_t* csock, const string& reason) {
+const int abort(conn_rec* const conn, apr_socket_t* const csock, const string& reason) {
     debug("modssltunnel::abort");
     apr_socket_close(csock);
     conn->aborted = 1;
@@ -138,21 +138,21 @@ const int abort(conn_rec* conn, apr_sock
 /**
  * Tunnel traffic from a client connection to a target URL.
  */
-int tunnel(conn_rec* conn, const string& ca, const string& cert, const string& key, const string& url, const string& preamble, const gc_pool& p, unused ap_filter_t* ifilter, ap_filter_t* ofilter) {
+int tunnel(conn_rec* const conn, const string& ca, const string& cert, const string& key, const string& url, const string& preamble, const gc_pool& p, unused ap_filter_t* const ifilter, ap_filter_t* const ofilter) {
 
     // Create input/output bucket brigades
-    apr_bucket_brigade* ib = apr_brigade_create(pool(p), conn->bucket_alloc);
-    apr_bucket_brigade* ob = apr_brigade_create(pool(p), conn->bucket_alloc);
+    apr_bucket_brigade* const ib = apr_brigade_create(pool(p), conn->bucket_alloc);
+    apr_bucket_brigade* const ob = apr_brigade_create(pool(p), conn->bucket_alloc);
 
     // Get client connection socket
-    apr_socket_t* csock = (apr_socket_t*)ap_get_module_config(conn->conn_config, &core_module);
+    apr_socket_t* const csock = (apr_socket_t*)ap_get_module_config(conn->conn_config, &core_module);
 
     // Open connection to target
-    http::CURLSession cs(ca, cert, key, "", 0);
+    const http::CURLSession cs(ca, cert, key, emptyString, 0);
     const failable<bool> crc = http::connect(url, cs);
     if (!hasContent(crc))
         return abort(conn, csock, reason(crc));
-    apr_socket_t* tsock = http::sock(cs);
+    apr_socket_t* const tsock = http::sock(cs);
 
     // Send preamble
     if (length(preamble) != 0) {
@@ -164,7 +164,7 @@ int tunnel(conn_rec* conn, const string&
 
     // Create a pollset for the client and target sockets
     apr_pollset_t* pollset;
-    apr_status_t cprc = apr_pollset_create(&pollset, 2, pool(p), 0);
+    const apr_status_t cprc = apr_pollset_create(&pollset, 2, pool(p), 0);
     if (cprc != APR_SUCCESS)
         return abort(conn, csock, http::apreason(cprc));
     const apr_pollfd_t* cpollfd = http::pollfd(csock, APR_POLLIN, p);
@@ -241,7 +241,7 @@ int tunnel(conn_rec* conn, const string&
 
         // Poll the client and target sockets
         debug("modssltunnel::tunnel::poll");
-        apr_status_t pollrc = apr_pollset_poll(pollset, -1, &pollcount, &pollfds);
+        const apr_status_t pollrc = apr_pollset_poll(pollset, -1, &pollcount, &pollfds);
         if (pollrc != APR_SUCCESS)
             return abort(conn, csock, "Couldn't poll sockets");
         debug(pollcount, "modssltunnel::tunnel::pollfds");
@@ -254,7 +254,7 @@ int tunnel(conn_rec* conn, const string&
 /**
  * Return the first connection filter in a list of filters.
  */
-ap_filter_t* connectionFilter(ap_filter_t* f) {
+ap_filter_t* const connectionFilter(ap_filter_t* const f) {
     if (f == NULL)
         return f;
     if (f->frec->ftype < AP_FTYPE_CONNECTION)
@@ -265,14 +265,14 @@ ap_filter_t* connectionFilter(ap_filter_
 /**
  * Process a client connection and relay it to a tunnel.
  */
-int processConnection(conn_rec *conn) {
+int processConnection(conn_rec* conn) {
     // Only allow configured virtual hosts
     if (!conn->base_server->is_virtual)
         return DECLINED;
     if (ap_get_module_config(conn->base_server->module_config, &mod_tuscany_ssltunnel) == NULL)
         return DECLINED;
 
-    gc_scoped_pool pool(conn->pool);
+    const gc_scoped_pool sp(conn->pool);
 
     // Get the server configuration
     const ServerConf& sc = httpd::serverConf<ServerConf>(conn->base_server, &mod_tuscany_ssltunnel);
@@ -297,41 +297,41 @@ int handler(request_rec* r) {
     if (strcmp(r->server->server_scheme, "https"))
         return DECLINED;
 
-    gc_scoped_pool pool(r->pool);
+    const gc_scoped_pool sp(r->pool);
 
     // Build the target URL
     debug(r->uri, "modssltunnel::handler::uri");
     const list<value> path(pathValues(r->uri));
-    const string url = string(cadr(path)) + ":" + caddr(path);
+    const string url = string(cadr(path)) + ":" + (string)caddr(path);
     debug(url, "modssltunnel::handler::target");
 
     // Run the tunnel
-    return tunnel(r->connection, "", "", "", url, "", gc_pool(r->pool), connectionFilter(r->proto_input_filters), connectionFilter(r->proto_output_filters));
+    return tunnel(r->connection, emptyString, emptyString, emptyString, url, emptyString, gc_pool(r->pool), connectionFilter(r->proto_input_filters), connectionFilter(r->proto_output_filters));
 }
 
 /**
  * Configuration commands.
  */
-const char* confTunnelPass(cmd_parms *cmd, unused void *c, const char *arg) {
-    gc_scoped_pool pool(cmd->pool);
+char* confTunnelPass(cmd_parms *cmd, unused void *c, const char *arg) {
+    const gc_scoped_pool sp(cmd->pool);
     ServerConf& sc = httpd::serverConf<ServerConf>(cmd, &mod_tuscany_ssltunnel);
     sc.pass = arg;
     return NULL;
 }
-const char* confCAFile(cmd_parms *cmd, unused void *c, const char *arg) {
-    gc_scoped_pool pool(cmd->pool);
+char* confCAFile(cmd_parms *cmd, unused void *c, const char *arg) {
+    const gc_scoped_pool sp(cmd->pool);
     ServerConf& sc = httpd::serverConf<ServerConf>(cmd, &mod_tuscany_ssltunnel);
     sc.ca = arg;
     return NULL;
 }
-const char* confCertFile(cmd_parms *cmd, unused void *c, const char *arg) {
-    gc_scoped_pool pool(cmd->pool);
+char* confCertFile(cmd_parms *cmd, unused void *c, const char *arg) {
+    const gc_scoped_pool sp(cmd->pool);
     ServerConf& sc = httpd::serverConf<ServerConf>(cmd, &mod_tuscany_ssltunnel);
     sc.cert = arg;
     return NULL;
 }
-const char* confCertKeyFile(cmd_parms *cmd, unused void *c, const char *arg) {
-    gc_scoped_pool pool(cmd->pool);
+char* confCertKeyFile(cmd_parms *cmd, unused void *c, const char *arg) {
+    const gc_scoped_pool sp(cmd->pool);
     ServerConf& sc = httpd::serverConf<ServerConf>(cmd, &mod_tuscany_ssltunnel);
     sc.key = arg;
     return NULL;

Modified: tuscany/sca-cpp/trunk/modules/http/openauth.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/openauth.hpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/openauth.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/http/openauth.hpp Tue Dec 11 04:03:29 2012
@@ -42,11 +42,12 @@ namespace openauth {
 /**
  * Return the session id from a request.
  */
-const char* cookieName(const char* cs) {
+const char* const cookieName(const char* const cs) {
     if (*cs != ' ')
         return cs;
     return cookieName(cs + 1);
 }
+
 const maybe<string> sessionID(const list<string>& c, const string& key) {
     if (isNil(c))
         return maybe<string>();
@@ -62,7 +63,7 @@ const maybe<string> sessionID(const list
     return sessionID(cdr(c), key);
 }
 
-const maybe<string> sessionID(const request_rec* r, const string& key) {
+const maybe<string> sessionID(const request_rec* const r, const string& key) {
     const string c = httpd::cookie(r);
     debug(c, "openauth::sessionid::cookies");
     if (length(c) == 0)
@@ -74,10 +75,15 @@ const maybe<string> sessionID(const requ
  * Convert a session id to a cookie string.
  */
 const string cookie(const string& key, const string& sid, const string& domain) {
+    if (length(sid) == 0) {
+        const string c = key + string("=") + "; max-age=0; domain=." + httpd::realm(domain) + "; path=/; secure; httponly";
+        debug(c, "openauth::cookie");
+        return c;
+    }
     const time_t t = time(NULL) + 86400;
     char exp[32];
     strftime(exp, 32, "%a, %d-%b-%Y %H:%M:%S GMT", gmtime(&t));
-    const string c = key + string("=") + sid + "; expires=" + string(exp) + "; domain=." + httpd::realm(domain) + "; path=/";
+    const string c = key + string("=") + sid + "; expires=" + string(exp) + "; domain=." + httpd::realm(domain) + "; path=/; secure; httponly";
     debug(c, "openauth::cookie");
     return c;
 }
@@ -85,7 +91,7 @@ const string cookie(const string& key, c
 /**
  * Redirect to the configured login page.
  */
-const failable<int> login(const string& page, const value& ref, const value& attempt, request_rec* r) {
+const failable<int> login(const string& page, const value& ref, const value& attempt, request_rec* const r) {
     const list<list<value> > rarg = ref == string("/")? list<list<value> >() : mklist<list<value> >(mklist<value>("openauth_referrer", httpd::escape(httpd::url(isNil(ref)? r->uri : ref, r))));
     const list<list<value> > aarg = isNil(attempt)? list<list<value> >() : mklist<list<value> >(mklist<value>("openauth_attempt", attempt));
     const list<list<value> > largs = append<list<value> >(rarg, aarg);
@@ -94,6 +100,31 @@ const failable<int> login(const string& 
     return httpd::externalRedirect(loc, r);
 }
 
+/**
+ * Report a request auth status.
+ */
+const int reportStatus(const failable<int>& authrc, const string& page, const value& attempt, request_rec* const r) {
+    debug(authrc, "openauth::reportStatus::authrc");
+
+    // Redirect to the login page if not authorized
+    if (!hasContent(authrc) && rcode(authrc) == HTTP_UNAUTHORIZED) {
+
+        // Clear any auth cookies
+        if(hasContent(sessionID(r, "TuscanyOpenAuth")))
+            apr_table_set(r->err_headers_out, "Set-Cookie", c_str(cookie("TuscanyOpenAuth", emptyString, httpd::hostName(r))));
+        if(hasContent(sessionID(r, "TuscanyOpenIDAuth")))
+            apr_table_set(r->err_headers_out, "Set-Cookie", c_str(cookie("TuscanyOpenIDAuth", emptyString, httpd::hostName(r))));
+        if(hasContent(sessionID(r, "TuscanyOAuth1")))
+            apr_table_set(r->err_headers_out, "Set-Cookie", c_str(cookie("TuscanyOAuth1", emptyString, httpd::hostName(r))));
+        if(hasContent(sessionID(r, "TuscanyOAuth2")))
+            apr_table_set(r->err_headers_out, "Set-Cookie", c_str(cookie("TuscanyOAuth2", emptyString, httpd::hostName(r))));
+
+        return httpd::reportStatus(login(page, string("/"), attempt, r));
+    }
+
+    return httpd::reportStatus(authrc);
+}
+
 }
 }
 

Modified: tuscany/sca-cpp/trunk/modules/java/Makefile.am
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/java/Makefile.am?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/java/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/modules/java/Makefile.am Tue Dec 11 04:03:29 2012
@@ -36,7 +36,7 @@ EXTRA_DIST = domain-test.composite
 
 mod_LTLIBRARIES = libmod_tuscany_java.la
 libmod_tuscany_java_la_SOURCES = mod-java.cpp
-libmod_tuscany_java_la_LDFLAGS = -lxml2 -lcurl -lmozjs ${JAVA_LDFLAGS}
+libmod_tuscany_java_la_LDFLAGS = -lxml2 -lcurl -ljansson ${JAVA_LDFLAGS}
 noinst_DATA = libmod_tuscany_java${libsuffix}
 libmod_tuscany_java${libsuffix}:
 	ln -s .libs/libmod_tuscany_java${libsuffix}
@@ -55,12 +55,13 @@ jardir = ${prefix}/modules/java
 jarfile = libmod-tuscany-java-${PACKAGE_VERSION}.jar
 jar_DATA = ${jarfile}
 ${jarfile}: ${dist_mod_JAVA}
+	${JAVAC} ${dist_mod_JAVA}
 	${JAR} cf $@ org/apache/tuscany/*.class
 
 CLEANFILES = *.stamp ${jarfile} org/apache/tuscany/*.class	test/*.class
 
 client_test_SOURCES = client-test.cpp
-client_test_LDFLAGS = -lxml2 -lcurl -lmozjs
+client_test_LDFLAGS = -lxml2 -lcurl -ljansson
 
 dist_noinst_SCRIPTS = server-test wiring-test
 noinst_PROGRAMS = jni-test java-test client-test

Modified: tuscany/sca-cpp/trunk/modules/java/driver.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/java/driver.hpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/java/driver.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/java/driver.hpp Tue Dec 11 04:03:29 2012
@@ -37,7 +37,7 @@ namespace java {
 
 const value evalDriverLoop(const JavaRuntime& jr, const JavaClass jc, istream& in, ostream& out) {
     scheme::promptForInput(scheme::evalInputPrompt, out);
-    value input = scheme::readValue(in);
+    const value input = content(scheme::readValue(in));
     if (isNil(input))
         return input;
     const failable<value> output = evalClass(jr, input, jc);
@@ -46,7 +46,7 @@ const value evalDriverLoop(const JavaRun
     return evalDriverLoop(jr, jc, in, out);
 }
 
-const bool evalDriverRun(const char* name, istream& in, ostream& out) {
+const bool evalDriverRun(const char* const name, istream& in, ostream& out) {
     scheme::setupDisplay(out);
     JavaRuntime javaRuntime;
     const failable<JavaClass> jc = readClass(javaRuntime, ".", name);

Modified: tuscany/sca-cpp/trunk/modules/java/eval.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/java/eval.hpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/java/eval.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/java/eval.hpp Tue Dec 11 04:03:29 2012
@@ -50,12 +50,12 @@ jobject JNICALL nativeUUID(JNIEnv *env);
 
 class JavaRuntime {
 public:
-    JavaRuntime() {
+    JavaRuntime() : h(*(new (gc_new<handles>()) handles())) {
         debug("java::javaruntime");
 
         // Get existing JVM
         jsize nvms = 0;
-        JNI_GetCreatedJavaVMs(&jvm, 1, &nvms);
+        JNI_GetCreatedJavaVMs(&h.jvm, 1, &nvms);
         if (nvms == 0) {
 
             // Create a new JVM
@@ -67,7 +67,7 @@ public:
             args.nOptions = 0;
 
             // Configure classpath
-            const char* envcp = getenv("CLASSPATH");
+            const char* const envcp = getenv("CLASSPATH");
             const string cp = string("-Djava.class.path=") + (envcp == NULL? "." : envcp);
             options[args.nOptions].optionString = const_cast<char*>(c_str(cp));
             options[args.nOptions++].extraInfo = NULL;
@@ -78,12 +78,12 @@ public:
 #endif
 
             // Configure Java debugging
-            const char* jpdaopts = getenv("JPDA_OPTS");
+            const char* const jpdaopts = getenv("JPDA_OPTS");
             if (jpdaopts != NULL) {
                 options[args.nOptions].optionString = const_cast<char*>(jpdaopts);
                 options[args.nOptions++].extraInfo = NULL;
             } else {
-                const char* jpdaaddr = getenv("JPDA_ADDRESS");
+                const char* const jpdaaddr = getenv("JPDA_ADDRESS");
                 if (jpdaaddr != NULL) {
                     const string jpda = string("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=") + jpdaaddr;
                     options[args.nOptions].optionString = const_cast<char*>(c_str(jpda));
@@ -93,114 +93,131 @@ public:
 
             // Create the JVM
 #ifdef JAVA_HARMONY_VM
-            JNI_CreateJavaVM(&jvm, &env, &args);
+            JNI_CreateJavaVM(&h.jvm, &h.env, &args);
 #else
-            JNI_CreateJavaVM(&jvm, (void**)&env, &args);
+            JNI_CreateJavaVM(&h.jvm, (void**)&h.env, &args);
 #endif
 
         } else {
 
             // Just point to existing JVM
-            jvm->GetEnv((void**)&env, JNI_VERSION);
+            h.jvm->GetEnv((void**)&h.env, JNI_VERSION);
         }
 
         // Lookup System classes and methods
-        classClass = env->FindClass("java/lang/Class");
-        methodClass = env->FindClass("java/lang/reflect/Method");
-        objectClass = env->FindClass("java/lang/Object");
-        doubleClass = env->FindClass("java/lang/Double");
-        booleanClass = env->FindClass("java/lang/Boolean");
-        stringClass = env->FindClass("java/lang/String");
-        objectArrayClass = env->FindClass("[Ljava/lang/Object;");
-        iterableClass = env->FindClass("java/lang/Iterable");
-        classForName = env->GetStaticMethodID(classClass, "forName", "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;");
-        doubleValueOf = env->GetStaticMethodID(doubleClass, "valueOf", "(D)Ljava/lang/Double;");
-        doubleValue = env->GetMethodID(doubleClass, "doubleValue", "()D");
-        booleanValueOf = env->GetStaticMethodID(booleanClass, "valueOf", "(Z)Ljava/lang/Boolean;");
-        booleanValue = env->GetMethodID(booleanClass, "booleanValue", "()Z");
-        declaredMethods = env->GetMethodID(classClass, "getDeclaredMethods", "()[Ljava/lang/reflect/Method;");
-        methodName = env->GetMethodID(methodClass, "getName", "()Ljava/lang/String;");
-        parameterTypes = env->GetMethodID(methodClass, "getParameterTypes", "()[Ljava/lang/Class;");
+        h.classClass = h.env->FindClass("java/lang/Class");
+        h.methodClass = h.env->FindClass("java/lang/reflect/Method");
+        h.objectClass = h.env->FindClass("java/lang/Object");
+        h.doubleClass = h.env->FindClass("java/lang/Double");
+        h.booleanClass = h.env->FindClass("java/lang/Boolean");
+        h.stringClass = h.env->FindClass("java/lang/String");
+        h.objectArrayClass = h.env->FindClass("[Ljava/lang/Object;");
+        h.iterableClass = h.env->FindClass("java/lang/Iterable");
+        h.classForName = h.env->GetStaticMethodID(h.classClass, "forName", "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;");
+        h.doubleValueOf = h.env->GetStaticMethodID(h.doubleClass, "valueOf", "(D)Ljava/lang/Double;");
+        h.doubleValue = h.env->GetMethodID(h.doubleClass, "doubleValue", "()D");
+        h.booleanValueOf = h.env->GetStaticMethodID(h.booleanClass, "valueOf", "(Z)Ljava/lang/Boolean;");
+        h.booleanValue = h.env->GetMethodID(h.booleanClass, "booleanValue", "()Z");
+        h.declaredMethods = h.env->GetMethodID(h.classClass, "getDeclaredMethods", "()[Ljava/lang/reflect/Method;");
+        h.methodName = h.env->GetMethodID(h.methodClass, "getName", "()Ljava/lang/String;");
+        h.parameterTypes = h.env->GetMethodID(h.methodClass, "getParameterTypes", "()[Ljava/lang/Class;");
 
         // Lookup Tuscany classes and methods
-        loaderClass = env->FindClass("org/apache/tuscany/ClassLoader");
-        loaderValueOf = env->GetStaticMethodID(loaderClass, "valueOf", "(Ljava/lang/String;)Ljava/lang/ClassLoader;");
-        loaderForName = env->GetStaticMethodID(loaderClass, "forName", "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;");
-        invokerClass = env->FindClass("org/apache/tuscany/InvocationHandler");
-        invokerValueOf = env->GetStaticMethodID(invokerClass, "valueOf", "(Ljava/lang/Class;J)Ljava/lang/Object;");
-        invokerStackTrace = env->GetStaticMethodID(invokerClass, "stackTrace", "(Ljava/lang/Throwable;)Ljava/lang/String;");
-        invokerLambda = env->GetFieldID(invokerClass, "lambda", "J");
-        iterableUtilClass = env->FindClass("org/apache/tuscany/IterableUtil");
-        iterableValueOf = env->GetStaticMethodID(iterableUtilClass, "list", "([Ljava/lang/Object;)Ljava/lang/Iterable;");
-        iterableIsNil = env->GetStaticMethodID(iterableUtilClass, "isNil", "(Ljava/lang/Object;)Z");
-        iterableCar = env->GetStaticMethodID(iterableUtilClass, "car", "(Ljava/lang/Object;)Ljava/lang/Object;");
-        iterableCdr = env->GetStaticMethodID(iterableUtilClass, "cdr", "(Ljava/lang/Object;)Ljava/lang/Iterable;");
-        uuidClass = env->FindClass("org/apache/tuscany/UUIDUtil");
+        h.loaderClass = h.env->FindClass("org/apache/tuscany/ClassLoader");
+        h.loaderValueOf = h.env->GetStaticMethodID(h.loaderClass, "valueOf", "(Ljava/lang/String;)Ljava/lang/ClassLoader;");
+        h.loaderForName = h.env->GetStaticMethodID(h.loaderClass, "forName", "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;");
+        h.invokerClass = h.env->FindClass("org/apache/tuscany/InvocationHandler");
+        h.invokerValueOf = h.env->GetStaticMethodID(h.invokerClass, "valueOf", "(Ljava/lang/Class;J)Ljava/lang/Object;");
+        h.invokerStackTrace = h.env->GetStaticMethodID(h.invokerClass, "stackTrace", "(Ljava/lang/Throwable;)Ljava/lang/String;");
+        h.invokerLambda = h.env->GetFieldID(h.invokerClass, "lambda", "J");
+        h.iterableUtilClass = h.env->FindClass("org/apache/tuscany/IterableUtil");
+        h.iterableValueOf = h.env->GetStaticMethodID(h.iterableUtilClass, "list", "([Ljava/lang/Object;)Ljava/lang/Iterable;");
+        h.iterableIsNil = h.env->GetStaticMethodID(h.iterableUtilClass, "isNil", "(Ljava/lang/Object;)Z");
+        h.iterableCar = h.env->GetStaticMethodID(h.iterableUtilClass, "car", "(Ljava/lang/Object;)Ljava/lang/Object;");
+        h.iterableCdr = h.env->GetStaticMethodID(h.iterableUtilClass, "cdr", "(Ljava/lang/Object;)Ljava/lang/Iterable;");
+        h.uuidClass = h.env->FindClass("org/apache/tuscany/UUIDUtil");
 
         // Register our native invocation handler function
         JNINativeMethod invokenm;
         invokenm.name = const_cast<char*>("invoke");
         invokenm.signature = const_cast<char*>("(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;");
         invokenm.fnPtr = (void*)nativeInvoke;
-        env->RegisterNatives(invokerClass, &invokenm, 1);
+        h.env->RegisterNatives(h.invokerClass, &invokenm, 1);
 
         // Register our native UUID function
         JNINativeMethod uuidnm;
         uuidnm.name = const_cast<char*>("uuid");
         uuidnm.signature = const_cast<char*>("()Ljava/lang/String;");
         uuidnm.fnPtr = (void*)nativeUUID;
-        env->RegisterNatives(uuidClass, &uuidnm, 1);
+        h.env->RegisterNatives(h.uuidClass, &uuidnm, 1);
     }
 
+    JavaRuntime(const JavaRuntime& c) : h(c.h) {
+    }
+
+    JavaRuntime& operator=(const JavaRuntime&) = delete;
+
     ~JavaRuntime() {
     }
 
-    JavaVM* jvm;
-    JNIEnv* env;
+public:
+    class handles {
+    public:
+        handles() {
+        }
+
+    public:
+        friend class JavaRuntime;
 
-    jclass classClass;
-    jclass methodClass;
-    jclass objectClass;
-    jclass doubleClass;
-    jclass booleanClass;
-    jclass stringClass;
-    jclass objectArrayClass;
-    jclass iterableClass;
-    jmethodID doubleValueOf;
-    jmethodID doubleValue;
-    jmethodID booleanValueOf;
-    jmethodID booleanValue;
-    jmethodID declaredMethods;
-    jmethodID methodName;
-    jmethodID parameterTypes;
-    jmethodID classForName;
-    jclass loaderClass;
-    jmethodID loaderValueOf;
-    jmethodID loaderForName;
-    jclass invokerClass;
-    jmethodID invokerValueOf;
-    jmethodID invokerStackTrace;
-    jfieldID invokerLambda;
-    jclass iterableUtilClass;
-    jmethodID iterableValueOf;
-    jmethodID iterableCar;
-    jmethodID iterableCdr;
-    jmethodID iterableIsNil;
-    jclass uuidClass;
+        JavaVM* jvm;
+        JNIEnv* env;
+
+        jclass classClass;
+        jclass methodClass;
+        jclass objectClass;
+        jclass doubleClass;
+        jclass booleanClass;
+        jclass stringClass;
+        jclass objectArrayClass;
+        jclass iterableClass;
+        jmethodID doubleValueOf;
+        jmethodID doubleValue;
+        jmethodID booleanValueOf;
+        jmethodID booleanValue;
+        jmethodID declaredMethods;
+        jmethodID methodName;
+        jmethodID parameterTypes;
+        jmethodID classForName;
+        jclass loaderClass;
+        jmethodID loaderValueOf;
+        jmethodID loaderForName;
+        jclass invokerClass;
+        jmethodID invokerValueOf;
+        jmethodID invokerStackTrace;
+        jfieldID invokerLambda;
+        jclass iterableUtilClass;
+        jmethodID iterableValueOf;
+        jmethodID iterableCar;
+        jmethodID iterableCdr;
+        jmethodID iterableIsNil;
+        jclass uuidClass;
+    };
+
+    handles& h;
 };
 
 /**
  * Return the last exception that occurred in a JVM.
  */
-string lastException(const JavaRuntime& jr) {
-    if (!jr.env->ExceptionCheck())
+const string lastException(const JavaRuntime& jr) {
+    if (!jr.h.env->ExceptionCheck())
         return "No Exception";
-    const jthrowable ex = jr.env->ExceptionOccurred();
-    const jstring trace = (jstring)jr.env->CallStaticObjectMethod(jr.invokerClass, jr.invokerStackTrace, ex);
-    const char* c = jr.env->GetStringUTFChars(trace, NULL);
+    const jthrowable ex = jr.h.env->ExceptionOccurred();
+    const jstring trace = (jstring)jr.h.env->CallStaticObjectMethod(jr.h.invokerClass, jr.h.invokerStackTrace, ex);
+    const char* const c = jr.h.env->GetStringUTFChars(trace, NULL);
     const string msg(c);
-    jr.env->ReleaseStringUTFChars(trace, c);
-    jr.env->ExceptionClear();
+    jr.h.env->ReleaseStringUTFChars(trace, c);
+    jr.h.env->ExceptionClear();
     return msg;
 }
 
@@ -216,7 +233,7 @@ const list<value> jiterableToValues(cons
 /**
  * Convert a Java class name to a JNI class name.
  */
-const bool jniClassNameHelper(char* to, const char* from) {
+const bool jniClassNameHelper(char* const to, const char* const from) {
     if (*from == '\0') {
         *to = '\0';
         return true;
@@ -236,7 +253,7 @@ const string jniClassName(const string& 
  */
 class javaLambda {
 public:
-    javaLambda(const JavaRuntime& jr, const value& iface, const lambda<value(const list<value>&)>& func) : jr(jr), iface(iface), func(func) {
+    javaLambda(const JavaRuntime& jr, const value& iface, const lvvlambda& func) : jr(jr), iface(iface), func(func) {
     }
 
     const value operator()(const list<value>& expr) const {
@@ -255,9 +272,10 @@ public:
         return func(expr);
     }
 
-    const JavaRuntime& jr;
+public:
+    const JavaRuntime jr;
     const value iface;
-    const lambda<value(const list<value>&)> func;
+    const lvvlambda func;
 };
 
 /**
@@ -267,12 +285,12 @@ public:
 jobject JNICALL nativeInvoke(JNIEnv* env, jobject self, unused jobject proxy, jobject method, jobjectArray args) {
 
     // Retrieve the lambda function from the invocation handler
-    jclass clazz = env->GetObjectClass(self);
-    jfieldID f = env->GetFieldID(clazz, "lambda", "J");
+    const jclass clazz = env->GetObjectClass(self);
+    const jfieldID f = env->GetFieldID(clazz, "lambda", "J");
     const javaLambda& jl = *(javaLambda*)(long)env->GetLongField(self, f);
 
     // Retrieve the function name
-    const jstring s = (jstring)env->CallObjectMethod(method, jl.jr.methodName);
+    const jstring s = (jstring)env->CallObjectMethod(method, jl.jr.h.methodName);
     const char* c = env->GetStringUTFChars(s, NULL);
     const value func(c);
     env->ReleaseStringUTFChars(s, c);
@@ -287,7 +305,7 @@ jobject JNICALL nativeInvoke(JNIEnv* env
     debug(result, "java::nativeInvoke::result");
 
     // Convert result to a jobject
-    return valueToJobject(jl.jr, value(), result);
+    return valueToJobject(jl.jr, nilValue, result);
 }
 
 /**
@@ -302,10 +320,10 @@ jobject JNICALL nativeUUID(JNIEnv* env) 
 /**
  * Convert a lambda function to Java proxy.
  */
-const jobject mkJavaLambda(const JavaRuntime& jr, unused const value& iface, const lambda<value(const list<value>&)>& l) {
+const jobject mkJavaLambda(const JavaRuntime& jr, unused const value& iface, const lvvlambda& l) {
     const gc_ptr<javaLambda> jl = new (gc_new<javaLambda>()) javaLambda(jr, iface, l);
     jclass jc = (jclass)(long)(double)iface;
-    const jobject obj = jr.env->CallStaticObjectMethod(jr.invokerClass, jr.invokerValueOf, jc, (long)(javaLambda*)jl);
+    const jobject obj = jr.h.env->CallStaticObjectMethod(jr.h.invokerClass, jr.h.invokerValueOf, jc, (long)(javaLambda*)jl);
     return obj;
 }
 
@@ -315,20 +333,20 @@ const jobject mkJavaLambda(const JavaRun
 const jobjectArray valuesToJarrayHelper(const JavaRuntime& jr, jobjectArray a, const list<value>& v, const int i) {
     if (isNil(v))
         return a;
-    jr.env->SetObjectArrayElement(a, i, valueToJobject(jr, value(), car(v)));
+    jr.h.env->SetObjectArrayElement(a, i, valueToJobject(jr, nilValue, car(v)));
     return valuesToJarrayHelper(jr, a, cdr(v), i + 1);
 }
 
 const jobjectArray valuesToJarray(const JavaRuntime& jr, const list<value>& v) {
-    jobjectArray a = jr.env->NewObjectArray((jsize)length(v), jr.objectClass, NULL);
+    jobjectArray a = jr.h.env->NewObjectArray((jsize)length(v), jr.h.objectClass, NULL);
     return valuesToJarrayHelper(jr, a, v, 0);
 }
 
 /**
  * Convert a Java jobjectArray to a Java iterable.
  */
-const jobject jarrayToJiterable(const JavaRuntime& jr, jobjectArray a) {
-    return jr.env->CallStaticObjectMethod(jr.iterableClass, jr.iterableValueOf, a);
+const jobject jarrayToJiterable(const JavaRuntime& jr, const jobjectArray a) {
+    return jr.h.env->CallStaticObjectMethod(jr.h.iterableClass, jr.h.iterableValueOf, a);
 }
 
 /**
@@ -341,13 +359,13 @@ const jobject valueToJobject(const JavaR
     case value::Lambda:
         return mkJavaLambda(jr, jtype, v);
     case value::Symbol:
-        return jr.env->NewStringUTF(c_str(string("'") + v));
+        return jr.h.env->NewStringUTF(c_str(string("'") + (string)v));
     case value::String:
-        return jr.env->NewStringUTF(c_str(v));
+        return jr.h.env->NewStringUTF(c_str(v));
     case value::Number:
-        return jr.env->CallStaticObjectMethod(jr.doubleClass, jr.doubleValueOf, (double)v);
+        return jr.h.env->CallStaticObjectMethod(jr.h.doubleClass, jr.h.doubleValueOf, (double)v);
     case value::Bool:
-        return jr.env->CallStaticObjectMethod(jr.booleanClass, jr.booleanValueOf, (bool)v);
+        return jr.h.env->CallStaticObjectMethod(jr.h.booleanClass, jr.h.booleanValueOf, (bool)v);
     default:
         return NULL;
     }
@@ -356,7 +374,7 @@ const jobject valueToJobject(const JavaR
 /**
  * Convert a list of values to an array of jvalues.
  */
-const jvalue* valuesToJvaluesHelper(const JavaRuntime& jr, jvalue* a, const list<value>& types, const list<value>& v) {
+const jvalue* valuesToJvaluesHelper(const JavaRuntime& jr, jvalue* const a, const list<value>& types, const list<value>& v) {
     if (isNil(v))
         return a;
     a->l = valueToJobject(jr, car(types), car(v));
@@ -365,7 +383,7 @@ const jvalue* valuesToJvaluesHelper(cons
 
 const jvalue* valuesToJvalues(const JavaRuntime& jr, const list<value>& types, const list<value>& v) {
     const size_t n = length(v);
-    jvalue* a = new (gc_anew<jvalue>(n)) jvalue[n];
+    jvalue* const a = new (gc_anew<jvalue>(n)) jvalue[n];
     valuesToJvaluesHelper(jr, a, types, v);
     return a;
 }
@@ -373,79 +391,67 @@ const jvalue* valuesToJvalues(const Java
 /**
  * Convert a Java jobjectArray to a list of values.
  */
-const list<value> jarrayToValuesHelper(const JavaRuntime& jr, jobjectArray a, const int i, const int size) {
+const list<value> jarrayToValuesHelper(const JavaRuntime& jr, const jobjectArray a, const int i, const int size) {
     if (i == size)
-        return list<value>();
-    return cons(jobjectToValue(jr, jr.env->GetObjectArrayElement(a, i)), jarrayToValuesHelper(jr, a, i + 1, size));
+        return nilListValue;
+    return cons(jobjectToValue(jr, jr.h.env->GetObjectArrayElement(a, i)), jarrayToValuesHelper(jr, a, i + 1, size));
 }
 
-const list<value> jarrayToValues(const JavaRuntime& jr, jobjectArray o) {
+const list<value> jarrayToValues(const JavaRuntime& jr, const jobjectArray o) {
     if (o == NULL)
-        return list<value>();
-    return jarrayToValuesHelper(jr, o, 0, jr.env->GetArrayLength(o));
+        return nilListValue;
+    return jarrayToValuesHelper(jr, o, 0, jr.h.env->GetArrayLength(o));
 }
 
 /**
  * Convert a Java Iterable to a list of values.
  */
-const list<value> jiterableToValuesHelper(const JavaRuntime& jr, jobject o) {
-    if ((bool)jr.env->CallStaticBooleanMethod(jr.iterableUtilClass, jr.iterableIsNil, o))
-        return list<value>();
-    jobject car = jr.env->CallStaticObjectMethod(jr.iterableUtilClass, jr.iterableCar, o);
-    jobject cdr = jr.env->CallStaticObjectMethod(jr.iterableUtilClass, jr.iterableCdr, o);
+const list<value> jiterableToValuesHelper(const JavaRuntime& jr, const jobject o) {
+    if ((bool)jr.h.env->CallStaticBooleanMethod(jr.h.iterableUtilClass, jr.h.iterableIsNil, o))
+        return nilListValue;
+    const jobject car = jr.h.env->CallStaticObjectMethod(jr.h.iterableUtilClass, jr.h.iterableCar, o);
+    const jobject cdr = jr.h.env->CallStaticObjectMethod(jr.h.iterableUtilClass, jr.h.iterableCdr, o);
     return cons(jobjectToValue(jr, car), jiterableToValuesHelper(jr, cdr));
 }
 
-const list<value> jiterableToValues(const JavaRuntime& jr, jobject o) {
+const list<value> jiterableToValues(const JavaRuntime& jr, const jobject o) {
     if (o == NULL)
-        return list<value>();
+        return nilListValue;
     return jiterableToValuesHelper(jr, o);
 }
 
 /**
- * Lambda function used to represent a Java callable object.
- */
-struct javaCallable {
-    const JavaRuntime& jr;
-    const jobject obj;
-
-    javaCallable(const JavaRuntime& jr, const jobject obj) : jr(jr), obj(obj) {
-    }
-
-    const value operator()(const list<value>& args) const {
-        jobjectArray jargs = valuesToJarray(jr, args);
-        jobject result = jargs; //CallObject(func, jargs);
-        return jobjectToValue(jr, result);
-    }
-};
-
-/**
  * Convert a Java jobject to a value.
  */
 const value jobjectToValue(const JavaRuntime& jr, const jobject o) {
     if (o == NULL)
-        return value();
-    const jclass clazz = jr.env->GetObjectClass(o);
-    if ((jr.env->IsSameObject(clazz, jr.stringClass))) {
-        const char* s = jr.env->GetStringUTFChars((jstring)o, NULL);
+        return nilValue;
+    const jclass clazz = jr.h.env->GetObjectClass(o);
+    if ((jr.h.env->IsSameObject(clazz, jr.h.stringClass))) {
+        const char* const s = jr.h.env->GetStringUTFChars((jstring)o, NULL);
         if (*s == '\'') {
             const value v(s + 1);
-            jr.env->ReleaseStringUTFChars((jstring)o, s);
+            jr.h.env->ReleaseStringUTFChars((jstring)o, s);
             return v;
         }
         const value v = string(s);
-        jr.env->ReleaseStringUTFChars((jstring)o, s);
+        jr.h.env->ReleaseStringUTFChars((jstring)o, s);
         return v;
     }
-    if (jr.env->IsSameObject(clazz, jr.booleanClass))
-        return value((bool)jr.env->CallBooleanMethod(o, jr.booleanValue));
-    if (jr.env->IsSameObject(clazz, jr.doubleClass))
-        return value((double)jr.env->CallDoubleMethod(o, jr.doubleValue));
-    if (jr.env->IsAssignableFrom(clazz, jr.iterableClass))
+    if (jr.h.env->IsSameObject(clazz, jr.h.booleanClass))
+        return value((bool)jr.h.env->CallBooleanMethod(o, jr.h.booleanValue));
+    if (jr.h.env->IsSameObject(clazz, jr.h.doubleClass))
+        return value((double)jr.h.env->CallDoubleMethod(o, jr.h.doubleValue));
+    if (jr.h.env->IsAssignableFrom(clazz, jr.h.iterableClass))
         return jiterableToValues(jr, o);
-    if (jr.env->IsAssignableFrom(clazz, jr.objectArrayClass))
+    if (jr.h.env->IsAssignableFrom(clazz, jr.h.objectArrayClass))
         return jarrayToValues(jr, (jobjectArray)o);
-    return lambda<value(const list<value>&)>(javaCallable(jr, o));
+    const lvvlambda javaCallable = [jr](const list<value>& params) -> const value {
+        jobjectArray jargs = valuesToJarray(jr, params);
+        jobject result = jargs; //CallObject(func, jargs);
+        return jobjectToValue(jr, result);
+    };
+    return value(javaCallable);
 }
 
 /**
@@ -457,33 +463,33 @@ const value parameterTypeToValue(const j
 
 const list<value> parameterTypesToValues(const JavaRuntime& jr, const jobjectArray t, const int i) {
     if (i == 0)
-        return list<value>();
-    return cons<value>(parameterTypeToValue(jr.env->GetObjectArrayElement(t, i - 1)), parameterTypesToValues(jr, t, i - 1));
+        return nilListValue;
+    return cons<value>(parameterTypeToValue(jr.h.env->GetObjectArrayElement(t, i - 1)), parameterTypesToValues(jr, t, i - 1));
 }
 
 const value methodToValue(const JavaRuntime& jr, const jobject m) {
-    const jobject s = jr.env->CallObjectMethod(m, jr.methodName);
-    const char* c = jr.env->GetStringUTFChars((jstring)s, NULL);
+    const jobject s = jr.h.env->CallObjectMethod(m, jr.h.methodName);
+    const char* const c = jr.h.env->GetStringUTFChars((jstring)s, NULL);
     const string& name = string(c);
-    jr.env->ReleaseStringUTFChars((jstring)s, c);
+    jr.h.env->ReleaseStringUTFChars((jstring)s, c);
 
-    const jmethodID mid = jr.env->FromReflectedMethod(m);
+    const jmethodID mid = jr.h.env->FromReflectedMethod(m);
 
-    const jobjectArray t = (jobjectArray)jr.env->CallObjectMethod(m, jr.parameterTypes);
-    const list<value> types = reverse(parameterTypesToValues(jr, t, jr.env->GetArrayLength(t)));
+    const jobjectArray t = (jobjectArray)jr.h.env->CallObjectMethod(m, jr.h.parameterTypes);
+    const list<value> types = reverse(parameterTypesToValues(jr, t, jr.h.env->GetArrayLength(t)));
 
     return cons<value>(c_str(name), cons<value>((double)(long)mid, types));
 }
 
 const list<value> methodsToValues(const JavaRuntime& jr, const jobjectArray m, const int i) {
     if (i == 0)
-        return list<value>();
-    return cons<value>(methodToValue(jr, jr.env->GetObjectArrayElement(m, i - 1)), methodsToValues(jr, m, i - 1));
+        return nilListValue;
+    return cons<value>(methodToValue(jr, jr.h.env->GetObjectArrayElement(m, i - 1)), methodsToValues(jr, m, i - 1));
 }
 
 const list<value> methodsToValues(const JavaRuntime& jr, const jclass clazz) {
-    const jobjectArray m = (jobjectArray)jr.env->CallObjectMethod(clazz, jr.declaredMethods);
-    return methodsToValues(jr, m, jr.env->GetArrayLength(m));
+    const jobjectArray m = (jobjectArray)jr.h.env->CallObjectMethod(clazz, jr.h.declaredMethods);
+    return methodsToValues(jr, m, jr.h.env->GetArrayLength(m));
 }
 
 /**
@@ -508,20 +514,20 @@ public:
 const failable<JavaClass> readClass(const JavaRuntime& jr, const string& path, const string& name) {
 
     // Create a class loader from the given path
-    const jobject jpath = jr.env->NewStringUTF(c_str(path));
-    jobject loader = jr.env->CallStaticObjectMethod(jr.loaderClass, jr.loaderValueOf, jpath);
+    const jobject jpath = jr.h.env->NewStringUTF(c_str(path));
+    const jobject loader = jr.h.env->CallStaticObjectMethod(jr.h.loaderClass, jr.h.loaderValueOf, jpath);
 
     // Load the class
-    const jobject jname = jr.env->NewStringUTF(c_str(name));
-    const jclass clazz = (jclass)jr.env->CallStaticObjectMethod(jr.loaderClass, jr.loaderForName, jname, JNI_TRUE, loader);
+    const jobject jname = jr.h.env->NewStringUTF(c_str(name));
+    const jclass clazz = (jclass)jr.h.env->CallStaticObjectMethod(jr.h.loaderClass, jr.h.loaderForName, jname, JNI_TRUE, loader);
     if (clazz == NULL)
         return mkfailure<JavaClass>(string("Couldn't load class: ") + name + " : " + lastException(jr));
 
     // Create an instance
-    const jmethodID constr = jr.env->GetMethodID(clazz, "<init>", "()V");
+    const jmethodID constr = jr.h.env->GetMethodID(clazz, "<init>", "()V");
     if (constr == NULL)
         return mkfailure<JavaClass>(string("Couldn't find constructor: ") + name + " : " + lastException(jr));
-    const jobject obj = jr.env->NewObject(clazz, constr);
+    const jobject obj = jr.h.env->NewObject(clazz, constr);
     if (obj == NULL)
         return mkfailure<JavaClass>(string("Couldn't construct object: ") + name + " : " + lastException(jr));
 
@@ -541,19 +547,19 @@ const failable<value> evalClass(const Ja
         // The start, stop, and restart functions are optional
         const value fn = car<value>(expr);
         if (fn == "start" || fn == "stop")
-            return value(lambda<value(const list<value>&)>());
+            return value(lvvlambda());
 
-        return mkfailure<value>(string("Couldn't find function: ") + car<value>(expr) + " : " + lastException(jr));
+        return mkfailure<value>(string("Couldn't find function: ") + (string)car<value>(expr) + " : " + lastException(jr));
     }
     const jmethodID fid = (jmethodID)(long)(double)cadr(func);
 
     // Convert args to Java jvalues
-    const jvalue* args = valuesToJvalues(jr, cddr(func), cdr<value>(expr));
+    const jvalue* const args = valuesToJvalues(jr, cddr(func), cdr<value>(expr));
 
     // Call the Java function
-    const jobject result = jr.env->CallObjectMethodA(jc.obj, fid, const_cast<jvalue*>(args));
+    const jobject result = jr.h.env->CallObjectMethodA(jc.obj, fid, const_cast<jvalue*>(args));
     if (result == NULL)
-        return mkfailure<value>(string("Function call failed: ") + car<value>(expr) + " : " + lastException(jr));
+        return mkfailure<value>(string("Function call failed: ") + (string)car<value>(expr) + " : " + lastException(jr));
 
     // Convert Java result to a value
     const value v = jobjectToValue(jr, result);

Modified: tuscany/sca-cpp/trunk/modules/java/java-shell.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/java/java-shell.cpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/java/java-shell.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/java/java-shell.cpp Tue Dec 11 04:03:29 2012
@@ -29,8 +29,8 @@
 #include "string.hpp"
 #include "driver.hpp"
 
-int main(const int argc, char** argv) {
-    tuscany::gc_scoped_pool pool;
+int main(const int argc, const char** const argv) {
+    const tuscany::gc_scoped_pool pool;
     if (argc != 2) {
         tuscany::cerr << "Usage: java-shell <class name>" << tuscany::endl;
         return 1;

Modified: tuscany/sca-cpp/trunk/modules/java/java-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/java/java-test.cpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/java/java-test.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/java/java-test.cpp Tue Dec 11 04:03:29 2012
@@ -32,8 +32,8 @@ namespace tuscany {
 namespace java {
 
 bool testEvalExpr() {
-    gc_scoped_pool pool;
-    JavaRuntime javaRuntime;
+    const gc_scoped_pool pool;
+    const JavaRuntime javaRuntime;
     {
         const failable<JavaClass> obj = readClass(javaRuntime, ".", "test.CalcImpl");
         assert(hasContent(obj));
@@ -48,7 +48,7 @@ bool testEvalExpr() {
         const value exp = mklist<value>("even", 2);
         const failable<value> r = evalClass(javaRuntime, exp, content(obj));
         assert(hasContent(r));
-        assert(content(r) == value(true));
+        assert(content(r) == trueValue);
     }
     {
         const failable<JavaClass> obj = readClass(javaRuntime, ".", "test.AdderImpl");
@@ -77,12 +77,12 @@ const value add(const list<value>& args)
 }
 
 bool testEvalLambda() {
-    gc_scoped_pool pool;
-    JavaRuntime javaRuntime;
+    const gc_scoped_pool pool;
+    const JavaRuntime javaRuntime;
     {
         const failable<JavaClass> obj = readClass(javaRuntime, ".", "test.CalcImpl");
         assert(hasContent(obj));
-        const value tcel = mklist<value>("add", 3, 4, lambda<value(const list<value>&)>(add));
+        const value tcel = mklist<value>("add", 3, 4, lvvlambda(add));
         const failable<value> r = evalClass(javaRuntime, tcel, content(obj));
         assert(hasContent(r));
         assert(content(r) == value(7));
@@ -90,7 +90,7 @@ bool testEvalLambda() {
     {
         const failable<JavaClass> obj = readClass(javaRuntime, ".", "test.CalcImpl");
         assert(hasContent(obj));
-        const value tcel = mklist<value>("addEval", 3, 4, lambda<value(const list<value>&)>(add));
+        const value tcel = mklist<value>("addEval", 3, 4, lvvlambda(add));
         const failable<value> r = evalClass(javaRuntime, tcel, content(obj));
         assert(hasContent(r));
         assert(content(r) == value(7));
@@ -99,26 +99,26 @@ bool testEvalLambda() {
 }
 
 bool testClassLoader() {
-    gc_scoped_pool pool;
-    JavaRuntime javaRuntime;
+    const gc_scoped_pool pool;
+    const JavaRuntime javaRuntime;
     const failable<JavaClass> obj = readClass(javaRuntime, ".", "org.apache.tuscany.ClassLoader$Test");
     assert(hasContent(obj));
     const value exp = mklist<value>("testClassLoader");
     const failable<value> r = evalClass(javaRuntime, exp, content(obj));
     assert(hasContent(r));
-    assert(content(r) == value(true));
+    assert(content(r) == trueValue);
     return true;
 }
 
 bool testIterableUtil() {
-    gc_scoped_pool pool;
-    JavaRuntime javaRuntime;
+    const gc_scoped_pool pool;
+    const JavaRuntime javaRuntime;
     const failable<JavaClass> obj = readClass(javaRuntime, ".", "org.apache.tuscany.IterableUtil$Test");
     assert(hasContent(obj));
     const value exp = mklist<value>("testList");
     const failable<value> r = evalClass(javaRuntime, exp, content(obj));
     assert(hasContent(r));
-    assert(content(r) == value(true));
+    assert(content(r) == trueValue);
     return true;
 }
 

Modified: tuscany/sca-cpp/trunk/modules/java/jni-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/java/jni-test.cpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/java/jni-test.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/java/jni-test.cpp Tue Dec 11 04:03:29 2012
@@ -40,7 +40,7 @@ namespace java {
 #endif
 
 bool testJNI() {
-    gc_scoped_pool pool;
+    const gc_scoped_pool pool;
     JavaVM* jvm;
     JNIEnv* env;
 
@@ -50,7 +50,7 @@ bool testJNI() {
     JavaVMOption options[3];
     args.options = options;
     args.nOptions = 0;
-    const char* envcp = getenv("CLASSPATH");
+    const char* const envcp = getenv("CLASSPATH");
     const string cp = string("-Djava.class.path=") + (envcp == NULL? "." : envcp);
     options[args.nOptions].optionString = const_cast<char*>(c_str(cp));
     options[args.nOptions++].extraInfo = NULL;
@@ -60,9 +60,9 @@ bool testJNI() {
     JNI_CreateJavaVM(&jvm, (void**)&env, &args);
 #endif
 
-    jclass classClass = env->FindClass("java/lang/Class");
+    const jclass classClass = env->FindClass("java/lang/Class");
     assert(classClass != NULL);
-    jclass loaderClass = env->FindClass("org/apache/tuscany/ClassLoader");
+    const jclass loaderClass = env->FindClass("org/apache/tuscany/ClassLoader");
     assert(loaderClass != NULL);
     return true;
 }

Modified: tuscany/sca-cpp/trunk/modules/java/mod-java.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/java/mod-java.cpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/java/mod-java.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/java/mod-java.cpp Tue Dec 11 04:03:29 2012
@@ -40,32 +40,25 @@ namespace modeval {
 /**
  * Apply a lifecycle start or restart event.
  */
-struct javaLifecycle {
-    javaLifecycle(java::JavaRuntime& jr) : jr(jr) {
-    }
-    const value operator()(const list<value>& params) const {
-        const value func = car(params);
-        if (func == "javaRuntime")
-            return (gc_ptr<value>)(value*)(void*)&jr;
-        return lambda<value(const list<value>&)>();
-    }
-    java::JavaRuntime& jr;
-};
-
 const value applyLifecycle(unused const list<value>& params) {
 
     // Create a Java runtime
-    java::JavaRuntime& jr = *(new (gc_new<java::JavaRuntime>()) java::JavaRuntime());
+    const java::JavaRuntime& jr = *(new (gc_new<java::JavaRuntime>()) java::JavaRuntime());
 
     // Return the function to invoke on subsequent events
-    return failable<value>(lambda<value(const list<value>&)>(javaLifecycle(jr)));
+    return failable<value>(lvvlambda([&jr](const list<value>& params) -> const value {
+        const value func = car(params);
+        if (func == "javaRuntime")
+            return (gc_ptr<value>)(value*)(void*)&jr;
+        return lvvlambda();
+    }));
 }
 
 /**
  * Evaluate a Java component implementation and convert it to an applicable
  * lambda function.
  */
-const failable<lambda<value(const list<value>&)> > evalImplementation(const string& path, const value& impl, const list<value>& px, const lambda<value(const list<value>&)>& lifecycle) {
+const failable<lvvlambda > evalImplementation(const string& path, const value& impl, const list<value>& px, const lvvlambda& lifecycle) {
     const string itype(elementName(impl));
     if (contains(itype, ".java")) {
         const void* p = (gc_ptr<value>)lifecycle(mklist<value>("javaRuntime"));
@@ -74,8 +67,8 @@ const failable<lambda<value(const list<v
     if (contains(itype, ".cpp"))
         return modcpp::evalImplementation(path, impl, px);
     if (contains(itype, ".widget"))
-        return mkfailure<lambda<value(const list<value>&)> >(string("Unsupported implementation type: ") + itype, -1, false);
-    return mkfailure<lambda<value(const list<value>&)> >(string("Unsupported implementation type: ") + itype);
+        return mkfailure<lvvlambda >(string("Unsupported implementation type: ") + itype, -1, false);
+    return mkfailure<lvvlambda >(string("Unsupported implementation type: ") + itype);
 }
 
 }

Modified: tuscany/sca-cpp/trunk/modules/java/mod-java.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/java/mod-java.hpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/java/mod-java.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/java/mod-java.hpp Tue Dec 11 04:03:29 2012
@@ -40,34 +40,26 @@ namespace server {
 namespace modjava {
 
 /**
- * Apply a Java component implementation function.
- */
-struct applyImplementation {
-    java::JavaClass impl;
-    const list<value> px;
-    java::JavaRuntime& jr;
-    applyImplementation(const java::JavaClass& impl, const list<value>& px, java::JavaRuntime& jr) : impl(impl), px(px), jr(jr) {
-    }
-    const value operator()(const list<value>& params) const {
-        const value expr = append<value>(params, px);
-        debug(expr, "modeval::java::applyImplementation::input");
-        const failable<value> res = java::evalClass(jr, expr, impl);
-        const value val = !hasContent(res)? mklist<value>(value(), reason(res), rcode(res)) : mklist<value>(content(res));
-        debug(val, "modeval::java::applyImplementation::result");
-        return val;
-    }
-};
-
-/**
  * Evaluate a Java component implementation and convert it to an applicable
  * lambda function.
  */
-const failable<lambda<value(const list<value>&)> > evalImplementation(const string& path, const value& impl, const list<value>& px, java::JavaRuntime& jr) {
+const failable<lvvlambda > evalImplementation(const string& path, const value& impl, const list<value>& px, const java::JavaRuntime& jr) {
     const string cn(attributeValue("class", impl));
-    const failable<java::JavaClass> jc = java::readClass(jr, path, cn);
-    if (!hasContent(jc))
-        return mkfailure<lambda<value(const list<value>&)> >(jc);
-    return lambda<value(const list<value>&)>(applyImplementation(content(jc), px, jr));
+    const failable<java::JavaClass> fjc = java::readClass(jr, path, cn);
+    if (!hasContent(fjc))
+        return mkfailure<lvvlambda >(fjc);
+
+    // Return Java component implementation lambda function
+    const java::JavaClass jc = content(fjc);
+    const lvvlambda applyImplementation = [jc, px, jr](const list<value>& params) -> const value {
+        const value expr = append<value>(params, px);
+        debug(expr, "modeval::java::applyImplementation::expr");
+        const failable<value> res = java::evalClass(jr, expr, jc);
+        const value val = !hasContent(res)? mklist<value>(nilValue, reason(res), rcode(res)) : mklist<value>(content(res));
+        debug(val, "modeval::java::applyImplementation::result");
+        return val;
+    };
+    return applyImplementation;
 }
 
 }

Modified: tuscany/sca-cpp/trunk/modules/oauth/Makefile.am
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/oauth/Makefile.am?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/oauth/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/modules/oauth/Makefile.am Tue Dec 11 04:03:29 2012
@@ -26,12 +26,12 @@ mod_LTLIBRARIES = libmod_tuscany_oauth1.
 noinst_DATA = libmod_tuscany_oauth1${libsuffix} libmod_tuscany_oauth2${libsuffix}
 
 libmod_tuscany_oauth1_la_SOURCES = mod-oauth1.cpp
-libmod_tuscany_oauth1_la_LDFLAGS = -L${LIBOAUTH_LIB} -R${LIBOAUTH_LIB} -loauth -lxml2 -lcurl -lmozjs
+libmod_tuscany_oauth1_la_LDFLAGS = -L${LIBOAUTH_LIB} -R${LIBOAUTH_LIB} -loauth -lxml2 -lcurl -ljansson
 libmod_tuscany_oauth1${libsuffix}:
 	ln -s .libs/libmod_tuscany_oauth1${libsuffix}
 
 libmod_tuscany_oauth2_la_SOURCES = mod-oauth2.cpp
-libmod_tuscany_oauth2_la_LDFLAGS = -lxml2 -lcurl -lmozjs
+libmod_tuscany_oauth2_la_LDFLAGS = -lxml2 -lcurl -ljansson
 libmod_tuscany_oauth2${libsuffix}:
 	ln -s .libs/libmod_tuscany_oauth2${libsuffix}
 

Modified: tuscany/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp?rev=1419987&r1=1419986&r2=1419987&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp Tue Dec 11 04:03:29 2012
@@ -56,18 +56,18 @@ namespace oauth1 {
  */
 class ServerConf {
 public:
-    ServerConf(apr_pool_t* p, server_rec* s) : p(p), server(s) {
+    ServerConf(apr_pool_t* const p, server_rec* const s) : p(p), server(s) {
     }
 
     const gc_pool p;
-    server_rec* server;
-    string ca;
-    string cert;
-    string key;
-    list<list<value> > appkeys;
-    list<string> mcaddrs;
-    memcache::MemCached mc;
-    perthread_ptr<http::CURLSession> cs;
+    server_rec* const server;
+    gc_mutable_ref<string> ca;
+    gc_mutable_ref<string> cert;
+    gc_mutable_ref<string> key;
+    gc_mutable_ref<list<list<value> > > appkeys;
+    gc_mutable_ref<list<string> > mcaddrs;
+    gc_mutable_ref<memcache::MemCached> mc;
+    gc_mutable_ref<perthread_ptr<http::CURLSession> > cs;
 };
 
 /**
@@ -80,7 +80,7 @@ public:
     AuthnProviderConf(const string name, const authn_provider* provider) : name(name), provider(provider) {
     }
 
-    string name;
+    const string name;
     const authn_provider* provider;
 };
 
@@ -89,21 +89,21 @@ public:
  */
 class DirConf {
 public:
-    DirConf(apr_pool_t* p, char* d) : p(p), dir(d), enabled(false), login("") {
+    DirConf(apr_pool_t* const p, const char* const d) : p(p), dir(d), enabled(false), login(emptyString) {
     }
 
     const gc_pool p;
-    const char* dir;
+    const char* const dir;
     bool enabled;
-    string login;
-    list<list<value> > scopeattrs;
-    list<AuthnProviderConf> apcs;
+    gc_mutable_ref<string> login;
+    gc_mutable_ref<list<list<value> > > scopeattrs;
+    gc_mutable_ref<list<AuthnProviderConf> > apcs;
 };
 
 /**
  * Run the authnz hooks to authenticate a request.
  */
-const failable<int> checkAuthnzProviders(const string& user, request_rec* r, const list<AuthnProviderConf>& apcs) {
+const failable<int> checkAuthnzProviders(const string& user, request_rec* const r, const list<AuthnProviderConf>& apcs) {
     if (isNil(apcs))
         return mkfailure<int>("Authentication failure for: " + user, HTTP_UNAUTHORIZED);
     const AuthnProviderConf apc = car<AuthnProviderConf>(apcs);
@@ -118,7 +118,7 @@ const failable<int> checkAuthnzProviders
     return OK;
 }
 
-const failable<int> checkAuthnz(const string& user, request_rec* r, const list<AuthnProviderConf>& apcs) {
+const failable<int> checkAuthnz(const string& user, request_rec* const r, const list<AuthnProviderConf>& apcs) {
     if (substr(user, 0, 1) == "/")
         return mkfailure<int>(string("Encountered FakeBasicAuth spoof: ") + user, HTTP_UNAUTHORIZED);
 
@@ -139,7 +139,7 @@ const failable<value> userInfo(const val
 /**
  * Handle an authenticated request.
  */
-const failable<int> authenticated(const list<list<value> >& userinfo, const bool check, request_rec* r, const list<list<value> >& scopeattrs, const list<AuthnProviderConf>& apcs) {
+const failable<int> authenticated(const list<list<value> >& userinfo, const bool check, request_rec* const r, const list<list<value> >& scopeattrs, const list<AuthnProviderConf>& apcs) {
     debug(userinfo, "modoauth2::authenticated::userinfo");
 
     if (isNil(scopeattrs)) {
@@ -147,7 +147,7 @@ const failable<int> authenticated(const 
         // Store user id in an environment variable
         const list<value> id = assoc<value>("id", userinfo);
         if (isNil(id) || isNil(cdr(id)))
-            return mkfailure<int>("Couldn't retrieve user id");
+            return mkfailure<int>("Couldn't retrieve user id", HTTP_UNAUTHORIZED);
         apr_table_set(r->subprocess_env, "OAUTH2_ID", apr_pstrdup(r->pool, c_str(cadr(id))));
 
         // If the request user field has not been mapped to another attribute, map the
@@ -157,7 +157,7 @@ const failable<int> authenticated(const 
 
         // Run the authnz hooks to check the authenticated user
         if (check)
-            return checkAuthnz(r->user == NULL? "" : r->user, r, apcs);
+            return checkAuthnz(r->user == NULL? emptyString : r->user, r, apcs);
         return OK;
     }
 
@@ -210,7 +210,7 @@ const string header(const string& qs, co
  */
 const list<string> sign(const string& verb, const string& uri, const list<value> appkey, const string& tok, const string& sec) {
     char* qs = NULL;
-    char* suri = oauth_sign_url2(c_str(uri), &qs, OA_HMAC, c_str(verb), c_str(car(appkey)), c_str(cadr(appkey)), length(tok) != 0? c_str(tok) : NULL, length(sec) != 0? c_str(sec) : NULL);
+    char* const suri = oauth_sign_url2(c_str(uri), &qs, OA_HMAC, c_str(verb), c_str(car(appkey)), c_str(cadr(appkey)), length(tok) != 0? c_str(tok) : NULL, length(sec) != 0? c_str(sec) : NULL);
     const list<string> res = mklist<string>(suri, qs);
     free(suri);
     free(qs);
@@ -220,7 +220,7 @@ const list<string> sign(const string& ve
 /**
  * Handle an authorize request.
  */
-const failable<int> authorize(const list<list<value> >& args, request_rec* r, const list<list<value> >& appkeys, const memcache::MemCached& mc) {
+const failable<int> authorize(const list<list<value> >& args, request_rec* const r, const list<list<value> >& appkeys, const memcache::MemCached& mc) {
     // Extract authorize, access_token, client ID and info URIs
     const list<value> ref = assoc<value>("openauth_referrer", args);
     if (isNil(ref) || isNil(cdr(ref)))
@@ -249,19 +249,19 @@ const failable<int> authorize(const list
     // Lookup client app configuration
     const list<value> app = assoc<value>(cadr(cid), appkeys);
     if (isNil(app) || isNil(cdr(app)))
-        return mkfailure<int>(string("client id not found: ") + cadr(cid));
+        return mkfailure<int>(string("client id not found: ") + (string)cadr(cid));
     list<value> appkey = cadr(app);
 
     // Build and sign the request token URI
     const string requri = httpd::unescape(cadr(req)) + string("&") + http::queryString(mklist<list<value> >(mklist<value>("oauth_callback", httpd::escape(redir))));
-    const list<string> srequri = sign("POST", requri, appkey, "", "");
+    const list<string> srequri = sign("POST", requri, appkey, emptyString, emptyString);
     debug(srequri, "modoauth1::authorize::srequri");
 
     // Put the args into an oauth header
-    const string reqhdr = header(cadr(srequri), redir, "");
+    const string reqhdr = header(cadr(srequri), redir, emptyString);
 
     // Send the request token request
-    char* pres = oauth_http_post2(c_str(car(srequri)), "", c_str(reqhdr));
+    char* const pres = oauth_http_post2(c_str(car(srequri)), "", c_str(reqhdr));
     if (pres == NULL)
         return mkfailure<int>("Couldn't send request token request");
     const string res(pres);
@@ -297,11 +297,10 @@ const failable<int> authorize(const list
  * User profile parsing needs to be made configurable.
  */
 const failable<list<value> > profileUserInfo(const value& cid, const string& info) {
-    string b = substr(info, 0, 1);
+    const string b = substr(info, 0, 1);
     if (b == "[") {
         // Twitter JSON profile
-        js::JSContext cx;
-        const list<value> infov(json::jsonValues(content(json::readJSON(mklist<string>(info), cx))));
+        const list<value> infov(content(json::readValue(mklist<string>(info))));
         if (isNil(infov))
             return mkfailure<list<value> >("Couldn't retrieve user info");
         debug(infov, "modoauth1::access_token::info");
@@ -314,8 +313,7 @@ const failable<list<value> > profileUser
     }
     if (b == "{") {
         // Foursquare JSON profile
-        js::JSContext cx;
-        const list<value> infov(json::jsonValues(content(json::readJSON(mklist<string>(info), cx))));
+        const list<value> infov(content(json::readValue(mklist<string>(info))));
         if (isNil(infov))
             return mkfailure<list<value> >("Couldn't retrieve user info");
         debug(infov, "modoauth1::access_token::info");
@@ -328,7 +326,7 @@ const failable<list<value> > profileUser
     }
     if (b == "<") {
         // XML profile
-        const list<value> infov = elementsToValues(readXML(mklist<string>(info)));
+        const list<value> infov = elementsToValues(content(xml::readElements(mklist<string>(info))));
         if (isNil(infov))
             return mkfailure<list<value> >("Couldn't retrieve user info");
         debug(infov, "modoauth1::access_token::info");
@@ -370,8 +368,8 @@ const failable<int> accessToken(const li
     // Lookup client app configuration
     const list<value> app = assoc<value>(cadr(cid), appkeys);
     if (isNil(app) || isNil(cdr(app)))
-        return mkfailure<int>(string("client id not found: ") + cadr(cid));
-    list<value> appkey = cadr(app);
+        return mkfailure<int>(string("client id not found: ") + (string)cadr(cid));
+    const list<value> appkey = cadr(app);
 
     // Retrieve the request token from memcached
     const failable<value> sv = memcache::get(mklist<value>("tuscanyOAuth1Token", cadr(tv)), mc);
@@ -384,10 +382,10 @@ const failable<int> accessToken(const li
     debug(stokuri, "modoauth1::access_token::stokuri");
 
     // Put the args into an oauth header
-    string tokhdr = header(cadr(stokuri), "", cadr(vv));
+    string tokhdr = header(cadr(stokuri), emptyString, cadr(vv));
 
     // Send the access token request
-    char* ptokres = oauth_http_post2(c_str(car(stokuri)), "", c_str(tokhdr));
+    char* const ptokres = oauth_http_post2(c_str(car(stokuri)), "", c_str(tokhdr));
     if (ptokres == NULL)
         return mkfailure<int>("Couldn't post access_token request");
     const string tokres(ptokres);
@@ -410,10 +408,10 @@ const failable<int> accessToken(const li
     debug(sprofuri, "modoauth1::access_token::sprofuri");
 
     // Put the args into an oauth header
-    string profhdr = header(cadr(sprofuri), "", "");
+    const string profhdr = header(cadr(sprofuri), emptyString, emptyString);
 
     // Send the user profile request
-    char* pprofres = oauth_http_get2(c_str(car(sprofuri)), NULL, c_str(profhdr));
+    char* const pprofres = oauth_http_get2(c_str(car(sprofuri)), NULL, c_str(profhdr));
     if (pprofres == NULL)
         return mkfailure<int>("Couldn't get user info");
     const string profres(pprofres);
@@ -431,7 +429,7 @@ const failable<int> accessToken(const li
         return authrc;
 
     // Store user info in memcached keyed by session ID
-    const value sid = string("OAuth1_") + mkrand();
+    const value sid = string("OAuth1_") + (string)mkrand();
     const failable<bool> prc = memcache::put(mklist<value>("tuscanyOAuth1", sid), content(userinfo), mc);
     if (!hasContent(prc))
         return mkfailure<int>(prc);
@@ -446,17 +444,17 @@ const failable<int> accessToken(const li
  * Check user authentication.
  */
 static int checkAuthn(request_rec *r) {
-    gc_scoped_pool pool(r->pool);
+    const gc_scoped_pool sp(r->pool);
 
     // Decline if we're not enabled or AuthType is not set to Open
     const DirConf& dc = httpd::dirConf<DirConf>(r, &mod_tuscany_oauth1);
     if (!dc.enabled)
         return DECLINED;
-    const char* atype = ap_auth_type(r);
+    const char* const atype = ap_auth_type(r);
     if (atype == NULL || strcasecmp(atype, "Open"))
         return DECLINED;
     debug_httpdRequest(r, "modoauth1::checkAuthn::input");
-    debug(atype, "modopenauth::checkAuthn::auth_type");
+    debug(atype, "modoauth1::checkAuthn::auth_type");
 
     // Get the server configuration
     const ServerConf& sc = httpd::serverConf<ServerConf>(r, &mod_tuscany_oauth1);
@@ -471,9 +469,9 @@ static int checkAuthn(request_rec *r) {
         // Extract the user info from the auth session
         const failable<value> userinfo = userInfo(content(sid), sc.mc);
         if (!hasContent(userinfo))
-            return httpd::reportStatus(mkfailure<int>(userinfo));
+            return openauth::reportStatus(mkfailure<int>(reason(userinfo), HTTP_UNAUTHORIZED), dc.login, nilValue, r);
         r->ap_auth_type = const_cast<char*>(atype);
-        return httpd::reportStatus(authenticated(content(userinfo), false, r, dc.scopeattrs, dc.apcs));
+        return openauth::reportStatus(authenticated(content(userinfo), false, r, dc.scopeattrs, dc.apcs), dc.login, nilValue, r);
     }
 
     // Get the request args
@@ -482,19 +480,14 @@ static int checkAuthn(request_rec *r) {
     // Handle OAuth authorize request step
     if (string(r->uri) == "/oauth1/authorize/") {
         r->ap_auth_type = const_cast<char*>(atype);
-        return httpd::reportStatus(authorize(args, r, sc.appkeys, sc.mc));
+        return openauth::reportStatus(authorize(args, r, sc.appkeys, sc.mc), dc.login, 1, r);
     }
 
     // Handle OAuth access_token request step
     if (string(r->uri) == "/oauth1/access_token/") {
         r->ap_auth_type = const_cast<char*>(atype);
         const failable<int> authrc = accessToken(args, r, sc.appkeys, dc.scopeattrs, dc.apcs, sc.mc);
-
-        // Redirect to the login page if user is not authorized
-        if (!hasContent(authrc) && rcode(authrc) == HTTP_UNAUTHORIZED)
-            return httpd::reportStatus(openauth::login(dc.login, string("/"), 1, r));
-
-        return httpd::reportStatus(authrc);
+        return openauth::reportStatus(authrc, dc.login, 1, r);
     }
 
     // Redirect to the login page, unless we have a session id or an authorization
@@ -509,22 +502,22 @@ static int checkAuthn(request_rec *r) {
         return DECLINED;
 
     r->ap_auth_type = const_cast<char*>(atype);
-    return httpd::reportStatus(openauth::login(dc.login, value(), value(), r));
+    return httpd::reportStatus(openauth::login(dc.login, nilValue, nilValue, r));
 }
 
 /**
  * Process the module configuration.
  */
-int postConfigMerge(ServerConf& mainsc, server_rec* s) {
+int postConfigMerge(const ServerConf& mainsc, server_rec* const s) {
     if (s == NULL)
         return OK;
     ServerConf& sc = httpd::serverConf<ServerConf>(s, &mod_tuscany_oauth1);
     debug(httpd::serverName(s), "modoauth1::postConfigMerge::serverName");
 
     // Merge configuration from main server
-    if (isNil(sc.appkeys))
+    if (isNil((list<list<value> >)sc.appkeys))
         sc.appkeys = mainsc.appkeys;
-    if (isNil(sc.mcaddrs))
+    if (isNil((list<string>)sc.mcaddrs))
         sc.mcaddrs = mainsc.mcaddrs;
     sc.mc = mainsc.mc;
     sc.cs = mainsc.cs;
@@ -532,10 +525,10 @@ int postConfigMerge(ServerConf& mainsc, 
     return postConfigMerge(mainsc, s->next);
 }
 
-int postConfig(apr_pool_t* p, unused apr_pool_t* plog, unused apr_pool_t* ptemp, server_rec* s) {
-    gc_scoped_pool pool(p);
+int postConfig(apr_pool_t* const p, unused apr_pool_t* const plog, unused apr_pool_t* const ptemp, server_rec* const s) {
+    const gc_scoped_pool sp(p);
 
-    ServerConf& sc = httpd::serverConf<ServerConf>(s, &mod_tuscany_oauth1);
+    const ServerConf& sc = httpd::serverConf<ServerConf>(s, &mod_tuscany_oauth1);
     debug(httpd::serverName(s), "modoauth1::postConfig::serverName");
 
     // Merge server configurations
@@ -543,30 +536,12 @@ int postConfig(apr_pool_t* p, unused apr
 }
 
 /**
- * Lambda function that creates a new CURL session.
- */
-class newsession {
-public:
-    newsession(const string& ca, const string& cert, const string& key) : ca(ca), cert(cert), key(key) {
-    }
-
-    const gc_ptr<http::CURLSession> operator()() const {
-        return new (gc_new<http::CURLSession>()) http::CURLSession(ca, cert, key, "", 0);
-    }
-
-private:
-    const string ca;
-    const string cert;
-    const string key;
-};
-
-/**
  * Child process initialization.
  */
-void childInit(apr_pool_t* p, server_rec* s) {
-    gc_scoped_pool pool(p);
+void childInit(apr_pool_t* const p, server_rec* const s) {
+    const gc_scoped_pool sp(p);
 
-    ServerConf* psc = (ServerConf*)ap_get_module_config(s->module_config, &mod_tuscany_oauth1);
+    ServerConf* const psc = (ServerConf*)ap_get_module_config(s->module_config, &mod_tuscany_oauth1);
     if(psc == NULL) {
         cfailure << "[Tuscany] Due to one or more errors mod_tuscany_oauth1 loading failed. Causing apache to stop loading." << endl;
         exit(APEXIT_CHILDFATAL);
@@ -574,13 +549,21 @@ void childInit(apr_pool_t* p, server_rec
     ServerConf& sc = *psc;
 
     // Connect to Memcached
-    if (isNil(sc.mcaddrs))
+    if (isNil((list<string>)sc.mcaddrs))
         sc.mc = *(new (gc_new<memcache::MemCached>()) memcache::MemCached("localhost", 11211));
     else
         sc.mc = *(new (gc_new<memcache::MemCached>()) memcache::MemCached(sc.mcaddrs));
 
     // Setup a CURL session
-    sc.cs = perthread_ptr<http::CURLSession>(lambda<gc_ptr<http::CURLSession>()>(newsession(sc.ca, sc.cert, sc.key)));
+    const string ca(sc.ca);
+    const string cert(sc.cert);
+    const string key(sc.key);
+    const gc_pool cp(gc_current_pool());
+    const lambda<const gc_ptr<http::CURLSession>()> newsession = [ca, cert, key, cp]() -> const gc_ptr<http::CURLSession> {
+        const gc_scoped_pool sp(pool(cp));
+        return new (gc_new<http::CURLSession>()) http::CURLSession(ca, cert, key, emptyString, 0);
+    };
+    sc.cs = *(new (gc_new<perthread_ptr<http::CURLSession> >()) perthread_ptr<http::CURLSession>(newsession));
 
     // Merge the updated configuration into the virtual hosts
     postConfigMerge(sc, s->next);
@@ -589,56 +572,56 @@ void childInit(apr_pool_t* p, server_rec
 /**
  * Configuration commands.
  */
-const char* confAppKey(cmd_parms *cmd, unused void *c, const char *arg1, const char* arg2, const char* arg3) {
-    gc_scoped_pool pool(cmd->pool);
+char* const confAppKey(cmd_parms* cmd, unused void *c, char *arg1, char* arg2, char* arg3) {
+    const gc_scoped_pool sp(cmd->pool);
     ServerConf& sc = httpd::serverConf<ServerConf>(cmd, &mod_tuscany_oauth1);
-    sc.appkeys = cons<list<value> >(mklist<value>(arg1, mklist<value>(arg2, arg3)), sc.appkeys);
+    sc.appkeys = cons<list<value> >(mklist<value>(arg1, mklist<value>(arg2, arg3)), (list<list<value> >)sc.appkeys);
     return NULL;
 }
-const char* confMemcached(cmd_parms *cmd, unused void *c, const char *arg) {
-    gc_scoped_pool pool(cmd->pool);
+char* confMemcached(cmd_parms *cmd, unused void *c, char *arg) {
+    const gc_scoped_pool sp(cmd->pool);
     ServerConf& sc = httpd::serverConf<ServerConf>(cmd, &mod_tuscany_oauth1);
-    sc.mcaddrs = cons<string>(arg, sc.mcaddrs);
+    sc.mcaddrs = cons<string>(arg, (list<string>)sc.mcaddrs);
     return NULL;
 }
-const char* confEnabled(cmd_parms *cmd, void *c, const int arg) {
-    gc_scoped_pool pool(cmd->pool);
+char* confEnabled(cmd_parms *cmd, void *c, int arg) {
+    const gc_scoped_pool sp(cmd->pool);
     DirConf& dc = httpd::dirConf<DirConf>(c);
     dc.enabled = (bool)arg;
     return NULL;
 }
-const char* confLogin(cmd_parms *cmd, void *c, const char* arg) {
-    gc_scoped_pool pool(cmd->pool);
+char* confLogin(cmd_parms *cmd, void *c, char* arg) {
+    const gc_scoped_pool sp(cmd->pool);
     DirConf& dc = httpd::dirConf<DirConf>(c);
     dc.login = arg;
     return NULL;
 }
-const char* confCAFile(cmd_parms *cmd, unused void *c, const char *arg) {
-    gc_scoped_pool pool(cmd->pool);
+char* confCAFile(cmd_parms *cmd, unused void *c, char *arg) {
+    const gc_scoped_pool sp(cmd->pool);
     ServerConf& sc = httpd::serverConf<ServerConf>(cmd, &mod_tuscany_oauth1);
     sc.ca = arg;
     return NULL;
 }
-const char* confCertFile(cmd_parms *cmd, unused void *c, const char *arg) {
-    gc_scoped_pool pool(cmd->pool);
+char* confCertFile(cmd_parms *cmd, unused void *c, char *arg) {
+    const gc_scoped_pool sp(cmd->pool);
     ServerConf& sc = httpd::serverConf<ServerConf>(cmd, &mod_tuscany_oauth1);
     sc.cert = arg;
     return NULL;
 }
-const char* confCertKeyFile(cmd_parms *cmd, unused void *c, const char *arg) {
-    gc_scoped_pool pool(cmd->pool);
+char* confCertKeyFile(cmd_parms *cmd, unused void *c, char *arg) {
+    const gc_scoped_pool sp(cmd->pool);
     ServerConf& sc = httpd::serverConf<ServerConf>(cmd, &mod_tuscany_oauth1);
     sc.key = arg;
     return NULL;
 }
-const char* confScopeAttr(cmd_parms *cmd, void* c, const char* arg1, const char* arg2) {
-    gc_scoped_pool pool(cmd->pool);
+char* confScopeAttr(cmd_parms *cmd, void* c, char* arg1, char* arg2) {
+    const gc_scoped_pool sp(cmd->pool);
     DirConf& dc = httpd::dirConf<DirConf>(c);
-    dc.scopeattrs = cons<list<value> >(mklist<value>(arg1, arg2), dc.scopeattrs);
+    dc.scopeattrs = cons<list<value> >(mklist<value>(arg1, arg2), (list<list<value> >)dc.scopeattrs);
     return NULL;
 }
-const char* confAuthnProvider(cmd_parms *cmd, void *c, const char* arg) {
-    gc_scoped_pool pool(cmd->pool);
+char* confAuthnProvider(cmd_parms *cmd, void *c, char* arg) {
+    const gc_scoped_pool sp(cmd->pool);
     DirConf& dc = httpd::dirConf<DirConf>(c);
 
     // Lookup and cache the Authn provider



Mime
View raw message