http_send_response(c);
}
-static void response_open_no_status(struct http_channel *c, const char *command)
+static void response_open_command(struct http_channel *c, const char *command)
{
wrbuf_rewind(c->wrbuf);
- wrbuf_printf(c->wrbuf, "%s<%s>",
- HTTP_COMMAND_RESPONSE_PREFIX, command);
+ wrbuf_puts(c->wrbuf, HTTP_COMMAND_RESPONSE_PREFIX);
+ if (command)
+ wrbuf_printf(c->wrbuf, "<%s>", command);
}
-static void response_open(struct http_channel *c, const char *command)
+static void response_open_ok(struct http_channel *c, const char *command)
{
- response_open_no_status(c, command);
+ response_open_command(c, command);
wrbuf_puts(c->wrbuf, "<status>OK</status>");
}
{
struct http_response *rs = c->response;
- wrbuf_printf(c->wrbuf, "</%s>", command);
+ if (command)
+ wrbuf_printf(c->wrbuf, "</%s>", command);
rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
http_send_response(c);
}
{
yaz_log(YLOG_WARN, "exit");
- response_open(c, "exit");
+ response_open_ok(c, "exit");
response_close(c, "exit");
if (global_parameters.debug_mode)
http_close_server(c->server);
if (process_settings(s->psession, c->request, c->response) < 0)
return;
- response_open(c, "init");
+ response_open_ok(c, "init");
wrbuf_printf(c->wrbuf, "<session>%d", sesid);
if (c->server->server_id)
{
release_session(c, s);
return;
}
- response_open(c, "settings");
+ response_open_ok(c, "settings");
response_close(c, "settings");
release_session(c, s);
}
status = session_active_clients(s->psession);
- response_open_no_status(c, "termlist");
+ response_open_command(c, "termlist");
/* new protocol add a status to response. Triggered by a status parameter */
if (cmd_status != 0)
wrbuf_printf(c->wrbuf, "<status>%s</status>\n", cmd_status);
if (!s)
return;
- response_open(c, "service");
+ response_open_command(c, 0);
xml_node = s->psession->service->xml_node;
if (xml_node)
{
xmlBufferFree(buf);
}
- response_close(c, "service");
+ response_close(c, 0);
release_session(c, s);
}
if (!s)
return;
- response_open(c, "session-status");
+ response_open_ok(c, "session-status");
session_status(c, s);
response_close(c, "session-status");
release_session(c, s);
int clients = clients_count();
int resultsets = resultsets_count();
- response_open(c, "server-status");
+ response_open_ok(c, "server-status");
wrbuf_printf(c->wrbuf, "\n <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 */
ht = get_hitsbytarget(s->psession, &count, c->nmem);
if (!cmd_status)
/* Old protocol, always ok */
- response_open(c, "bytarget");
+ response_open_ok(c, "bytarget");
else {
/* New protocol, OK or WARNING (...)*/
- response_open_no_status(c, "bytarget");
+ response_open_command(c, "bytarget");
wrbuf_printf(c->wrbuf, "<status>%s</status>", cmd_status);
}
else
{
struct record *r;
- response_open_no_status(c, "record");
+ response_open_command(c, "record");
wrbuf_puts(c->wrbuf, "\n <recid>");
wrbuf_xmlputs(c->wrbuf, rec->recid);
wrbuf_puts(c->wrbuf, "</recid>\n");
if (!rl)
return;
- response_open(c, "show");
+ response_open_ok(c, "show");
wrbuf_printf(c->wrbuf, "\n<activeclients>%d</activeclients>\n", active);
wrbuf_printf(c->wrbuf, "<merged>%d</merged>\n", total);
wrbuf_printf(c->wrbuf, "<total>" ODR_INT_PRINTF "</total>\n", total_hits);
struct http_session *s = locate_session(c);
if (!s)
return;
- response_open(c, "ping");
+ response_open_ok(c, "ping");
response_close(c, "ping");
release_session(c, s);
}
release_session(c, s);
return;
}
- response_open(c, "search");
+ response_open_ok(c, "search");
response_close(c, "search");
release_session(c, s);
}
progress = (stat.num_clients - clients) / (float)stat.num_clients;
}
- response_open_no_status(c, "stat");
+ response_open_command(c, "stat");
wrbuf_printf(c->wrbuf, "\n <activeclients>%d</activeclients>\n", clients);
wrbuf_printf(c->wrbuf, " <hits>" ODR_INT_PRINTF "</hits>\n", stat.num_hits);
wrbuf_printf(c->wrbuf, " <records>%d</records>\n", stat.num_records);
char yaz_version_str[20];
char yaz_sha1_str[42];
- response_open_no_status(c, "info");
+ response_open_command(c, "info");
wrbuf_puts(c->wrbuf, "\n <version>\n");
wrbuf_puts(c->wrbuf, " <pazpar2");
#ifdef PAZPAR2_VERSION_SHA1