1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-06-23 06:25:24 +00:00

Feature: Clear XSLT cache on config reload

This commit is contained in:
Philipp Schafft 2018-07-06 21:40:37 +00:00
parent 3ffe5f4e96
commit 45d44a6349
3 changed files with 27 additions and 9 deletions

View File

@ -44,6 +44,7 @@
#include "connection.h" #include "connection.h"
#include "main.h" #include "main.h"
#include "slave.h" #include "slave.h"
#include "xslt.h"
#define CATMODULE "CONFIG" #define CATMODULE "CONFIG"
#define CONFIG_DEFAULT_LOCATION "Earth" #define CONFIG_DEFAULT_LOCATION "Earth"
@ -748,6 +749,7 @@ void config_reread_config(void)
stats_global(config); stats_global(config);
config_release_config(); config_release_config();
slave_update_all_mounts(); slave_update_all_mounts();
xslt_clear_cache();
} }
} }

View File

@ -115,14 +115,8 @@ void xslt_initialize(void)
} }
void xslt_shutdown(void) { void xslt_shutdown(void) {
int i;
for(i=0; i < CACHESIZE; i++) { xslt_clear_cache();
if(cache[i].filename)
free(cache[i].filename);
if(cache[i].stylesheet)
xsltFreeStylesheet(cache[i].stylesheet);
}
thread_mutex_destroy (&xsltlock); thread_mutex_destroy (&xsltlock);
xmlCleanupParser(); xmlCleanupParser();
@ -131,6 +125,26 @@ void xslt_shutdown(void) {
xmlFree(admin_path); xmlFree(admin_path);
} }
static void clear_cache_entry(size_t idx) {
free(cache[idx].filename);
if (cache[idx].stylesheet)
xsltFreeStylesheet(cache[idx].stylesheet);
}
void xslt_clear_cache(void)
{
size_t i;
ICECAST_LOG_DEBUG("Clearing stylesheet cache.");
thread_mutex_lock(&xsltlock);
for (i = 0; i < CACHESIZE; i++)
clear_cache_entry(i);
thread_mutex_unlock(&xsltlock);
}
static int evict_cache_entry(void) { static int evict_cache_entry(void) {
int i, age=0, oldest=0; int i, age=0, oldest=0;
@ -141,8 +155,7 @@ static int evict_cache_entry(void) {
} }
} }
xsltFreeStylesheet(cache[oldest].stylesheet); clear_cache_entry(oldest);
free(cache[oldest].filename);
return oldest; return oldest;
} }
@ -282,9 +295,11 @@ static xmlDocPtr custom_loader(const xmlChar *URI,
/* Get the actual xmlDoc */ /* Get the actual xmlDoc */
if (final_URI) { if (final_URI) {
ICECAST_LOG_DEBUG("Calling xslt_loader() for \"%s\" (was: \"%s\").", final_URI, URI);
ret = xslt_loader(final_URI, dict, options, ctxt, type); ret = xslt_loader(final_URI, dict, options, ctxt, type);
xmlFree(final_URI); xmlFree(final_URI);
} else { } else {
ICECAST_LOG_DEBUG("Calling xslt_loader() for \"%s\".", URI);
ret = xslt_loader(URI, dict, options, ctxt, type); ret = xslt_loader(URI, dict, options, ctxt, type);
} }
return ret; return ret;

View File

@ -19,4 +19,5 @@
void xslt_transform(xmlDocPtr doc, const char *xslfilename, client_t *client, int status); void xslt_transform(xmlDocPtr doc, const char *xslfilename, client_t *client, int status);
void xslt_initialize(void); void xslt_initialize(void);
void xslt_shutdown(void); void xslt_shutdown(void);
void xslt_clear_cache(void);