X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fhttp_command.c;h=c800b62c8876170567de770df4a95c427ea1dbf4;hb=eae6eee32de3560f84a83ee5cc922a2d3d63cc44;hp=913af7929a8e6a11bf84604b4df371912cae4294;hpb=d24d65a3a42bbb6e8c8d0f919bf33510dd356a45;p=pazpar2-moved-to-github.git diff --git a/src/http_command.c b/src/http_command.c index 913af79..c800b62 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -35,7 +35,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "eventl.h" #include "parameters.h" -#include "pazpar2.h" +#include "session.h" #include "http.h" #include "settings.h" #include "client.h" @@ -50,6 +50,8 @@ struct http_session { struct session *psession; unsigned int session_id; int timestamp; + int destroy_counter; + int activity_counter; NMEM nmem; http_sessions_t http_sessions; struct http_session *next; @@ -105,6 +107,7 @@ struct http_session *http_session_create(struct conf_service *service, r->session_id = 0; r->timestamp = 0; r->nmem = nmem; + r->destroy_counter = r->activity_counter; r->http_sessions = http_sessions; yaz_mutex_enter(http_sessions->mutex); @@ -114,6 +117,7 @@ struct http_session *http_session_create(struct conf_service *service, r->timeout_iochan = iochan_create(-1, session_timeout, 0); iochan_setdata(r->timeout_iochan, r); + yaz_log(YLOG_LOG, "timeout=%d", service->session_timeout); iochan_settimeout(r->timeout_iochan, service->session_timeout); iochan_add(service->server->iochan_man, r->timeout_iochan); @@ -122,22 +126,42 @@ struct http_session *http_session_create(struct conf_service *service, void http_session_destroy(struct http_session *s) { - struct http_session **p; + int must_destroy = 1; http_sessions_t http_sessions = s->http_sessions; + yaz_log(YLOG_LOG, "http_session_destroy %u", s->session_id); yaz_mutex_enter(http_sessions->mutex); - for (p = &http_sessions->session_list; *p; p = &(*p)->next) - if (*p == s) - { - *p = (*p)->next; - break; - } + + /* only if http_session destroy was already called, we will allow it + to be destroyed */ + if (s->destroy_counter != s->activity_counter) + must_destroy = 0; + + /* only if there are no active Z39.50 clients we will allow it to be + destroyed */ + if (session_active_clients(s->psession)) + must_destroy = 0; + + s->destroy_counter = s->activity_counter = 0; + if (must_destroy) + { + struct http_session **p = 0; + for (p = &http_sessions->session_list; *p; p = &(*p)->next) + if (*p == s) + { + *p = (*p)->next; + break; + } + } yaz_mutex_leave(http_sessions->mutex); - yaz_log(YLOG_LOG, "Destroying session %u", s->session_id); - iochan_destroy(s->timeout_iochan); - destroy_session(s->psession); - nmem_destroy(s->nmem); + if (must_destroy) + { /* destroying for real */ + yaz_log(YLOG_LOG, "Destroying session %u", s->session_id); + iochan_destroy(s->timeout_iochan); + destroy_session(s->psession); + nmem_destroy(s->nmem); + } } static const char *get_msg(enum pazpar2_error_code code) @@ -245,6 +269,8 @@ static struct http_session *locate_session(struct http_channel *c) for (p = http_sessions->session_list; p; p = p->next) if (id == p->session_id) break; + if (p) + p->activity_counter++; yaz_mutex_leave(http_sessions->mutex); if (p) iochan_activity(p->timeout_iochan); @@ -702,7 +728,7 @@ static void cmd_record(struct http_channel *c) return; } wrbuf_rewind(c->wrbuf); - if (!(rec = show_single(s->psession, idstr, &prev_r, &next_r))) + if (!(rec = show_single_start(s->psession, idstr, &prev_r, &next_r))) { if (session_active_clients(s->psession) == 0) { @@ -732,7 +758,6 @@ static void cmd_record(struct http_channel *c) if (!r) { error(rs, PAZPAR2_RECORD_FAIL, "no record at offset given"); - return; } else { @@ -780,6 +805,7 @@ static void cmd_record(struct http_channel *c) rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf)); http_send_response(c); } + show_single_stop(s->psession, rec); } static void cmd_record_ready(void *data) @@ -824,7 +850,8 @@ static void show_records(struct http_channel *c, int active) return; } - rl = show(s->psession, sp, startn, &numn, &total, &total_hits, c->nmem); + + rl = show_range_start(s->psession, sp, startn, &numn, &total, &total_hits); wrbuf_rewind(c->wrbuf); wrbuf_puts(c->wrbuf, HTTP_COMMAND_RESPONSE_PREFIX "\nOK\n"); @@ -848,13 +875,16 @@ static void show_records(struct http_channel *c, int active) if (ccount > 1) wrbuf_printf(c->wrbuf, "%d\n", ccount); if (strstr(sort, "relevance")) - wrbuf_printf(c->wrbuf, "%d\n", rec->relevance); + wrbuf_printf(c->wrbuf, "%d\n", + rec->relevance_score); wrbuf_puts(c->wrbuf, ""); wrbuf_xmlputs(c->wrbuf, rec->recid); wrbuf_puts(c->wrbuf, "\n"); wrbuf_puts(c->wrbuf, "\n"); } + show_range_stop(s->psession, rl); + wrbuf_puts(c->wrbuf, "\n"); rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf)); http_send_response(c);