summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYossi Gottlieb <yossigo@gmail.com>2019-03-18 23:05:52 +0200
committerantirez <antirez@gmail.com>2019-05-13 16:35:32 +0200
commit6dd5bad49bbdb784d78200ddbc99dc0c7569ff72 (patch)
treee10df6098161138895e63f012d7e16b492da5d7b
parent8302610199a07043dfa88f1eb0d5a276c661e7af (diff)
downloadredis-6dd5bad49bbdb784d78200ddbc99dc0c7569ff72.tar.gz
CommandFilter API: More cleanup.
-rw-r--r--src/module.c37
-rw-r--r--src/redismodule.h2
2 files changed, 10 insertions, 29 deletions
diff --git a/src/module.c b/src/module.c
index 8bf8a3d7b..919671114 100644
--- a/src/module.c
+++ b/src/module.c
@@ -270,32 +270,23 @@ typedef struct RedisModuleDictIter {
raxIterator ri;
} RedisModuleDictIter;
-/* Information about the command to be executed, as passed to and from a
- * filter. */
-typedef struct RedisModuleFilteredCommand {
+typedef struct RedisModuleCommandFilterCtx {
RedisModuleString **argv;
int argc;
-} RedisModuleFilteredCommand;
+} RedisModuleCommandFilterCtx;
-typedef void (*RedisModuleCommandFilterFunc) (RedisModuleCtx *ctx, RedisModuleFilteredCommand *cmd);
+typedef void (*RedisModuleCommandFilterFunc) (RedisModuleCommandFilterCtx *filter);
typedef struct RedisModuleCommandFilter {
/* The module that registered the filter */
RedisModule *module;
/* Filter callback function */
RedisModuleCommandFilterFunc callback;
- /* Indicates a filter is active, avoid reentrancy */
- int active;
} RedisModuleCommandFilter;
/* Registered filters */
static list *moduleCommandFilters;
-typedef struct RedisModuleCommandFilterCtx {
- RedisModuleString **argv;
- int argc;
-} RedisModuleCommandFilterCtx;
-
/* --------------------------------------------------------------------------
* Prototypes
* -------------------------------------------------------------------------- */
@@ -4804,16 +4795,13 @@ int moduleUnregisterUsedAPI(RedisModule *module) {
/* Register a new command filter function. Filters get executed by Redis
* before processing an inbound command and can be used to manipulate the
- * behavior of standard Redis commands. Filters must not attempt to
- * perform Redis commands or operate on the dataset, and must restrict
- * themselves to manipulation of the arguments.
+ * behavior of standard Redis commands.
*/
int RM_RegisterCommandFilter(RedisModuleCtx *ctx, RedisModuleCommandFilterFunc callback) {
RedisModuleCommandFilter *filter = zmalloc(sizeof(*filter));
filter->module = ctx->module;
filter->callback = callback;
- filter->active = 0;
listAddNodeTail(moduleCommandFilters, filter);
return REDISMODULE_OK;
@@ -4826,26 +4814,19 @@ void moduleCallCommandFilters(client *c) {
listNode *ln;
listRewind(moduleCommandFilters,&li);
- RedisModuleFilteredCommand cmd = {
+ RedisModuleCommandFilterCtx filter = {
.argv = c->argv,
.argc = c->argc
};
while((ln = listNext(&li))) {
- RedisModuleCommandFilter *filter = ln->value;
- if (filter->active) continue;
+ RedisModuleCommandFilter *f = ln->value;
- RedisModuleCtx ctx = REDISMODULE_CTX_INIT;
- ctx.module = filter->module;
-
- filter->active = 1;
- filter->callback(&ctx, &cmd);
- filter->active = 0;
- moduleFreeContext(&ctx);
+ f->callback(&filter);
}
- c->argv = cmd.argv;
- c->argc = cmd.argc;
+ c->argv = filter.argv;
+ c->argc = filter.argc;
}
/* Return the number of arguments a filtered command has. The number of
diff --git a/src/redismodule.h b/src/redismodule.h
index a4d66544e..b89be1012 100644
--- a/src/redismodule.h
+++ b/src/redismodule.h
@@ -163,7 +163,7 @@ typedef void (*RedisModuleTypeDigestFunc)(RedisModuleDigest *digest, void *value
typedef void (*RedisModuleTypeFreeFunc)(void *value);
typedef void (*RedisModuleClusterMessageReceiver)(RedisModuleCtx *ctx, const char *sender_id, uint8_t type, const unsigned char *payload, uint32_t len);
typedef void (*RedisModuleTimerProc)(RedisModuleCtx *ctx, void *data);
-typedef void (*RedisModuleCommandFilterFunc) (RedisModuleCtx *ctx, RedisModuleCommandFilterCtx *filter);
+typedef void (*RedisModuleCommandFilterFunc) (RedisModuleCommandFilterCtx *filter);
#define REDISMODULE_TYPE_METHOD_VERSION 1
typedef struct RedisModuleTypeMethods {