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);
wrbuf_printf(c->wrbuf, "<session_nmem>%zu</session_nmem>\n", session_nmem);
}
+static void cmd_service(struct http_channel *c)
+{
+ struct http_session *s = locate_session(c);
+ xmlNode *xml_node;
+ if (!s)
+ return;
+
+ response_open_command(c, 0);
+ xml_node = s->psession->service->xml_node;
+ if (xml_node)
+ {
+ xmlNode *tmp = xmlCopyNode(xml_node, 1);
+ xmlBufferPtr buf = xmlBufferCreate();
+
+ xmlNodeDump(buf, tmp->doc, tmp, 0, 0);
+
+ wrbuf_write(c->wrbuf, (const char *) buf->content, buf->use);
+ xmlBufferFree(buf);
+ xmlFreeNode(tmp);
+ }
+
+ response_close(c, 0);
+ release_session(c, s);
+}
+
static void cmd_session_status(struct http_channel *c)
{
struct http_session *s = locate_session(c);
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 sessions_count(void);
-int clients_count(void);
#ifdef HAVE_RESULTSETS_COUNT
int resultsets_count(void);
#else
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);
}
if (checksumstr)
{
- long v = atol(checksumstr);
+ unsigned v = strtoul(checksumstr, 0, 10);
for (i = 0; r; r = r->next)
if (v == r->checksum)
break;
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);
const char *sort = http_argbyname(rq, "sort");
const char *block_error = http_argbyname(rq, "report");
const char *mergekey = http_argbyname(rq, "mergekey");
+ const char *rank = http_argbyname(rq, "rank");
struct conf_service *service = 0;
struct reclist_sortparms *sp;
release_session(c, s);
return;
}
- session_sort(s->psession, sp, mergekey);
+ session_sort(s->psession, sp, mergekey, rank);
status = session_active_clients(s->psession);
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);
}
const char *startrecs = http_argbyname(rq, "startrecs");
const char *limit = http_argbyname(rq, "limit");
const char *sort = http_argbyname(rq, "sort");
+ const char *mergekey = http_argbyname(rq, "mergekey");
+ const char *rank = http_argbyname(rq, "rank");
enum pazpar2_error_code code;
const char *addinfo = 0;
struct reclist_sortparms *sp;
}
code = session_search(s->psession, query, startrecs, maxrecs, filter, limit,
- &addinfo, sp);
+ &addinfo, sp, mergekey, rank);
if (code)
{
error(rs, code, addinfo);
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
{ "exit", cmd_exit },
{ "session-status", cmd_session_status },
{ "server-status", cmd_server_status },
+ { "service", cmd_service },
{ "ping", cmd_ping },
{ "record", cmd_record },
{ "info", cmd_info },