Asterisk - The Open Source Telephony Project GIT-master-f36a736
Data Structures | Functions | Variables
event.c File Reference

Internal generic event system. More...

#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/event.h"
#include "asterisk/linkedlists.h"
#include "asterisk/dlinkedlists.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "asterisk/unaligned.h"
#include "asterisk/taskprocessor.h"
#include "asterisk/astobj2.h"
#include "asterisk/cli.h"
Include dependency graph for event.c:

Go to the source code of this file.

Data Structures

struct  ast_ev_check_list
 Subscription event check list. More...
 
struct  ast_event
 An event. More...
 
struct  ast_event_ie
 An event information element. More...
 
struct  ast_event_ie_str_payload
 The payload for a string information element. More...
 
struct  ast_event_ie_val
 
struct  ie_map
 IE payload types and names. More...
 

Functions

int ast_event_append_eid (struct ast_event **event)
 Append the global EID IE. More...
 
int ast_event_append_ie_bitflags (struct ast_event **event, enum ast_event_ie_type ie_type, uint32_t flags)
 Append an information element that has a bitflags payload. More...
 
int ast_event_append_ie_raw (struct ast_event **event, enum ast_event_ie_type ie_type, const void *data, size_t data_len)
 Append an information element that has a raw payload. More...
 
int ast_event_append_ie_str (struct ast_event **event, enum ast_event_ie_type ie_type, const char *str)
 Append an information element that has a string payload. More...
 
int ast_event_append_ie_uint (struct ast_event **event, enum ast_event_ie_type ie_type, uint32_t data)
 Append an information element that has an integer payload. More...
 
void ast_event_destroy (struct ast_event *event)
 Destroy an event. More...
 
enum ast_event_ie_pltype ast_event_get_ie_pltype (enum ast_event_ie_type ie_type)
 Get the payload type for a given information element type. More...
 
const void * ast_event_get_ie_raw (const struct ast_event *event, enum ast_event_ie_type ie_type)
 Get the value of an information element that has a raw payload. More...
 
uint16_t ast_event_get_ie_raw_payload_len (const struct ast_event *event, enum ast_event_ie_type ie_type)
 Get the length of the raw payload for a particular IE. More...
 
const char * ast_event_get_ie_str (const struct ast_event *event, enum ast_event_ie_type ie_type)
 Get the value of an information element that has a string payload. More...
 
const char * ast_event_get_ie_type_name (enum ast_event_ie_type ie_type)
 Get the string representation of an information element type. More...
 
uint32_t ast_event_get_ie_uint (const struct ast_event *event, enum ast_event_ie_type ie_type)
 Get the value of an information element that has an integer payload. More...
 
size_t ast_event_get_size (const struct ast_event *event)
 Get the size of an event. More...
 
enum ast_event_type ast_event_get_type (const struct ast_event *event)
 Get the type for an event. More...
 
const char * ast_event_get_type_name (const struct ast_event *event)
 Get the string representation of the type of the given event. More...
 
const char * ast_event_iterator_get_ie_str (struct ast_event_iterator *iterator)
 Get the value of the current IE in the iterator as a string payload. More...
 
enum ast_event_ie_type ast_event_iterator_get_ie_type (struct ast_event_iterator *iterator)
 Get the type of the current IE in the iterator instance. More...
 
uint32_t ast_event_iterator_get_ie_uint (struct ast_event_iterator *iterator)
 Get the value of the current IE in the iterator as an integer payload. More...
 
int ast_event_iterator_init (struct ast_event_iterator *iterator, const struct ast_event *event)
 Initialize an event iterator instance. More...
 
int ast_event_iterator_next (struct ast_event_iterator *iterator)
 Move iterator instance to next IE. More...
 
size_t ast_event_minimum_length (void)
 Get the minimum length of an ast_event. More...
 
struct ast_eventast_event_new (enum ast_event_type type,...)
 Create a new event. More...
 
static void * event_iterator_get_ie_raw (struct ast_event_iterator *iterator)
 
static uint16_t event_iterator_get_ie_raw_payload_len (struct ast_event_iterator *iterator)
 

Variables

static const char *const event_names [AST_EVENT_TOTAL]
 Event Names. More...
 
static const struct ie_map ie_maps [AST_EVENT_IE_TOTAL]
 

Detailed Description

Internal generic event system.

Author
Russell Bryant russe.nosp@m.ll@d.nosp@m.igium.nosp@m..com

Definition in file event.c.

Function Documentation

◆ ast_event_append_eid()

int ast_event_append_eid ( struct ast_event **  event)

Append the global EID IE.

Parameters
eventthe event to append IE to
Note
For ast_event_new() that includes IEs, this is done automatically for you.
Return values
0success
-1failure

Definition at line 519 of file event.c.

520{
523}
int ast_event_append_ie_raw(struct ast_event **event, enum ast_event_ie_type ie_type, const void *data, size_t data_len)
Append an information element that has a raw payload.
Definition: event.c:375
@ AST_EVENT_IE_EID
Entity ID Used by All events Payload type: RAW This IE indicates which server the event originated fr...
Definition: event_defs.h:272
Definition: astman.c:222
struct ast_eid ast_eid_default
Global EID.
Definition: options.c:93

References ast_eid_default, ast_event_append_ie_raw(), and AST_EVENT_IE_EID.

Referenced by ast_event_new().

◆ ast_event_append_ie_bitflags()

int ast_event_append_ie_bitflags ( struct ast_event **  event,
enum ast_event_ie_type  ie_type,
uint32_t  bitflags 
)

Append an information element that has a bitflags payload.

Parameters
eventthe event that the IE will be appended to
ie_typethe type of IE to append
bitflagsthe flags that are the payload of the IE
Return values
0success
-1failure
Since
1.8

The pointer to the event will get updated with the new location for the event that now contains the appended information element. If the re-allocation of the memory for this event fails, it will be set to NULL.

Definition at line 368 of file event.c.

370{
371 flags = htonl(flags);
372 return ast_event_append_ie_raw(event, ie_type, &flags, sizeof(flags));
373}

References ast_event_append_ie_raw().

Referenced by ast_event_new().

◆ ast_event_append_ie_raw()

int ast_event_append_ie_raw ( struct ast_event **  event,
enum ast_event_ie_type  ie_type,
const void *  data,
size_t  data_len 
)

Append an information element that has a raw payload.

Parameters
eventthe event that the IE will be appended to
ie_typethe type of IE to append
dataA pointer to the raw data for the payload of the IE
data_lenThe amount of data to copy into the payload
Return values
0success
-1failure

The pointer to the event will get updated with the new location for the event that now contains the appended information element. If the re-allocation of the memory for this event fails, it will be set to NULL.

Definition at line 375 of file event.c.

377{
378 struct ast_event_ie *ie;
379 struct ast_event *old_event;
380 unsigned int extra_len;
381 uint16_t event_len;
382
383 event_len = ntohs((*event)->event_len);
384 extra_len = sizeof(*ie) + data_len;
385
386 old_event = *event;
387 *event = ast_realloc(*event, event_len + extra_len);
388 if (!*event) {
389 ast_free(old_event);
390 return -1;
391 }
392
393 ie = (struct ast_event_ie *) ( ((char *) *event) + event_len );
394 ie->ie_type = htons(ie_type);
395 ie->ie_payload_len = htons(data_len);
396 memcpy(ie->ie_payload, data, data_len);
397
398 (*event)->event_len = htons(event_len + extra_len);
399
400 return 0;
401}
#define ast_free(a)
Definition: astmm.h:180
#define ast_realloc(p, len)
A wrapper for realloc()
Definition: astmm.h:226
An event information element.
Definition: event.c:53
unsigned char ie_payload[0]
Definition: event.c:57
uint16_t ie_payload_len
Definition: event.c:56
enum ast_event_ie_type ie_type
Definition: event.c:54
An event.
Definition: event.c:81
uint16_t event_len
Definition: event.c:85

References ast_free, ast_realloc, ast_event::event_len, ast_event_ie::ie_payload, ast_event_ie::ie_payload_len, and ast_event_ie::ie_type.

Referenced by ast_event_append_eid(), ast_event_append_ie_bitflags(), ast_event_append_ie_str(), ast_event_append_ie_uint(), and ast_event_new().

◆ ast_event_append_ie_str()

int ast_event_append_ie_str ( struct ast_event **  event,
enum ast_event_ie_type  ie_type,
const char *  str 
)

Append an information element that has a string payload.

Parameters
eventthe event that the IE will be appended to
ie_typethe type of IE to append
strThe string for the payload of the IE
Return values
0success
-1failure

The pointer to the event will get updated with the new location for the event that now contains the appended information element. If the re-allocation of the memory for this event fails, it will be set to NULL.

Definition at line 346 of file event.c.

348{
349 struct ast_event_ie_str_payload *str_payload;
350 size_t payload_len;
351
352 payload_len = sizeof(*str_payload) + strlen(str);
353 str_payload = ast_alloca(payload_len);
354
355 strcpy(str_payload->str, str);
356 str_payload->hash = ast_str_hash(str);
357
358 return ast_event_append_ie_raw(event, ie_type, str_payload, payload_len);
359}
const char * str
Definition: app_jack.c:147
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:288
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
Definition: strings.h:1259
The payload for a string information element.
Definition: event.c:63
char str[1]
The actual string, null terminated.
Definition: event.c:67
uint32_t hash
A hash calculated with ast_str_hash(), to speed up comparisons.
Definition: event.c:65

References ast_alloca, ast_event_append_ie_raw(), ast_str_hash(), ast_event_ie_str_payload::hash, str, and ast_event_ie_str_payload::str.

Referenced by ast_event_new(), and AST_TEST_DEFINE().

◆ ast_event_append_ie_uint()

int ast_event_append_ie_uint ( struct ast_event **  event,
enum ast_event_ie_type  ie_type,
uint32_t  data 
)

Append an information element that has an integer payload.

Parameters
eventthe event that the IE will be appended to
ie_typethe type of IE to append
dataThe integer for the payload of the IE
Return values
0success
-1failure

The pointer to the event will get updated with the new location for the event that now contains the appended information element. If the re-allocation of the memory for this event fails, it will be set to NULL.

Definition at line 361 of file event.c.

363{
364 data = htonl(data);
365 return ast_event_append_ie_raw(event, ie_type, &data, sizeof(data));
366}

References ast_event_append_ie_raw().

Referenced by ast_event_new(), and AST_TEST_DEFINE().

◆ ast_event_destroy()

void ast_event_destroy ( struct ast_event event)

Destroy an event.

Parameters
eventthe event to destroy

Definition at line 525 of file event.c.

526{
528}

References ast_free.

Referenced by AST_TEST_DEFINE(), cel_report_event(), corosync_ping(), publish_to_corosync(), and send_cluster_notify().

◆ ast_event_get_ie_pltype()

enum ast_event_ie_pltype ast_event_get_ie_pltype ( enum ast_event_ie_type  ie_type)

Get the payload type for a given information element type.

Parameters
ie_typethe information element type to get the payload type of
Returns
the payload type for the provided IE type
Since
1.6.1

Definition at line 219 of file event.c.

220{
221 if (ie_type <= 0 || ie_type >= ARRAY_LEN(ie_maps)) {
222 ast_log(LOG_ERROR, "Invalid IE type - '%d'\n", ie_type);
224 }
225
226 return ie_maps[ie_type].ie_pltype;
227}
#define ast_log
Definition: astobj2.c:42
static const struct ie_map ie_maps[AST_EVENT_IE_TOTAL]
@ AST_EVENT_IE_PLTYPE_UNKNOWN
Definition: event_defs.h:329
#define LOG_ERROR
enum ast_event_ie_pltype ie_pltype
Definition: event.c:129
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, AST_EVENT_IE_PLTYPE_UNKNOWN, ast_log, ie_maps, ie_map::ie_pltype, and LOG_ERROR.

Referenced by dump_event(), and match_ie_val().

◆ ast_event_get_ie_raw()

const void * ast_event_get_ie_raw ( const struct ast_event event,
enum ast_event_ie_type  ie_type 
)

Get the value of an information element that has a raw payload.

Parameters
eventThe event to get the IE from
ie_typethe type of information element to retrieve
Returns
This returns the payload of the information element with the given type. If the information element isn't found, NULL will be returned.

Definition at line 312 of file event.c.

313{
314 struct ast_event_iterator iterator;
315 int res;
316
317 for (res = ast_event_iterator_init(&iterator, event); !res; res = ast_event_iterator_next(&iterator)) {
318 if (ast_event_iterator_get_ie_type(&iterator) == ie_type) {
319 return event_iterator_get_ie_raw(&iterator);
320 }
321 }
322
323 return NULL;
324}
static void * event_iterator_get_ie_raw(struct ast_event_iterator *iterator)
Definition: event.c:284
enum ast_event_ie_type ast_event_iterator_get_ie_type(struct ast_event_iterator *iterator)
Get the type of the current IE in the iterator instance.
Definition: event.c:265
int ast_event_iterator_next(struct ast_event_iterator *iterator)
Move iterator instance to next IE.
Definition: event.c:259
int ast_event_iterator_init(struct ast_event_iterator *iterator, const struct ast_event *event)
Initialize an event iterator instance.
Definition: event.c:243
#define NULL
Definition: resample.c:96
supposed to be an opaque type
Definition: event_defs.h:359

References ast_event_iterator_get_ie_type(), ast_event_iterator_init(), ast_event_iterator_next(), event_iterator_get_ie_raw(), and NULL.

Referenced by ast_event_get_ie_str(), ast_event_get_ie_uint(), ast_event_new(), corosync_node_alloc(), corosync_ping_to_event(), cpg_deliver_cb(), publish_cluster_discovery_to_stasis(), publish_corosync_ping_to_stasis(), publish_device_state_to_stasis(), publish_mwi_to_stasis(), and publish_to_corosync().

◆ ast_event_get_ie_raw_payload_len()

uint16_t ast_event_get_ie_raw_payload_len ( const struct ast_event event,
enum ast_event_ie_type  ie_type 
)

Get the length of the raw payload for a particular IE.

Parameters
eventThe event to get the IE payload length from
ie_typethe type of information element to get the length of
Returns
If an IE of type ie_type is found, its payload length is returned. Otherwise, 0 is returned.

Definition at line 331 of file event.c.

332{
333 struct ast_event_iterator iterator;
334 int res;
335
336 for (res = ast_event_iterator_init(&iterator, event); !res; res = ast_event_iterator_next(&iterator)) {
337 if (ast_event_iterator_get_ie_type(&iterator) == ie_type) {
339 }
340 }
341
342 return 0;
343}
static uint16_t event_iterator_get_ie_raw_payload_len(struct ast_event_iterator *iterator)
Definition: event.c:326

References ast_event_iterator_get_ie_type(), ast_event_iterator_init(), ast_event_iterator_next(), and event_iterator_get_ie_raw_payload_len().

◆ ast_event_get_ie_str()

const char * ast_event_get_ie_str ( const struct ast_event event,
enum ast_event_ie_type  ie_type 
)

Get the value of an information element that has a string payload.

Parameters
eventThe event to get the IE from
ie_typethe type of information element to retrieve
Returns
This returns the payload of the information element with the given type. If the information element isn't found, NULL will be returned.

Definition at line 303 of file event.c.

304{
305 const struct ast_event_ie_str_payload *str_payload;
306
307 str_payload = ast_event_get_ie_raw(event, ie_type);
308
309 return str_payload ? str_payload->str : NULL;
310}
const void * ast_event_get_ie_raw(const struct ast_event *event, enum ast_event_ie_type ie_type)
Get the value of an information element that has a raw payload.
Definition: event.c:312

References ast_event_get_ie_raw(), NULL, and ast_event_ie_str_payload::str.

Referenced by ast_cel_fill_record(), check_event(), corosync_node_alloc(), match_ie_val(), publish_device_state_to_stasis(), publish_mwi_to_stasis(), and test_sub().

◆ ast_event_get_ie_type_name()

const char * ast_event_get_ie_type_name ( enum ast_event_ie_type  ie_type)

Get the string representation of an information element type.

Parameters
ie_typethe information element type to get the string representation of
Returns
the string representation of the information element type
Since
1.6.1

Definition at line 209 of file event.c.

210{
211 if (ie_type <= 0 || ie_type >= ARRAY_LEN(ie_maps)) {
212 ast_log(LOG_ERROR, "Invalid IE type - '%d'\n", ie_type);
213 return "";
214 }
215
216 return ie_maps[ie_type].name;
217}
const char * name
Definition: event.c:130

References ARRAY_LEN, ast_log, ie_maps, LOG_ERROR, and ie_map::name.

Referenced by add_ip_json_object(), add_json_object(), alloc_security_event_json_object(), append_event_str_single(), append_json_single(), dump_event(), and events_are_equal().

◆ ast_event_get_ie_uint()

uint32_t ast_event_get_ie_uint ( const struct ast_event event,
enum ast_event_ie_type  ie_type 
)

Get the value of an information element that has an integer payload.

Parameters
eventThe event to get the IE from
ie_typethe type of information element to retrieve
Returns
This returns the payload of the information element with the given type. However, an IE with a payload of 0, and the case where no IE is found yield the same return value.

Definition at line 294 of file event.c.

295{
296 const uint32_t *ie_val;
297
298 ie_val = ast_event_get_ie_raw(event, ie_type);
299
300 return ie_val ? ntohl(get_unaligned_uint32(ie_val)) : 0;
301}
static unsigned int get_unaligned_uint32(const void *p)
Definition: unaligned.h:38

References ast_event_get_ie_raw(), and get_unaligned_uint32().

Referenced by ast_cel_fill_record(), check_event(), corosync_node_alloc(), dump_event(), match_ie_val(), publish_cluster_discovery_to_stasis(), publish_device_state_to_stasis(), and publish_mwi_to_stasis().

◆ ast_event_get_size()

size_t ast_event_get_size ( const struct ast_event event)

Get the size of an event.

Parameters
eventthe event to get the size of
Returns
the number of bytes contained in the event
Since
1.6.1

Definition at line 229 of file event.c.

230{
231 size_t res;
232
233 res = ntohs(event->event_len);
234
235 return res;
236}

Referenced by ao2_dup_event(), ast_event_iterator_init(), AST_TEST_DEFINE(), and publish_event_to_corosync().

◆ ast_event_get_type()

enum ast_event_type ast_event_get_type ( const struct ast_event event)

Get the type for an event.

Parameters
eventthe event to get the type for
Returns
the event type as represented by one of the values in the ast_event_type enum

Definition at line 289 of file event.c.

290{
291 return ntohs(event->type);
292}

Referenced by ast_event_get_type_name(), check_event(), check_events(), cpg_deliver_cb(), events_are_equal(), publish_cluster_discovery_to_stasis(), publish_corosync_ping_to_stasis(), publish_device_state_to_stasis(), publish_event_to_corosync(), publish_mwi_to_stasis(), and publish_to_corosync().

◆ ast_event_get_type_name()

const char * ast_event_get_type_name ( const struct ast_event event)

Get the string representation of the type of the given event.

  • event the event to get the type of
Returns
the string representation of the event type of the provided event
Since
1.6.1

Definition at line 195 of file event.c.

196{
197 enum ast_event_type type;
198
200
201 if ((unsigned int)type >= ARRAY_LEN(event_names)) {
202 ast_log(LOG_ERROR, "Invalid event type - '%u'\n", type);
203 return "";
204 }
205
206 return event_names[type];
207}
static const char type[]
Definition: chan_ooh323.c:109
static const char *const event_names[AST_EVENT_TOTAL]
Event Names.
Definition: event.c:109
enum ast_event_type ast_event_get_type(const struct ast_event *event)
Get the type for an event.
Definition: event.c:289
ast_event_type
Definition: event_defs.h:28

References ARRAY_LEN, ast_event_get_type(), ast_log, event_names, LOG_ERROR, and type.

Referenced by cpg_deliver_cb(), and publish_event_to_corosync().

◆ ast_event_iterator_get_ie_str()

const char * ast_event_iterator_get_ie_str ( struct ast_event_iterator iterator)

Get the value of the current IE in the iterator as a string payload.

Parameters
iteratorThe iterator instance
Returns
This returns the payload of the information element as a string.

Definition at line 275 of file event.c.

276{
277 const struct ast_event_ie_str_payload *str_payload;
278
279 str_payload = (struct ast_event_ie_str_payload *) iterator->ie->ie_payload;
280
281 return str_payload ? str_payload->str : NULL;
282}
struct ast_event_ie * ie
Definition: event_defs.h:362

References ast_event_iterator::ie, ast_event_ie::ie_payload, NULL, and ast_event_ie_str_payload::str.

Referenced by dump_event().

◆ ast_event_iterator_get_ie_type()

enum ast_event_ie_type ast_event_iterator_get_ie_type ( struct ast_event_iterator iterator)

Get the type of the current IE in the iterator instance.

Parameters
iteratorThe iterator instance
Returns
the ie type as represented by one of the value sin the ast_event_ie_type enum

Definition at line 265 of file event.c.

266{
267 return ntohs(iterator->ie->ie_type);
268}

References ast_event_iterator::ie, and ast_event_ie::ie_type.

Referenced by ast_event_get_ie_raw(), ast_event_get_ie_raw_payload_len(), dump_event(), and events_are_equal().

◆ ast_event_iterator_get_ie_uint()

uint32_t ast_event_iterator_get_ie_uint ( struct ast_event_iterator iterator)

Get the value of the current IE in the iterator as an integer payload.

Parameters
iteratorThe iterator instance
Returns
This returns the payload of the information element as a uint.

Definition at line 270 of file event.c.

271{
272 return ntohl(get_unaligned_uint32(iterator->ie->ie_payload));
273}

References get_unaligned_uint32(), ast_event_iterator::ie, and ast_event_ie::ie_payload.

Referenced by dump_event().

◆ ast_event_iterator_init()

int ast_event_iterator_init ( struct ast_event_iterator iterator,
const struct ast_event event 
)

Initialize an event iterator instance.

Parameters
iteratorThe iterator instance to initialize
eventThe event that will be iterated through
Return values
0Success, there are IEs available to iterate
-1Failure, there are no IEs in the event to iterate

Definition at line 243 of file event.c.

244{
245 int res = 0;
246
248 iterator->event = event;
249 if (iterator->event_len >= sizeof(*event) + sizeof(struct ast_event_ie)) {
250 iterator->ie = (struct ast_event_ie *) ( ((char *) event) + sizeof(*event) );
251 } else {
252 iterator->ie = NULL;
253 res = -1;
254 }
255
256 return res;
257}
size_t ast_event_get_size(const struct ast_event *event)
Get the size of an event.
Definition: event.c:229
const struct ast_event * event
Definition: event_defs.h:361
uint16_t event_len
Definition: event_defs.h:360

References ast_event_get_size(), ast_event_iterator::event, ast_event_iterator::event_len, ast_event_iterator::ie, and NULL.

Referenced by ast_event_get_ie_raw(), ast_event_get_ie_raw_payload_len(), dump_event(), and events_are_equal().

◆ ast_event_iterator_next()

int ast_event_iterator_next ( struct ast_event_iterator iterator)

Move iterator instance to next IE.

Parameters
iteratorThe iterator instance
Return values
0on success
-1if end is reached

Definition at line 259 of file event.c.

260{
261 iterator->ie = (struct ast_event_ie *) ( ((char *) iterator->ie) + sizeof(*iterator->ie) + ntohs(iterator->ie->ie_payload_len));
262 return ((iterator->event_len <= (((char *) iterator->ie) - ((char *) iterator->event))) ? -1 : 0);
263}

References ast_event_iterator::event, ast_event_iterator::event_len, ast_event_iterator::ie, and ast_event_ie::ie_payload_len.

Referenced by ast_event_get_ie_raw(), ast_event_get_ie_raw_payload_len(), dump_event(), and events_are_equal().

◆ ast_event_minimum_length()

size_t ast_event_minimum_length ( void  )

Get the minimum length of an ast_event.

Returns
minimum amount of memory that will be consumed by any ast_event.

Definition at line 530 of file event.c.

531{
532 return sizeof(struct ast_event);
533}

Referenced by cpg_deliver_cb().

◆ ast_event_new()

struct ast_event * ast_event_new ( enum ast_event_type  event_type,
  ... 
)

Create a new event.

Parameters
event_typeThe type of event to create

The rest of the arguments to this function specify information elements to add to the event. They are specified in the form:

<enum ast_event_ie_type>, [enum ast_event_ie_pltype, [payload] ]
ast_event_ie_type
Event Information Element types.
Definition: event_defs.h:68
ast_event_ie_pltype
Payload types for event information elements.
Definition: event_defs.h:328

and must end with AST_EVENT_IE_END.

If the ie_type specified is not AST_EVENT_IE_END, then it must be followed by a valid IE payload type. A payload must also be specified after the IE payload type.

Note
The EID IE will be appended automatically when this function is used with at least one IE specified.
Returns
This returns the event that has been created. If there is an error creating the event, NULL will be returned.

Example usage:

return;
}
struct ast_event * ast_event_new(enum ast_event_type event_type,...)
Create a new event.
Definition: event.c:403
@ AST_EVENT_IE_END
Definition: event_defs.h:70
@ AST_EVENT_IE_MAILBOX
Mailbox name.
Definition: event_defs.h:89
@ AST_EVENT_IE_OLDMSGS
Number of Used by: AST_EVENT_MWI Payload type: UINT.
Definition: event_defs.h:83
@ AST_EVENT_IE_NEWMSGS
Number of new messages Used by: AST_EVENT_MWI Payload type: UINT.
Definition: event_defs.h:77
@ AST_EVENT_MWI
Definition: event_defs.h:38
@ AST_EVENT_IE_PLTYPE_UINT
Definition: event_defs.h:333
@ AST_EVENT_IE_PLTYPE_STR
Definition: event_defs.h:335

This creates a MWI event with 3 information elements, a mailbox which is a string, and the number of new and old messages, specified as integers.

Definition at line 403 of file event.c.

404{
405 va_list ap;
406 struct ast_event *event;
407 enum ast_event_ie_type ie_type;
408 struct ast_event_ie_val *ie_val;
410
411 /* Invalid type */
412 if (type >= AST_EVENT_TOTAL) {
413 ast_log(LOG_WARNING, "Someone tried to create an event of invalid "
414 "type '%u'!\n", type);
415 return NULL;
416 }
417
418 va_start(ap, type);
419 for (ie_type = va_arg(ap, enum ast_event_ie_type);
421 ie_type = va_arg(ap, enum ast_event_ie_type))
422 {
423 struct ast_event_ie_val *ie_value = ast_malloc(sizeof(*ie_value));
424 int insert = 0;
425
426 memset(ie_value, 0, sizeof(*ie_value));
427 ie_value->ie_type = ie_type;
428 ie_value->ie_pltype = va_arg(ap, enum ast_event_ie_pltype);
429
430 switch (ie_value->ie_pltype) {
432 ie_value->payload.uint = va_arg(ap, uint32_t);
433 insert = 1;
434 break;
436 ie_value->payload.uint = va_arg(ap, uint32_t);
437 insert = 1;
438 break;
440 ie_value->payload.str = va_arg(ap, const char *);
441 insert = 1;
442 break;
444 {
445 void *data = va_arg(ap, void *);
446 size_t datalen = va_arg(ap, size_t);
447 ie_value->payload.raw = ast_malloc(datalen);
448 memcpy(ie_value->payload.raw, data, datalen);
449 ie_value->raw_datalen = datalen;
450 insert = 1;
451 break;
452 }
455 break;
456 }
457
458 if (insert) {
459 AST_LIST_INSERT_TAIL(&ie_vals, ie_value, entry);
460 } else {
461 ast_log(LOG_WARNING, "Unsupported PLTYPE(%d)\n", ie_value->ie_pltype);
462 }
463 }
464 va_end(ap);
465
466 if (!(event = ast_calloc(1, sizeof(*event)))) {
467 return NULL;
468 }
469
470 event->type = htons(type);
471 event->event_len = htons(sizeof(*event));
472
473 AST_LIST_TRAVERSE(&ie_vals, ie_val, entry) {
474 switch (ie_val->ie_pltype) {
476 ast_event_append_ie_str(&event, ie_val->ie_type, ie_val->payload.str);
477 break;
480 break;
483 break;
486 ie_val->payload.raw, ie_val->raw_datalen);
487 break;
490 break;
491 }
492
493 /* realloc inside one of the append functions failed */
494 if (!event) {
495 goto cleanup;
496 }
497 }
498
500 /* If the event is originating on this server, add the server's
501 * entity ID to the event. */
503 }
504
505cleanup:
506 AST_LIST_TRAVERSE_SAFE_BEGIN(&ie_vals, ie_val, entry) {
508
509 if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_RAW) {
510 ast_free(ie_val->payload.raw);
511 }
512 ast_free(ie_val);
513 }
515
516 return event;
517}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191
int ast_event_append_ie_bitflags(struct ast_event **event, enum ast_event_ie_type ie_type, uint32_t flags)
Append an information element that has a bitflags payload.
Definition: event.c:368
int ast_event_append_ie_str(struct ast_event **event, enum ast_event_ie_type ie_type, const char *str)
Append an information element that has a string payload.
Definition: event.c:346
int ast_event_append_ie_uint(struct ast_event **event, enum ast_event_ie_type ie_type, uint32_t data)
Append an information element that has an integer payload.
Definition: event.c:361
int ast_event_append_eid(struct ast_event **event)
Append the global EID IE.
Definition: event.c:519
@ AST_EVENT_TOTAL
Definition: event_defs.h:64
@ AST_EVENT_IE_PLTYPE_RAW
Definition: event_defs.h:337
@ AST_EVENT_IE_PLTYPE_BITFLAGS
Definition: event_defs.h:339
@ AST_EVENT_IE_PLTYPE_EXISTS
Definition: event_defs.h:331
#define LOG_WARNING
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:731
#define AST_LIST_HEAD_NOLOCK_STATIC(name, type)
Defines a structure to be used to hold a list of specified type, statically initialized.
Definition: linkedlists.h:346
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:615
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:529
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:557
static void * cleanup(void *unused)
Definition: pbx_realtime.c:124
enum ast_event_ie_pltype ie_pltype
Definition: event.c:94
union ast_event_ie_val::@347 payload
size_t raw_datalen
Definition: event.c:103
void * raw
Definition: event.c:101
uint32_t uint
Definition: event.c:96
enum ast_event_ie_type ie_type
Definition: event.c:93
const char * str
Definition: event.c:99
Definition: search.h:40

References ast_calloc, ast_event_append_eid(), ast_event_append_ie_bitflags(), ast_event_append_ie_raw(), ast_event_append_ie_str(), ast_event_append_ie_uint(), ast_event_get_ie_raw(), AST_EVENT_IE_EID, AST_EVENT_IE_END, AST_EVENT_IE_PLTYPE_BITFLAGS, AST_EVENT_IE_PLTYPE_EXISTS, AST_EVENT_IE_PLTYPE_RAW, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_IE_PLTYPE_UNKNOWN, AST_EVENT_TOTAL, ast_free, AST_LIST_HEAD_NOLOCK_STATIC, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log, ast_malloc, cleanup(), ast_event_ie_val::ie_pltype, ast_event_ie_val::ie_type, LOG_WARNING, NULL, ast_event_ie_val::payload, ast_event_ie_val::raw, ast_event_ie_val::raw_datalen, ast_event_ie_val::str, type, and ast_event_ie_val::uint.

Referenced by ast_cel_create_event_with_time(), AST_TEST_DEFINE(), corosync_ping(), corosync_ping_to_event(), devstate_to_event(), fake_event(), mwi_to_event(), publish_corosync_ping_to_stasis(), and send_cluster_notify().

◆ event_iterator_get_ie_raw()

static void * event_iterator_get_ie_raw ( struct ast_event_iterator iterator)
static

Definition at line 284 of file event.c.

285{
286 return iterator->ie->ie_payload;
287}

References ast_event_iterator::ie, and ast_event_ie::ie_payload.

Referenced by ast_event_get_ie_raw().

◆ event_iterator_get_ie_raw_payload_len()

static uint16_t event_iterator_get_ie_raw_payload_len ( struct ast_event_iterator iterator)
static

Definition at line 326 of file event.c.

327{
328 return ntohs(iterator->ie->ie_payload_len);
329}

References ast_event_iterator::ie, and ast_event_ie::ie_payload_len.

Referenced by ast_event_get_ie_raw_payload_len().

Variable Documentation

◆ event_names

const char* const event_names[AST_EVENT_TOTAL]
static

Event Names.

Definition at line 109 of file event.c.

Referenced by ast_event_get_type_name().

◆ ie_maps

const struct ie_map ie_maps[AST_EVENT_IE_TOTAL]
static