1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-11-03 04:17:17 -05:00

Feature: Added source media type to events if known

This commit is contained in:
Philipp Schafft 2022-09-17 09:28:57 +00:00
parent 0df67e7971
commit 6f29ca2996
5 changed files with 26 additions and 12 deletions

View File

@ -484,6 +484,12 @@ void event_emit_va(const char *trigger, ...) {
}
va_end(ap);
if (source) {
if (source->format && source->format->contenttype) {
extra_add(event, EVENT_EXTRA_KEY_SOURCE_MEDIA_TYPE, source->format->contenttype);
}
}
if (client) {
event->connection_id = client->con->id;
event->connection_time = client->con->con_time;

View File

@ -35,7 +35,8 @@ typedef enum {
EVENT_EXTRA_KEY_CONNECTION_IP,
EVENT_EXTRA_KEY_CLIENT_ROLE,
EVENT_EXTRA_KEY_CLIENT_USERNAME,
EVENT_EXTRA_KEY_CLIENT_USERAGENT
EVENT_EXTRA_KEY_CLIENT_USERAGENT,
EVENT_EXTRA_KEY_SOURCE_MEDIA_TYPE,
} event_extra_key_t;
typedef struct {

View File

@ -152,6 +152,7 @@ static inline void __setup_environ(ice_config_t *config, event_exec_t *self, eve
__update_environ("EVENT_TRIGGER", event->trigger); /* new name */
__update_environ("SOURCE_ACTION", event->trigger); /* old name (deprecated) */
__update_environ_with_key(event, "EVENT_URI", EVENT_EXTRA_KEY_URI);
__update_environ_with_key(event, "SOURCE_MEDIA_TYPE", EVENT_EXTRA_KEY_SOURCE_MEDIA_TYPE);
__update_environ_with_key(event, "CLIENT_IP", EVENT_EXTRA_KEY_CONNECTION_IP);
__update_environ_with_key(event, "CLIENT_ROLE", EVENT_EXTRA_KEY_CLIENT_ROLE);
__update_environ_with_key(event, "CLIENT_USERNAME", EVENT_EXTRA_KEY_CLIENT_USERNAME);

View File

@ -30,7 +30,7 @@ static int event_log_emit(void *state, event_t *event) {
ICECAST_LOG(self->level, ICECAST_LOGFLAG_NONE,
"%s%strigger=%# H uri=%#H "
"connection_id=%lu connection_ip=%#H connection_time=%lli "
"client_role=%# H client_username=%#H client_useragent=%# H client_admin_command=%i",
"client_role=%# H client_username=%#H client_useragent=%# H client_admin_command=%i source_media_type=%#H",
self->prefix ? self->prefix : "", self->prefix ? ": " : "",
event->trigger,
event_extra_get(event, EVENT_EXTRA_KEY_URI),
@ -38,7 +38,9 @@ static int event_log_emit(void *state, event_t *event) {
event_extra_get(event, EVENT_EXTRA_KEY_CLIENT_ROLE),
event_extra_get(event, EVENT_EXTRA_KEY_CLIENT_USERNAME),
event_extra_get(event, EVENT_EXTRA_KEY_CLIENT_USERAGENT),
event->client_admin_command);
event->client_admin_command,
event_extra_get(event, EVENT_EXTRA_KEY_SOURCE_MEDIA_TYPE)
);
return 0;
}

View File

@ -43,16 +43,17 @@ static inline char *__escape(const char *src, const char *default_value) {
static int event_url_emit(void *state, event_t *event) {
event_url_t *self = state;
ice_config_t *config;
char *action, *mount, *server, *role, *username, *ip, *agent;
char *action, *mount, *server, *role, *username, *ip, *agent, *media_type;
time_t duration;
char post[4096];
action = util_url_escape(self->action ? self->action : event->trigger);
mount = __escape(event_extra_get(event, EVENT_EXTRA_KEY_URI), "");
role = __escape(event_extra_get(event, EVENT_EXTRA_KEY_CLIENT_ROLE), "");
username = __escape(event_extra_get(event, EVENT_EXTRA_KEY_CLIENT_USERNAME), "");
ip = __escape(event_extra_get(event, EVENT_EXTRA_KEY_CONNECTION_IP), "");
agent = __escape(event_extra_get(event, EVENT_EXTRA_KEY_CLIENT_USERAGENT), "-");
action = util_url_escape(self->action ? self->action : event->trigger);
mount = __escape(event_extra_get(event, EVENT_EXTRA_KEY_URI), "");
role = __escape(event_extra_get(event, EVENT_EXTRA_KEY_CLIENT_ROLE), "");
username = __escape(event_extra_get(event, EVENT_EXTRA_KEY_CLIENT_USERNAME), "");
ip = __escape(event_extra_get(event, EVENT_EXTRA_KEY_CONNECTION_IP), "");
agent = __escape(event_extra_get(event, EVENT_EXTRA_KEY_CLIENT_USERAGENT), "-");
media_type = __escape(event_extra_get(event, EVENT_EXTRA_KEY_CLIENT_USERAGENT), "-");
if (event->connection_time) {
duration = time(NULL) - event->connection_time;
@ -64,9 +65,11 @@ static int event_url_emit(void *state, event_t *event) {
server = __escape(config->hostname, "");
snprintf (post, sizeof (post),
"action=%s&mount=%s&server=%s&port=%d&client=%lu&role=%s&username=%s&ip=%s&agent=%s&duration=%lli&admin=%i",
"action=%s&mount=%s&server=%s&port=%d&client=%lu&role=%s&username=%s&ip=%s&agent=%s&duration=%lli&admin=%i&source-media-type=%s",
action, mount, server, config->port,
event->connection_id, role, username, ip, agent, (long long int)duration, event->client_admin_command);
event->connection_id, role, username, ip, agent, (long long int)duration, event->client_admin_command,
media_type
);
config_release_config();
free(action);
@ -76,6 +79,7 @@ static int event_url_emit(void *state, event_t *event) {
free(username);
free(ip);
free(agent);
free(media_type);
if (strchr(self->url, '@') == NULL && self->userpwd) {
curl_easy_setopt(self->handle, CURLOPT_USERPWD, self->userpwd);