0
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2025-06-30 22:18:19 -04:00

Cleanup: Remove redundant passing of client's uri

This commit is contained in:
Philipp Schafft 2018-09-13 13:38:57 +00:00
parent e4560e15a2
commit c97e5d95fc
6 changed files with 55 additions and 55 deletions

View File

@ -809,10 +809,10 @@ int connection_complete_source(source_t *source, int response)
return -1; return -1;
} }
static inline void source_startup(client_t *client, const char *uri) static inline void source_startup(client_t *client)
{ {
source_t *source; source_t *source;
source = source_reserve(uri); source = source_reserve(client->uri);
if (source) { if (source) {
source->client = client; source->client = client;
@ -872,27 +872,27 @@ static inline void source_startup(client_t *client, const char *uri)
} }
} else { } else {
client_send_error_by_id(client, ICECAST_ERROR_CON_MOUNT_IN_USE); client_send_error_by_id(client, ICECAST_ERROR_CON_MOUNT_IN_USE);
ICECAST_LOG_WARN("Mountpoint %s in use", uri); ICECAST_LOG_WARN("Mountpoint %s in use", client->uri);
} }
} }
/* only called for native icecast source clients */ /* only called for native icecast source clients */
static void _handle_source_request(client_t *client, const char *uri) static void _handle_source_request(client_t *client)
{ {
ICECAST_LOG_INFO("Source logging in at mountpoint \"%s\" from %s as role %s", ICECAST_LOG_INFO("Source logging in at mountpoint \"%s\" from %s as role %s",
uri, client->con->ip, client->role); client->uri, client->con->ip, client->role);
if (uri[0] != '/') { if (client->uri[0] != '/') {
ICECAST_LOG_WARN("source mountpoint not starting with /"); ICECAST_LOG_WARN("source mountpoint not starting with /");
client_send_error_by_id(client, ICECAST_ERROR_CON_MOUNTPOINT_NOT_STARTING_WITH_SLASH); client_send_error_by_id(client, ICECAST_ERROR_CON_MOUNTPOINT_NOT_STARTING_WITH_SLASH);
return; return;
} }
source_startup(client, uri); source_startup(client);
} }
static void _handle_stats_request(client_t *client, char *uri) static void _handle_stats_request(client_t *client)
{ {
stats_event_inc(NULL, "stats_connections"); stats_event_inc(NULL, "stats_connections");
@ -988,10 +988,10 @@ static inline ssize_t __count_user_role_on_mount (source_t *source, client_t *cl
return ret; return ret;
} }
static void _handle_get_request(client_t *client, char *uri) { static void _handle_get_request(client_t *client) {
source_t *source = NULL; source_t *source = NULL;
ICECAST_LOG_DEBUG("Got client %p with URI %H", client, uri); ICECAST_LOG_DEBUG("Got client %p with URI %H", client, client->uri);
/* there are several types of HTTP GET clients /* there are several types of HTTP GET clients
* media clients, which are looking for a source (eg, URI = /stream.ogg), * media clients, which are looking for a source (eg, URI = /stream.ogg),
@ -1017,16 +1017,16 @@ static void _handle_get_request(client_t *client, char *uri) {
return; return;
} }
if (util_check_valid_extension(uri) == XSLT_CONTENT) { if (util_check_valid_extension(client->uri) == XSLT_CONTENT) {
/* If the file exists, then transform it, otherwise, write a 404 */ /* If the file exists, then transform it, otherwise, write a 404 */
ICECAST_LOG_DEBUG("Stats request, sending XSL transformed stats"); ICECAST_LOG_DEBUG("Stats request, sending XSL transformed stats");
stats_transform_xslt(client, uri); stats_transform_xslt(client);
return; return;
} }
avl_tree_rlock(global.source_tree); avl_tree_rlock(global.source_tree);
/* let's see if this is a source or just a random fserve file */ /* let's see if this is a source or just a random fserve file */
source = source_find_mount(uri); source = source_find_mount(client->uri);
if (source) { if (source) {
/* true mount */ /* true mount */
int in_error = 0; int in_error = 0;
@ -1061,7 +1061,7 @@ static void _handle_get_request(client_t *client, char *uri) {
} else { } else {
/* file */ /* file */
avl_tree_unlock(global.source_tree); avl_tree_unlock(global.source_tree);
fserve_client_create(client, uri); fserve_client_create(client);
} }
} }
@ -1272,7 +1272,7 @@ static void _handle_admin_request(client_t *client, char *adminuri)
/* Handle any client that passed the authing process. /* Handle any client that passed the authing process.
*/ */
static void _handle_authed_client(client_t *client, void *uri, auth_result result) static void _handle_authed_client(client_t *client, void *userdata, auth_result result)
{ {
auth_stack_release(client->authstack); auth_stack_release(client->authstack);
client->authstack = NULL; client->authstack = NULL;
@ -1285,25 +1285,25 @@ static void _handle_authed_client(client_t *client, void *uri, auth_result resul
} }
if (acl_test_method(client->acl, client->parser->req_type) != ACL_POLICY_ALLOW) { if (acl_test_method(client->acl, client->parser->req_type) != ACL_POLICY_ALLOW) {
ICECAST_LOG_ERROR("Client (role=%s, username=%s) not allowed to use this request method on %H", client->role, client->username, uri); ICECAST_LOG_ERROR("Client (role=%s, username=%s) not allowed to use this request method on %H", client->role, client->username, client->uri);
client_send_error_by_id(client, ICECAST_ERROR_GEN_CLIENT_NEEDS_TO_AUTHENTICATE); client_send_error_by_id(client, ICECAST_ERROR_GEN_CLIENT_NEEDS_TO_AUTHENTICATE);
return; return;
} }
/* Dispatch legacy admin.cgi requests */ /* Dispatch legacy admin.cgi requests */
if (strcmp(uri, "/admin.cgi") == 0) { if (strcmp(client->uri, "/admin.cgi") == 0) {
_handle_admin_request(client, uri + 1); _handle_admin_request(client, client->uri + 1);
return; return;
} /* Dispatch all admin requests */ } /* Dispatch all admin requests */
else if (strncmp(uri, "/admin/", 7) == 0) { else if (strncmp(client->uri, "/admin/", 7) == 0) {
_handle_admin_request(client, uri + 7); _handle_admin_request(client, client->uri + 7);
return; return;
} }
if (client->handler_module && client->handler_function) { if (client->handler_module && client->handler_function) {
const module_client_handler_t *handler = module_get_client_handler(client->handler_module, client->handler_function); const module_client_handler_t *handler = module_get_client_handler(client->handler_module, client->handler_function);
if (handler) { if (handler) {
handler->cb(client->handler_module, client, uri); handler->cb(client->handler_module, client);
return; return;
} else { } else {
ICECAST_LOG_ERROR("No such handler function in module: %s", client->handler_function); ICECAST_LOG_ERROR("No such handler function in module: %s", client->handler_function);
@ -1313,15 +1313,15 @@ static void _handle_authed_client(client_t *client, void *uri, auth_result resul
switch (client->parser->req_type) { switch (client->parser->req_type) {
case httpp_req_source: case httpp_req_source:
case httpp_req_put: case httpp_req_put:
_handle_source_request(client, uri); _handle_source_request(client);
break; break;
case httpp_req_stats: case httpp_req_stats:
_handle_stats_request(client, uri); _handle_stats_request(client);
break; break;
case httpp_req_get: case httpp_req_get:
case httpp_req_post: case httpp_req_post:
case httpp_req_options: case httpp_req_options:
_handle_get_request(client, uri); _handle_get_request(client);
break; break;
default: default:
ICECAST_LOG_ERROR("Wrong request type from client"); ICECAST_LOG_ERROR("Wrong request type from client");
@ -1333,7 +1333,7 @@ static void _handle_authed_client(client_t *client, void *uri, auth_result resul
/* Handle clients that still need to authenticate. /* Handle clients that still need to authenticate.
*/ */
static void _handle_authentication_global(client_t *client, void *uri, auth_result result) static void _handle_authentication_global(client_t *client, void *userdata, auth_result result)
{ {
ice_config_t *config; ice_config_t *config;
@ -1342,13 +1342,13 @@ static void _handle_authentication_global(client_t *client, void *uri, auth_resu
if (result != AUTH_NOMATCH && if (result != AUTH_NOMATCH &&
!(result == AUTH_OK && client->admin_command != ADMIN_COMMAND_ERROR && acl_test_admin(client->acl, client->admin_command) == ACL_POLICY_DENY)) { !(result == AUTH_OK && client->admin_command != ADMIN_COMMAND_ERROR && acl_test_admin(client->acl, client->admin_command) == ACL_POLICY_DENY)) {
_handle_authed_client(client, uri, result); _handle_authed_client(client, userdata, result);
return; return;
} }
ICECAST_LOG_DEBUG("Trying global authenticators for client %p.", client); ICECAST_LOG_DEBUG("Trying global authenticators for client %p.", client);
config = config_get_config(); config = config_get_config();
auth_stack_add_client(config->authstack, client, _handle_authed_client, uri); auth_stack_add_client(config->authstack, client, _handle_authed_client, userdata);
config_release_config(); config_release_config();
} }
@ -1360,14 +1360,14 @@ static inline mount_proxy * __find_non_admin_mount(ice_config_t *config, const c
return config_find_mount(config, name, type); return config_find_mount(config, name, type);
} }
static void _handle_authentication_mount_generic(client_t *client, void *uri, mount_type type, void (*callback)(client_t*, void*, auth_result)) static void _handle_authentication_mount_generic(client_t *client, void *userdata, mount_type type, void (*callback)(client_t*, void*, auth_result))
{ {
ice_config_t *config; ice_config_t *config;
mount_proxy *mountproxy; mount_proxy *mountproxy;
auth_stack_t *stack = NULL; auth_stack_t *stack = NULL;
config = config_get_config(); config = config_get_config();
mountproxy = __find_non_admin_mount(config, uri, type); mountproxy = __find_non_admin_mount(config, client->uri, type);
if (!mountproxy) { if (!mountproxy) {
int command_type = admin_get_command_type(client->admin_command); int command_type = admin_get_command_type(client->admin_command);
if (command_type == ADMINTYPE_MOUNT || command_type == ADMINTYPE_HYBRID) { if (command_type == ADMINTYPE_MOUNT || command_type == ADMINTYPE_HYBRID) {
@ -1382,44 +1382,44 @@ static void _handle_authentication_mount_generic(client_t *client, void *uri, mo
config_release_config(); config_release_config();
if (stack) { if (stack) {
auth_stack_add_client(stack, client, callback, uri); auth_stack_add_client(stack, client, callback, userdata);
auth_stack_release(stack); auth_stack_release(stack);
} else { } else {
callback(client, uri, AUTH_NOMATCH); callback(client, userdata, AUTH_NOMATCH);
} }
} }
static void _handle_authentication_mount_default(client_t *client, void *uri, auth_result result) static void _handle_authentication_mount_default(client_t *client, void *userdata, auth_result result)
{ {
auth_stack_release(client->authstack); auth_stack_release(client->authstack);
client->authstack = NULL; client->authstack = NULL;
if (result != AUTH_NOMATCH && if (result != AUTH_NOMATCH &&
!(result == AUTH_OK && client->admin_command != ADMIN_COMMAND_ERROR && acl_test_admin(client->acl, client->admin_command) == ACL_POLICY_DENY)) { !(result == AUTH_OK && client->admin_command != ADMIN_COMMAND_ERROR && acl_test_admin(client->acl, client->admin_command) == ACL_POLICY_DENY)) {
_handle_authed_client(client, uri, result); _handle_authed_client(client, userdata, result);
return; return;
} }
ICECAST_LOG_DEBUG("Trying <mount type=\"default\"> specific authenticators for client %p.", client); ICECAST_LOG_DEBUG("Trying <mount type=\"default\"> specific authenticators for client %p.", client);
_handle_authentication_mount_generic(client, uri, MOUNT_TYPE_DEFAULT, _handle_authentication_global); _handle_authentication_mount_generic(client, userdata, MOUNT_TYPE_DEFAULT, _handle_authentication_global);
} }
static void _handle_authentication_mount_normal(client_t *client, void *uri, auth_result result) static void _handle_authentication_mount_normal(client_t *client, void *userdata, auth_result result)
{ {
auth_stack_release(client->authstack); auth_stack_release(client->authstack);
client->authstack = NULL; client->authstack = NULL;
if (result != AUTH_NOMATCH && if (result != AUTH_NOMATCH &&
!(result == AUTH_OK && client->admin_command != ADMIN_COMMAND_ERROR && acl_test_admin(client->acl, client->admin_command) == ACL_POLICY_DENY)) { !(result == AUTH_OK && client->admin_command != ADMIN_COMMAND_ERROR && acl_test_admin(client->acl, client->admin_command) == ACL_POLICY_DENY)) {
_handle_authed_client(client, uri, result); _handle_authed_client(client, userdata, result);
return; return;
} }
ICECAST_LOG_DEBUG("Trying <mount type=\"normal\"> specific authenticators for client %p.", client); ICECAST_LOG_DEBUG("Trying <mount type=\"normal\"> specific authenticators for client %p.", client);
_handle_authentication_mount_generic(client, uri, MOUNT_TYPE_NORMAL, _handle_authentication_mount_default); _handle_authentication_mount_generic(client, userdata, MOUNT_TYPE_NORMAL, _handle_authentication_mount_default);
} }
static void _handle_authentication_listen_socket(client_t *client, char *uri) static void _handle_authentication_listen_socket(client_t *client)
{ {
auth_stack_t *stack = NULL; auth_stack_t *stack = NULL;
const listener_t *listener; const listener_t *listener;
@ -1433,17 +1433,17 @@ static void _handle_authentication_listen_socket(client_t *client, char *uri)
} }
if (stack) { if (stack) {
auth_stack_add_client(stack, client, _handle_authentication_mount_normal, uri); auth_stack_add_client(stack, client, _handle_authentication_mount_normal, NULL);
auth_stack_release(stack); auth_stack_release(stack);
} else { } else {
_handle_authentication_mount_normal(client, uri, AUTH_NOMATCH); _handle_authentication_mount_normal(client, NULL, AUTH_NOMATCH);
} }
} }
static void _handle_authentication(client_t *client, char *uri) static void _handle_authentication(client_t *client)
{ {
fastevent_emit(FASTEVENT_TYPE_CLIENT_READY_FOR_AUTH, FASTEVENT_FLAG_MODIFICATION_ALLOWED, FASTEVENT_DATATYPE_CLIENT, client); fastevent_emit(FASTEVENT_TYPE_CLIENT_READY_FOR_AUTH, FASTEVENT_FLAG_MODIFICATION_ALLOWED, FASTEVENT_DATATYPE_CLIENT, client);
_handle_authentication_listen_socket(client, uri); _handle_authentication_listen_socket(client);
} }
static void __prepare_shoutcast_admin_cgi_request(client_t *client) static void __prepare_shoutcast_admin_cgi_request(client_t *client)
@ -1644,7 +1644,7 @@ static void _handle_connection(void)
if (_update_admin_command(client) == -1) if (_update_admin_command(client) == -1)
continue; continue;
_handle_authentication(client, uri); _handle_authentication(client);
} else { } else {
free (node); free (node);
ICECAST_LOG_ERROR("HTTP request parsing failed"); ICECAST_LOG_ERROR("HTTP request parsing failed");

View File

@ -405,7 +405,7 @@ static void fserve_client_destroy(fserve_t *fclient)
/* client has requested a file, so check for it and send the file. Do not /* client has requested a file, so check for it and send the file. Do not
* refer to the client_t afterwards. return 0 for success, -1 on error. * refer to the client_t afterwards. return 0 for success, -1 on error.
*/ */
int fserve_client_create (client_t *httpclient, const char *path) int fserve_client_create (client_t *httpclient)
{ {
int bytes; int bytes;
struct stat file_buf; struct stat file_buf;
@ -421,8 +421,8 @@ int fserve_client_create (client_t *httpclient, const char *path)
ice_config_t *config; ice_config_t *config;
FILE *file; FILE *file;
fullpath = util_get_path_from_normalised_uri (path); fullpath = util_get_path_from_normalised_uri(httpclient->uri);
ICECAST_LOG_INFO("checking for file %H (%H)", path, fullpath); ICECAST_LOG_INFO("checking for file %H (%H)", httpclient->uri, fullpath);
if (strcmp (util_get_extension (fullpath), "m3u") == 0) if (strcmp (util_get_extension (fullpath), "m3u") == 0)
m3u_requested = 1; m3u_requested = 1;
@ -452,7 +452,7 @@ int fserve_client_create (client_t *httpclient, const char *path)
if (m3u_requested && m3u_file_available == 0) if (m3u_requested && m3u_file_available == 0)
{ {
char *sourceuri = strdup (path); char *sourceuri = strdup(httpclient->uri);
char *dot = strrchr(sourceuri, '.'); char *dot = strrchr(sourceuri, '.');
*dot = 0; *dot = 0;
@ -476,7 +476,7 @@ int fserve_client_create (client_t *httpclient, const char *path)
if (xslt_playlist_requested && xslt_playlist_file_available == 0) if (xslt_playlist_requested && xslt_playlist_file_available == 0)
{ {
xmlDocPtr doc; xmlDocPtr doc;
char *reference = strdup (path); char *reference = strdup(httpclient->uri);
char *eol = strrchr (reference, '.'); char *eol = strrchr (reference, '.');
if (eol) if (eol)
*eol = '\0'; *eol = '\0';
@ -554,7 +554,7 @@ int fserve_client_create (client_t *httpclient, const char *path)
endpos = 0; endpos = 0;
} }
httpclient->respcode = 206; httpclient->respcode = 206;
type = fserve_content_type (path); type = fserve_content_type(httpclient->uri);
bytes = util_http_build_header (httpclient->refbuf->data, BUFSIZE, 0, bytes = util_http_build_header (httpclient->refbuf->data, BUFSIZE, 0,
0, 206, NULL, 0, 206, NULL,
type, NULL, type, NULL,
@ -584,7 +584,7 @@ int fserve_client_create (client_t *httpclient, const char *path)
} }
} }
else { else {
char *type = fserve_content_type(path); char *type = fserve_content_type(httpclient->uri);
httpclient->respcode = 200; httpclient->respcode = 200;
bytes = util_http_build_header (httpclient->refbuf->data, BUFSIZE, 0, bytes = util_http_build_header (httpclient->refbuf->data, BUFSIZE, 0,
0, 200, NULL, 0, 200, NULL,

View File

@ -32,7 +32,7 @@ typedef struct _fserve_t
void fserve_initialize(void); void fserve_initialize(void);
void fserve_shutdown(void); void fserve_shutdown(void);
int fserve_client_create(client_t *httpclient, const char *path); int fserve_client_create(client_t *httpclient);
int fserve_add_client (client_t *client, FILE *file); int fserve_add_client (client_t *client, FILE *file);
void fserve_add_client_callback (client_t *client, fserve_callback_t callback, void *arg); void fserve_add_client_callback (client_t *client, fserve_callback_t callback, void *arg);
char *fserve_content_type (const char *path); char *fserve_content_type (const char *path);

View File

@ -13,7 +13,7 @@
#include "icecasttypes.h" #include "icecasttypes.h"
typedef void (*module_client_handler_function_t)(module_t *self, client_t *client, const char *uri); typedef void (*module_client_handler_function_t)(module_t *self, client_t *client);
typedef int (*module_setup_handler_t)(module_t *self, void **userdata); typedef int (*module_setup_handler_t)(module_t *self, void **userdata);
typedef struct { typedef struct {

View File

@ -1022,10 +1022,10 @@ typedef struct _source_xml_tag {
} source_xml_t; } source_xml_t;
void stats_transform_xslt(client_t *client, const char *uri) void stats_transform_xslt(client_t *client)
{ {
xmlDocPtr doc; xmlDocPtr doc;
char *xslpath = util_get_path_from_normalised_uri(uri); char *xslpath = util_get_path_from_normalised_uri(client->uri);
const char *mount = httpp_get_param(client->parser, "mount"); const char *mount = httpp_get_param(client->parser, "mount");
doc = stats_get_xml(0, mount, client); doc = stats_get_xml(0, mount, client);

View File

@ -92,7 +92,7 @@ void stats_event_time_iso8601 (const char *mount, const char *name);
void *stats_connection(void *arg); void *stats_connection(void *arg);
void stats_callback (client_t *client, void *notused); void stats_callback (client_t *client, void *notused);
void stats_transform_xslt(client_t *client, const char *uri); void stats_transform_xslt(client_t *client);
void stats_sendxml(client_t *client); void stats_sendxml(client_t *client);
xmlDocPtr stats_get_xml(int show_hidden, const char *show_mount, client_t *client); xmlDocPtr stats_get_xml(int show_hidden, const char *show_mount, client_t *client);
char *stats_get_value(const char *source, const char *name); char *stats_get_value(const char *source, const char *name);