1 /* This file is part of Pazpar2.
2 Copyright (C) 2006-2008 Index Data
4 Pazpar2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 * $Id: http_command.c,v 1.66 2007-10-28 18:55:26 adam Exp $
25 #include <sys/types.h>
38 #include <yaz/snprintf.h>
43 #include <yaz/yaz-util.h>
49 #include "http_command.h"
53 // Update this when the protocol changes
54 #define PAZPAR2_PROTOCOL_VERSION "1"
57 IOCHAN timeout_iochan; // NOTE: This is NOT associated with a socket
58 struct session *psession;
59 unsigned int session_id;
62 struct http_session *next;
65 static struct http_session *session_list = 0;
66 void http_session_destroy(struct http_session *s);
68 static void session_timeout(IOCHAN i, int event)
70 struct http_session *s = iochan_getdata(i);
71 http_session_destroy(s);
74 struct http_session *http_session_create()
76 NMEM nmem = nmem_create();
77 struct http_session *r = nmem_malloc(nmem, sizeof(*r));
79 r->psession = new_session(nmem);
83 r->next = session_list;
85 r->timeout_iochan = iochan_create(-1, session_timeout, 0);
86 iochan_setdata(r->timeout_iochan, r);
87 iochan_settimeout(r->timeout_iochan, global_parameters.session_timeout);
89 pazpar2_add_channel(r->timeout_iochan);
93 void http_session_destroy(struct http_session *s)
95 struct http_session **p;
97 for (p = &session_list; *p; p = &(*p)->next)
103 yaz_log(YLOG_LOG, "Destroying session %u", s->session_id);
104 iochan_destroy(s->timeout_iochan);
105 destroy_session(s->psession);
106 nmem_destroy(s->nmem);
109 static const char *get_msg(enum pazpar2_error_code code)
111 struct pazpar2_error_msg {
112 enum pazpar2_error_code code;
115 static const struct pazpar2_error_msg ar[] = {
116 { PAZPAR2_NO_SESSION, "Session does not exist or it has expired"},
117 { PAZPAR2_MISSING_PARAMETER, "Missing parameter"},
118 { PAZPAR2_MALFORMED_PARAMETER_VALUE, "Malformed parameter value"},
119 { PAZPAR2_MALFORMED_PARAMETER_ENCODING, "Malformed parameter encoding"},
120 { PAZPAR2_MALFORMED_SETTING, "Malformed setting argument"},
121 { PAZPAR2_HITCOUNTS_FAILED, "Failed to retrieve hitcounts"},
122 { PAZPAR2_RECORD_MISSING, "Record missing"},
123 { PAZPAR2_NO_TARGETS, "No targets"},
124 { PAZPAR2_CONFIG_TARGET, "Target cannot be configured"},
125 { PAZPAR2_RECORD_FAIL, "Record command failed"},
126 { PAZPAR2_NOT_IMPLEMENTED, "Not implemented"},
127 { PAZPAR2_LAST_ERROR, "Last error"},
133 if (code == ar[i].code)
140 static void error(struct http_response *rs,
141 enum pazpar2_error_code code,
144 struct http_channel *c = rs->channel;
145 WRBUF text = wrbuf_alloc();
146 const char *http_status = "417";
147 const char *msg = get_msg(code);
149 rs->msg = nmem_strdup(c->nmem, msg);
150 strcpy(rs->code, http_status);
152 wrbuf_printf(text, "<error code=\"%d\" msg=\"%s\">", (int) code,
155 wrbuf_xmlputs(text, addinfo);
156 wrbuf_puts(text, "</error>");
158 yaz_log(YLOG_WARN, "HTTP %s %s%s%s", http_status,
159 msg, addinfo ? ": " : "" , addinfo ? addinfo : "");
160 rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(text));
162 http_send_response(c);
165 unsigned int make_sessionid()
171 if (global_parameters.debug_mode)
180 if (gettimeofday(&t, 0) < 0)
182 yaz_log(YLOG_WARN|YLOG_ERRNO, "gettimeofday");
185 /* at most 256 sessions per second ..
186 (long long would be more appropriate)*/
188 res = ((res << 8) | (seq & 0xff)) & ((1U << 31) - 1);
194 static struct http_session *locate_session(struct http_request *rq, struct http_response *rs)
196 struct http_session *p;
197 char *session = http_argbyname(rq, "session");
202 error(rs, PAZPAR2_MISSING_PARAMETER, "session");
206 for (p = session_list; p; p = p->next)
207 if (id == p->session_id)
209 iochan_activity(p->timeout_iochan);
212 error(rs, PAZPAR2_NO_SESSION, session);
216 // Decode settings parameters and apply to session
217 // Syntax: setting[target]=value
218 static int process_settings(struct session *se, struct http_request *rq,
219 struct http_response *rs)
221 struct http_argument *a;
223 for (a = rq->arguments; a; a = a->next)
224 if (strchr(a->name, '['))
231 // Nmem_strsplit *rules*!!!
232 nmem_strsplit(se->session_nmem, "[]", a->name, &res, &num);
235 error(rs, PAZPAR2_MALFORMED_SETTING, a->name);
240 session_apply_setting(se, dbname, setting,
241 nmem_strdup(se->session_nmem, a->value));
246 static void cmd_exit(struct http_channel *c)
248 yaz_log(YLOG_WARN, "exit");
252 static void cmd_init(struct http_channel *c)
256 const char *clear = http_argbyname(c->request, "clear");
257 struct http_session *s = http_session_create();
258 struct http_response *rs = c->response;
260 yaz_log(YLOG_DEBUG, "HTTP Session init");
261 if (!clear || *clear == '0')
262 session_init_databases(s->psession);
264 yaz_log(YLOG_LOG, "No databases preloaded");
265 sesid = make_sessionid();
266 s->session_id = sesid;
267 if (process_settings(s->psession, c->request, c->response) < 0)
269 sprintf(buf, "<init><status>OK</status><session>%u</session>"
270 "<protocol>" PAZPAR2_PROTOCOL_VERSION "</protocol></init>", sesid);
271 rs->payload = nmem_strdup(c->nmem, buf);
272 http_send_response(c);
275 static void cmd_settings(struct http_channel *c)
277 struct http_response *rs = c->response;
278 struct http_request *rq = c->request;
279 struct http_session *s = locate_session(rq, rs);
284 if (process_settings(s->psession, rq, rs) < 0)
286 rs->payload = "<settings><status>OK</status></settings>";
287 http_send_response(c);
290 // Compares two hitsbytarget nodes by hitcount
291 static int cmp_ht(const void *p1, const void *p2)
293 const struct hitsbytarget *h1 = p1;
294 const struct hitsbytarget *h2 = p2;
295 return h2->hits - h1->hits;
298 // This implements functionality somewhat similar to 'bytarget', but in a termlist form
299 static void targets_termlist(WRBUF wrbuf, struct session *se, int num,
302 struct hitsbytarget *ht;
305 ht = hitsbytarget(se, &count, nmem);
306 qsort(ht, count, sizeof(struct hitsbytarget), cmp_ht);
307 for (i = 0; i < count && i < num && ht[i].hits > 0; i++)
310 // do only print terms which have display names
312 wrbuf_puts(wrbuf, "<term>\n");
314 wrbuf_puts(wrbuf, "<id>");
315 wrbuf_xmlputs(wrbuf, ht[i].id);
316 wrbuf_puts(wrbuf, "</id>\n");
318 wrbuf_puts(wrbuf, "<name>");
319 if (!ht[i].name || !ht[i].name[0])
320 wrbuf_xmlputs(wrbuf, "NO TARGET NAME");
322 wrbuf_xmlputs(wrbuf, ht[i].name);
323 wrbuf_puts(wrbuf, "</name>\n");
325 wrbuf_printf(wrbuf, "<frequency>%d</frequency>\n", ht[i].hits);
327 wrbuf_puts(wrbuf, "<state>");
328 wrbuf_xmlputs(wrbuf, ht[i].state);
329 wrbuf_puts(wrbuf, "</state>\n");
331 wrbuf_printf(wrbuf, "<diagnostic>%d</diagnostic>\n",
333 wrbuf_puts(wrbuf, "</term>\n");
337 static void cmd_termlist(struct http_channel *c)
339 struct http_response *rs = c->response;
340 struct http_request *rq = c->request;
341 struct http_session *s = locate_session(rq, rs);
342 struct termlist_score **p;
345 char *name = http_argbyname(rq, "name");
346 char *nums = http_argbyname(rq, "num");
353 status = session_active_clients(s->psession);
357 if (strlen(name) > 255)
362 wrbuf_rewind(c->wrbuf);
364 wrbuf_puts(c->wrbuf, "<termlist>\n");
365 wrbuf_printf(c->wrbuf, "<activeclients>%d</activeclients>\n", status);
371 if (!(tp = strchr(name, ',')))
372 tp = name + strlen(name);
373 strncpy(tname, name, tp - name);
374 tname[tp - name] = '\0';
376 wrbuf_puts(c->wrbuf, "<list name=\"");
377 wrbuf_xmlputs(c->wrbuf, tname);
378 wrbuf_puts(c->wrbuf, "\">\n");
379 if (!strcmp(tname, "xtargets"))
380 targets_termlist(c->wrbuf, s->psession, num, c->nmem);
383 p = termlist(s->psession, tname, &len);
385 for (i = 0; i < len && i < num; i++){
386 // prevnt sending empty term elements
387 if (!p[i]->term || !p[i]->term[0])
390 wrbuf_puts(c->wrbuf, "<term>");
391 wrbuf_puts(c->wrbuf, "<name>");
392 wrbuf_xmlputs(c->wrbuf, p[i]->term);
393 wrbuf_puts(c->wrbuf, "</name>");
395 wrbuf_printf(c->wrbuf,
396 "<frequency>%d</frequency>",
398 wrbuf_puts(c->wrbuf, "</term>\n");
401 wrbuf_puts(c->wrbuf, "</list>\n");
406 wrbuf_puts(c->wrbuf, "</termlist>\n");
407 rs->payload = nmem_strdup(rq->channel->nmem, wrbuf_cstr(c->wrbuf));
408 http_send_response(c);
412 static void cmd_bytarget(struct http_channel *c)
414 struct http_response *rs = c->response;
415 struct http_request *rq = c->request;
416 struct http_session *s = locate_session(rq, rs);
417 struct hitsbytarget *ht;
422 ht = hitsbytarget(s->psession, &count, c->nmem);
423 wrbuf_rewind(c->wrbuf);
424 wrbuf_puts(c->wrbuf, "<bytarget><status>OK</status>");
426 for (i = 0; i < count; i++)
428 wrbuf_puts(c->wrbuf, "\n<target>");
430 wrbuf_puts(c->wrbuf, "<id>");
431 wrbuf_xmlputs(c->wrbuf, ht[i].id);
432 wrbuf_puts(c->wrbuf, "</id>\n");
434 wrbuf_printf(c->wrbuf, "<hits>%d</hits>\n", ht[i].hits);
435 wrbuf_printf(c->wrbuf, "<diagnostic>%d</diagnostic>\n", ht[i].diagnostic);
436 wrbuf_printf(c->wrbuf, "<records>%d</records>\n", ht[i].records);
438 wrbuf_puts(c->wrbuf, "<state>");
439 wrbuf_xmlputs(c->wrbuf, ht[i].state);
440 wrbuf_puts(c->wrbuf, "</state>\n");
442 wrbuf_puts(c->wrbuf, "</target>");
445 wrbuf_puts(c->wrbuf, "</bytarget>");
446 rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
447 http_send_response(c);
450 static void write_metadata(WRBUF w, struct conf_service *service,
451 struct record_metadata **ml, int full)
455 for (imeta = 0; imeta < service->num_metadata; imeta++)
457 struct conf_metadata *cmd = &service->metadata[imeta];
458 struct record_metadata *md;
459 if (!cmd->brief && !full)
461 for (md = ml[imeta]; md; md = md->next)
463 wrbuf_printf(w, "\n<md-%s>", cmd->name);
467 case Metadata_type_generic:
468 wrbuf_xmlputs(w, md->data.text.disp);
470 case Metadata_type_year:
471 wrbuf_printf(w, "%d", md->data.number.min);
472 if (md->data.number.min != md->data.number.max)
473 wrbuf_printf(w, "-%d", md->data.number.max);
476 wrbuf_puts(w, "[can't represent]");
478 wrbuf_printf(w, "</md-%s>", cmd->name);
483 static void write_subrecord(struct record *r, WRBUF w,
484 struct conf_service *service, int show_details)
486 const char *name = session_setting_oneval(
487 client_get_database(r->client), PZ_NAME);
489 wrbuf_puts(w, "<location id=\"");
490 wrbuf_xmlputs(w, client_get_database(r->client)->database->url);
491 wrbuf_puts(w, "\" ");
493 wrbuf_puts(w, "name=\"");
494 wrbuf_xmlputs(w, *name ? name : "Unknown");
495 wrbuf_puts(w, "\">");
498 write_metadata(w, service, r->metadata, 1);
499 wrbuf_puts(w, "</location>\n");
502 static void show_raw_record_error(void *data, const char *addinfo)
504 http_channel_observer_t obs = data;
505 struct http_channel *c = http_channel_observer_chan(obs);
506 struct http_response *rs = c->response;
508 http_remove_observer(obs);
510 error(rs, PAZPAR2_RECORD_FAIL, addinfo);
513 static void show_raw_record_ok(void *data, const char *buf, size_t sz)
515 http_channel_observer_t obs = data;
516 struct http_channel *c = http_channel_observer_chan(obs);
517 struct http_response *rs = c->response;
519 http_remove_observer(obs);
521 wrbuf_write(c->wrbuf, buf, sz);
522 rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
523 http_send_response(c);
527 static void show_raw_record_ok_binary(void *data, const char *buf, size_t sz)
529 http_channel_observer_t obs = data;
530 struct http_channel *c = http_channel_observer_chan(obs);
531 struct http_response *rs = c->response;
533 http_remove_observer(obs);
535 wrbuf_write(c->wrbuf, buf, sz);
536 rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
538 rs->content_type = "application/octet-stream";
539 http_send_response(c);
543 void show_raw_reset(void *data, struct http_channel *c, void *data2)
545 struct client *client = data;
546 client_show_raw_remove(client, data2);
549 static void cmd_record_ready(void *data);
551 static void cmd_record(struct http_channel *c)
553 struct http_response *rs = c->response;
554 struct http_request *rq = c->request;
555 struct http_session *s = locate_session(rq, rs);
556 struct record_cluster *rec;
558 struct conf_service *service = global_parameters.server->service;
559 const char *idstr = http_argbyname(rq, "id");
560 const char *offsetstr = http_argbyname(rq, "offset");
561 const char *binarystr = http_argbyname(rq, "binary");
567 error(rs, PAZPAR2_MISSING_PARAMETER, "id");
570 wrbuf_rewind(c->wrbuf);
571 if (!(rec = show_single(s->psession, idstr)))
573 if (session_set_watch(s->psession, SESSION_WATCH_RECORD,
574 cmd_record_ready, c, c) != 0)
576 error(rs, PAZPAR2_RECORD_MISSING, idstr);
582 int offset = atoi(offsetstr);
583 const char *syntax = http_argbyname(rq, "syntax");
584 const char *esn = http_argbyname(rq, "esn");
586 struct record*r = rec->records;
589 if (binarystr && *binarystr != '0')
592 for (i = 0; i < offset && r; r = r->next, i++)
596 error(rs, PAZPAR2_RECORD_FAIL, "no record at offset given");
602 http_channel_observer_t obs =
603 http_add_observer(c, r->client, show_raw_reset);
605 client_show_raw_begin(r->client, r->position, syntax, esn,
607 show_raw_record_error,
609 show_raw_record_ok_binary :
615 http_remove_observer(obs);
616 error(rs, PAZPAR2_NO_SESSION, 0);
623 wrbuf_puts(c->wrbuf, "<record>\n");
624 wrbuf_printf(c->wrbuf, "<recid>%s</recid>\n", rec->recid);
625 write_metadata(c->wrbuf, service, rec->metadata, 1);
626 for (r = rec->records; r; r = r->next)
627 write_subrecord(r, c->wrbuf, service, 1);
628 wrbuf_puts(c->wrbuf, "</record>\n");
629 rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
630 http_send_response(c);
634 static void cmd_record_ready(void *data)
636 struct http_channel *c = (struct http_channel *) data;
641 static void show_records(struct http_channel *c, int active)
643 struct http_request *rq = c->request;
644 struct http_response *rs = c->response;
645 struct http_session *s = locate_session(rq, rs);
646 struct record_cluster **rl;
647 struct reclist_sortparms *sp;
648 char *start = http_argbyname(rq, "start");
649 char *num = http_argbyname(rq, "num");
650 char *sort = http_argbyname(rq, "sort");
660 // We haven't counted clients yet if we're called on a block release
662 active = session_active_clients(s->psession);
665 startn = atoi(start);
670 if (!(sp = reclist_parse_sortparms(c->nmem, sort)))
672 error(rs, PAZPAR2_MALFORMED_PARAMETER_VALUE, "sort");
676 rl = show(s->psession, sp, startn, &numn, &total, &total_hits, c->nmem);
678 wrbuf_rewind(c->wrbuf);
679 wrbuf_puts(c->wrbuf, "<show>\n<status>OK</status>\n");
680 wrbuf_printf(c->wrbuf, "<activeclients>%d</activeclients>\n", active);
681 wrbuf_printf(c->wrbuf, "<merged>%d</merged>\n", total);
682 wrbuf_printf(c->wrbuf, "<total>%d</total>\n", total_hits);
683 wrbuf_printf(c->wrbuf, "<start>%d</start>\n", startn);
684 wrbuf_printf(c->wrbuf, "<num>%d</num>\n", numn);
686 for (i = 0; i < numn; i++)
690 struct record_cluster *rec = rl[i];
691 struct conf_service *service = global_parameters.server->service;
693 wrbuf_puts(c->wrbuf, "<hit>\n");
694 write_metadata(c->wrbuf, service, rec->metadata, 0);
695 for (ccount = 0, p = rl[i]->records; p; p = p->next, ccount++)
696 write_subrecord(p, c->wrbuf, service, 0); // subrecs w/o details
698 wrbuf_printf(c->wrbuf, "<count>%d</count>\n", ccount);
699 wrbuf_printf(c->wrbuf, "<recid>%s</recid>\n", rec->recid);
700 wrbuf_puts(c->wrbuf, "</hit>\n");
703 wrbuf_puts(c->wrbuf, "</show>\n");
704 rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
705 http_send_response(c);
708 static void show_records_ready(void *data)
710 struct http_channel *c = (struct http_channel *) data;
715 static void cmd_show(struct http_channel *c)
717 struct http_request *rq = c->request;
718 struct http_response *rs = c->response;
719 struct http_session *s = locate_session(rq, rs);
720 char *block = http_argbyname(rq, "block");
726 status = session_active_clients(s->psession);
730 if (status && (!s->psession->reclist || !s->psession->reclist->num_records))
732 // if there is already a watch/block. we do not block this one
733 if (session_set_watch(s->psession, SESSION_WATCH_SHOW,
734 show_records_ready, c, c) != 0)
736 yaz_log(YLOG_DEBUG, "Blocking on cmd_show");
742 show_records(c, status);
745 static void cmd_ping(struct http_channel *c)
747 struct http_request *rq = c->request;
748 struct http_response *rs = c->response;
749 struct http_session *s = locate_session(rq, rs);
752 rs->payload = "<ping><status>OK</status></ping>";
753 http_send_response(c);
756 static int utf_8_valid(const char *str)
758 yaz_iconv_t cd = yaz_iconv_open("utf-8", "utf-8");
761 /* check that query is UTF-8 encoded */
762 char *inbuf = (char *) str; /* we know iconv does not alter this */
763 size_t inbytesleft = strlen(inbuf);
765 size_t outbytesleft = strlen(inbuf) + 10;
766 char *out = xmalloc(outbytesleft);
768 size_t r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
770 /* if OK, try flushing the rest */
771 if (r != (size_t) (-1))
772 r = yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft);
775 if (r == (size_t) (-1))
781 static void cmd_search(struct http_channel *c)
783 struct http_request *rq = c->request;
784 struct http_response *rs = c->response;
785 struct http_session *s = locate_session(rq, rs);
786 char *query = http_argbyname(rq, "query");
787 char *filter = http_argbyname(rq, "filter");
788 enum pazpar2_error_code code;
789 const char *addinfo = 0;
795 error(rs, PAZPAR2_MISSING_PARAMETER, "query");
798 if (!utf_8_valid(query))
800 error(rs, PAZPAR2_MALFORMED_PARAMETER_ENCODING, "query");
803 code = search(s->psession, query, filter, &addinfo);
806 error(rs, code, addinfo);
809 rs->payload = "<search><status>OK</status></search>";
810 http_send_response(c);
814 static void cmd_stat(struct http_channel *c)
816 struct http_request *rq = c->request;
817 struct http_response *rs = c->response;
818 struct http_session *s = locate_session(rq, rs);
819 struct statistics stat;
825 clients = session_active_clients(s->psession);
826 statistics(s->psession, &stat);
828 wrbuf_rewind(c->wrbuf);
829 wrbuf_puts(c->wrbuf, "<stat>");
830 wrbuf_printf(c->wrbuf, "<activeclients>%d</activeclients>\n", clients);
831 wrbuf_printf(c->wrbuf, "<hits>%d</hits>\n", stat.num_hits);
832 wrbuf_printf(c->wrbuf, "<records>%d</records>\n", stat.num_records);
833 wrbuf_printf(c->wrbuf, "<clients>%d</clients>\n", stat.num_clients);
834 wrbuf_printf(c->wrbuf, "<unconnected>%d</unconnected>\n", stat.num_no_connection);
835 wrbuf_printf(c->wrbuf, "<connecting>%d</connecting>\n", stat.num_connecting);
836 wrbuf_printf(c->wrbuf, "<initializing>%d</initializing>\n", stat.num_initializing);
837 wrbuf_printf(c->wrbuf, "<searching>%d</searching>\n", stat.num_searching);
838 wrbuf_printf(c->wrbuf, "<presenting>%d</presenting>\n", stat.num_presenting);
839 wrbuf_printf(c->wrbuf, "<idle>%d</idle>\n", stat.num_idle);
840 wrbuf_printf(c->wrbuf, "<failed>%d</failed>\n", stat.num_failed);
841 wrbuf_printf(c->wrbuf, "<error>%d</error>\n", stat.num_error);
842 wrbuf_puts(c->wrbuf, "</stat>");
843 rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
844 http_send_response(c);
847 static void cmd_info(struct http_channel *c)
849 char yaz_version_str[20];
850 struct http_response *rs = c->response;
852 wrbuf_rewind(c->wrbuf);
853 wrbuf_puts(c->wrbuf, "<info>\n");
854 wrbuf_puts(c->wrbuf, " <version>\n");
855 wrbuf_puts(c->wrbuf, "<pazpar2>");
856 wrbuf_xmlputs(c->wrbuf, VERSION);
857 wrbuf_puts(c->wrbuf, "</pazpar2>");
860 yaz_version(yaz_version_str, 0);
861 wrbuf_puts(c->wrbuf, " <yaz compiled=\"");
862 wrbuf_xmlputs(c->wrbuf, YAZ_VERSION);
863 wrbuf_puts(c->wrbuf, "\">");
864 wrbuf_xmlputs(c->wrbuf, yaz_version_str);
865 wrbuf_puts(c->wrbuf, "</yaz>\n");
867 wrbuf_puts(c->wrbuf, " </version>\n");
869 wrbuf_puts(c->wrbuf, "</info>");
870 rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
871 http_send_response(c);
876 void (*fun)(struct http_channel *c);
878 { "init", cmd_init },
879 { "settings", cmd_settings },
880 { "stat", cmd_stat },
881 { "bytarget", cmd_bytarget },
882 { "show", cmd_show },
883 { "search", cmd_search },
884 { "termlist", cmd_termlist },
885 { "exit", cmd_exit },
886 { "ping", cmd_ping },
887 { "record", cmd_record },
888 { "info", cmd_info },
892 void http_command(struct http_channel *c)
894 char *command = http_argbyname(c->request, "command");
895 struct http_response *rs = http_create_response(c);
900 http_addheader(rs, "Expires", "Thu, 19 Nov 1981 08:52:00 GMT");
901 http_addheader(rs, "Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
905 error(rs, PAZPAR2_MISSING_PARAMETER, "command");
908 for (i = 0; commands[i].name; i++)
909 if (!strcmp(commands[i].name, command))
911 (*commands[i].fun)(c);
914 if (!commands[i].name)
915 error(rs, PAZPAR2_MALFORMED_PARAMETER_VALUE, "command");
923 * indent-tabs-mode: nil
925 * vim: shiftwidth=4 tabstop=8 expandtab