summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Noordhuis <pcnoordhuis@gmail.com>2011-04-21 14:21:58 +0200
committerPieter Noordhuis <pcnoordhuis@gmail.com>2011-04-21 14:21:58 +0200
commit727e1babeccc40c9823e477df3de9986cf172659 (patch)
tree62af38fc4f1615d7a48a3a48a3aea3732733b49c
parentfc790ebea63d122066180b255e6a3b980b37f73e (diff)
Make redisReader struct public
-rw-r--r--hiredis.c31
-rw-r--r--hiredis.h32
2 files changed, 32 insertions, 31 deletions
diff --git a/hiredis.c b/hiredis.c
index 8d39692..8b121f1 100644
--- a/hiredis.c
+++ b/hiredis.c
@@ -41,21 +41,6 @@
#include "sds.h"
#include "util.h"
-typedef struct redisReader {
- int err; /* Error flags, 0 when there is no error */
- char errstr[128]; /* String representation of error when applicable */
- struct redisReplyObjectFunctions *fn;
- void *reply; /* holds temporary reply */
-
- sds buf; /* read buffer */
- size_t pos; /* buffer cursor */
- size_t len; /* buffer length */
-
- redisReadTask rstack[3]; /* stack of read tasks */
- int ridx; /* index of stack */
- void *privdata; /* user-settable arbitrary field */
-} redisReader;
-
static redisReply *createReplyObject(int type);
static void *createStringObject(const redisReadTask *task, char *str, size_t len);
static void *createArrayObject(const redisReadTask *task, int elements);
@@ -542,7 +527,7 @@ static int processItem(redisReader *r) {
}
}
-void *redisReplyReaderCreate(void) {
+redisReader *redisReplyReaderCreate(void) {
redisReader *r = calloc(sizeof(redisReader),1);
r->err = 0;
r->errstr[0] = '\0';
@@ -554,7 +539,7 @@ void *redisReplyReaderCreate(void) {
/* Set the function set to build the reply. Returns REDIS_OK when there
* is no temporary object and it can be set, REDIS_ERR otherwise. */
-int redisReplyReaderSetReplyObjectFunctions(void *reader, redisReplyObjectFunctions *fn) {
+int redisReplyReaderSetReplyObjectFunctions(redisReader *reader, redisReplyObjectFunctions *fn) {
redisReader *r = reader;
if (r->reply == NULL) {
r->fn = fn;
@@ -565,7 +550,7 @@ int redisReplyReaderSetReplyObjectFunctions(void *reader, redisReplyObjectFuncti
/* Set the private data field that is used in the read tasks. This argument can
* be used to curry arbitrary data to the custom reply object functions. */
-int redisReplyReaderSetPrivdata(void *reader, void *privdata) {
+int redisReplyReaderSetPrivdata(redisReader *reader, void *privdata) {
redisReader *r = reader;
if (r->reply == NULL) {
r->privdata = privdata;
@@ -578,12 +563,12 @@ int redisReplyReaderSetPrivdata(void *reader, void *privdata) {
* variable while the reply is built up. When the reader contains an
* object in between receiving some bytes to parse, this object might
* otherwise be free'd by garbage collection. */
-void *redisReplyReaderGetObject(void *reader) {
+void *redisReplyReaderGetObject(redisReader *reader) {
redisReader *r = reader;
return r->reply;
}
-void redisReplyReaderFree(void *reader) {
+void redisReplyReaderFree(redisReader *reader) {
redisReader *r = reader;
if (r->reply != NULL && r->fn && r->fn->freeObject)
r->fn->freeObject(r->reply);
@@ -592,12 +577,12 @@ void redisReplyReaderFree(void *reader) {
free(r);
}
-char *redisReplyReaderGetError(void *reader) {
+char *redisReplyReaderGetError(redisReader *reader) {
redisReader *r = reader;
return r->errstr;
}
-void redisReplyReaderFeed(void *reader, const char *buf, size_t len) {
+void redisReplyReaderFeed(redisReader *reader, const char *buf, size_t len) {
redisReader *r = reader;
/* Copy the provided buffer. */
@@ -614,7 +599,7 @@ void redisReplyReaderFeed(void *reader, const char *buf, size_t len) {
}
}
-int redisReplyReaderGetReply(void *reader, void **reply) {
+int redisReplyReaderGetReply(redisReader *reader, void **reply) {
redisReader *r = reader;
/* Default target pointer to NULL. */
diff --git a/hiredis.h b/hiredis.h
index 858ec8d..e581684 100644
--- a/hiredis.h
+++ b/hiredis.h
@@ -129,15 +129,31 @@ typedef struct redisContext {
void *reader;
} redisContext;
+typedef struct redisReader {
+ int err; /* Error flags, 0 when there is no error */
+ char errstr[128]; /* String representation of error when applicable */
+
+ char *buf; /* Read buffer */
+ size_t pos; /* Buffer cursor */
+ size_t len; /* Buffer length */
+
+ redisReadTask rstack[3];
+ int ridx; /* Index of current read task */
+ void *reply; /* Temporary reply pointer */
+
+ redisReplyObjectFunctions *fn;
+ void *privdata;
+} redisReader;
+
void freeReplyObject(void *reply);
-void *redisReplyReaderCreate(void);
-int redisReplyReaderSetReplyObjectFunctions(void *reader, redisReplyObjectFunctions *fn);
-int redisReplyReaderSetPrivdata(void *reader, void *privdata);
-void *redisReplyReaderGetObject(void *reader);
-char *redisReplyReaderGetError(void *reader);
-void redisReplyReaderFree(void *ptr);
-void redisReplyReaderFeed(void *reader, const char *buf, size_t len);
-int redisReplyReaderGetReply(void *reader, void **reply);
+redisReader *redisReplyReaderCreate(void);
+int redisReplyReaderSetReplyObjectFunctions(redisReader *reader, redisReplyObjectFunctions *fn);
+int redisReplyReaderSetPrivdata(redisReader *reader, void *privdata);
+void *redisReplyReaderGetObject(redisReader *reader);
+char *redisReplyReaderGetError(redisReader *reader);
+void redisReplyReaderFree(redisReader *ptr);
+void redisReplyReaderFeed(redisReader *reader, const char *buf, size_t len);
+int redisReplyReaderGetReply(redisReader *reader, void **reply);
/* Functions to format a command according to the protocol. */
int redisvFormatCommand(char **target, const char *format, va_list ap);