+ release_session(c,s);
+}
+
+size_t session_get_memory_status(struct session *session);
+
+static void session_status(struct http_channel *c, struct http_session *s)
+{
+ size_t session_nmem;
+ wrbuf_printf(c->wrbuf, "<http_count>%u</http_count>\n", s->activity_counter);
+ wrbuf_printf(c->wrbuf, "<http_nmem>%zu</http_nmem>\n", nmem_total(s->nmem) );
+ session_nmem = session_get_memory_status(s->psession);
+ wrbuf_printf(c->wrbuf, "<session_nmem>%zu</session_nmem>\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);
+ if (!s)
+ return;
+
+ wrbuf_rewind(c->wrbuf);
+ wrbuf_puts(c->wrbuf, HTTP_COMMAND_RESPONSE_PREFIX "<sessionstatus><status>OK</status>\n");
+ session_status(c, s);
+ wrbuf_puts(c->wrbuf, "</sessionstatus>\n");
+ rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
+ http_send_response(c);
+ release_session(c,s);
+
+}
+
+int sessions_count(void);
+int clients_count(void);
+#ifdef HAVE_RESULTSETS_COUNT
+int resultsets_count(void);
+#else
+#define resultsets_count() 0
+#endif
+
+static void cmd_server_status(struct http_channel *c)
+{
+ struct http_response *rs = c->response;
+ int sessions = sessions_count();
+ int clients = clients_count();
+ int resultsets = resultsets_count();
+ wrbuf_rewind(c->wrbuf);
+ wrbuf_puts(c->wrbuf, HTTP_COMMAND_RESPONSE_PREFIX "<server-status>\n");
+ wrbuf_printf(c->wrbuf, " <sessions>%u</sessions>\n", sessions);
+ wrbuf_printf(c->wrbuf, " <clients>%u</clients>\n", clients);
+ /* Only works if yaz has been compiled with enabling of this */
+ wrbuf_printf(c->wrbuf, " <resultsets>%u</resultsets>\n",resultsets);
+ print_meminfo(c->wrbuf);
+
+/* TODO add all sessions status */
+/* http_sessions_t http_sessions = c->http_sessions; */
+/* struct http_session *p; */
+/*
+ yaz_mutex_enter(http_sessions->mutex);
+ for (p = http_sessions->session_list; p; p = p->next) {
+ p->activity_counter++;
+ wrbuf_puts(c->wrbuf, "<session-status>\n");
+ wrbuf_printf(c->wrbuf, "<id>%s</id>\n", p->session_id);
+ yaz_mutex_leave(http_sessions->mutex);
+ session_status(c, p);
+ wrbuf_puts(c->wrbuf, "</session-status>\n");
+ yaz_mutex_enter(http_sessions->mutex);
+ p->activity_counter--;
+ }
+ yaz_mutex_leave(http_sessions->mutex);
+*/
+ wrbuf_puts(c->wrbuf, "</server-status>\n");
+ rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
+ http_send_response(c);
+ xmalloc_trav(0);