summaryrefslogtreecommitdiff
path: root/cethcan/http.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2013-06-04 19:37:09 +0000
committerroot <root@beaglebone.local.sublab.org>2013-06-28 18:55:08 +0000
commitb9041388478bd29c15d35764c2ee20b6bdec6d9e (patch)
tree1ff7d0fa09949c754b833914571b8aff4e5df000 /cethcan/http.c
parentc35cf61a00b0bd8c65b4aec5dc76eb235ab1dc81 (diff)
cethcan: JSON-RPC
Diffstat (limited to 'cethcan/http.c')
-rw-r--r--cethcan/http.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/cethcan/http.c b/cethcan/http.c
index f82d576..60e457c 100644
--- a/cethcan/http.c
+++ b/cethcan/http.c
@@ -66,6 +66,31 @@ out_inval:
evbuffer_free(out);
}
+static void http_jsonrpc_response(void *arg, struct evbuffer *data)
+{
+ struct evhttp_request *req = arg;
+ evhttp_send_reply_chunk(req, data);
+ evhttp_send_reply_end(req);
+}
+
+static void http_jsonrpc(struct evhttp_request *req, void *arg)
+{
+ struct evkeyvalq *outhdr = evhttp_request_get_output_headers(req);
+ struct evbuffer *inp = evhttp_request_get_input_buffer(req);
+
+ if (evhttp_request_get_command(req) != EVHTTP_REQ_POST) {
+ evhttp_send_error(req, 405, "JSON-RPC request must be POSTed");
+ return;
+ }
+
+ evhttp_add_header(outhdr, "Content-Type", "application/json; charset=utf-8");
+ evhttp_send_reply_start(req, 200, "OK");
+ evhttp_request_own(req);
+
+ rpc_perform(inp, http_jsonrpc_response, req);
+ return;
+}
+
static void http_json_bump(struct evhttp_request *req, void *arg)
{
struct evkeyvalq *outhdr = evhttp_request_get_output_headers(req);
@@ -182,6 +207,7 @@ void http_init(void)
evhttp_set_cb(evhttp, "/set", http_json_set, NULL);
evhttp_set_cb(evhttp, "/longpoll", http_json_longpoll, NULL);
evhttp_set_cb(evhttp, "/bump", http_json_bump, NULL);
+ evhttp_set_cb(evhttp, "/jsonrpc", http_jsonrpc, NULL);
evhttp_bind_socket(evhttp, "127.0.0.1", 34999);
longpoll_updatedata();