+ if (ht[i].name && ht[i].name[0])
+ {
+ wrbuf_puts(c->wrbuf, "<name>");
+ wrbuf_xmlputs(c->wrbuf, ht[i].name);
+ wrbuf_puts(c->wrbuf, "</name>\n");
+ }
+
+ wrbuf_printf(c->wrbuf, "<hits>" ODR_INT_PRINTF "</hits>\n", ht[i].hits);
+ wrbuf_printf(c->wrbuf, "<diagnostic>%d</diagnostic>\n", ht[i].diagnostic);
+ if (ht[i].diagnostic)
+ {
+ wrbuf_puts(c->wrbuf, "<message>");
+ wrbuf_xmlputs(c->wrbuf, ht[i].message);
+ wrbuf_puts(c->wrbuf, "</message>\n");
+ wrbuf_puts(c->wrbuf, "<addinfo>");
+ if (ht[i].addinfo)
+ wrbuf_xmlputs(c->wrbuf, ht[i].addinfo);
+ wrbuf_puts(c->wrbuf, "</addinfo>\n");
+ }
+
+ wrbuf_printf(c->wrbuf, "<records>%d</records>\n", ht[i].records - ht[i].filtered);
+ if (version >= 2) {
+ wrbuf_printf(c->wrbuf, "<filtered>%d</filtered>\n", ht[i].filtered);
+ wrbuf_printf(c->wrbuf, "<approximation>" ODR_INT_PRINTF "</approximation>\n", ht[i].approximation);
+ }
+ wrbuf_puts(c->wrbuf, "<state>");
+ wrbuf_xmlputs(c->wrbuf, ht[i].state);
+ wrbuf_puts(c->wrbuf, "</state>\n");
+ if (settings && *settings == '1')
+ {
+ wrbuf_puts(c->wrbuf, "<settings>\n");
+ wrbuf_puts(c->wrbuf, ht[i].settings_xml);
+ wrbuf_puts(c->wrbuf, "</settings>\n");
+ }
+ if (ht[i].suggestions_xml && ht[i].suggestions_xml[0]) {
+ wrbuf_puts(c->wrbuf, "<suggestions>");
+ wrbuf_puts(c->wrbuf, ht[i].suggestions_xml);
+ wrbuf_puts(c->wrbuf, "</suggestions>");
+ }
+ wrbuf_puts(c->wrbuf, "</target>");
+ }
+ response_close(c, "bytarget");
+}
+
+static void bytarget_result_ready(void *data)
+{
+ struct http_channel *c = (struct http_channel *) data;
+ struct http_session *s = locate_session(c);
+ const char *status_message = "OK";
+ if (s) {
+ yaz_log(c->http_sessions->log_level, "Session %u: bytarget watch released", s->session_id);
+ bytarget_response(c, s, status_message);
+ release_session(c, s);
+ }
+ else {
+ yaz_log(c->http_sessions->log_level, "No Session found for released bytarget watch");
+ }
+}
+
+
+static void cmd_bytarget(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");
+ const char *report = http_argbyname(rq, "report");
+ int report_error = 0;
+ int report_status = 0;
+ const char *status_message = "OK";
+ int no_active;
+
+ if (report && !strcmp("error", report)) {
+ report_error = 1;
+ }
+ if (report && !strcmp("status", report)) {
+ report_status = 1;
+ }