/*! \brief Publish a received device state \ref ast_event to \ref stasis */ static void publish_device_state_to_stasis(struct ast_event *event) { const char *device; enum ast_device_state state; unsigned int cachable; struct ast_eid *event_eid; ast_assert(ast_event_get_type(event) == AST_EVENT_DEVICE_STATE_CHANGE); device = ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE); state = ast_event_get_ie_uint(event, AST_EVENT_IE_STATE); cachable = ast_event_get_ie_uint(event, AST_EVENT_IE_CACHABLE); event_eid = (struct ast_eid *)ast_event_get_ie_raw(event, AST_EVENT_IE_EID); if (ast_strlen_zero(device)) { return; } if (ast_publish_device_state_full(device, state, cachable, event_eid)) { char eid[18]; ast_eid_to_str(eid, sizeof(eid), event_eid); ast_log(LOG_WARNING, "Failed to publish device state message for %s from %s\n", device, eid); } }
static void append_ie(struct ast_str **str, const struct ast_event *event, const enum ast_event_ie_type ie_type, enum ie_required required) { if (!required && !ie_is_present(event, ie_type)) { /* Optional IE isn't present. Ignore. */ return; } /* At this point, it _better_ be there! */ ast_assert(ie_is_present(event, ie_type)); switch (ast_event_get_ie_pltype(ie_type)) { case AST_EVENT_IE_PLTYPE_UINT: ast_str_append(str, 0, ",%s=\"%u\"", ast_event_get_ie_type_name(ie_type), ast_event_get_ie_uint(event, ie_type)); break; case AST_EVENT_IE_PLTYPE_STR: ast_str_append(str, 0, ",%s=\"%s\"", ast_event_get_ie_type_name(ie_type), ast_event_get_ie_str(event, ie_type)); break; case AST_EVENT_IE_PLTYPE_BITFLAGS: ast_str_append(str, 0, ",%s=\"%u\"", ast_event_get_ie_type_name(ie_type), ast_event_get_ie_bitflags(event, ie_type)); break; case AST_EVENT_IE_PLTYPE_UNKNOWN: case AST_EVENT_IE_PLTYPE_EXISTS: case AST_EVENT_IE_PLTYPE_RAW: ast_log(LOG_WARNING, "Unexpected payload type for IE '%s'\n", ast_event_get_ie_type_name(ie_type)); break; } }
static void print_cel_sub(const struct ast_event *event, void *data) { struct ast_cli_args *a = data; ast_cli(a->fd, "CEL Event Subscriber: %s\n", ast_event_get_ie_str(event, AST_EVENT_IE_DESCRIPTION)); }
static int check_event(struct ast_event *event, struct ast_test *test, enum ast_event_type expected_type, const char *type_name, const char *str, uint32_t uint) { enum ast_event_type type; const void *foo; /* Check #1: Ensure event type is set properly. */ type = ast_event_get_type(event); if (ast_event_get_type(event) != type) { ast_test_status_update(test, "Expected event type: '%u', got '%u'\n", expected_type, type); return -1; } /* Check #4: Check for the string IE */ if (strcmp(str, ast_event_get_ie_str(event, AST_EVENT_IE_CEL_USEREVENT_NAME))) { ast_test_status_update(test, "Failed to get string IE.\n"); return -1; } /* Check #5: Check for the uint IE */ if (uint != ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_AMAFLAGS)) { ast_test_status_update(test, "Failed to get uint IE.\n"); return -1; } /* Check #6: Check if a check for a str IE that isn't there works */ if ((foo = ast_event_get_ie_str(event, AST_EVENT_IE_CEL_CIDNAME))) { ast_test_status_update(test, "CEL_CIDNAME IE check returned non-NULL %p\n", foo); return -1; } /* Check #7: Check if a check for a uint IE that isn't there returns 0 */ if (ast_event_get_ie_uint(event, AST_EVENT_IE_CEL_EVENT_TIME_USEC)) { ast_test_status_update(test, "UNIQUEID IE should be 0\n"); return -1; } ast_test_status_update(test, "Event looks good.\n"); return 0; }
static struct corosync_node *corosync_node_alloc(struct ast_event *event) { struct corosync_node *node; node = ao2_alloc_options(sizeof(*node), NULL, AO2_ALLOC_OPT_LOCK_NOLOCK); if (!node) { return NULL; } memcpy(&node->eid, (struct ast_eid *)ast_event_get_ie_raw(event, AST_EVENT_IE_EID), sizeof(node->eid)); node->id = ast_event_get_ie_uint(event, AST_EVENT_IE_NODE_ID); ast_sockaddr_parse(&node->addr, ast_event_get_ie_str(event, AST_EVENT_IE_LOCAL_ADDR), PARSE_PORT_IGNORE); return node; }
/*! \brief Publish a received MWI \ref ast_event to \ref stasis */ static void publish_mwi_to_stasis(struct ast_event *event) { const char *mailbox; const char *context; unsigned int new_msgs; unsigned int old_msgs; struct ast_eid *event_eid; ast_assert(ast_event_get_type(event) == AST_EVENT_MWI); mailbox = ast_event_get_ie_str(event, AST_EVENT_IE_MAILBOX); context = ast_event_get_ie_str(event, AST_EVENT_IE_CONTEXT); new_msgs = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS); old_msgs = ast_event_get_ie_uint(event, AST_EVENT_IE_OLDMSGS); event_eid = (struct ast_eid *)ast_event_get_ie_raw(event, AST_EVENT_IE_EID); if (ast_strlen_zero(mailbox) || ast_strlen_zero(context)) { return; } if (new_msgs > INT_MAX) { new_msgs = INT_MAX; } if (old_msgs > INT_MAX) { old_msgs = INT_MAX; } if (ast_publish_mwi_state_full(mailbox, context, (int)new_msgs, (int)old_msgs, NULL, event_eid)) { char eid[18]; ast_eid_to_str(eid, sizeof(eid), event_eid); ast_log(LOG_WARNING, "Failed to publish MWI message for %s@%s from %s\n", mailbox, context, eid); } }
int ast_cel_fill_record(const struct ast_event *e, struct ast_cel_event_record *r) { if (r->version != AST_CEL_EVENT_RECORD_VERSION) { ast_log(LOG_ERROR, "Module ABI mismatch for ast_cel_event_record. " "Please ensure all modules were compiled for " "this version of Asterisk.\n"); return -1; } r->event_type = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_EVENT_TYPE); r->event_time.tv_sec = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_EVENT_TIME); r->event_time.tv_usec = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_EVENT_TIME_USEC); r->user_defined_name = ""; if (r->event_type == AST_CEL_USER_DEFINED) { r->user_defined_name = ast_event_get_ie_str(e, AST_EVENT_IE_CEL_USEREVENT_NAME); r->event_name = r->user_defined_name; } else { r->event_name = ast_cel_get_type_name(r->event_type); } r->caller_id_name = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDNAME), ""); r->caller_id_num = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDNUM), ""); r->caller_id_ani = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDANI), ""); r->caller_id_rdnis = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDRDNIS), ""); r->caller_id_dnid = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CIDDNID), ""); r->extension = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_EXTEN), ""); r->context = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CONTEXT), ""); r->channel_name = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_CHANNAME), ""); r->application_name = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_APPNAME), ""); r->application_data = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_APPDATA), ""); r->account_code = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_ACCTCODE), ""); r->peer_account = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_ACCTCODE), ""); r->unique_id = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_UNIQUEID), ""); r->linked_id = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_LINKEDID), ""); r->amaflag = ast_event_get_ie_uint(e, AST_EVENT_IE_CEL_AMAFLAGS); r->user_field = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_USERFIELD), ""); r->peer = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_PEER), ""); r->extra = S_OR(ast_event_get_ie_str(e, AST_EVENT_IE_CEL_EXTRA), ""); return 0; }
static int check_event(struct ast_event *event, struct ast_test *test, enum ast_event_type expected_type, const char *type_name, const char *str, uint32_t uint, uint32_t bitflags) { enum ast_event_type type; const void *foo; /* Check #1: Ensure event type is set properly. */ type = ast_event_get_type(event); if (ast_event_get_type(event) != type) { ast_test_status_update(test, "Expected event type: '%d', got '%d'\n", expected_type, type); return -1; } /* Check #2: Check string representation of event type */ if (strcmp(type_name, ast_event_get_type_name(event))) { ast_test_status_update(test, "Didn't get expected type name: '%s' != '%s'\n", type_name, ast_event_get_type_name(event)); return -1; } /* Check #3: Check for automatically included EID */ if (memcmp(&ast_eid_default, ast_event_get_ie_raw(event, AST_EVENT_IE_EID), sizeof(ast_eid_default))) { ast_test_status_update(test, "Failed to get EID\n"); return -1; } /* Check #4: Check for the string IE */ if (strcmp(str, ast_event_get_ie_str(event, AST_EVENT_IE_MAILBOX))) { ast_test_status_update(test, "Failed to get string IE.\n"); return -1; } /* Check #5: Check for the uint IE */ if (uint != ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS)) { ast_test_status_update(test, "Failed to get uint IE.\n"); return -1; } /* Check #6: Check for the bitflags IE */ if (bitflags != ast_event_get_ie_bitflags(event, AST_EVENT_IE_OLDMSGS)) { ast_test_status_update(test, "Failed to get bitflags IE.\n"); return -1; } /* Check #7: Check if a check for a str IE that isn't there works */ if ((foo = ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE))) { ast_test_status_update(test, "DEVICE IE check returned non-NULL %p\n", foo); return -1; } /* Check #8: Check if a check for a uint IE that isn't there returns 0 */ if (ast_event_get_ie_uint(event, AST_EVENT_IE_STATE)) { ast_test_status_update(test, "OLDMSGS IE should be 0\n"); return -1; } ast_test_status_update(test, "Event looks good.\n"); return 0; }