summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/http
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sca-cpp/trunk/modules/http/curl-connect.cpp2
-rw-r--r--sca-cpp/trunk/modules/http/curl-get.cpp2
-rw-r--r--sca-cpp/trunk/modules/http/curl-test.cpp6
-rw-r--r--sca-cpp/trunk/modules/http/http.hpp45
-rw-r--r--sca-cpp/trunk/modules/http/httpd.hpp17
-rw-r--r--sca-cpp/trunk/modules/http/mod-ssltunnel.cpp2
-rw-r--r--sca-cpp/trunk/modules/http/openauth.hpp4
7 files changed, 58 insertions, 20 deletions
diff --git a/sca-cpp/trunk/modules/http/curl-connect.cpp b/sca-cpp/trunk/modules/http/curl-connect.cpp
index 432ccc2000..0bb193623f 100644
--- a/sca-cpp/trunk/modules/http/curl-connect.cpp
+++ b/sca-cpp/trunk/modules/http/curl-connect.cpp
@@ -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));
diff --git a/sca-cpp/trunk/modules/http/curl-get.cpp b/sca-cpp/trunk/modules/http/curl-get.cpp
index 762423bebb..cd575ccc66 100644
--- a/sca-cpp/trunk/modules/http/curl-get.cpp
+++ b/sca-cpp/trunk/modules/http/curl-get.cpp
@@ -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;
diff --git a/sca-cpp/trunk/modules/http/curl-test.cpp b/sca-cpp/trunk/modules/http/curl-test.cpp
index a7b8fd90b6..2a1803b873 100644
--- a/sca-cpp/trunk/modules/http/curl-test.cpp
+++ b/sca-cpp/trunk/modules/http/curl-test.cpp
@@ -40,7 +40,7 @@ ostream* curlWriter(const string& s, ostream* os) {
}
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();
diff --git a/sca-cpp/trunk/modules/http/http.hpp b/sca-cpp/trunk/modules/http/http.hpp
index 1a207669c0..d4159add29 100644
--- a/sca-cpp/trunk/modules/http/http.hpp
+++ b/sca-cpp/trunk/modules/http/http.hpp
@@ -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& url, const CURLSession& cs) {
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 string& url, const CURLSession& cs) {
/**
* 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;
};
diff --git a/sca-cpp/trunk/modules/http/httpd.hpp b/sca-cpp/trunk/modules/http/httpd.hpp
index 86a89d8823..534fd78503 100644
--- a/sca-cpp/trunk/modules/http/httpd.hpp
+++ b/sca-cpp/trunk/modules/http/httpd.hpp
@@ -145,13 +145,6 @@ const string hostName(request_rec* r, const string& def = "localhost") {
}
/**
- * 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_rec* 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) {
diff --git a/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp b/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp
index edbc8f3b99..0fd347c469 100644
--- a/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp
+++ b/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp
@@ -141,7 +141,7 @@ int tunnel(conn_rec* conn, const string& ca, const string& cert, const string& k
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));
diff --git a/sca-cpp/trunk/modules/http/openauth.hpp b/sca-cpp/trunk/modules/http/openauth.hpp
index 9b49cfa4c2..d7377324d9 100644
--- a/sca-cpp/trunk/modules/http/openauth.hpp
+++ b/sca-cpp/trunk/modules/http/openauth.hpp
@@ -63,9 +63,9 @@ const maybe<string> sessionID(const list<string> c) {
}
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));
}