Skip to content

Commit

Permalink
Bugfix in RAW mode, more code doc.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasff committed Jan 3, 2011
1 parent 07d7c13 commit a3aa1a9
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions cmd.c
Expand Up @@ -92,7 +92,7 @@ cmd_run(struct server *s, struct evhttp_request *rq,
const char *uri, size_t uri_len) {

char *qmark = strchr(uri, '?');
char *slash = strchr(uri, '/');
char *slash;
const char *p;
int cmd_len;
int param_count = 0, cur_param = 1, i;
Expand All @@ -112,6 +112,7 @@ cmd_run(struct server *s, struct evhttp_request *rq,

cmd = cmd_new(rq, param_count);

slash = memchr(uri, '/', uri_len);
if(slash) {
cmd_len = slash - uri;
} else {
Expand Down Expand Up @@ -145,6 +146,7 @@ cmd_run(struct server *s, struct evhttp_request *rq,
evhttp_connection_set_closecb(rq->evcon, on_http_disconnect, ps);
}

/* no args (e.g. INFO command) */
if(!slash) {
redisAsyncCommandArgv(s->ac, f_format, cmd, 1, cmd->argv, cmd->argv_len);
return 0;
Expand All @@ -171,6 +173,7 @@ cmd_run(struct server *s, struct evhttp_request *rq,
/* transform command if we need to. */
if(f_transform) f_transform(cmd);

/* push command to Redis. */
redisAsyncCommandArgv(s->ac, f_format, cmd, cmd->count, cmd->argv, cmd->argv_len);

for(i = 1; i < cur_param; ++i) {
Expand All @@ -180,6 +183,10 @@ cmd_run(struct server *s, struct evhttp_request *rq,
return 0;
}

/**
* Return 2 functions, one to format the reply and
* one to transform the command before processing it.
*/
void
get_functions(struct cmd *cmd, formatting_fun *f_format, transform_fun *f_transform) {

Expand All @@ -189,20 +196,20 @@ get_functions(struct cmd *cmd, formatting_fun *f_format, transform_fun *f_transf
*f_format = json_reply;
*f_transform = NULL;

/* check for JSONP */
/* loop over the query string */
TAILQ_FOREACH(kv, &cmd->uri_params, next) {
if(strcmp(kv->key, "format") == 0) {
if(strcmp(kv->key, "format") == 0) { /* output format */
if(strcmp(kv->value, "raw") == 0) {
*f_format = raw_reply;
} else if(strcmp(kv->value, "json") == 0) {
*f_format = json_reply;
}
break;
} else if(strcmp(kv->key, "typeKey") == 0) { /* MIME type in key. */
} else if(strcmp(kv->key, "typeKey") == 0) { /* MIME type in a key. */
cmd->mimeKey = strdup(kv->value);
*f_transform = custom_type_process_cmd;
*f_format = custom_type_reply;
} else if(strcmp(kv->key, "type") == 0) { /* MIME type in parameter */
} else if(strcmp(kv->key, "type") == 0) { /* MIME type directly in parameter */
cmd->mime = strdup(kv->value);
*f_format = custom_type_reply;
}
Expand Down

0 comments on commit a3aa1a9

Please sign in to comment.