stumpless  2.1.0
Data Structures | Typedefs | Functions
param.h File Reference
#include <stddef.h>
#include <stumpless/config.h>
#include <stumpless/entry.h>

Go to the source code of this file.

Data Structures

struct  stumpless_param
 A parameter within a structured data element. More...
 

Typedefs

typedef size_t(* stumpless_param_namer_func_t) (const struct stumpless_entry *entry, size_t element_index, size_t param_index, char *destination, size_t size)
 Gets the name to use for the journald field corresponding to this param. More...
 

Functions

struct stumpless_paramstumpless_copy_param (const struct stumpless_param *param)
 Creates a copy of a param. More...
 
void stumpless_destroy_param (const struct stumpless_param *param)
 Destroys a param, freeing any allocated memory. More...
 
const char * stumpless_get_param_name (const struct stumpless_param *param)
 Returns the name of the given param. More...
 
const char * stumpless_get_param_value (const struct stumpless_param *param)
 Returns the value of the given param. More...
 
struct stumpless_paramstumpless_new_param (const char *name, const char *value)
 Creates a new param with the given name and value. More...
 
struct stumpless_paramstumpless_set_param_name (struct stumpless_param *param, const char *name)
 Sets the name of the given param. More...
 
struct stumpless_paramstumpless_set_param_value (struct stumpless_param *param, const char *value)
 Sets the value of the given param. More...
 
const char * stumpless_param_to_string (const struct stumpless_param *param)
 Returns the name and the value from param as a formatted string. More...
 

Detailed Description

Types and functions for creating and modifying params.

Typedef Documentation

◆ stumpless_param_namer_func_t

typedef size_t( * stumpless_param_namer_func_t) (const struct stumpless_entry *entry, size_t element_index, size_t param_index, char *destination, size_t size)

Gets the name to use for the journald field corresponding to this param.

If the destination buffer is too small to hold the complete name, then nothing should be done. Callers must be able to detect this by comparing the return value to the value provided in the size argument. If the return value is larger, then the name was not written into destination.

Thread Safety: MT-Unsafe This function need not be thread safe. It will be called when locks are already held on the entry, element, and param in question, and therefore should not use any functions that will attempt to lock any of these as this will result in deadlock.

Async Signal Safety: AS-Safe This function must be safe to call from signal handlers.

Async Cancel Safety: AC-Safe This function must be safe to call from threads that may be asynchronously cancelled.

Since
v2.1.0
Parameters
entryThe entry that the param is part of.
element_indexThe index of the element in the entry.
param_indexThe index of the param within the element.
destinationThe buffer to write the name to.
sizeThe maximum number of bytes to write to the destination buffer.
Returns
The number of bytes needed to write the complete name, not including a NULL terminating character. If this is greater than size, then it signifies that nothing was done.

Function Documentation

◆ stumpless_copy_param()

struct stumpless_param* stumpless_copy_param ( const struct stumpless_param param)

Creates a copy of a param.

Thread Safety: MT-Safe This function is thread safe. A mutex is used to coordinate the read of the param with other accesses and modifications.

Async Signal Safety: AS-Unsafe lock heap This function is not safe to call from signal handlers due to the use of a non-reentrant lock to coordinate access and the use of memory management functions to create the copy.

Async Cancel Safety: AC-Unsafe lock heap This function is not safe to call from threads that may be asynchronously cancelled, due to the use of a lock that could be left locked as well as memory management functions.

Parameters
paramThe param to copy.
Returns
A new param that is a copy of the original. If an error is encountered, then NULL is returned and an error code is set appropriately.

◆ stumpless_destroy_param()

void stumpless_destroy_param ( const struct stumpless_param param)

Destroys a param, freeing any allocated memory.

Thread Safety: MT-Unsafe This function is not thread safe as it destroys resources that other threads would use if they tried to reference this struct.

Async Signal Safety: AS-Unsafe lock heap This function is not safe to call from signal handlers due to the destruction of a lock that may be in use as well as the use of the memory deallocation function to release memory.

Async Cancel Safety: AC-Unsafe lock heap This function is not safe to call from threads that may be asynchronously cancelled, as the cleanup of the lock may not be completed, and the memory deallocation function may not be AC-Safe itself.

Parameters
paramThe param to destroy.

◆ stumpless_get_param_name()

const char* stumpless_get_param_name ( const struct stumpless_param param)

Returns the name of the given param.

The character buffer must be freed by the caller when it is no longer needed to avoid memory leaks.

In versions prior to v2.0.0, the returned pointer was to the internal buffer used to store the name and was not to be modified by the caller. This behavior changed in v2.0.0 in order to avoid thread safety issues.

Thread Safety: MT-Safe This function is thread safe. A mutex is used to coordinate the read of the param with other accesses and modifications.

Async Signal Safety: AS-Unsafe lock heap This function is not safe to call from signal handlers due to the use of a non-reentrant lock to coordinate access and the use of memory management functions to create the result.

Async Cancel Safety: AC-Unsafe lock heap This function is not safe to call from threads that may be asynchronously cancelled, due to the use of a lock that could be left locked as well as memory management functions.

Since
release v1.6.0
Parameters
paramThe param to get the name from.
Returns
The name of param, if no error is encountered. If an error is encountered, then NULL is returned and an error code is set appropriately.

◆ stumpless_get_param_value()

const char* stumpless_get_param_value ( const struct stumpless_param param)

Returns the value of the given param.

The character buffer must be freed by the caller when it is no longer needed to avoid memory leaks.

In versions prior to v2.0.0, the returned pointer was to the internal buffer used to store the value and was not to be modified by the caller. This behavior changed in v2.0.0 in order to avoid thread safety issues.

Thread Safety: MT-Safe This function is thread safe. A mutex is used to coordinate the read of the param with other accesses and modifications.

Async Signal Safety: AS-Unsafe lock heap This function is not safe to call from signal handlers due to the use of a non-reentrant lock to coordinate access and the use of memory management functions to create the result.

Async Cancel Safety: AC-Unsafe lock heap This function is not safe to call from threads that may be asynchronously cancelled, due to the use of a lock that could be left locked as well as memory management functions.

Since
release v1.6.0
Parameters
paramThe param to get the value from.
Returns
The value of param, if no error is encountered. If an error is encountered, then NULL is returned and an error code is set appropriately.

◆ stumpless_new_param()

struct stumpless_param* stumpless_new_param ( const char *  name,
const char *  value 
)

Creates a new param with the given name and value.

Thread Safety: MT-Safe race:name race:value This function is thread safe, of course assuming that name and value are not changed by other threads during execution.

Async Signal Safety: AS-Unsafe heap This function is not safe to call from signal handlers due to the use of memory management functions to create the new param.

Async Cancel Safety: AC-Unsafe heap This function is not safe to call from threads that may be asynchronously cancelled, due to the use of memory management functions.

Parameters
nameThe name of the new param. Restricted to printable ASCII characters different from '=', ']' and '"'.
valueThe value of the new param.
Returns
The created param, if no error is encountered. If an error is encountered, then NULL is returned and an error code set appropriately.

◆ stumpless_param_to_string()

const char* stumpless_param_to_string ( const struct stumpless_param param)

Returns the name and the value from param as a formatted string.

The character buffer should be freed when no longer is needed by the caller.

Thread Safety: MT-Safe This function is thread safe. A mutex is used to coordinate the read of the param with other accesses and modifications.

Async Signal Safety: AS-Unsafe lock heap This function is not safe to call from signal handlers due to the use of a non-reentrant lock to coordinate access and the use of memory management functions to create the result.

Async Cancel Safety: AC-Unsafe lock heap This function is not safe to call from threads that may be asynchronously cancelled, due to the use of a lock that could be left locked as well as memory management functions.

Since
release v2.0.0
Parameters
paramThe param to get the name and the value from.
Returns
The formatted string of <name>:

if no error is encountered. If an error is encountered, then NULL is returned and an error code is set appropriately.

◆ stumpless_set_param_name()

struct stumpless_param* stumpless_set_param_name ( struct stumpless_param param,
const char *  name 
)

Sets the name of the given param.

Thread Safety: MT-Safe This function is thread safe. A mutex is used to coordinate changes to the param while it is being modified.

Async Signal Safety: AS-Unsafe lock heap This function is not safe to call from signal handlers due to the use of a non-reentrant lock to coordinate changes and the use of memory management functions to create the new name and free the old one.

Async Cancel Safety: AC-Unsafe lock heap This function is not safe to call from threads that may be asynchronously cancelled, due to the use of a lock that could be left locked as well as memory management functions.

Since
release v1.6.0
Parameters
paramThe param to set the name of.
nameThe new name of param. Restricted to printable ASCII characters different from '=', ']' and '"'.
Returns
The modified param, if no error is encountered. If an error is encountered, then NULL is returned and an error code is set appropriately.

◆ stumpless_set_param_value()

struct stumpless_param* stumpless_set_param_value ( struct stumpless_param param,
const char *  value 
)

Sets the value of the given param.

Thread Safety: MT-Safe This function is thread safe. A mutex is used to coordinate changes to the param while it is being modified.

Async Signal Safety: AS-Unsafe lock heap This function is not safe to call from signal handlers due to the use of a non-reentrant lock to coordinate changes and the use of memory management functions to create the new value and free the old one.

Async Cancel Safety: AC-Unsafe lock heap This function is not safe to call from threads that may be asynchronously cancelled, due to the use of a lock that could be left locked as well as memory management functions.

Since
release v1.6.0
Parameters
paramThe param to set the value of.
valueThe new name of param.
Returns
The modified param, if no error is encountered. If an error is encountered, then NULL is returned and an error code is set appropriately.