High Performance OPC UA Server SDK  1.7.1.383
filetransfer

For creating instances of filetypes and managing those types. More...

Data Structures

struct  ua_file_context
 Stores the information about a file. More...
 
struct  ua_file_handle
 Stores the information of an opened file. More...
 
interface  ua_filetype_interface
 Interface table for implementing custom filetypes. More...
 
struct  ua_filetype_callbacks
 Filetype user callback table. More...
 
struct  ua_trustlist_create_args
 
struct  ua_filetype_trust_list_interface
 
class  ua_filesystem_implementation
 
class  ua_memoryfile_implementation
 
class  ua_trustlistfile_implementation
 

Macros

#define UA_FILETYPE_READ   1
 READ bit as defined in OPC UA Spec, Part 5, Annex C.
 
#define UA_FILETYPE_WRITE   2
 WRITE bit as defined in OPC UA Spec, Part 5, Annex C.
 
#define UA_FILETYPE_ERASEEXISTING   4
 ERASEEXISTING bit as defined in OPC UA Spec, Part 5, Annex C.
 
#define UA_FILETYPE_APPEND   8
 APPEND bit as defined in OPC UA Spec, Part 5, Annex C.
 
#define UA_FILETYPE_CALLBACKS_INITIALIZER
 This macro can be used to initialize variables of type ua_filetype_callbacks. More...
 

Functions

SERVER_EXPORT int ua_file_context_init (struct ua_file_context *ctx, struct ua_filetype_interface *ftif, const void *args)
 
SERVER_EXPORT int ua_file_context_clear (struct ua_file_context *ctx)
 
SERVER_EXPORT struct ua_file_contextua_file_context_create (struct ua_filetype_interface *ftif, const void *args)
 
SERVER_EXPORT void ua_file_context_delete (struct ua_file_context *ctx)
 
SERVER_EXPORT void ua_file_context_set_node (struct ua_file_context *ctx, ua_node_t node)
 
SERVER_EXPORT ua_statuscode ua_file_context_open (struct ua_file_context *ctx, bool exclusive)
 
SERVER_EXPORT ua_statuscode ua_file_context_close (struct ua_file_context *ctx)
 
SERVER_EXPORT ua_statuscode ua_file_context_set_mimetype (struct ua_file_context *ctx, const char *mimetype)
 Sets the optional Mime Type of the file context. More...
 
SERVER_EXPORT int ua_file_handle_init (void)
 
SERVER_EXPORT int ua_file_handle_cleanup (void)
 
SERVER_EXPORT struct ua_file_handleua_file_handle_create (struct ua_file_context *file, uint8_t mode)
 Creates a new file handle context. More...
 
SERVER_EXPORT int ua_file_handle_delete (struct ua_file_handle *fh)
 
SERVER_EXPORT struct ua_file_handleua_file_handle_lookup (uint32_t handle)
 Lookup file context by its handle. More...
 
SERVER_EXPORT void ua_file_handle_update_use_timestamp (struct ua_file_handle *fh)
 
SERVER_EXPORT ua_statuscode ua_file_handle_open (struct ua_file_handle *fh)
 
SERVER_EXPORT ua_statuscode ua_file_handle_close (struct ua_file_handle *fh)
 
SERVER_EXPORT ua_statuscode ua_file_handle_read (struct ua_file_handle *fh, int32_t length, struct ua_bytestring *data)
 
SERVER_EXPORT ua_statuscode ua_file_handle_write (struct ua_file_handle *fh, const struct ua_bytestring *data)
 
SERVER_EXPORT ua_statuscode ua_file_handle_getposition (struct ua_file_handle *fh, uint64_t *position)
 
SERVER_EXPORT ua_statuscode ua_file_handle_setposition (struct ua_file_handle *fh, const uint64_t *position)
 
SERVER_EXPORT ua_statuscode ua_file_handle_getsize (struct ua_file_handle *fh, uint64_t *position)
 
SERVER_NO_EXPORT ua_statuscode ua_filesystemimpl_create (struct ua_file_context *ctx, const void *args)
 
SERVER_NO_EXPORT ua_statuscode ua_filesystemimpl_delete (struct ua_file_context *ctx)
 
SERVER_NO_EXPORT ua_statuscode ua_filesystemimpl_open (struct ua_file_handle *ctx, uint8_t mode)
 
SERVER_NO_EXPORT ua_statuscode ua_filesystemimpl_close (struct ua_file_handle *ctx)
 
SERVER_NO_EXPORT ua_statuscode ua_filesystemimpl_read (struct ua_file_handle *ctx, int32_t length, struct ua_bytestring *data)
 
SERVER_NO_EXPORT ua_statuscode ua_filesystemimpl_write (struct ua_file_handle *ctx, const struct ua_bytestring *data)
 
SERVER_NO_EXPORT ua_statuscode ua_filesystemimpl_get_position (struct ua_file_handle *ctx, uint64_t *position)
 
SERVER_NO_EXPORT ua_statuscode ua_filesystemimpl_set_position (struct ua_file_handle *ctx, const uint64_t *position)
 
SERVER_NO_EXPORT ua_statuscode ua_filesystemimpl_get_size (struct ua_file_context *ctx, uint64_t *size)
 
SERVER_EXPORT struct ua_filetype_ctxua_filetype_ctx_create (void)
 Creates new instance of a ua_filetype_ctx, which servers the same purpose as ua_instance_ctx, but for ua_filetype_create_ex(). More...
 
SERVER_EXPORT void ua_filetype_ctx_delete (struct ua_filetype_ctx *ctx)
 Deletes the context created with ua_filetype_ctx_create().
 
SERVER_EXPORT void ua_filetype_ctx_set_mime_type (struct ua_filetype_ctx *ctx, const char *mimetype)
 Sets the optional MIME type of the file that should be created. More...
 
SERVER_EXPORT ua_node_t ua_filetype_ctx_get_new_node (struct ua_filetype_ctx *ctx)
 Returns the newly create filetype node. More...
 
SERVER_EXPORT void ua_filetype_ctx_set_cb_data (struct ua_filetype_ctx *ctx, void *data)
 Set some arbitrary callback data, can be retrieved with ua_instance_get_cb_data. More...
 
SERVER_EXPORT void ua_filetype_ctx_set_pre_create_cb (struct ua_filetype_ctx *ctx, ua_instance_pre_create_cb cb)
 Set the pre create callback. More...
 
SERVER_EXPORT void ua_filetype_ctx_set_post_create_cb (struct ua_filetype_ctx *ctx, ua_instance_post_create_cb cb)
 Set the post create callback. More...
 
SERVER_EXPORT void ua_filetype_ctx_set_delete_cb (struct ua_filetype_ctx *ctx, ua_instance_delete_cb cb)
 Set the delete callback. More...
 
SERVER_EXPORT void ua_filetype_ctx_set_parent (struct ua_filetype_ctx *ctx, ua_node_t parent_node, ua_node_t ref_type)
 Set a parent for new instances. More...
 
SERVER_EXPORT uint32_t ua_filetype_ctx_get_last_numeric_id (struct ua_filetype_ctx *ctx)
 Get the number used for the last created node with numeric nodeid. More...
 
SERVER_EXPORT int ua_filetype_init (void)
 
SERVER_EXPORT int ua_filetype_cleanup (void)
 
SERVER_EXPORT ua_node_t ua_filetype_create (const struct ua_nodeid *nodeid, ua_node_t type, const char *displayname, struct ua_filetype_interface *ftif, const void *args)
 Creates an instance of a file type. More...
 
SERVER_EXPORT int ua_filetype_create_ex (struct ua_filetype_ctx *ctx, const struct ua_nodeid *nodeid, ua_node_t type, uint16_t browsename_idx, const char *browsename, const char *displayname, struct ua_filetype_interface *ftif, const void *args)
 Creates an instance of a file type. More...
 
SERVER_EXPORT ua_node_t ua_filetype_create_with_existing_node (struct ua_nodeid *nodeid, struct ua_filetype_interface *ftif, const void *args)
 Creates an instance of a file type from an existing node. More...
 
SERVER_EXPORT int ua_filetype_delete (ua_node_t file)
 Delete a file instance that was creates using ua_filetype_create. More...
 
SERVER_EXPORT int ua_filetype_delete_ex (struct ua_filetype_ctx *ctx, ua_node_t file)
 Delete a file instance that was creates using ua_filetype_create_ex. More...
 
SERVER_EXPORT int ua_filetype_set_callbacks (ua_node_t file, struct ua_filetype_callbacks *callbacks)
 Sets user callbacks for the given filetype instance. More...
 
SERVER_EXPORT int ua_filetype_set_userdata (ua_node_t file, void *userdata)
 Stores a userdata pointer within the file context. More...
 
SERVER_EXPORT void * ua_filetype_get_userdata (ua_node_t file)
 Returns the userdata pointer of the file context that was previously stored using ua_filetype_set_userdata(). More...
 
SERVER_EXPORT int ua_verify_filetype_config (void)
 
SERVER_EXPORT ua_statuscode ua_filetype_check_args (const struct ua_nodeid *object_id, struct ua_file_context **f)
 Generic function for verifying method call object_id and retrieving the file context. More...
 
SERVER_EXPORT ua_statuscode ua_filetype_check_filehandle (struct ua_file_context *f, uint32_t file_handle, struct uasession_session *session, struct ua_file_handle **pfh)
 Generic function for verifying the file handle and retrieving the file handle context. More...
 
SERVER_EXPORT ua_node_t ua_file_type_get_write_method (ua_node_t file)
 
SERVER_EXPORT ua_node_t ua_file_type_get_read_method (ua_node_t file)
 
SERVER_EXPORT ua_node_t ua_file_type_get_open_method (ua_node_t file)
 
SERVER_EXPORT ua_node_t ua_file_type_get_close_method (ua_node_t file)
 
SERVER_EXPORT ua_node_t ua_file_type_get_setposition_method (ua_node_t file)
 
SERVER_EXPORT ua_node_t ua_file_type_get_getposition_method (ua_node_t file)
 
SERVER_EXPORT struct ua_file_contextua_filetype_get_filecontext (ua_node_t file)
 
SERVER_NO_EXPORT ua_statuscode ua_memoryfileimpl_create (struct ua_file_context *ctx, const void *args)
 
SERVER_NO_EXPORT ua_statuscode ua_memoryfileimpl_delete (struct ua_file_context *ctx)
 
SERVER_NO_EXPORT ua_statuscode ua_memoryfileimpl_open (struct ua_file_handle *fh, uint8_t mode)
 
SERVER_NO_EXPORT ua_statuscode ua_memoryfileimpl_close (struct ua_file_handle *fh)
 
SERVER_NO_EXPORT ua_statuscode ua_memoryfileimpl_read (struct ua_file_handle *fh, int32_t length, struct ua_bytestring *data)
 
SERVER_NO_EXPORT ua_statuscode ua_memoryfileimpl_write (struct ua_file_handle *fh, const struct ua_bytestring *data)
 
SERVER_NO_EXPORT ua_statuscode ua_memoryfileimpl_get_position (struct ua_file_handle *fh, uint64_t *position)
 
SERVER_NO_EXPORT ua_statuscode ua_memoryfileimpl_set_position (struct ua_file_handle *fh, const uint64_t *position)
 
SERVER_NO_EXPORT ua_statuscode ua_memoryfileimpl_get_size (struct ua_file_context *ctx, uint64_t *position)
 

Variables

SERVER_EXPORT struct ua_filetype_interface ua_filesystem_implementation
 filetype interface table for real filesystem files. More...
 
SERVER_EXPORT struct ua_filetype_interface ua_memoryfile_implementation
 filetype interface table for in-memory files. More...
 
SERVER_EXPORT struct ua_filetype_trust_list_interface ua_trustlistfile_implementation
 

Detailed Description

For creating instances of filetypes and managing those types.

The SDK offers a ua_filetype_interface to register custom file IO implementations. Two ready to use implementations are also available:

  1. ua_filesystem_implementation: An implementation which works for real filesystem files. This is implemented using the platform layer file API and works on all platforms, which implement file IO in the platform layer. This requires the option SUPPORT_FILE_IO to be enabled.
  2. ua_memoryfile_implementation: An in-memory file which is based on a ua_bytestring.

Macro Definition Documentation

◆ UA_FILETYPE_CALLBACKS_INITIALIZER

#define UA_FILETYPE_CALLBACKS_INITIALIZER
Value:
{ \
NULL, NULL, NULL \
}

This macro can be used to initialize variables of type ua_filetype_callbacks.

Function Documentation

◆ ua_file_context_set_mimetype()

SERVER_EXPORT ua_statuscode ua_file_context_set_mimetype ( struct ua_file_context ctx,
const char *  mimetype 
)

Sets the optional Mime Type of the file context.

Parameters
ctxthe file context to work on.
mimetypethe mime type to set.
Returns
UA_SCEGOOD on success, or UA_SCBADOUTOFMEMORY if memory allocation fails.

◆ ua_file_handle_create()

SERVER_EXPORT struct ua_file_handle* ua_file_handle_create ( struct ua_file_context file,
uint8_t  mode 
)

Creates a new file handle context.

Returns
Pointer to new context on success, NULL if the operation fails.

◆ ua_file_handle_lookup()

SERVER_EXPORT struct ua_file_handle* ua_file_handle_lookup ( uint32_t  handle)

Lookup file context by its handle.

Parameters
handleThe file handle to search for.
Returns
The according file context or NULL if not found.

◆ ua_filetype_check_args()

SERVER_EXPORT ua_statuscode ua_filetype_check_args ( const struct ua_nodeid object_id,
struct ua_file_context **  f 
)

Generic function for verifying method call object_id and retrieving the file context.

This can be used in subtypes of filetype which need the same type of argument checks.

Parameters
object_idNodeid to check.
fReturns the file context for the given nodeid (mandatory).
Returns
UA_SCGOOD if all checks pass, a negative status code on error.

◆ ua_filetype_check_filehandle()

SERVER_EXPORT ua_statuscode ua_filetype_check_filehandle ( struct ua_file_context f,
uint32_t  file_handle,
struct uasession_session session,
struct ua_file_handle **  pfh 
)

Generic function for verifying the file handle and retrieving the file handle context.

◆ ua_filetype_create()

SERVER_EXPORT ua_node_t ua_filetype_create ( const struct ua_nodeid nodeid,
ua_node_t  type,
const char *  displayname,
struct ua_filetype_interface ftif,
const void *  args 
)

Creates an instance of a file type.

This function is a convenience wrapper function for ua_filetype_create_ex(), which can be used for the typical use cases. Use ua_filetype_create_ex() to get more control over instance creation.

Parameters
nodeidThe nodeid of the new node to create.
typeThe type to create an instance from. This must be UA_NODE_FILETYPE or a subclass of it.
displaynameThe displayname to use for the new node.
ftifThe calltable of the file implementation to use. If NULL the SDK will use its own implementation which creates a real file in the file system.
argsArguments for the file implementation. For the default implementation this must be the filename.
Note
You must use ua_filetype_delete to cleanup the resources of instances created using this function. The normal node_remove is not sufficient, because this cleans up only the node in address space and not the file resources associated with this node.
Returns
The created node handle or UA_NODE_INVALID if the operation fails.

◆ ua_filetype_create_ex()

SERVER_EXPORT int ua_filetype_create_ex ( struct ua_filetype_ctx ctx,
const struct ua_nodeid nodeid,
ua_node_t  type,
uint16_t  browsename_idx,
const char *  browsename,
const char *  displayname,
struct ua_filetype_interface ftif,
const void *  args 
)

Creates an instance of a file type.

Parameters
ctxConfiguration object to control the node instance creation.
nodeidThe nodeid of the new node to create.
typeThe type to create an instance from. This must be UA_NODE_FILETYPE or a subclass of it.
displaynameThe displayname to use for the new node.
browsenameBrowsename for the new node, no browsename is set if NULL.
browsename_idxNamespace index for the browsename of the new node.
ftifThe calltable of the file implementation to use. If NULL the SDK will use its own implementation which creates a real file in the file system.
argsArguments for the file implementation. For the default implementation this must be the filename.
Note
You must use ua_filetype_delete to cleanup the resources of instances created using this function. The normal node_remove is not sufficient, because this cleans up only the node in address space and not the file resources associated with this node.
Returns
Zero on success, a negative error code on error. Use ua_filetype_ctx_get_new_node() to get the node handle of the newly created filetype instance.

◆ ua_filetype_create_with_existing_node()

SERVER_EXPORT ua_node_t ua_filetype_create_with_existing_node ( struct ua_nodeid nodeid,
struct ua_filetype_interface ftif,
const void *  args 
)

Creates an instance of a file type from an existing node.

Parameters
nodeidThe existing nodeid from which an instance shall be created.
ftifThe calltable of the file implementation to use. If NULL the SDK will use its own implementation which creates a real file in the file system.
argsArguments for the file implementation. For the default implementation this must be the filename.
Note
You must use ua_filetype_delete to cleanup the resources of instances created using this function. The normal node_remove is not sufficient, because this cleans up only the node in address space and not the file resources associated with this node.
Returns
The created node handle or NODE_INVALID if the operation fails.

◆ ua_filetype_ctx_create()

SERVER_EXPORT struct ua_filetype_ctx* ua_filetype_ctx_create ( void  )

Creates new instance of a ua_filetype_ctx, which servers the same purpose as ua_instance_ctx, but for ua_filetype_create_ex().

This instance is used as argument for ua_filetype_create_ex().

Use ua_filetype_ctx_delete() to cleanup the resource after the ua_filetype_create_ex() call.

Returns
Pointer to context or NULL if memory allocation fails.

◆ ua_filetype_ctx_get_last_numeric_id()

SERVER_EXPORT uint32_t ua_filetype_ctx_get_last_numeric_id ( struct ua_filetype_ctx ctx)

Get the number used for the last created node with numeric nodeid.

May be used to calculate the nodeid for the next instance without gaps, however only the numeric part is returned, so the namespace index must still be set.

In case no node with numeric nodeid was ever created with this ctx it returns zero.

◆ ua_filetype_ctx_get_new_node()

SERVER_EXPORT ua_node_t ua_filetype_ctx_get_new_node ( struct ua_filetype_ctx ctx)

Returns the newly create filetype node.

◆ ua_filetype_ctx_set_cb_data()

SERVER_EXPORT void ua_filetype_ctx_set_cb_data ( struct ua_filetype_ctx ctx,
void *  data 
)

Set some arbitrary callback data, can be retrieved with ua_instance_get_cb_data.

◆ ua_filetype_ctx_set_delete_cb()

SERVER_EXPORT void ua_filetype_ctx_set_delete_cb ( struct ua_filetype_ctx ctx,
ua_instance_delete_cb  cb 
)

Set the delete callback.

For further information regarding the callback see ua_instance_delete_cb.

◆ ua_filetype_ctx_set_mime_type()

SERVER_EXPORT void ua_filetype_ctx_set_mime_type ( struct ua_filetype_ctx ctx,
const char *  mimetype 
)

Sets the optional MIME type of the file that should be created.

Parameters
ctxConfiguration object to control the node instance deletion.
mimetypeString constant for mime type e.g. "text/plain;charset=UTF-8". When this is set the optional property MimeType will be created.

◆ ua_filetype_ctx_set_parent()

SERVER_EXPORT void ua_filetype_ctx_set_parent ( struct ua_filetype_ctx ctx,
ua_node_t  parent_node,
ua_node_t  ref_type 
)

Set a parent for new instances.

When setting a parent, a new reference from the parent node to the top level node of the newly created instance will be created after instantiation.

To unset the parent pass UA_NODE_INVALID as parent node and reference type.

Parameters
ctxThe ua_instance context to modify.
parent_nodeNode handle of the parent node.
ref_typeNode handle of the reference type from the parent node to the new instance.

◆ ua_filetype_ctx_set_post_create_cb()

SERVER_EXPORT void ua_filetype_ctx_set_post_create_cb ( struct ua_filetype_ctx ctx,
ua_instance_post_create_cb  cb 
)

Set the post create callback.

For further information regarding the callback see ua_instance_post_create_cb.

◆ ua_filetype_ctx_set_pre_create_cb()

SERVER_EXPORT void ua_filetype_ctx_set_pre_create_cb ( struct ua_filetype_ctx ctx,
ua_instance_pre_create_cb  cb 
)

Set the pre create callback.

Note: This callback is not called if ua_instance_pre_create2_cb is set.

For further information regarding the callback see ua_instance_pre_create_cb.

◆ ua_filetype_delete()

SERVER_EXPORT int ua_filetype_delete ( ua_node_t  file)

Delete a file instance that was creates using ua_filetype_create.

Parameters
fileThe node handle of the file.
Returns
Zero on success, a negative error code on error.

◆ ua_filetype_delete_ex()

SERVER_EXPORT int ua_filetype_delete_ex ( struct ua_filetype_ctx ctx,
ua_node_t  file 
)

Delete a file instance that was creates using ua_filetype_create_ex.

Parameters
ctxConfiguration object to control the node instance deletion.
fileThe node handle of the file.
See also
ua_filetype_ctx_set_delete_cb
Returns
Zero on success, a negative error code on error.

◆ ua_filetype_get_userdata()

SERVER_EXPORT void* ua_filetype_get_userdata ( ua_node_t  file)

Returns the userdata pointer of the file context that was previously stored using ua_filetype_set_userdata().

Parameters
fileNode handle of the file.
Returns
The userdata, or NULL in case of an error.

◆ ua_filetype_set_callbacks()

SERVER_EXPORT int ua_filetype_set_callbacks ( ua_node_t  file,
struct ua_filetype_callbacks callbacks 
)

Sets user callbacks for the given filetype instance.

Parameters
fileNode handle of the file to monitor.
callbacksPointer to callback table. The callbacks table gets copied into the internal file context, so the pointer is not needed anymore when the function returns. E.g. you can use a local variable (stack variable) for register the callbacks.
Returns
Zero on success, a negative error code on error.

◆ ua_filetype_set_userdata()

SERVER_EXPORT int ua_filetype_set_userdata ( ua_node_t  file,
void *  userdata 
)

Stores a userdata pointer within the file context.

Parameters
fileNode handle of the file.
userdataData to store.
Returns
Zero on success, UA_EBADINVALIDARGUMENT if the given node was not a filetype.

Variable Documentation

◆ ua_filesystem_implementation

filetype interface table for real filesystem files.

◆ ua_memoryfile_implementation

filetype interface table for in-memory files.