HTTP error handler yaz_logs and uses yaz_snprintf to prevent buffer
[pazpar2-moved-to-github.git] / src / http_command.c
1 /* $Id: http_command.c,v 1.43 2007-05-23 09:57:54 adam Exp $
2    Copyright (c) 2006-2007, Index Data.
3
4 This file is part of Pazpar2.
5
6 Pazpar2 is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Pazpar2; see the file LICENSE.  If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20  */
21
22 /*
23  * $Id: http_command.c,v 1.43 2007-05-23 09:57:54 adam Exp $
24  */
25
26 #include <stdio.h>
27 #include <sys/types.h>
28 #include <sys/uio.h>
29 #include <unistd.h>
30 #include <stdlib.h>
31 #include <strings.h>
32 #include <ctype.h>
33 #include <sys/time.h>
34 #include <yaz/snprintf.h>
35 #if HAVE_CONFIG_H
36 #include <cconfig.h>
37 #endif
38
39 #include <yaz/yaz-util.h>
40
41 #include "config.h"
42 #include "util.h"
43 #include "eventl.h"
44 #include "pazpar2.h"
45 #include "http.h"
46 #include "http_command.h"
47 #include "settings.h"
48 #include "client.h"
49
50 // Update this when the protocol changes
51 #define PAZPAR2_PROTOCOL_VERSION "1"
52
53 struct http_session {
54     IOCHAN timeout_iochan;     // NOTE: This is NOT associated with a socket
55     struct session *psession;
56     unsigned int session_id;
57     int timestamp;
58     NMEM nmem;
59     struct http_session *next;
60 };
61
62 static struct http_session *session_list = 0;
63
64 void http_session_destroy(struct http_session *s);
65
66 static void session_timeout(IOCHAN i, int event)
67 {
68     struct http_session *s = iochan_getdata(i);
69     http_session_destroy(s);
70 }
71
72 struct http_session *http_session_create()
73 {
74     NMEM nmem = nmem_create();
75     struct http_session *r = nmem_malloc(nmem, sizeof(*r));
76
77     r->psession = new_session(nmem);
78     r->session_id = 0;
79     r->timestamp = 0;
80     r->nmem = nmem;
81     r->next = session_list;
82     session_list = r;
83     r->timeout_iochan = iochan_create(-1, session_timeout, 0);
84     iochan_setdata(r->timeout_iochan, r);
85     iochan_settimeout(r->timeout_iochan, global_parameters.session_timeout);
86
87     pazpar2_add_channel(r->timeout_iochan);
88     return r;
89 }
90
91 void http_session_destroy(struct http_session *s)
92 {
93     struct http_session **p;
94
95     for (p = &session_list; *p; p = &(*p)->next)
96         if (*p == s)
97         {
98             *p = (*p)->next;
99             break;
100         }
101     iochan_destroy(s->timeout_iochan);
102     destroy_session(s->psession);
103     nmem_destroy(s->nmem);
104 }
105
106 static void error(struct http_response *rs, 
107                   const char *code, const char *msg, const char *extra)
108 {
109     struct http_channel *c = rs->channel;
110     char text[1024];
111     char *sep = extra ? ": " : "";
112
113     rs->msg = nmem_strdup(c->nmem, msg);
114     strcpy(rs->code, code);
115
116     yaz_snprintf(text, sizeof(text),
117                  "<error code=\"general\">%s%s%s</error>", msg, sep,
118                  extra ? extra : "");
119
120     yaz_log(YLOG_WARN, "HTTP %s %s%s%s", code, msg, sep,
121             extra ? extra : "");
122     rs->payload = nmem_strdup(c->nmem, text);
123     http_send_response(c);
124 }
125
126 unsigned int make_sessionid()
127 {
128     static int seq = 0;
129 #if 1
130     return ++seq;
131 #else
132     struct timeval t;
133     unsigned int res;
134
135     seq++;
136     if (gettimeofday(&t, 0) < 0)
137         abort();
138     res = t.tv_sec;
139     res = ((res << 8) | (seq & 0xff)) & ((1U << 31) - 1);
140     return res;
141 #endif
142 }
143
144 static struct http_session *locate_session(struct http_request *rq, struct http_response *rs)
145 {
146     struct http_session *p;
147     char *session = http_argbyname(rq, "session");
148     unsigned int id;
149
150     if (!session)
151     {
152         error(rs, "417", "Must supply session", 0);
153         return 0;
154     }
155     id = atoi(session);
156     for (p = session_list; p; p = p->next)
157         if (id == p->session_id)
158         {
159             iochan_activity(p->timeout_iochan);
160             return p;
161         }
162     error(rs, "417", "Session does not exist, or it has expired", 0);
163     return 0;
164 }
165
166 // Decode settings parameters and apply to session
167 // Syntax: setting[target]=value
168 static int process_settings(struct session *se, struct http_request *rq,
169         struct http_response *rs)
170 {
171     struct http_argument *a;
172
173     for (a = rq->arguments; a; a = a->next)
174         if (strchr(a->name, '['))
175         {
176             char **res;
177             int num;
178             char *dbname;
179             char *setting;
180
181             // Nmem_strsplit *rules*!!!
182             nmem_strsplit(se->session_nmem, "[]", a->name, &res, &num);
183             if (num != 2)
184             {
185                 error(rs, "417", "Malformed setting argument", a->name);
186                 return -1;
187             }
188             setting = res[0];
189             dbname = res[1];
190             session_apply_setting(se, dbname, setting,
191                     nmem_strdup(se->session_nmem, a->value));
192         }
193     return 0;
194 }
195
196 static void cmd_exit(struct http_channel *c)
197 {
198     yaz_log(YLOG_WARN, "exit");
199     exit(0);
200 }
201
202 static void cmd_init(struct http_channel *c)
203 {
204     unsigned int sesid;
205     char buf[1024];
206     struct http_session *s = http_session_create();
207     struct http_response *rs = c->response;
208
209     yaz_log(YLOG_DEBUG, "HTTP Session init");
210     sesid = make_sessionid();
211     s->session_id = sesid;
212     if (process_settings(s->psession, c->request, c->response) < 0)
213         return;
214     sprintf(buf, "<init><status>OK</status><session>%u</session>"
215             "<protocol>" PAZPAR2_PROTOCOL_VERSION "</protocol></init>", sesid);
216     rs->payload = nmem_strdup(c->nmem, buf);
217     http_send_response(c);
218 }
219
220 static void cmd_settings(struct http_channel *c)
221 {
222     struct http_response *rs = c->response;
223     struct http_request *rq = c->request;
224     struct http_session *s = locate_session(rq, rs);
225
226     if (!s)
227         return;
228
229     if (process_settings(s->psession, rq, rs) < 0)
230         return;
231     rs->payload = "<settings><status>OK</status></settings>";
232     http_send_response(c);
233 }
234
235 // Compares two hitsbytarget nodes by hitcount
236 static int cmp_ht(const void *p1, const void *p2)
237 {
238     const struct hitsbytarget *h1 = p1;
239     const struct hitsbytarget *h2 = p2;
240     return h2->hits - h1->hits;
241 }
242
243 // This implements functionality somewhat similar to 'bytarget', but in a termlist form
244 static void targets_termlist(WRBUF wrbuf, struct session *se, int num)
245 {
246     struct hitsbytarget *ht;
247     int count, i;
248
249     if (!(ht = hitsbytarget(se, &count)))
250         return;
251     qsort(ht, count, sizeof(struct hitsbytarget), cmp_ht);
252     for (i = 0; i < count && i < num && ht[i].hits > 0; i++)
253     {
254         wrbuf_puts(wrbuf, "\n<term>\n");
255         wrbuf_printf(wrbuf, "<id>%s</id>\n", ht[i].id);
256         wrbuf_printf(wrbuf, "<name>%s</name>\n", ht[i].name);
257         wrbuf_printf(wrbuf, "<frequency>%d</frequency>\n", ht[i].hits);
258         wrbuf_printf(wrbuf, "<state>%s</state>\n", ht[i].state);
259         wrbuf_printf(wrbuf, "<diagnostic>%d</diagnostic>\n", ht[i].diagnostic);
260         wrbuf_puts(wrbuf, "\n</term>\n");
261     }
262 }
263
264 static void cmd_termlist(struct http_channel *c)
265 {
266     struct http_response *rs = c->response;
267     struct http_request *rq = c->request;
268     struct http_session *s = locate_session(rq, rs);
269     struct termlist_score **p;
270     int len;
271     int i;
272     char *name = http_argbyname(rq, "name");
273     char *nums = http_argbyname(rq, "num");
274     int num = 15;
275     int status;
276
277     if (!s)
278         return;
279
280     status = session_active_clients(s->psession);
281
282     if (!name)
283         name = "subject";
284     if (strlen(name) > 255)
285         return;
286     if (nums)
287         num = atoi(nums);
288
289     wrbuf_rewind(c->wrbuf);
290
291     wrbuf_puts(c->wrbuf, "<termlist>");
292     wrbuf_printf(c->wrbuf, "\n<activeclients>%d</activeclients>", status);
293     while (*name)
294     {
295         char tname[256];
296         char *tp;
297
298         if (!(tp = strchr(name, ',')))
299             tp = name + strlen(name);
300         strncpy(tname, name, tp - name);
301         tname[tp - name] = '\0';
302
303         wrbuf_printf(c->wrbuf, "\n<list name=\"%s\">\n", tname);
304         if (!strcmp(tname, "xtargets"))
305             targets_termlist(c->wrbuf, s->psession, num);
306         else
307         {
308             p = termlist(s->psession, tname, &len);
309             if (p)
310                 for (i = 0; i < len && i < num; i++)
311                 {
312                     wrbuf_puts(c->wrbuf, "\n<term>");
313                     wrbuf_printf(c->wrbuf, "<name>%s</name>", p[i]->term);
314                     wrbuf_printf(c->wrbuf, "<frequency>%d</frequency>", p[i]->frequency);
315                     wrbuf_puts(c->wrbuf, "</term>");
316                 }
317         }
318         wrbuf_puts(c->wrbuf, "\n</list>");
319         name = tp;
320         if (*name == ',')
321             name++;
322     }
323     wrbuf_puts(c->wrbuf, "</termlist>");
324     rs->payload = nmem_strdup(rq->channel->nmem, wrbuf_cstr(c->wrbuf));
325     http_send_response(c);
326 }
327
328
329 static void cmd_bytarget(struct http_channel *c)
330 {
331     struct http_response *rs = c->response;
332     struct http_request *rq = c->request;
333     struct http_session *s = locate_session(rq, rs);
334     struct hitsbytarget *ht;
335     int count, i;
336
337     if (!s)
338         return;
339     if (!(ht = hitsbytarget(s->psession, &count)))
340     {
341         error(rs, "500", "Failed to retrieve hitcounts", 0);
342         return;
343     }
344     wrbuf_rewind(c->wrbuf);
345     wrbuf_puts(c->wrbuf, "<bytarget><status>OK</status>");
346
347     for (i = 0; i < count; i++)
348     {
349         wrbuf_puts(c->wrbuf, "\n<target>");
350         wrbuf_printf(c->wrbuf, "<id>%s</id>\n", ht[i].id);
351         wrbuf_printf(c->wrbuf, "<hits>%d</hits>\n", ht[i].hits);
352         wrbuf_printf(c->wrbuf, "<diagnostic>%d</diagnostic>\n", ht[i].diagnostic);
353         wrbuf_printf(c->wrbuf, "<records>%d</records>\n", ht[i].records);
354         wrbuf_printf(c->wrbuf, "<state>%s</state>\n", ht[i].state);
355         wrbuf_puts(c->wrbuf, "</target>");
356     }
357
358     wrbuf_puts(c->wrbuf, "</bytarget>");
359     rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
360     http_send_response(c);
361 }
362
363 static void write_metadata(WRBUF w, struct conf_service *service,
364         struct record_metadata **ml, int full)
365 {
366     int imeta;
367
368     for (imeta = 0; imeta < service->num_metadata; imeta++)
369     {
370         struct conf_metadata *cmd = &service->metadata[imeta];
371         struct record_metadata *md;
372         if (!cmd->brief && !full)
373             continue;
374         for (md = ml[imeta]; md; md = md->next)
375         {
376             wrbuf_printf(w, "\n<md-%s>", cmd->name);
377             switch (cmd->type)
378             {
379                 case Metadata_type_generic:
380                     wrbuf_puts(w, md->data.text);
381                     break;
382                 case Metadata_type_year:
383                     wrbuf_printf(w, "%d", md->data.number.min);
384                     if (md->data.number.min != md->data.number.max)
385                         wrbuf_printf(w, "-%d", md->data.number.max);
386                     break;
387                 default:
388                     wrbuf_puts(w, "[can't represent]");
389             }
390             wrbuf_printf(w, "</md-%s>", cmd->name);
391         }
392     }
393 }
394
395 static void write_subrecord(struct record *r, WRBUF w,
396         struct conf_service *service, int show_details)
397 {
398     char *name = session_setting_oneval(client_get_database(r->client), PZ_NAME);
399
400     wrbuf_printf(w, "<location id=\"%s\" name=\"%s\">",
401             client_get_database(r->client)->database->url,
402             *name ? name : "Unknown");
403     if (show_details)
404         write_metadata(w, service, r->metadata, 1);
405     wrbuf_puts(w, "</location>\n");
406 }
407
408 static void cmd_record(struct http_channel *c)
409 {
410     struct http_response *rs = c->response;
411     struct http_request *rq = c->request;
412     struct http_session *s = locate_session(rq, rs);
413     struct record_cluster *rec;
414     struct record *r;
415     struct conf_service *service = global_parameters.server->service;
416     char *idstr = http_argbyname(rq, "id");
417     int id;
418
419     if (!s)
420         return;
421     if (!idstr)
422     {
423         error(rs, "417", "Must supply id", 0);
424         return;
425     }
426     wrbuf_rewind(c->wrbuf);
427     id = atoi(idstr);
428     if (!(rec = show_single(s->psession, id)))
429     {
430         error(rs, "500", "Record missing", 0);
431         return;
432     }
433     wrbuf_puts(c->wrbuf, "<record>\n");
434     wrbuf_printf(c->wrbuf, "<recid>%d</recid>", rec->recid);
435     write_metadata(c->wrbuf, service, rec->metadata, 1);
436     for (r = rec->records; r; r = r->next)
437         write_subrecord(r, c->wrbuf, service, 1);
438     wrbuf_puts(c->wrbuf, "</record>\n");
439     rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
440     http_send_response(c);
441 }
442
443 static void show_records(struct http_channel *c, int active)
444 {
445     struct http_request *rq = c->request;
446     struct http_response *rs = c->response;
447     struct http_session *s = locate_session(rq, rs);
448     struct record_cluster **rl;
449     struct reclist_sortparms *sp;
450     char *start = http_argbyname(rq, "start");
451     char *num = http_argbyname(rq, "num");
452     char *sort = http_argbyname(rq, "sort");
453     int startn = 0;
454     int numn = 20;
455     int total;
456     int total_hits;
457     int i;
458
459     if (!s)
460         return;
461
462     // We haven't counted clients yet if we're called on a block release
463     if (active < 0)
464         active = session_active_clients(s->psession);
465
466     if (start)
467         startn = atoi(start);
468     if (num)
469         numn = atoi(num);
470     if (!sort)
471         sort = "relevance";
472     if (!(sp = reclist_parse_sortparms(c->nmem, sort)))
473     {
474         error(rs, "500", "Bad sort parameters", 0);
475         return;
476     }
477
478     rl = show(s->psession, sp, startn, &numn, &total, &total_hits, c->nmem);
479
480     wrbuf_rewind(c->wrbuf);
481     wrbuf_puts(c->wrbuf, "<show>\n<status>OK</status>\n");
482     wrbuf_printf(c->wrbuf, "<activeclients>%d</activeclients>\n", active);
483     wrbuf_printf(c->wrbuf, "<merged>%d</merged>\n", total);
484     wrbuf_printf(c->wrbuf, "<total>%d</total>\n", total_hits);
485     wrbuf_printf(c->wrbuf, "<start>%d</start>\n", startn);
486     wrbuf_printf(c->wrbuf, "<num>%d</num>\n", numn);
487
488     for (i = 0; i < numn; i++)
489     {
490         int ccount;
491         struct record *p;
492         struct record_cluster *rec = rl[i];
493         struct conf_service *service = global_parameters.server->service;
494
495         wrbuf_puts(c->wrbuf, "<hit>\n");
496         write_metadata(c->wrbuf, service, rec->metadata, 0);
497         for (ccount = 0, p = rl[i]->records; p;  p = p->next, ccount++)
498             write_subrecord(p, c->wrbuf, service, 0); // subrecs w/o details
499         if (ccount > 1)
500             wrbuf_printf(c->wrbuf, "<count>%d</count>\n", ccount);
501         wrbuf_printf(c->wrbuf, "<recid>%d</recid>\n", rec->recid);
502         wrbuf_puts(c->wrbuf, "</hit>\n");
503     }
504
505     wrbuf_puts(c->wrbuf, "</show>\n");
506     rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
507     http_send_response(c);
508 }
509
510 static void show_records_ready(void *data)
511 {
512     struct http_channel *c = (struct http_channel *) data;
513
514     show_records(c, -1);
515 }
516
517 static void cmd_show(struct http_channel *c)
518 {
519     struct http_request *rq = c->request;
520     struct http_response *rs = c->response;
521     struct http_session *s = locate_session(rq, rs);
522     char *block = http_argbyname(rq, "block");
523     int status;
524
525     if (!s)
526         return;
527
528     status = session_active_clients(s->psession);
529
530     if (block)
531     {
532         if (status && (!s->psession->reclist || !s->psession->reclist->num_records))
533         {
534             session_set_watch(s->psession, SESSION_WATCH_RECORDS, show_records_ready, c);
535             yaz_log(YLOG_DEBUG, "Blocking on cmd_show");
536             return;
537         }
538     }
539
540     show_records(c, status);
541 }
542
543 static void cmd_ping(struct http_channel *c)
544 {
545     struct http_request *rq = c->request;
546     struct http_response *rs = c->response;
547     struct http_session *s = locate_session(rq, rs);
548     if (!s)
549         return;
550     rs->payload = "<ping><status>OK</status></ping>";
551     http_send_response(c);
552 }
553
554 static int utf_8_valid(const char *str)
555 {
556     yaz_iconv_t cd = yaz_iconv_open("utf-8", "utf-8");
557     if (cd)
558     {
559         /* check that query is UTF-8 encoded */
560         char *inbuf = (char *) str; /* we know iconv does not alter this */
561         size_t inbytesleft = strlen(inbuf);
562
563         size_t outbytesleft = strlen(inbuf) + 10;
564         char *out = xmalloc(outbytesleft);
565         char *outbuf = out;
566         size_t r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
567
568         /* if OK, try flushing the rest  */
569         if (r != (size_t) (-1))
570             r = yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft);
571         yaz_iconv_close(cd);
572         xfree(out);
573         if (r == (size_t) (-1))
574             return 0;
575     }
576     return 1;
577 }
578
579 static void cmd_search(struct http_channel *c)
580 {
581     struct http_request *rq = c->request;
582     struct http_response *rs = c->response;
583     struct http_session *s = locate_session(rq, rs);
584     char *query = http_argbyname(rq, "query");
585     char *filter = http_argbyname(rq, "filter");
586     char *res;
587
588     if (!s)
589         return;
590     if (!query)
591     {
592         error(rs, "417", "Must supply query", 0);
593         return;
594     }
595     if (!utf_8_valid(query))
596     {
597         error(rs, "417", "Query not UTF-8 encoded", 0);
598         return;
599     }
600     res = search(s->psession, query, filter);
601     if (res)
602     {
603         error(rs, "417", res, 0);
604         return;
605     }
606     rs->payload = "<search><status>OK</status></search>";
607     http_send_response(c);
608 }
609
610
611 static void cmd_stat(struct http_channel *c)
612 {
613     struct http_request *rq = c->request;
614     struct http_response *rs = c->response;
615     struct http_session *s = locate_session(rq, rs);
616     struct statistics stat;
617     int clients;
618
619     if (!s)
620         return;
621
622     clients = session_active_clients(s->psession);
623     statistics(s->psession, &stat);
624
625     wrbuf_rewind(c->wrbuf);
626     wrbuf_puts(c->wrbuf, "<stat>");
627     wrbuf_printf(c->wrbuf, "<activeclients>%d</activeclients>\n", clients);
628     wrbuf_printf(c->wrbuf, "<hits>%d</hits>\n", stat.num_hits);
629     wrbuf_printf(c->wrbuf, "<records>%d</records>\n", stat.num_records);
630     wrbuf_printf(c->wrbuf, "<clients>%d</clients>\n", stat.num_clients);
631     wrbuf_printf(c->wrbuf, "<unconnected>%d</unconnected>\n", stat.num_no_connection);
632     wrbuf_printf(c->wrbuf, "<connecting>%d</connecting>\n", stat.num_connecting);
633     wrbuf_printf(c->wrbuf, "<initializing>%d</initializing>\n", stat.num_initializing);
634     wrbuf_printf(c->wrbuf, "<searching>%d</searching>\n", stat.num_searching);
635     wrbuf_printf(c->wrbuf, "<presenting>%d</presenting>\n", stat.num_presenting);
636     wrbuf_printf(c->wrbuf, "<idle>%d</idle>\n", stat.num_idle);
637     wrbuf_printf(c->wrbuf, "<failed>%d</failed>\n", stat.num_failed);
638     wrbuf_printf(c->wrbuf, "<error>%d</error>\n", stat.num_error);
639     wrbuf_puts(c->wrbuf, "</stat>");
640     rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
641     http_send_response(c);
642 }
643
644 static void cmd_info(struct http_channel *c)
645 {
646     char yaz_version_str[20];
647     struct http_response *rs = c->response;
648
649     wrbuf_rewind(c->wrbuf);
650     wrbuf_puts(c->wrbuf, "<info>\n");
651     wrbuf_printf(c->wrbuf, " <version>\n");
652     wrbuf_printf(c->wrbuf, "  <pazpar2>%s</pazpar2>\n", VERSION);
653
654     yaz_version(yaz_version_str, 0);
655     wrbuf_printf(c->wrbuf, "  <yaz compiled=\"%s\">%s</yaz>\n",
656                  YAZ_VERSION, yaz_version_str);
657     wrbuf_printf(c->wrbuf, " </version>\n");
658     
659     wrbuf_puts(c->wrbuf, "</info>");
660     rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
661     http_send_response(c);
662 }
663
664 struct {
665     char *name;
666     void (*fun)(struct http_channel *c);
667 } commands[] = {
668     { "init", cmd_init },
669     { "settings", cmd_settings },
670     { "stat", cmd_stat },
671     { "bytarget", cmd_bytarget },
672     { "show", cmd_show },
673     { "search", cmd_search },
674     { "termlist", cmd_termlist },
675     { "exit", cmd_exit },
676     { "ping", cmd_ping },
677     { "record", cmd_record },
678     { "info", cmd_info },
679     {0,0}
680 };
681
682 void http_command(struct http_channel *c)
683 {
684     char *command = http_argbyname(c->request, "command");
685     struct http_response *rs = http_create_response(c);
686     int i;
687
688     c->response = rs;
689
690     http_addheader(rs, "Expires", "Thu, 19 Nov 1981 08:52:00 GMT");
691     http_addheader(rs, "Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
692
693     if (!command)
694     {
695         error(rs, "417", "Must supply command", 0);
696         return;
697     }
698     for (i = 0; commands[i].name; i++)
699         if (!strcmp(commands[i].name, command))
700         {
701             (*commands[i].fun)(c);
702             break;
703         }
704     if (!commands[i].name)
705         error(rs, "417", "Unknown command", command);
706
707     return;
708 }
709
710 /*
711  * Local variables:
712  * c-basic-offset: 4
713  * indent-tabs-mode: nil
714  * End:
715  * vim: shiftwidth=4 tabstop=8 expandtab
716  */