Commit f915fe76 authored by Philipp Schafft's avatar Philipp Schafft 🦁

Update: Migrated from refobject to igloo_ro

parent ae9a7ca0
...@@ -28,7 +28,6 @@ noinst_HEADERS = \ ...@@ -28,7 +28,6 @@ noinst_HEADERS = \
md5.h \ md5.h \
matchfile.h \ matchfile.h \
tls.h \ tls.h \
refobject.h \
buffer.h \ buffer.h \
module.h \ module.h \
reportxml.h \ reportxml.h \
...@@ -74,7 +73,6 @@ icecast_SOURCES = \ ...@@ -74,7 +73,6 @@ icecast_SOURCES = \
md5.c \ md5.c \
matchfile.c \ matchfile.c \
tls.c \ tls.c \
refobject.c \
buffer.c \ buffer.c \
module.c \ module.c \
reportxml.c \ reportxml.c \
......
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
#include <stdarg.h> #include <stdarg.h>
#include "buffer.h" #include "buffer.h"
#include "refobject.h" #include <igloo/ro.h>
struct buffer_tag { struct buffer_tag {
refobject_base_t __base; igloo_ro_base_t __base;
/* Buffer itself */ /* Buffer itself */
void *buffer; void *buffer;
/* Length in bytes of buffer */ /* Length in bytes of buffer */
...@@ -30,21 +30,23 @@ struct buffer_tag { ...@@ -30,21 +30,23 @@ struct buffer_tag {
size_t offset; 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); free(buffer->buffer);
} }
REFOBJECT_DEFINE_TYPE(buffer_t, buffer_t * buffer_new(ssize_t preallocation, const char *name, igloo_ro_t associated)
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 = refobject_new_ext(buffer_t, userdata, name, associated); buffer_t *buffer = igloo_ro_new_ext(buffer_t, name, associated);
if (!buffer) if (!buffer)
return NULL; return NULL;
...@@ -57,7 +59,7 @@ buffer_t * buffer_new(ssize_t preallocation, void *userdata, const char *name, ...@@ -57,7 +59,7 @@ buffer_t * buffer_new(ssize_t preallocation, void *userdata, const char *name,
buffer_t * buffer_new_simple(void) 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) void buffer_preallocate(buffer_t *buffer, size_t request)
......
...@@ -22,13 +22,13 @@ ...@@ -22,13 +22,13 @@
#include "icecasttypes.h" #include "icecasttypes.h"
#include "compat.h" #include "compat.h"
#include "refobject.h" #include <igloo/ro.h>
/* About thread safety: /* About thread safety:
* This set of functions is intentinally not thread safe. * 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. /* This creates a new buffer object.
* Parameters: * Parameters:
...@@ -37,7 +37,7 @@ REFOBJECT_FORWARD_TYPE(buffer_t); ...@@ -37,7 +37,7 @@ REFOBJECT_FORWARD_TYPE(buffer_t);
* userdata, name, associated * userdata, name, associated
* See refobject_new(). * 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. /* Depreciated: This creates a new buffer with defaults.
* Do NOT use this. Use refobject_new(buffer_t) * Do NOT use this. Use refobject_new(buffer_t)
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include "util.h" #include "util.h"
#include "auth.h" #include "auth.h"
#include "event.h" #include "event.h"
#include "refobject.h" #include <igloo/ro.h>
#include "reportxml.h" #include "reportxml.h"
/* for config_reread_config() */ /* for config_reread_config() */
...@@ -234,7 +234,7 @@ void config_init_configuration(ice_config_t *configuration) ...@@ -234,7 +234,7 @@ void config_init_configuration(ice_config_t *configuration)
{ {
memset(configuration, 0, sizeof(ice_config_t)); memset(configuration, 0, sizeof(ice_config_t));
_set_defaults(configuration); _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) static inline void __read_int(xmlDocPtr doc, xmlNodePtr node, int *val, const char *warning)
...@@ -699,7 +699,7 @@ void config_clear(ice_config_t *c) ...@@ -699,7 +699,7 @@ void config_clear(ice_config_t *c)
config_clear_http_header(c->http_headers); 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)); memset(c, 0, sizeof(ice_config_t));
} }
...@@ -2241,7 +2241,7 @@ static void _parse_paths(xmlDocPtr doc, ...@@ -2241,7 +2241,7 @@ static void _parse_paths(xmlDocPtr doc,
ICECAST_LOG_ERROR("Can not parse report xml database \"%H\"", temp); ICECAST_LOG_ERROR("Can not parse report xml database \"%H\"", temp);
} else { } else {
reportxml_database_add_report(configuration->reportxml_db, report); 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); ICECAST_LOG_INFO("File \"%H\" added to report xml database", temp);
} }
} }
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include <igloo/httpp.h> #include <igloo/httpp.h>
#include "global.h" #include "global.h"
#include "refobject.h" #include <igloo/ro.h>
#include "cfgfile.h" #include "cfgfile.h"
#include "connection.h" #include "connection.h"
#include "tls.h" #include "tls.h"
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
#include "fserve.h" #include "fserve.h"
#include "errors.h" #include "errors.h"
#include "reportxml.h" #include "reportxml.h"
#include "refobject.h" #include <igloo/ro.h>
#include "xslt.h" #include "xslt.h"
#include "source.h" #include "source.h"
...@@ -266,7 +266,7 @@ void client_destroy(client_t *client) ...@@ -266,7 +266,7 @@ void client_destroy(client_t *client)
if (client->free_client_data) if (client->free_client_data)
client->free_client_data(client); client->free_client_data(client);
refobject_unref(client->handler_module); igloo_ro_unref(client->handler_module);
free(client->handler_function); free(client->handler_function);
free(client->uri); free(client->uri);
free(client->username); free(client->username);
...@@ -344,7 +344,7 @@ static inline void _client_send_report(client_t *client, const char *uuid, const ...@@ -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); 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) void client_send_error_by_error(client_t *client, const icecast_error_t *error)
...@@ -659,7 +659,7 @@ static void client_get_reportxml__add_basic_stats(reportxml_t *report) ...@@ -659,7 +659,7 @@ static void client_get_reportxml__add_basic_stats(reportxml_t *report)
reportxml_node_add_child(rootnode, extension); reportxml_node_add_child(rootnode, extension);
refobject_unref(rootnode); igloo_ro_unref(rootnode);
xmlroot = xmlNewNode(NULL, XMLSTR("icestats")); xmlroot = xmlNewNode(NULL, XMLSTR("icestats"));
modules = module_container_get_modulelist_as_xml(global.modulecontainer); modules = module_container_get_modulelist_as_xml(global.modulecontainer);
...@@ -667,7 +667,7 @@ static void client_get_reportxml__add_basic_stats(reportxml_t *report) ...@@ -667,7 +667,7 @@ static void client_get_reportxml__add_basic_stats(reportxml_t *report)
reportxml_node_add_xml_child(extension, xmlroot); reportxml_node_add_xml_child(extension, xmlroot);
refobject_unref(extension); igloo_ro_unref(extension);
xmlFreeNode(xmlroot); xmlFreeNode(xmlroot);
} }
...@@ -686,7 +686,7 @@ reportxml_t *client_get_reportxml(const char *state_definition, const char *stat ...@@ -686,7 +686,7 @@ reportxml_t *client_get_reportxml(const char *state_definition, const char *stat
if (!report) { if (!report) {
reportxml_node_t *rootnode, *incidentnode, *statenode; reportxml_node_t *rootnode, *incidentnode, *statenode;
report = refobject_new(reportxml_t); report = igloo_ro_new(reportxml_t);
rootnode = reportxml_get_root_node(report); rootnode = reportxml_get_root_node(report);
incidentnode = reportxml_node_new(REPORTXML_NODE_TYPE_INCIDENT, NULL, NULL, NULL); incidentnode = reportxml_node_new(REPORTXML_NODE_TYPE_INCIDENT, NULL, NULL, NULL);
statenode = reportxml_node_new(REPORTXML_NODE_TYPE_STATE, NULL, state_definition, state_akindof); statenode = reportxml_node_new(REPORTXML_NODE_TYPE_STATE, NULL, state_definition, state_akindof);
...@@ -697,14 +697,14 @@ reportxml_t *client_get_reportxml(const char *state_definition, const char *stat ...@@ -697,14 +697,14 @@ reportxml_t *client_get_reportxml(const char *state_definition, const char *stat
textnode = reportxml_node_new(REPORTXML_NODE_TYPE_TEXT, NULL, NULL, NULL); textnode = reportxml_node_new(REPORTXML_NODE_TYPE_TEXT, NULL, NULL, NULL);
reportxml_node_set_content(textnode, state_text); reportxml_node_set_content(textnode, state_text);
reportxml_node_add_child(statenode, textnode); reportxml_node_add_child(statenode, textnode);
refobject_unref(textnode); igloo_ro_unref(textnode);
} }
reportxml_node_add_child(incidentnode, statenode); reportxml_node_add_child(incidentnode, statenode);
reportxml_node_add_child(rootnode, incidentnode); reportxml_node_add_child(rootnode, incidentnode);
refobject_unref(statenode); igloo_ro_unref(statenode);
refobject_unref(incidentnode); igloo_ro_unref(incidentnode);
refobject_unref(rootnode); igloo_ro_unref(rootnode);
} }
client_get_reportxml__add_basic_stats(report); client_get_reportxml__add_basic_stats(report);
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
#include "cfgfile.h" #include "cfgfile.h"
#include "global.h" #include "global.h"
#include "util.h" #include "util.h"
#include "refobject.h" #include <igloo/ro.h>
#include "refbuf.h" #include "refbuf.h"
#include "client.h" #include "client.h"
#include "errors.h" #include "errors.h"
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
#include "matchfile.h" #include "matchfile.h"
#include "tls.h" #include "tls.h"
#include "acl.h" #include "acl.h"
#include "refobject.h" #include <igloo/ro.h>
#include "listensocket.h" #include "listensocket.h"
#include "fastevent.h" #include "fastevent.h"
...@@ -261,8 +261,8 @@ connection_t *connection_create(igloo_sock_t sock, listensocket_t *listensocket_ ...@@ -261,8 +261,8 @@ connection_t *connection_create(igloo_sock_t sock, listensocket_t *listensocket_
con = (connection_t *)calloc(1, sizeof(connection_t)); con = (connection_t *)calloc(1, sizeof(connection_t));
if (con) { if (con) {
refobject_ref(listensocket_real); igloo_ro_ref(listensocket_real);
refobject_ref(listensocket_effective); igloo_ro_ref(listensocket_effective);
con->sock = sock; con->sock = sock;
con->listensocket_real = listensocket_real; con->listensocket_real = listensocket_real;
...@@ -1242,7 +1242,7 @@ static int _handle_resources(client_t *client, char **uri) ...@@ -1242,7 +1242,7 @@ static int _handle_resources(client_t *client, char **uri)
module_t *module = module_container_get_module(global.modulecontainer, resource->module); module_t *module = module_container_get_module(global.modulecontainer, resource->module);
if (module != NULL) { if (module != NULL) {
refobject_unref(client->handler_module); igloo_ro_unref(client->handler_module);
client->handler_module = module; client->handler_module = module;
} else { } else {
ICECAST_LOG_ERROR("Module used in alias not found: %s", resource->module); 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) ...@@ -1701,7 +1701,7 @@ static void __on_sock_count(size_t count, void *userdata)
void connection_setup_sockets (ice_config_t *config) void connection_setup_sockets (ice_config_t *config)
{ {
global_lock(); global_lock();
refobject_unref(global.listensockets); igloo_ro_unref(global.listensockets);
if (config == NULL) { if (config == NULL) {
global_unlock(); global_unlock();
...@@ -1721,7 +1721,7 @@ void connection_setup_sockets (ice_config_t *config) ...@@ -1721,7 +1721,7 @@ void connection_setup_sockets (ice_config_t *config)
allowed_ip = matchfile_new(config->allowfile); 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); listensocket_container_configure(global.listensockets, config);
global_unlock(); global_unlock();
...@@ -1745,8 +1745,8 @@ void connection_close(connection_t *con) ...@@ -1745,8 +1745,8 @@ void connection_close(connection_t *con)
free(con->ip); free(con->ip);
if (con->readbuffer) if (con->readbuffer)
free(con->readbuffer); free(con->readbuffer);
refobject_unref(con->listensocket_real); igloo_ro_unref(con->listensocket_real);
refobject_unref(con->listensocket_effective); igloo_ro_unref(con->listensocket_effective);
free(con); free(con);
} }
......
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
#include <config.h> #include <config.h>
#endif #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 <stdlib.h>
#include <string.h> #include <string.h>
...@@ -26,14 +30,19 @@ ...@@ -26,14 +30,19 @@
#ifdef FASTEVENT_ENABLED #ifdef FASTEVENT_ENABLED
typedef struct { struct fastevent_registration_tag {
refobject_base_t __base; igloo_ro_base_t __base;
fastevent_type_t type; fastevent_type_t type;
fastevent_cb_t cb; fastevent_cb_t cb;
fastevent_freecb_t freecb; fastevent_freecb_t freecb;
void *userdata; 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 { struct eventrow {
size_t length; size_t length;
...@@ -96,13 +105,11 @@ static int __remove_from_row(struct eventrow * row, fastevent_registration_t *re ...@@ -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; struct eventrow * row;
(void)userdata;
igloo_thread_rwlock_wlock(&fastevent_lock); igloo_thread_rwlock_wlock(&fastevent_lock);
row = __get_row(registration->type); row = __get_row(registration->type);
if (__remove_from_row(row, registration) != 0) { if (__remove_from_row(row, registration) != 0) {
...@@ -143,31 +150,28 @@ int fastevent_shutdown(void) ...@@ -143,31 +150,28 @@ int fastevent_shutdown(void)
return 0; 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; struct eventrow * row;
fastevent_registration_t *registration; fastevent_registration_t *registration;
if (cb == NULL) if (cb == NULL)
return REFOBJECT_NULL; return igloo_RO_NULL;
igloo_thread_rwlock_wlock(&fastevent_lock); igloo_thread_rwlock_wlock(&fastevent_lock);
row = __get_row(type); row = __get_row(type);
if (row == NULL) { if (row == NULL) {
igloo_thread_rwlock_unlock(&fastevent_lock); 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) { if (!registration) {
igloo_thread_rwlock_unlock(&fastevent_lock); igloo_thread_rwlock_unlock(&fastevent_lock);
return REFOBJECT_NULL; return igloo_RO_NULL;
} }
registration->type = type; registration->type = type;
...@@ -177,12 +181,12 @@ refobject_t fastevent_register(fastevent_type_t type, fastevent_cb_t cb, fasteve ...@@ -177,12 +181,12 @@ refobject_t fastevent_register(fastevent_type_t type, fastevent_cb_t cb, fasteve
if (__add_to_row(row, registration) != 0) { if (__add_to_row(row, registration) != 0) {
igloo_thread_rwlock_unlock(&fastevent_lock); igloo_thread_rwlock_unlock(&fastevent_lock);
refobject_unref(REFOBJECT_FROM_TYPE(registration)); igloo_ro_unref(registration);
return REFOBJECT_NULL; return igloo_RO_NULL;
} }
igloo_thread_rwlock_unlock(&fastevent_lock); 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, ...) void fastevent_emit(fastevent_type_t type, fastevent_flag_t flags, fastevent_datatype_t datatype, ...)
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#endif #endif
#include <stdarg.h> #include <stdarg.h>
#include "refobject.h" #include <igloo/ro.h>
typedef enum { typedef enum {
FASTEVENT_TYPE_SLOWEVENT = 0, FASTEVENT_TYPE_SLOWEVENT = 0,
...@@ -54,7 +54,7 @@ typedef void (*fastevent_freecb_t)(void **userdata); ...@@ -54,7 +54,7 @@ typedef void (*fastevent_freecb_t)(void **userdata);
#ifdef FASTEVENT_ENABLED #ifdef FASTEVENT_ENABLED
int fastevent_initialize(void); int fastevent_initialize(void);
int fastevent_shutdown(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, ...); void fastevent_emit(fastevent_type_t type, fastevent_flag_t flags, fastevent_datatype_t datatype, ...);
#else #else
#define fastevent_initialize() 0 #define fastevent_initialize() 0
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include <igloo/avl.h> #include <igloo/avl.h>
#include "global.h" #include "global.h"
#include "refobject.h" #include <igloo/ro.h>
#include "module.h" #include "module.h"
#include "source.h" #include "source.h"
...@@ -39,14 +39,14 @@ void global_initialize(void) ...@@ -39,14 +39,14 @@ void global_initialize(void)
global.clients = 0; global.clients = 0;
global.sources = 0; global.sources = 0;
global.source_tree = igloo_avl_tree_new(source_compare_sources, NULL); 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); igloo_thread_mutex_create(&_global_mutex);
} }
void global_shutdown(void) void global_shutdown(void)
{ {
igloo_thread_mutex_destroy(&_global_mutex); igloo_thread_mutex_destroy(&_global_mutex);
refobject_unref(global.modulecontainer); igloo_ro_unref(global.modulecontainer);
igloo_avl_tree_free(global.source_tree, NULL); igloo_avl_tree_free(global.source_tree, NULL);
} }
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include "compat.h" #include "compat.h"
#include <igloo/typedef.h>
/* ---[ client.[ch] ]--- */ /* ---[ client.[ch] ]--- */
typedef struct _client_tag client_t; typedef struct _client_tag client_t;
...@@ -116,22 +118,14 @@ typedef struct listensocket_tag listensocket_t; ...@@ -116,22 +118,14 @@ typedef struct listensocket_tag listensocket_t;
/* ---[ refobject.[ch] ]--- */ /* ---[ refobject.[ch] ]--- */
typedef struct refobject_base_tag refobject_base_t; #define igloo_RO_APPTYPES \
igloo_RO_TYPE(buffer_t) \
#ifdef HAVE_TYPE_ATTRIBUTE_TRANSPARENT_UNION igloo_RO_TYPE(module_t) \
typedef union __attribute__ ((__transparent_union__)) { igloo_RO_TYPE(module_container_t) \
refobject_base_t *refobject_base; igloo_RO_TYPE(reportxml_t) \
buffer_t *buffer; igloo_RO_TYPE(reportxml_node_t) \
module_t *module; igloo_RO_TYPE(reportxml_database_t) \
module_container_t *module_container; igloo_RO_TYPE(listensocket_container_t) \
reportxml_t *reportxml; igloo_RO_TYPE(listensocket_t)
reportxml_node_t *