1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-09-22 04:15:54 -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;
}
static inline void source_startup(client_t *client, const char *uri)
static inline void source_startup(client_t *client)
{
source_t *source;
source = source_reserve(uri);
source = source_reserve(client->uri);
if (source) {
source->client = client;
@ -872,27 +872,27 @@ static inline void source_startup(client_t *client, const char *uri)
}
} else {
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 */
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",
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 /");
client_send_error_by_id(client, ICECAST_ERROR_CON_MOUNTPOINT_NOT_STARTING_WITH_SLASH);
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");
@ -988,10 +988,10 @@ static inline ssize_t __count_user_role_on_mount (source_t *source, client_t *cl
return ret;
}
static void _handle_get_request(client_t *client, char *uri) {
static void _handle_get_request(client_t *client) {
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
* 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;
}
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 */
ICECAST_LOG_DEBUG("Stats request, sending XSL transformed stats");
stats_transform_xslt(client, uri);
stats_transform_xslt(client);
return;
}
avl_tree_rlock(global.source_tree);
/* 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) {
/* true mount */
int in_error = 0;
@ -1061,7 +1061,7 @@ static void _handle_get_request(client_t *client, char *uri) {
} else {
/* file */
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.
*/
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);
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) {
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);
return;
}
/* Dispatch legacy admin.cgi requests */
if (strcmp(uri, "/admin.cgi") == 0) {
_handle_admin_request(client, uri + 1);
if (strcmp(client->uri, "/admin.cgi") == 0) {
_handle_admin_request(client, client->uri + 1);
return;
} /* Dispatch all admin requests */
else if (strncmp(uri, "/admin/", 7) == 0) {
_handle_admin_request(client, uri + 7);
else if (strncmp(client->uri, "/admin/", 7) == 0) {
_handle_admin_request(client, client->uri + 7);
return;
}
if (client->handler_module && client->handler_function) {
const module_client_handler_t *handler = module_get_client_handler(client->handler_module, client->handler_function);
if (handler) {
handler->cb(client->handler_module, client, uri);
handler->cb(client->handler_module, client);
return;
} else {
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) {
case httpp_req_source:
case httpp_req_put:
_handle_source_request(client, uri);
_handle_source_request(client);
break;
case httpp_req_stats:
_handle_stats_request(client, uri);
_handle_stats_request(client);
break;
case httpp_req_get:
case httpp_req_post:
case httpp_req_options:
_handle_get_request(client, uri);
_handle_get_request(client);
break;
default:
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.
*/
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;
@ -1342,13 +1342,13 @@ static void _handle_authentication_global(client_t *client, void *uri, auth_resu
if (result != AUTH_NOMATCH &&
!(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;
}
ICECAST_LOG_DEBUG("Trying global authenticators for client %p.", client);
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();
}
@ -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);
}
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;
mount_proxy *mountproxy;
auth_stack_t *stack = NULL;
config = config_get_config();
mountproxy = __find_non_admin_mount(config, uri, type);
mountproxy = __find_non_admin_mount(config, client->uri, type);
if (!mountproxy) {
int command_type = admin_get_command_type(client->admin_command);
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();
if (stack) {
auth_stack_add_client(stack, client, callback, uri);
auth_stack_add_client(stack, client, callback, userdata);
auth_stack_release(stack);
} 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);
client->authstack = NULL;
if (result != AUTH_NOMATCH &&
!(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;
}
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);
client->authstack = NULL;
if (result != AUTH_NOMATCH &&
!(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;
}
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;
const listener_t *listener;
@ -1433,17 +1433,17 @@ static void _handle_authentication_listen_socket(client_t *client, char *uri)
}
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);
} 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);
_handle_authentication_listen_socket(client, uri);
_handle_authentication_listen_socket(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)
continue;
_handle_authentication(client, uri);
_handle_authentication(client);
} else {
free (node);
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
* 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;
struct stat file_buf;
@ -421,8 +421,8 @@ int fserve_client_create (client_t *httpclient, const char *path)
ice_config_t *config;
FILE *file;
fullpath = util_get_path_from_normalised_uri (path);
ICECAST_LOG_INFO("checking for file %H (%H)", path, fullpath);
fullpath = util_get_path_from_normalised_uri(httpclient->uri);
ICECAST_LOG_INFO("checking for file %H (%H)", httpclient->uri, fullpath);
if (strcmp (util_get_extension (fullpath), "m3u") == 0)
m3u_requested = 1;
@ -452,7 +452,7 @@ int fserve_client_create (client_t *httpclient, const char *path)
if (m3u_requested && m3u_file_available == 0)
{
char *sourceuri = strdup (path);
char *sourceuri = strdup(httpclient->uri);
char *dot = strrchr(sourceuri, '.');
*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)
{
xmlDocPtr doc;
char *reference = strdup (path);
char *reference = strdup(httpclient->uri);
char *eol = strrchr (reference, '.');
if (eol)
*eol = '\0';
@ -554,7 +554,7 @@ int fserve_client_create (client_t *httpclient, const char *path)
endpos = 0;
}
httpclient->respcode = 206;
type = fserve_content_type (path);
type = fserve_content_type(httpclient->uri);
bytes = util_http_build_header (httpclient->refbuf->data, BUFSIZE, 0,
0, 206, NULL,
type, NULL,
@ -584,7 +584,7 @@ int fserve_client_create (client_t *httpclient, const char *path)
}
}
else {
char *type = fserve_content_type(path);
char *type = fserve_content_type(httpclient->uri);
httpclient->respcode = 200;
bytes = util_http_build_header (httpclient->refbuf->data, BUFSIZE, 0,
0, 200, NULL,

View File

@ -32,7 +32,7 @@ typedef struct _fserve_t
void fserve_initialize(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);
void fserve_add_client_callback (client_t *client, fserve_callback_t callback, void *arg);
char *fserve_content_type (const char *path);

View File

@ -13,7 +13,7 @@
#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 struct {

View File

@ -1022,10 +1022,10 @@ typedef struct _source_xml_tag {
} source_xml_t;
void stats_transform_xslt(client_t *client, const char *uri)
void stats_transform_xslt(client_t *client)
{
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");
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_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);
xmlDocPtr stats_get_xml(int show_hidden, const char *show_mount, client_t *client);
char *stats_get_value(const char *source, const char *name);