2014-12-07 19:39:57 -05:00
|
|
|
/* Icecast
|
|
|
|
*
|
|
|
|
* This program is distributed under the GNU General Public License, version 2.
|
|
|
|
* A copy of this license is included with this source.
|
|
|
|
*
|
2022-09-17 05:30:40 -04:00
|
|
|
* Copyright 2014-2022, Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
|
2014-12-07 19:39:57 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __EVENT_H__
|
|
|
|
#define __EVENT_H__
|
|
|
|
|
|
|
|
#include <libxml/xmlmemory.h>
|
|
|
|
#include <libxml/parser.h>
|
|
|
|
#include <libxml/tree.h>
|
|
|
|
|
2018-06-17 08:28:38 -04:00
|
|
|
#include "common/thread/thread.h"
|
|
|
|
|
|
|
|
#include "icecasttypes.h"
|
2014-12-07 19:39:57 -05:00
|
|
|
|
|
|
|
/* implemented */
|
|
|
|
#define EVENT_TYPE_LOG "log"
|
|
|
|
#define EVENT_TYPE_EXEC "exec"
|
|
|
|
/* not implemented */
|
|
|
|
#define EVENT_TYPE_URL "url"
|
|
|
|
|
|
|
|
#define MAX_REGLISTS_PER_EVENT 8
|
|
|
|
|
2022-09-06 08:31:11 -04:00
|
|
|
typedef enum {
|
2022-09-16 09:28:18 -04:00
|
|
|
/* special keys */
|
|
|
|
EVENT_EXTRA_LIST_END,
|
|
|
|
EVENT_EXTRA_CLIENT,
|
|
|
|
/* real keys */
|
2022-09-06 08:31:11 -04:00
|
|
|
EVENT_EXTRA_KEY_URI,
|
2022-09-16 10:28:23 -04:00
|
|
|
EVENT_EXTRA_KEY_CONNECTION_IP,
|
|
|
|
EVENT_EXTRA_KEY_CLIENT_ROLE,
|
|
|
|
EVENT_EXTRA_KEY_CLIENT_USERNAME,
|
|
|
|
EVENT_EXTRA_KEY_CLIENT_USERAGENT
|
2022-09-06 08:31:11 -04:00
|
|
|
} event_extra_key_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
event_extra_key_t key;
|
|
|
|
const char *value;
|
|
|
|
} event_extra_entry_t;
|
|
|
|
|
2014-12-07 19:39:57 -05:00
|
|
|
struct event_registration_tag;
|
|
|
|
typedef struct event_registration_tag event_registration_t;
|
|
|
|
|
|
|
|
struct event_tag;
|
|
|
|
typedef struct event_tag event_t;
|
|
|
|
/* this has no lock member to protect multiple accesses as every non-readonly access is within event.c
|
|
|
|
* and is protected by global lock or on the same thread anyway.
|
|
|
|
*/
|
|
|
|
struct event_tag {
|
|
|
|
/* refernece counter */
|
|
|
|
size_t refcount;
|
|
|
|
/* reference to next element in chain */
|
|
|
|
event_t *next;
|
|
|
|
|
|
|
|
/* event_registration lists.
|
|
|
|
* They are referenced here to avoid the need to access
|
|
|
|
* config and global client list each time an event is emitted.
|
|
|
|
*/
|
|
|
|
event_registration_t *reglist[MAX_REGLISTS_PER_EVENT];
|
|
|
|
|
|
|
|
/* trigger name */
|
|
|
|
char *trigger;
|
|
|
|
|
|
|
|
/* from client */
|
|
|
|
unsigned long connection_id; /* from client->con->id */
|
|
|
|
time_t connection_time; /* from client->con->con_time */
|
2018-05-25 07:42:08 -04:00
|
|
|
admin_command_id_t client_admin_command; /* from client->admin_command */
|
2022-09-06 08:31:11 -04:00
|
|
|
/* extra */
|
|
|
|
size_t extra_size;
|
|
|
|
size_t extra_fill;
|
|
|
|
event_extra_entry_t *extra_entries;
|
2014-12-07 19:39:57 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
struct event_registration_tag {
|
|
|
|
/* refernece counter */
|
|
|
|
size_t refcount;
|
|
|
|
/* reference to next element in chain */
|
|
|
|
event_registration_t *next;
|
|
|
|
|
|
|
|
/* protection */
|
|
|
|
mutex_t lock;
|
|
|
|
|
|
|
|
/* type of event */
|
|
|
|
char *type;
|
|
|
|
|
|
|
|
/* trigger name */
|
|
|
|
char *trigger;
|
|
|
|
|
|
|
|
/* backend state */
|
|
|
|
void *state;
|
|
|
|
|
|
|
|
/* emit events */
|
|
|
|
int (*emit)(void *state, event_t *event);
|
|
|
|
|
|
|
|
/* free backend state */
|
|
|
|
void (*free)(void *state);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* subsystem functions */
|
|
|
|
void event_initialise(void);
|
|
|
|
void event_shutdown(void);
|
|
|
|
|
|
|
|
|
|
|
|
/* basic functions to work with event registrations */
|
|
|
|
event_registration_t * event_new_from_xml_node(xmlNodePtr node);
|
|
|
|
|
|
|
|
void event_registration_addref(event_registration_t *er);
|
|
|
|
void event_registration_release(event_registration_t *er);
|
|
|
|
void event_registration_push(event_registration_t **er, event_registration_t *tail);
|
|
|
|
|
|
|
|
/* event signaling */
|
2022-09-16 09:28:18 -04:00
|
|
|
void event_emit_va(const char *trigger, const char *uri, ...);
|
|
|
|
#define event_emit_clientevent(event,client,uri) event_emit_va((event), (uri), EVENT_EXTRA_CLIENT, (client), EVENT_EXTRA_LIST_END)
|
|
|
|
#define event_emit_global(event) event_emit_va((event), EVENT_EXTRA_LIST_END)
|
2014-12-07 19:39:57 -05:00
|
|
|
|
2022-09-06 08:31:11 -04:00
|
|
|
/* reading extra from events */
|
|
|
|
const char * event_extra_get(const event_t *event, const event_extra_key_t key);
|
|
|
|
|
2022-04-15 08:31:19 -04:00
|
|
|
/* Implementations */
|
|
|
|
int event_get_exec(event_registration_t *er, config_options_t *options);
|
|
|
|
int event_get_url(event_registration_t *er, config_options_t *options);
|
|
|
|
int event_get_log(event_registration_t *er, config_options_t *options);
|
|
|
|
|
2014-12-07 19:39:57 -05:00
|
|
|
#endif
|