working redis string connections
This commit is contained in:
parent
3eb7630f28
commit
e49e442535
25
lib/redis.c
25
lib/redis.c
@ -28,14 +28,14 @@ static redisContext *rctx;
|
|||||||
redisconf_t *redis_parse_connstr(char *connstr)
|
redisconf_t *redis_parse_connstr(char *connstr)
|
||||||
{
|
{
|
||||||
redisconf_t *retv = malloc(sizeof(redisconf_t));
|
redisconf_t *retv = malloc(sizeof(redisconf_t));
|
||||||
if (strcmp("tcp://", connstr) == 6) {
|
if (!strncmp("tcp://", connstr, 6)) {
|
||||||
char *servername = malloc(strlen(connstr));
|
char *servername = malloc(strlen(connstr));
|
||||||
assert(servername);
|
assert(servername);
|
||||||
char *list_name = malloc(strlen(connstr));
|
char *list_name = malloc(strlen(connstr));
|
||||||
assert(list_name);
|
assert(list_name);
|
||||||
uint16_t port;
|
uint32_t port;
|
||||||
if (scanf(connstr, "tcp://%s:%u/%s", servername,
|
if (sscanf(connstr, "tcp://%[^:]:%u/%s", servername,
|
||||||
port, list_name) != 3) {
|
&port, list_name) != 3) {
|
||||||
log_fatal("redis", "unable to parse redis connection string. This "
|
log_fatal("redis", "unable to parse redis connection string. This "
|
||||||
"should be of the form tcp://server:port/list-name "
|
"should be of the form tcp://server:port/list-name "
|
||||||
"for TCP connections. All fields are required.");
|
"for TCP connections. All fields are required.");
|
||||||
@ -45,17 +45,18 @@ redisconf_t *redis_parse_connstr(char *connstr)
|
|||||||
retv->port = port;
|
retv->port = port;
|
||||||
retv->list_name = list_name;
|
retv->list_name = list_name;
|
||||||
retv->path = NULL;
|
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));
|
char *path = malloc(strlen(connstr));
|
||||||
assert(path);
|
assert(path);
|
||||||
char *list_name = malloc(strlen(connstr));
|
char *list_name = malloc(strlen(connstr));
|
||||||
assert(list_name);
|
assert(list_name);
|
||||||
if (scanf(connstr, "local://%s/%s", path,
|
connstr = connstr + (size_t) 8;
|
||||||
list_name) != 3) {
|
char *listname = strrchr(connstr, '/') + (size_t) 1;
|
||||||
log_fatal("redis", "unable to parse redis connection string. This "
|
connstr[strrchr(connstr, '/') - connstr] = '\0';
|
||||||
"should be of the form tcp://server:port/list-name "
|
strcpy(path, connstr);
|
||||||
"for TCP connections. All fields are required.");
|
strcpy(list_name, listname);
|
||||||
}
|
|
||||||
retv->type = T_LOCAL;
|
retv->type = T_LOCAL;
|
||||||
retv->list_name = list_name;
|
retv->list_name = list_name;
|
||||||
retv->path = path;
|
retv->path = path;
|
||||||
@ -63,7 +64,7 @@ redisconf_t *redis_parse_connstr(char *connstr)
|
|||||||
retv->port = 0;
|
retv->port = 0;
|
||||||
} else {
|
} else {
|
||||||
log_fatal("redis", "unable to parse connection string. does not begin with "
|
log_fatal("redis", "unable to parse connection string. does not begin with "
|
||||||
"unix:// or tcp:// as expected");
|
"local:// or tcp:// as expected");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
#define UNUSED __attribute__((unused))
|
#define UNUSED __attribute__((unused))
|
||||||
|
|
||||||
#define BUFFER_SIZE 500
|
#define BUFFER_SIZE 500
|
||||||
#define SOURCE_ZMAP 0
|
|
||||||
|
|
||||||
static uint32_t *buffer;
|
static uint32_t *buffer;
|
||||||
static int buffer_fill = 0;
|
static int buffer_fill = 0;
|
||||||
@ -36,16 +35,20 @@ static int redismodule_init(struct state_conf *conf, char **fields, int fieldlen
|
|||||||
assert(buffer);
|
assert(buffer);
|
||||||
buffer_fill = 0;
|
buffer_fill = 0;
|
||||||
|
|
||||||
redisconf_t *rconf = redis_parse_connstr(conf->output_args);
|
if (conf->output_args) {
|
||||||
if (rconf->type == T_TCP) {
|
redisconf_t *rconf = redis_parse_connstr(conf->output_args);
|
||||||
log_info("redis-module", "{type: TCP, server: %s, "
|
if (rconf->type == T_TCP) {
|
||||||
"port %u, list %s", rconf->server,
|
log_info("redis-module", "{type: TCP, server: %s, "
|
||||||
rconf->port, rconf->list_name);
|
"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 {
|
} else {
|
||||||
log_info("redis-module", "{type: LOCAL, path: %s, "
|
queue_name = "zmap_output";
|
||||||
"list %s", rconf->path, rconf->list_name);
|
|
||||||
}
|
}
|
||||||
queue_name = rconf->list_name;
|
|
||||||
return redis_init(conf->output_args);
|
return redis_init(conf->output_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user