...
 
Commits (12)
[submodule "m4"] [submodule "m4"]
path = m4 path = m4
url = ../icecast-m4.git url = ../icecast-m4.git
[submodule "src/common"]
path = src/common
url = ../icecast-common.git
...@@ -5,13 +5,10 @@ set -e ...@@ -5,13 +5,10 @@ set -e
srcdir=$(dirname "$0") srcdir=$(dirname "$0")
test -n "$srcdir" && cd "$srcdir" test -n "$srcdir" && cd "$srcdir"
if ! {
# Test for any file in the m4 submodule # Test for any file in the m4 submodule
test -e "$srcdir/m4/ax_check_compile_flag.m4" && if ! test -e "$srcdir/m4/ax_check_compile_flag.m4"
# Test for any file in the common submodule
test -e "$srcdir/src/common/log/log.c"; };
then then
echo "ERROR: Submodules missing! Ensure you git cloned with '--recursive' or run:" echo "ERROR: Submodule missing! Ensure you git cloned with '--recursive' or run:"
echo " git submodule update --init" echo " git submodule update --init"
exit 1 exit 1
fi fi
......
...@@ -8,6 +8,8 @@ AC_CONFIG_AUX_DIR([build-aux]) ...@@ -8,6 +8,8 @@ AC_CONFIG_AUX_DIR([build-aux])
AC_PROG_CC AC_PROG_CC
LT_INIT
AX_CHECK_COMPILE_FLAG([-std=c99], [ AX_CHECK_COMPILE_FLAG([-std=c99], [
AX_APPEND_FLAG([-std=c99]) AX_APPEND_FLAG([-std=c99])
], [ ], [
...@@ -44,9 +46,6 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) ...@@ -44,9 +46,6 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
AM_MAINTAINER_MODE([enable]) AM_MAINTAINER_MODE([enable])
LT_INIT
dnl Sanitizer flags dnl Sanitizer flags
AC_ARG_WITH([sanitizer], AC_ARG_WITH([sanitizer],
...@@ -100,8 +99,6 @@ AC_CHECK_HEADERS([sys/timeb.h]) ...@@ -100,8 +99,6 @@ AC_CHECK_HEADERS([sys/timeb.h])
AC_CHECK_HEADERS([sys/socket.h]) AC_CHECK_HEADERS([sys/socket.h])
AC_CHECK_HEADERS([pwd.h grp.h]) AC_CHECK_HEADERS([pwd.h grp.h])
XIPH_NET
dnl Check for functions dnl Check for functions
AC_FUNC_FORK AC_FUNC_FORK
AC_FUNC_CHOWN AC_FUNC_CHOWN
...@@ -109,24 +106,17 @@ AC_FUNC_CHOWN ...@@ -109,24 +106,17 @@ AC_FUNC_CHOWN
AC_CHECK_FUNCS([setuid]) AC_CHECK_FUNCS([setuid])
AC_CHECK_FUNCS([chroot]) AC_CHECK_FUNCS([chroot])
AC_CHECK_FUNCS([strcasestr]) AC_CHECK_FUNCS([strcasestr])
AC_CHECK_FUNCS([gethostname])
AC_CHECK_FUNCS([uname]) AC_CHECK_FUNCS([uname])
AC_CHECK_FUNCS([setenv]) AC_CHECK_FUNCS([setenv])
AC_CHECK_FUNCS([setresuid]) AC_CHECK_FUNCS([setresuid])
AC_CHECK_FUNCS([setresgid]) AC_CHECK_FUNCS([setresgid])
AC_CHECK_FUNCS([localtime_r]) AC_CHECK_FUNCS([localtime_r])
AC_CHECK_FUNCS([gettimeofday])
AC_CHECK_FUNCS([ftime])
dnl Do not check for poll on Darwin, it is broken in some versions dnl Do not check for poll on Darwin, it is broken in some versions
AS_IF([test "${SYS}" != "darwin"], [ AS_IF([test "${SYS}" != "darwin"], [
AC_CHECK_FUNCS([poll]) AC_CHECK_FUNCS([poll])
]) ])
AC_SEARCH_LIBS([nanosleep], [rt posix4], [
AC_DEFINE([HAVE_NANOSLEEP], [1], [Define if you have nanosleep])
])
dnl Checks for types and typedefs dnl Checks for types and typedefs
AC_TYPE_OFF_T AC_TYPE_OFF_T
AC_TYPE_PID_T AC_TYPE_PID_T
...@@ -136,6 +126,16 @@ AC_TYPE_UID_T ...@@ -136,6 +126,16 @@ AC_TYPE_UID_T
dnl Checks for required libraries dnl Checks for required libraries
dnl
dnl igloo
dnl
PKG_CHECK_MODULES([IGLOO], [igloo], [], [
AC_MSG_ERROR([${IGLOO_PKG_ERRORS}. igloo is required.])
])
CFLAGS="${CFLAGS} ${IGLOO_CFLAGS}"
LIBS="${LIBS} ${IGLOO_LIBS}"
dnl dnl
dnl libxml2 dnl libxml2
dnl dnl
...@@ -274,24 +274,12 @@ AS_IF([test "$with_default_config" != "no"], [ ...@@ -274,24 +274,12 @@ AS_IF([test "$with_default_config" != "no"], [
]) ])
dnl Make substitutions
AC_SUBST(XIPH_LIBS)
AC_SUBST(XIPH_CPPFLAGS)
AC_SUBST(XIPH_CFLAGS)
AC_SUBST(XIPH_LDFLAGS)
AC_CONFIG_HEADERS([config.h]) AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([ AC_CONFIG_FILES([
Makefile Makefile
conf/Makefile conf/Makefile
src/Makefile src/Makefile
src/common/avl/Makefile
src/common/httpp/Makefile
src/common/thread/Makefile
src/common/log/Makefile
src/common/net/Makefile
src/common/timing/Makefile
doc/Makefile doc/Makefile
web/Makefile web/Makefile
admin/Makefile admin/Makefile
......
## Process this with automake to create Makefile.in ## Process this with automake to create Makefile.in
SUBDIRS = common/avl common/net common/thread common/httpp common/log common/timing
bin_PROGRAMS = icecast bin_PROGRAMS = icecast
noinst_HEADERS = \ noinst_HEADERS = \
...@@ -30,10 +28,7 @@ noinst_HEADERS = \ ...@@ -30,10 +28,7 @@ noinst_HEADERS = \
md5.h \ md5.h \
matchfile.h \ matchfile.h \
tls.h \ tls.h \
refobject.h \
buffer.h \
module.h \ module.h \
reportxml.h \
listensocket.h \ listensocket.h \
fastevent.h \ fastevent.h \
event.h \ event.h \
...@@ -76,10 +71,7 @@ icecast_SOURCES = \ ...@@ -76,10 +71,7 @@ icecast_SOURCES = \
md5.c \ md5.c \
matchfile.c \ matchfile.c \
tls.c \ tls.c \
refobject.c \
buffer.c \
module.c \ module.c \
reportxml.c \
listensocket.c \ listensocket.c \
fastevent.c \ fastevent.c \
format.c \ format.c \
...@@ -132,15 +124,4 @@ EXTRA_icecast_SOURCES = \ ...@@ -132,15 +124,4 @@ EXTRA_icecast_SOURCES = \
format_theora.c \ format_theora.c \
format_speex.c format_speex.c
icecast_DEPENDENCIES = \
common/net/libicenet.la \
common/thread/libicethread.la \
common/httpp/libicehttpp.la \
common/log/libicelog.la \
common/avl/libiceavl.la \
common/timing/libicetiming.la
icecast_LDADD = $(icecast_DEPENDENCIES)
icecast_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/common
include $(srcdir)/tests/Makefile.am include $(srcdir)/tests/Makefile.am
...@@ -28,7 +28,7 @@ struct acl_tag { ...@@ -28,7 +28,7 @@ struct acl_tag {
size_t refcount; size_t refcount;
/* allowed methods */ /* allowed methods */
acl_policy_t method[httpp_req_unknown+1]; acl_policy_t method[igloo_httpp_req_unknown+1];
/* admin/ interface */ /* admin/ interface */
struct { struct {
...@@ -242,15 +242,15 @@ int acl_set_method_str__callback(acl_t *acl, ...@@ -242,15 +242,15 @@ int acl_set_method_str__callback(acl_t *acl,
acl_policy_t policy, acl_policy_t policy,
const char *str) const char *str)
{ {
httpp_request_type_e method; igloo_httpp_request_type_e method;
size_t i; size_t i;
if (strcmp(str, "*") == 0) { if (strcmp(str, "*") == 0) {
for (i = 0; i < (sizeof(acl->method)/sizeof(*acl->method)); i++) for (i = 0; i < (sizeof(acl->method)/sizeof(*acl->method)); i++)
acl->method[i] = policy; acl->method[i] = policy;
} else { } else {
method = httpp_str_to_method(str); method = igloo_httpp_str_to_method(str);
if (method == httpp_req_unknown) if (method == igloo_httpp_req_unknown)
return -1; return -1;
acl->method[method] = policy; acl->method[method] = policy;
...@@ -259,9 +259,9 @@ int acl_set_method_str__callback(acl_t *acl, ...@@ -259,9 +259,9 @@ int acl_set_method_str__callback(acl_t *acl,
return 0; return 0;
} }
acl_policy_t acl_test_method(acl_t * acl, httpp_request_type_e method) acl_policy_t acl_test_method(acl_t * acl, igloo_httpp_request_type_e method)
{ {
if (!acl || method < httpp_req_none || method > httpp_req_unknown) if (!acl || method < igloo_httpp_req_none || method > igloo_httpp_req_unknown)
return ACL_POLICY_ERROR; return ACL_POLICY_ERROR;
return acl->method[method]; return acl->method[method];
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include <libxml/xmlmemory.h> #include <libxml/xmlmemory.h>
#include <libxml/parser.h> #include <libxml/parser.h>
#include <libxml/tree.h> #include <libxml/tree.h>
#include "common/httpp/httpp.h" #include <igloo/httpp.h>
#include "icecasttypes.h" #include "icecasttypes.h"
#include "cfgfile.h" #include "cfgfile.h"
...@@ -44,7 +44,7 @@ int acl_set_ANY_str(acl_t * acl, acl_policy_t policy, const char * str, int (*ca ...@@ -44,7 +44,7 @@ int acl_set_ANY_str(acl_t * acl, acl_policy_t policy, const char * str, int (*ca
/* HTTP Method specific functions */ /* HTTP Method specific functions */
int acl_set_method_str__callback(acl_t * acl, acl_policy_t policy, const char * str); int acl_set_method_str__callback(acl_t * acl, acl_policy_t policy, const char * str);
#define acl_set_method_str(acl,policy,str) acl_set_ANY_str((acl), (policy), (str), acl_set_method_str__callback) #define acl_set_method_str(acl,policy,str) acl_set_ANY_str((acl), (policy), (str), acl_set_method_str__callback)
acl_policy_t acl_test_method(acl_t * acl, httpp_request_type_e method); acl_policy_t acl_test_method(acl_t * acl, igloo_httpp_request_type_e method);
/* admin/ interface specific functions */ /* admin/ interface specific functions */
int acl_set_admin_str__callbck(acl_t * acl, acl_policy_t policy, const char * str); int acl_set_admin_str__callbck(acl_t * acl, acl_policy_t policy, const char * str);
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
/* Helper macros */ /* Helper macros */
#define COMMAND_REQUIRE(client,name,var) \ #define COMMAND_REQUIRE(client,name,var) \
do { \ do { \
(var) = httpp_get_param((client)->parser, (name)); \ (var) = igloo_httpp_get_param((client)->parser, (name)); \
if((var) == NULL) { \ if((var) == NULL) { \
client_send_error_by_id(client, ICECAST_ERROR_ADMIN_MISSING_PARAMETER); \ client_send_error_by_id(client, ICECAST_ERROR_ADMIN_MISSING_PARAMETER); \
return; \ return; \
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
} while(0); } while(0);
#define COMMAND_OPTIONAL(client,name,var) \ #define COMMAND_OPTIONAL(client,name,var) \
(var) = httpp_get_param((client)->parser, (name)) (var) = igloo_httpp_get_param((client)->parser, (name))
#define FALLBACK_RAW_REQUEST "fallbacks" #define FALLBACK_RAW_REQUEST "fallbacks"
#define FALLBACK_HTML_REQUEST "fallbacks.xsl" #define FALLBACK_HTML_REQUEST "fallbacks.xsl"
...@@ -329,7 +329,7 @@ xmlNodePtr admin_build_rootnode(xmlDocPtr doc, const char *name) ...@@ -329,7 +329,7 @@ xmlNodePtr admin_build_rootnode(xmlDocPtr doc, const char *name)
* doc even if the source is running */ * doc even if the source is running */
xmlDocPtr admin_build_sourcelist(const char *mount) xmlDocPtr admin_build_sourcelist(const char *mount)
{ {
avl_node *node; igloo_avl_node *node;
source_t *source; source_t *source;
xmlNodePtr xmlnode, srcnode; xmlNodePtr xmlnode, srcnode;
xmlDocPtr doc; xmlDocPtr doc;
...@@ -344,12 +344,12 @@ xmlDocPtr admin_build_sourcelist(const char *mount) ...@@ -344,12 +344,12 @@ xmlDocPtr admin_build_sourcelist(const char *mount)
xmlNewTextChild (xmlnode, NULL, XMLSTR("current_source"), XMLSTR(mount)); xmlNewTextChild (xmlnode, NULL, XMLSTR("current_source"), XMLSTR(mount));
} }
node = avl_get_first(global.source_tree); node = igloo_avl_get_first(global.source_tree);
while(node) { while(node) {
source = (source_t *)node->key; source = (source_t *)node->key;
if (mount && strcmp (mount, source->mount) == 0) if (mount && strcmp (mount, source->mount) == 0)
{ {
node = avl_get_next (node); node = igloo_avl_get_next (node);
continue; continue;
} }
...@@ -371,9 +371,9 @@ xmlDocPtr admin_build_sourcelist(const char *mount) ...@@ -371,9 +371,9 @@ xmlDocPtr admin_build_sourcelist(const char *mount)
config = config_get_config(); config = config_get_config();
mountinfo = config_find_mount(config, source->mount, MOUNT_TYPE_NORMAL); mountinfo = config_find_mount(config, source->mount, MOUNT_TYPE_NORMAL);
if (mountinfo) if (mountinfo)
acl = auth_stack_get_anonymous_acl(mountinfo->authstack, httpp_req_get); acl = auth_stack_get_anonymous_acl(mountinfo->authstack, igloo_httpp_req_get);
if (!acl) if (!acl)
acl = auth_stack_get_anonymous_acl(config->authstack, httpp_req_get); acl = auth_stack_get_anonymous_acl(config->authstack, igloo_httpp_req_get);
if (acl && acl_test_web(acl) == ACL_POLICY_DENY) { if (acl && acl_test_web(acl) == ACL_POLICY_DENY) {
xmlNewTextChild(srcnode, NULL, XMLSTR("authenticator"), XMLSTR("(dummy)")); xmlNewTextChild(srcnode, NULL, XMLSTR("authenticator"), XMLSTR("(dummy)"));
} }
...@@ -390,7 +390,7 @@ xmlDocPtr admin_build_sourcelist(const char *mount) ...@@ -390,7 +390,7 @@ xmlDocPtr admin_build_sourcelist(const char *mount)
XMLSTR(source->format->contenttype)); XMLSTR(source->format->contenttype));
} }
} }
node = avl_get_next(node); node = igloo_avl_get_next(node);
} }
return(doc); return(doc);
} }
...@@ -499,8 +499,8 @@ void admin_handle_request(client_t *client, const char *uri) ...@@ -499,8 +499,8 @@ void admin_handle_request(client_t *client, const char *uri)
/* ACL disallows, check exceptions */ /* ACL disallows, check exceptions */
if ((handler->function == command_metadata && handler->format == ADMIN_FORMAT_RAW) && if ((handler->function == command_metadata && handler->format == ADMIN_FORMAT_RAW) &&
(acl_test_method(client->acl, httpp_req_source) == ACL_POLICY_ALLOW || (acl_test_method(client->acl, igloo_httpp_req_source) == ACL_POLICY_ALLOW ||
acl_test_method(client->acl, httpp_req_put) == ACL_POLICY_ALLOW)) { acl_test_method(client->acl, igloo_httpp_req_put) == ACL_POLICY_ALLOW)) {
ICECAST_LOG_DEBUG("Granted right to call COMMAND_RAW_METADATA_UPDATE to " ICECAST_LOG_DEBUG("Granted right to call COMMAND_RAW_METADATA_UPDATE to "
"client because it is allowed to do SOURCE or PUT."); "client because it is allowed to do SOURCE or PUT.");
} else { } else {
...@@ -516,19 +516,19 @@ void admin_handle_request(client_t *client, const char *uri) ...@@ -516,19 +516,19 @@ void admin_handle_request(client_t *client, const char *uri)
if(mount != NULL) { if(mount != NULL) {
/* This is a mount request, handle it as such */ /* This is a mount request, handle it as such */
avl_tree_rlock(global.source_tree); igloo_avl_tree_rlock(global.source_tree);
source = source_find_mount_raw(mount); source = source_find_mount_raw(mount);
/* No Source found */ /* No Source found */
if (source == NULL) { if (source == NULL) {
avl_tree_unlock(global.source_tree); igloo_avl_tree_unlock(global.source_tree);
ICECAST_LOG_WARN("Admin command \"%H\" on non-existent source \"%H\"", ICECAST_LOG_WARN("Admin command \"%H\" on non-existent source \"%H\"",
uri, mount); uri, mount);
client_send_error_by_id(client, ICECAST_ERROR_ADMIN_SOURCE_DOES_NOT_EXIST); client_send_error_by_id(client, ICECAST_ERROR_ADMIN_SOURCE_DOES_NOT_EXIST);
return; return;
} /* No Source running */ } /* No Source running */
else if (source->running == 0 && source->on_demand == 0) { else if (source->running == 0 && source->on_demand == 0) {
avl_tree_unlock(global.source_tree); igloo_avl_tree_unlock(global.source_tree);
ICECAST_LOG_INFO("Received admin command \"%H\" on unavailable mount \"%H\"", ICECAST_LOG_INFO("Received admin command \"%H\" on unavailable mount \"%H\"",
uri, mount); uri, mount);
client_send_error_by_id(client, ICECAST_ERROR_ADMIN_SOURCE_IS_NOT_AVAILABLE); client_send_error_by_id(client, ICECAST_ERROR_ADMIN_SOURCE_IS_NOT_AVAILABLE);
...@@ -550,8 +550,8 @@ void admin_handle_request(client_t *client, const char *uri) ...@@ -550,8 +550,8 @@ void admin_handle_request(client_t *client, const char *uri)
} }
switch (client->parser->req_type) { switch (client->parser->req_type) {
case httpp_req_get: case igloo_httpp_req_get:
case httpp_req_post: case igloo_httpp_req_post:
if (handler->function) { if (handler->function) {
handler->function(client, source, format); handler->function(client, source, format);
} else { } else {
...@@ -572,7 +572,7 @@ void admin_handle_request(client_t *client, const char *uri) ...@@ -572,7 +572,7 @@ void admin_handle_request(client_t *client, const char *uri)
} }
} }
break; break;
case httpp_req_options: case igloo_httpp_req_options:
client_send_204(client); client_send_204(client);
break; break;
default: default:
...@@ -582,7 +582,7 @@ void admin_handle_request(client_t *client, const char *uri) ...@@ -582,7 +582,7 @@ void admin_handle_request(client_t *client, const char *uri)
} }
if (source) { if (source) {
avl_tree_unlock(global.source_tree); igloo_avl_tree_unlock(global.source_tree);
} }
return; return;
} }
...@@ -695,15 +695,15 @@ static inline xmlNodePtr __add_listener(client_t *client, ...@@ -695,15 +695,15 @@ static inline xmlNodePtr __add_listener(client_t *client,
xmlNewTextChild(node, NULL, XMLSTR(mode == OMODE_LEGACY ? "IP" : "ip"), XMLSTR(client->con->ip)); xmlNewTextChild(node, NULL, XMLSTR(mode == OMODE_LEGACY ? "IP" : "ip"), XMLSTR(client->con->ip));
tmp = httpp_getvar(client->parser, "user-agent"); tmp = igloo_httpp_getvar(client->parser, "user-agent");
if (tmp) if (tmp)
xmlNewTextChild(node, NULL, XMLSTR(mode == OMODE_LEGACY ? "UserAgent" : "useragent"), XMLSTR(tmp)); xmlNewTextChild(node, NULL, XMLSTR(mode == OMODE_LEGACY ? "UserAgent" : "useragent"), XMLSTR(tmp));
tmp = httpp_getvar(client->parser, "referer"); tmp = igloo_httpp_getvar(client->parser, "referer");
if (tmp) if (tmp)
xmlNewTextChild(node, NULL, XMLSTR("referer"), XMLSTR(tmp)); xmlNewTextChild(node, NULL, XMLSTR("referer"), XMLSTR(tmp));
tmp = httpp_getvar(client->parser, "host"); tmp = igloo_httpp_getvar(client->parser, "host");
if (tmp) if (tmp)
xmlNewTextChild(node, NULL, XMLSTR("host"), XMLSTR(tmp)); xmlNewTextChild(node, NULL, XMLSTR("host"), XMLSTR(tmp));
...@@ -735,15 +735,15 @@ void admin_add_listeners_to_mount(source_t *source, ...@@ -735,15 +735,15 @@ void admin_add_listeners_to_mount(source_t *source,
operation_mode mode) operation_mode mode)
{ {
time_t now = time(NULL); time_t now = time(NULL);
avl_node *client_node; igloo_avl_node *client_node;
avl_tree_rlock(source->client_tree); igloo_avl_tree_rlock(source->client_tree);
client_node = avl_get_first(source->client_tree); client_node = igloo_avl_get_first(source->client_tree);
while(client_node) { while(client_node) {
__add_listener((client_t *)client_node->key, parent, now, mode); __add_listener((client_t *)client_node->key, parent, now, mode);
client_node = avl_get_next(client_node); client_node = igloo_avl_get_next(client_node);
} }
avl_tree_unlock(source->client_tree); igloo_avl_tree_unlock(source->client_tree);
} }
static void command_show_listeners(client_t *client, static void command_show_listeners(client_t *client,
...@@ -1044,7 +1044,7 @@ static void command_metadata(client_t *client, ...@@ -1044,7 +1044,7 @@ static void command_metadata(client_t *client,
ICECAST_LOG_DEBUG("Got metadata update request"); ICECAST_LOG_DEBUG("Got metadata update request");
if (source->parser && source->parser->req_type == httpp_req_put) { if (source->parser && source->parser->req_type == igloo_httpp_req_put) {
ICECAST_LOG_ERROR("Got legacy SOURCE-style metadata update command on " ICECAST_LOG_ERROR("Got legacy SOURCE-style metadata update command on "
"source connected with PUT at mountpoint %s", source->mount); "source connected with PUT at mountpoint %s", source->mount);
} }
...@@ -1115,7 +1115,7 @@ static void command_shoutcast_metadata(client_t *client, ...@@ -1115,7 +1115,7 @@ static void command_shoutcast_metadata(client_t *client,
return; return;
} }
if (source->parser->req_type == httpp_req_put) { if (source->parser->req_type == igloo_httpp_req_put) {
ICECAST_LOG_ERROR("Got legacy shoutcast-style metadata update command " ICECAST_LOG_ERROR("Got legacy shoutcast-style metadata update command "
"on source connected with PUT at mountpoint %s", source->mount); "on source connected with PUT at mountpoint %s", source->mount);
} }
...@@ -1200,9 +1200,9 @@ static void command_list_mounts(client_t *client, source_t *source, admin_format ...@@ -1200,9 +1200,9 @@ static void command_list_mounts(client_t *client, source_t *source, admin_format
fserve_add_client (client, NULL); fserve_add_client (client, NULL);
} else { } else {
xmlDocPtr doc; xmlDocPtr doc;
avl_tree_rlock(global.source_tree); igloo_avl_tree_rlock(global.source_tree);
doc = admin_build_sourcelist(NULL); doc = admin_build_sourcelist(NULL);
avl_tree_unlock(global.source_tree); igloo_avl_tree_unlock(global.source_tree);
admin_send_response(doc, client, response, admin_send_response(doc, client, response,
LISTMOUNTS_HTML_REQUEST); LISTMOUNTS_HTML_REQUEST);
......
This diff is collapsed.
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
#include <libxml/parser.h> #include <libxml/parser.h>
#include <libxml/tree.h> #include <libxml/tree.h>
#include "common/thread/thread.h" #include <igloo/thread.h>
#include "common/httpp/httpp.h" #include <igloo/httpp.h>
#include "icecasttypes.h" #include "icecasttypes.h"
#include "cfgfile.h" #include "cfgfile.h"
...@@ -108,7 +108,7 @@ struct auth_tag ...@@ -108,7 +108,7 @@ struct auth_tag
char *mount; char *mount;
/* filters */ /* filters */
auth_matchtype_t filter_method[httpp_req_unknown+1]; auth_matchtype_t filter_method[igloo_httpp_req_unknown+1];
auth_matchtype_t filter_web_policy; auth_matchtype_t filter_web_policy;
auth_matchtype_t filter_admin_policy; auth_matchtype_t filter_admin_policy;
struct { struct {
...@@ -142,11 +142,11 @@ struct auth_tag ...@@ -142,11 +142,11 @@ struct auth_tag
auth_result (*deleteuser)(auth_t *auth, const char *username); auth_result (*deleteuser)(auth_t *auth, const char *username);
auth_result (*listuser)(auth_t *auth, xmlNodePtr srcnode); auth_result (*listuser)(auth_t *auth, xmlNodePtr srcnode);
mutex_t lock; igloo_mutex_t lock;
int running; int running;
size_t refcount; size_t refcount;
thread_type *thread; igloo_thread_type *thread;
/* per-auth queue for clients */ /* per-auth queue for clients */
auth_client *head, **tailp; auth_client *head, **tailp;
...@@ -200,6 +200,6 @@ int auth_stack_push(auth_stack_t **stack, auth_t *auth); ...@@ -200,6 +200,6 @@ int auth_stack_push(auth_stack_t **stack, auth_t *auth);
int auth_stack_append(auth_stack_t *stack, auth_stack_t *tail); int auth_stack_append(auth_stack_t *stack, auth_stack_t *tail);
auth_t *auth_stack_get(auth_stack_t *stack); auth_t *auth_stack_get(auth_stack_t *stack);
auth_t *auth_stack_getbyid(auth_stack_t *stack, unsigned long id); auth_t *auth_stack_getbyid(auth_stack_t *stack, unsigned long id);
acl_t *auth_stack_get_anonymous_acl(auth_stack_t *stack, httpp_request_type_e method); acl_t *auth_stack_get_anonymous_acl(auth_stack_t *stack, igloo_httpp_request_type_e method);
#endif #endif
...@@ -26,11 +26,12 @@ ...@@ -26,11 +26,12 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <igloo/httpp.h>
#include "auth.h" #include "auth.h"
#include "source.h" #include "source.h"
#include "client.h" #include "client.h"
#include "cfgfile.h" #include "cfgfile.h"
#include "common/httpp/httpp.h"
#include "md5.h" #include "md5.h"
#include "logging.h" #include "logging.h"
...@@ -52,8 +53,8 @@ typedef struct { ...@@ -52,8 +53,8 @@ typedef struct {
typedef struct { typedef struct {
char *filename; char *filename;
rwlock_t file_rwlock; igloo_rwlock_t file_rwlock;
avl_tree *users; igloo_avl_tree *users;
time_t mtime; time_t mtime;
} htpasswd_auth_state; } htpasswd_auth_state;
...@@ -62,8 +63,8 @@ static void htpasswd_clear(auth_t *self) ...@@ -62,8 +63,8 @@ static void htpasswd_clear(auth_t *self)
htpasswd_auth_state *state = self->state; htpasswd_auth_state *state = self->state;
free(state->filename); free(state->filename);
if (state->users) if (state->users)
avl_tree_free (state->users, _free_user); igloo_avl_tree_free (state->users, _free_user);
thread_rwlock_destroy(&state->file_rwlock); igloo_thread_rwlock_destroy(&state->file_rwlock);
free(state); free(state);
} }
...@@ -108,7 +109,7 @@ static int _free_user(void *key) ...@@ -108,7 +109,7 @@ static int _free_user(void *key)
static void htpasswd_recheckfile(htpasswd_auth_state *htpasswd) static void htpasswd_recheckfile(htpasswd_auth_state *htpasswd)
{ {
FILE *passwdfile; FILE *passwdfile;
avl_tree *new_users; igloo_avl_tree *new_users;
int num = 0; int num = 0;
struct stat file_stat; struct stat file_stat;
char *sep; char *sep;
...@@ -120,10 +121,10 @@ static void htpasswd_recheckfile(htpasswd_auth_state *htpasswd) ...@@ -120,10 +121,10 @@ static void htpasswd_recheckfile(htpasswd_auth_state *htpasswd)
ICECAST_LOG_WARN("failed to check status of %s", htpasswd->filename); ICECAST_LOG_WARN("failed to check status of %s", htpasswd->filename);
/* Create a dummy users tree for things to use later */ /* Create a dummy users tree for things to use later */
thread_rwlock_wlock (&htpasswd->file_rwlock); igloo_thread_rwlock_wlock (&htpasswd->file_rwlock);
if(!htpasswd->users) if(!htpasswd->users)
htpasswd->users = avl_tree_new(compare_users, NULL); htpasswd->users = igloo_avl_tree_new(compare_users, NULL);
thread_rwlock_unlock (&htpasswd->file_rwlock); igloo_thread_rwlock_unlock (&htpasswd->file_rwlock);
return; return;
} }
...@@ -141,7 +142,7 @@ static void htpasswd_recheckfile(htpasswd_auth_state *htpasswd) ...@@ -141,7 +142,7 @@ static void htpasswd_recheckfile(htpasswd_auth_state *htpasswd)
} }
htpasswd->mtime = file_stat.st_mtime; htpasswd->mtime = file_stat.st_mtime;
new_users = avl_tree_new (compare_users, NULL); new_users = igloo_avl_tree_new (compare_users, NULL);
while (get_line(passwdfile, line, MAX_LINE_LEN)) { while (get_line(passwdfile, line, MAX_LINE_LEN)) {
int len; int len;
...@@ -162,15 +163,15 @@ static void htpasswd_recheckfile(htpasswd_auth_state *htpasswd) ...@@ -162,15 +163,15 @@ static void htpasswd_recheckfile(htpasswd_auth_state *htpasswd)
*sep = 0; *sep = 0;
memcpy (entry->name, line, len); memcpy (entry->name, line, len);
entry->pass = entry->name + (sep-line) + 1; entry->pass = entry->name + (sep-line) + 1;
avl_insert (new_users, entry); igloo_avl_insert (new_users, entry);
} }
fclose (passwdfile); fclose (passwdfile);
thread_rwlock_wlock (&htpasswd->file_rwlock); igloo_thread_rwlock_wlock (&htpasswd->file_rwlock);
if (htpasswd->users) if (htpasswd->users)
avl_tree_free (htpasswd->users, _free_user); igloo_avl_tree_free (htpasswd->users, _free_user);
htpasswd->users = new_users; htpasswd->users = new_users;
thread_rwlock_unlock (&htpasswd->file_rwlock); igloo_thread_rwlock_unlock (&htpasswd->file_rwlock);
} }
...@@ -196,13 +197,13 @@ static auth_result htpasswd_auth (auth_client *auth_user) ...@@ -196,13 +197,13 @@ static auth_result htpasswd_auth (auth_client *auth_user)
return AUTH_NOMATCH; return AUTH_NOMATCH;
} }
thread_rwlock_rlock (&htpasswd->file_rwlock); igloo_thread_rwlock_rlock (&htpasswd->file_rwlock);
entry.name = client->username; entry.name = client->username;
if (avl_get_by_key (htpasswd->users, &entry, &result) == 0) { if (igloo_avl_get_by_key (htpasswd->users, &entry, &result) == 0) {
htpasswd_user *found = result; htpasswd_user *found = result;
char *hashed_pw; char *hashed_pw;
thread_rwlock_unlock (&htpasswd->file_rwlock); igloo_thread_rwlock_unlock (&htpasswd->file_rwlock);
hashed_pw = get_hash (client->password, strlen (client->password)); hashed_pw = get_hash (client->password, strlen (client->password));
if (strcmp (found->pass, hashed_pw) == 0) { if (strcmp (found->pass, hashed_pw) == 0) {
free (hashed_pw); free (hashed_pw);
...@@ -213,7 +214,7 @@ static auth_result htpasswd_auth (auth_client *auth_user) ...@@ -213,7 +214,7 @@ static auth_result htpasswd_auth (auth_client *auth_user)
return AUTH_FAILED; return AUTH_FAILED;
} }
ICECAST_LOG_DEBUG("no such username: %s", client->username); ICECAST_LOG_DEBUG("no such username: %s", client->username);
thread_rwlock_unlock (&htpasswd->file_rwlock); igloo_thread_rwlock_unlock (&htpasswd->file_rwlock);
return AUTH_NOMATCH; return AUTH_NOMATCH;
} }
...@@ -247,7 +248,7 @@ int auth_get_htpasswd_auth (auth_t *authenticator, config_options_t *options) ...@@ -247,7 +248,7 @@ int auth_get_htpasswd_auth (auth_t *authenticator, config_options_t *options)
authenticator->state = state; authenticator->state = state;
thread_rwlock_create(&state->file_rwlock); igloo_thread_rwlock_create(&state->file_rwlock);
htpasswd_recheckfile(state); htpasswd_recheckfile(state);
return 0; return 0;
...@@ -274,18 +275,18 @@ static auth_result htpasswd_adduser (auth_t *auth, const char *username, const c ...@@ -274,18 +275,18 @@ static auth_result htpasswd_adduser (auth_t *auth, const char *username, const c
return AUTH_FAILED; return AUTH_FAILED;
} }
thread_rwlock_wlock (&state->file_rwlock); igloo_thread_rwlock_wlock (&state->file_rwlock);
entry.name = (char*)username; entry.name = (char*)username;
if (avl_get_by_key (state->users, &entry, &result) == 0) { if (igloo_avl_get_by_key (state->users, &entry, &result) == 0) {
thread_rwlock_unlock (&state->file_rwlock); igloo_thread_rwlock_unlock (&state->file_rwlock);
return AUTH_USEREXISTS; return AUTH_USEREXISTS;
} }
passwdfile = fopen(state->filename, "ab"); passwdfile = fopen(state->filename, "ab");
if (passwdfile == NULL) { if (passwdfile == NULL) {
thread_rwlock_unlock (&state->file_rwlock); igloo_thread_rwlock_unlock (&state->file_rwlock);
ICECAST_LOG_WARN("Failed to open authentication database \"%s\": %s", ICECAST_LOG_WARN("Failed to open authentication database \"%s\": %s",
state->filename, strerror(errno)); state->filename, strerror(errno));
return AUTH_FAILED; return AUTH_FAILED;
...@@ -298,7 +299,7 @@ static auth_result htpasswd_adduser (auth_t *auth, const char *username, const c ...@@ -298,7 +299,7 @@ static auth_result htpasswd_adduser (auth_t *auth, const char *username, const c
} }
fclose(passwdfile); fclose(passwdfile);
thread_rwlock_unlock (&state->file_rwlock); igloo_thread_rwlock_unlock (&state->file_rwlock);
return AUTH_USERADDED; return AUTH_USERADDED;
} }
...@@ -327,13 +328,13 @@ static auth_result htpasswd_deleteuser(auth_t *auth, const char *username) ...@@ -327,13 +328,13 @@ static auth_result htpasswd_deleteuser(auth_t *auth, const char *username)
return AUTH_FAILED; return AUTH_FAILED;
} }
thread_rwlock_wlock (&state->file_rwlock); igloo_thread_rwlock_wlock (&state->file_rwlock);
passwdfile = fopen(state->filename, "rb"); passwdfile = fopen(state->filename, "rb");
if(passwdfile == NULL) { if(passwdfile == NULL) {
ICECAST_LOG_WARN("Failed to open authentication database \"%s\": %s", ICECAST_LOG_WARN("Failed to open authentication database \"%s\": %s",
state->filename, strerror(errno)); state->filename, strerror(errno));
thread_rwlock_unlock (&state->file_rwlock); igloo_thread_rwlock_unlock (&state->file_rwlock);
return AUTH_FAILED; return AUTH_FAILED;
} }
tmpfile_len = strlen(state->filename) + 6; tmpfile_len = strlen(state->filename) + 6;
...@@ -343,7 +344,7 @@ static auth_result htpasswd_deleteuser(auth_t *auth, const char *username) ...@@ -343,7 +344,7 @@ static auth_result htpasswd_deleteuser(auth_t *auth, const char *username)
ICECAST_LOG_WARN("temp file \"%s\" exists, rejecting operation", tmpfile); ICECAST_LOG_WARN("temp file \"%s\" exists, rejecting operation", tmpfile);
free (tmpfile); free (tmpfile);
fclose (passwdfile); fclose (passwdfile);
thread_rwlock_unlock (&state->file_rwlock); igloo_thread_rwlock_unlock (&state->file_rwlock);
return AUTH_FAILED; return AUTH_FAILED;
} }
...@@ -354,7 +355,7 @@ static auth_result htpasswd_deleteuser(auth_t *auth, const char *username) ...@@ -354,7 +355,7 @@ static auth_result htpasswd_deleteuser(auth_t *auth, const char *username)
tmpfile, strerror(errno)); tmpfile, strerror(errno));
fclose(passwdfile); fclose(passwdfile);
free(tmpfile); free(tmpfile);
thread_rwlock_unlock (&state->file_rwlock); igloo_thread_rwlock_unlock (&state->file_rwlock);
return AUTH_FAILED; return AUTH_FAILED;
} }
...@@ -394,7 +395,7 @@ static auth_result htpasswd_deleteuser(auth_t *auth, const char *username) ...@@ -394,7 +395,7 @@ static auth_result htpasswd_deleteuser(auth_t *auth, const char *username)
} }
} }
free(tmpfile); free(tmpfile);
thread_rwlock_unlock(&state->file_rwlock); igloo_thread_rwlock_unlock(&state->file_rwlock);
htpasswd_recheckfile(state); htpasswd_recheckfile(state);
return AUTH_USERDELETED; return AUTH_USERDELETED;
...@@ -405,7 +406,7 @@ static auth_result htpasswd_userlist(auth_t *auth, xmlNodePtr srcnode) ...@@ -405,7 +406,7 @@ static auth_result htpasswd_userlist(auth_t *auth, xmlNodePtr srcnode)
{ {
htpasswd_auth_state *state; htpasswd_auth_state *state;
xmlNodePtr newnode; xmlNodePtr newnode;
avl_node *node; igloo_avl_node *node;
state = auth->state; state = auth->state;
...@@ -421,15 +422,15 @@ static auth_result htpasswd_userlist(auth_t *auth, xmlNodePtr srcnode) ...@@ -421,15 +422,15 @@ static auth_result htpasswd_userlist(auth_t *auth, xmlNodePtr srcnode)
return AUTH_FAILED; return AUTH_FAILED;
} }
thread_rwlock_rlock(&state->file_rwlock); igloo_thread_rwlock_rlock(&state->file_rwlock);
node = avl_get_first(state->users); node = igloo_avl_get_first(state->users);
while (node) { while (node) {
htpasswd_user *user = (htpasswd_user *)node->key; htpasswd_user *user = (htpasswd_user *)node->key;
newnode = xmlNewChild(srcnode, NULL, XMLSTR("user"), NULL); newnode = xmlNewChild(srcnode, NULL, XMLSTR("user"), NULL);
xmlNewTextChild(newnode, NULL, XMLSTR("username"), XMLSTR(user->name)); xmlNewTextChild(newnode, NULL, XMLSTR("username"), XMLSTR(user->name));
node = avl_get_next(node); node = igloo_avl_get_next(node);
} }
thread_rwlock_unlock(&state->file_rwlock); igloo_thread_rwlock_unlock(&state->file_rwlock);
return AUTH_OK; return AUTH_OK;
} }
...@@ -74,7 +74,8 @@ ...@@ -74,7 +74,8 @@
#include "client.h" #include "client.h"
#include "cfgfile.h" #include "cfgfile.h"
#include "connection.h" #include "connection.h"
#include "common/httpp/httpp.h"
#include <igloo/httpp.h>
#include "logging.h" #include "logging.h"
#define CATMODULE "auth_url" #define CATMODULE "auth_url"
...@@ -120,7 +121,7 @@ typedef struct { ...@@ -120,7 +121,7 @@ typedef struct {
typedef struct { typedef struct {
char *all_headers; char *all_headers;
size_t all_headers_len; size_t all_headers_len;
http_parser_t *parser; igloo_http_parser_t *parser;
} auth_user_url_t; } auth_user_url_t;
static inline const char * __str_or_default(const char *str, const char *def) static inline const char * __str_or_default(const char *str, const char *def)
...@@ -166,7 +167,7 @@ static void auth_user_url_clear(auth_client *auth_user) ...@@ -166,7 +167,7 @@ static void auth_user_url_clear(auth_client *auth_user)
free(au_url->all_headers); free(au_url->all_headers);
if (au_url->parser) if (au_url->parser)
httpp_destroy(au_url->parser); igloo_httpp_destroy(au_url->parser);
free(au_url); free(au_url);
auth_user->authbackend_userdata = NULL; auth_user->authbackend_userdata = NULL;
...@@ -186,34 +187,34 @@ static void handle_returned_header__complete(auth_client *auth_user) ...@@ -186,34 +187,34 @@ static void handle_returned_header__complete(auth_client *auth_user)
if (au_url->parser) if (au_url->parser)
return; return;
au_url->parser = httpp_create_parser(); au_url->parser = igloo_httpp_create_parser();
httpp_initialize(au_url->parser, NULL); igloo_httpp_initialize(au_url->parser, NULL);
if (!httpp_parse_response(au_url->parser, au_url->all_headers, au_url->all_headers_len, NULL)) { if (!igloo_httpp_parse_response(au_url->parser, au_url->all_headers, au_url->all_headers_len, NULL)) {
ICECAST_LOG_ERROR("Can not parse auth backend reply."); ICECAST_LOG_ERROR("Can not parse auth backend reply.");
return; return;
} }
tmp = httpp_getvar(au_url->parser, HTTPP_VAR_ERROR_CODE); tmp = igloo_httpp_getvar(au_url->parser, igloo_HTTPP_VAR_ERROR_CODE);
if (tmp[0] == '2') { if (tmp[0] == '2') {
ICECAST_LOG_DEBUG("Got final status: %#H", tmp); ICECAST_LOG_DEBUG("Got final status: %#H", tmp);
} else { } else {
ICECAST_LOG_DEBUG("Got non-final status: %#H", tmp); ICECAST_LOG_DEBUG("Got non-final status: %#H", tmp);
httpp_destroy(au_url->parser); igloo_httpp_destroy(au_url->parser);
au_url->parser = NULL; au_url->parser = NULL;
au_url->all_headers_len = 0; au_url->all_headers_len = 0;
return; return;
} }
if (url->header_auth) { if (url->header_auth) {
tmp = httpp_getvar(au_url->parser, url->header_auth); tmp = igloo_httpp_getvar(au_url->parser, url->header_auth);
if (tmp) { if (tmp) {
url->result = auth_str2result(tmp); url->result = auth_str2result(tmp);
} }
} }
if (url->header_timelimit) { if (url->header_timelimit) {
tmp = httpp_getvar(au_url->parser, url->header_timelimit); tmp = igloo_httpp_getvar(au_url->parser, url->header_timelimit);
if (tmp) { if (tmp) {
long long int ret; long long int ret;
char *endptr; char *endptr;
...@@ -228,8 +229,8 @@ static void handle_returned_header__complete(auth_client *auth_user) ...@@ -228,8 +229,8 @@ static void handle_returned_header__complete(auth_client *auth_user)
} }
} }
action = httpp_getvar(au_url->parser, __str_or_default(url->header_alter_action, DEFAULT_HEADER_NEW_ALTER_ACTION)); action = igloo_httpp_getvar(au_url->parser, __str_or_default(url->header_alter_action, DEFAULT_HEADER_NEW_ALTER_ACTION));
argument = httpp_getvar(au_url->parser, __str_or_default(url->header_alter_argument, DEFAULT_HEADER_NEW_ALTER_ARGUMENT)); argument = igloo_httpp_getvar(au_url->parser, __str_or_default(url->header_alter_argument, DEFAULT_HEADER_NEW_ALTER_ARGUMENT));
if (action && argument) { if (action && argument) {
if (auth_alter_client(auth_user->client->auth, auth_user, auth_str2alter(action), argument) != 0) { if (auth_alter_client(auth_user->client->auth, auth_user, auth_str2alter(action), argument) != 0) {
...@@ -240,11 +241,11 @@ static void handle_returned_header__complete(auth_client *auth_user) ...@@ -240,11 +241,11 @@ static void handle_returned_header__complete(auth_client *auth_user)
} }
if (url->header_message) { if (url->header_message) {
tmp = httpp_getvar(au_url->parser, url->header_message); tmp = igloo_httpp_getvar(au_url->parser, url->header_message);
} else { } else {
tmp = httpp_getvar(au_url->parser, DEFAULT_HEADER_NEW_MESSAGE); tmp = igloo_httpp_getvar(au_url->parser, DEFAULT_HEADER_NEW_MESSAGE);
if (!tmp) if (!tmp)
tmp = httpp_getvar(au_url->parser, DEFAULT_HEADER_OLD_MESSAGE); tmp = igloo_httpp_getvar(au_url->parser, DEFAULT_HEADER_OLD_MESSAGE);
} }
if (tmp) { if (tmp) {
snprintf(url->errormsg, sizeof(url->errormsg), "%s", tmp); snprintf(url->errormsg, sizeof(url->errormsg), "%s", tmp);
...@@ -353,7 +354,7 @@ static auth_result url_remove_client(auth_client *auth_user) ...@@ -353,7 +354,7 @@ static auth_result url_remove_client(auth_client *auth_user)
port = config->port; port = config->port;
config_release_config(); config_release_config();
agent = httpp_getvar(client->parser, "user-agent"); agent = igloo_httpp_getvar(client->parser, "user-agent");
if (agent) { if (agent) {
user_agent = util_url_escape(agent); user_agent = util_url_escape(agent);
} else { } else {
...@@ -373,9 +374,9 @@ static auth_result url_remove_client(auth_client *auth_user) ...@@ -373,9 +374,9 @@ static auth_result url_remove_client(auth_client *auth_user)
} }
/* get the full uri (with query params if available) */ /* get the full uri (with query params if available) */
mountreq = httpp_getvar(client->parser, HTTPP_VAR_RAWURI); mountreq = igloo_httpp_getvar(client->parser, igloo_HTTPP_VAR_RAWURI);
if (mountreq == NULL) if (mountreq == NULL)
mountreq = httpp_getvar(client->parser, HTTPP_VAR_URI); mountreq = igloo_httpp_getvar(client->parser, igloo_HTTPP_VAR_URI);
mount = util_url_escape(mountreq); mount = util_url_escape(mountreq);
ipaddr = util_url_escape(client->con->ip); ipaddr = util_url_escape(client->con->ip);
...@@ -466,7 +467,7 @@ static auth_result url_add_client(auth_client *auth_user) ...@@ -466,7 +467,7 @@ static auth_result url_add_client(auth_client *auth_user)
port = config->port; port = config->port;
config_release_config(); config_release_config();
agent = httpp_getvar(client->parser, "user-agent"); agent = igloo_httpp_getvar(client->parser, "user-agent");
if (agent) { if (agent) {
user_agent = util_url_escape(agent); user_agent = util_url_escape(agent);
} else { } else {
...@@ -486,9 +487,9 @@ static auth_result url_add_client(auth_client *auth_user) ...@@ -486,9 +487,9 @@ static auth_result url_add_client(auth_client *auth_user)
} }
/* get the full uri (with query params if available) */ /* get the full uri (with query params if available) */
mountreq = httpp_getvar(client->parser, HTTPP_VAR_RAWURI); mountreq = igloo_httpp_getvar(client->parser, igloo_HTTPP_VAR_RAWURI);
if (mountreq == NULL) if (mountreq == NULL)
mountreq = httpp_getvar(client->parser, HTTPP_VAR_URI); mountreq = igloo_httpp_getvar(client->parser, igloo_HTTPP_VAR_URI);
mount = util_url_escape(mountreq); mount = util_url_escape(mountreq);
ipaddr = util_url_escape(client->con->ip); ipaddr = util_url_escape(client->con->ip);
...@@ -525,7 +526,7 @@ static auth_result url_add_client(auth_client *auth_user) ...@@ -525,7 +526,7 @@ static auth_result url_add_client(auth_client *auth_user)
next_header++; next_header++;
} }
header_val = httpp_getvar (client->parser, cur_header); header_val = igloo_httpp_getvar (client->parser, cur_header);
if (header_val) { if (header_val) {
size_t left = sizeof(post) - post_offset; size_t left = sizeof(post) - post_offset;
int ret; int ret;
......
/* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "buffer.h"
#include "refobject.h"
struct buffer_tag {
refobject_base_t __base;
/* Buffer itself */
void *buffer;
/* Length in bytes of buffer */
size_t length;
/* Amount of bytes in use of the buffer. This includes offset bytes */
size_t fill;
/* Bytes of offset at the start of the buffer */
size_t offset;
};
static void __free(refobject_t self, void **userdata)
{
buffer_t *buffer = REFOBJECT_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 = refobject_new_ext(buffer_t, userdata, name, associated);
if (!buffer)
return NULL;
if (preallocation > 0)
buffer_preallocate(buffer, preallocation);
return buffer;
}
buffer_t * buffer_new_simple(void)
{
return refobject_new(buffer_t);
}
void buffer_preallocate(buffer_t *buffer, size_t request)
{
void *n;
size_t newlen;
if (!buffer)
return;
/* Remove the offset if it makes sense to do so. */
if (buffer->offset == buffer->fill) {
buffer->offset = 0;
buffer->fill = 0;
} else if ((2*buffer->offset) < buffer->fill || buffer->offset >= 512 || (buffer->offset > 128 && buffer->offset >= request)) {
buffer->fill -= buffer->offset;
memmove(buffer->buffer, buffer->buffer + buffer->offset, buffer->fill);
buffer->offset = 0;
}
if (!request)
return;
newlen = buffer->fill + request;
if (buffer->length >= newlen)
return;
/* Make sure we at least add 64 bytes and are 64 byte aligned */
newlen = newlen + 64 - (newlen % 64);
n = realloc(buffer->buffer, newlen);
/* Just return if this failed */
if (!n)
return;
buffer->buffer = n;
buffer->length = newlen;
}
int buffer_get_data(buffer_t *buffer, const void **data, size_t *length)
{
if (!buffer)
return -1;
if (data) {
*data = buffer->buffer + buffer->offset;
}
if (length) {
*length = buffer->fill - buffer->offset;
}
return 0;
}
int buffer_get_string(buffer_t *buffer, const char **string)
{
char *ret;
if (!buffer || !string)
return -1;
/* Ensure we have space for one additional byte ('\0'-termination). */
if (buffer->length == buffer->fill) {
buffer_preallocate(buffer, 1);
if (buffer->length == buffer->fill)
return -1;
}
/* Actually add a '\0'-termination. */
ret = buffer->buffer;
ret[buffer->fill] = 0;
*string = ret + buffer->offset;
return 0;
}
int buffer_set_length(buffer_t *buffer, size_t length)
{
if (!buffer)
return -1;
if (length > (buffer->fill - buffer->offset))
return -1;
buffer->fill = length + buffer->offset;
return 0;
}
int buffer_shift(buffer_t *buffer, size_t amount)
{
if (!buffer)
return -1;
if (amount > (buffer->fill - buffer->offset))
return -1;
buffer->offset += amount;
/* run cleanup */
buffer_preallocate(buffer, 0);
return 0;
}
int buffer_push_data(buffer_t *buffer, const void *data, size_t length)
{
void *buf;
int ret;
if (!buffer)
return -1;
if (!length)
return 0;
if (!data)
return -1;
ret = buffer_zerocopy_push_request(buffer, &buf, length);
if (ret != 0)
return ret;
memcpy(buf, data, length);
ret = buffer_zerocopy_push_complete(buffer, length);
return ret;
}
int buffer_push_string(buffer_t *buffer, const char *string)
{
if (!buffer || !string)
return -1;
return buffer_push_data(buffer, string, strlen(string));
}
int buffer_push_printf(buffer_t *buffer, const char *format, ...)
{
int ret;
va_list ap;
if (!buffer || !format)
return -1;
if (!*format)
return 0;
va_start(ap, format);
ret = buffer_push_vprintf(buffer, format, ap);
va_end(ap);
return ret;
}
int buffer_push_vprintf(buffer_t *buffer, const char *format, va_list ap)
{
void *buf;
int ret;
size_t length = 1024;
if (!buffer || !format)
return -1;
if (!*format)
return 0;
ret = buffer_zerocopy_push_request(buffer, &buf, length);
if (ret != 0)
return ret;
ret = vsnprintf(buf, length, format, ap);
if (ret >= 0 && (size_t)ret < length) {
return buffer_zerocopy_push_complete(buffer, ret);
} else if (ret < 0) {
/* This vsnprintf() likely does not follow POSIX.
* We don't know what length we need to asume. So asume a big one and hope for the best. */
length = 8192;
} else {
/* Reallocate the buffer to the size reported plus one for '\0'-termination */
length = ret + 1;
}
/* We have not written any data yet. */
ret = buffer_zerocopy_push_complete(buffer, 0);
if (ret != 0)
return ret;
/* Now let's try again. */
ret = buffer_zerocopy_push_request(buffer, &buf, length);
if (ret != 0)
return ret;
ret = vsnprintf(buf, length, format, ap);
if (ret < 0 || (size_t)ret >= length) {
/* This still didn't work. Giving up. */
buffer_zerocopy_push_complete(buffer, 0);
return -1;
}
return buffer_zerocopy_push_complete(buffer, ret);
}
int buffer_push_buffer(buffer_t *buffer, buffer_t *source)
{
const void *data;
size_t length;
int ret;
if (!buffer || !source)
return -1;
ret = buffer_get_data(source, &data, &length);
if (ret != 0)
return ret;
return buffer_push_data(buffer, data, length);
}
int buffer_zerocopy_push_request(buffer_t *buffer, void **data, size_t request)
{
if (!buffer || !data)
return -1;
buffer_preallocate(buffer, request);
if (request > (buffer->length - buffer->fill))
return -1;
*data = buffer->buffer + buffer->fill;
return 0;
}
int buffer_zerocopy_push_complete(buffer_t *buffer, size_t done)
{
if (!buffer)
return -1;
if (done > (buffer->length - buffer->fill))
return -1;
buffer->fill += done;
return 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 a refobject based buffer object.
* It can be used to store data and allows on the fly re-allocation.
*/
#ifndef __BUFFER_H__
#define __BUFFER_H__
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdarg.h>
#include "icecasttypes.h"
#include "compat.h"
#include "refobject.h"
/* About thread safety:
* This set of functions is intentinally not thread safe.
*/
REFOBJECT_FORWARD_TYPE(buffer_t);
/* This creates a new buffer object.
* Parameters:
* preallocation
* The number of bytes to allocate for use later on. See buffer_preallocate() for details.
* userdata, name, associated
* See refobject_new().
*/
buffer_t * buffer_new(ssize_t preallocation, void *userdata, const char *name, refobject_t associated);
/* Depreciated: This creates a new buffer with defaults.
* Do NOT use this. Use refobject_new(buffer_t)
*
* This is the same as:
* buffer_new(-1, NULL, NULL, REFOBJECT_NULL)
*/
buffer_t * buffer_new_simple(void);
/* This function preallocates space for later use.
* Parameters:
* buffer
* The buffer to operate on.
* request
* Number of bytes to additionally allocate.
* Notes:
* This function is very usedful when adding a large number of smaller buffers to avoid
* internal reallocation calls happening to often. However it is not required to call
* this function before adding data to the buffer.
*/
void buffer_preallocate(buffer_t *buffer, size_t request);
/* Gets data and length of the buffer.
* Parameters:
* buffer
* The buffer to operate on.
* data
* Pointer to the stored data. If NULL the pointer is not returned.
* length
* Pointer to the length of how many bytes are in the buffer. If NULL
* length is not returned.
*/
int buffer_get_data(buffer_t *buffer, const void **data, size_t *length);
/* Gets data as a string. The string is '\0'-terminated.
* Parameters:
* buffery
* The buffer to operate on.
* string
* The string representing the data hold by the buffer.
*/
int buffer_get_string(buffer_t *buffer, const char **string);
/* Sets the length of the buffer.
* Parameters:
* buffer
* The buffer to operate on.
* length
* New length of the buffer.
* Notes:
* This can only be used to reduce the size of the buffer. To add data to
* the buffer use buffer_push_*().
*
* Calling this with length set to 0 clears the buffer but does not deallocate it.
*/
int buffer_set_length(buffer_t *buffer, size_t length);
/* Shifts data out of the buffer.
* Parameters:
* buffer
* The buffer to operate on.
* amount
* The amount of bytes to be removed from the begin of the buffer.
* Notes:
* This function can be useful for skipping some small header. However this
* must not be used to implement a kind of ring buffer as it will result in
* poor performance caused by massive reallocations and memory copies.
*/
int buffer_shift(buffer_t *buffer, size_t amount);
/* This pushes data to the end of the buffer.
* Parameters:
* buffer
* The buffer to operate on.
* data
* The data to push.
* length
* The length of the data to push in byte.
* Notes:
* Consider using buffer_zerocopy_*().
*/
int buffer_push_data(buffer_t *buffer, const void *data, size_t length);
/* This pushes a string to the end of the buffer.
* Parameters:
* buffer
* The buffer to operate on.
* string
* The string to be pushed. The tailing '\0'-termination will not be
* part of the buffer.
* Notes:
* Consider using buffer_zerocopy_*().
*/
int buffer_push_string(buffer_t *buffer, const char *string);
/* This pushes a formated string to the end of the buffer.
* Parameters:
* buffer
* The buffer to operate on.
* format
* The format string as for printf() family functions.
* ...
* The parameters according to the format string.
*/
int buffer_push_printf(buffer_t *buffer, const char *format, ...);
/* This pushes a formated string to the end of the buffer using a va_list.
* Parameters:
* buffer
* The buffer to operate on.
* format
* The format string as for printf() family functions.
* ap
* The parameters according to the format string as va_list.
* See also:
* vprintf(3).
*/
int buffer_push_vprintf(buffer_t *buffer, const char *format, va_list ap);
/* This pushes the content of another buffer to the end of the buffer.
* Parameters:
* buffer
* The buffer to operate on.
* source
* The buffer which's content is to be copied.
*/
int buffer_push_buffer(buffer_t *buffer, buffer_t *source);
/* This requests for a memory buffer that can be pushed to without the need for copy.
* Parameters:
* buffer
* The buffer to operate on.
* data
* Pointer to memory that can be written and will become part of the buffer object.
* request
* Size of the memory area that is returned by data in bytes.
* Notes:
* This is the first step of the zero copy push. After the memory returned by data has been
* written (e.g. used in a call to read(2)) buffer_zerocopy_push_complete() must be called.
*/
int buffer_zerocopy_push_request(buffer_t *buffer, void **data, size_t request);
/* This is the final step of a zero copy push.
* Parameters:
* buffer
* The buffer to operate on.
* done
* Amount of data in bytes that has actually been written into the memory area.
* May be zero to what has been requested with request.
*/
int buffer_zerocopy_push_complete(buffer_t *buffer, size_t done);
#endif
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include <libxml/xmlmemory.h> #include <libxml/xmlmemory.h>
#include <libxml/parser.h> #include <libxml/parser.h>
#include "common/thread/thread.h" #include <igloo/thread.h>
#include "cfgfile.h" #include "cfgfile.h"
#include "global.h" #include "global.h"
...@@ -34,8 +34,7 @@ ...@@ -34,8 +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"
/* for config_reread_config() */ /* for config_reread_config() */
#include "yp.h" #include "yp.h"
...@@ -231,14 +230,14 @@ char * config_href_to_id(const char *href) ...@@ -231,14 +230,14 @@ char * config_href_to_id(const char *href)
static void create_locks(void) static void create_locks(void)
{ {
thread_mutex_create(&_locks.relay_lock); igloo_thread_mutex_create(&_locks.relay_lock);
thread_rwlock_create(&_locks.config_lock); igloo_thread_rwlock_create(&_locks.config_lock);
} }
static void