Commit 38c71f76 authored by Philipp Schafft's avatar Philipp Schafft 🦁

Feature: Allow modules to handle client requests via <resource> tags

parent f02c23a5
......@@ -562,6 +562,8 @@ static void config_clear_resource(resource_t *resource)
xmlFree(resource->destination);
xmlFree(resource->bind_address);
xmlFree(resource->vhost);
xmlFree(resource->module);
xmlFree(resource->handler);
free(resource);
resource = nextresource;
}
......@@ -1948,6 +1950,9 @@ static void _parse_resource(xmlDocPtr doc,
resource->vhost = (char *)xmlGetProp(node, XMLSTR("vhost"));
resource->module = (char *)xmlGetProp(node, XMLSTR("module"));
resource->handler = (char *)xmlGetProp(node, XMLSTR("handler"));
temp = (char *)xmlGetProp(node, XMLSTR("omode"));
if (temp) {
resource->omode = config_str_to_omode(temp);
......
......@@ -139,6 +139,8 @@ typedef struct _resource {
int port;
char *bind_address;
char *vhost;
char *module;
char *handler;
operation_mode omode;
unsigned int flags;
struct _resource *next;
......
......@@ -29,6 +29,7 @@
#include "common/httpp/httpp.h"
#include "global.h"
#include "refobject.h"
#include "cfgfile.h"
#include "connection.h"
#include "refbuf.h"
......@@ -171,6 +172,8 @@ void client_destroy(client_t *client)
if (client->free_client_data)
client->free_client_data(client);
refobject_unref(client->handler_module);
free(client->handler_function);
free(client->username);
free(client->password);
free(client->role);
......
......@@ -25,6 +25,7 @@
#include "icecasttypes.h"
#include "errors.h"
#include "refbuf.h"
#include "module.h"
#define CLIENT_DEFAULT_ADMIN_FORMAT ADMIN_FORMAT_TRANSFORMED
......@@ -82,6 +83,10 @@ struct _client_tag {
/* active ACL, set as soon as the client is authenticated */
acl_t *acl;
/* Handler module and function */
module_t *handler_module;
char *handler_function;
/* is client getting intro data */
long intro_offset;
......
......@@ -43,6 +43,7 @@
#include "cfgfile.h"
#include "global.h"
#include "util.h"
#include "refobject.h"
#include "refbuf.h"
#include "client.h"
#include "errors.h"
......@@ -1135,6 +1136,28 @@ static int _handle_resources(client_t *client, char **uri)
}
if (resource->omode != OMODE_DEFAULT)
client->mode = resource->omode;
if (resource->module) {
module_t *module = module_container_get_module(global.modulecontainer, resource->module);
if (module != NULL) {
refobject_unref(client->handler_module);
client->handler_module = module;
} else {
ICECAST_LOG_ERROR("Module used in alias not found: %s", resource->module);
}
}
if (resource->handler) {
char *func = strdup(resource->handler);
if (func) {
free(client->handler_function);
client->handler_function = func;
} else {
ICECAST_LOG_ERROR("Can not allocate memory.");
}
}
ICECAST_LOG_DEBUG("resource has made %s into %s", *uri, new_uri);
break;
}
......@@ -1193,6 +1216,17 @@ static void _handle_authed_client(client_t *client, void *uri, auth_result resul
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);
free(uri);
return;
} else {
ICECAST_LOG_ERROR("No such handler function in module: %s", client->handler_function);
}
}
switch (client->parser->req_type) {
case httpp_req_source:
case httpp_req_put:
......
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