Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
1483f5aa
Unverified
Commit
1483f5aa
authored
Aug 01, 2021
by
Guy Korland
Committed by
GitHub
Aug 01, 2021
Browse files
Remove const from CommandFilterArgGet result (#9247)
Co-authored-by:
Yossi Gottlieb
<
yossigo@gmail.com
>
parent
89fdcbec
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
1483f5aa
...
...
@@ -7551,7 +7551,7 @@ int RM_CommandFilterArgsCount(RedisModuleCommandFilterCtx *fctx)
/* Return the specified command argument. The first argument (position 0) is
* the command itself, and the rest are user-provided args.
*/
const
RedisModuleString
*
RM_CommandFilterArgGet
(
RedisModuleCommandFilterCtx
*
fctx
,
int
pos
)
RedisModuleString
*
RM_CommandFilterArgGet
(
RedisModuleCommandFilterCtx
*
fctx
,
int
pos
)
{
if
(
pos
<
0
||
pos
>=
fctx
->
argc
)
return
NULL
;
return
fctx
->
argv
[
pos
];
...
...
src/redismodule.h
View file @
1483f5aa
...
...
@@ -835,7 +835,7 @@ REDISMODULE_API void * (*RedisModule_GetSharedAPI)(RedisModuleCtx *ctx, const ch
REDISMODULE_API
RedisModuleCommandFilter
*
(
*
RedisModule_RegisterCommandFilter
)(
RedisModuleCtx
*
ctx
,
RedisModuleCommandFilterFunc
cb
,
int
flags
)
REDISMODULE_ATTR
;
REDISMODULE_API
int
(
*
RedisModule_UnregisterCommandFilter
)(
RedisModuleCtx
*
ctx
,
RedisModuleCommandFilter
*
filter
)
REDISMODULE_ATTR
;
REDISMODULE_API
int
(
*
RedisModule_CommandFilterArgsCount
)(
RedisModuleCommandFilterCtx
*
fctx
)
REDISMODULE_ATTR
;
REDISMODULE_API
const
RedisModuleString
*
(
*
RedisModule_CommandFilterArgGet
)(
RedisModuleCommandFilterCtx
*
fctx
,
int
pos
)
REDISMODULE_ATTR
;
REDISMODULE_API
RedisModuleString
*
(
*
RedisModule_CommandFilterArgGet
)(
RedisModuleCommandFilterCtx
*
fctx
,
int
pos
)
REDISMODULE_ATTR
;
REDISMODULE_API
int
(
*
RedisModule_CommandFilterArgInsert
)(
RedisModuleCommandFilterCtx
*
fctx
,
int
pos
,
RedisModuleString
*
arg
)
REDISMODULE_ATTR
;
REDISMODULE_API
int
(
*
RedisModule_CommandFilterArgReplace
)(
RedisModuleCommandFilterCtx
*
fctx
,
int
pos
,
RedisModuleString
*
arg
)
REDISMODULE_ATTR
;
REDISMODULE_API
int
(
*
RedisModule_CommandFilterArgDelete
)(
RedisModuleCommandFilterCtx
*
fctx
,
int
pos
)
REDISMODULE_ATTR
;
...
...
tests/modules/commandfilter.c
View file @
1483f5aa
...
...
@@ -7,10 +7,12 @@ static RedisModuleString *log_key_name;
static
const
char
log_command_name
[]
=
"commandfilter.log"
;
static
const
char
ping_command_name
[]
=
"commandfilter.ping"
;
static
const
char
retained_command_name
[]
=
"commandfilter.retained"
;
static
const
char
unregister_command_name
[]
=
"commandfilter.unregister"
;
static
int
in_log_command
=
0
;
static
RedisModuleCommandFilter
*
filter
=
NULL
;
static
RedisModuleString
*
retained
=
NULL
;
int
CommandFilter_UnregisterCommand
(
RedisModuleCtx
*
ctx
,
RedisModuleString
**
argv
,
int
argc
)
{
...
...
@@ -39,6 +41,20 @@ int CommandFilter_PingCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int
return
REDISMODULE_OK
;
}
int
CommandFilter_Retained
(
RedisModuleCtx
*
ctx
,
RedisModuleString
**
argv
,
int
argc
)
{
(
void
)
argc
;
(
void
)
argv
;
if
(
retained
)
{
RedisModule_ReplyWithString
(
ctx
,
retained
);
}
else
{
RedisModule_ReplyWithNull
(
ctx
);
}
return
REDISMODULE_OK
;
}
int
CommandFilter_LogCommand
(
RedisModuleCtx
*
ctx
,
RedisModuleString
**
argv
,
int
argc
)
{
RedisModuleString
*
s
=
RedisModule_CreateString
(
ctx
,
""
,
0
);
...
...
@@ -106,6 +122,11 @@ void CommandFilter_CommandFilter(RedisModuleCommandFilterCtx *filter)
RedisModule_CommandFilterArgInsert
(
filter
,
pos
+
1
,
RedisModule_CreateString
(
NULL
,
"--inserted-after--"
,
18
));
pos
++
;
}
else
if
(
arg_len
==
7
&&
!
memcmp
(
arg_str
,
"@retain"
,
7
))
{
if
(
retained
)
RedisModule_FreeString
(
NULL
,
retained
);
retained
=
RedisModule_CommandFilterArgGet
(
filter
,
pos
+
1
);
RedisModule_RetainString
(
NULL
,
retained
);
pos
++
;
}
else
if
(
arg_len
==
4
&&
!
memcmp
(
arg_str
,
"@log"
,
4
))
{
log
=
1
;
}
...
...
@@ -137,6 +158,10 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
CommandFilter_PingCommand
,
"deny-oom"
,
1
,
1
,
1
)
==
REDISMODULE_ERR
)
return
REDISMODULE_ERR
;
if
(
RedisModule_CreateCommand
(
ctx
,
retained_command_name
,
CommandFilter_Retained
,
"readonly"
,
1
,
1
,
1
)
==
REDISMODULE_ERR
)
return
REDISMODULE_ERR
;
if
(
RedisModule_CreateCommand
(
ctx
,
unregister_command_name
,
CommandFilter_UnregisterCommand
,
"write deny-oom"
,
1
,
1
,
1
)
==
REDISMODULE_ERR
)
return
REDISMODULE_ERR
;
...
...
@@ -150,5 +175,6 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
int
RedisModule_OnUnload
(
RedisModuleCtx
*
ctx
)
{
RedisModule_FreeString
(
ctx
,
log_key_name
);
if
(
retained
)
RedisModule_FreeString
(
NULL
,
retained
);
return
REDISMODULE_OK
;
}
tests/unit/moduleapi/commandfilter.tcl
View file @
1483f5aa
...
...
@@ -3,6 +3,13 @@ set testmodule [file normalize tests/modules/commandfilter.so]
start_server
{
tags
{
"modules"
}}
{
r module load $testmodule log-key 0
test
{
Retain a command filter argument
}
{
# Retain an argument now. Later we'll try to re-read it and make sure
# it is not corrupt and that valgrind does not complain.
r rpush some-list @retain my-retained-string
r commandfilter.retained
}
{
my-retained-string
}
test
{
Command Filter handles redirected commands
}
{
r set mykey @log
r lrange log-key 0 -1
...
...
@@ -43,6 +50,10 @@ start_server {tags {"modules"}} {
r lrange log-key 0 -1
}
"{ping @log}"
test
{
Command Filter strings can be retained
}
{
r commandfilter.retained
}
{
my-retained-string
}
test
{
Command Filter is unregistered implicitly on module unload
}
{
r del log-key
r module unload commandfilter
...
...
@@ -80,5 +91,4 @@ start_server {tags {"modules"}} {
r eval
"redis.call('commandfilter.ping')"
0
assert_equal
{}
[
r lrange log-key 0 -1
]
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment