Author: jsdelfino
Date: Mon May 23 06:50:15 2011
New Revision: 1126336
URL: http://svn.apache.org/viewvc?rev=1126336&view=rev
Log:
Support cookies over outgoing HTTP calls and a shorter component URL addressing
scheme.
Modified:
tuscany/sca-cpp/trunk/components/cache/client-test.cpp
tuscany/sca-cpp/trunk/components/chat/client-test.cpp
tuscany/sca-cpp/trunk/components/filedb/client-test.cpp
tuscany/sca-cpp/trunk/components/http/client-test.cpp
tuscany/sca-cpp/trunk/components/http/httpdelete.cpp
tuscany/sca-cpp/trunk/components/http/httpget.cpp
tuscany/sca-cpp/trunk/components/log/client-test.cpp
tuscany/sca-cpp/trunk/components/nosqldb/client-test.cpp
tuscany/sca-cpp/trunk/components/queue/client-test.cpp
tuscany/sca-cpp/trunk/components/sqldb/client-test.cpp
tuscany/sca-cpp/trunk/components/webservice/client-test.cpp
tuscany/sca-cpp/trunk/modules/http/curl-connect.cpp
tuscany/sca-cpp/trunk/modules/http/curl-get.cpp
tuscany/sca-cpp/trunk/modules/http/curl-test.cpp
tuscany/sca-cpp/trunk/modules/http/http.hpp
tuscany/sca-cpp/trunk/modules/http/httpd.hpp
tuscany/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp
tuscany/sca-cpp/trunk/modules/http/openauth.hpp
tuscany/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp
tuscany/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp
tuscany/sca-cpp/trunk/modules/server/client-test.hpp
tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp
tuscany/sca-cpp/trunk/modules/server/mod-wiring.cpp
Modified: tuscany/sca-cpp/trunk/components/cache/client-test.cpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/client-test.cpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/cache/client-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/cache/client-test.cpp Mon May 23 06:50:15
2011
@@ -41,7 +41,7 @@ const string datacacheuri("http://localh
const string memocacheuri("http://localhost:8090/memocache");
bool testCache(const string& uri) {
- http::CURLSession cs("", "", "");
+ http::CURLSession cs("", "", "", "");
const list<value> i = list<value>() + "content" + (list<value>() + "item"
+ (list<value>() + "name" + string("Apple"))
@@ -101,7 +101,7 @@ bool testDatacache() {
}
bool testMemocache() {
- http::CURLSession cs("", "", "");
+ http::CURLSession cs("", "", "", "");
const failable<value> res = http::evalExpr(mklist<value>(string("add"),
33, 22), memocacheuri, cs);
assert(hasContent(res));
@@ -137,7 +137,7 @@ bool testGetPerf() {
+ (list<value>() + "id" +
string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ i);
- http::CURLSession cs("", "", "");
+ http::CURLSession cs("", "", "", "");
const failable<value> id = http::post(a, memcacheuri, cs);
assert(hasContent(id));
const string p = path(content(id));
Modified: tuscany/sca-cpp/trunk/components/chat/client-test.cpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/chat/client-test.cpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/chat/client-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/chat/client-test.cpp Mon May 23 06:50:15
2011
@@ -86,7 +86,7 @@ bool testListen() {
bool testPost() {
gc_scoped_pool pool;
- http::CURLSession ch("", "", "");
+ http::CURLSession ch("", "", "", "");
const failable<value> id = http::post(entry,
"http://localhost:8090/print-sender/sca2@localhost", ch);
assert(hasContent(id));
return true;
Modified: tuscany/sca-cpp/trunk/components/filedb/client-test.cpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/filedb/client-test.cpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/filedb/client-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/filedb/client-test.cpp Mon May 23 06:50:15
2011
@@ -39,7 +39,7 @@ namespace filedb {
const string uri("http://localhost:8090/filedb");
bool testFileDB() {
- http::CURLSession cs("", "", "");
+ http::CURLSession cs("", "", "", "");
const list<value> i = list<value>() + "content" + (list<value>() + "item"
+ (list<value>() + "name" + string("Apple"))
@@ -113,7 +113,7 @@ bool testGetPerf() {
+ (list<value>() + "id" +
string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ i);
- http::CURLSession cs("", "", "");
+ http::CURLSession cs("", "", "", "");
const failable<value> id = http::post(a, uri, cs);
assert(hasContent(id));
const string p = path(content(id));
Modified: tuscany/sca-cpp/trunk/components/http/client-test.cpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/http/client-test.cpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/http/client-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/http/client-test.cpp Mon May 23 06:50:15
2011
@@ -39,7 +39,7 @@ namespace http {
const string uri("http://localhost:8090/httpget");
bool testGet() {
- http::CURLSession cs("", "", "");
+ http::CURLSession cs("", "", "", "");
const failable<value> val = http::get(uri, cs);
assert(hasContent(val));
@@ -61,7 +61,7 @@ struct getLoop {
};
bool testGetPerf() {
- http::CURLSession cs("", "", "");
+ http::CURLSession cs("", "", "", "");
const lambda<bool()> gl = getLoop(cs);
cout << "HTTP get test " << time(gl, 5, 200) << " ms" << endl;
Modified: tuscany/sca-cpp/trunk/components/http/httpdelete.cpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/http/httpdelete.cpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/http/httpdelete.cpp (original)
+++ tuscany/sca-cpp/trunk/components/http/httpdelete.cpp Mon May 23 06:50:15
2011
@@ -69,7 +69,7 @@ private:
*/
const failable<value> start(const list<value>& params) {
// Create a CURL session
- http::CURLSession& ch = *(new (gc_new<http::CURLSession>())
http::CURLSession("", "", ""));
+ http::CURLSession& ch = *(new (gc_new<http::CURLSession>())
http::CURLSession("", "", "", ""));
// Return the component implementation lambda function
return value(lambda<value(const list<value>&)>(applyhttp(car(params),
ch)));
Modified: tuscany/sca-cpp/trunk/components/http/httpget.cpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/http/httpget.cpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/http/httpget.cpp (original)
+++ tuscany/sca-cpp/trunk/components/http/httpget.cpp Mon May 23 06:50:15 2011
@@ -69,7 +69,7 @@ private:
*/
const failable<value> start(const list<value>& params) {
// Create a CURL session
- http::CURLSession& ch = *(new (gc_new<http::CURLSession>())
http::CURLSession("", "", ""));
+ http::CURLSession& ch = *(new (gc_new<http::CURLSession>())
http::CURLSession("", "", "", ""));
// Return the component implementation lambda function
return value(lambda<value(const list<value>&)>(applyhttp(car(params),
ch)));
Modified: tuscany/sca-cpp/trunk/components/log/client-test.cpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/log/client-test.cpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/log/client-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/log/client-test.cpp Mon May 23 06:50:15
2011
@@ -39,7 +39,7 @@ namespace log {
const string uri("http://localhost:8090/log");
bool testLog() {
- http::CURLSession cs("", "", "");
+ http::CURLSession cs("", "", "", "");
const list<value> i = list<value>() + "content" + (list<value>() + "item"
+ (list<value>() + "name" + string("Apple"))
@@ -77,7 +77,7 @@ bool testLogPerf() {
+ (list<value>() + "id" +
string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ i);
- http::CURLSession cs("", "", "");
+ http::CURLSession cs("", "", "", "");
const failable<value> id = http::post(a, uri, cs);
assert(hasContent(id));
@@ -88,7 +88,7 @@ bool testLogPerf() {
}
bool testLogger() {
- http::CURLSession cs("", "", "");
+ http::CURLSession cs("", "", "", "");
const failable<value> res = http::evalExpr(mklist<value>(string("sum"),
33, 22), string("http://localhost:8090/client"), cs);
assert(hasContent(res));
Modified: tuscany/sca-cpp/trunk/components/nosqldb/client-test.cpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/nosqldb/client-test.cpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/nosqldb/client-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/nosqldb/client-test.cpp Mon May 23
06:50:15 2011
@@ -39,7 +39,7 @@ namespace nosqldb {
const string uri("http://localhost:8090/nosqldb");
bool testNoSqlDb() {
- http::CURLSession cs("", "", "");
+ http::CURLSession cs("", "", "", "");
const list<value> i = list<value>() + "content" + (list<value>() + "item"
+ (list<value>() + "name" + string("Apple"))
@@ -113,7 +113,7 @@ bool testGetPerf() {
+ (list<value>() + "id" +
string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ i);
- http::CURLSession cs("", "", "");
+ http::CURLSession cs("", "", "", "");
const failable<value> id = http::post(a, uri, cs);
assert(hasContent(id));
const string p = path(content(id));
Modified: tuscany/sca-cpp/trunk/components/queue/client-test.cpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/queue/client-test.cpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/queue/client-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/queue/client-test.cpp Mon May 23 06:50:15
2011
@@ -80,7 +80,7 @@ bool testListen() {
bool testPost() {
gc_scoped_pool pool;
- http::CURLSession ch("", "", "");
+ http::CURLSession ch("", "", "", "");
const failable<value> id = http::post(entry,
"http://localhost:8090/print-sender", ch);
assert(hasContent(id));
return true;
Modified: tuscany/sca-cpp/trunk/components/sqldb/client-test.cpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/sqldb/client-test.cpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/sqldb/client-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/sqldb/client-test.cpp Mon May 23 06:50:15
2011
@@ -39,7 +39,7 @@ namespace sqldb {
const string uri("http://localhost:8090/sqldb");
bool testSqlDb() {
- http::CURLSession cs("", "", "");
+ http::CURLSession cs("", "", "", "");
const list<value> i = list<value>() + "content" + (list<value>() + "item"
+ (list<value>() + "name" + string("Apple"))
@@ -113,7 +113,7 @@ bool testGetPerf() {
+ (list<value>() + "id" +
string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ i);
- http::CURLSession cs("", "", "");
+ http::CURLSession cs("", "", "", "");
const failable<value> id = http::post(a, uri, cs);
assert(hasContent(id));
const string p = path(content(id));
Modified: tuscany/sca-cpp/trunk/components/webservice/client-test.cpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/webservice/client-test.cpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/webservice/client-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/webservice/client-test.cpp Mon May 23
06:50:15 2011
@@ -60,7 +60,7 @@ bool testModAxis2() {
}
bool testEval() {
- http::CURLSession cs("", "", "");
+ http::CURLSession cs("", "", "", "");
const value func = "http://ws.apache.org/axis2/c/samples/echoString";
const list<value> arg = mklist<value>(
Modified: tuscany/sca-cpp/trunk/modules/http/curl-connect.cpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/curl-connect.cpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/curl-connect.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/http/curl-connect.cpp Mon May 23 06:50:15 2011
@@ -36,7 +36,7 @@ namespace http {
const bool testConnect(const string& url, const string& ca = "", const string&
cert = "", const string& key = "") {
gc_scoped_pool p;
- CURLSession cs(ca, cert, key);
+ CURLSession cs(ca, cert, key, "");
const failable<bool> crc = connect(url, cs);
assert(hasContent(crc));
Modified: tuscany/sca-cpp/trunk/modules/http/curl-get.cpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/curl-get.cpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/curl-get.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/http/curl-get.cpp Mon May 23 06:50:15 2011
@@ -33,7 +33,7 @@ namespace tuscany {
namespace http {
const bool testGet(const string& url, const string& ca = "", const string&
cert = "", const string& key = "") {
- CURLSession ch(ca, cert, key);
+ CURLSession ch(ca, cert, key, "");
const failable<value> val = get(url, ch);
assert(hasContent(val));
cout << content(val) << endl;
Modified: tuscany/sca-cpp/trunk/modules/http/curl-test.cpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/curl-test.cpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/curl-test.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/http/curl-test.cpp Mon May 23 06:50:15 2011
@@ -40,7 +40,7 @@ ostream* curlWriter(const string& s, ost
}
const bool testGet() {
- CURLSession ch("", "", "");
+ CURLSession ch("", "", "", "");
{
ostringstream os;
const failable<list<ostream*> > r = get<ostream*>(curlWriter, &os,
testURI, ch);
@@ -69,7 +69,7 @@ struct getLoop {
};
const bool testGetPerf() {
- CURLSession ch("", "", "");
+ CURLSession ch("", "", "", "");
lambda<bool()> gl = getLoop(ch);
cout << "Static GET test " << time(gl, 5, 200) << " ms" << endl;
return true;
@@ -80,7 +80,7 @@ const bool testGetPerf() {
int main() {
tuscany::cout << "Testing..." << tuscany::endl;
- tuscany::http::testURI = tuscany::string("http://") +
tuscany::http::hostname() + ":8090";
+ tuscany::http::testURI = tuscany::string("http://") +
tuscany::http::hostName() + ":8090";
tuscany::http::testGet();
tuscany::http::testGetPerf();
Modified: tuscany/sca-cpp/trunk/modules/http/http.hpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/http.hpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/http.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/http/http.hpp Mon May 23 06:50:15 2011
@@ -35,6 +35,7 @@
#include <apr_network_io.h>
#include <apr_portable.h>
#include <apr_poll.h>
+#include <apr_uri.h>
#include "string.hpp"
#include "gc.hpp"
@@ -65,13 +66,13 @@ public:
*/
class CURLSession {
public:
- CURLSession() : h(NULL), p(NULL), sock(NULL), wpollset(NULL),
wpollfd(NULL), rpollset(NULL), rpollfd(NULL), owner(false), ca(""), cert(""),
key("") {
+ CURLSession() : h(NULL), p(NULL), sock(NULL), wpollset(NULL),
wpollfd(NULL), rpollset(NULL), rpollfd(NULL), owner(false), ca(""), cert(""),
key(""), cookie("") {
}
- CURLSession(const string& ca, const string& cert, const string& key) :
h(curl_easy_init()), p(gc_pool(mkpool())), sock(NULL), wpollset(NULL),
wpollfd(NULL), rpollset(NULL), rpollfd(NULL), owner(true), ca(ca), cert(cert),
key(key) {
+ CURLSession(const string& ca, const string& cert, const string& key, const
string& cookie) : h(curl_easy_init()), p(gc_pool(mkpool())), sock(NULL),
wpollset(NULL), wpollfd(NULL), rpollset(NULL), rpollfd(NULL), owner(true),
ca(ca), cert(cert), key(key), cookie(cookie) {
}
- CURLSession(const CURLSession& c) : h(c.h), p(c.p), sock(c.sock),
wpollset(c.wpollset), wpollfd(c.wpollfd), rpollset(c.rpollset),
rpollfd(c.rpollfd), owner(false), ca(c.ca), cert(c.cert), key(c.key) {
+ CURLSession(const CURLSession& c) : h(c.h), p(c.p), sock(c.sock),
wpollset(c.wpollset), wpollfd(c.wpollfd), rpollset(c.rpollset),
rpollfd(c.rpollfd), owner(false), ca(c.ca), cert(c.cert), key(c.key),
cookie(c.cookie) {
}
~CURLSession() {
@@ -104,6 +105,7 @@ public:
string ca;
string cert;
string key;
+ string cookie;
};
/**
@@ -185,6 +187,34 @@ const string escapeArg(const string& arg
}
/**
+ * Parse a URI and return its host name.
+ */
+const string hostName(const string& uri, const gc_pool& p) {
+ apr_uri_t u;
+ const apr_status_t rc = apr_uri_parse(pool(p), c_str(uri), &u);
+ if (rc != APR_SUCCESS)
+ return "";
+ if (u.hostname == NULL)
+ return "";
+ return u.hostname;
+}
+
+/**
+ * Return the first subdomain name in a host name.
+ */
+const string subDomain(const string& host) {
+ return substr(host, 0, find(host, '.'));
+}
+
+/**
+ * Return the top domain name in a host name.
+ */
+const string topDomain(const string& host) {
+ const size_t d = find(host, '.');
+ return d == length(host) ? host : substr(host, d + 1);
+}
+
+/**
* Setup a CURL session
*/
const failable<CURL*> setup(const string& url, const CURLSession& cs) {
@@ -217,6 +247,10 @@ const failable<CURL*> setup(const string
curl_easy_setopt(ch, CURLOPT_SSLKEY, c_str(cs.key));
curl_easy_setopt(ch, CURLOPT_SSLKEYTYPE, "PEM");
}
+ if (cs.cookie != "") {
+ debug(cs.cookie, "http::setup::cookie");
+ curl_easy_setopt(ch, CURLOPT_COOKIE, c_str(cs.cookie));
+ }
// Set target URL
curl_easy_setopt(ch, CURLOPT_URL, c_str(escapeURI(url)));
@@ -567,7 +601,7 @@ const failable<value, string> del(const
/**
* Returns the current host name.
*/
-const string hostname() {
+const string hostName() {
char h[256];
if (gethostname(h, 256) == -1)
return "localhost";
@@ -722,7 +756,7 @@ const value escapeQuery(const value& arg
* HTTP client proxy function.
*/
struct proxy {
- proxy(const string& uri, const string& ca, const string& cert, const
string& key, const gc_pool& p) : p(p), uri(uri), ca(ca), cert(cert), key(key),
cs(*(new (gc_new<CURLSession>(p)) CURLSession(ca, cert, key))) {
+ proxy(const string& uri, const string& ca, const string& cert, const
string& key, const string& cookie, const gc_pool& p) : p(p), uri(uri), ca(ca),
cert(cert), key(key), cookie(cookie), cs(*(new (gc_new<CURLSession>(p))
CURLSession(ca, cert, key, cookie))) {
}
const value operator()(const list<value>& args) const {
@@ -757,6 +791,7 @@ struct proxy {
const string ca;
const string cert;
const string key;
+ const string cookie;
const CURLSession& cs;
};
Modified: tuscany/sca-cpp/trunk/modules/http/httpd.hpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/httpd.hpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/httpd.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/http/httpd.hpp Mon May 23 06:50:15 2011
@@ -145,13 +145,6 @@ const string hostName(request_rec* r, co
}
/**
- * Return the first subdomain name in a host name.
- */
-const string subdomain(const string& host) {
- return substr(host, 0, find(host, '.'));
-}
-
-/**
* Return true if a request is targeting a virtual host.
*/
const bool isVirtualHostRequest(const server_rec* s, request_rec* r) {
@@ -190,6 +183,16 @@ const string contentType(const request_r
}
/**
+ * Return the cookie header of a request.
+ */
+const string cookie(const request_rec* r) {
+ const char* c = apr_table_get(r->headers_in, "Cookie");
+ if (c == NULL)
+ return "";
+ return c;
+}
+
+/**
* Return the remaining part of a uri after the given path (aka the path info.)
*/
const list<value> pathInfo(const list<value>& uri, const list<value>& path) {
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=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp Mon May 23 06:50:15
2011
@@ -141,7 +141,7 @@ int tunnel(conn_rec* conn, const string&
apr_socket_t* csock =
(apr_socket_t*)ap_get_module_config(conn->conn_config, &core_module);
// Open connection to target
- http::CURLSession cs(ca, cert, key);
+ http::CURLSession cs(ca, cert, key, "");
const failable<bool> crc = http::connect(url, cs);
if (!hasContent(crc))
return abort(conn, csock, reason(crc));
Modified: tuscany/sca-cpp/trunk/modules/http/openauth.hpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/openauth.hpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/openauth.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/http/openauth.hpp Mon May 23 06:50:15 2011
@@ -63,9 +63,9 @@ const maybe<string> sessionID(const list
}
const maybe<string> sessionID(const request_rec* r) {
- const char* c = apr_table_get(r->headers_in, "Cookie");
+ const string c = httpd::cookie(r);
debug(c, "openauth::sessionid::cookies");
- if (c == NULL)
+ if (length(c) == 0)
return maybe<string>();
return sessionID(tokenize(";", c));
}
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=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp Mon May 23 06:50:15 2011
@@ -493,7 +493,7 @@ void childInit(apr_pool_t* p, server_rec
sc.mc = *(new (gc_new<memcache::MemCached>())
memcache::MemCached(sc.mcaddrs));
// Setup a CURL session
- sc.cs = *(new (gc_new<http::CURLSession>()) http::CURLSession(sc.ca,
sc.cert, sc.key));
+ sc.cs = *(new (gc_new<http::CURLSession>()) http::CURLSession(sc.ca,
sc.cert, sc.key, ""));
// Merge the updated configuration into the virtual hosts
postConfigMerge(sc, s->next);
Modified: tuscany/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp Mon May 23 06:50:15 2011
@@ -345,7 +345,7 @@ void childInit(apr_pool_t* p, server_rec
sc.mc = *(new (gc_new<memcache::MemCached>())
memcache::MemCached(sc.mcaddrs));
// Setup a CURL session
- sc.cs = *(new (gc_new<http::CURLSession>()) http::CURLSession(sc.ca,
sc.cert, sc.key));
+ sc.cs = *(new (gc_new<http::CURLSession>()) http::CURLSession(sc.ca,
sc.cert, sc.key, ""));
// Merge the updated configuration into the virtual hosts
postConfigMerge(sc, s->next);
Modified: tuscany/sca-cpp/trunk/modules/server/client-test.hpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/client-test.hpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/client-test.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/server/client-test.hpp Mon May 23 06:50:15
2011
@@ -46,7 +46,7 @@ ostream* curlWriter(const string& s, ost
const bool testGet() {
gc_scoped_pool pool;
- http::CURLSession ch("", "", "");
+ http::CURLSession ch("", "", "", "");
{
ostringstream os;
const failable<list<ostream*> > r = http::get<ostream*>(curlWriter,
&os, "http://localhost:8090/index.html", ch);
@@ -76,7 +76,7 @@ struct getLoop {
const bool testGetPerf() {
gc_scoped_pool pool;
- http::CURLSession ch("", "", "");
+ http::CURLSession ch("", "", "", "");
const lambda<bool()> gl = getLoop(ch);
cout << "Static GET test " << time(gl, 5, 200) << " ms" << endl;
return true;
@@ -84,7 +84,7 @@ const bool testGetPerf() {
const bool testEval() {
gc_scoped_pool pool;
- http::CURLSession ch("", "", "");
+ http::CURLSession ch("", "", "", "");
const value val = content(http::evalExpr(mklist<value>(string("echo"),
string("Hello")), testURI, ch));
assert(val == string("Hello"));
return true;
@@ -119,7 +119,7 @@ struct blobEvalLoop {
const bool testEvalPerf() {
gc_scoped_pool pool;
- http::CURLSession ch("", "", "");
+ http::CURLSession ch("", "", "", "");
const lambda<bool()> el = evalLoop(testURI, ch);
cout << "JSON-RPC eval echo test " << time(el, 5, 200) << " ms" << endl;
@@ -139,7 +139,7 @@ bool testPost() {
+ (list<value>() + "title" + string("item"))
+ (list<value>() + "id" +
string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ i);
- http::CURLSession ch("", "", "");
+ http::CURLSession ch("", "", "", "");
const failable<value> id = http::post(a, testURI, ch);
assert(hasContent(id));
return true;
@@ -174,7 +174,7 @@ struct postBlobLoop {
const bool testPostPerf() {
gc_scoped_pool pool;
- http::CURLSession ch("", "", "");
+ http::CURLSession ch("", "", "", "");
{
const list<value> i = list<value>() + "content" + (list<value>() +
"item"
+ (list<value>() + "name" + string("Apple"))
@@ -206,7 +206,7 @@ const bool testPostPerf() {
const bool postThread(const string& uri, const int count, const value& val) {
gc_scoped_pool pool;
- http::CURLSession ch("", "", "");
+ http::CURLSession ch("", "", "", "");
const lambda<bool()> pl = postLoop(uri, val, ch);
time(pl, 0, count);
return true;
@@ -263,7 +263,7 @@ const bool testPostThreadPerf() {
const bool postProc(const string& uri, const int count, const value& val) {
gc_scoped_pool pool;
- http::CURLSession ch("", "", "");
+ http::CURLSession ch("", "", "", "");
const lambda<bool()> pl = postLoop(uri, val, ch);
time(pl, 0, count);
return true;
@@ -333,7 +333,7 @@ const bool testPut() {
+ (list<value>() + "title" + string("item"))
+ (list<value>() + "id" +
string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"))
+ i);
- http::CURLSession ch("", "", "");
+ http::CURLSession ch("", "", "", "");
value rc = content(http::put(a, testURI + "/111", ch));
assert(rc == value(true));
return true;
@@ -341,7 +341,7 @@ const bool testPut() {
const bool testDel() {
gc_scoped_pool pool;
- http::CURLSession ch("", "", "");
+ http::CURLSession ch("", "", "", "");
value rc = content(http::del(testURI + "/111", ch));
assert(rc == value(true));
return true;
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=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp Mon May 23 06:50:15 2011
@@ -97,6 +97,25 @@ const failable<value> failableResult(con
}
/**
+ * Store current HTTP request for access from property and proxy lambda
functions.
+ */
+#ifdef WANT_THREADS
+__thread
+#endif
+request_rec* currentRequest = NULL;
+
+class ScopedRequest {
+public:
+ ScopedRequest(request_rec* r) {
+ currentRequest = r;
+ }
+
+ ~ScopedRequest() {
+ currentRequest = NULL;
+ }
+};
+
+/**
* Handle an HTTP GET.
*/
const failable<int> get(request_rec* r, const lambda<value(const
list<value>&)>& impl) {
@@ -311,7 +330,7 @@ const failable<int> del(request_rec* r,
int translate(request_rec *r) {
if(r->method_number != M_GET && r->method_number != M_POST &&
r->method_number != M_PUT && r->method_number != M_DELETE)
return DECLINED;
- if (strncmp(r->uri, "/components/", 12) != 0)
+ if (strncmp(r->uri, "/components/", 12) != 0 && strncmp(r->uri, "/c/", 3)
!= 0)
return DECLINED;
r->handler = "mod_tuscany_eval";
return OK;
@@ -323,7 +342,7 @@ int translate(request_rec *r) {
const value mkhttpProxy(const ServerConf& sc, const string& ref, const string&
base) {
const string uri = base + ref;
debug(uri, "modeval::mkhttpProxy::uri");
- return lambda<value(const list<value>&)>(http::proxy(uri, sc.ca, sc.cert,
sc.key, sc.p));
+ return lambda<value(const list<value>&)>(http::proxy(uri, sc.ca, sc.cert,
sc.key, "", sc.p));
}
/**
@@ -331,7 +350,7 @@ const value mkhttpProxy(const ServerConf
*/
const value mkhttpProxy(const ServerConf& sc, const string& uri) {
debug(uri, "modeval::mkhttpProxy::uri");
- return lambda<value(const list<value>&)>(http::proxy(uri, "", "", "",
sc.p));
+ return lambda<value(const list<value>&)>(http::proxy(uri, "", "", "", "",
sc.p));
}
/**
@@ -342,17 +361,7 @@ public:
implProxy(const ServerConf& sc, const value& name) : sc(sc), name(name) {
}
- const value operator()(const list<value>& params) const {
- debug(name, "modeval::implProxy::name");
- debug(params, "modeval::implProxy::input");
-
- // If no component name was configured, use the first param as
component name
- const value cname = isNil(name)? cadr(params) : name;
- const list<value> aparams = isNil(name)? cons<value>(car(params),
cddr(params)) : params;
- if (isNil(name)) {
- debug(cname, "modeval::implProxy::wiredByImpl::name");
- debug(aparams, "modeval::implProxy::wiredByImpl::input");
- }
+ const value callImpl(const value& cname, const list<value>& aparams) const
{
// Lookup the component implementation
const list<value> impl(assoctree<value>(cname, sc.implTree));
@@ -369,6 +378,43 @@ public:
return content(val);
}
+ const value operator()(const list<value>& params) const {
+ debug(name, "modeval::implProxy::name");
+ debug(params, "modeval::implProxy::input");
+
+ // If the reference was 'wiredByImpl' use the first param as target
+ if (isNil(name)) {
+ const value uri = cadr(params);
+ const list<value> aparams = cons<value>(car(params), cddr(params));
+ debug(uri, "modeval::implProxy::wiredByImpl::uri");
+ debug(aparams, "modeval::implProxy::wiredByImpl::input");
+
+ // Use an HTTP proxy if the target is an absolute http:// target
+ if (httpd::isAbsolute(uri)) {
+ gc_pool p(currentRequest->pool);
+
+ // Pass our certificate and the cookie from the current request
+ // if the target is in the same domain
+ if (http::topDomain(http::hostName(uri, p)) ==
http::topDomain(httpd::hostName(currentRequest))) {
+ debug(uri, "modeval::implProxy::httpproxy::samedomain");
+ const lambda<value(const list<value>&)> px =
lambda<value(const list<value>&)>(http::proxy(uri, sc.ca, sc.cert, sc.key,
httpd::cookie(currentRequest), p));
+ return px(aparams);
+ }
+
+ // No certificate or cookie on a cross domain call
+ debug(uri, "modeval::implProxy::httpproxy::crossdomain");
+ const lambda<value(const list<value>&)> px =
lambda<value(const list<value>&)>(http::proxy(uri, "", "", "", "", p));
+ return px(aparams);
+ }
+
+ // Call the component implementation
+ return callImpl(uri, aparams);
+ }
+
+ // Call the component implementation
+ return callImpl(name, params);
+ }
+
private:
const ServerConf& sc;
const value name;
@@ -380,9 +426,43 @@ const value mkimplProxy(const ServerConf
}
/**
+ * Return a proxy lambda for an unwired reference.
+ */
+class unwiredProxy {
+public:
+ unwiredProxy(const value& name) : name(name) {
+ }
+
+ const value operator()(const list<value>& params) const {
+ debug(name, "modeval::unwiredProxy::name");
+ debug(params, "modeval::unwiredProxy::input");
+
+ // Get function returns a default empty value
+ if (car(params) == "get") {
+ debug(value(), "modeval::unwiredProxy::result");
+ return value();
+ }
+
+ // All other functions return a failure
+ return mkfailure<value>(string("Reference is not wired: ") + name);
+ }
+
+private:
+ const value name;
+};
+
+/**
+ * Make a proxy lambda for an unwired reference.
+ */
+const value mkunwiredProxy(const string& ref) {
+ debug(ref, "modeval::mkunwiredProxy::ref");
+ return lambda<value(const list<value>&)>(unwiredProxy(ref));
+}
+
+/**
* Convert a list of component references to a list of proxy lambdas.
*/
-const value mkrefProxy(const ServerConf& sc, const value& ref, const string&
base) {
+const value mkrefProxy(const ServerConf& sc, const value& ref, unused const
string& base) {
const value target = scdl::target(ref);
const bool wbyimpl = scdl::wiredByImpl(ref);
debug(ref, "modeval::mkrefProxy::ref");
@@ -393,7 +473,7 @@ const value mkrefProxy(const ServerConf&
if (wbyimpl)
return mkimplProxy(sc, value());
if (isNil(target))
- return mkhttpProxy(sc, scdl::name(ref), base);
+ return mkunwiredProxy(scdl::name(ref));
if (httpd::isAbsolute(target))
return mkhttpProxy(sc, target);
return mkimplProxy(sc, car(pathValues(target)));
@@ -406,25 +486,6 @@ const list<value> refProxies(const Serve
}
/**
- * Store current HTTP request for access from property lambda functions.
- */
-#ifdef WANT_THREADS
-__thread
-#endif
-request_rec* currentRequest = NULL;
-
-class ScopedRequest {
-public:
- ScopedRequest(request_rec* r) {
- currentRequest = r;
- }
-
- ~ScopedRequest() {
- currentRequest = NULL;
- }
-};
-
-/**
* Convert a list of component properties to a list of lambda functions that
just return
* the property value. The host, user and email properties are configured with
the values
* from the HTTP request, if any.
@@ -682,7 +743,7 @@ const failable<bool> virtualHostConfig(S
// Resolve the configured virtual contribution under
// the virtual host's SCA contribution root
- vsc.contributionPath = vsc.virtualHostContributionPath +
httpd::subdomain(httpd::hostName(r)) + "/";
+ vsc.contributionPath = vsc.virtualHostContributionPath +
http::subDomain(httpd::hostName(r)) + "/";
vsc.compositeName = vsc.virtualHostCompositeName;
// Chdir to the virtual host's contribution
Modified: tuscany/sca-cpp/trunk/modules/server/mod-wiring.cpp
URL:
http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/mod-wiring.cpp?rev=1126336&r1=1126335&r2=1126336&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/mod-wiring.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/server/mod-wiring.cpp Mon May 23 06:50:15 2011
@@ -33,6 +33,7 @@
#include "value.hpp"
#include "monad.hpp"
#include "../scdl/scdl.hpp"
+#include "../http/http.hpp"
#include "../http/httpd.hpp"
extern "C" {
@@ -292,7 +293,7 @@ const failable<bool> virtualHostConfig(S
// Resolve the configured virtual contribution under
// the virtual host's SCA contribution root
- sc.contributionPath = sc.virtualHostContributionPath +
httpd::subdomain(httpd::hostName(r)) + "/";
+ sc.contributionPath = sc.virtualHostContributionPath +
http::subDomain(httpd::hostName(r)) + "/";
sc.compositeName = sc.virtualHostCompositeName;
// Configure the wiring for the deployed components
@@ -309,7 +310,7 @@ int translate(request_rec *r) {
return DECLINED;
// No translation needed for a component or tunnel request
- if (!strncmp(r->uri, "/components/", 12))
+ if (!strncmp(r->uri, "/components/", 12) || !strncmp(r->uri, "/c/", 3))
return DECLINED;
// Create a scoped memory pool
@@ -328,7 +329,7 @@ int translate(request_rec *r) {
}
// Translate a component reference request
- if (!strncmp(r->uri, "/references/", 12))
+ if (!strncmp(r->uri, "/references/", 12) || !strncmp(r->uri, "/r/", 3))
return translateReference(usevh? vhc.sc: sc, r);
// Translate a service request