summaryrefslogtreecommitdiff
path: root/src/libfast/request.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libfast/request.c')
-rw-r--r--src/libfast/request.c82
1 files changed, 42 insertions, 40 deletions
diff --git a/src/libfast/request.c b/src/libfast/request.c
index 96dfab8e7..3f4894c45 100644
--- a/src/libfast/request.c
+++ b/src/libfast/request.c
@@ -20,10 +20,13 @@
#include <library.h>
#include <debug.h>
#include <stdlib.h>
-#include <string.h>
#include <pthread.h>
+#include <string.h>
#include <ClearSilver/ClearSilver.h>
+#include <threading/thread.h>
+#include <threading/thread_value.h>
+
typedef struct private_request_t private_request_t;
/**
@@ -35,32 +38,32 @@ struct private_request_t {
* public functions
*/
request_t public;
-
+
/**
* FastCGI request object
*/
FCGX_Request req;
-
+
/**
* length of the req.envp array
*/
int req_env_len;
-
+
/**
* ClearSilver CGI Kit context
*/
CGI *cgi;
-
+
/**
* ClearSilver HDF dataset for this request
*/
HDF *hdf;
-
- /**
+
+ /**
* close the session?
*/
bool closed;
-
+
/**
* reference count
*/
@@ -68,11 +71,10 @@ struct private_request_t {
};
/**
- * key to a the threads "this" request, used for ClearSilver cgiwrap callbacks.
* ClearSilver cgiwrap is not threadsave, so we use a private
* context for each thread.
*/
-static pthread_key_t this_key;
+static thread_value_t *thread_this;
/**
* control variable for pthread_once
@@ -84,8 +86,8 @@ pthread_once_t once = PTHREAD_ONCE_INIT;
*/
static int read_cb(void *null, char *buf, int size)
{
- private_request_t *this = (private_request_t*)pthread_getspecific(this_key);
-
+ private_request_t *this = (private_request_t*)thread_this->get(thread_this);
+
return FCGX_GetStr(buf, size, this->req.in);
}
@@ -94,8 +96,8 @@ static int read_cb(void *null, char *buf, int size)
*/
static int writef_cb(void *null, const char *format, va_list args)
{
- private_request_t *this = (private_request_t*)pthread_getspecific(this_key);
-
+ private_request_t *this = (private_request_t*)thread_this->get(thread_this);
+
FCGX_VFPrintF(this->req.out, format, args);
return 0;
}
@@ -104,8 +106,8 @@ static int writef_cb(void *null, const char *format, va_list args)
*/
static int write_cb(void *null, const char *buf, int size)
{
- private_request_t *this = (private_request_t*)pthread_getspecific(this_key);
-
+ private_request_t *this = (private_request_t*)thread_this->get(thread_this);
+
return FCGX_PutStr(buf, size, this->req.out);
}
@@ -115,8 +117,8 @@ static int write_cb(void *null, const char *buf, int size)
static char *getenv_cb(void *null, const char *key)
{
char *value;
- private_request_t *this = (private_request_t*)pthread_getspecific(this_key);
-
+ private_request_t *this = (private_request_t*)thread_this->get(thread_this);
+
value = FCGX_GetParam(key, this->req.envp);
return value ? strdup(value) : NULL;
}
@@ -137,7 +139,7 @@ static int iterenv_cb(void *null, int num, char **key, char **value)
{
*key = NULL;
*value = NULL;
- private_request_t *this = (private_request_t*)pthread_getspecific(this_key);
+ private_request_t *this = (private_request_t*)thread_this->get(thread_this);
if (num < this->req_env_len)
{
char *eq;
@@ -157,7 +159,7 @@ static int iterenv_cb(void *null, int num, char **key, char **value)
}
return 0;
}
-
+
/**
* Implementation of request_t.get_cookie.
*/
@@ -165,7 +167,7 @@ static char* get_cookie(private_request_t *this, char *name)
{
return hdf_get_valuef(this->hdf, "Cookie.%s", name);
}
-
+
/**
* Implementation of request_t.get_path.
*/
@@ -206,12 +208,12 @@ static char* get_query_data(private_request_t *this, char *name)
*/
static void add_cookie(private_request_t *this, char *name, char *value)
{
- pthread_setspecific(this_key, this);
+ thread_this->set(thread_this, this);
cgi_cookie_set (this->cgi, name, value,
FCGX_GetParam("SCRIPT_NAME", this->req.envp),
NULL, NULL, 0, 0);
}
-
+
/**
* Implementation of request_t.redirect.
*/
@@ -246,7 +248,7 @@ static char* get_base(private_request_t *this)
{
return FCGX_GetParam("SCRIPT_NAME", this->req.envp);
}
-
+
/**
* Implementation of request_t.session_closed.
*/
@@ -279,8 +281,8 @@ static void serve(private_request_t *this, char *headers, chunk_t chunk)
static void render(private_request_t *this, char *template)
{
NEOERR* err;
-
- pthread_setspecific(this_key, this);
+
+ thread_this->set(thread_this, this);
err = cgi_display(this->cgi, template);
if (err)
{
@@ -327,8 +329,8 @@ static void setf(private_request_t *this, char *format, ...)
va_start(args, format);
hdf_set_valuevf(this->hdf, format, args);
va_end(args);
-}
-
+}
+
/**
* Implementation of request_t.get_ref.
*/
@@ -345,7 +347,7 @@ static void destroy(private_request_t *this)
{
if (ref_put(&this->ref))
{
- pthread_setspecific(this_key, this);
+ thread_this->set(thread_this, this);
cgi_destroy(&this->cgi);
FCGX_Finish_r(&this->req);
free(this);
@@ -359,8 +361,8 @@ static void destroy(private_request_t *this)
static void init(void)
{
cgiwrap_init_emu(NULL, read_cb, writef_cb, write_cb,
- getenv_cb, putenv_cb, iterenv_cb);
- pthread_key_create(&this_key, NULL);
+ getenv_cb, putenv_cb, iterenv_cb);
+ thread_this = thread_value_create(NULL);
}
/*
@@ -371,14 +373,14 @@ request_t *request_create(int fd, bool debug)
NEOERR* err;
private_request_t *this = malloc_thing(private_request_t);
bool failed = FALSE;
-
- pthread_cleanup_push(free, this);
+
+ thread_cleanup_push(free, this);
if (FCGX_InitRequest(&this->req, fd, 0) != 0 ||
FCGX_Accept_r(&this->req) != 0)
{
failed = TRUE;
}
- pthread_cleanup_pop(failed);
+ thread_cleanup_pop(failed);
if (failed)
{
return NULL;
@@ -402,18 +404,18 @@ request_t *request_create(int fd, bool debug)
this->public.setf = (void(*)(request_t*, char *format, ...))setf;
this->public.get_ref = (request_t*(*)(request_t*))get_ref;
this->public.destroy = (void(*)(request_t*))destroy;
-
+
pthread_once(&once, init);
- pthread_setspecific(this_key, this);
-
+ thread_this->set(thread_this, this);
+
this->ref = 1;
this->closed = FALSE;
- this->req_env_len = 0;
+ this->req_env_len = 0;
while (this->req.envp[this->req_env_len] != NULL)
{
this->req_env_len++;
}
-
+
err = hdf_init(&this->hdf);
if (!err)
{
@@ -425,7 +427,7 @@ request_t *request_create(int fd, bool debug)
hdf_set_value(this->hdf, "Config.CompressionEnabled", "1");
hdf_set_value(this->hdf, "Config.WhiteSpaceStrip", "2");
}
-
+
err = cgi_init(&this->cgi, this->hdf);
if (!err)
{