34 #include "asterisk/_private.h"
62 } __attribute__((packed));
72 } __attribute__((packed));
92 } __attribute__((packed));
146 #define NUM_CACHE_BUCKETS 17
148 #define NUM_CACHE_BUCKETS 563
151 #define MAX_CACHE_ARGS 8
195 static const char *
const cached_event_types[] = {
"MWI",
"DeviceState",
"DeviceStateChange", NULL };
389 if (sub_ie_val->ie_type == event_ie_val->
ie_type) {
398 if (sub_ie_val->ie_pltype != event_ie_val->
ie_pltype) {
407 switch (sub_ie_val->ie_pltype) {
409 res = (sub_ie_val->payload.uint == event_ie_val->
payload.
uint);
416 res = (sub_ie_val->payload.uint & event_ie_val->
payload.
uint);
420 const char *substr = sub_ie_val->payload.str;
426 res = !strcmp(substr, estr);
430 res = (sub_ie_val->raw_datalen == event_ie_val->
raw_datalen
431 && !memcmp(sub_ie_val->payload.raw, event_ie_val->
payload.
raw,
432 sub_ie_val->raw_datalen));
460 int want_specific_event;
462 if (type >= AST_EVENT_TOTAL) {
467 want_specific_event = 0;
476 memset(ie_value, 0,
sizeof(*ie_value));
489 ie_value->
payload.
str = va_arg(ap,
const char *);
494 void *data = va_arg(ap,
void *);
495 size_t datalen = va_arg(ap,
size_t);
510 want_specific_event = 1;
518 for (i = 0; i <
ARRAY_LEN(event_types); i++) {
520 if (want_specific_event) {
593 const char *e1str, *e2str;
602 if (!strcmp(e1str, e2str)) {
718 if (event_type == -1)
723 if (event_sub == sub) {
744 if (type < 0 || type >= AST_EVENT_TOTAL) {
770 if (!(ie_val =
ast_calloc(1,
sizeof(*ie_val)))) {
792 if (!(ie_val =
ast_calloc(1,
sizeof(*ie_val)))) {
814 if (!(ie_val =
ast_calloc(1,
sizeof(*ie_val)))) {
835 if (!(ie_val =
ast_calloc(1,
sizeof(*ie_val)))) {
869 if (!(ie_val =
ast_calloc(1,
sizeof(*ie_val)))) {
882 memcpy(ie_val->
payload.
raw, data, raw_datalen);
922 va_start(ap, userdata);
936 uint32_t unsigned_int = va_arg(ap, uint32_t);
942 uint32_t unsigned_int = va_arg(ap, uint32_t);
948 const char *
str = va_arg(ap,
const char *);
954 void *data = va_arg(ap,
void *);
955 size_t data_len = va_arg(ap,
size_t);
1019 iterator->
event = event;
1021 iterator->
ie = (
struct ast_event_ie *) ( ((
char *) event) +
sizeof(*event) );
1023 iterator->
ie = NULL;
1033 return ((iterator->
event_len <= (((
char *) iterator->
ie) - ((
char *) iterator->
event))) ? -1 : 0);
1038 return ntohs(iterator->
ie->ie_type);
1057 return str_payload ? str_payload->
str : NULL;
1072 return ntohs(event->type);
1077 const uint32_t *ie_val;
1086 const uint32_t *ie_val;
1099 return str_payload ? str_payload->
hash : 0;
1108 return str_payload ? str_payload->
str : NULL;
1145 payload_len =
sizeof(*str_payload) + strlen(str);
1148 strcpy(str_payload->
str, str);
1170 flags = htonl(flags);
1175 const void *data,
size_t data_len)
1179 unsigned int extra_len;
1182 event_len = ntohs((*event)->event_len);
1183 extra_len =
sizeof(*ie) + data_len;
1186 *
event =
ast_realloc(*event, event_len + extra_len);
1192 ie = (
struct ast_event_ie *) ( ((
char *) *event) + event_len );
1193 ie->ie_type = htons(ie_type);
1197 (*event)->event_len = htons(event_len + extra_len);
1212 if (type >= AST_EVENT_TOTAL) {
1214 "type '%u'!\n", type);
1226 memset(ie_value, 0,
sizeof(*ie_value));
1239 ie_value->
payload.
str = va_arg(ap,
const char *);
1244 void *data = va_arg(ap,
void *);
1245 size_t datalen = va_arg(ap,
size_t);
1247 memcpy(ie_value->
payload.
raw, data, datalen);
1266 if (!(event =
ast_calloc(1,
sizeof(*event)))) {
1270 event->type = htons(type);
1271 event->event_len = htons(
sizeof(*event));
1333 if (!(dup_event =
ast_calloc(1, event_len))) {
1337 memcpy(dup_event, event, event_len);
1354 if (type >= AST_EVENT_TOTAL) {
1377 switch (ie_pltype) {
1389 void *data = va_arg(ap,
void *);
1390 size_t datalen = va_arg(ap,
size_t);
1403 tmp_event_ref.
event = cache_arg_event;
1408 cache_arg_event = NULL;
1410 if (cached_event_ref) {
1412 ao2_ref(cached_event_ref, -1);
1413 cached_event_ref = NULL;
1454 event_ref->
event = dup_event;
1487 ntohs(event_ref->
event->type),
1492 for (i = 0; i <
ARRAY_LEN(event_types); i++) {
1520 uint16_t host_event_type;
1523 host_event_type = ntohs(event->type);
1526 if (host_event_type >= AST_EVENT_TOTAL) {
1528 "type '%d'!\n", host_event_type);
1547 event_ref->
event = NULL;
1601 event = event_ref->
event;
1637 event = event_ref->
event;
1640 event2 = event_ref2->
event;
1647 .ie_type = cache_args[i],
1663 const char *ie_type_name;
1671 ast_cli(a->
fd,
"%.30s: %s\n", ie_type_name, eid_buf);
1687 ast_cli(a->
fd,
"Failed to initialize event iterator. :-(\n");
1696 const char *ie_type_name;
1702 switch (ie_pltype) {
1708 ast_cli(a->
fd,
"%.30s: %s\n", ie_type_name,
1712 ast_cli(a->
fd,
"%.30s: %u\n", ie_type_name,
1716 ast_cli(a->
fd,
"%.30s: %u\n", ie_type_name,
1738 e->
command =
"event dump cache";
1740 "Usage: event dump cache <event type>\n"
1741 " Dump all of the cached events for the given event type.\n"
1742 " This is primarily intended for debugging.\n";
1774 ast_cli(a->
fd,
"\n--- Begin Cache Dump ---\n\n");
1776 ast_cli(a->
fd,
"--- End Cache Dump ---\n\n");
1793 if (event_dispatcher) {
1835 goto event_init_cleanup;
1840 goto event_init_cleanup;
#define NUM_CACHE_BUCKETS
int ast_event_sub_append_ie_str(struct ast_event_sub *sub, enum ast_event_ie_type ie_type, const char *str)
Append a string parameter to a subscription.
#define AST_RWDLLIST_HEAD(name, type)
Defines a structure to be used to hold a read/write list of specified type.
Channel Event CID name Used by: AST_EVENT_CEL Payload type: STR.
Channel Event app name Used by: AST_EVENT_CEL Payload type: STR.
#define AST_CLI_DEFINE(fn, txt,...)
int ast_event_str_to_ie_type(const char *str, enum ast_event_ie_type *ie_type)
Convert a string to an IE type.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
#define ao2_link(arg1, arg2)
int ast_event_sub_append_ie_bitflags(struct ast_event_sub *sub, enum ast_event_ie_type ie_type, uint32_t flags)
Append a bitflags parameter to a subscription.
uint32_t hash
A hash calculated with ast_str_hash(), to speed up comparisons.
#define AST_RWDLLIST_HEAD_INIT(head)
Initializes an rwlist head structure.
static int event_dump_cli(void *obj, void *arg, int flags)
int ast_event_str_to_event_type(const char *str, enum ast_event_type *event_type)
Convert a string into an event type.
uint32_t ast_event_get_ie_bitflags(const struct ast_event *event, enum ast_event_ie_type ie_type)
Get the value of an information element that has a bitflags payload.
enum ast_event_type ast_event_get_type(const struct ast_event *event)
Get the type for an event.
Channel Event extra data Used by: AST_EVENT_CEL Payload type: STR.
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
char * ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
ast_event_ie_pltype
Payload types for event information elements.
enum ast_event_subscriber_res ast_event_check_subscriber(enum ast_event_type event_type,...)
Check if subscribers exist.
enum ast_event_ie_pltype ie_pltype
int ast_taskprocessor_push(struct ast_taskprocessor *tps, int(*task_exe)(void *datap), void *datap)
Push a task into the specified taskprocessor queue and signal the taskprocessor thread.
struct ast_event_ie_val::@256 entry
int ast_event_queue_and_cache(struct ast_event *event)
Queue and cache an event.
void ast_event_report_subs(const struct ast_event_sub *sub)
Report current subscriptions to a subscription subscriber.
descriptor for a cli entry.
struct ast_event_sub * event_sub
union ast_event_ie_val::@257 payload
#define ao2_callback(c, flags, cb_fn, arg)
struct ast_taskprocessor * ast_taskprocessor_get(const char *name, enum ast_tps_options create)
Get a reference to a taskprocessor with the specified name and create the taskprocessor if necessary...
Must be the last IE value +1.
Channel Event channel name Used by: AST_EVENT_CEL Payload type: STR.
Hint that someone cares that an IE exists Used by: AST_EVENT_SUB Payload type: UINT (ast_event_ie_typ...
Subscription event check list.
Channel Event UniqueID Used by: AST_EVENT_CEL Payload type: STR.
Channel Event context name Used by: AST_EVENT_CEL Payload type: STR.
ast_event_subscriber_res
Results for checking for subscribers.
Channel Event app args/data Used by: AST_EVENT_CEL Payload type: STR.
Channel Event peeraccount Used by: AST_EVENT_CEL Payload type: STR.
Channel Event Time (micro-seconds) Used by: AST_EVENT_CEL Payload type: UINT.
Channel Event CID dnid Used by: AST_EVENT_CEL Payload type: STR.
const char * ast_event_subscriber_get_description(struct ast_event_sub *sub)
Get description for a subscription.
Description Used by: AST_EVENT_SUB, AST_EVENT_UNSUB Payload type: STR.
struct ast_event * ast_event_get_cached(enum ast_event_type,...)
Retrieve an event from the cache.
#define AST_RWDLLIST_HEAD_DESTROY(head)
Destroys an rwlist head structure.
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.
Number of new messages Used by: AST_EVENT_MWI Payload type: UINT.
Number of Used by: AST_EVENT_MWI Payload type: UINT.
uint32_t ast_event_iterator_get_ie_bitflags(struct ast_event_iterator *iterator)
Get the value of the current IE in the iterator as a bitflags payload.
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.
#define AST_RWDLLIST_ENTRY
char str[1]
The actual string, null terminated.
enum ast_event_ie_type cache_args[MAX_CACHE_ARGS]
Information Elements used for caching.
supposed to be an opaque type
void ast_event_sub_destroy(struct ast_event_sub *sub)
Destroy an allocated subscription.
static int dump_cache_cb(void *obj, void *arg, int flags)
uint32_t ast_event_get_ie_str_hash(const struct ast_event *event, enum ast_event_ie_type ie_type)
Get the hash for the string payload of an IE.
void ast_cli(int fd, const char *fmt,...)
static const char *const event_names[AST_EVENT_TOTAL]
Event Names.
struct ao2_container * container
The asterisk data main content structure.
struct ast_ev_check_list::@261 ie_vals
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return * the previous value of *p. This can be used to handle reference co...
Channel Event Type Used by: AST_EVENT_CEL Payload type: UINT.
Entity ID Used by All events Payload type: RAW This IE indicates which server the event originated fr...
int args
This gets set in ast_cli_register()
static struct ast_event_sub_list ast_event_subs[AST_EVENT_TOTAL]
Channel Event Time (seconds) Used by: AST_EVENT_CEL Payload type: UINT.
char * ast_cli_complete(const char *word, const char *const choices[], int pos)
Channel Event CID num Used by: AST_EVENT_CEL Payload type: STR.
static force_inline int ast_str_hash_add(const char *str, int hash)
Compute a hash value on a string.
Channel Event extension name Used by: AST_EVENT_CEL Payload type: STR.
int ast_event_queue(struct ast_event *event)
Queue an event.
ast_event_ie_type
Event Information Element types.
Handle unaligned data access.
ast_event_type
Event types.
Context IE Used by AST_EVENT_MWI Payload type: str.
Event subscriptions The event subscribers are indexed by which event they are subscribed to...
A set of macros to manage doubly-linked lists.
void(* ast_event_cb_t)(const struct ast_event *event, void *userdata)
Subscriber event callback type.
static struct ast_event * ast_event_dup(const struct ast_event *event)
#define AST_RWDLLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
An event information element.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
static int ast_event_cmp(void *obj, void *arg, int flags)
#define ao2_ref(o, delta)
int ast_register_atexit(void(*func)(void))
Register a function to be executed before Asterisk exits.
static struct ie_map ie_maps[AST_EVENT_IE_TOTAL]
Channel Event Userfield Used by: AST_EVENT_CEL Payload type: STR.
A set of macros to manage forward-linked lists.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
static int ast_event_hash_devstate(const void *obj, const int flags)
Channel Event CID RDNIS field Used by: AST_EVENT_CEL Payload type: STR.
static unsigned int get_unaligned_uint32(const void *p)
static char * event_dump_cache(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Event non-cachability flag Used by: All events Payload type: UINT.
int ast_event_sub_append_ie_raw(struct ast_event_sub *sub, enum ast_event_ie_type ie_type, void *data, size_t raw_datalen)
Append a raw parameter to a subscription.
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.
static int match_ie_val(const struct ast_event *event, const struct ast_event_ie_val *ie_val, const struct ast_event *event2)
Event type Used by: AST_EVENT_SUB, AST_EVENT_UNSUB Payload type: UINT.
void ast_event_dump_cache(const struct ast_event_sub *event_sub)
Dump the event cache for the subscriber.
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
#define ast_strdupa(s)
duplicate a string in memory from the stack
static int match_sub_ie_val_to_event(const struct ast_event_ie_val *sub_ie_val, const struct ast_ev_check_list *check_ie_vals)
#define AST_LIST_HEAD_NOLOCK_STATIC(name, type)
Defines a structure to be used to hold a list of specified type, statically initialized.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
char * ast_tech_to_upper(char *dev_str)
Convert the tech portion of a device string to upper case.
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.
enum ast_event_ie_type ie_type
Channel Event User Event Name Used by: AST_EVENT_CEL Payload type: STR.
static uint32_t sub_uniqueid
#define AST_RWDLLIST_REMOVE_HEAD
static struct ast_taskprocessor * event_dispatcher
int ast_event_sub_activate(struct ast_event_sub *sub)
Activate a dynamically built subscription.
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.
#define AST_RWDLLIST_INSERT_TAIL
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
static int ast_event_hash_mwi(const void *obj, const int flags)
#define ao2_alloc(data_size, destructor_fn)
static struct @255 ast_event_cache[AST_EVENT_TOTAL]
Event types that are kept in the cache.
static void ast_event_ref_destroy(void *obj)
static struct ast_event_ref * alloc_event_ref(void)
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
#define ao2_find(arg1, arg2, arg3)
size_t ast_event_minimum_length(void)
Get the minimum length of an ast_event.
struct ast_event_sub::@260 ie_vals
Channel Event Peer – for Things involving multiple channels, like BRIDGE Used by: AST_EVENT_CEL Paylo...
Channel Event CID ANI field Used by: AST_EVENT_CEL Payload type: STR.
int ast_event_sub_append_ie_uint(struct ast_event_sub *sub, enum ast_event_ie_type ie_type, uint32_t uint)
Append a uint parameter to a subscription.
static void event_update_cache(struct ao2_container *cache, struct ast_event *event)
static int handle_event(void *data)
An API for managing task processing threads that can be shared across modules.
#define AST_RWDLLIST_WRLOCK(head)
Write locks a list.
Channel Event AMA flags Used by: AST_EVENT_CEL Payload type: UINT.
static const char *const cached_event_types[]
Names of cached event types, for CLI tab completion.
static int ast_event_hash(const void *obj, const int flags)
#define AST_LIST_HEAD_NOLOCK_INIT_VALUE
Defines initial values for a declaration of AST_LIST_HEAD_NOLOCK.
static int ast_event_hash_devstate_change(const void *obj, const int flags)
struct ao2_container * cache
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.
struct ast_eid ast_eid_default
Global EID.
int ast_event_iterator_init(struct ast_event_iterator *iterator, const struct ast_event *event)
Initialize an event iterator instance.
Channel Event LinkedID Used by: AST_EVENT_CEL Payload type: STR.
A ast_taskprocessor structure is a singleton by name.
void ast_event_destroy(struct ast_event *event)
Destroy an event.
int ast_event_iterator_next(struct ast_event_iterator *iterator)
Move iterator instance to next IE.
static struct ast_cli_entry event_cli[]
Standard Command Line Interface.
struct ast_event * ast_event_new(enum ast_event_type event_type,...)
Create a new event.
struct ast_event_sub * ast_event_subscribe(enum ast_event_type event_type, ast_event_cb_t cb, const char *description, void *userdata,...)
Subscribe to events.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
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.
#define ao2_container_alloc(arg1, arg2, arg3)
void * ast_taskprocessor_unreference(struct ast_taskprocessor *tps)
Unreference the specified taskprocessor and its reference count will decrement.
#define AST_RWDLLIST_TRAVERSE
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
int ast_event_append_eid(struct ast_event **event)
Append the global EID IE.
#define ast_realloc(a, b)
uint16_t ast_event_iterator_get_ie_raw_payload_len(struct ast_event_iterator *iterator)
Get the length of the raw payload for the current IE for an iterator.
static struct ast_event * gen_sub_event(struct ast_event_sub *sub)
const char * ast_event_get_ie_type_name(enum ast_event_ie_type ie_type)
Get the string representation of an information element type.
int( ao2_hash_fn)(const void *obj, const int flags)
static void ast_event_ie_val_destroy(struct ast_event_ie_val *ie_val)
#define AST_DLLIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
Unique ID Used by: AST_EVENT_SUB, AST_EVENT_UNSUB Payload type: UINT.
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.
size_t ast_event_get_size(const struct ast_event *event)
Get the size of an event.
const char * ast_event_get_type_name(const struct ast_event *event)
Get the string representation of the type of the given event.
static void dump_raw_ie(struct ast_event_iterator *i, struct ast_cli_args *a)
enum ast_event_ie_pltype ie_pltype
static char context[AST_MAX_CONTEXT]
Generic State IE Used by AST_EVENT_DEVICE_STATE_CHANGE Payload type: UINT The actual state values dep...
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.
#define AST_RWDLLIST_RDLOCK(head)
Read locks a list.
void * ast_event_iterator_get_ie_raw(struct ast_event_iterator *iterator)
Get the value of the current IE in the iterator instance that has a raw payload.
Device Name Used by AST_EVENT_DEVICE_STATE_CHANGE Payload type: STR.
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.
static void event_shutdown(void)
struct ast_event_sub * ast_event_unsubscribe(struct ast_event_sub *event_sub)
Un-subscribe from events.
struct ast_event_sub * ast_event_subscribe_new(enum ast_event_type type, ast_event_cb_t cb, void *userdata)
Allocate a subscription, but do not activate it.
ao2_hash_fn * hash_fn
Event type specific hash function.
IE payload types and names.
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.
static char mailbox[AST_MAX_EXTENSION]
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.
Channel Event AccountCode Used by: AST_EVENT_CEL Payload type: STR.
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
unsigned char ie_payload[0]
The payload for a string information element.
int ast_event_sub_append_ie_exists(struct ast_event_sub *sub, enum ast_event_ie_type ie_type)
Append an 'exists' parameter to a subscription.
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.