trmsg_foreach_messages()

trmsg_foreach_messages()#

trmsg_foreach_messages() iterates over all messages in the given list, invoking the provided callback function for each message. The callback receives either duplicated or cloned message instances based on the duplicated flag.

Prototype

int trmsg_foreach_messages(
    json_t *list,
    BOOL duplicated,
    int (*callback)(
        json_t *list,
        const char *key,
        json_t *instances,
        void *user_data1,
        void *user_data2
    ),
    void *user_data1,
    void *user_data2,
    json_t *jn_filter
);

Parameters

Key

Type

Description

list

json_t *

The list containing messages to iterate over.

duplicated

BOOL

If true, the callback receives duplicated messages; otherwise, it receives cloned messages.

callback

int (*)(json_t *, const char *, json_t *, void *, void *)

A function pointer to the callback that processes each message. It should return a negative value to break the iteration.

user_data1

void *

User-defined data passed to the callback function.

user_data2

void *

Additional user-defined data passed to the callback function.

jn_filter

json_t *

A JSON object specifying filtering criteria for selecting messages. The caller owns this parameter.


Return Value

Returns 0 on success, a negative value if the iteration was interrupted by the callback, or a positive error code on failure.

Notes

The callback function receives a reference to the list, the message key, and the instances JSON object. The instances parameter must be owned by the callback function. This function is similar to trmsg_foreach_active_messages() and trmsg_foreach_instances_messages(), but it allows selecting between duplicated and cloned messages.

Prototype

// Not applicable in JS

Prototype

# Not applicable in Python
Examples
// TODO C examples
// TODO JS examples
# TODO Python examples