diff --git a/src/Makefile.am b/src/Makefile.am index f8168ac0..8bff44c1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -41,6 +41,7 @@ noinst_HEADERS = \ xml2json.h \ listensocket.h \ fastevent.h \ + navigation.h \ event.h \ event_log.h \ event_exec.h \ @@ -92,6 +93,7 @@ icecast_SOURCES = \ xml2json.c \ listensocket.c \ fastevent.c \ + navigation.c \ format.c \ format_ogg.c \ format_mp3.c \ diff --git a/src/icecasttypes.h b/src/icecasttypes.h index f0c643c1..8a4c113b 100644 --- a/src/icecasttypes.h +++ b/src/icecasttypes.h @@ -126,6 +126,10 @@ typedef struct listensocket_tag listensocket_t; typedef struct digest_tag digest_t; +/* ---[ navigation.[ch] ]--- */ + +typedef struct mount_identifier_tag mount_identifier_t; + /* ---[ refobject.[ch] ]--- */ typedef struct refobject_base_tag refobject_base_t; @@ -142,6 +146,7 @@ typedef union __attribute__ ((__transparent_union__)) { listensocket_container_t *listensocket_container; listensocket_t *listensocket; digest_t *digest; + mount_identifier_t *mount_identifier; } refobject_t; #else typedef void * refobject_t; diff --git a/src/main.c b/src/main.c index 10a54a31..aecde897 100644 --- a/src/main.c +++ b/src/main.c @@ -80,6 +80,7 @@ #include "listensocket.h" #include "fastevent.h" #include "prng.h" +#include "navigation.h" #include @@ -146,6 +147,7 @@ static void initialize_subsystems(void) log_initialize(); thread_initialize(); prng_initialize(); + navigation_initialize(); global_initialize(); #ifndef FASTEVENT_ENABLED fastevent_initialize(); @@ -186,6 +188,7 @@ static void shutdown_subsystems(void) refobject_unref(fastevent_reg); fastevent_shutdown(); #endif + navigation_shutdown(); prng_shutdown(); global_shutdown(); thread_shutdown(); diff --git a/src/navigation.c b/src/navigation.c new file mode 100644 index 00000000..7d81db84 --- /dev/null +++ b/src/navigation.c @@ -0,0 +1,80 @@ +/* Icecast + * + * This program is distributed under the GNU General Public License, version 2. + * A copy of this license is included with this source. + * + * Copyright 2020, Philipp "ph3-der-loewe" Schafft + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "common/avl/avl.h" + +#include "navigation.h" + +#include "logging.h" +#define CATMODULE "navigation" + +struct mount_identifier_tag { + /* base object */ + refobject_base_t __base; +}; + +REFOBJECT_DEFINE_TYPE(mount_identifier_t); + +static avl_tree *mount_identifier_list; + +static int mount_identifier_compare(void *compare_arg, void *a, void *b) +{ + const char *id_a, *id_b; + + id_a = refobject_get_name(a); + id_b = refobject_get_name(b); + + if (!id_a || !id_b || id_a == id_b) { + return 0; + } else { + return strcmp(id_a, id_b); + } +} + +void navigation_initialize(void) +{ + mount_identifier_list = avl_tree_new(mount_identifier_compare, NULL); +} + +void navigation_shutdown(void) +{ + avl_tree_free(mount_identifier_list, (avl_free_key_fun_type)refobject_unref); +} + + +mount_identifier_t * mount_identifier_new(const char *mount) +{ + mount_identifier_t *n; + void *result; + + if (!mount) + return NULL; + + n = refobject_new_ext(mount_identifier_t, NULL, mount, NULL); + if (!n) + return NULL; + + avl_tree_wlock(mount_identifier_list); + if (avl_get_by_key(mount_identifier_list, n, &result) == 0) { + refobject_unref(n); + n = result; + refobject_ref(n); + } else { + refobject_ref(n); + avl_insert(mount_identifier_list, n); + } + avl_tree_unlock(mount_identifier_list); + + return n; +} diff --git a/src/navigation.h b/src/navigation.h new file mode 100644 index 00000000..4d468b64 --- /dev/null +++ b/src/navigation.h @@ -0,0 +1,21 @@ +/* Icecast + * + * This program is distributed under the GNU General Public License, version 2. + * A copy of this license is included with this source. + * + * Copyright 2020, Philipp "ph3-der-loewe" Schafft + */ + +#ifndef __NAVIGATION_H__ +#define __NAVIGATION_H__ + +#include "refobject.h" + +REFOBJECT_FORWARD_TYPE(mount_identifier_t); + +void navigation_initialize(void); +void navigation_shutdown(void); + +mount_identifier_t * mount_identifier_new(const char *mount); + +#endif