mirror of
https://github.com/zeek/zeek.git
synced 2025-10-17 14:08:20 +00:00
Change args to Storage::put to be a record
The number of args being passed to the put() methods was getting to be fairly long, with more on the horizon. Changing to a record means simplifying things a little bit.
This commit is contained in:
parent
69d940533d
commit
8dee733a7d
2 changed files with 21 additions and 11 deletions
|
@ -5,6 +5,19 @@
|
||||||
module Storage;
|
module Storage;
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
## Record for passing arguments to :zeek:see:`Storage::put`.
|
||||||
|
type PutArgs: record {
|
||||||
|
# The key to store the value under.
|
||||||
|
key: any;
|
||||||
|
|
||||||
|
# The value to store associated with the key.
|
||||||
|
value: any;
|
||||||
|
|
||||||
|
# Indicates whether this value should overwrite an existing entry
|
||||||
|
# for the key.
|
||||||
|
overwrite: bool &default=T;
|
||||||
|
};
|
||||||
|
|
||||||
## Opens a new backend connection based on a configuration object.
|
## Opens a new backend connection based on a configuration object.
|
||||||
##
|
##
|
||||||
## btype: A tag indicating what type of backend should be opened. These are
|
## btype: A tag indicating what type of backend should be opened. These are
|
||||||
|
@ -33,20 +46,17 @@ export {
|
||||||
|
|
||||||
## Inserts a new entry into a backend.
|
## Inserts a new entry into a backend.
|
||||||
##
|
##
|
||||||
|
##
|
||||||
## backend: A handle to a backend connection.
|
## backend: A handle to a backend connection.
|
||||||
##
|
##
|
||||||
## key: A key value.
|
## args: A :zeek:see:`Storage::PutArgs` record containing the arguments for the
|
||||||
##
|
## operation.
|
||||||
## value: A corresponding value.
|
|
||||||
##
|
|
||||||
## overwrite: A flag indicating whether this value should overwrite an existing
|
|
||||||
## entry for the key.
|
|
||||||
##
|
##
|
||||||
## Returns: A boolean indicating success or failure of the operation. Type
|
## Returns: A boolean indicating success or failure of the operation. Type
|
||||||
## comparison failures against the types passed to
|
## comparison failures against the types passed to
|
||||||
## :zeek:see:`Storage::open_backend` for the backend will cause false to
|
## :zeek:see:`Storage::open_backend` for the backend will cause false to
|
||||||
## be returned.
|
## be returned.
|
||||||
global put: function(backend: opaque of Storage::BackendHandle, key: any, value: any, overwrite: bool): bool;
|
global put: function(backend: opaque of Storage::BackendHandle, args: Storage::PutArgs): bool;
|
||||||
|
|
||||||
## Gets an entry from the backend.
|
## Gets an entry from the backend.
|
||||||
##
|
##
|
||||||
|
@ -83,9 +93,9 @@ function close_backend(backend: opaque of Storage::BackendHandle): bool
|
||||||
return Storage::__close_backend(backend);
|
return Storage::__close_backend(backend);
|
||||||
}
|
}
|
||||||
|
|
||||||
function put(backend: opaque of Storage::BackendHandle, key: any, value: any, overwrite: bool): bool
|
function put(backend: opaque of Storage::BackendHandle, args: Storage::PutArgs): bool
|
||||||
{
|
{
|
||||||
return Storage::__put(backend, key, value, overwrite);
|
return Storage::__put(backend, args$key, args$value, args$overwrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
function get(backend: opaque of Storage::BackendHandle, key: any): any
|
function get(backend: opaque of Storage::BackendHandle, key: any): any
|
||||||
|
|
|
@ -27,7 +27,7 @@ event zeek_init() {
|
||||||
# Test basic operation. The second get() should return an error
|
# Test basic operation. The second get() should return an error
|
||||||
# as the key should have been erased.
|
# as the key should have been erased.
|
||||||
local b = Storage::open_backend(Storage::STORAGEDUMMY, opts, str, str);
|
local b = Storage::open_backend(Storage::STORAGEDUMMY, opts, str, str);
|
||||||
local put_res = Storage::put(b, key, value, F);
|
local put_res = Storage::put(b, [$key=key, $value=value, $overwrite=F]);
|
||||||
local get_res = Storage::get(b, key);
|
local get_res = Storage::get(b, key);
|
||||||
if ( get_res is bool ) {
|
if ( get_res is bool ) {
|
||||||
print("Got an invalid value in response!");
|
print("Got an invalid value in response!");
|
||||||
|
@ -38,7 +38,7 @@ event zeek_init() {
|
||||||
Storage::close_backend(b);
|
Storage::close_backend(b);
|
||||||
|
|
||||||
# Test attempting to use the closed handle.
|
# Test attempting to use the closed handle.
|
||||||
put_res = Storage::put(b, "a", "b", F);
|
put_res = Storage::put(b, [$key="a", $value="b", $overwrite=F]);
|
||||||
get_res = Storage::get(b, "a");
|
get_res = Storage::get(b, "a");
|
||||||
erase_res = Storage::erase(b, "a");
|
erase_res = Storage::erase(b, "a");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue