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

Update: Make client's URI part of it's object

parent f68973d3
...@@ -253,6 +253,7 @@ void client_destroy(client_t *client) ...@@ -253,6 +253,7 @@ void client_destroy(client_t *client)
refobject_unref(client->handler_module); refobject_unref(client->handler_module);
free(client->handler_function); free(client->handler_function);
free(client->uri);
free(client->username); free(client->username);
free(client->password); free(client->password);
free(client->role); free(client->role);
......
...@@ -107,6 +107,9 @@ struct _client_tag { ...@@ -107,6 +107,9 @@ struct _client_tag {
/* active ACL, set as soon as the client is authenticated */ /* active ACL, set as soon as the client is authenticated */
acl_t *acl; acl_t *acl;
/* URI */
char *uri;
/* Handler module and function */ /* Handler module and function */
module_t *handler_module; module_t *handler_module;
char *handler_function; char *handler_function;
......
...@@ -1281,26 +1281,22 @@ static void _handle_authed_client(client_t *client, void *uri, auth_result resul ...@@ -1281,26 +1281,22 @@ static void _handle_authed_client(client_t *client, void *uri, auth_result resul
if (result != AUTH_OK) { if (result != AUTH_OK) {
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);
free(uri);
return; return;
} }
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, 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);
free(uri);
return; return;
} }
/* Dispatch legacy admin.cgi requests */ /* Dispatch legacy admin.cgi requests */
if (strcmp(uri, "/admin.cgi") == 0) { if (strcmp(uri, "/admin.cgi") == 0) {
_handle_admin_request(client, uri + 1); _handle_admin_request(client, uri + 1);
free(uri);
return; return;
} /* Dispatch all admin requests */ } /* Dispatch all admin requests */
else if (strncmp(uri, "/admin/", 7) == 0) { else if (strncmp(uri, "/admin/", 7) == 0) {
_handle_admin_request(client, uri + 7); _handle_admin_request(client, uri + 7);
free(uri);
return; return;
} }
...@@ -1308,7 +1304,6 @@ static void _handle_authed_client(client_t *client, void *uri, auth_result resul ...@@ -1308,7 +1304,6 @@ static void _handle_authed_client(client_t *client, void *uri, auth_result resul
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, uri);
free(uri);
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);
...@@ -1333,8 +1328,6 @@ static void _handle_authed_client(client_t *client, void *uri, auth_result resul ...@@ -1333,8 +1328,6 @@ static void _handle_authed_client(client_t *client, void *uri, auth_result resul
client_send_error_by_id(client, ICECAST_ERROR_CON_UNKNOWN_REQUEST); client_send_error_by_id(client, ICECAST_ERROR_CON_UNKNOWN_REQUEST);
break; break;
} }
free(uri);
} }
/* Handle clients that still need to authenticate. /* Handle clients that still need to authenticate.
...@@ -1610,6 +1603,7 @@ static void _handle_connection(void) ...@@ -1610,6 +1603,7 @@ static void _handle_connection(void)
} }
if (parser->req_type == httpp_req_options && strcmp(rawuri, "*") == 0) { if (parser->req_type == httpp_req_options && strcmp(rawuri, "*") == 0) {
client->uri = strdup("*");
client_send_204(client); client_send_204(client);
continue; continue;
} }
...@@ -1628,6 +1622,8 @@ static void _handle_connection(void) ...@@ -1628,6 +1622,8 @@ static void _handle_connection(void)
continue; continue;
} }
client->uri = uri;
if (strcmp(uri, "/admin.cgi") == 0) { if (strcmp(uri, "/admin.cgi") == 0) {
client->admin_command = admin_get_command(uri + 1); client->admin_command = admin_get_command(uri + 1);
__prepare_shoutcast_admin_cgi_request(client); __prepare_shoutcast_admin_cgi_request(client);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment