Add vrequest "environment" (a GString -> GString hashtable)

personal/stbuehler/wip
Stefan Bühler 15 years ago
parent d30e1b018a
commit c56ade056f

@ -40,6 +40,7 @@
#include <lighttpd/http_request_parser.h>
#include <lighttpd/request.h>
#include <lighttpd/response.h>
#include <lighttpd/environment.h>
#include <lighttpd/virtualrequest.h>
#include <lighttpd/log.h>

@ -0,0 +1,20 @@
#ifndef _LIGHTTPD_ENVIRONMENT_H_
#define _LIGHTTPD_ENVIRONMENT_H_
#ifndef _LIGHTTPD_BASE_H_
#error Please include <lighttpd/base.h> instead of this file
#endif
struct environment {
GHashTable *table;
};
LI_API void environment_init(environment *env);
LI_API void environment_reset(environment *env);
LI_API void environment_clear(environment *env);
LI_API void environment_set(environment *env, const gchar *key, size_t keylen, const gchar *val, size_t valuelen);
LI_API void environment_remove(environment *env, const gchar *key, size_t keylen);
LI_API GString* environment_get(environment *env, const gchar *key, size_t keylen);
#endif

@ -62,6 +62,10 @@ typedef struct condition condition;
struct connection;
typedef struct connection connection;
/* environment.h */
struct environment;
typedef struct environment environment;
/* hhtp_headers.h */
struct http_header;

@ -67,6 +67,8 @@ struct vrequest {
physical physical;
response response;
environment env;
/* -> vr_in -> filters_in -> in -> handle -> out -> filters_out -> vr_out -> */
gboolean cq_memory_limit_hit; /* stop feeding chunkqueues with memory chunks */
filters filters_in, filters_out;

@ -282,6 +282,7 @@ SET(COMMON_SRC
condition_parsers.c
config_parser.c
connection.c
environment.c
filter_chunked.c
http_headers.c
http_request_parser.c
@ -334,9 +335,9 @@ SET(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd)
SET(COMMON_LDFLAGS "${LUA_LDFLAGS} ${EV_LDFLAGS} ${GTHREAD_LDFLAGS} ${GMODULE_LDFLAGS}")
SET(COMMON_CFLAGS "${LUA_CFLAGS} ${EV_CFLAGS} ${GTHREAD_CFLAGS} ${GMODULE_CFLAGS}")
ADD_AND_INSTALL_LIBRARY(mod_balancer "modules/mod_balancer.c")
ADD_AND_INSTALL_LIBRARY(mod_fortune "modules/mod_fortune.c")
ADD_AND_INSTALL_LIBRARY(mod_status "modules/mod_status.c")
ADD_AND_INSTALL_LIBRARY(mod_balancer "modules/mod_balancer.c")
ADD_TARGET_PROPERTIES(lighttpd LINK_FLAGS ${COMMON_LDFLAGS})
ADD_TARGET_PROPERTIES(lighttpd COMPILE_FLAGS ${COMMON_CFLAGS})

@ -0,0 +1,36 @@
#include <lighttpd/base.h>
static void _hash_free_gstring(gpointer data) {
g_string_free((GString*) data, TRUE);
}
void environment_init(environment *env) {
env->table = g_hash_table_new_full(
(GHashFunc) g_string_hash, (GEqualFunc) g_string_equal,
_hash_free_gstring, _hash_free_gstring);
}
void environment_reset(environment *env) {
g_hash_table_remove_all(env->table);
}
void environment_clear(environment *env) {
g_hash_table_destroy(env->table);
}
void environment_set(environment *env, const gchar *key, size_t keylen, const gchar *val, size_t valuelen) {
GString *skey = g_string_new_len(key, keylen);
GString *sval = g_string_new_len(val, valuelen);
g_hash_table_insert(env->table, skey, sval);
}
void environment_remove(environment *env, const gchar *key, size_t keylen) {
const GString skey = { (gchar*) key, keylen, 0 }; /* fake a constant GString */
g_hash_table_remove(env->table, &skey);
}
GString* environment_get(environment *env, const gchar *key, size_t keylen) {
const GString skey = { (gchar*) key, keylen, 0 }; /* fake a constant GString */
return (GString*) g_hash_table_lookup(env->table, &skey);
}

@ -54,6 +54,7 @@ vrequest* vrequest_new(connection *con, vrequest_handler handle_response_headers
request_init(&vr->request);
physical_init(&vr->physical);
response_init(&vr->response);
environment_init(&vr->env);
filters_init(&vr->filters_in);
filters_init(&vr->filters_out);
@ -68,15 +69,16 @@ vrequest* vrequest_new(connection *con, vrequest_handler handle_response_headers
}
void vrequest_free(vrequest* vr) {
action_stack_clear(vr, &vr->action_stack);
request_clear(&vr->request);
physical_clear(&vr->physical);
response_clear(&vr->response);
environment_clear(&vr->env);
filters_clean(&vr->filters_in);
filters_clean(&vr->filters_out);
action_stack_clear(vr, &vr->action_stack);
if (vr->job_queue_link) {
g_queue_delete_link(&vr->con->wrk->job_queue, vr->job_queue_link);
vr->job_queue_link = NULL;
@ -88,6 +90,8 @@ void vrequest_free(vrequest* vr) {
}
void vrequest_reset(vrequest *vr) {
action_stack_reset(vr, &vr->action_stack);
vr->state = VRS_CLEAN;
vr->handle_request_body = NULL;
@ -95,12 +99,11 @@ void vrequest_reset(vrequest *vr) {
request_reset(&vr->request);
physical_reset(&vr->physical);
response_reset(&vr->response);
environment_reset(&vr->env);
filters_reset(&vr->filters_in);
filters_reset(&vr->filters_out);
action_stack_reset(vr, &vr->action_stack);
if (vr->job_queue_link) {
g_queue_delete_link(&vr->con->wrk->job_queue, vr->job_queue_link);
vr->job_queue_link = NULL;

Loading…
Cancel
Save