stumpless  2.1.0
element.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0 */
2 
3 /*
4  * Copyright 2018-2022 Joel E. Anderson
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
23 #ifndef __STUMPLESS_ELEMENT_H
24 # define __STUMPLESS_ELEMENT_H
25 
26 # include <stdbool.h>
27 # include <stddef.h>
28 # include <stumpless/config.h>
29 # include <stumpless/entry.h>
30 # include <stumpless/param.h>
31 
33 # define STUMPLESS_MAX_ELEMENT_NAME_LENGTH 32
34 
35 # ifdef __cplusplus
36 extern "C" {
37 # endif
38 
39 // this is required due to the circular dependency with the entry header.
40 struct stumpless_entry;
41 
42 #ifdef STUMPLESS_JOURNALD_TARGETS_SUPPORTED
43 
79 typedef
80 size_t
81 ( *stumpless_element_namer_func_t )( const struct stumpless_entry *entry,
82  size_t element_index,
83  char *destination,
84  size_t size );
85 #endif
86 
116  size_t name_length;
127  size_t param_count;
128 #ifdef STUMPLESS_JOURNALD_TARGETS_SUPPORTED
129 
133 #endif
134 #ifdef STUMPLESS_THREAD_SAFETY_SUPPORTED
135 
139  void *mutex;
140 #endif
141 };
142 
176 struct stumpless_element *
178  const char *param_name,
179  const char *param_value );
180 
206 struct stumpless_element *
208  struct stumpless_param *param );
209 
240 struct stumpless_element *
241 stumpless_copy_element( const struct stumpless_element *element );
242 
268 void
270 
292 void
294 
316 void
318 
346 bool
348  const char *name );
349 
380 const char *
382 
408 struct stumpless_param *
410  size_t index );
411 
447 struct stumpless_param *
449  const char *name );
450 
474 size_t
476 
512 size_t
514  const char *name );
515 
550 const char *
552  size_t index );
553 
585 size_t
587  const char *name );
588 
623 const char *
625  size_t index );
626 
665 const char *
667  const char *name );
668 
691 struct stumpless_element *
693 
722 struct stumpless_element *
724  const char *name );
725 
761 struct stumpless_element *
763  size_t index,
764  struct stumpless_param *param );
765 
796 struct stumpless_element *
798  size_t index,
799  const char *value );
800 
839 struct stumpless_element *
841  const char *name,
842  const char *value );
843 
870 const char *
872 
873 
874 # ifdef __cplusplus
875 } /* extern "C" */
876 # endif
877 
878 #endif /* __STUMPLESS_ELEMENT_H */
stumpless_get_param_name_by_index
const char * stumpless_get_param_name_by_index(const struct stumpless_element *element, size_t index)
Gets the name of the param with the given index in this element.
stumpless_element::param_count
size_t param_count
The number of params in the array.
Definition: element.h:127
stumpless_set_param_value_by_index
struct stumpless_element * stumpless_set_param_value_by_index(struct stumpless_element *element, size_t index, const char *value)
Sets the value of the param at the given index in the given element.
stumpless_set_param
struct stumpless_element * stumpless_set_param(struct stumpless_element *element, size_t index, struct stumpless_param *param)
Puts the param at the given index in the given element.
stumpless_param::name
char * name
The name of the parameter.
Definition: param.h:105
stumpless_destroy_element_only
void stumpless_destroy_element_only(const struct stumpless_element *element)
Destroys an element, freeing any allocated memory.
stumpless_element_namer_func_t
size_t(* stumpless_element_namer_func_t)(const struct stumpless_entry *entry, size_t element_index, char *destination, size_t size)
Gets the name to use for the journald field corresponding to this element.
Definition: element.h:81
stumpless_set_param_value_by_name
struct stumpless_element * stumpless_set_param_value_by_name(struct stumpless_element *element, const char *name, const char *value)
Sets the value of the first param with the given name in the given element.
stumpless_new_element
struct stumpless_element * stumpless_new_element(const char *name)
Creates a new element with the given name.
stumpless_set_element_name
struct stumpless_element * stumpless_set_element_name(struct stumpless_element *element, const char *name)
Sets the name of the given element.
stumpless_element::name_length
size_t name_length
The number of characters in name.
Definition: element.h:116
stumpless_param
A parameter within a structured data element.
Definition: param.h:90
stumpless_element::get_journald_name
stumpless_element_namer_func_t get_journald_name
Gets the name to use for the journald field corresponding to this element.
Definition: element.h:132
entry.h
stumpless_get_param_count
size_t stumpless_get_param_count(const struct stumpless_element *element)
Returns the number of params in the given element.
stumpless_element::name
char name[32+1]
The name of the element.
Definition: element.h:114
param.h
stumpless_add_param
struct stumpless_element * stumpless_add_param(struct stumpless_element *element, struct stumpless_param *param)
Adds a param to an element.
stumpless_destroy_element_and_contents
void stumpless_destroy_element_and_contents(const struct stumpless_element *e)
Destroys an element as well as all params that it contains, freeing any allocated memory.
stumpless_get_param_value_by_name
const char * stumpless_get_param_value_by_name(const struct stumpless_element *element, const char *name)
Returns the value of the first param with the given name in the given element.
stumpless_element::params
struct stumpless_param ** params
The parameters this element contains.
Definition: element.h:125
stumpless_get_param_value_by_index
const char * stumpless_get_param_value_by_index(const struct stumpless_element *element, size_t index)
Returns the value of the param at the given index in the given element.
stumpless_add_new_param
struct stumpless_element * stumpless_add_new_param(struct stumpless_element *element, const char *param_name, const char *param_value)
Creates a new param and adds it to the given element.
stumpless_element::mutex
void * mutex
A pointer to a mutex which protects all element fields.
Definition: element.h:139
STUMPLESS_MAX_ELEMENT_NAME_LENGTH
#define STUMPLESS_MAX_ELEMENT_NAME_LENGTH
The maximum length of an element name, as specified by RFC 5424.
Definition: element.h:33
STUMPLESS_PUBLIC_FUNCTION
#define STUMPLESS_PUBLIC_FUNCTION
Marks functions that are provided for use by the library.
Definition: config.h:31
stumpless_element_to_string
const char * stumpless_element_to_string(const struct stumpless_element *element)
Returns name and params from element as a formatted string.
config.h
stumpless_get_param_by_index
struct stumpless_param * stumpless_get_param_by_index(const struct stumpless_element *element, size_t index)
Returns the param in the given element at the specified index.
stumpless_get_param_by_name
struct stumpless_param * stumpless_get_param_by_name(const struct stumpless_element *element, const char *name)
Returns the first occurrence of a param with the given name in element, if it is found.
stumpless_entry
A log entry.
Definition: entry.h:63
stumpless_copy_element
struct stumpless_element * stumpless_copy_element(const struct stumpless_element *element)
Creates a copy of an element.
stumpless_get_element_name
const char * stumpless_get_element_name(const struct stumpless_element *element)
Returns the name of the given element.
stumpless_get_param_name_count
size_t stumpless_get_param_name_count(const struct stumpless_element *element, const char *name)
Gives the number of params with the given name found in the given element.
stumpless_element
An element of structured data.
Definition: element.h:93
stumpless_destroy_element
void stumpless_destroy_element(const struct stumpless_element *element)
An alias for stumpless_destroy_element_and_contents.
stumpless_get_param_index
size_t stumpless_get_param_index(const struct stumpless_element *element, const char *name)
Gives the index of the first occurrence of a param with the given name in the given element.
stumpless_element_has_param
bool stumpless_element_has_param(const struct stumpless_element *element, const char *name)
True if the given element has a param with the given name, false otherwise.