+}
+
+static void termlist_result_ready(void *data)
+{
+ struct http_channel *c = (struct http_channel *) data;
+ struct http_session *s = locate_session(c);
+ if (s) {
+ yaz_log(c->http_sessions->log_level, "Session %u termlist watch released", s->session_id);
+ termlist_response(c, s);
+ release_session(c,s);
+ }
+}
+
+static void cmd_termlist(struct http_channel *c)
+{
+ struct http_request *rq = c->request;
+ struct http_response *rs = c->response;
+ struct http_session *s = locate_session(c);
+ const char *block = http_argbyname(rq, "block");
+ int active_clients;
+ if (!s)
+ return;
+
+ active_clients = session_active_clients(s->psession);
+
+ if (block && !strcmp("1", block) && active_clients)
+ {
+ // if there is already a watch/block. we do not block this one
+ if (session_set_watch(s->psession, SESSION_WATCH_TERMLIST,
+ termlist_result_ready, c, c) != 0)
+ {
+ yaz_log(YLOG_WARN, "Session %u: Attempt to block multiple times on termlist block. Not supported!", s->session_id);
+ error(rs, PAZPAR2_ALREADY_BLOCKED, "termlist");
+ }
+ else
+ {
+ yaz_log(c->http_sessions->log_level, "Session %u: Blocking on command termlist", s->session_id);
+ }
+ release_session(c, s);
+ return;
+ }
+
+ termlist_response(c, s);