From e49e4425359ff33ea7d2802d054e49f8e621b304 Mon Sep 17 00:00:00 2001 From: Zakir Durumeric Date: Fri, 11 Oct 2013 23:15:59 -0400 Subject: [PATCH] working redis string connections --- lib/redis.c | 25 +++++++++++++------------ src/output_modules/module_redis.c | 21 ++++++++++++--------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/redis.c b/lib/redis.c index 9383a39..1bad06b 100644 --- a/lib/redis.c +++ b/lib/redis.c @@ -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"); } } diff --git a/src/output_modules/module_redis.c b/src/output_modules/module_redis.c index a2ad693..f766693 100644 --- a/src/output_modules/module_redis.c +++ b/src/output_modules/module_redis.c @@ -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; - 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, - rconf->port, rconf->list_name); + 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, + rconf->port, rconf->list_name); + } else { + log_info("redis-module", "{type: LOCAL, path: %s, " + "list: %s}", rconf->path, rconf->list_name); + } + queue_name = rconf->list_name; } else { - log_info("redis-module", "{type: LOCAL, path: %s, " - "list %s", rconf->path, rconf->list_name); + queue_name = "zmap_output"; } - queue_name = rconf->list_name; return redis_init(conf->output_args); }