2 * $Id: http_command.c,v 1.1 2006-11-21 18:46:43 quinn Exp $
13 #include <yaz/yaz-util.h>
20 #include "http_command.h"
23 struct session *psession;
26 struct http_session *next;
29 static struct http_session *session_list = 0;
31 struct http_session *http_session_create()
33 struct http_session *r = xmalloc(sizeof(*r));
35 *r->session_id = '\0';
37 r->next = session_list;
42 void http_session_destroy(struct http_session *s)
44 struct http_session **p;
46 for (p = &session_list; *p; p = &(*p)->next)
52 session_destroy(s->psession);
56 static void error(struct http_response *rs, char *code, char *msg, char *txt)
58 struct http_channel *c = rs->channel;
63 rs->msg = nmem_strdup(c->nmem, msg);
64 strcpy(rs->code, code);
65 sprintf(tmp, "<error code=\"general\">%s</error>", txt);
66 rs->payload = nmem_strdup(c->nmem, tmp);
69 static void cmd_init(struct http_request *rq, struct http_response *rs)
73 static void cmd_stat(struct http_request *rq, struct http_response *rs)
77 static void cmd_load(struct http_request *rq, struct http_response *rs)
83 void (*fun)(struct http_request *rq, struct http_response *rs);
91 struct http_response *http_command(struct http_request *rq)
93 char *command = argbyname(rq, "command");
94 struct http_channel *c = rq->channel;
95 struct http_response *rs = http_create_response(c);
100 error(rs, "417", "Must supply command", 0);
103 for (i = 0; commands[i].name; i++)
104 if (!strcmp(commands[i].name, command))
106 (*commands[i].fun)(rq, rs);
109 if (!commands[i].name)
110 error(rs, "417", "Unknown command", 0);
118 * indent-tabs-mode: nil
120 * vim: shiftwidth=4 tabstop=8 expandtab