diff --git a/src/core/auth.c b/src/core/auth.c index 6afb533..b274d3e 100644 --- a/src/core/auth.c +++ b/src/core/auth.c @@ -1,6 +1,6 @@ /* * uhub - A tiny ADC p2p connection hub - * Copyright (C) 2007-2009, Jan Vidar Krey + * Copyright (C) 2007-2010, Jan Vidar Krey * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -176,14 +176,10 @@ static int check_cmd_addr(const char* cmd, struct linked_list* list, char* line, static int acl_parse_line(char* line, int line_count, void* ptr_data) { - char* pos; struct acl_handle* handle = (struct acl_handle*) ptr_data; int ret; - if ((pos = strchr(line, '#')) != NULL) - { - pos[0] = 0; - } + strip_off_ini_line_comments(line, line_count); line = strip_white_space(line); if (!*line) diff --git a/src/core/auth.h b/src/core/auth.h index 2e40a06..fe807b3 100644 --- a/src/core/auth.h +++ b/src/core/auth.h @@ -1,6 +1,6 @@ /* * uhub - A tiny ADC p2p connection hub - * Copyright (C) 2007-2009, Jan Vidar Krey + * Copyright (C) 2007-2010, Jan Vidar Krey * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/core/config.c b/src/core/config.c index 8ab295d..b291431 100644 --- a/src/core/config.c +++ b/src/core/config.c @@ -85,11 +85,8 @@ static int config_parse_line(char* line, int line_count, void* ptr_data) char* data; struct hub_config* config = (struct hub_config*) ptr_data; - if ((pos = strchr(line, '#')) != NULL) - { - pos[0] = 0; - } - + strip_off_ini_line_comments(line, line_count); + if (!*line) return 0; LOG_DUMP("config_parse_line(): '%s'", line); diff --git a/src/util/misc.c b/src/util/misc.c index 7475a45..1612663 100644 --- a/src/util/misc.c +++ b/src/util/misc.c @@ -400,3 +400,51 @@ const char* get_timestamp(time_t now) sprintf(ts, "[%02d:%02d]", t->tm_hour, t->tm_min); return ts; } + +void strip_off_ini_line_comments(char* line, int line_count) +{ + char* p = line; + char* out = line; + int backslash = 0; + + if (!*line) + return; + + for (; *p; p++) + { + if (!backslash) + { + if (*p == '\\') + { + backslash = 1; + } + else if (*p == '#') + { + *out = '\0'; + out++; + break; + } + else + { + *out = *p; + out++; + } + } + else + { + if (*p == '\\' || *p == '#' || *p == '\"') + { + *out = *p; + out++; + } + else + { + LOG_WARN("Invalid backslash escape on line %d", line_count); + *out = *p; + out++; + } + backslash = 0; + } + } + *out = '\0'; +} diff --git a/src/util/misc.h b/src/util/misc.h index 1f7c635..43f8d10 100644 --- a/src/util/misc.h +++ b/src/util/misc.h @@ -33,10 +33,12 @@ extern int is_valid_base32_char(char c); extern void base32_encode(const unsigned char* buffer, size_t len, char* result); extern void base32_decode(const char* src, unsigned char* dst, size_t len); extern char* strip_white_space(char* string); +extern void strip_off_ini_line_comments(char* line, int line_count); extern int file_read_lines(const char* file, void* data, file_line_handler_t handler); + extern const char* uhub_itoa(int val); extern const char* uhub_ulltoa(uint64_t val);