Commit 37d9319b authored by Philipp Schafft's avatar Philipp Schafft 🦁

Cleanup: Use replace_string() and only strdup() if needed

parent 7b608e27
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
# define strncasecmp strnicmp # define strncasecmp strnicmp
#endif #endif
#include "util.h"
#include "curl.h" #include "curl.h"
#include "auth.h" #include "auth.h"
#include "source.h" #include "source.h"
...@@ -427,43 +428,31 @@ int auth_get_url_auth(auth_t *authenticator, config_options_t *options) ...@@ -427,43 +428,31 @@ int auth_get_url_auth(auth_t *authenticator, config_options_t *options)
url_info = calloc(1, sizeof(auth_url)); url_info = calloc(1, sizeof(auth_url));
authenticator->state = url_info; authenticator->state = url_info;
/* default headers */
url_info->auth_header = strdup("icecast-auth-user: 1\r\n");
url_info->timelimit_header = strdup("icecast-auth-timelimit:");
/* force auth thread to call function. this makes sure the auth_t is attached to client */ /* force auth thread to call function. this makes sure the auth_t is attached to client */
authenticator->authenticate_client = url_add_client; authenticator->authenticate_client = url_add_client;
while(options) { while(options) {
if(strcmp(options->name, "username") == 0) { if(strcmp(options->name, "username") == 0) {
free(url_info->username); replace_string(&(url_info->username), options->value);
url_info->username = strdup(options->value);
} else if(strcmp(options->name, "password") == 0) { } else if(strcmp(options->name, "password") == 0) {
free(url_info->password); replace_string(&(url_info->password), options->value);
url_info->password = strdup(options->value);
} else if(strcmp(options->name, "headers") == 0) { } else if(strcmp(options->name, "headers") == 0) {
free(url_info->pass_headers); replace_string(&(url_info->pass_headers), options->value);
url_info->pass_headers = strdup(options->value);
} else if(strcmp(options->name, "header_prefix") == 0) { } else if(strcmp(options->name, "header_prefix") == 0) {
free(url_info->prefix_headers); replace_string(&(url_info->prefix_headers), options->value);
url_info->prefix_headers = strdup(options->value);
} else if(strcmp(options->name, "client_add") == 0) { } else if(strcmp(options->name, "client_add") == 0) {
free(url_info->addurl); replace_string(&(url_info->addurl), options->value);
url_info->addurl = strdup(options->value);
} else if(strcmp(options->name, "client_remove") == 0) { } else if(strcmp(options->name, "client_remove") == 0) {
authenticator->release_client = url_remove_client; authenticator->release_client = url_remove_client;
free(url_info->removeurl); replace_string(&(url_info->removeurl), options->value);
url_info->removeurl = strdup(options->value);
} else if(strcmp(options->name, "action_add") == 0) { } else if(strcmp(options->name, "action_add") == 0) {
addaction = options->value; addaction = options->value;
} else if(strcmp(options->name, "action_remove") == 0) { } else if(strcmp(options->name, "action_remove") == 0) {
removeaction = options->value; removeaction = options->value;
} else if(strcmp(options->name, "auth_header") == 0) { } else if(strcmp(options->name, "auth_header") == 0) {
free(url_info->auth_header); replace_string(&(url_info->auth_header), options->value);
url_info->auth_header = strdup(options->value);
} else if (strcmp(options->name, "timelimit_header") == 0) { } else if (strcmp(options->name, "timelimit_header") == 0) {
free(url_info->timelimit_header); replace_string(&(url_info->timelimit_header), options->value);
url_info->timelimit_header = strdup(options->value);
} else { } else {
ICECAST_LOG_ERROR("Unknown option: %s", options->name); ICECAST_LOG_ERROR("Unknown option: %s", options->name);
} }
...@@ -479,6 +468,12 @@ int auth_get_url_auth(auth_t *authenticator, config_options_t *options) ...@@ -479,6 +468,12 @@ int auth_get_url_auth(auth_t *authenticator, config_options_t *options)
return -1; return -1;
} }
/* default headers */
if (!url_info->auth_header)
url_info->auth_header = strdup("icecast-auth-user: 1\r\n");
if (!url_info->timelimit_header)
url_info->timelimit_header = strdup("icecast-auth-timelimit:");
if (url_info->auth_header) if (url_info->auth_header)
url_info->auth_header_len = strlen (url_info->auth_header); url_info->auth_header_len = strlen (url_info->auth_header);
if (url_info->timelimit_header) if (url_info->timelimit_header)
......
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