From 13316443850a6b60216219c3cab5915d9a28751a Mon Sep 17 00:00:00 2001 From: Dennis Schafroth Date: Thu, 24 Feb 2011 15:14:27 +0100 Subject: [PATCH] Refactor a bit. Rename commands to server-status and session-status --- src/http_command.c | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/src/http_command.c b/src/http_command.c index 0bc8503..5e804ce 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -587,22 +587,24 @@ static void cmd_termlist(struct http_channel *c) size_t session_get_memory_status(struct session *session); -static void cmd_session_status(struct http_channel *c) +static void session_status(struct http_channel *c, struct http_session *s) { + size_t session_nmem; + wrbuf_printf(c->wrbuf, "%u\n", s->activity_counter); + wrbuf_printf(c->wrbuf, "%zu\n", nmem_total(s->nmem) ); + session_nmem = session_get_memory_status(s->psession); + wrbuf_printf(c->wrbuf, "%zu\n", session_nmem); +} + +static void cmd_session_status(struct http_channel *c) { struct http_response *rs = c->response; struct http_session *s = locate_session(c); - size_t session_nmem; if (!s) return; wrbuf_rewind(c->wrbuf); wrbuf_puts(c->wrbuf, HTTP_COMMAND_RESPONSE_PREFIX "OK\n"); - wrbuf_printf(c->wrbuf, "%u\n", s->activity_counter); - wrbuf_printf(c->wrbuf, "%zu\n", nmem_total(s->nmem) ); - - session_nmem = session_get_memory_status(s->psession); - wrbuf_printf(c->wrbuf, "%zu\n", session_nmem); - + session_status(c, s); wrbuf_puts(c->wrbuf, "\n"); rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf)); http_send_response(c); @@ -621,12 +623,31 @@ int resultsets_count(void); static void cmd_server_status(struct http_channel *c) { struct http_response *rs = c->response; + http_sessions_t http_sessions = c->http_sessions; + struct http_session *p; int sessions = sessions_count(); int clients = clients_count(); int resultsets = resultsets_count(); wrbuf_rewind(c->wrbuf); - wrbuf_puts(c->wrbuf, HTTP_COMMAND_RESPONSE_PREFIX "OK\n"); - wrbuf_printf(c->wrbuf, "Sessions %u Clients: %u Resultsets: %u\n\n", sessions, clients, resultsets); + wrbuf_puts(c->wrbuf, HTTP_COMMAND_RESPONSE_PREFIX "\n"); + wrbuf_printf(c->wrbuf, " %u\n", sessions); + wrbuf_printf(c->wrbuf, " %u\n", clients); + wrbuf_printf(c->wrbuf, " %u\n",resultsets); + /* + yaz_mutex_enter(http_sessions->mutex); + for (p = http_sessions->session_list; p; p = p->next) { + p->activity_counter++; + wrbuf_puts(c->wrbuf, "\n"); + wrbuf_printf(c->wrbuf, "%s\n", p->session_id); + yaz_mutex_leave(http_sessions->mutex); + session_status(c, p); + wrbuf_puts(c->wrbuf, "\n"); + yaz_mutex_enter(http_sessions->mutex); + p->activity_counter--; + } + yaz_mutex_leave(http_sessions->mutex); +*/ + wrbuf_puts(c->wrbuf, "\n"); rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf)); http_send_response(c); } @@ -1151,7 +1172,7 @@ static void cmd_info(struct http_channel *c) wrbuf_rewind(c->wrbuf); wrbuf_puts(c->wrbuf, HTTP_COMMAND_RESPONSE_PREFIX "\n"); wrbuf_puts(c->wrbuf, " \n"); - wrbuf_puts(c->wrbuf, "wrbuf, " wrbuf, " sha1=\"%s\"", PAZPAR2_VERSION_SHA1); #endif @@ -1188,8 +1209,8 @@ struct { { "search", cmd_search }, { "termlist", cmd_termlist }, { "exit", cmd_exit }, - { "sessionstatus", cmd_session_status }, - { "serverstatus", cmd_server_status }, + { "session-status", cmd_session_status }, + { "server-status", cmd_server_status }, { "ping", cmd_ping }, { "record", cmd_record }, { "info", cmd_info }, -- 1.7.10.4