2008-10-25 12:53:57 +00:00
|
|
|
|
2008-11-16 20:33:53 +00:00
|
|
|
#include <lighttpd/base.h>
|
|
|
|
#include <lighttpd/plugin_core.h>
|
2008-10-25 12:53:57 +00:00
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
static void filters_init(liFilters *fs) {
|
2008-10-25 12:53:57 +00:00
|
|
|
fs->queue = g_ptr_array_new();
|
2009-07-09 20:17:24 +00:00
|
|
|
fs->in = li_chunkqueue_new();
|
|
|
|
fs->out = li_chunkqueue_new();
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
static void filters_clean(liVRequest *vr, liFilters *fs) {
|
2008-10-25 12:53:57 +00:00
|
|
|
guint i;
|
|
|
|
for (i = 0; i < fs->queue->len; i++) {
|
2009-07-08 19:06:07 +00:00
|
|
|
liFilter *f = (liFilter*) g_ptr_array_index(fs->queue, i);
|
2009-03-12 20:08:27 +00:00
|
|
|
if (f->handle_free && f->param) f->handle_free(vr, f);
|
2009-07-09 20:17:24 +00:00
|
|
|
if (i > 0) li_chunkqueue_free(fs->in);
|
2009-07-08 19:06:07 +00:00
|
|
|
g_slice_free(liFilter, f);
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
|
|
|
g_ptr_array_free(fs->queue, TRUE);
|
2009-07-09 20:17:24 +00:00
|
|
|
li_chunkqueue_free(fs->in);
|
|
|
|
li_chunkqueue_free(fs->out);
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
static void filters_reset(liVRequest *vr, liFilters *fs) {
|
2008-10-25 12:53:57 +00:00
|
|
|
guint i;
|
|
|
|
for (i = 0; i < fs->queue->len; i++) {
|
2009-07-08 19:06:07 +00:00
|
|
|
liFilter *f = (liFilter*) g_ptr_array_index(fs->queue, i);
|
2009-03-12 20:08:27 +00:00
|
|
|
if (f->handle_free && f->param) f->handle_free(vr, f);
|
2009-09-26 19:13:27 +00:00
|
|
|
if (i > 0) li_chunkqueue_free(f->in);
|
2009-07-08 19:06:07 +00:00
|
|
|
g_slice_free(liFilter, f);
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
|
|
|
g_ptr_array_set_size(fs->queue, 0);
|
2009-07-09 20:17:24 +00:00
|
|
|
li_chunkqueue_reset(fs->in);
|
|
|
|
li_chunkqueue_reset(fs->out);
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
|
|
|
|
2009-09-29 09:45:55 +00:00
|
|
|
static gboolean filters_handle_out_close(liVRequest *vr, liFilters *fs) {
|
|
|
|
guint i;
|
|
|
|
if (0 == fs->queue->len) {
|
|
|
|
if (fs->out->is_closed) fs->in->is_closed = TRUE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
for (i = fs->queue->len; i-- > 0; ) {
|
|
|
|
liFilter *f = (liFilter*) g_ptr_array_index(fs->queue, i);
|
|
|
|
if (f->out->is_closed && !f->knows_out_is_closed) {
|
|
|
|
f->knows_out_is_closed = TRUE;
|
|
|
|
switch (f->handle_data(vr, f)) {
|
|
|
|
case LI_HANDLER_GO_ON:
|
|
|
|
break;
|
|
|
|
case LI_HANDLER_COMEBACK:
|
|
|
|
li_vrequest_joblist_append(vr);
|
|
|
|
break;
|
|
|
|
case LI_HANDLER_WAIT_FOR_EVENT:
|
|
|
|
break; /* ignore - filter has to call li_vrequest_joblist_append(vr); */
|
|
|
|
case LI_HANDLER_ERROR:
|
2009-12-20 22:45:03 +00:00
|
|
|
if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) {
|
|
|
|
VR_DEBUG(vr, "filter %i return an error", i);
|
|
|
|
}
|
2009-09-29 09:45:55 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
static gboolean filters_run(liVRequest *vr, liFilters *fs) {
|
2009-03-11 15:57:07 +00:00
|
|
|
guint i;
|
|
|
|
if (0 == fs->queue->len) {
|
2009-07-09 20:17:24 +00:00
|
|
|
li_chunkqueue_steal_all(fs->out, fs->in);
|
2009-03-11 15:57:07 +00:00
|
|
|
if (fs->in->is_closed) fs->out->is_closed = TRUE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
for (i = 0; i < fs->queue->len; i++) {
|
2009-07-08 19:06:07 +00:00
|
|
|
liFilter *f = (liFilter*) g_ptr_array_index(fs->queue, i);
|
2009-03-12 20:08:27 +00:00
|
|
|
switch (f->handle_data(vr, f)) {
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_GO_ON:
|
2009-03-11 15:57:07 +00:00
|
|
|
break;
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_COMEBACK:
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_joblist_append(vr);
|
2009-03-11 15:57:07 +00:00
|
|
|
break;
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_WAIT_FOR_EVENT:
|
2009-07-09 20:17:24 +00:00
|
|
|
break; /* ignore - filter has to call li_vrequest_joblist_append(vr); */
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_ERROR:
|
2009-12-20 22:45:03 +00:00
|
|
|
if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) {
|
|
|
|
VR_DEBUG(vr, "filter %i return an error", i);
|
|
|
|
}
|
2009-03-11 15:57:07 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2009-09-29 09:45:55 +00:00
|
|
|
f->knows_out_is_closed = f->out->is_closed;
|
|
|
|
if (f->in->is_closed && i > 0) {
|
|
|
|
guint j;
|
|
|
|
for (j = i; j-- > 0; ) {
|
|
|
|
liFilter *g = (liFilter*) g_ptr_array_index(fs->queue, j);
|
|
|
|
if (g->knows_out_is_closed) break;
|
|
|
|
g->knows_out_is_closed = TRUE;
|
|
|
|
switch (f->handle_data(vr, f)) {
|
|
|
|
case LI_HANDLER_GO_ON:
|
|
|
|
break;
|
|
|
|
case LI_HANDLER_COMEBACK:
|
|
|
|
li_vrequest_joblist_append(vr);
|
|
|
|
break;
|
|
|
|
case LI_HANDLER_WAIT_FOR_EVENT:
|
|
|
|
break; /* ignore - filter has to call li_vrequest_joblist_append(vr); */
|
|
|
|
case LI_HANDLER_ERROR:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (!g->in->is_closed) break;
|
2009-03-11 15:57:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-09-29 09:45:55 +00:00
|
|
|
static liFilter* filters_add(liFilters *fs, liFilterHandlerCB handle_data, liFilterFreeCB handle_free, gpointer param) {
|
2009-07-08 19:06:07 +00:00
|
|
|
liFilter *f = g_slice_new0(liFilter);
|
2009-03-11 15:57:07 +00:00
|
|
|
f->out = fs->out;
|
2009-03-12 20:08:27 +00:00
|
|
|
f->param = param;
|
|
|
|
f->handle_data = handle_data;
|
|
|
|
f->handle_free = handle_free;
|
2009-03-11 15:57:07 +00:00
|
|
|
if (0 == fs->queue->len) {
|
|
|
|
f->in = fs->in;
|
|
|
|
} else {
|
2009-07-08 19:06:07 +00:00
|
|
|
liFilter *prev = (liFilter*) g_ptr_array_index(fs->queue, fs->queue->len - 1);
|
2009-07-09 20:17:24 +00:00
|
|
|
f->in = prev->out = li_chunkqueue_new();
|
|
|
|
li_chunkqueue_set_limit(f->in, fs->in->limit);
|
2009-03-11 15:57:07 +00:00
|
|
|
}
|
|
|
|
g_ptr_array_add(fs->queue, f);
|
2009-09-29 09:45:55 +00:00
|
|
|
return f;
|
2009-03-11 15:57:07 +00:00
|
|
|
}
|
|
|
|
|
2009-09-29 09:45:55 +00:00
|
|
|
liFilter* li_vrequest_add_filter_in(liVRequest *vr, liFilterHandlerCB handle_data, liFilterFreeCB handle_free, gpointer param) {
|
|
|
|
return filters_add(&vr->filters_in, handle_data, handle_free, param);
|
2009-03-11 15:57:07 +00:00
|
|
|
}
|
|
|
|
|
2009-09-29 09:45:55 +00:00
|
|
|
liFilter* li_vrequest_add_filter_out(liVRequest *vr, liFilterHandlerCB handle_data, liFilterFreeCB handle_free, gpointer param) {
|
|
|
|
return filters_add(&vr->filters_out, handle_data, handle_free, param);
|
2009-03-11 15:57:07 +00:00
|
|
|
}
|
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
liVRequest* li_vrequest_new(liConnection *con, liVRequestHandlerCB handle_response_headers, liVRequestHandlerCB handle_response_body, liVRequestHandlerCB handle_response_error, liVRequestHandlerCB handle_request_headers) {
|
2009-07-08 19:06:07 +00:00
|
|
|
liServer *srv = con->srv;
|
|
|
|
liVRequest *vr = g_slice_new0(liVRequest);
|
2008-10-25 12:53:57 +00:00
|
|
|
|
|
|
|
vr->con = con;
|
2009-04-15 10:34:06 +00:00
|
|
|
vr->wrk = con->wrk;
|
2009-07-08 19:06:07 +00:00
|
|
|
vr->ref = g_slice_new0(liVRequestRef);
|
2009-04-14 16:18:25 +00:00
|
|
|
vr->ref->refcount = 1;
|
|
|
|
vr->ref->vr = vr;
|
2009-07-08 19:06:07 +00:00
|
|
|
vr->state = LI_VRS_CLEAN;
|
2008-10-25 12:53:57 +00:00
|
|
|
|
|
|
|
vr->handle_response_headers = handle_response_headers;
|
|
|
|
vr->handle_response_body = handle_response_body;
|
|
|
|
vr->handle_response_error = handle_response_error;
|
|
|
|
vr->handle_request_headers = handle_request_headers;
|
|
|
|
|
2009-01-01 15:44:42 +00:00
|
|
|
vr->plugin_ctx = g_ptr_array_new();
|
|
|
|
g_ptr_array_set_size(vr->plugin_ctx, g_hash_table_size(srv->plugins));
|
2009-07-08 19:06:07 +00:00
|
|
|
vr->options = g_slice_copy(srv->option_def_values->len * sizeof(liOptionValue), srv->option_def_values->data);
|
2010-01-24 20:30:41 +00:00
|
|
|
vr->optionptrs = g_slice_copy(srv->optionptr_def_values->len * sizeof(liOptionPtrValue*), srv->optionptr_def_values->data);
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
for (i = 0; i < srv->optionptr_def_values->len; i++) {
|
|
|
|
if (vr->optionptrs[i]) {
|
|
|
|
g_atomic_int_inc(&vr->optionptrs[i]->refcount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-30 00:21:03 +00:00
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
li_request_init(&vr->request);
|
|
|
|
li_physical_init(&vr->physical);
|
|
|
|
li_response_init(&vr->response);
|
|
|
|
li_environment_init(&vr->env);
|
2008-10-25 12:53:57 +00:00
|
|
|
|
|
|
|
filters_init(&vr->filters_in);
|
|
|
|
filters_init(&vr->filters_out);
|
|
|
|
vr->vr_in = vr->filters_in.in;
|
2009-12-19 21:18:10 +00:00
|
|
|
vr->in_memory = vr->filters_in.out;
|
|
|
|
vr->in = li_chunkqueue_new();
|
2008-10-25 12:53:57 +00:00
|
|
|
vr->out = vr->filters_out.in;
|
|
|
|
vr->vr_out = vr->filters_out.out;
|
|
|
|
|
2009-12-19 21:18:10 +00:00
|
|
|
li_chunkqueue_use_limit(vr->in, vr);
|
|
|
|
li_chunkqueue_set_limit(vr->vr_in, vr->in->limit);
|
|
|
|
li_chunkqueue_set_limit(vr->in_memory, vr->in->limit);
|
|
|
|
li_chunkqueue_use_limit(vr->out, vr);
|
|
|
|
li_chunkqueue_set_limit(vr->vr_out, vr->out->limit);
|
|
|
|
|
|
|
|
vr->in_buffer_state.flush_limit = -1; /* wait until upload is complete */
|
|
|
|
vr->in_buffer_state.split_on_file_chunks = FALSE;
|
|
|
|
|
2009-03-26 22:05:17 +00:00
|
|
|
vr->stat_cache_entries = g_ptr_array_sized_new(2);
|
|
|
|
|
2009-04-14 16:18:25 +00:00
|
|
|
vr->job_queue_link.data = vr;
|
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
li_action_stack_init(&vr->action_stack);
|
2008-10-25 12:53:57 +00:00
|
|
|
|
|
|
|
return vr;
|
|
|
|
}
|
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
void li_vrequest_free(liVRequest* vr) {
|
2010-01-24 20:30:41 +00:00
|
|
|
liServer *srv = vr->wrk->srv;
|
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
li_action_stack_clear(vr, &vr->action_stack);
|
2010-04-03 19:16:11 +00:00
|
|
|
if (vr->state != LI_VRS_CLEAN) {
|
|
|
|
li_plugins_handle_vrclose(vr);
|
|
|
|
}
|
2009-01-01 15:44:42 +00:00
|
|
|
g_ptr_array_free(vr->plugin_ctx, TRUE);
|
2008-12-31 15:23:00 +00:00
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
li_request_clear(&vr->request);
|
|
|
|
li_physical_clear(&vr->physical);
|
|
|
|
li_response_clear(&vr->response);
|
|
|
|
li_environment_clear(&vr->env);
|
2008-10-25 12:53:57 +00:00
|
|
|
|
2009-03-12 20:08:27 +00:00
|
|
|
filters_clean(vr, &vr->filters_in);
|
|
|
|
filters_clean(vr, &vr->filters_out);
|
2009-12-19 21:18:10 +00:00
|
|
|
li_chunkqueue_free(vr->in);
|
|
|
|
li_filter_buffer_on_disk_reset(&vr->in_buffer_state);
|
2008-10-25 12:53:57 +00:00
|
|
|
|
2009-04-14 16:18:25 +00:00
|
|
|
if (g_atomic_int_get(&vr->queued)) { /* atomic access shouldn't be needed here; no one else can access vr here... */
|
2009-04-15 10:34:06 +00:00
|
|
|
g_queue_unlink(&vr->wrk->job_queue, &vr->job_queue_link);
|
2009-04-14 16:18:25 +00:00
|
|
|
g_atomic_int_set(&vr->queued, 0);
|
2008-12-30 20:55:00 +00:00
|
|
|
}
|
|
|
|
|
2010-01-24 20:30:41 +00:00
|
|
|
g_slice_free1(srv->option_def_values->len * sizeof(liOptionValue), vr->options);
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
for (i = 0; i < srv->optionptr_def_values->len; i++) {
|
|
|
|
li_release_optionptr(srv, vr->optionptrs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_slice_free1(srv->optionptr_def_values->len * sizeof(liOptionPtrValue*), vr->optionptrs);
|
2008-12-30 00:21:03 +00:00
|
|
|
|
2009-03-26 22:05:17 +00:00
|
|
|
|
2009-10-05 17:41:48 +00:00
|
|
|
while (vr->stat_cache_entries->len > 0 ) {
|
|
|
|
liStatCacheEntry *sce = g_ptr_array_index(vr->stat_cache_entries, 0);
|
2009-07-09 20:17:24 +00:00
|
|
|
li_stat_cache_entry_release(vr, sce);
|
2009-03-26 22:05:17 +00:00
|
|
|
}
|
|
|
|
g_ptr_array_free(vr->stat_cache_entries, TRUE);
|
|
|
|
|
2009-04-14 16:18:25 +00:00
|
|
|
vr->ref->vr = NULL;
|
|
|
|
if (g_atomic_int_dec_and_test(&vr->ref->refcount)) {
|
2009-07-08 19:06:07 +00:00
|
|
|
g_slice_free(liVRequestRef, vr->ref);
|
2009-04-14 16:18:25 +00:00
|
|
|
}
|
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
g_slice_free(liVRequest, vr);
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
|
|
|
|
2009-10-07 14:02:09 +00:00
|
|
|
void li_vrequest_reset(liVRequest *vr, gboolean keepalive) {
|
2010-01-24 20:30:41 +00:00
|
|
|
liServer *srv = vr->wrk->srv;
|
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
li_action_stack_reset(vr, &vr->action_stack);
|
2010-04-03 19:32:02 +00:00
|
|
|
if (vr->state != LI_VRS_CLEAN) {
|
|
|
|
li_plugins_handle_vrclose(vr);
|
|
|
|
}
|
2009-01-01 15:44:42 +00:00
|
|
|
{
|
|
|
|
gint len = vr->plugin_ctx->len;
|
|
|
|
g_ptr_array_set_size(vr->plugin_ctx, 0);
|
|
|
|
g_ptr_array_set_size(vr->plugin_ctx, len);
|
|
|
|
}
|
2008-12-31 15:23:00 +00:00
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
vr->state = LI_VRS_CLEAN;
|
2008-10-25 12:53:57 +00:00
|
|
|
|
2009-01-01 15:44:42 +00:00
|
|
|
vr->backend = NULL;
|
2008-10-25 12:53:57 +00:00
|
|
|
|
2009-10-07 14:02:09 +00:00
|
|
|
/* don't reset request for keep-alive tracking */
|
|
|
|
if (!keepalive) li_request_reset(&vr->request);
|
2009-07-09 20:17:24 +00:00
|
|
|
li_physical_reset(&vr->physical);
|
|
|
|
li_response_reset(&vr->response);
|
|
|
|
li_environment_reset(&vr->env);
|
2008-10-25 12:53:57 +00:00
|
|
|
|
2009-03-12 20:08:27 +00:00
|
|
|
filters_reset(vr, &vr->filters_in);
|
|
|
|
filters_reset(vr, &vr->filters_out);
|
2009-12-19 21:18:10 +00:00
|
|
|
li_chunkqueue_reset(vr->in);
|
|
|
|
li_filter_buffer_on_disk_reset(&vr->in_buffer_state);
|
|
|
|
vr->in_buffer_state.flush_limit = -1; /* wait until upload is complete */
|
|
|
|
vr->in_buffer_state.split_on_file_chunks = FALSE;
|
|
|
|
|
|
|
|
li_chunkqueue_use_limit(vr->in, vr);
|
|
|
|
li_chunkqueue_set_limit(vr->vr_in, vr->in->limit);
|
|
|
|
li_chunkqueue_set_limit(vr->in_memory, vr->in->limit);
|
|
|
|
li_chunkqueue_use_limit(vr->out, vr);
|
|
|
|
li_chunkqueue_set_limit(vr->vr_out, vr->out->limit);
|
2008-10-25 12:53:57 +00:00
|
|
|
|
2009-04-14 16:18:25 +00:00
|
|
|
if (g_atomic_int_get(&vr->queued)) { /* atomic access shouldn't be needed here; no one else can access vr here... */
|
2009-04-15 10:34:06 +00:00
|
|
|
g_queue_unlink(&vr->wrk->job_queue, &vr->job_queue_link);
|
2009-04-14 16:18:25 +00:00
|
|
|
g_atomic_int_set(&vr->queued, 0);
|
2008-12-30 20:55:00 +00:00
|
|
|
}
|
|
|
|
|
2009-10-05 17:41:48 +00:00
|
|
|
while (vr->stat_cache_entries->len > 0 ) {
|
|
|
|
liStatCacheEntry *sce = g_ptr_array_index(vr->stat_cache_entries, 0);
|
2009-07-09 20:17:24 +00:00
|
|
|
li_stat_cache_entry_release(vr, sce);
|
2009-03-01 20:16:58 +00:00
|
|
|
}
|
|
|
|
|
2010-01-24 20:30:41 +00:00
|
|
|
memcpy(vr->options, srv->option_def_values->data, srv->option_def_values->len * sizeof(liOptionValue));
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
for (i = 0; i < srv->optionptr_def_values->len; i++) {
|
|
|
|
liOptionPtrValue *oval = g_array_index(srv->optionptr_def_values, liOptionPtrValue*, i);
|
|
|
|
if (vr->optionptrs[i] != oval) {
|
|
|
|
li_release_optionptr(srv, vr->optionptrs[i]);
|
|
|
|
g_atomic_int_inc(&oval->refcount);
|
|
|
|
vr->optionptrs[i] = oval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-04-14 16:18:25 +00:00
|
|
|
|
|
|
|
if (1 != g_atomic_int_get(&vr->ref->refcount)) {
|
|
|
|
/* If we are not the only user of vr->ref we have to get a new one and detach the old */
|
|
|
|
vr->ref->vr = NULL;
|
|
|
|
if (g_atomic_int_dec_and_test(&vr->ref->refcount)) {
|
2009-07-08 19:06:07 +00:00
|
|
|
g_slice_free(liVRequestRef, vr->ref);
|
2009-04-14 16:18:25 +00:00
|
|
|
}
|
2009-07-08 19:06:07 +00:00
|
|
|
vr->ref = g_slice_new0(liVRequestRef);
|
2009-04-14 16:18:25 +00:00
|
|
|
vr->ref->refcount = 1;
|
|
|
|
vr->ref->vr = vr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
liVRequestRef* li_vrequest_acquire_ref(liVRequest *vr) {
|
2009-07-08 19:06:07 +00:00
|
|
|
liVRequestRef* vr_ref = vr->ref;
|
2009-04-14 16:18:25 +00:00
|
|
|
g_assert(vr_ref->refcount > 0);
|
|
|
|
g_atomic_int_inc(&vr_ref->refcount);
|
|
|
|
return vr_ref;
|
|
|
|
}
|
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
liVRequest* li_vrequest_release_ref(liVRequestRef *vr_ref) {
|
2009-07-08 19:06:07 +00:00
|
|
|
liVRequest *vr = vr_ref->vr;
|
2009-04-14 16:18:25 +00:00
|
|
|
g_assert(vr_ref->refcount > 0);
|
|
|
|
if (g_atomic_int_dec_and_test(&vr_ref->refcount)) {
|
|
|
|
g_assert(vr == NULL); /* we are the last user, and the ref holded by vr itself is handled extra, so the vr was already reset */
|
2009-07-08 19:06:07 +00:00
|
|
|
g_slice_free(liVRequestRef, vr_ref);
|
2009-04-14 16:18:25 +00:00
|
|
|
}
|
|
|
|
return vr;
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
void li_vrequest_error(liVRequest *vr) {
|
2009-07-08 19:06:07 +00:00
|
|
|
vr->state = LI_VRS_ERROR;
|
2009-01-01 15:44:42 +00:00
|
|
|
vr->out->is_closed = TRUE;
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_joblist_append(vr);
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
void li_vrequest_backend_error(liVRequest *vr, liBackendError berror) {
|
2008-12-31 13:36:24 +00:00
|
|
|
vr->action_stack.backend_failed = TRUE;
|
|
|
|
vr->action_stack.backend_error = berror;
|
2009-07-08 19:06:07 +00:00
|
|
|
vr->state = LI_VRS_HANDLE_REQUEST_HEADERS;
|
2009-01-01 15:44:42 +00:00
|
|
|
vr->backend = NULL;
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_joblist_append(vr);
|
2008-12-31 13:36:24 +00:00
|
|
|
}
|
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
void li_vrequest_backend_overloaded(liVRequest *vr) {
|
|
|
|
li_vrequest_backend_error(vr, BACKEND_OVERLOAD);
|
2009-01-01 15:44:42 +00:00
|
|
|
}
|
2009-07-09 20:17:24 +00:00
|
|
|
void li_vrequest_backend_dead(liVRequest *vr) {
|
|
|
|
li_vrequest_backend_error(vr, BACKEND_DEAD);
|
2008-12-31 13:36:24 +00:00
|
|
|
}
|
|
|
|
|
2009-01-01 15:44:42 +00:00
|
|
|
|
2009-10-07 14:02:09 +00:00
|
|
|
/* resets fields which weren't reset in favor of keep-alive tracking */
|
|
|
|
void li_vrequest_start(liVRequest *vr) {
|
|
|
|
if (LI_VRS_CLEAN == vr->state) {
|
|
|
|
li_request_reset(&vr->request);
|
|
|
|
}
|
2010-01-03 16:39:26 +00:00
|
|
|
|
|
|
|
vr->ts_started = CUR_TS(vr->wrk);
|
2009-10-07 14:02:09 +00:00
|
|
|
}
|
|
|
|
|
2008-10-25 12:53:57 +00:00
|
|
|
/* received all request headers */
|
2009-07-09 20:17:24 +00:00
|
|
|
void li_vrequest_handle_request_headers(liVRequest *vr) {
|
2009-07-08 19:06:07 +00:00
|
|
|
if (LI_VRS_CLEAN == vr->state) {
|
|
|
|
vr->state = LI_VRS_HANDLE_REQUEST_HEADERS;
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_joblist_append(vr);
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* received (partial) request content */
|
2009-07-09 20:17:24 +00:00
|
|
|
void li_vrequest_handle_request_body(liVRequest *vr) {
|
2009-07-08 19:06:07 +00:00
|
|
|
if (LI_VRS_READ_CONTENT <= vr->state) {
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_joblist_append(vr);
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* received all response headers/status code - call once from your indirect handler */
|
2009-07-09 20:17:24 +00:00
|
|
|
void li_vrequest_handle_response_headers(liVRequest *vr) {
|
2009-07-08 19:06:07 +00:00
|
|
|
if (LI_VRS_HANDLE_RESPONSE_HEADERS > vr->state) {
|
|
|
|
vr->state = LI_VRS_HANDLE_RESPONSE_HEADERS;
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_joblist_append(vr);
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* received (partial) response content - call from your indirect handler */
|
2009-07-09 20:17:24 +00:00
|
|
|
void li_vrequest_handle_response_body(liVRequest *vr) {
|
2009-07-08 19:06:07 +00:00
|
|
|
if (LI_VRS_WRITE_CONTENT == vr->state) {
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_joblist_append(vr);
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* response completely ready */
|
2009-07-09 20:17:24 +00:00
|
|
|
gboolean li_vrequest_handle_direct(liVRequest *vr) {
|
2009-07-08 19:06:07 +00:00
|
|
|
if (vr->state < LI_VRS_READ_CONTENT) {
|
|
|
|
vr->state = LI_VRS_HANDLE_RESPONSE_HEADERS;
|
2008-10-25 12:53:57 +00:00
|
|
|
vr->out->is_closed = TRUE;
|
2009-01-01 15:44:42 +00:00
|
|
|
vr->backend = NULL;
|
2008-10-25 12:53:57 +00:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle request over time */
|
2009-07-09 20:17:24 +00:00
|
|
|
gboolean li_vrequest_handle_indirect(liVRequest *vr, liPlugin *p) {
|
2009-07-08 19:06:07 +00:00
|
|
|
if (vr->state < LI_VRS_READ_CONTENT) {
|
|
|
|
vr->state = LI_VRS_READ_CONTENT;
|
2009-01-01 15:44:42 +00:00
|
|
|
vr->backend = p;
|
2008-10-25 12:53:57 +00:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
gboolean li_vrequest_is_handled(liVRequest *vr) {
|
2009-07-08 19:06:07 +00:00
|
|
|
return vr->state >= LI_VRS_READ_CONTENT;
|
2009-03-17 10:42:50 +00:00
|
|
|
}
|
|
|
|
|
2009-09-28 22:24:37 +00:00
|
|
|
static liHandlerResult vrequest_do_handle_actions(liVRequest *vr) {
|
2009-07-09 20:17:24 +00:00
|
|
|
liHandlerResult res = li_action_execute(vr);
|
2008-10-25 12:53:57 +00:00
|
|
|
switch (res) {
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_GO_ON:
|
|
|
|
if (vr->state == LI_VRS_HANDLE_REQUEST_HEADERS) {
|
2008-10-25 12:53:57 +00:00
|
|
|
/* request not handled */
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_handle_direct(vr);
|
2009-09-15 19:30:25 +00:00
|
|
|
if (vr->request.http_method == LI_HTTP_METHOD_OPTIONS) {
|
|
|
|
vr->response.http_status = 200;
|
|
|
|
li_http_header_append(vr->response.headers, CONST_STR_LEN("Allow"), CONST_STR_LEN("OPTIONS, GET, HEAD, POST"));
|
|
|
|
} else {
|
|
|
|
vr->response.http_status = 404;
|
|
|
|
if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) {
|
|
|
|
VR_DEBUG(vr, "%s", "actions didn't handle request");
|
|
|
|
}
|
2009-03-17 13:27:31 +00:00
|
|
|
}
|
2009-09-28 22:24:37 +00:00
|
|
|
return LI_HANDLER_GO_ON;
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
|
|
|
/* otherwise state already changed */
|
|
|
|
break;
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_COMEBACK:
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_joblist_append(vr); /* come back later */
|
2009-09-28 22:24:37 +00:00
|
|
|
return LI_HANDLER_COMEBACK;
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_WAIT_FOR_EVENT:
|
2009-09-28 22:24:37 +00:00
|
|
|
return LI_HANDLER_WAIT_FOR_EVENT;
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_ERROR:
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_error(vr);
|
2009-09-28 22:24:37 +00:00
|
|
|
return LI_HANDLER_ERROR;
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
2009-09-28 22:24:37 +00:00
|
|
|
return LI_HANDLER_GO_ON;
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
|
|
|
|
2009-01-04 20:59:56 +00:00
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
static gboolean vrequest_do_handle_read(liVRequest *vr) {
|
2009-01-01 15:44:42 +00:00
|
|
|
if (vr->backend && vr->backend->handle_request_body) {
|
2009-12-19 21:18:10 +00:00
|
|
|
goffset lim_avail;
|
|
|
|
|
|
|
|
if (vr->in->is_closed) vr->in_memory->is_closed = TRUE;
|
2009-09-29 09:45:55 +00:00
|
|
|
if (!filters_handle_out_close(vr, &vr->filters_in)) {
|
|
|
|
li_vrequest_error(vr);
|
|
|
|
}
|
2009-03-11 15:57:07 +00:00
|
|
|
if (!filters_run(vr, &vr->filters_in)) {
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_error(vr);
|
2009-03-11 15:57:07 +00:00
|
|
|
}
|
|
|
|
|
2009-12-19 21:18:10 +00:00
|
|
|
if (vr->in_buffer_state.tempfile || vr->request.content_length < 0 || vr->request.content_length > 64*1024 ||
|
|
|
|
((lim_avail = li_chunkqueue_limit_available(vr->in)) <= 32*1024 && lim_avail >= 0)) {
|
|
|
|
switch (li_filter_buffer_on_disk(vr, vr->in, vr->in_memory, &vr->in_buffer_state)) {
|
|
|
|
case LI_HANDLER_GO_ON:
|
|
|
|
break;
|
|
|
|
case LI_HANDLER_COMEBACK:
|
|
|
|
li_vrequest_joblist_append(vr); /* come back later */
|
|
|
|
return FALSE;
|
|
|
|
case LI_HANDLER_WAIT_FOR_EVENT:
|
|
|
|
return FALSE;
|
|
|
|
case LI_HANDLER_ERROR:
|
|
|
|
li_vrequest_error(vr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
li_chunkqueue_steal_all(vr->in, vr->in_memory);
|
|
|
|
if (vr->in_memory->is_closed) vr->in->is_closed = TRUE;
|
|
|
|
}
|
|
|
|
|
2009-03-11 15:57:07 +00:00
|
|
|
switch (vr->backend->handle_request_body(vr, vr->backend)) {
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_GO_ON:
|
2008-10-25 12:53:57 +00:00
|
|
|
break;
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_COMEBACK:
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_joblist_append(vr); /* come back later */
|
2008-10-25 12:53:57 +00:00
|
|
|
return FALSE;
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_WAIT_FOR_EVENT:
|
2008-10-25 12:53:57 +00:00
|
|
|
return FALSE;
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_ERROR:
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_error(vr);
|
2008-10-25 12:53:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2009-07-09 20:17:24 +00:00
|
|
|
li_chunkqueue_skip_all(vr->vr_in);
|
2008-10-25 12:53:57 +00:00
|
|
|
if (vr->vr_in->is_closed) vr->in->is_closed = TRUE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-12-20 22:45:03 +00:00
|
|
|
static void vrequest_do_handle_write(liVRequest *vr) {
|
2009-09-29 09:45:55 +00:00
|
|
|
if (!filters_handle_out_close(vr, &vr->filters_out)) {
|
|
|
|
li_vrequest_error(vr);
|
2009-12-20 22:45:03 +00:00
|
|
|
return;
|
2009-09-29 09:45:55 +00:00
|
|
|
}
|
2009-03-11 15:57:07 +00:00
|
|
|
if (!filters_run(vr, &vr->filters_out)) {
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_error(vr);
|
2009-12-20 22:45:03 +00:00
|
|
|
return;
|
2009-03-11 15:57:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (vr->handle_response_body(vr)) {
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_GO_ON:
|
2008-10-25 12:53:57 +00:00
|
|
|
break;
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_COMEBACK:
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_joblist_append(vr); /* come back later */
|
2009-12-20 22:45:03 +00:00
|
|
|
return;
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_WAIT_FOR_EVENT:
|
2009-12-20 22:45:03 +00:00
|
|
|
return;
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_ERROR:
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_error(vr);
|
2008-10-25 12:53:57 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-12-20 22:45:03 +00:00
|
|
|
return;
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
void li_vrequest_state_machine(liVRequest *vr) {
|
2008-10-25 12:53:57 +00:00
|
|
|
gboolean done = FALSE;
|
2009-07-08 19:06:07 +00:00
|
|
|
liHandlerResult res;
|
2008-10-25 12:53:57 +00:00
|
|
|
do {
|
|
|
|
switch (vr->state) {
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_VRS_CLEAN:
|
2008-10-25 12:53:57 +00:00
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_VRS_HANDLE_REQUEST_HEADERS:
|
|
|
|
if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) {
|
2008-12-30 13:24:33 +00:00
|
|
|
VR_DEBUG(vr, "%s", "handle request header");
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
2009-09-28 22:24:37 +00:00
|
|
|
switch (vrequest_do_handle_actions(vr)) {
|
|
|
|
case LI_HANDLER_GO_ON:
|
|
|
|
break;
|
|
|
|
case LI_HANDLER_COMEBACK:
|
|
|
|
li_vrequest_joblist_append(vr); /* come back later */
|
|
|
|
return;
|
|
|
|
case LI_HANDLER_WAIT_FOR_EVENT:
|
|
|
|
if (vr->state == LI_VRS_HANDLE_REQUEST_HEADERS) return;
|
|
|
|
break; /* go on to get post data/response headers if request is already handled */
|
|
|
|
case LI_HANDLER_ERROR:
|
|
|
|
return;
|
|
|
|
}
|
2008-10-25 12:53:57 +00:00
|
|
|
res = vr->handle_request_headers(vr);
|
|
|
|
switch (res) {
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_GO_ON:
|
|
|
|
if (vr->state == LI_VRS_HANDLE_REQUEST_HEADERS) {
|
2009-09-15 20:59:59 +00:00
|
|
|
if (vr->request.http_method == LI_HTTP_METHOD_OPTIONS) {
|
|
|
|
vr->response.http_status = 200;
|
|
|
|
li_http_header_append(vr->response.headers, CONST_STR_LEN("Allow"), CONST_STR_LEN("OPTIONS, GET, HEAD, POST"));
|
|
|
|
} else {
|
|
|
|
/* unhandled request */
|
|
|
|
vr->response.http_status = 404;
|
|
|
|
}
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_handle_direct(vr);
|
2008-12-31 01:57:27 +00:00
|
|
|
}
|
2008-10-25 12:53:57 +00:00
|
|
|
break;
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_COMEBACK:
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_joblist_append(vr); /* come back later */
|
2008-10-25 12:53:57 +00:00
|
|
|
done = TRUE;
|
|
|
|
break;
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_WAIT_FOR_EVENT:
|
|
|
|
done = (vr->state == LI_VRS_HANDLE_REQUEST_HEADERS);
|
2008-10-25 12:53:57 +00:00
|
|
|
break;
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_ERROR:
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_error(vr);
|
2008-10-25 12:53:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_VRS_READ_CONTENT:
|
2009-09-29 12:52:59 +00:00
|
|
|
if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) {
|
|
|
|
VR_DEBUG(vr, "%s", "read content");
|
|
|
|
}
|
2008-10-25 12:53:57 +00:00
|
|
|
done = !vrequest_do_handle_read(vr);
|
2009-07-08 19:06:07 +00:00
|
|
|
done = done || (vr->state == LI_VRS_READ_CONTENT);
|
2008-10-25 12:53:57 +00:00
|
|
|
break;
|
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_VRS_HANDLE_RESPONSE_HEADERS:
|
2009-09-29 12:52:59 +00:00
|
|
|
if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) {
|
|
|
|
VR_DEBUG(vr, "%s", "handle response header");
|
|
|
|
}
|
2009-09-28 22:24:37 +00:00
|
|
|
switch (vrequest_do_handle_actions(vr)) {
|
|
|
|
case LI_HANDLER_GO_ON:
|
|
|
|
break;
|
|
|
|
case LI_HANDLER_COMEBACK:
|
|
|
|
return;
|
|
|
|
case LI_HANDLER_WAIT_FOR_EVENT:
|
|
|
|
return; /* wait to handle response headers */
|
|
|
|
case LI_HANDLER_ERROR:
|
|
|
|
return;
|
|
|
|
}
|
2008-10-25 12:53:57 +00:00
|
|
|
res = vr->handle_response_headers(vr);
|
|
|
|
switch (res) {
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_GO_ON:
|
|
|
|
vr->state = LI_VRS_WRITE_CONTENT;
|
2008-10-25 12:53:57 +00:00
|
|
|
break;
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_COMEBACK:
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_joblist_append(vr); /* come back later */
|
2008-10-25 12:53:57 +00:00
|
|
|
done = TRUE;
|
|
|
|
break;
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_WAIT_FOR_EVENT:
|
|
|
|
done = (vr->state == LI_VRS_HANDLE_REQUEST_HEADERS);
|
2008-10-25 12:53:57 +00:00
|
|
|
break;
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_HANDLER_ERROR:
|
2009-07-09 20:17:24 +00:00
|
|
|
li_vrequest_error(vr);
|
2008-10-25 12:53:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_VRS_WRITE_CONTENT:
|
2009-09-29 12:52:59 +00:00
|
|
|
if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) {
|
|
|
|
VR_DEBUG(vr, "%s", "write content");
|
|
|
|
}
|
2008-10-25 12:53:57 +00:00
|
|
|
vrequest_do_handle_read(vr);
|
|
|
|
vrequest_do_handle_write(vr);
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
|
2009-07-08 19:06:07 +00:00
|
|
|
case LI_VRS_ERROR:
|
2009-09-29 12:52:59 +00:00
|
|
|
if (CORE_OPTION(LI_CORE_OPTION_DEBUG_REQUEST_HANDLING).boolean) {
|
|
|
|
VR_DEBUG(vr, "%s", "error");
|
|
|
|
}
|
2009-01-04 20:59:56 +00:00
|
|
|
/* this will probably reset the vrequest, so stop handling after it */
|
2008-10-25 12:53:57 +00:00
|
|
|
vr->handle_response_error(vr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} while (!done);
|
|
|
|
}
|
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
void li_vrequest_joblist_append(liVRequest *vr) {
|
2009-07-08 19:06:07 +00:00
|
|
|
liWorker *wrk = vr->wrk;
|
2009-04-15 10:34:06 +00:00
|
|
|
GQueue *const q = &wrk->job_queue;
|
2009-04-14 16:18:25 +00:00
|
|
|
if (!g_atomic_int_compare_and_exchange(&vr->queued, 0, 1)) return; /* already in queue */
|
|
|
|
g_queue_push_tail_link(q, &vr->job_queue_link);
|
2008-12-30 20:55:00 +00:00
|
|
|
ev_timer_start(wrk->loop, &wrk->job_queue_watcher);
|
2008-10-25 12:53:57 +00:00
|
|
|
}
|
2009-01-05 21:24:54 +00:00
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
void li_vrequest_joblist_append_async(liVRequest *vr) {
|
2009-07-08 19:06:07 +00:00
|
|
|
liWorker *wrk = vr->wrk;
|
2009-04-15 10:34:06 +00:00
|
|
|
GAsyncQueue *const q = wrk->job_async_queue;
|
2009-04-14 16:18:25 +00:00
|
|
|
if (!g_atomic_int_compare_and_exchange(&vr->queued, 0, 1)) return; /* already in queue */
|
2009-07-09 20:17:24 +00:00
|
|
|
g_async_queue_push(q, li_vrequest_acquire_ref(vr));
|
2009-04-14 16:18:25 +00:00
|
|
|
ev_async_send(wrk->loop, &wrk->job_async_queue_watcher);
|
|
|
|
}
|
|
|
|
|
2009-07-09 20:17:24 +00:00
|
|
|
gboolean li_vrequest_redirect(liVRequest *vr, GString *uri) {
|
|
|
|
if (!li_vrequest_handle_direct(vr))
|
2009-03-01 20:16:58 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
vr->response.http_status = 301;
|
2009-07-09 20:17:24 +00:00
|
|
|
li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Location"), GSTR_LEN(uri));
|
2009-03-01 20:16:58 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2009-03-11 15:57:07 +00:00
|
|
|
}
|
2009-11-15 20:59:16 +00:00
|
|
|
|
|
|
|
gboolean li_vrequest_redirect_directory(liVRequest *vr) {
|
|
|
|
GString *uri = vr->wrk->tmp_str;
|
|
|
|
|
|
|
|
/* redirect to scheme + host + path + / + querystring if directory without trailing slash */
|
|
|
|
/* TODO: local addr if HTTP 1.0 without host header, url encoding */
|
|
|
|
|
|
|
|
if (li_vrequest_is_handled(vr)) return FALSE;
|
|
|
|
|
|
|
|
g_string_truncate(uri, 0);
|
|
|
|
g_string_append_len(uri, GSTR_LEN(vr->request.uri.scheme));
|
|
|
|
g_string_append_len(uri, CONST_STR_LEN("://"));
|
|
|
|
if (vr->request.uri.authority->len > 0) {
|
|
|
|
g_string_append_len(uri, GSTR_LEN(vr->request.uri.authority));
|
|
|
|
} else {
|
|
|
|
g_string_append_len(uri, GSTR_LEN(vr->con->local_addr_str));
|
|
|
|
}
|
|
|
|
g_string_append_len(uri, GSTR_LEN(vr->request.uri.raw_orig_path));
|
|
|
|
g_string_append_c(uri, '/');
|
|
|
|
if (vr->request.uri.query->len) {
|
|
|
|
g_string_append_c(uri, '?');
|
|
|
|
g_string_append_len(uri, GSTR_LEN(vr->request.uri.query));
|
|
|
|
}
|
|
|
|
|
|
|
|
return li_vrequest_redirect(vr, uri);
|
|
|
|
}
|