Commit 0dfc7c5b authored by Marvin Scholz's avatar Marvin Scholz

Cleanup codestyle

This commit cleanups codestyle a bit, yet there is still some work to be done
parent 9d84ba20
......@@ -46,21 +46,25 @@ struct acl_tag {
};
/* some string util functions */
static inline void __skip_spaces(const char **str) {
static inline void __skip_spaces(const char **str)
{
register const char * p;
for (p = *str; *p == ' '; p++);
*str = p;
}
int acl_set_ANY_str(acl_t * acl, acl_policy_t policy, const char * str, int (*callback)(acl_t *, acl_policy_t, const char *)) {
const char * end;
int acl_set_ANY_str(acl_t *acl,
acl_policy_t policy,
const char *str,
int (*callback)(acl_t *, acl_policy_t, const char *))
{
const char *end;
size_t len;
char buf[64];
int ret;
if (!acl || !str || !callback || (policy != ACL_POLICY_ALLOW && policy != ACL_POLICY_DENY))
if ( !acl || !str || !callback || (policy != ACL_POLICY_ALLOW && policy != ACL_POLICY_DENY) )
return -1;
do {
......@@ -88,7 +92,8 @@ int acl_set_ANY_str(acl_t * acl, acl_policy_t policy, const char * str, int (*ca
}
/* basic functions to work with ACLs */
acl_t * acl_new(void) {
acl_t *acl_new(void)
{
acl_t * ret = calloc(1, sizeof(*ret));
if (!ret)
return NULL;
......@@ -109,7 +114,8 @@ acl_t * acl_new(void) {
return ret;
}
acl_t * acl_new_from_xml_node(xmlNodePtr node) {
acl_t *acl_new_from_xml_node(xmlNodePtr node)
{
acl_t * ret;
char * tmp;
xmlAttrPtr prop;
......@@ -191,14 +197,16 @@ acl_t * acl_new_from_xml_node(xmlNodePtr node) {
return ret;
}
void acl_addref(acl_t * acl) {
void acl_addref(acl_t * acl)
{
if (!acl)
return;
acl->refcount++;
}
void acl_release(acl_t * acl) {
void acl_release(acl_t * acl)
{
if (!acl)
return;
......@@ -210,7 +218,10 @@ void acl_release(acl_t * acl) {
}
/* HTTP Method specific functions */
int acl_set_method_str__callback(acl_t * acl, acl_policy_t policy, const char * str) {
int acl_set_method_str__callback(acl_t *acl,
acl_policy_t policy,
const char *str)
{
httpp_request_type_e method;
size_t i;
......@@ -228,7 +239,8 @@ int acl_set_method_str__callback(acl_t * acl, acl_policy_t policy, const char *
return 0;
}
acl_policy_t acl_test_method(acl_t * acl, httpp_request_type_e method) {
acl_policy_t acl_test_method(acl_t * acl, httpp_request_type_e method)
{
if (!acl || method < httpp_req_none || method > httpp_req_unknown)
return ACL_POLICY_ERROR;
......@@ -236,7 +248,10 @@ acl_policy_t acl_test_method(acl_t * acl, httpp_request_type_e method) {
}
/* admin/ interface specific functions */
int acl_set_admin_str__callbck(acl_t * acl, acl_policy_t policy, const char * str) {
int acl_set_admin_str__callbck(acl_t *acl,
acl_policy_t policy,
const char *str)
{
size_t read_i, write_i;
int command = admin_get_command(str);
......@@ -264,7 +279,8 @@ int acl_set_admin_str__callbck(acl_t * acl, acl_policy_t policy, const char * st
return 0;
}
acl_policy_t acl_test_admin(acl_t * acl, int command) {
acl_policy_t acl_test_admin(acl_t *acl, int command)
{
size_t i;
if (!acl)
......@@ -278,7 +294,8 @@ acl_policy_t acl_test_admin(acl_t * acl, int command) {
}
/* web/ interface specific functions */
int acl_set_web_policy(acl_t * acl, acl_policy_t policy) {
int acl_set_web_policy(acl_t *acl, acl_policy_t policy)
{
if (!acl || (policy != ACL_POLICY_ALLOW && policy != ACL_POLICY_DENY))
return -1;
......@@ -287,7 +304,8 @@ int acl_set_web_policy(acl_t * acl, acl_policy_t policy) {
return 0;
}
acl_policy_t acl_test_web(acl_t * acl) {
acl_policy_t acl_test_web(acl_t *acl)
{
if (!acl)
return ACL_POLICY_ERROR;
......@@ -295,7 +313,8 @@ acl_policy_t acl_test_web(acl_t * acl) {
}
/* mount specific functons */
int acl_set_max_connection_duration(acl_t * acl, time_t duration) {
int acl_set_max_connection_duration(acl_t *acl, time_t duration)
{
if (!acl)
return -1;
......@@ -304,14 +323,16 @@ int acl_set_max_connection_duration(acl_t * acl, time_t duration) {
return 0;
}
time_t acl_get_max_connection_duration(acl_t * acl) {
time_t acl_get_max_connection_duration(acl_t *acl)
{
if (!acl)
return -1;
return acl->max_connection_duration;
}
int acl_set_max_connections_per_user(acl_t * acl, size_t limit) {
int acl_set_max_connections_per_user(acl_t *acl, size_t limit)
{
if (!acl)
return -1;
......@@ -320,7 +341,8 @@ int acl_set_max_connections_per_user(acl_t * acl, size_t limit) {
return 0;
}
ssize_t acl_get_max_connections_per_user(acl_t * acl) {
ssize_t acl_get_max_connections_per_user(acl_t *acl)
{
if (!acl)
return -1;
......
This diff is collapsed.
......@@ -28,19 +28,25 @@
#define ADMINTYPE_HYBRID (ADMINTYPE_GENERAL|ADMINTYPE_MOUNT)
/* formats */
#define RAW 1
#define TRANSFORMED 2
#define PLAINTEXT 3
#define RAW 1
#define TRANSFORMED 2
#define PLAINTEXT 3
/* special commands */
#define ADMIN_COMMAND_ERROR (-1)
#define ADMIN_COMMAND_ANY 0 /* for ACL framework */
#define ADMIN_COMMAND_ERROR (-1)
#define ADMIN_COMMAND_ANY 0 /* for ACL framework */
void admin_handle_request(client_t *client, const char *uri);
void admin_send_response(xmlDocPtr doc, client_t *client,
int response, const char *xslt_template);
void admin_add_listeners_to_mount(source_t *source, xmlNodePtr parent, operation_mode mode);
void admin_send_response(xmlDocPtr doc,
client_t *client,
int response,
const char *xslt_template);
void admin_add_listeners_to_mount(source_t *source,
xmlNodePtr parent,
operation_mode mode);
xmlNodePtr admin_add_role_to_authentication(auth_t *auth, xmlNodePtr parent);
int admin_get_command(const char *command);
......
......@@ -46,7 +46,7 @@ struct auth_stack_tag {
};
/* code */
static void __handle_auth_client (auth_t *auth, auth_client *auth_user);
static void __handle_auth_client(auth_t *auth, auth_client *auth_user);
static mutex_t _auth_lock; /* protects _current_id */
static volatile unsigned long _current_id = 0;
......
......@@ -118,22 +118,27 @@ typedef struct auth_tag
typedef struct auth_stack_tag auth_stack_t;
/* prototypes for auths that do not need own header file */
int auth_get_anonymous_auth (auth_t *auth, config_options_t *options);
int auth_get_static_auth (auth_t *auth, config_options_t *options);
int auth_get_url_auth (auth_t *authenticator, config_options_t *options);
int auth_get_anonymous_auth(auth_t *auth, config_options_t *options);
int auth_get_static_auth(auth_t *auth, config_options_t *options);
int auth_get_url_auth(auth_t *authenticator, config_options_t *options);
int auth_get_htpasswd_auth(auth_t *auth, config_options_t *options);
/* prototypes for auth.c */
void auth_initialise (void);
void auth_shutdown (void);
void auth_initialise(void);
void auth_shutdown(void);
auth_t *auth_get_authenticator (xmlNodePtr node);
void auth_release (auth_t *authenticator);
void auth_addref (auth_t *authenticator);
auth_t *auth_get_authenticator(xmlNodePtr node);
void auth_release(auth_t *authenticator);
void auth_addref(auth_t *authenticator);
int auth_release_client(client_t *client);
int auth_release_client(client_t *client);
void auth_stack_add_client(auth_stack_t *stack, client_t *client, void (*on_result)(client_t *client, void *userdata, auth_result result), void *userdata);
void auth_stack_add_client(auth_stack_t *stack,
client_t *client,
void (*on_result)(client_t *client,
void *userdata,
auth_result result),
void *userdata);
void auth_stack_release(auth_stack_t *stack);
void auth_stack_addref(auth_stack_t *stack);
......
......@@ -20,11 +20,13 @@
#include "logging.h"
#define CATMODULE "auth_anonymous"
static auth_result anonymous_auth (auth_client *auth_user) {
static auth_result anonymous_auth(auth_client *auth_user)
{
return AUTH_OK;
}
int auth_get_anonymous_auth (auth_t *authenticator, config_options_t *options) {
int auth_get_anonymous_auth(auth_t *authenticator, config_options_t *options)
{
authenticator->authenticate_client = anonymous_auth;
authenticator->immediate = 1;
return 0;
......
......@@ -45,8 +45,7 @@ static auth_result htpasswd_deleteuser(auth_t *auth, const char *username);
static auth_result htpasswd_userlist(auth_t *auth, xmlNodePtr srcnode);
static int _free_user (void *key);
typedef struct
{
typedef struct {
char *name;
char *pass;
} htpasswd_user;
......@@ -58,7 +57,8 @@ typedef struct {
time_t mtime;
} htpasswd_auth_state;
static void htpasswd_clear(auth_t *self) {
static void htpasswd_clear(auth_t *self)
{
htpasswd_auth_state *state = self->state;
free(state->filename);
if (state->users)
......@@ -84,7 +84,7 @@ static char *get_hash(const char *data, int len)
}
static int compare_users (void *arg, void *a, void *b)
static int compare_users(void *arg, void *a, void *b)
{
htpasswd_user *user1 = (htpasswd_user *)a;
htpasswd_user *user2 = (htpasswd_user *)b;
......@@ -93,7 +93,7 @@ static int compare_users (void *arg, void *a, void *b)
}
static int _free_user (void *key)
static int _free_user(void *key)
{
htpasswd_user *user = (htpasswd_user *)key;
......@@ -103,7 +103,7 @@ static int _free_user (void *key)
}
static void htpasswd_recheckfile (htpasswd_auth_state *htpasswd)
static void htpasswd_recheckfile(htpasswd_auth_state *htpasswd)
{
FILE *passwdfile;
avl_tree *new_users;
......@@ -114,8 +114,7 @@ static void htpasswd_recheckfile (htpasswd_auth_state *htpasswd)
if (htpasswd->filename == NULL)
return;
if (stat (htpasswd->filename, &file_stat) < 0)
{
if (stat (htpasswd->filename, &file_stat) < 0) {
ICECAST_LOG_WARN("failed to check status of %s", htpasswd->filename);
/* Create a dummy users tree for things to use later */
......@@ -127,15 +126,13 @@ static void htpasswd_recheckfile (htpasswd_auth_state *htpasswd)
return;
}
if (file_stat.st_mtime == htpasswd->mtime)
{
if (file_stat.st_mtime == htpasswd->mtime) {
/* common case, no update to file */
return;
}
ICECAST_LOG_INFO("re-reading htpasswd file \"%s\"", htpasswd->filename);
passwdfile = fopen (htpasswd->filename, "rb");
if (passwdfile == NULL)
{
if (passwdfile == NULL) {
ICECAST_LOG_WARN("Failed to open authentication database \"%s\": %s",
htpasswd->filename, strerror(errno));
return;
......@@ -144,8 +141,7 @@ static void htpasswd_recheckfile (htpasswd_auth_state *htpasswd)
new_users = avl_tree_new (compare_users, NULL);
while (get_line(passwdfile, line, MAX_LINE_LEN))
{
while (get_line(passwdfile, line, MAX_LINE_LEN)) {
int len;
htpasswd_user *entry;
......@@ -154,8 +150,7 @@ static void htpasswd_recheckfile (htpasswd_auth_state *htpasswd)
continue;
sep = strrchr (line, ':');
if (sep == NULL)
{
if (sep == NULL) {
ICECAST_LOG_WARN("No separator on line %d (%s)", num, htpasswd->filename);
continue;
}
......@@ -196,15 +191,13 @@ static auth_result htpasswd_auth (auth_client *auth_user)
thread_rwlock_rlock (&htpasswd->file_rwlock);
entry.name = client->username;
if (avl_get_by_key (htpasswd->users, &entry, &result) == 0)
{
if (avl_get_by_key (htpasswd->users, &entry, &result) == 0) {
htpasswd_user *found = result;
char *hashed_pw;
thread_rwlock_unlock (&htpasswd->file_rwlock);
hashed_pw = get_hash (client->password, strlen (client->password));
if (strcmp (found->pass, hashed_pw) == 0)
{
if (strcmp (found->pass, hashed_pw) == 0) {
free (hashed_pw);
return AUTH_OK;
}
......@@ -231,19 +224,19 @@ int auth_get_htpasswd_auth (auth_t *authenticator, config_options_t *options)
state = calloc(1, sizeof(htpasswd_auth_state));
while(options) {
if(!strcmp(options->name, "filename"))
{
if(!strcmp(options->name, "filename")) {
free (state->filename);
state->filename = strdup(options->value);
}
options = options->next;
}
if (state->filename)
if (state->filename) {
ICECAST_LOG_INFO("Configured htpasswd authentication using password file \"%s\"",
state->filename);
else
} else {
ICECAST_LOG_ERROR("No filename given in options for authenticator.");
}
authenticator->state = state;
......@@ -267,16 +260,14 @@ static auth_result htpasswd_adduser (auth_t *auth, const char *username, const c
thread_rwlock_wlock (&state->file_rwlock);
entry.name = (char*)username;
if (avl_get_by_key (state->users, &entry, &result) == 0)
{
if (avl_get_by_key (state->users, &entry, &result) == 0) {
thread_rwlock_unlock (&state->file_rwlock);
return AUTH_USEREXISTS;
}
passwdfile = fopen(state->filename, "ab");
if (passwdfile == NULL)
{
if (passwdfile == NULL) {
thread_rwlock_unlock (&state->file_rwlock);
ICECAST_LOG_WARN("Failed to open authentication database \"%s\": %s",
state->filename, strerror(errno));
......@@ -320,8 +311,7 @@ static auth_result htpasswd_deleteuser(auth_t *auth, const char *username)
tmpfile_len = strlen(state->filename) + 6;
tmpfile = calloc(1, tmpfile_len);
snprintf (tmpfile, tmpfile_len, "%s.tmp", state->filename);
if (stat (tmpfile, &file_info) == 0)
{
if (stat (tmpfile, &file_info) == 0) {
ICECAST_LOG_WARN("temp file \"%s\" exists, rejecting operation", tmpfile);
free (tmpfile);
fclose (passwdfile);
......@@ -369,8 +359,7 @@ static auth_result htpasswd_deleteuser(auth_t *auth, const char *username)
if (remove(state->filename) != 0) {
ICECAST_LOG_ERROR("Problem moving temp authentication file to original \"%s\" - \"%s\": %s",
tmpfile, state->filename, strerror(errno));
}
else {
} else {
if (rename(tmpfile, state->filename) != 0) {
ICECAST_LOG_ERROR("Problem moving temp authentication file to original \"%s\" - \"%s\": %s",
tmpfile, state->filename, strerror(errno));
......@@ -392,19 +381,18 @@ static auth_result htpasswd_userlist(auth_t *auth, xmlNodePtr srcnode)
state = auth->state;
htpasswd_recheckfile (state);
htpasswd_recheckfile(state);
thread_rwlock_rlock (&state->file_rwlock);
node = avl_get_first (state->users);
while (node)
{
thread_rwlock_rlock(&state->file_rwlock);
node = avl_get_first(state->users);
while (node) {
htpasswd_user *user = (htpasswd_user *)node->key;
newnode = xmlNewChild (srcnode, NULL, XMLSTR("user"), NULL);
newnode = xmlNewChild(srcnode, NULL, XMLSTR("user"), NULL);
xmlNewChild(newnode, NULL, XMLSTR("username"), XMLSTR(user->name));
xmlNewChild(newnode, NULL, XMLSTR("password"), XMLSTR(user->pass));
node = avl_get_next (node);
node = avl_get_next(node);
}
thread_rwlock_unlock (&state->file_rwlock);
thread_rwlock_unlock(&state->file_rwlock);
return AUTH_OK;
}
......@@ -28,10 +28,11 @@ typedef struct auth_static {
char *password;
} auth_static_t;
static auth_result static_auth (auth_client *auth_user) {
client_t *client = auth_user->client;
auth_t *auth = client->auth;
auth_static_t *auth_info = auth->state;
static auth_result static_auth(auth_client *auth_user)
{
client_t *client = auth_user->client;
auth_t *auth = client->auth;
auth_static_t *auth_info = auth->state;
if (auth_info->username) {
if (!client->username)
......@@ -49,17 +50,21 @@ static auth_result static_auth (auth_client *auth_user) {
return AUTH_FAILED;
}
static void clear_auth (auth_t *auth) {
static void clear_auth (auth_t *auth)
{
auth_static_t *auth_info = auth->state;
if (auth_info->username) free(auth_info->username);
if (auth_info->password) free(auth_info->password);
if (auth_info->username)
free(auth_info->username);
if (auth_info->password)
free(auth_info->password);
free(auth_info);
auth->state = NULL;
}
static auth_result static_userlist(auth_t *auth, xmlNodePtr srcnode) {
static auth_result static_userlist(auth_t *auth, xmlNodePtr srcnode)
{
auth_static_t *auth_info = auth->state;
xmlNodePtr newnode;
xmlNodePtr newnode;
newnode = xmlNewChild(srcnode, NULL, XMLSTR("user"), NULL);
xmlNewChild(newnode, NULL, XMLSTR("username"), XMLSTR(auth_info->username));
......@@ -68,9 +73,10 @@ static auth_result static_userlist(auth_t *auth, xmlNodePtr srcnode) {
return AUTH_OK;
}
int auth_get_static_auth (auth_t *authenticator, config_options_t *options) {
int auth_get_static_auth (auth_t *authenticator, config_options_t *options)
{
auth_static_t *auth_info;
int need_user;
int need_user;
if (strcmp(authenticator->type, AUTH_TYPE_STATIC) == 0) {
need_user = 1;
......@@ -93,10 +99,12 @@ int auth_get_static_auth (auth_t *authenticator, config_options_t *options) {
while (options) {
if (strcmp(options->name, "username") == 0) {
if (auth_info->username) free(auth_info->username);
if (auth_info->username)
free(auth_info->username);
auth_info->username = strdup(options->value);
} else if (strcmp(options->name, "password") == 0) {
if (auth_info->password) free(auth_info->password);
if (auth_info->password)
free(auth_info->password);
auth_info->password = strdup(options->value);
} else {
ICECAST_LOG_ERROR("Unknown option: %s", options->name);
......
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -77,32 +77,47 @@ typedef enum _mount_type {
} mount_type;
typedef struct _mount_proxy {
char *mountname; /* The mountpoint this proxy is used for */
mount_type mounttype; /* The type of the mount point */
char *dumpfile; /* Filename to dump this stream to (will be appended). NULL
to not dump. */
char *intro_filename; /* Send contents of file to client before the stream */
int fallback_when_full; /* switch new listener to fallback source
when max listeners reached */
int max_listeners; /* Max listeners for this mountpoint only. -1 to not
limit here (i.e. only use the global limit) */
char *fallback_mount; /* Fallback mountname */
int fallback_override; /* When this source arrives, do we steal back
clients from the fallback? */
int no_mount; /* Do we permit direct requests of this mountpoint? (or only
indirect, through fallbacks) */
int burst_size; /* amount to send to a new client if possible, -1 take
* from global setting */
/* The mountpoint this proxy is used for */
char *mountname;
/* The type of the mount point */
mount_type mounttype;
/* Filename to dump this stream to (will be appended).
* NULL to not dump.
*/
char *dumpfile;
/* Send contents of file to client before the stream */
char *intro_filename;
/* Switch new listener to fallback source when max listeners reached */
int fallback_when_full;
/* Max listeners for this mountpoint only.
* -1 to not limit here (i.e. only use the global limit)
*/
int max_listeners;
/* Fallback mountname */
char *fallback_mount;
/* When this source arrives, do we steal back
* clients from the fallback?
*/
int fallback_override;
/* Do we permit direct requests of this mountpoint?
* (or only indirect, through fallbacks)
*/
int no_mount;
/* amount to send to a new client if possible, -1 take
* from global setting
*/
int burst_size;
unsigned int queue_size_limit;
int hidden; /* Do we list this on the xsl pages */
unsigned int source_timeout; /* source timeout in seconds */
char *charset; /* character set if not utf8 */
int mp3_meta_interval; /* outgoing per-stream metadata interval */
ice_config_http_header_t *http_headers; /* additional HTTP headers */
/* Do we list this on the xsl pages */
int hidden;
/* source timeout in seconds */
unsigned int source_timeout;
/* character set if not utf8 */
char *charset;
/* outgoing per-stream metadata interval */
int mp3_meta_interval;
/* additional HTTP headers */
ice_config_http_header_t *http_headers;
struct event_registration_tag *event;
......@@ -233,8 +248,8 @@ int config_parse_cmdline(int arg, char **argv);
void config_set_config(ice_config_t *config);
listener_t *config_clear_listener (listener_t *listener);
void config_clear(ice_config_t *config);
mount_proxy *config_find_mount (ice_config_t *config, const char *mount, mount_type type);
listener_t *config_get_listen_sock (ice_config_t *config, connection_t *con);
mount_proxy *config_find_mount(ice_config_t *config, const char *mount, mount_type type);
listener_t *config_get_listen_sock(ice_config_t *config, connection_t *con);
config_options_t *config_parse_options(xmlNodePtr node);
void config_clear_options(config_options_t *options);
......
......@@ -60,9 +60,9 @@ static inline void client_send_500(client_t *client, const char *message);
*/
int client_create(client_t **c_ptr, connection_t *con, http_parser_t *parser)
{
ice_config_t *config;
client_t *client = (client_t *) calloc(1, sizeof(client_t));
int ret = -1;
ice_config_t *config;
client_t *client = (client_t *) calloc(1, sizeof(client_t));
int ret = -1;
if (client == NULL)
abort();
......@@ -70,10 +70,11 @@ int client_create(client_t **c_ptr, connection_t *con, http_parser_t *parser)
config = config_get_config();
global.clients++;
if (config->client_limit < global.clients)
if (config->client_limit < global.clients) {
ICECAST_LOG_WARN("server client limit reached (%d/%d)", config->client_limit, global.clients);
else
} else {
ret = 0;
}
config_release_config ();
......@@ -99,8 +100,7 @@ void client_destroy(client_t *client)
/* release the buffer now, as the buffer could be on the source queue
* and may of disappeared after auth completes */
if (client->refbuf)
{
if (client->refbuf) {
refbuf_release (client->refbuf);
client->refbuf = NULL;
}
......@@ -113,7 +113,6 @@ void client_destroy(client_t *client)
*/
if (client->respcode && client->parser)
logging_access(client);
if (client->con)
connection_close(client->con);
if (client->parser)
......@@ -141,14 +140,12 @@ int client_read_bytes(client_t *client, void *buf, unsigned len)
{
int bytes;
if (client->refbuf && client->refbuf->len)
{
if (client->refbuf && client->refbuf->len) {
/* we have data to read from a refbuf first */
if (client->refbuf->len < len)
len = client->refbuf->len;
memcpy (buf, client->refbuf->data, len);
if (len < client->refbuf->len)
{
if (len < client->refbuf->len) {
char *ptr = client->refbuf->data;
memmove (ptr, ptr+len, client->refbuf->len - len);
}
......@@ -200,7 +197,8 @@ void client_send_100(client_t *client)
}
/* this function is designed to work even if client is in bad state */
static inline void client_send_500(client_t *client, const char *message) {
static inline void client_send_500(client_t *client, const char *message)
{
const char header[] = "HTTP/1.0 500 Internal Server Error\r\nContent-Type: text/plain; charset=utf-8\r\n\r\n"
"500 - Internal Server Error\n---------------------------\n";
const ssize_t header_len = sizeof(header) - 1;
......
This diff is collapsed.
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