From ced20d7fc3ee98005ea8a2d09d2a0d99361ff0a4 Mon Sep 17 00:00:00 2001 From: Ebus-at-dockstar Date: Thu, 18 Sep 2014 18:01:01 +0200 Subject: add /api/list --- datastore-leveldb/src/web.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'datastore-leveldb/src/web.cpp') diff --git a/datastore-leveldb/src/web.cpp b/datastore-leveldb/src/web.cpp index 503e3aa..3485539 100644 --- a/datastore-leveldb/src/web.cpp +++ b/datastore-leveldb/src/web.cpp @@ -177,3 +177,25 @@ void web_handle_api_range_size(const boost::cmatch &match, struct mg_connection mg_write(conn, outbuf.str().c_str(), outbuf.tellp()); delete it; } + + +const boost::regex web_handle_api_list_R( + "/api/list"); +void web_handle_api_list(const boost::cmatch &match, struct mg_connection *conn) { + reply_header(conn, true, "OK", "Content-Type: application/json\r\n\r\n"); + mg_write(conn, "[", 1); + + std::list * list = db_list(); + for (std::list::iterator it = list->begin(); + it != list->end(); ++it) { + if (it != list->begin()) { + mg_write(conn, ",\"", 2); + } else { + mg_write(conn, "\"", 1); + } + mg_write(conn, (*it).c_str(), (*it).size()); + mg_write(conn, "\"\n", 2); + } + delete(list); + mg_write(conn, "]", 1); +} -- cgit v1.2.1