working redis string connections

This commit is contained in:
Zakir Durumeric 2013-10-11 23:15:59 -04:00
parent 3eb7630f28
commit e49e442535
2 changed files with 25 additions and 21 deletions

View File

@ -28,14 +28,14 @@ static redisContext *rctx;
redisconf_t *redis_parse_connstr(char *connstr)
{
redisconf_t *retv = malloc(sizeof(redisconf_t));
if (strcmp("tcp://", connstr) == 6) {
if (!strncmp("tcp://", connstr, 6)) {
char *servername = malloc(strlen(connstr));
assert(servername);
char *list_name = malloc(strlen(connstr));
assert(list_name);
uint16_t port;
if (scanf(connstr, "tcp://%s:%u/%s", servername,
port, list_name) != 3) {
uint32_t port;
if (sscanf(connstr, "tcp://%[^:]:%u/%s", servername,
&port, list_name) != 3) {
log_fatal("redis", "unable to parse redis connection string. This "
"should be of the form tcp://server:port/list-name "
"for TCP connections. All fields are required.");
@ -45,17 +45,18 @@ redisconf_t *redis_parse_connstr(char *connstr)
retv->port = port;
retv->list_name = list_name;
retv->path = NULL;
} else if (strcmp("local://", connstr) == 8) {
} else if (!strncmp("local://", connstr, 8)) {
// looking for something along the lines of
// local:///tmp/redis.sock/list-name
char *path = malloc(strlen(connstr));
assert(path);
char *list_name = malloc(strlen(connstr));
assert(list_name);
if (scanf(connstr, "local://%s/%s", path,
list_name) != 3) {
log_fatal("redis", "unable to parse redis connection string. This "
"should be of the form tcp://server:port/list-name "
"for TCP connections. All fields are required.");
}
connstr = connstr + (size_t) 8;
char *listname = strrchr(connstr, '/') + (size_t) 1;
connstr[strrchr(connstr, '/') - connstr] = '\0';
strcpy(path, connstr);
strcpy(list_name, listname);
retv->type = T_LOCAL;
retv->list_name = list_name;
retv->path = path;
@ -63,7 +64,7 @@ redisconf_t *redis_parse_connstr(char *connstr)
retv->port = 0;
} else {
log_fatal("redis", "unable to parse connection string. does not begin with "
"unix:// or tcp:// as expected");
"local:// or tcp:// as expected");
}
}

View File

@ -23,7 +23,6 @@
#define UNUSED __attribute__((unused))
#define BUFFER_SIZE 500
#define SOURCE_ZMAP 0
static uint32_t *buffer;
static int buffer_fill = 0;
@ -36,16 +35,20 @@ static int redismodule_init(struct state_conf *conf, char **fields, int fieldlen
assert(buffer);
buffer_fill = 0;
if (conf->output_args) {
redisconf_t *rconf = redis_parse_connstr(conf->output_args);
if (rconf->type == T_TCP) {
log_info("redis-module", "{type: TCP, server: %s, "
"port %u, list %s", rconf->server,
"port: %u, list: %s}", rconf->server,
rconf->port, rconf->list_name);
} else {
log_info("redis-module", "{type: LOCAL, path: %s, "
"list %s", rconf->path, rconf->list_name);
"list: %s}", rconf->path, rconf->list_name);
}
queue_name = rconf->list_name;
} else {
queue_name = "zmap_output";
}
return redis_init(conf->output_args);
}