1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-06-16 06:15:24 +00:00

Feature: Added support for a mountpoint identifier

This commit is contained in:
Philipp Schafft 2020-10-22 20:09:27 +00:00
parent 76f7105e27
commit cf6fad00bd
5 changed files with 111 additions and 0 deletions

View File

@ -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 \

View File

@ -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;

View File

@ -80,6 +80,7 @@
#include "listensocket.h"
#include "fastevent.h"
#include "prng.h"
#include "navigation.h"
#include <libxml/xmlmemory.h>
@ -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();

80
src/navigation.c Normal file
View File

@ -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 <lion@lion.leolix.org>
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#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;
}

21
src/navigation.h Normal file
View File

@ -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 <lion@lion.leolix.org>
*/
#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