Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOD-8036 move AddACLCategory to redismodule-rs #394

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,21 @@ macro_rules! redis_command {
return $crate::raw::Status::Err as c_int;
}

if unsafe {
$crate::raw::RedisModule_SetCommandACLCategories.unwrap()(
command,
acl_categories.as_ptr(),
)
} == $crate::raw::Status::Err as c_int
if let Some(RM_SetCommandACLCategories) =
$crate::raw::RedisModule_SetCommandACLCategories
{
return $crate::raw::Status::Err as c_int;
if RM_SetCommandACLCategories(command, acl_categories.as_ptr())
== $crate::raw::Status::Err as c_int
{
$crate::raw::redis_log(
$ctx,
&format!(
"Error: failed to set command {} ACL categories {}",
$command_name, $acl_categories
),
);
return $crate::raw::Status::Err as c_int;
}
}
}
}};
Expand Down Expand Up @@ -127,6 +134,7 @@ macro_rules! redis_module {
data_types: [
$($data_type:ident),* $(,)*
],
$(acl_category: $acl_category:expr,)* $(,)*
$(init: $init_func:ident,)* $(,)*
$(deinit: $deinit_func:ident,)* $(,)*
$(info: $info_func:ident,)?
Expand Down Expand Up @@ -262,6 +270,16 @@ macro_rules! redis_module {
}
)*

$(
let category = CString::new($acl_category).unwrap();
if let Some(RM_AddACLCategory) = raw::RedisModule_AddACLCategory {
if RM_AddACLCategory(ctx, category.as_ptr()) == raw::Status::Err as c_int {
raw::redis_log(ctx, &format!("Error: failed to add ACL category {}", $acl_category));
return raw::Status::Err as c_int;
}
}
)*

$(
$crate::redis_command!(ctx, $name, $command, $flags, $firstkey, $lastkey, $keystep, $acl_categories);
)*
Expand Down
16 changes: 3 additions & 13 deletions src/native_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl RedisType {
pub fn create_data_type(&self, ctx: *mut raw::RedisModuleCtx) -> Result<(), &str> {
if self.name.len() != 9 {
let msg = "Redis requires the length of native type names to be exactly 9 characters";
redis_log(ctx, format!("{msg}, name is: '{}'", self.name).as_str());
raw::redis_log(ctx, format!("{msg}, name is: '{}'", self.name).as_str());
return Err(msg);
}

Expand All @@ -50,27 +50,17 @@ impl RedisType {
};

if redis_type.is_null() {
redis_log(ctx, "Error: created data type is null");
raw::redis_log(ctx, "Error: created data type is null");
return Err("Error: created data type is null");
}

*self.raw_type.borrow_mut() = redis_type;

redis_log(
raw::redis_log(
ctx,
format!("Created new data type '{}'", self.name).as_str(),
);

Ok(())
}
}

// TODO: Move to raw
#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn redis_log(ctx: *mut raw::RedisModuleCtx, msg: &str) {
let level = CString::new("notice").unwrap(); // FIXME reuse this
let msg = CString::new(msg).unwrap();
unsafe {
raw::RedisModule_Log.unwrap()(ctx, level.as_ptr(), msg.as_ptr());
}
}
9 changes: 9 additions & 0 deletions src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,3 +952,12 @@ impl From<c_int> for Version {
pub fn is_io_error(rdb: *mut RedisModuleIO) -> bool {
unsafe { RedisModule_IsIOError.unwrap()(rdb) != 0 }
}

#[allow(clippy::not_unsafe_ptr_arg_deref)]
pub fn redis_log(ctx: *mut RedisModuleCtx, msg: &str) {
let level = CString::new("notice").unwrap(); // FIXME reuse this
let msg = CString::new(msg).unwrap();
unsafe {
RedisModule_Log.unwrap()(ctx, level.as_ptr(), msg.as_ptr());
}
}
Loading