X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fhttp_command.c;h=e3a290fa9fc7c070434f954df0558e4c4ef60c5d;hb=e3f0464ea4e840107ec25c1b6747e3a382c408d3;hp=a149e50d578db2360f5dc6970035b5cbccecfc28;hpb=0f2e7a8c7c10f2c3ccb24f4184747f3ebb4284c8;p=pazpar2-moved-to-github.git diff --git a/src/http_command.c b/src/http_command.c index a149e50..e3a290f 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -1,5 +1,5 @@ /* This file is part of Pazpar2. - Copyright (C) 2006-2009 Index Data + Copyright (C) 2006-2010 Index Data Pazpar2 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -117,6 +117,7 @@ static const char *get_msg(enum pazpar2_error_code code) { PAZPAR2_CONFIG_TARGET, "Target cannot be configured"}, { PAZPAR2_RECORD_FAIL, "Record command failed"}, { PAZPAR2_NOT_IMPLEMENTED, "Not implemented"}, + { PAZPAR2_NO_SERVICE, "No service"}, { PAZPAR2_LAST_ERROR, "Last error"}, { 0, 0 } }; @@ -279,7 +280,7 @@ static void cmd_init(struct http_channel *c) service = locate_service(c->server, service_name); if (!service) { - error(rs, PAZPAR2_MALFORMED_PARAMETER_VALUE, "service"); + error(rs, PAZPAR2_NO_SERVICE, service_name ? service_name : "unnamed"); return; } service_incref(service); @@ -296,8 +297,16 @@ static void cmd_init(struct http_channel *c) s->session_id = sesid; if (process_settings(s->psession, c->request, c->response) < 0) return; - sprintf(buf, HTTP_COMMAND_RESPONSE_PREFIX "OK%u" - "" PAZPAR2_PROTOCOL_VERSION "", sesid); + + sprintf(buf, HTTP_COMMAND_RESPONSE_PREFIX + "OK%u", sesid); + if (c->server->server_id) + { + strcat(buf, "."); + strcat(buf, c->server->server_id); + } + strcat(buf, "" + "" PAZPAR2_PROTOCOL_VERSION ""); rs->payload = nmem_strdup(c->nmem, buf); http_send_response(c); } @@ -379,7 +388,8 @@ static void targets_termlist(WRBUF wrbuf, struct session *se, int num, wrbuf_xmlputs(wrbuf, ht[i].name); wrbuf_puts(wrbuf, "\n"); - wrbuf_printf(wrbuf, "%d\n", ht[i].hits); + wrbuf_printf(wrbuf, "" ODR_INT_PRINTF "\n", + ht[i].hits); wrbuf_puts(wrbuf, ""); wrbuf_xmlputs(wrbuf, ht[i].state); @@ -472,6 +482,7 @@ static void cmd_bytarget(struct http_channel *c) struct http_request *rq = c->request; struct http_session *s = locate_session(rq, rs); struct hitsbytarget *ht; + const char *settings = http_argbyname(rq, "settings"); int count, i; if (!s) @@ -495,15 +506,21 @@ static void cmd_bytarget(struct http_channel *c) wrbuf_puts(c->wrbuf, "\n"); } - wrbuf_printf(c->wrbuf, "%d\n", ht[i].hits); + wrbuf_printf(c->wrbuf, "" ODR_INT_PRINTF "\n", ht[i].hits); wrbuf_printf(c->wrbuf, "%d\n", ht[i].diagnostic); wrbuf_printf(c->wrbuf, "%d\n", ht[i].records); wrbuf_puts(c->wrbuf, ""); wrbuf_xmlputs(c->wrbuf, ht[i].state); wrbuf_puts(c->wrbuf, "\n"); - + if (settings && *settings == '1') + { + wrbuf_puts(c->wrbuf, "\n"); + wrbuf_puts(c->wrbuf, wrbuf_cstr(ht[i].settings_xml)); + wrbuf_puts(c->wrbuf, "\n"); + } wrbuf_puts(c->wrbuf, ""); + wrbuf_destroy(ht[i].settings_xml); } wrbuf_puts(c->wrbuf, ""); @@ -524,8 +541,16 @@ static void write_metadata(WRBUF w, struct conf_service *service, continue; for (md = ml[imeta]; md; md = md->next) { - wrbuf_printf(w, "\n", cmd->name); + struct record_metadata_attr *attr = md->attributes; + wrbuf_printf(w, "\nname); + for (; attr; attr = attr->next) + { + wrbuf_printf(w, " %s=\"", attr->name); + wrbuf_xmlputs(w, attr->value); + wrbuf_puts(w, "\""); + } + wrbuf_puts(w, ">"); switch (cmd->type) { case Metadata_type_generic: @@ -732,7 +757,7 @@ static void show_records(struct http_channel *c, int active) int startn = 0; int numn = 20; int total; - int total_hits; + Odr_int total_hits; int i; if (!s) @@ -760,7 +785,7 @@ static void show_records(struct http_channel *c, int active) wrbuf_puts(c->wrbuf, HTTP_COMMAND_RESPONSE_PREFIX "\nOK\n"); wrbuf_printf(c->wrbuf, "%d\n", active); wrbuf_printf(c->wrbuf, "%d\n", total); - wrbuf_printf(c->wrbuf, "%d\n", total_hits); + wrbuf_printf(c->wrbuf, "" ODR_INT_PRINTF "\n", total_hits); wrbuf_printf(c->wrbuf, "%d\n", startn); wrbuf_printf(c->wrbuf, "%d\n", numn); @@ -777,6 +802,8 @@ static void show_records(struct http_channel *c, int active) write_subrecord(p, c->wrbuf, service, 0); // subrecs w/o details if (ccount > 1) wrbuf_printf(c->wrbuf, "%d\n", ccount); + if (strstr(sort, "relevance")) + wrbuf_printf(c->wrbuf, "%d\n", rec->relevance); wrbuf_puts(c->wrbuf, ""); wrbuf_xmlputs(c->wrbuf, rec->recid); wrbuf_puts(c->wrbuf, "\n"); @@ -810,7 +837,7 @@ static void cmd_show(struct http_channel *c) if (block) { - if (status && (!s->psession->reclist || !s->psession->reclist->num_records)) + if (status && reclist_get_num_records(s->psession->reclist) == 0) { // if there is already a watch/block. we do not block this one if (session_set_watch(s->psession, SESSION_WATCH_SHOW, @@ -868,6 +895,8 @@ static void cmd_search(struct http_channel *c) struct http_session *s = locate_session(rq, rs); const char *query = http_argbyname(rq, "query"); const char *filter = http_argbyname(rq, "filter"); + const char *maxrecs = http_argbyname(rq, "maxrecs"); + const char *startrecs = http_argbyname(rq, "startrecs"); enum pazpar2_error_code code; const char *addinfo = 0; @@ -883,7 +912,7 @@ static void cmd_search(struct http_channel *c) error(rs, PAZPAR2_MALFORMED_PARAMETER_ENCODING, "query"); return; } - code = search(s->psession, query, filter, &addinfo); + code = search(s->psession, query, startrecs, maxrecs, filter, &addinfo); if (code) { error(rs, code, addinfo); @@ -917,7 +946,7 @@ static void cmd_stat(struct http_channel *c) wrbuf_rewind(c->wrbuf); wrbuf_puts(c->wrbuf, HTTP_COMMAND_RESPONSE_PREFIX ""); wrbuf_printf(c->wrbuf, "%d\n", clients); - wrbuf_printf(c->wrbuf, "%d\n", stat.num_hits); + wrbuf_printf(c->wrbuf, "" ODR_INT_PRINTF "\n", stat.num_hits); wrbuf_printf(c->wrbuf, "%d\n", stat.num_records); wrbuf_printf(c->wrbuf, "%d\n", stat.num_clients); wrbuf_printf(c->wrbuf, "%d\n", stat.num_no_connection);