mirror of
https://gitlab.xiph.org/xiph/icecast-server.git
synced 2024-11-03 04:17:17 -05:00
Update: Migrated from refobject to igloo_ro
This commit is contained in:
parent
0a87e9026b
commit
6c3be854a0
@ -28,7 +28,6 @@ noinst_HEADERS = \
|
||||
md5.h \
|
||||
matchfile.h \
|
||||
tls.h \
|
||||
refobject.h \
|
||||
buffer.h \
|
||||
module.h \
|
||||
reportxml.h \
|
||||
@ -74,7 +73,6 @@ icecast_SOURCES = \
|
||||
md5.c \
|
||||
matchfile.c \
|
||||
tls.c \
|
||||
refobject.c \
|
||||
buffer.c \
|
||||
module.c \
|
||||
reportxml.c \
|
||||
|
26
src/buffer.c
26
src/buffer.c
@ -16,10 +16,10 @@
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "buffer.h"
|
||||
#include "refobject.h"
|
||||
#include <igloo/ro.h>
|
||||
|
||||
struct buffer_tag {
|
||||
refobject_base_t __base;
|
||||
igloo_ro_base_t __base;
|
||||
/* Buffer itself */
|
||||
void *buffer;
|
||||
/* Length in bytes of buffer */
|
||||
@ -30,21 +30,23 @@ struct buffer_tag {
|
||||
size_t offset;
|
||||
};
|
||||
|
||||
static void __free(refobject_t self, void **userdata)
|
||||
static void __free(igloo_ro_t self);
|
||||
|
||||
igloo_RO_PUBLIC_TYPE(buffer_t,
|
||||
igloo_RO_TYPEDECL_FREE(__free),
|
||||
igloo_RO_TYPEDECL_NEW_NOOP()
|
||||
);
|
||||
|
||||
static void __free(igloo_ro_t self)
|
||||
{
|
||||
buffer_t *buffer = REFOBJECT_TO_TYPE(self, buffer_t*);
|
||||
buffer_t *buffer = igloo_RO_TO_TYPE(self, buffer_t);
|
||||
|
||||
free(buffer->buffer);
|
||||
}
|
||||
|
||||
REFOBJECT_DEFINE_TYPE(buffer_t,
|
||||
REFOBJECT_DEFINE_TYPE_FREE(__free),
|
||||
REFOBJECT_DEFINE_TYPE_NEW_NOOP()
|
||||
);
|
||||
|
||||
buffer_t * buffer_new(ssize_t preallocation, void *userdata, const char *name, refobject_t associated)
|
||||
buffer_t * buffer_new(ssize_t preallocation, const char *name, igloo_ro_t associated)
|
||||
{
|
||||
buffer_t *buffer = refobject_new_ext(buffer_t, userdata, name, associated);
|
||||
buffer_t *buffer = igloo_ro_new_ext(buffer_t, name, associated);
|
||||
|
||||
if (!buffer)
|
||||
return NULL;
|
||||
@ -57,7 +59,7 @@ buffer_t * buffer_new(ssize_t preallocation, void *userdata, const char *name,
|
||||
|
||||
buffer_t * buffer_new_simple(void)
|
||||
{
|
||||
return refobject_new(buffer_t);
|
||||
return igloo_ro_new(buffer_t);
|
||||
}
|
||||
|
||||
void buffer_preallocate(buffer_t *buffer, size_t request)
|
||||
|
@ -22,13 +22,13 @@
|
||||
|
||||
#include "icecasttypes.h"
|
||||
#include "compat.h"
|
||||
#include "refobject.h"
|
||||
#include <igloo/ro.h>
|
||||
|
||||
/* About thread safety:
|
||||
* This set of functions is intentinally not thread safe.
|
||||
*/
|
||||
|
||||
REFOBJECT_FORWARD_TYPE(buffer_t);
|
||||
igloo_RO_FORWARD_TYPE(buffer_t);
|
||||
|
||||
/* This creates a new buffer object.
|
||||
* Parameters:
|
||||
@ -37,7 +37,7 @@ REFOBJECT_FORWARD_TYPE(buffer_t);
|
||||
* userdata, name, associated
|
||||
* See refobject_new().
|
||||
*/
|
||||
buffer_t * buffer_new(ssize_t preallocation, void *userdata, const char *name, refobject_t associated);
|
||||
buffer_t * buffer_new(ssize_t preallocation, const char *name, igloo_ro_t associated);
|
||||
|
||||
/* Depreciated: This creates a new buffer with defaults.
|
||||
* Do NOT use this. Use refobject_new(buffer_t)
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include "util.h"
|
||||
#include "auth.h"
|
||||
#include "event.h"
|
||||
#include "refobject.h"
|
||||
#include <igloo/ro.h>
|
||||
#include "reportxml.h"
|
||||
|
||||
/* for config_reread_config() */
|
||||
@ -258,7 +258,7 @@ void config_init_configuration(ice_config_t *configuration)
|
||||
{
|
||||
memset(configuration, 0, sizeof(ice_config_t));
|
||||
_set_defaults(configuration);
|
||||
configuration->reportxml_db = refobject_new(reportxml_database_t);
|
||||
configuration->reportxml_db = igloo_ro_new(reportxml_database_t);
|
||||
}
|
||||
|
||||
static inline void __read_int(xmlDocPtr doc, xmlNodePtr node, int *val, const char *warning)
|
||||
@ -723,7 +723,7 @@ void config_clear(ice_config_t *c)
|
||||
|
||||
config_clear_http_header(c->http_headers);
|
||||
|
||||
refobject_unref(c->reportxml_db);
|
||||
igloo_ro_unref(c->reportxml_db);
|
||||
|
||||
memset(c, 0, sizeof(ice_config_t));
|
||||
}
|
||||
@ -2265,7 +2265,7 @@ static void _parse_paths(xmlDocPtr doc,
|
||||
ICECAST_LOG_ERROR("Can not parse report xml database \"%H\"", temp);
|
||||
} else {
|
||||
reportxml_database_add_report(configuration->reportxml_db, report);
|
||||
refobject_unref(report);
|
||||
igloo_ro_unref(report);
|
||||
ICECAST_LOG_INFO("File \"%H\" added to report xml database", temp);
|
||||
}
|
||||
}
|
||||
|
22
src/client.c
22
src/client.c
@ -31,7 +31,7 @@
|
||||
#include <igloo/httpp.h>
|
||||
|
||||
#include "global.h"
|
||||
#include "refobject.h"
|
||||
#include <igloo/ro.h>
|
||||
#include "cfgfile.h"
|
||||
#include "connection.h"
|
||||
#include "tls.h"
|
||||
@ -41,7 +41,7 @@
|
||||
#include "fserve.h"
|
||||
#include "errors.h"
|
||||
#include "reportxml.h"
|
||||
#include "refobject.h"
|
||||
#include <igloo/ro.h>
|
||||
#include "xslt.h"
|
||||
#include "source.h"
|
||||
|
||||
@ -266,7 +266,7 @@ void client_destroy(client_t *client)
|
||||
if (client->free_client_data)
|
||||
client->free_client_data(client);
|
||||
|
||||
refobject_unref(client->handler_module);
|
||||
igloo_ro_unref(client->handler_module);
|
||||
free(client->handler_function);
|
||||
free(client->uri);
|
||||
free(client->username);
|
||||
@ -344,7 +344,7 @@ static inline void _client_send_report(client_t *client, const char *uuid, const
|
||||
|
||||
client_send_reportxml(client, report, DOCUMENT_DOMAIN_ADMIN, xslt, admin_format, http_status, location);
|
||||
|
||||
refobject_unref(report);
|
||||
igloo_ro_unref(report);
|
||||
}
|
||||
|
||||
void client_send_error_by_error(client_t *client, const icecast_error_t *error)
|
||||
@ -660,7 +660,7 @@ static void client_get_reportxml__add_basic_stats(reportxml_t *report)
|
||||
|
||||
reportxml_node_add_child(rootnode, extension);
|
||||
|
||||
refobject_unref(rootnode);
|
||||
igloo_ro_unref(rootnode);
|
||||
|
||||
xmlroot = xmlNewNode(NULL, XMLSTR("icestats"));
|
||||
modules = module_container_get_modulelist_as_xml(global.modulecontainer);
|
||||
@ -668,7 +668,7 @@ static void client_get_reportxml__add_basic_stats(reportxml_t *report)
|
||||
|
||||
|
||||
reportxml_node_add_xml_child(extension, xmlroot);
|
||||
refobject_unref(extension);
|
||||
igloo_ro_unref(extension);
|
||||
xmlFreeNode(xmlroot);
|
||||
}
|
||||
|
||||
@ -687,7 +687,7 @@ reportxml_t *client_get_reportxml(const char *state_definition, const char *stat
|
||||
if (!report) {
|
||||
reportxml_node_t *rootnode, *incidentnode, *statenode;
|
||||
|
||||
report = refobject_new(reportxml_t);
|
||||
report = igloo_ro_new(reportxml_t);
|
||||
rootnode = reportxml_get_root_node(report);
|
||||
incidentnode = reportxml_node_new(REPORTXML_NODE_TYPE_INCIDENT, NULL, NULL, NULL);
|
||||
statenode = reportxml_node_new(REPORTXML_NODE_TYPE_STATE, NULL, state_definition, state_akindof);
|
||||
@ -698,14 +698,14 @@ reportxml_t *client_get_reportxml(const char *state_definition, const char *stat
|
||||
textnode = reportxml_node_new(REPORTXML_NODE_TYPE_TEXT, NULL, NULL, NULL);
|
||||
reportxml_node_set_content(textnode, state_text);
|
||||
reportxml_node_add_child(statenode, textnode);
|
||||
refobject_unref(textnode);
|
||||
igloo_ro_unref(textnode);
|
||||
}
|
||||
|
||||
reportxml_node_add_child(incidentnode, statenode);
|
||||
reportxml_node_add_child(rootnode, incidentnode);
|
||||
refobject_unref(statenode);
|
||||
refobject_unref(incidentnode);
|
||||
refobject_unref(rootnode);
|
||||
igloo_ro_unref(statenode);
|
||||
igloo_ro_unref(incidentnode);
|
||||
igloo_ro_unref(rootnode);
|
||||
}
|
||||
|
||||
client_get_reportxml__add_basic_stats(report);
|
||||
|
@ -43,7 +43,7 @@
|
||||
#include "cfgfile.h"
|
||||
#include "global.h"
|
||||
#include "util.h"
|
||||
#include "refobject.h"
|
||||
#include <igloo/ro.h>
|
||||
#include "refbuf.h"
|
||||
#include "client.h"
|
||||
#include "errors.h"
|
||||
@ -58,7 +58,7 @@
|
||||
#include "matchfile.h"
|
||||
#include "tls.h"
|
||||
#include "acl.h"
|
||||
#include "refobject.h"
|
||||
#include <igloo/ro.h>
|
||||
#include "listensocket.h"
|
||||
#include "fastevent.h"
|
||||
|
||||
@ -261,8 +261,8 @@ connection_t *connection_create(igloo_sock_t sock, listensocket_t *listensocket_
|
||||
|
||||
con = (connection_t *)calloc(1, sizeof(connection_t));
|
||||
if (con) {
|
||||
refobject_ref(listensocket_real);
|
||||
refobject_ref(listensocket_effective);
|
||||
igloo_ro_ref(listensocket_real);
|
||||
igloo_ro_ref(listensocket_effective);
|
||||
|
||||
con->sock = sock;
|
||||
con->listensocket_real = listensocket_real;
|
||||
@ -1242,7 +1242,7 @@ static int _handle_resources(client_t *client, char **uri)
|
||||
module_t *module = module_container_get_module(global.modulecontainer, resource->module);
|
||||
|
||||
if (module != NULL) {
|
||||
refobject_unref(client->handler_module);
|
||||
igloo_ro_unref(client->handler_module);
|
||||
client->handler_module = module;
|
||||
} else {
|
||||
ICECAST_LOG_ERROR("Module used in alias not found: %s", resource->module);
|
||||
@ -1701,7 +1701,7 @@ static void __on_sock_count(size_t count, void *userdata)
|
||||
void connection_setup_sockets (ice_config_t *config)
|
||||
{
|
||||
global_lock();
|
||||
refobject_unref(global.listensockets);
|
||||
igloo_ro_unref(global.listensockets);
|
||||
|
||||
if (config == NULL) {
|
||||
global_unlock();
|
||||
@ -1721,7 +1721,7 @@ void connection_setup_sockets (ice_config_t *config)
|
||||
allowed_ip = matchfile_new(config->allowfile);
|
||||
}
|
||||
|
||||
global.listensockets = refobject_new(listensocket_container_t);
|
||||
global.listensockets = igloo_ro_new(listensocket_container_t);
|
||||
listensocket_container_configure(global.listensockets, config);
|
||||
|
||||
global_unlock();
|
||||
@ -1745,8 +1745,8 @@ void connection_close(connection_t *con)
|
||||
free(con->ip);
|
||||
if (con->readbuffer)
|
||||
free(con->readbuffer);
|
||||
refobject_unref(con->listensocket_real);
|
||||
refobject_unref(con->listensocket_effective);
|
||||
igloo_ro_unref(con->listensocket_real);
|
||||
igloo_ro_unref(con->listensocket_effective);
|
||||
free(con);
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,10 @@
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <igloo/typedef.h>
|
||||
typedef struct fastevent_registration_tag fastevent_registration_t;
|
||||
#define igloo_RO_PRIVATETYPES igloo_RO_TYPE(fastevent_registration_t)
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -26,14 +30,19 @@
|
||||
|
||||
#ifdef FASTEVENT_ENABLED
|
||||
|
||||
typedef struct {
|
||||
refobject_base_t __base;
|
||||
struct fastevent_registration_tag {
|
||||
igloo_ro_base_t __base;
|
||||
|
||||
fastevent_type_t type;
|
||||
fastevent_cb_t cb;
|
||||
fastevent_freecb_t freecb;
|
||||
void *userdata;
|
||||
} fastevent_registration_t;
|
||||
};
|
||||
|
||||
static void __unregister(igloo_ro_t self);
|
||||
igloo_RO_PRIVATE_TYPE(fastevent_registration_t,
|
||||
igloo_RO_TYPEDECL_FREE(__unregister)
|
||||
);
|
||||
|
||||
struct eventrow {
|
||||
size_t length;
|
||||
@ -96,13 +105,11 @@ static int __remove_from_row(struct eventrow * row, fastevent_registration_t *re
|
||||
}
|
||||
|
||||
|
||||
static void __unregister(refobject_t self, void **userdata)
|
||||
static void __unregister(igloo_ro_t self)
|
||||
{
|
||||
fastevent_registration_t *registration = REFOBJECT_TO_TYPE(self, fastevent_registration_t *);
|
||||
fastevent_registration_t *registration = igloo_RO_TO_TYPE(self, fastevent_registration_t);
|
||||
struct eventrow * row;
|
||||
|
||||
(void)userdata;
|
||||
|
||||
igloo_thread_rwlock_wlock(&fastevent_lock);
|
||||
row = __get_row(registration->type);
|
||||
if (__remove_from_row(row, registration) != 0) {
|
||||
@ -143,31 +150,28 @@ int fastevent_shutdown(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
REFOBJECT_DEFINE_PRIVATE_TYPE(fastevent_registration_t,
|
||||
REFOBJECT_DEFINE_TYPE_FREE(__unregister)
|
||||
);
|
||||
|
||||
refobject_t fastevent_register(fastevent_type_t type, fastevent_cb_t cb, fastevent_freecb_t freecb, void *userdata)
|
||||
igloo_ro_t fastevent_register(fastevent_type_t type, fastevent_cb_t cb, fastevent_freecb_t freecb, void *userdata)
|
||||
{
|
||||
struct eventrow * row;
|
||||
fastevent_registration_t *registration;
|
||||
|
||||
if (cb == NULL)
|
||||
return REFOBJECT_NULL;
|
||||
return igloo_RO_NULL;
|
||||
|
||||
igloo_thread_rwlock_wlock(&fastevent_lock);
|
||||
row = __get_row(type);
|
||||
|
||||
if (row == NULL) {
|
||||
igloo_thread_rwlock_unlock(&fastevent_lock);
|
||||
return REFOBJECT_NULL;
|
||||
return igloo_RO_NULL;
|
||||
}
|
||||
|
||||
registration = refobject_new__new(fastevent_registration_t, NULL, NULL, NULL);
|
||||
registration = igloo_ro_new_raw(fastevent_registration_t, NULL, igloo_RO_NULL);
|
||||
|
||||
if (!registration) {
|
||||
igloo_thread_rwlock_unlock(&fastevent_lock);
|
||||
return REFOBJECT_NULL;
|
||||
return igloo_RO_NULL;
|
||||
}
|
||||
|
||||
registration->type = type;
|
||||
@ -177,12 +181,12 @@ refobject_t fastevent_register(fastevent_type_t type, fastevent_cb_t cb, fasteve
|
||||
|
||||
if (__add_to_row(row, registration) != 0) {
|
||||
igloo_thread_rwlock_unlock(&fastevent_lock);
|
||||
refobject_unref(REFOBJECT_FROM_TYPE(registration));
|
||||
return REFOBJECT_NULL;
|
||||
igloo_ro_unref(registration);
|
||||
return igloo_RO_NULL;
|
||||
}
|
||||
|
||||
igloo_thread_rwlock_unlock(&fastevent_lock);
|
||||
return REFOBJECT_FROM_TYPE(registration);
|
||||
return (igloo_ro_t)registration;
|
||||
}
|
||||
|
||||
void fastevent_emit(fastevent_type_t type, fastevent_flag_t flags, fastevent_datatype_t datatype, ...)
|
||||
|
@ -15,7 +15,7 @@
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "refobject.h"
|
||||
#include <igloo/ro.h>
|
||||
|
||||
typedef enum {
|
||||
FASTEVENT_TYPE_SLOWEVENT = 0,
|
||||
@ -54,7 +54,7 @@ typedef void (*fastevent_freecb_t)(void **userdata);
|
||||
#ifdef FASTEVENT_ENABLED
|
||||
int fastevent_initialize(void);
|
||||
int fastevent_shutdown(void);
|
||||
refobject_t fastevent_register(fastevent_type_t type, fastevent_cb_t cb, fastevent_freecb_t freecb, void *userdata);
|
||||
igloo_ro_t fastevent_register(fastevent_type_t type, fastevent_cb_t cb, fastevent_freecb_t freecb, void *userdata);
|
||||
void fastevent_emit(fastevent_type_t type, fastevent_flag_t flags, fastevent_datatype_t datatype, ...);
|
||||
#else
|
||||
#define fastevent_initialize() 0
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include <igloo/avl.h>
|
||||
|
||||
#include "global.h"
|
||||
#include "refobject.h"
|
||||
#include <igloo/ro.h>
|
||||
#include "module.h"
|
||||
#include "source.h"
|
||||
|
||||
@ -39,14 +39,14 @@ void global_initialize(void)
|
||||
global.clients = 0;
|
||||
global.sources = 0;
|
||||
global.source_tree = igloo_avl_tree_new(source_compare_sources, NULL);
|
||||
global.modulecontainer = refobject_new(module_container_t);
|
||||
global.modulecontainer = igloo_ro_new(module_container_t);
|
||||
igloo_thread_mutex_create(&_global_mutex);
|
||||
}
|
||||
|
||||
void global_shutdown(void)
|
||||
{
|
||||
igloo_thread_mutex_destroy(&_global_mutex);
|
||||
refobject_unref(global.modulecontainer);
|
||||
igloo_ro_unref(global.modulecontainer);
|
||||
igloo_avl_tree_free(global.source_tree, NULL);
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
#include <igloo/typedef.h>
|
||||
|
||||
/* ---[ client.[ch] ]--- */
|
||||
|
||||
typedef struct _client_tag client_t;
|
||||
@ -116,22 +118,14 @@ typedef struct listensocket_tag listensocket_t;
|
||||
|
||||
/* ---[ refobject.[ch] ]--- */
|
||||
|
||||
typedef struct refobject_base_tag refobject_base_t;
|
||||
|
||||
#ifdef HAVE_TYPE_ATTRIBUTE_TRANSPARENT_UNION
|
||||
typedef union __attribute__ ((__transparent_union__)) {
|
||||
refobject_base_t *refobject_base;
|
||||
buffer_t *buffer;
|
||||
module_t *module;
|
||||
module_container_t *module_container;
|
||||
reportxml_t *reportxml;
|
||||
reportxml_node_t *reportxml_node;
|
||||
reportxml_database_t *reportxml_database;
|
||||
listensocket_container_t *listensocket_container;
|
||||
listensocket_t *listensocket;
|
||||
} refobject_t;
|
||||
#else
|
||||
typedef void * refobject_t;
|
||||
#endif
|
||||
#define igloo_RO_APPTYPES \
|
||||
igloo_RO_TYPE(buffer_t) \
|
||||
igloo_RO_TYPE(module_t) \
|
||||
igloo_RO_TYPE(module_container_t) \
|
||||
igloo_RO_TYPE(reportxml_t) \
|
||||
igloo_RO_TYPE(reportxml_node_t) \
|
||||
igloo_RO_TYPE(reportxml_database_t) \
|
||||
igloo_RO_TYPE(listensocket_container_t) \
|
||||
igloo_RO_TYPE(listensocket_t)
|
||||
|
||||
#endif
|
||||
|
@ -22,20 +22,22 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "icecasttypes.h"
|
||||
|
||||
#include <igloo/sock.h>
|
||||
#include <igloo/thread.h>
|
||||
|
||||
#include "listensocket.h"
|
||||
#include "global.h"
|
||||
#include "connection.h"
|
||||
#include "refobject.h"
|
||||
#include <igloo/ro.h>
|
||||
|
||||
#include "logging.h"
|
||||
#define CATMODULE "listensocket"
|
||||
|
||||
|
||||
struct listensocket_container_tag {
|
||||
refobject_base_t __base;
|
||||
igloo_ro_base_t __base;
|
||||
igloo_mutex_t lock;
|
||||
listensocket_t **sock;
|
||||
int *sockref;
|
||||
@ -44,7 +46,7 @@ struct listensocket_container_tag {
|
||||
void *sockcount_userdata;
|
||||
};
|
||||
struct listensocket_tag {
|
||||
refobject_base_t __base;
|
||||
igloo_ro_base_t __base;
|
||||
size_t sockrefc;
|
||||
igloo_mutex_t lock;
|
||||
igloo_rwlock_t listener_rwlock;
|
||||
@ -53,6 +55,17 @@ struct listensocket_tag {
|
||||
igloo_sock_t sock;
|
||||
};
|
||||
|
||||
static void __listensocket_container_free(igloo_ro_t self);
|
||||
int __listensocket_container_new(igloo_ro_t self, const igloo_ro_type_t *type, va_list ap);
|
||||
igloo_RO_PUBLIC_TYPE(listensocket_container_t,
|
||||
igloo_RO_TYPEDECL_FREE(__listensocket_container_free),
|
||||
igloo_RO_TYPEDECL_NEW(__listensocket_container_new)
|
||||
);
|
||||
static void __listensocket_free(igloo_ro_t self);
|
||||
igloo_RO_PUBLIC_TYPE(listensocket_t,
|
||||
igloo_RO_TYPEDECL_FREE(__listensocket_free)
|
||||
);
|
||||
|
||||
static listensocket_t * listensocket_container_get_by_id(listensocket_container_t *self, const char *id);
|
||||
static int listensocket_container_configure__unlocked(listensocket_container_t *self, const ice_config_t *config);
|
||||
static int listensocket_container_setup__unlocked(listensocket_container_t *self);
|
||||
@ -126,7 +139,7 @@ static void __listensocket_container_clear_sockets(listensocket_container_t *sel
|
||||
if (self->sockref[i]) {
|
||||
listensocket_unrefsock(self->sock[i]);
|
||||
}
|
||||
refobject_unref(self->sock[i]);
|
||||
igloo_ro_unref(self->sock[i]);
|
||||
self->sock[i] = NULL;
|
||||
}
|
||||
}
|
||||
@ -141,18 +154,18 @@ static void __listensocket_container_clear_sockets(listensocket_container_t *sel
|
||||
}
|
||||
|
||||
|
||||
static void __listensocket_container_free(refobject_t self, void **userdata)
|
||||
static void __listensocket_container_free(igloo_ro_t self)
|
||||
{
|
||||
listensocket_container_t *container = REFOBJECT_TO_TYPE(self, listensocket_container_t *);
|
||||
listensocket_container_t *container = igloo_RO_TO_TYPE(self, listensocket_container_t);
|
||||
igloo_thread_mutex_lock(&container->lock);
|
||||
__listensocket_container_clear_sockets(container);
|
||||
igloo_thread_mutex_unlock(&container->lock);
|
||||
igloo_thread_mutex_destroy(&container->lock);
|
||||
}
|
||||
|
||||
int __listensocket_container_new(refobject_t self, const refobject_type_t *type, va_list ap)
|
||||
int __listensocket_container_new(igloo_ro_t self, const igloo_ro_type_t *type, va_list ap)
|
||||
{
|
||||
listensocket_container_t *ret = REFOBJECT_TO_TYPE(self, listensocket_container_t*);
|
||||
listensocket_container_t *ret = igloo_RO_TO_TYPE(self, listensocket_container_t);
|
||||
|
||||
ret->sock = NULL;
|
||||
ret->sock_len = 0;
|
||||
@ -164,11 +177,6 @@ int __listensocket_container_new(refobject_t self, const refobject_type_t *type,
|
||||
return 0;
|
||||
}
|
||||
|
||||
REFOBJECT_DEFINE_TYPE(listensocket_container_t,
|
||||
REFOBJECT_DEFINE_TYPE_FREE(__listensocket_container_free),
|
||||
REFOBJECT_DEFINE_TYPE_NEW(__listensocket_container_new)
|
||||
);
|
||||
|
||||
static inline void __find_matching_entry(listensocket_container_t *self, const listener_t *listener, listensocket_t ***found, int **ref)
|
||||
{
|
||||
const listener_t *b;
|
||||
@ -251,7 +259,7 @@ static int listensocket_container_configure__unlocked(listensocket_container_t *
|
||||
}
|
||||
if (n[i] == NULL) {
|
||||
for (; i; i--) {
|
||||
refobject_unref(n[i - 1]);
|
||||
igloo_ro_unref(n[i - 1]);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@ -434,11 +442,11 @@ connection_t * listensocket_container_accept(listensocket_container
|
||||
|
||||
igloo_thread_mutex_lock(&self->lock);
|
||||
ls = listensocket_container_accept__inner(self, timeout);
|
||||
refobject_ref(ls);
|
||||
igloo_ro_ref(ls);
|
||||
igloo_thread_mutex_unlock(&self->lock);
|
||||
|
||||
ret = listensocket_accept(ls, self);
|
||||
refobject_unref(ls);
|
||||
igloo_ro_unref(ls);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -495,7 +503,7 @@ static listensocket_t * listensocket_container_get_by_id(listensocket_container_
|
||||
if (listener) {
|
||||
if (listener->id != NULL && strcmp(listener->id, id) == 0) {
|
||||
listensocket_release_listener(self->sock[i]);
|
||||
if (refobject_ref(self->sock[i]) == 0) {
|
||||
if (igloo_ro_ref(self->sock[i]) == 0) {
|
||||
return self->sock[i];
|
||||
}
|
||||
}
|
||||
@ -509,9 +517,9 @@ static listensocket_t * listensocket_container_get_by_id(listensocket_container_
|
||||
|
||||
/* ---------------------------------------------------------------------------- */
|
||||
|
||||
static void __listensocket_free(refobject_t self, void **userdata)
|
||||
static void __listensocket_free(igloo_ro_t self)
|
||||
{
|
||||
listensocket_t *listensocket = REFOBJECT_TO_TYPE(self, listensocket_t *);
|
||||
listensocket_t *listensocket = igloo_RO_TO_TYPE(self, listensocket_t);
|
||||
|
||||
igloo_thread_mutex_lock(&listensocket->lock);
|
||||
|
||||
@ -530,17 +538,13 @@ static void __listensocket_free(refobject_t self, void **userdata)
|
||||
igloo_thread_mutex_destroy(&listensocket->lock);
|
||||
}
|
||||
|
||||
REFOBJECT_DEFINE_TYPE(listensocket_t,
|
||||
REFOBJECT_DEFINE_TYPE_FREE(__listensocket_free)
|
||||
);
|
||||
|
||||
static listensocket_t * listensocket_new(const listener_t *listener) {
|
||||
listensocket_t *self;
|
||||
|
||||
if (listener == NULL)
|
||||
return NULL;
|
||||
|
||||
self = refobject_new__new(listensocket_t, NULL, NULL, NULL);
|
||||
self = igloo_ro_new_raw(listensocket_t, NULL, igloo_RO_NULL);
|
||||
if (!self)
|
||||
return NULL;
|
||||
|
||||
@ -551,7 +555,7 @@ static listensocket_t * listensocket_new(const listener_t *listener) {
|
||||
|
||||
self->listener = config_copy_listener_one(listener);
|
||||
if (self->listener == NULL) {
|
||||
refobject_unref(self);
|
||||
igloo_ro_unref(self);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -738,12 +742,12 @@ connection_t * listensocket_accept(listensocket_t *self, listensock
|
||||
|
||||
if (!effective) {
|
||||
effective = self;
|
||||
refobject_ref(effective);
|
||||
igloo_ro_ref(effective);
|
||||
}
|
||||
|
||||
con = connection_create(sock, self, effective, ip);
|
||||
|
||||
refobject_unref(effective);
|
||||
igloo_ro_unref(effective);
|
||||
|
||||
if (con == NULL) {
|
||||
igloo_sock_close(sock);
|
||||
|
@ -10,10 +10,10 @@
|
||||
#define __LISTENSOCKET_H__
|
||||
|
||||
#include "icecasttypes.h"
|
||||
#include "refobject.h"
|
||||
#include <igloo/ro.h>
|
||||
#include "cfgfile.h"
|
||||
|
||||
REFOBJECT_FORWARD_TYPE(listensocket_container_t);
|
||||
igloo_RO_FORWARD_TYPE(listensocket_container_t);
|
||||
|
||||
listensocket_container_t * listensocket_container_new(void);
|
||||
int listensocket_container_configure(listensocket_container_t *self, const ice_config_t *config);
|
||||
@ -23,7 +23,7 @@ connection_t * listensocket_container_accept(listensocket_container
|
||||
int listensocket_container_set_sockcount_cb(listensocket_container_t *self, void (*cb)(size_t count, void *userdata), void *userdata);
|
||||
ssize_t listensocket_container_sockcount(listensocket_container_t *self);
|
||||
|
||||
REFOBJECT_FORWARD_TYPE(listensocket_t);
|
||||
igloo_RO_FORWARD_TYPE(listensocket_t);
|
||||
|
||||
int listensocket_refsock(listensocket_t *self);
|
||||
int listensocket_unrefsock(listensocket_t *self);
|
||||
|
@ -141,7 +141,7 @@ static void __fastevent_cb(const void *userdata, fastevent_type_t type, fasteven
|
||||
}
|
||||
}
|
||||
|
||||
static refobject_t fastevent_reg;
|
||||
static igloo_ro_t fastevent_reg;
|
||||
#endif
|
||||
|
||||
static void initialize_subsystems(void)
|
||||
@ -179,7 +179,7 @@ static void shutdown_subsystems(void)
|
||||
tls_shutdown();
|
||||
config_shutdown();
|
||||
#ifndef FASTEVENT_ENABLED
|
||||
refobject_unref(fastevent_reg);
|
||||
igloo_ro_unref(fastevent_reg);
|
||||
fastevent_shutdown();
|
||||
#endif
|
||||
global_shutdown();
|
||||
|
67
src/module.c
67
src/module.c
@ -13,15 +13,17 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "icecasttypes.h"
|
||||
|
||||
#include <igloo/thread.h>
|
||||
#include <igloo/avl.h>
|
||||
|
||||
#include "refobject.h"
|
||||
#include <igloo/ro.h>
|
||||
#include "module.h"
|
||||
#include "cfgfile.h" /* for XMLSTR() */
|
||||
|
||||
struct module_tag {
|
||||
refobject_base_t __base;
|
||||
igloo_ro_base_t __base;
|
||||
igloo_mutex_t lock;
|
||||
const module_client_handler_t *client_handlers;
|
||||
size_t client_handlers_len;
|
||||
@ -33,26 +35,38 @@ struct module_tag {
|
||||
|
||||
|
||||
struct module_container_tag {
|
||||
refobject_base_t __base;
|
||||
igloo_ro_base_t __base;
|
||||
igloo_mutex_t lock;
|
||||
igloo_avl_tree *module;
|
||||
};
|
||||
|
||||
static void __module_container_free(igloo_ro_t self);
|
||||
int __module_container_new(igloo_ro_t self, const igloo_ro_type_t *type, va_list ap);
|
||||
igloo_RO_PUBLIC_TYPE(module_container_t,
|
||||
igloo_RO_TYPEDECL_FREE(__module_container_free),
|
||||
igloo_RO_TYPEDECL_NEW(__module_container_new)
|
||||
);
|
||||
|
||||
static void __module_free(igloo_ro_t self);
|
||||
igloo_RO_PUBLIC_TYPE(module_t,
|
||||
igloo_RO_TYPEDECL_FREE(__module_free)
|
||||
);
|
||||
|
||||
static int compare_refobject_t_name(void *arg, void *a, void *b)
|
||||
{
|
||||
return strcmp(refobject_get_name(a), refobject_get_name(b));
|
||||
return strcmp(igloo_ro_get_name(a), igloo_ro_get_name(b));
|
||||
}
|
||||
|
||||
static void __module_container_free(refobject_t self, void **userdata)
|
||||
static void __module_container_free(igloo_ro_t self)
|
||||
{
|
||||
module_container_t *cont = REFOBJECT_TO_TYPE(self, module_container_t *);
|
||||
module_container_t *cont = igloo_RO_TO_TYPE(self, module_container_t);
|
||||
igloo_thread_mutex_destroy(&(cont->lock));
|
||||
igloo_avl_tree_free(cont->module, (igloo_avl_free_key_fun_type)refobject_unref);
|
||||
igloo_avl_tree_free(cont->module, (igloo_avl_free_key_fun_type)igloo_ro_unref);
|
||||
}
|
||||
|
||||
int __module_container_new(refobject_t self, const refobject_type_t *type, va_list ap)
|
||||
int __module_container_new(igloo_ro_t self, const igloo_ro_type_t *type, va_list ap)
|
||||
{
|
||||
module_container_t *ret = REFOBJECT_TO_TYPE(self, module_container_t*);
|
||||
module_container_t *ret = igloo_RO_TO_TYPE(self, module_container_t);
|
||||
|
||||
igloo_thread_mutex_create(&(ret->lock));
|
||||
|
||||
@ -61,17 +75,12 @@ int __module_container_new(refobject_t self, const refobject_type_t *type, va_li
|
||||
return 0;
|
||||
}
|
||||
|
||||
REFOBJECT_DEFINE_TYPE(module_container_t,
|
||||
REFOBJECT_DEFINE_TYPE_FREE(__module_container_free),
|
||||
REFOBJECT_DEFINE_TYPE_NEW(__module_container_new)
|
||||
);
|
||||
|
||||
int module_container_add_module(module_container_t *self, module_t *module)
|
||||
{
|
||||
if (!self)
|
||||
return -1;
|
||||
|
||||
if (refobject_ref(module) != 0)
|
||||
if (igloo_ro_ref(module) != 0)
|
||||
return -1;
|
||||
|
||||
igloo_thread_mutex_lock(&(self->lock));
|
||||
@ -93,32 +102,32 @@ int module_container_delete_module(module_container_t *self,
|
||||
return -1;
|
||||
|
||||
igloo_thread_mutex_lock(&(self->lock));
|
||||
igloo_avl_delete(self->module, module, (igloo_avl_free_key_fun_type)refobject_unref);
|
||||
igloo_avl_delete(self->module, module, (igloo_avl_free_key_fun_type)igloo_ro_unref);
|
||||
igloo_thread_mutex_unlock(&(self->lock));
|
||||
|
||||
refobject_unref(module);
|
||||
igloo_ro_unref(module);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
module_t * module_container_get_module(module_container_t *self, const char *name)
|
||||
{
|
||||
refobject_base_t *search;
|
||||
igloo_ro_base_t *search;
|
||||
module_t *ret;
|
||||
|
||||
if (!self || !name)
|
||||
return NULL;
|
||||
|
||||
search = refobject_new__new(refobject_base_t, NULL, name, NULL);
|
||||
search = igloo_ro_new_ext(igloo_ro_base_t, name, igloo_RO_NULL);
|
||||
|
||||
igloo_thread_mutex_lock(&(self->lock));
|
||||
if (igloo_avl_get_by_key(self->module, REFOBJECT_TO_TYPE(search, void *), (void**)&ret) != 0) {
|
||||
if (igloo_avl_get_by_key(self->module, (void*)igloo_RO_TO_TYPE(search, igloo_ro_base_t), (void**)&ret) != 0) {
|
||||
ret = NULL;
|
||||
}
|
||||
igloo_thread_mutex_unlock(&(self->lock));
|
||||
|
||||
refobject_unref(search);
|
||||
refobject_ref(ret);
|
||||
igloo_ro_unref(search);
|
||||
igloo_ro_ref(ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -141,7 +150,7 @@ xmlNodePtr module_container_get_modulelist_as_xml(module_co
|
||||
module_t *module = avlnode->key;
|
||||
xmlNodePtr node = xmlNewChild(root, NULL, XMLSTR("module"), NULL);
|
||||
|
||||
xmlSetProp(node, XMLSTR("name"), XMLSTR(refobject_get_name(module)));
|
||||
xmlSetProp(node, XMLSTR("name"), XMLSTR(igloo_ro_get_name(module)));
|
||||
if (module->management_link_url)
|
||||
xmlSetProp(node, XMLSTR("management-url"), XMLSTR(module->management_link_url));
|
||||
if (module->management_link_title)
|
||||
@ -154,9 +163,9 @@ xmlNodePtr module_container_get_modulelist_as_xml(module_co
|
||||
return root;
|
||||
}
|
||||
|
||||
static void __module_free(refobject_t self, void **userdata)
|
||||
static void __module_free(igloo_ro_t self)
|
||||
{
|
||||
module_t *mod = REFOBJECT_TO_TYPE(self, module_t *);
|
||||
module_t *mod = igloo_RO_TO_TYPE(self, module_t);
|
||||
|
||||
if (mod->freecb)
|
||||
mod->freecb(mod, &(mod->userdata));
|
||||
@ -170,13 +179,9 @@ static void __module_free(refobject_t self, void **userdata)
|
||||
igloo_thread_mutex_destroy(&(mod->lock));
|
||||
}
|
||||
|
||||
REFOBJECT_DEFINE_TYPE(module_t,
|
||||
REFOBJECT_DEFINE_TYPE_FREE(__module_free)
|
||||
);
|
||||
|
||||
module_t * module_new(const char *name, module_setup_handler_t newcb, module_setup_handler_t freecb, void *userdata)
|
||||
{
|
||||
module_t *ret = refobject_new__new(module_t, NULL, name, NULL);
|
||||
module_t *ret = igloo_ro_new_raw(module_t, name, igloo_RO_NULL);
|
||||
|
||||
if (!ret)
|
||||
return NULL;
|
||||
@ -188,7 +193,7 @@ module_t * module_new(const char *name, module_setup_handler_t newc
|
||||
|
||||
if (newcb) {
|
||||
if (newcb(ret, &(ret->userdata)) != 0) {
|
||||
refobject_unref(ret);
|
||||
igloo_ro_unref(ret);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include <libxml/tree.h>
|
||||
|
||||
#include "icecasttypes.h"
|
||||
#include "refobject.h"
|
||||
#include <igloo/ro.h>
|
||||
|
||||
typedef void (*module_client_handler_function_t)(module_t *self, client_t *client);
|
||||
typedef int (*module_setup_handler_t)(module_t *self, void **userdata);
|
||||
@ -22,8 +22,8 @@ typedef struct {
|
||||
module_client_handler_function_t cb;
|
||||
} module_client_handler_t;
|
||||
|
||||
REFOBJECT_FORWARD_TYPE(module_container_t);
|
||||
REFOBJECT_FORWARD_TYPE(module_t);
|
||||
igloo_RO_FORWARD_TYPE(module_container_t);
|
||||
igloo_RO_FORWARD_TYPE(module_t);
|
||||
|
||||
int module_container_add_module(module_container_t *self, module_t *module);
|
||||
int module_container_delete_module(module_container_t *self, const char *name);
|
||||
|
198
src/refobject.c
198
src/refobject.c
@ -1,198 +0,0 @@
|
||||
/* Icecast
|
||||
*
|
||||
* This program is distributed under the GNU General Public License, version 2.
|
||||
* A copy of this license is included with this source.
|
||||
*
|
||||
* Copyright 2018, Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <igloo/thread.h>
|
||||
|
||||
#include "refobject.h"
|
||||
|
||||
#define TO_BASE(x) REFOBJECT_TO_TYPE((x), refobject_base_t *)
|
||||
|
||||
int refobject_new__return_zero(refobject_t self, const refobject_type_t *type, va_list ap)
|
||||
{
|
||||
(void)self, (void)type, (void)ap;
|
||||
return 0;
|
||||
}
|
||||
|
||||
REFOBJECT_DEFINE_TYPE(refobject_base_t,
|
||||
REFOBJECT_DEFINE_TYPE_NEW_NOOP()
|
||||
);
|
||||
|
||||
static inline int check_type(const refobject_type_t *type)
|
||||
{
|
||||
return type->control_length == sizeof(refobject_type_t) && type->control_version == REFOBJECT_CONTROL_VERSION &&
|
||||
type->type_length >= sizeof(refobject_base_t);
|
||||
}
|
||||
|
||||
refobject_t refobject_new__real(const refobject_type_t *type, void *userdata, const char *name, refobject_t associated)
|
||||
{
|
||||
refobject_base_t *ret = NULL;
|
||||
|
||||
if (!check_type(type))
|
||||
return (refobject_t)ret;
|
||||
|
||||
ret = calloc(1, type->type_length);
|
||||
if (ret == NULL)
|
||||
return (refobject_t)ret;
|
||||
|
||||
ret->type = type;
|
||||
ret->refc = 1;
|
||||
ret->userdata = userdata;
|
||||
|
||||
igloo_thread_mutex_create(&(ret->lock));
|
||||
|
||||
if (name) {
|
||||
ret->name = strdup(name);
|
||||
if (!ret->name) {
|
||||
refobject_unref(ret);
|
||||
return REFOBJECT_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!REFOBJECT_IS_NULL(associated)) {
|
||||
if (refobject_ref(associated) != 0) {
|
||||
refobject_unref(ret);
|
||||
return REFOBJECT_NULL;
|
||||
}
|
||||
|
||||
ret->associated = associated;
|
||||
}
|
||||
|
||||
return (refobject_t)ret;
|
||||
}
|
||||
|
||||
refobject_t refobject_new__simple(const refobject_type_t *type, void *userdata, const char *name, refobject_t associated, ...)
|
||||
{
|
||||
refobject_t ret;
|
||||
int res;
|
||||
va_list ap;
|
||||
|
||||
if (!check_type(type))
|
||||
return REFOBJECT_NULL;
|
||||
|
||||
if (!type->type_newcb)
|
||||
return REFOBJECT_NULL;
|
||||
|
||||
ret = refobject_new__real(type, userdata, name, associated);
|
||||
if (REFOBJECT_IS_NULL(ret))
|
||||
return REFOBJECT_NULL;
|
||||
|
||||
va_start(ap, associated);
|
||||
res = type->type_newcb(ret, type, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (res != 0) {
|
||||
refobject_unref(ret);
|
||||
return REFOBJECT_NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int refobject_ref(refobject_t self)
|
||||
{
|
||||
if (REFOBJECT_IS_NULL(self))
|
||||
return -1;
|
||||
|
||||
igloo_thread_mutex_lock(&(TO_BASE(self)->lock));
|
||||
TO_BASE(self)->refc++;
|
||||
igloo_thread_mutex_unlock(&(TO_BASE(self)->lock));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int refobject_unref(refobject_t self)
|
||||
{
|
||||
register refobject_base_t *base = TO_BASE(self);
|
||||
|
||||
if (REFOBJECT_IS_NULL(self))
|
||||
return -1;
|
||||
|
||||
igloo_thread_mutex_lock(&(base->lock));
|
||||
base->refc--;
|
||||
if (base->refc) {
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (base->type->type_freecb)
|
||||
base->type->type_freecb(self, &(base->userdata));
|
||||
|
||||
if (base->userdata)
|
||||
free(base->userdata);
|
||||
|
||||
if (base->name)
|
||||
free(base->name);
|
||||
|
||||
igloo_thread_mutex_unlock(&(base->lock));
|
||||
igloo_thread_mutex_destroy(&(base->lock));
|
||||
|
||||
free(base);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void * refobject_get_userdata(refobject_t self)
|
||||
{
|
||||
void *ret;
|
||||
|
||||
if (REFOBJECT_IS_NULL(self))
|
||||
return NULL;
|
||||
|
||||
igloo_thread_mutex_lock(&(TO_BASE(self)->lock));
|
||||
ret = TO_BASE(self)->userdata;
|
||||
igloo_thread_mutex_unlock(&(TO_BASE(self)->lock));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int refobject_set_userdata(refobject_t self, void *userdata)
|
||||
{
|
||||
if (REFOBJECT_IS_NULL(self))
|
||||
return -1;
|
||||
|
||||
igloo_thread_mutex_lock(&(TO_BASE(self)->lock));
|
||||
TO_BASE(self)->userdata = userdata;
|
||||
igloo_thread_mutex_unlock(&(TO_BASE(self)->lock));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char * refobject_get_name(refobject_t self)
|
||||
{
|
||||
const char *ret;
|
||||
|
||||
if (REFOBJECT_IS_NULL(self))
|
||||
return NULL;
|
||||
|
||||
igloo_thread_mutex_lock(&(TO_BASE(self)->lock));
|
||||
ret = TO_BASE(self)->name;
|
||||
igloo_thread_mutex_unlock(&(TO_BASE(self)->lock));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
refobject_t refobject_get_associated(refobject_t self)
|
||||
{
|
||||
refobject_t ret;
|
||||
|
||||
if (REFOBJECT_IS_NULL(self))
|
||||
return REFOBJECT_NULL;
|
||||
|
||||
igloo_thread_mutex_lock(&(TO_BASE(self)->lock));
|
||||
ret = TO_BASE(self)->associated;
|
||||
igloo_thread_mutex_unlock(&(TO_BASE(self)->lock));
|
||||
|
||||
return ret;
|
||||
}
|
206
src/refobject.h
206
src/refobject.h
@ -1,206 +0,0 @@
|
||||
/* Icecast
|
||||
*
|
||||
* This program is distributed under the GNU General Public License, version 2.
|
||||
* A copy of this license is included with this source.
|
||||
*
|
||||
* Copyright 2018, Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
|
||||
*/
|
||||
|
||||
/* This file contains the API for the refobject helper type.
|
||||
* The refobject helper type is a base type that allows building other types with safe reference counting.
|
||||
*/
|
||||
|
||||
#ifndef __REFOBJECT_H__
|
||||
#define __REFOBJECT_H__
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <igloo/thread.h>
|
||||
|
||||
#include "icecasttypes.h"
|
||||
#include "compat.h"
|
||||
|
||||
/* The following macros are defined. The definition depends on if the compiler
|
||||
* supports transparent unions. If supported full type checking is enabled.
|
||||
* If the compiler does not support transparent unions, we fall back to using
|
||||
* (void*) pointers.
|
||||
*
|
||||
* REFOBJECT_NULL
|
||||
* Can be used to set an refobject to NULL.
|
||||
* REFOBJECT_IS_NULL(x)
|
||||
* Can be used to check if the refobject x is NULL.
|
||||
* Checking by doing (x == NULL) does not work with transparent unions
|
||||
* as the operation is only defined for it's members.
|
||||
* REFOBJECT_TO_TYPE(type,x)
|
||||
* This casts the refobject (x) to the type (type).
|
||||
* REFOBJECT_FROM_TYPE(x)
|
||||
* Converts an object to a (refobject_t). This is the inverse of REFOBJECT_TO_TYPE().
|
||||
* REFOBJECT_GET_TYPENAME(x)
|
||||
* Get the name of the type of the object.
|
||||
* REFOBJECT_IS_VALID(x,type)
|
||||
* This returns true if x is not NULL and of type type.
|
||||
* REFOBJECT_GET_BASE(x)
|
||||
* REFOBJECT_GET_TYPE(x)
|
||||
* Not to be used by the user.
|
||||
*/
|
||||
#ifdef HAVE_TYPE_ATTRIBUTE_TRANSPARENT_UNION
|
||||
#define REFOBJECT_NULL ((refobject_t)(refobject_base_t*)NULL)
|
||||
#define REFOBJECT_GET_BASE(x) (((refobject_t)(x)).refobject_base)
|
||||
#define REFOBJECT_IS_NULL(x) (((refobject_t)(x)).refobject_base == NULL)
|
||||
#define REFOBJECT_TO_TYPE(x,y) ((y)(((refobject_t)(x)).refobject_base))
|
||||
#else
|
||||
#define REFOBJECT_NULL NULL
|
||||
#define REFOBJECT_GET_BASE(x) ((refobject_base_t)(x))
|
||||
#define REFOBJECT_IS_NULL(x) ((x) == NULL)
|
||||
#define REFOBJECT_TO_TYPE(x,y) ((y)(x))
|
||||
#endif
|
||||
|
||||
#define REFOBJECT_FROM_TYPE(x) ((refobject_t)(refobject_base_t*)(x))
|
||||
|
||||
#define REFOBJECT_GET_TYPE(x) (REFOBJECT_GET_BASE((x)) == NULL ? NULL : REFOBJECT_GET_BASE((x))->type)
|
||||
#define REFOBJECT_GET_TYPENAME(x) (REFOBJECT_GET_TYPE((x)) == NULL ? NULL : REFOBJECT_GET_TYPE((x))->type_name)
|
||||
|
||||
#define REFOBJECT_IS_VALID(x,type) (!REFOBJECT_IS_NULL((x)) && REFOBJECT_GET_TYPE((x)) == (refobject_type__ ## type))
|
||||
|
||||
/* The following macros are used to define types.
|
||||
*
|
||||
* REFOBJECT_FORWARD_TYPE(type)
|
||||
* Adds a forward decleration for the type. This is useful for non private types.
|
||||
* REFOBJECT_DEFINE_TYPE(type,extras...)
|
||||
* This defines a public type. One or more of the EXTRA macros be used.
|
||||
* REFOBJECT_DEFINE_PRIVATE_TYPE(type,extras...)
|
||||
* Same as REFOBJECT_DEFINE_TYPE() but defines private type.
|
||||
*
|
||||
* EXTRA Marcos:
|
||||
* REFOBJECT_DEFINE_TYPE_FREE(cb)
|
||||
* This defines a callback to be called when the object is freed.
|
||||
* cb must be of type refobject_free_t.
|
||||
* REFOBJECT_DEFINE_TYPE_NEW(cb)
|
||||
* This defines a callback to be called when a new object is created.
|
||||
* cb must be of type refobject_new_t.
|
||||
* REFOBJECT_DEFINE_TYPE_NEW_NOOP()
|
||||
* This installs a dummy callback for creation. This allows the type
|
||||
* to be created using refobject_new(type) as with REFOBJECT_DEFINE_TYPE_NEW().
|
||||
* This is useful for types that do not need to be initialized more than what
|
||||
* refobject_new() already does.
|
||||
*
|
||||
* Other Macros:
|
||||
* REFOBJECT_CONTROL_VERSION
|
||||
* REFOBJECT_DEFINE_TYPE__RAW()
|
||||
* Not to be used by the user.
|
||||
*/
|
||||
#define REFOBJECT_CONTROL_VERSION 1
|
||||
#define REFOBJECT_FORWARD_TYPE(type) extern const refobject_type_t * refobject_type__ ## type;
|
||||
#define REFOBJECT_DEFINE_TYPE__RAW(type, ...) \
|
||||
static const refobject_type_t refobject_typedef__ ## type = \
|
||||
{ \
|
||||
.control_length = sizeof(refobject_type_t), \
|
||||
.control_version = REFOBJECT_CONTROL_VERSION, \
|
||||
.type_length = sizeof(type), \
|
||||
.type_name = # type \
|
||||
, ## __VA_ARGS__ \
|
||||
}
|
||||
#define REFOBJECT_DEFINE_TYPE(type, ...) REFOBJECT_DEFINE_TYPE__RAW(type, ## __VA_ARGS__); const refobject_type_t * refobject_type__ ## type = &refobject_typedef__ ## type
|
||||
#define REFOBJECT_DEFINE_PRIVATE_TYPE(type, ...) REFOBJECT_DEFINE_TYPE__RAW(type, ## __VA_ARGS__); static const refobject_type_t * refobject_type__ ## type = &refobject_typedef__ ## type
|
||||
#define REFOBJECT_DEFINE_TYPE_FREE(cb) .type_freecb = (cb)
|
||||
#define REFOBJECT_DEFINE_TYPE_NEW(cb) .type_newcb = (cb)
|
||||
#define REFOBJECT_DEFINE_TYPE_NEW_NOOP() .type_newcb = refobject_new__return_zero
|
||||
|
||||
typedef struct refobject_type_tag refobject_type_t;
|
||||
int refobject_new__return_zero(refobject_t self, const refobject_type_t *type, va_list ap);
|
||||
|
||||
/* Type used for callback called then the object is actually freed
|
||||
* That is once all references to it are gone.
|
||||
*
|
||||
* If the callback does not set *userdata to NULL *userdata will
|
||||
* be freed automatically by calling free(3).
|
||||
*
|
||||
* This function must not try to deallocate or alter self.
|
||||
*/
|
||||
typedef void (*refobject_free_t)(refobject_t self, void **userdata);
|
||||
|
||||
/* Type used for callback called then the object is created
|
||||
* using the generic refobject_new().
|
||||
*
|
||||
* Additional parameters passed to refobject_new() are passed
|
||||
* in the list ap. All limitations of <stdarg.h> apply.
|
||||
*
|
||||
* This function must return zero in case of success and
|
||||
* non-zero in case of error. In case of error refobject_unref()
|
||||
* is called internally to clear the object.
|
||||
*/
|
||||
typedef int (*refobject_new_t)(refobject_t self, const refobject_type_t *type, va_list ap);
|
||||
|
||||
/* Meta type used to defined types.
|
||||
* DO NOT use any of the members in here directly!
|
||||
*/
|
||||
|
||||
struct refobject_type_tag {
|
||||
/* Size of this control structure */
|
||||
size_t control_length;
|
||||
/* ABI version of this structure */
|
||||
int control_version;
|
||||
|
||||
/* Total length of the objects to be created */
|
||||
size_t type_length;
|
||||
/* Name of type */
|
||||
const char * type_name;
|
||||
/* Callback to be called on final free() */
|
||||
refobject_free_t type_freecb;
|
||||
/* Callback to be callback by refobject_new() */
|
||||
refobject_new_t type_newcb;
|
||||
};
|
||||
|
||||
/* Only defined here as the size must be publically known.
|
||||
* DO NOT use any of the members in here directly!
|
||||
*/
|
||||
struct refobject_base_tag {
|
||||
const refobject_type_t* type;
|
||||
size_t refc;
|
||||
igloo_mutex_t lock;
|
||||
void *userdata;
|
||||
char *name;
|
||||
refobject_t associated;
|
||||
};
|
||||
|
||||
REFOBJECT_FORWARD_TYPE(refobject_base_t);
|
||||
|
||||
/* Create a new refobject
|
||||
* The total length of the new object is given by len (see malloc(3)),
|
||||
* the callback called on free is given by freecb (see refobject_free_t above),
|
||||
* the userdata us given by userdata,
|
||||
* the name for the object is given by name, and
|
||||
* the associated refobject is given by associated.
|
||||
*
|
||||
* All parameters beside len are optional and can be NULL/REFOBJECT_NULL.
|
||||
* If no freecb is given the userdata is freed (see refobject_free_t above).
|
||||
*/
|
||||
#define refobject_new__new(type, userdata, name, associated) REFOBJECT_TO_TYPE(refobject_new__real((refobject_type__ ## type), (userdata), (name), (associated)), type*)
|
||||
refobject_t refobject_new__real(const refobject_type_t *type, void *userdata, const char *name, refobject_t associated);
|
||||
#define refobject_new(type, ...) REFOBJECT_TO_TYPE(refobject_new__simple((refobject_type__ ## type), NULL, NULL, REFOBJECT_NULL, ## __VA_ARGS__), type*)
|
||||
#define refobject_new_ext(type, userdata, name, associated, ...) REFOBJECT_TO_TYPE(refobject_new__simple((refobject_type__ ## type), (userdata), (name), (associated), ## __VA_ARGS__), type*)
|
||||
refobject_t refobject_new__simple(const refobject_type_t *type, void *userdata, const char *name, refobject_t associated, ...);
|
||||
|
||||
/* This increases the reference counter of the object */
|
||||
int refobject_ref(refobject_t self);
|
||||
/* This decreases the reference counter of the object.
|
||||
* If the object's reference counter reaches zero the object is freed.
|
||||
*/
|
||||
int refobject_unref(refobject_t self);
|
||||
|
||||
/* This gets and sets the userdata */
|
||||
void * refobject_get_userdata(refobject_t self);
|
||||
int refobject_set_userdata(refobject_t self, void *userdata);
|
||||
|
||||
/* This gets the object's name */
|
||||
const char * refobject_get_name(refobject_t self);
|
||||
|
||||
/* This gets the object's associated object. */
|
||||
refobject_t refobject_get_associated(refobject_t self);
|
||||
|
||||
#endif
|
229
src/reportxml.c
229
src/reportxml.c
@ -20,7 +20,7 @@
|
||||
#include <igloo/avl.h>
|
||||
|
||||
#include "reportxml.h"
|
||||
#include "refobject.h"
|
||||
#include <igloo/ro.h>
|
||||
|
||||
/* For XMLSTR() */
|
||||
#include "cfgfile.h"
|
||||
@ -31,7 +31,7 @@
|
||||
/* The report XML document type */
|
||||
struct reportxml_tag {
|
||||
/* base object */
|
||||
refobject_base_t __base;
|
||||
igloo_ro_base_t __base;
|
||||
/* the root report XML node of the document */
|
||||
reportxml_node_t *root;
|
||||
};
|
||||
@ -39,7 +39,7 @@ struct reportxml_tag {
|
||||
/* The report XML node type */
|
||||
struct reportxml_node_tag {
|
||||
/* base object */
|
||||
refobject_base_t __base;
|
||||
igloo_ro_base_t __base;
|
||||
/* an XML node used to store the attributes */
|
||||
xmlNodePtr xmlnode;
|
||||
/* the type of the node */
|
||||
@ -57,13 +57,30 @@ struct reportxml_node_tag {
|
||||
/* The report XML database type */
|
||||
struct reportxml_database_tag {
|
||||
/* base object */
|
||||
refobject_base_t __base;
|
||||
igloo_ro_base_t __base;
|
||||
/* the lock used to ensure the database object is thread safe. */
|
||||
igloo_mutex_t lock;
|
||||
/* The tree of definitions */
|
||||
igloo_avl_tree *definitions;
|
||||
};
|
||||
|
||||
static void __report_free(igloo_ro_t self);
|
||||
static int __report_new(igloo_ro_t self, const igloo_ro_type_t *type, va_list ap);
|
||||
igloo_RO_PUBLIC_TYPE(reportxml_t,
|
||||
igloo_RO_TYPEDECL_FREE(__report_free),
|
||||
igloo_RO_TYPEDECL_NEW(__report_new)
|
||||
);
|
||||
static void __report_node_free(igloo_ro_t self);
|
||||
igloo_RO_PUBLIC_TYPE(reportxml_node_t,
|
||||
igloo_RO_TYPEDECL_FREE(__report_node_free),
|
||||
);
|
||||
static void __database_free(igloo_ro_t self);
|
||||
static int __database_new(igloo_ro_t self, const igloo_ro_type_t *type, va_list ap);
|
||||
igloo_RO_PUBLIC_TYPE(reportxml_database_t,
|
||||
igloo_RO_TYPEDECL_FREE(__database_free),
|
||||
igloo_RO_TYPEDECL_NEW(__database_new)
|
||||
);
|
||||
|
||||
/* The nodeattr structure is used to store definition of node attributes */
|
||||
struct nodeattr;
|
||||
struct nodeattr {
|
||||
@ -229,16 +246,16 @@ static const struct nodeattr * __get_nodeattr(const struct nodedef * nodedef, co
|
||||
}
|
||||
|
||||
|
||||
static void __report_free(refobject_t self, void **userdata)
|
||||
static void __report_free(igloo_ro_t self)
|
||||
{
|
||||
reportxml_t *report = REFOBJECT_TO_TYPE(self, reportxml_t *);
|
||||
reportxml_t *report = igloo_RO_TO_TYPE(self, reportxml_t);
|
||||
|
||||
refobject_unref(report->root);
|
||||
igloo_ro_unref(report->root);
|
||||
}
|
||||
|
||||
static int __report_new(refobject_t self, const refobject_type_t *type, va_list ap)
|
||||
static int __report_new(igloo_ro_t self, const igloo_ro_type_t *type, va_list ap)
|
||||
{
|
||||
reportxml_t *ret = REFOBJECT_TO_TYPE(self, reportxml_t*);
|
||||
reportxml_t *ret = igloo_RO_TO_TYPE(self, reportxml_t);
|
||||
reportxml_node_t *root = reportxml_node_new(REPORTXML_NODE_TYPE_REPORT, NULL, NULL, NULL);
|
||||
|
||||
if (!root)
|
||||
@ -249,11 +266,6 @@ static int __report_new(refobject_t self, const refobject_type_t *type, va_list
|
||||
return 0;
|
||||
}
|
||||
|
||||
REFOBJECT_DEFINE_TYPE(reportxml_t,
|
||||
REFOBJECT_DEFINE_TYPE_FREE(__report_free),
|
||||
REFOBJECT_DEFINE_TYPE_NEW(__report_new)
|
||||
);
|
||||
|
||||
static reportxml_t * reportxml_new_with_root(reportxml_node_t *root)
|
||||
{
|
||||
reportxml_t *ret;
|
||||
@ -261,7 +273,7 @@ static reportxml_t * reportxml_new_with_root(reportxml_node_t *root)
|
||||
if (!root)
|
||||
return NULL;
|
||||
|
||||
ret = refobject_new__new(reportxml_t, NULL, NULL, NULL);
|
||||
ret = igloo_ro_new_raw(reportxml_t, NULL, igloo_RO_NULL);
|
||||
ret->root = root;
|
||||
|
||||
return ret;
|
||||
@ -269,7 +281,7 @@ static reportxml_t * reportxml_new_with_root(reportxml_node_t *root)
|
||||
|
||||
reportxml_t * reportxml_new(void)
|
||||
{
|
||||
return refobject_new(reportxml_t);
|
||||
return igloo_ro_new(reportxml_t);
|
||||
}
|
||||
|
||||
reportxml_node_t * reportxml_get_root_node(reportxml_t *report)
|
||||
@ -277,7 +289,7 @@ reportxml_node_t * reportxml_get_root_node(reportxml_t *report)
|
||||
if (!report)
|
||||
return NULL;
|
||||
|
||||
if (refobject_ref(report->root) != 0)
|
||||
if (igloo_ro_ref(report->root) != 0)
|
||||
return NULL;
|
||||
|
||||
return report->root;
|
||||
@ -317,13 +329,13 @@ reportxml_t * reportxml_parse_xmldoc(xmlDocPtr doc)
|
||||
return NULL;
|
||||
|
||||
if (reportxml_node_get_type(root) != REPORTXML_NODE_TYPE_REPORT) {
|
||||
refobject_unref(root);
|
||||
igloo_ro_unref(root);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = reportxml_new_with_root(root);
|
||||
if (!ret) {
|
||||
refobject_unref(root);
|
||||
igloo_ro_unref(root);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -353,15 +365,15 @@ xmlDocPtr reportxml_render_xmldoc(reportxml_t *report)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __report_node_free(refobject_t self, void **userdata)
|
||||
static void __report_node_free(igloo_ro_t self)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
reportxml_node_t *node = REFOBJECT_TO_TYPE(self, reportxml_node_t *);
|
||||
reportxml_node_t *node = igloo_RO_TO_TYPE(self, reportxml_node_t);
|
||||
xmlFreeNode(node->xmlnode);
|
||||
|
||||
for (i = 0; i < node->childs_len; i++) {
|
||||
refobject_unref(node->childs[i]);
|
||||
igloo_ro_unref(node->childs[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < node->xml_childs_len; i++) {
|
||||
@ -373,10 +385,6 @@ static void __report_node_free(refobject_t self, void **userdata)
|
||||
free(node->xml_childs);
|
||||
}
|
||||
|
||||
REFOBJECT_DEFINE_TYPE(reportxml_node_t,
|
||||
REFOBJECT_DEFINE_TYPE_FREE(__report_node_free)
|
||||
);
|
||||
|
||||
reportxml_node_t * reportxml_node_new(reportxml_node_type_t type, const char *id, const char *definition, const char *akindof)
|
||||
{
|
||||
reportxml_node_t *ret;
|
||||
@ -386,7 +394,7 @@ reportxml_node_t * reportxml_node_new(reportxml_node_type_t type, const cha
|
||||
if (!nodedef)
|
||||
return NULL;
|
||||
|
||||
ret = refobject_new__new(reportxml_node_t, NULL, NULL, NULL);
|
||||
ret = igloo_ro_new_raw(reportxml_node_t, NULL, igloo_RO_NULL);
|
||||
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
@ -396,7 +404,7 @@ reportxml_node_t * reportxml_node_new(reportxml_node_type_t type, const cha
|
||||
ret->xmlnode = xmlNewNode(NULL, XMLSTR(nodedef->name));
|
||||
|
||||
if (!ret->xmlnode) {
|
||||
refobject_unref(ret);
|
||||
igloo_ro_unref(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -407,7 +415,7 @@ reportxml_node_t * reportxml_node_new(reportxml_node_type_t type, const cha
|
||||
|
||||
if (nodeattr->def) {
|
||||
if (reportxml_node_set_attribute(ret, nodeattr->name, nodeattr->def) != 0) {
|
||||
refobject_unref(ret);
|
||||
igloo_ro_unref(ret);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -416,7 +424,7 @@ reportxml_node_t * reportxml_node_new(reportxml_node_type_t type, const cha
|
||||
#define _set_attr(x) \
|
||||
if ((x)) { \
|
||||
if (reportxml_node_set_attribute(ret, # x , (x)) != 0) { \
|
||||
refobject_unref(ret); \
|
||||
igloo_ro_unref(ret); \
|
||||
return NULL; \
|
||||
} \
|
||||
}
|
||||
@ -453,12 +461,12 @@ reportxml_node_t * reportxml_node_parse_xmlnode(xmlNodePtr xmlnode)
|
||||
do {
|
||||
xmlChar *value = xmlNodeListGetString(xmlnode->doc, cur->children, 1);
|
||||
if (!value) {
|
||||
refobject_unref(node);
|
||||
igloo_ro_unref(node);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (reportxml_node_set_attribute(node, (const char*)cur->name, (const char*)value) != 0) {
|
||||
refobject_unref(node);
|
||||
igloo_ro_unref(node);
|
||||
ICECAST_LOG_DEBUG("Can not parse XML node: attribute \"%H\" value \"%H\" is invalid on node of type <%s>", cur->name, value, nodedef->name);
|
||||
return NULL;
|
||||
}
|
||||
@ -473,7 +481,7 @@ reportxml_node_t * reportxml_node_parse_xmlnode(xmlNodePtr xmlnode)
|
||||
do {
|
||||
if (nodedef->content == NC_XML) {
|
||||
if (reportxml_node_add_xml_child(node, cur) != 0) {
|
||||
refobject_unref(node);
|
||||
igloo_ro_unref(node);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
@ -489,12 +497,12 @@ reportxml_node_t * reportxml_node_parse_xmlnode(xmlNodePtr xmlnode)
|
||||
xmlChar *value = xmlNodeListGetString(xmlnode->doc, cur, 1);
|
||||
|
||||
if (!value) {
|
||||
refobject_unref(node);
|
||||
igloo_ro_unref(node);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (reportxml_node_set_content(node, (const char *)value) != 0) {
|
||||
refobject_unref(node);
|
||||
igloo_ro_unref(node);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -504,16 +512,16 @@ reportxml_node_t * reportxml_node_parse_xmlnode(xmlNodePtr xmlnode)
|
||||
|
||||
child = reportxml_node_parse_xmlnode(cur);
|
||||
if (!child) {
|
||||
refobject_unref(node);
|
||||
igloo_ro_unref(node);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (reportxml_node_add_child(node, child) != 0) {
|
||||
refobject_unref(child);
|
||||
refobject_unref(node);
|
||||
igloo_ro_unref(child);
|
||||
igloo_ro_unref(node);
|
||||
return NULL;
|
||||
}
|
||||
refobject_unref(child);
|
||||
igloo_ro_unref(child);
|
||||
}
|
||||
} while ((cur = cur->next));
|
||||
}
|
||||
@ -545,7 +553,7 @@ static reportxml_node_t * __reportxml_node_copy_with_db(reportxml_node_t *n
|
||||
|
||||
if (node->content) {
|
||||
if (reportxml_node_set_content(ret, node->content) != 0) {
|
||||
refobject_unref(ret);
|
||||
igloo_ro_unref(ret);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -555,28 +563,28 @@ static reportxml_node_t * __reportxml_node_copy_with_db(reportxml_node_t *n
|
||||
|
||||
if (db && depth > 0) {
|
||||
if (__attach_copy_of_node_or_definition(ret, child, db, depth) != 0) {
|
||||
refobject_unref(child);
|
||||
refobject_unref(ret);
|
||||
igloo_ro_unref(child);
|
||||
igloo_ro_unref(ret);
|
||||
return NULL;
|
||||
}
|
||||
refobject_unref(child);
|
||||
igloo_ro_unref(child);
|
||||
} else {
|
||||
reportxml_node_t *copy = __reportxml_node_copy_with_db(child, NULL, -1);
|
||||
|
||||
refobject_unref(child);
|
||||
igloo_ro_unref(child);
|
||||
|
||||
if (!copy) {
|
||||
refobject_unref(ret);
|
||||
igloo_ro_unref(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (reportxml_node_add_child(ret, copy) != 0) {
|
||||
refobject_unref(copy);
|
||||
refobject_unref(ret);
|
||||
igloo_ro_unref(copy);
|
||||
igloo_ro_unref(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
refobject_unref(copy);
|
||||
igloo_ro_unref(copy);
|
||||
}
|
||||
}
|
||||
|
||||
@ -584,7 +592,7 @@ static reportxml_node_t * __reportxml_node_copy_with_db(reportxml_node_t *n
|
||||
xmlNodePtr child = reportxml_node_get_xml_child(node, i);
|
||||
if (reportxml_node_add_xml_child(ret, child) != 0) {
|
||||
xmlFreeNode(child);
|
||||
refobject_unref(ret);
|
||||
igloo_ro_unref(ret);
|
||||
return NULL;
|
||||
}
|
||||
xmlFreeNode(child);
|
||||
@ -638,7 +646,7 @@ xmlNodePtr reportxml_node_render_xmlnode(reportxml_node_t *node)
|
||||
}
|
||||
|
||||
xmlchild = reportxml_node_render_xmlnode(child);
|
||||
refobject_unref(child);
|
||||
igloo_ro_unref(child);
|
||||
if (!xmlchild) {
|
||||
xmlFreeNode(ret);
|
||||
return NULL;
|
||||
@ -773,7 +781,7 @@ int reportxml_node_add_child(reportxml_node_t *node, reportx
|
||||
|
||||
node->childs = n;
|
||||
|
||||
if (refobject_ref(child) != 0)
|
||||
if (igloo_ro_ref(child) != 0)
|
||||
return -1;
|
||||
|
||||
node->childs[node->childs_len++] = child;
|
||||
@ -799,7 +807,7 @@ reportxml_node_t * reportxml_node_get_child(reportxml_node_t *node, size_t
|
||||
if (idx >= node->childs_len)
|
||||
return NULL;
|
||||
|
||||
if (refobject_ref(node->childs[idx]) != 0)
|
||||
if (igloo_ro_ref(node->childs[idx]) != 0)
|
||||
return NULL;
|
||||
|
||||
return node->childs[idx];
|
||||
@ -819,7 +827,7 @@ reportxml_node_t * reportxml_node_get_child_by_attribute(reportxml_node_t *
|
||||
if (strcmp((const char*)k, value) == 0) {
|
||||
xmlFree(k);
|
||||
|
||||
if (refobject_ref(node) != 0)
|
||||
if (igloo_ro_ref(node) != 0)
|
||||
return NULL;
|
||||
|
||||
return node;
|
||||
@ -847,7 +855,7 @@ reportxml_node_t * reportxml_node_get_child_by_type(reportxml_node_t *node,
|
||||
return NULL;
|
||||
|
||||
if (node->type == type) {
|
||||
if (refobject_ref(node) != 0)
|
||||
if (igloo_ro_ref(node) != 0)
|
||||
return NULL;
|
||||
return node;
|
||||
}
|
||||
@ -954,12 +962,12 @@ xmlNodePtr reportxml_node_get_xml_child(reportxml_node_t *node, siz
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __database_free(refobject_t self, void **userdata)
|
||||
static void __database_free(igloo_ro_t self)
|
||||
{
|
||||
reportxml_database_t *db = REFOBJECT_TO_TYPE(self, reportxml_database_t *);
|
||||
reportxml_database_t *db = igloo_RO_TO_TYPE(self, reportxml_database_t);
|
||||
|
||||
if (db->definitions)
|
||||
igloo_avl_tree_free(db->definitions, (igloo_avl_free_key_fun_type)refobject_unref);
|
||||
igloo_avl_tree_free(db->definitions, (igloo_avl_free_key_fun_type)igloo_ro_unref);
|
||||
|
||||
igloo_thread_mutex_destroy(&(db->lock));
|
||||
}
|
||||
@ -984,9 +992,9 @@ static int __compare_definitions(void *arg, void *a, void *b)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int __database_new(refobject_t self, const refobject_type_t *type, va_list ap)
|
||||
static int __database_new(igloo_ro_t self, const igloo_ro_type_t *type, va_list ap)
|
||||
{
|
||||
reportxml_database_t *ret = REFOBJECT_TO_TYPE(self, reportxml_database_t*);
|
||||
reportxml_database_t *ret = igloo_RO_TO_TYPE(self, reportxml_database_t);
|
||||
|
||||
igloo_thread_mutex_create(&(ret->lock));
|
||||
|
||||
@ -997,14 +1005,9 @@ static int __database_new(refobject_t self, const refobject_type_t *type, va_lis
|
||||
return 0;
|
||||
}
|
||||
|
||||
REFOBJECT_DEFINE_TYPE(reportxml_database_t,
|
||||
REFOBJECT_DEFINE_TYPE_FREE(__database_free),
|
||||
REFOBJECT_DEFINE_TYPE_NEW(__database_new)
|
||||
);
|
||||
|
||||
reportxml_database_t * reportxml_database_new(void)
|
||||
{
|
||||
return refobject_new(reportxml_database_t);
|
||||
return igloo_ro_new(reportxml_database_t);
|
||||
}
|
||||
|
||||
int reportxml_database_add_report(reportxml_database_t *db, reportxml_t *report)
|
||||
@ -1031,12 +1034,12 @@ int reportxml_database_add_report(reportxml_database_t *db,
|
||||
reportxml_node_t *copy;
|
||||
|
||||
if (reportxml_node_get_type(node) != REPORTXML_NODE_TYPE_DEFINITION) {
|
||||
refobject_unref(node);
|
||||
igloo_ro_unref(node);
|
||||
continue;
|
||||
}
|
||||
|
||||
copy = reportxml_node_copy(node);
|
||||
refobject_unref(node);
|
||||
igloo_ro_unref(node);
|
||||
|
||||
if (!copy)
|
||||
continue;
|
||||
@ -1046,7 +1049,7 @@ int reportxml_database_add_report(reportxml_database_t *db,
|
||||
|
||||
igloo_thread_mutex_unlock(&(db->lock));
|
||||
|
||||
refobject_unref(root);
|
||||
igloo_ro_unref(root);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1078,7 +1081,7 @@ static int __attach_copy_of_node_or_definition(reportxml_node_t *parent, reportx
|
||||
ICECAST_LOG_DEBUG("parent=%p, node=%p, depth=%zi, Found definition.", parent, node, depth);
|
||||
|
||||
if (count < 0) {
|
||||
refobject_unref(def);
|
||||
igloo_ro_unref(def);
|
||||
ICECAST_LOG_DEBUG("parent=%p, node=%p, depth=%zi <- -1", parent, node, depth);
|
||||
return -1;
|
||||
}
|
||||
@ -1089,16 +1092,16 @@ static int __attach_copy_of_node_or_definition(reportxml_node_t *parent, reportx
|
||||
ICECAST_LOG_DEBUG("parent=%p, node=%p, depth=%zi, Itering, child #%zu (%p)", parent, node, depth, i, child);
|
||||
|
||||
if (__attach_copy_of_node_or_definition(parent, child, db, depth - 1) != 0) {
|
||||
refobject_unref(child);
|
||||
refobject_unref(def);
|
||||
igloo_ro_unref(child);
|
||||
igloo_ro_unref(def);
|
||||
ICECAST_LOG_DEBUG("parent=%p, node=%p, depth=%zi <- -1", parent, node, depth);
|
||||
return -1;
|
||||
}
|
||||
|
||||
refobject_unref(child);
|
||||
igloo_ro_unref(child);
|
||||
}
|
||||
|
||||
refobject_unref(def);
|
||||
igloo_ro_unref(def);
|
||||
|
||||
ICECAST_LOG_DEBUG("parent=%p, node=%p, depth=%zi <- 0", parent, node, depth);
|
||||
return 0;
|
||||
@ -1115,7 +1118,7 @@ static int __attach_copy_of_node_or_definition(reportxml_node_t *parent, reportx
|
||||
|
||||
ret = reportxml_node_add_child(parent, copy);
|
||||
|
||||
refobject_unref(copy);
|
||||
igloo_ro_unref(copy);
|
||||
|
||||
ICECAST_LOG_DEBUG("parent=%p, node=%p, depth=%zi <- %i", parent, node, depth, ret);
|
||||
return ret;
|
||||
@ -1154,20 +1157,20 @@ static reportxml_node_t * __reportxml_database_build_node_ext(reportxml_dat
|
||||
return NULL;
|
||||
|
||||
if (reportxml_node_set_attribute(search, "defines", id) != 0) {
|
||||
refobject_unref(search);
|
||||
igloo_ro_unref(search);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
igloo_thread_mutex_lock(&(db->lock));
|
||||
if (igloo_avl_get_by_key(db->definitions, REFOBJECT_TO_TYPE(search, void *), (void**)&found) != 0) {
|
||||
if (igloo_avl_get_by_key(db->definitions, (void*)search, (void**)&found) != 0) {
|
||||
igloo_thread_mutex_unlock(&(db->lock));
|
||||
refobject_unref(search);
|
||||
igloo_ro_unref(search);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
refobject_unref(search);
|
||||
igloo_ro_unref(search);
|
||||
|
||||
if (refobject_ref(found) != 0) {
|
||||
if (igloo_ro_ref(found) != 0) {
|
||||
igloo_thread_mutex_unlock(&(db->lock));
|
||||
return NULL;
|
||||
}
|
||||
@ -1175,7 +1178,7 @@ static reportxml_node_t * __reportxml_database_build_node_ext(reportxml_dat
|
||||
|
||||
count = reportxml_node_count_child(found);
|
||||
if (count < 0) {
|
||||
refobject_unref(found);
|
||||
igloo_ro_unref(found);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -1187,7 +1190,7 @@ static reportxml_node_t * __reportxml_database_build_node_ext(reportxml_dat
|
||||
|
||||
if (tpl) {
|
||||
ret = reportxml_node_copy(tpl);
|
||||
refobject_unref(tpl);
|
||||
igloo_ro_unref(tpl);
|
||||
} else {
|
||||
ret = NULL;
|
||||
}
|
||||
@ -1196,7 +1199,7 @@ static reportxml_node_t * __reportxml_database_build_node_ext(reportxml_dat
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
refobject_unref(found);
|
||||
igloo_ro_unref(found);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -1222,22 +1225,22 @@ static reportxml_node_t * __reportxml_database_build_node_ext(reportxml_dat
|
||||
|
||||
/* We want depth, not depth - 1 here. __attach_copy_of_node_or_definition() takes care of this for us. */
|
||||
if (__attach_copy_of_node_or_definition(ret, node, db, depth) != 0) {
|
||||
refobject_unref(node);
|
||||
refobject_unref(found);
|
||||
refobject_unref(ret);
|
||||
igloo_ro_unref(node);
|
||||
igloo_ro_unref(found);
|
||||
igloo_ro_unref(ret);
|
||||
ICECAST_LOG_ERROR("Can not attach child #%zu (%p) to attachment point (%p) in report. BAD.", i, node, ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
refobject_unref(node);
|
||||
igloo_ro_unref(node);
|
||||
}
|
||||
|
||||
refobject_unref(found);
|
||||
igloo_ro_unref(found);
|
||||
|
||||
if (all_childs_same_type == ACST_YES) {
|
||||
count = reportxml_node_count_child(ret);
|
||||
if (count < 0) {
|
||||
refobject_unref(ret);
|
||||
igloo_ro_unref(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -1245,17 +1248,17 @@ static reportxml_node_t * __reportxml_database_build_node_ext(reportxml_dat
|
||||
reportxml_node_t *node = reportxml_node_get_child(ret, i);
|
||||
|
||||
if (!node) {
|
||||
refobject_unref(ret);
|
||||
igloo_ro_unref(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (reportxml_node_set_attribute(node, "_definition", id) != 0) {
|
||||
refobject_unref(node);
|
||||
refobject_unref(ret);
|
||||
igloo_ro_unref(node);
|
||||
igloo_ro_unref(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
refobject_unref(node);
|
||||
igloo_ro_unref(node);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1300,27 +1303,27 @@ reportxml_t * reportxml_database_build_report(reportxml_database_t *db
|
||||
/* Let's see how many children we have. */
|
||||
count = reportxml_node_count_child(definition);
|
||||
if (count < 0) {
|
||||
refobject_unref(definition);
|
||||
igloo_ro_unref(definition);
|
||||
ICECAST_LOG_ERROR("Can not get child count from definition. BAD.");
|
||||
return NULL;
|
||||
} else if (count == 0) {
|
||||
/* Empty definition? Not exactly an exciting report... */
|
||||
ICECAST_LOG_WARN("Empty definition for \"%H\". Returning empty report. This is likely an error.", id);
|
||||
refobject_unref(definition);
|
||||
return refobject_new(reportxml_t);
|
||||
igloo_ro_unref(definition);
|
||||
return igloo_ro_new(reportxml_t);
|
||||
}
|
||||
|
||||
if (type == REPORTXML_NODE_TYPE__ERROR) {
|
||||
/* Now the hard part: find out what level we are. */
|
||||
child = reportxml_node_get_child(definition, 0);
|
||||
if (!child) {
|
||||
refobject_unref(definition);
|
||||
igloo_ro_unref(definition);
|
||||
ICECAST_LOG_ERROR("Can not get first child. BAD.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
type = reportxml_node_get_type(child);
|
||||
refobject_unref(child);
|
||||
igloo_ro_unref(child);
|
||||
}
|
||||
|
||||
/* check for supported configurations */
|
||||
@ -1329,34 +1332,34 @@ reportxml_t * reportxml_database_build_report(reportxml_database_t *db
|
||||
case REPORTXML_NODE_TYPE_STATE:
|
||||
break;
|
||||
default:
|
||||
refobject_unref(definition);
|
||||
igloo_ro_unref(definition);
|
||||
ICECAST_LOG_WARN("Unsupported type of first child.");
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
ret = refobject_new(reportxml_t);
|
||||
ret = igloo_ro_new(reportxml_t);
|
||||
if (!ret) {
|
||||
refobject_unref(definition);
|
||||
igloo_ro_unref(definition);
|
||||
ICECAST_LOG_ERROR("Can not allocate new report. BAD.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
root = reportxml_get_root_node(ret);
|
||||
if (!ret) {
|
||||
refobject_unref(definition);
|
||||
refobject_unref(ret);
|
||||
igloo_ro_unref(definition);
|
||||
igloo_ro_unref(ret);
|
||||
ICECAST_LOG_ERROR("Can not get root node from report. BAD.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (type == REPORTXML_NODE_TYPE_INCIDENT) {
|
||||
refobject_ref(attach_to = root);
|
||||
igloo_ro_ref(attach_to = root);
|
||||
} else if (type == REPORTXML_NODE_TYPE_STATE) {
|
||||
attach_to = reportxml_node_new(REPORTXML_NODE_TYPE_INCIDENT, NULL, NULL, NULL);
|
||||
if (attach_to) {
|
||||
if (reportxml_node_add_child(root, attach_to) != 0) {
|
||||
refobject_unref(attach_to);
|
||||
igloo_ro_unref(attach_to);
|
||||
attach_to = NULL;
|
||||
}
|
||||
}
|
||||
@ -1364,11 +1367,11 @@ reportxml_t * reportxml_database_build_report(reportxml_database_t *db
|
||||
attach_to = NULL;
|
||||
}
|
||||
|
||||
refobject_unref(root);
|
||||
igloo_ro_unref(root);
|
||||
|
||||
if (!attach_to) {
|
||||
refobject_unref(definition);
|
||||
refobject_unref(ret);
|
||||
igloo_ro_unref(definition);
|
||||
igloo_ro_unref(ret);
|
||||
ICECAST_LOG_ERROR("No point to attach to in report. BAD.");
|
||||
return NULL;
|
||||
}
|
||||
@ -1388,18 +1391,18 @@ reportxml_t * reportxml_database_build_report(reportxml_database_t *db
|
||||
|
||||
/* we can directly attach as it's a already a copy. */
|
||||
if (reportxml_node_add_child(attach_to, child) != 0) {
|
||||
refobject_unref(definition);
|
||||
refobject_unref(attach_to);
|
||||
refobject_unref(ret);
|
||||
igloo_ro_unref(definition);
|
||||
igloo_ro_unref(attach_to);
|
||||
igloo_ro_unref(ret);
|
||||
ICECAST_LOG_ERROR("Can not attach child #%zu (%p) to attachment point (%p) in report. BAD.", i, child, attach_to);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
refobject_unref(child);
|
||||
igloo_ro_unref(child);
|
||||
}
|
||||
|
||||
refobject_unref(definition);
|
||||
refobject_unref(attach_to);
|
||||
igloo_ro_unref(definition);
|
||||
igloo_ro_unref(attach_to);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
#include "icecasttypes.h"
|
||||
#include "compat.h"
|
||||
#include "refobject.h"
|
||||
#include <igloo/ro.h>
|
||||
|
||||
/* XML Tag Types
|
||||
* While a hint of what the nodes are used for is given, see the specification for more details.
|
||||
@ -61,9 +61,9 @@ typedef enum {
|
||||
REPORTXML_NODE_TYPE_EXTENSION
|
||||
} reportxml_node_type_t;
|
||||
|
||||
REFOBJECT_FORWARD_TYPE(reportxml_t);
|
||||
REFOBJECT_FORWARD_TYPE(reportxml_node_t);
|
||||
REFOBJECT_FORWARD_TYPE(reportxml_database_t);
|
||||
igloo_RO_FORWARD_TYPE(reportxml_t);
|
||||
igloo_RO_FORWARD_TYPE(reportxml_node_t);
|
||||
igloo_RO_FORWARD_TYPE(reportxml_database_t);
|
||||
|
||||
/* ---[ Document level ]--- */
|
||||
/* The document object is NOT thread safe. */
|
||||
|
Loading…
Reference in New Issue
Block a user