Permalink
Browse files

Added JSON output.

  • Loading branch information...
nicolasff committed Dec 21, 2010
1 parent 7107ed0 commit 2507fcee7205e39f58d107edf6706cc12bf49adf
View
@@ -1,6 +1,8 @@
OUT=turnip
-OBJS=turnip.o conf.o hiredis/hiredis.o hiredis/sds.o hiredis/net.o hiredis/async.o
-CFLAGS=-O0 -ggdb -Wall -Wextra -I.
+HIREDIS_OBJ=hiredis/hiredis.o hiredis/sds.o hiredis/net.o hiredis/async.o
+JANSSON_OBJ=jansson/src/dump.o jansson/src/error.o jansson/src/hashtable.o jansson/src/load.o jansson/src/strbuffer.o jansson/src/utf.o jansson/src/value.o jansson/src/variadic.o
+OBJS=turnip.o conf.o json.o cmd.o $(HIREDIS_OBJ) $(JANSSON_OBJ)
+CFLAGS=-O0 -ggdb -Wall -Wextra -I. -Ijansson/src
LDFLAGS=-levent
all: $(OUT) Makefile
View
@@ -21,6 +21,23 @@ curl -d "GET/hello" http://127.0.0.1:7379/
* Support PUT, DELETE, HEAD?
* Add JSON output
* Add JSONP callbacks
+* Add support for Redis UNIX socket
* Enrich config file
* Provide timeout
* Restrict commands by IP range
+
+# HTTP error codes
+* Missing key: 404 Not Found
+* Timeout on the redis side: 503 Service Unavailable
+* Unknown verb: 405 Method Not Allowed
+
+
+# JSON output
+
+## /GET/x
+`{"GET": "value here"}`
+
+## /INCR/y
+`{"INCR": 42}`
+
+##
View
89 cmd.c
@@ -0,0 +1,89 @@
+#include "cmd.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <hiredis/hiredis.h>
+
+extern void
+cmdCallback(redisAsyncContext *c, void *r, void *privdata);
+
+struct cmd *
+cmd_new(struct evhttp_request *rq, int count) {
+
+ struct cmd *c = calloc(1, sizeof(struct cmd));
+
+ c->rq = rq;
+ c->count = count;
+
+ c->argv = calloc(count, sizeof(char*));
+ c->argv_len = calloc(count, sizeof(size_t));
+
+ return c;
+}
+
+
+void
+cmd_free(struct cmd *c) {
+
+ free(c->argv);
+ free(c->argv_len);
+
+ free(c);
+}
+
+void
+cmd_run(redisAsyncContext *c, struct evhttp_request *rq, const char *uri, size_t uri_len) {
+
+ char *slash = strchr(uri, '/');
+ int cmd_len;
+ int param_count = 0, cur_param = 1;
+
+ struct cmd *cmd;
+
+ const char *p;
+
+ /* count arguments */
+ for(p = uri; p && p < uri + uri_len; param_count++) {
+ p = strchr(p+1, '/');
+ }
+
+ cmd = cmd_new(rq, param_count);
+
+ if(slash) {
+ cmd_len = slash - uri;
+ } else {
+ cmd_len = uri_len;
+ }
+
+ /* there is always a first parameter, it's the command name */
+ cmd->argv[0] = uri;
+ cmd->argv_len[0] = cmd_len;
+
+ if(!slash) {
+ redisAsyncCommandArgv(c, cmdCallback, cmd, 1, cmd->argv, cmd->argv_len);
+ return;
+ }
+ p = slash + 1;
+ while(p < uri + uri_len) {
+
+ const char *arg = p;
+ int arg_len;
+ char *next = strchr(arg, '/');
+ if(next) { /* found a slash */
+ arg_len = next - arg;
+ p = next + 1;
+ } else { /* last argument */
+ arg_len = uri + uri_len - arg;
+ p = uri + uri_len;
+ }
+
+ /* record argument */
+ cmd->argv[cur_param] = arg;
+ cmd->argv_len[cur_param] = arg_len;
+
+ cur_param++;
+ }
+
+ redisAsyncCommandArgv(c, cmdCallback, cmd, param_count, cmd->argv, cmd->argv_len);
+}
+
View
26 cmd.h
@@ -0,0 +1,26 @@
+#ifndef CMD_H
+#define CMD_H
+
+#include <stdlib.h>
+#include <hiredis/async.h>
+
+struct evhttp_request;
+
+struct cmd {
+
+ int count;
+ const char **argv;
+ size_t *argv_len;
+ struct evhttp_request *rq;
+};
+
+struct cmd *
+cmd_new(struct evhttp_request *rq, int count);
+
+void
+cmd_free(struct cmd *c);
+
+void
+cmd_run(redisAsyncContext *c, struct evhttp_request *rq, const char *uri, size_t uri_len);
+
+#endif
View
@@ -0,0 +1,27 @@
+*~
+*.o
+*.a
+.libs
+.deps
+Makefile
+Makefile.in
+aclocal.m4
+autom4te.cache
+config.guess
+config.h
+config.h.in
+config.log
+config.status
+config.sub
+configure
+depcomp
+install-sh
+libtool
+ltmain.sh
+missing
+*.lo
+*.la
+stamp-h1
+*.pyc
+*.pc
+/src/jansson_config.h
View
@@ -0,0 +1,206 @@
+Version 1.3
+===========
+
+Released 2010-06-13
+
+* New functions:
+
+ - `json_object_iter_set()`, `json_object_iter_set_new()`: Change
+ object contents while iterating over it.
+
+ - `json_object_iter_at()`: Return an iterator that points to a
+ specific object item.
+
+* New encoding flags:
+
+ - ``JSON_PRESERVE_ORDER``: Preserve the insertion order of object
+ keys.
+
+* Bug fixes:
+
+ - Fix an error that occured when an array or object was first
+ encoded as empty, then populated with some data, and then
+ re-encoded
+
+ - Fix the situation like above, but when the first encoding resulted
+ in an error
+
+* Documentation:
+
+ - Clarify the documentation on reference stealing, providing an
+ example usage pattern
+
+
+Version 1.2.1
+=============
+
+Released 2010-04-03
+
+* Bug fixes:
+
+ - Fix reference counting on ``true``, ``false`` and ``null``
+ - Estimate real number underflows in decoder with 0.0 instead of
+ issuing an error
+
+* Portability:
+
+ - Make ``int32_t`` available on all systems
+ - Support compilers that don't have the ``inline`` keyword
+ - Require Autoconf 2.60 (for ``int32_t``)
+
+* Tests:
+
+ - Print test names correctly when ``VERBOSE=1``
+ - ``test/suites/api``: Fail when a test fails
+ - Enhance tests for iterators
+ - Enhance tests for decoding texts that contain null bytes
+
+* Documentation:
+
+ - Don't remove ``changes.rst`` in ``make clean``
+ - Add a chapter on RFC conformance
+
+
+Version 1.2
+===========
+
+Released 2010-01-21
+
+* New functions:
+
+ - `json_equal()`: Test whether two JSON values are equal
+ - `json_copy()` and `json_deep_copy()`: Make shallow and deep copies
+ of JSON values
+ - Add a version of all functions taking a string argument that
+ doesn't check for valid UTF-8: `json_string_nocheck()`,
+ `json_string_set_nocheck()`, `json_object_set_nocheck()`,
+ `json_object_set_new_nocheck()`
+
+* New encoding flags:
+
+ - ``JSON_SORT_KEYS``: Sort objects by key
+ - ``JSON_ENSURE_ASCII``: Escape all non-ASCII Unicode characters
+ - ``JSON_COMPACT``: Use a compact representation with all unneeded
+ whitespace stripped
+
+* Bug fixes:
+
+ - Revise and unify whitespace usage in encoder: Add spaces between
+ array and object items, never append newline to output.
+ - Remove const qualifier from the ``json_t`` parameter in
+ `json_string_set()`, `json_integer_set()` and `json_real_set`.
+ - Use ``int32_t`` internally for representing Unicode code points
+ (int is not enough on all platforms)
+
+* Other changes:
+
+ - Convert ``CHANGES`` (this file) to reStructured text and add it to
+ HTML documentation
+ - The test system has been refactored. Python is no longer required
+ to run the tests.
+ - Documentation can now be built by invoking ``make html``
+ - Support for pkg-config
+
+
+Version 1.1.3
+=============
+
+Released 2009-12-18
+
+* Encode reals correctly, so that first encoding and then decoding a
+ real always produces the same value
+* Don't export private symbols in ``libjansson.so``
+
+
+Version 1.1.2
+=============
+
+Released 2009-11-08
+
+* Fix a bug where an error message was not produced if the input file
+ could not be opened in `json_load_file()`
+* Fix an assertion failure in decoder caused by a minus sign without a
+ digit after it
+* Remove an unneeded include of ``stdint.h`` in ``jansson.h``
+
+
+Version 1.1.1
+=============
+
+Released 2009-10-26
+
+* All documentation files were not distributed with v1.1; build
+ documentation in make distcheck to prevent this in the future
+* Fix v1.1 release date in ``CHANGES``
+
+
+Version 1.1
+===========
+
+Released 2009-10-20
+
+* API additions and improvements:
+
+ - Extend array and object APIs
+ - Add functions to modify integer, real and string values
+ - Improve argument validation
+ - Use unsigned int instead of ``uint32_t`` for encoding flags
+
+* Enhance documentation
+
+ - Add getting started guide and tutorial
+ - Fix some typos
+ - General clarifications and cleanup
+
+* Check for integer and real overflows and underflows in decoder
+* Make singleton values thread-safe (``true``, ``false`` and ``null``)
+* Enhance circular reference handling
+* Don't define ``-std=c99`` in ``AM_CFLAGS``
+* Add C++ guards to ``jansson.h``
+* Minor performance and portability improvements
+* Expand test coverage
+
+
+Version 1.0.4
+=============
+
+Released 2009-10-11
+
+* Relax Autoconf version requirement to 2.59
+* Make Jansson compile on platforms where plain ``char`` is unsigned
+* Fix API tests for object
+
+
+Version 1.0.3
+=============
+
+Released 2009-09-14
+
+* Check for integer and real overflows and underflows in decoder
+* Use the Python json module for tests, or simplejson if the json
+ module is not found
+* Distribute changelog (this file)
+
+
+Version 1.0.2
+=============
+
+Released 2009-09-08
+
+* Handle EOF correctly in decoder
+
+
+Version 1.0.1
+=============
+
+Released 2009-09-04
+
+* Fixed broken `json_is_boolean()`
+
+
+Version 1.0
+===========
+
+Released 2009-08-25
+
+* Initial release
Oops, something went wrong.

0 comments on commit 2507fce

Please sign in to comment.