mirror of
https://github.com/zeek/zeek.git
synced 2025-10-09 18:18:19 +00:00
Pass key/value types for validation when opening backends
This commit is contained in:
parent
2ea0f3e70a
commit
69d940533d
10 changed files with 100 additions and 54 deletions
|
@ -7,13 +7,22 @@ module Storage;
|
|||
export {
|
||||
## Opens a new backend connection based on a configuration object.
|
||||
##
|
||||
## btype: A tag indicating what type of backend should be opened.
|
||||
## btype: A tag indicating what type of backend should be opened. These are
|
||||
## defined by the backend plugins loaded.
|
||||
##
|
||||
## options: A record containing the configuration for the connection.
|
||||
##
|
||||
## Returns: A handle to the new backend connection, or null if the
|
||||
## connection failed.
|
||||
global open_backend: function(btype: Storage::Backend, options: any): opaque of Storage::BackendHandle;
|
||||
## key_type: The script-level type of keys stored in the backend. Used for
|
||||
## validation of keys passed to other framework methods.
|
||||
##
|
||||
## val_type: The script-level type of keys stored in the backend. Used for
|
||||
## validation of values passed to :zeek:see:`Storage::put` as well as
|
||||
## for type conversions for return values from :zeek:see:`Storage::get`.
|
||||
##
|
||||
## Returns: A handle to the new backend connection, or ``F`` if the connection
|
||||
## failed.
|
||||
global open_backend: function(btype: Storage::Backend, options: any, key_type: any,
|
||||
val_type: any): opaque of Storage::BackendHandle;
|
||||
|
||||
## Closes an existing backend connection.
|
||||
##
|
||||
|
@ -30,10 +39,13 @@ export {
|
|||
##
|
||||
## value: A corresponding value.
|
||||
##
|
||||
## overwrite: A flag indicating whether this value should overwrite an
|
||||
## existing entry for the key.
|
||||
## 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.
|
||||
## Returns: A boolean indicating success or failure of the operation. Type
|
||||
## comparison failures against the types passed to
|
||||
## :zeek:see:`Storage::open_backend` for the backend will cause false to
|
||||
## be returned.
|
||||
global put: function(backend: opaque of Storage::BackendHandle, key: any, value: any, overwrite: bool): bool;
|
||||
|
||||
## Gets an entry from the backend.
|
||||
|
@ -42,12 +54,11 @@ export {
|
|||
##
|
||||
## key: The key to look up.
|
||||
##
|
||||
## val_type: The type of the value to return.
|
||||
##
|
||||
## Returns: A boolean indicating success or failure of the
|
||||
## operation. Type conversion failures for the value will
|
||||
## return false.
|
||||
global get: function(backend: opaque of Storage::BackendHandle, key: any, val_type: any): any;
|
||||
## Returns: A boolean indicating success or failure of the operation. Type
|
||||
## comparison failures against the types passed to
|
||||
## :zeek:see:`Storage::open_backend` for the backend will cause false to
|
||||
## be returned.
|
||||
global get: function(backend: opaque of Storage::BackendHandle, key: any): any;
|
||||
|
||||
## Erases an entry from the backend.
|
||||
##
|
||||
|
@ -55,13 +66,16 @@ export {
|
|||
##
|
||||
## key: The key to erase.
|
||||
##
|
||||
## Returns: A boolean indicating success or failure of the operation.
|
||||
## Returns: A boolean indicating success or failure of the operation. Type
|
||||
## comparison failures against the types passed to
|
||||
## :zeek:see:`Storage::open_backend` for the backend will cause false to
|
||||
## be returned.
|
||||
global erase: function(backend: opaque of Storage::BackendHandle, key: any): bool;
|
||||
}
|
||||
|
||||
function open_backend(btype: Storage::Backend, options: any): opaque of Storage::BackendHandle
|
||||
function open_backend(btype: Storage::Backend, options: any, key_type: any, val_type: any): opaque of Storage::BackendHandle
|
||||
{
|
||||
return Storage::__open_backend(btype, options);
|
||||
return Storage::__open_backend(btype, options, key_type, val_type);
|
||||
}
|
||||
|
||||
function close_backend(backend: opaque of Storage::BackendHandle): bool
|
||||
|
@ -74,9 +88,9 @@ function put(backend: opaque of Storage::BackendHandle, key: any, value: any, ov
|
|||
return Storage::__put(backend, key, value, overwrite);
|
||||
}
|
||||
|
||||
function get(backend: opaque of Storage::BackendHandle, key: any, val_type: any): any
|
||||
function get(backend: opaque of Storage::BackendHandle, key: any): any
|
||||
{
|
||||
return Storage::__get(backend, key, val_type);
|
||||
return Storage::__get(backend, key);
|
||||
}
|
||||
|
||||
function erase(backend: opaque of Storage::BackendHandle, key: any): bool
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue