Esempio n. 1
0
static void security_event_cb(const struct ast_event *event, void *data)
{
    struct ast_str *str;
    enum ast_security_event_type event_type;

    if (!(str = ast_str_thread_get(&security_event_buf,
                                   SECURITY_EVENT_BUF_INIT_LEN))) {
        return;
    }

    /* Note that the event type is guaranteed to be valid here. */
    event_type = ast_event_get_ie_uint(event, AST_EVENT_IE_SECURITY_EVENT);
    ast_assert(event_type >= 0 && event_type < AST_SECURITY_EVENT_NUM_TYPES);

    ast_str_set(&str, 0, "%s=\"%s\"",
                ast_event_get_ie_type_name(AST_EVENT_IE_SECURITY_EVENT),
                ast_security_event_get_name(event_type));

    append_ies(&str, event,
               ast_security_event_get_required_ies(event_type), REQUIRED);
    append_ies(&str, event,
               ast_security_event_get_optional_ies(event_type), NOT_REQUIRED);

    ast_log_dynamic_level(LOG_SECURITY, "%s\n", ast_str_buffer(str));
}
Esempio n. 2
0
static void security_event_stasis_cb(struct ast_json *json)
{
	struct ast_str *str;
	struct ast_json *event_type_json;
	enum ast_security_event_type event_type;

	event_type_json = ast_json_object_get(json, "SecurityEvent");
	event_type = ast_json_integer_get(event_type_json);

	ast_assert(event_type >= 0 && event_type < AST_SECURITY_EVENT_NUM_TYPES);

	if (!(str = ast_str_thread_get(&security_event_buf,
			SECURITY_EVENT_BUF_INIT_LEN))) {
		return;
	}

	ast_str_set(&str, 0, "SecurityEvent=\"%s\"",
			ast_security_event_get_name(event_type));

	append_json(&str, json,
			ast_security_event_get_required_ies(event_type), REQUIRED);
	append_json(&str, json,
			ast_security_event_get_optional_ies(event_type), NOT_REQUIRED);

	ast_log_dynamic_level(LOG_SECURITY, "%s\n", ast_str_buffer(str));
}
Esempio n. 3
0
static int handle_security_event(const struct ast_security_event_common *sec)
{
	struct ast_event *event;
	const struct ast_security_event_ie_type *ies;
	unsigned int i;

	if (!(event = alloc_event(sec))) {
		return -1;
	}

	for (ies = ast_security_event_get_required_ies(sec->event_type), i = 0;
			ies[i].ie_type != AST_EVENT_IE_END;
			i++) {
		if (add_ie(&event, sec, ies + i, REQUIRED)) {
			goto return_error;
		}
	}

	for (ies = ast_security_event_get_optional_ies(sec->event_type), i = 0;
			ies[i].ie_type != AST_EVENT_IE_END;
			i++) {
		if (add_ie(&event, sec, ies + i, NOT_REQUIRED)) {
			goto return_error;
		}
	}


	if (ast_event_queue(event)) {
		goto return_error;
	}

	return 0;

return_error:
	if (event) {
		ast_event_destroy(event);
	}

	return -1;
}