Fix bug #131 - Missing escape handling for # in config files.
Added support for escaping stuff in the configuration file parser.
This commit is contained in:
parent
c70119870a
commit
44860c8477
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* uhub - A tiny ADC p2p connection hub
|
* 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
|
* 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
|
* 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)
|
static int acl_parse_line(char* line, int line_count, void* ptr_data)
|
||||||
{
|
{
|
||||||
char* pos;
|
|
||||||
struct acl_handle* handle = (struct acl_handle*) ptr_data;
|
struct acl_handle* handle = (struct acl_handle*) ptr_data;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if ((pos = strchr(line, '#')) != NULL)
|
strip_off_ini_line_comments(line, line_count);
|
||||||
{
|
|
||||||
pos[0] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
line = strip_white_space(line);
|
line = strip_white_space(line);
|
||||||
if (!*line)
|
if (!*line)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* uhub - A tiny ADC p2p connection hub
|
* 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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -85,11 +85,8 @@ static int config_parse_line(char* line, int line_count, void* ptr_data)
|
||||||
char* data;
|
char* data;
|
||||||
struct hub_config* config = (struct hub_config*) ptr_data;
|
struct hub_config* config = (struct hub_config*) ptr_data;
|
||||||
|
|
||||||
if ((pos = strchr(line, '#')) != NULL)
|
strip_off_ini_line_comments(line, line_count);
|
||||||
{
|
|
||||||
pos[0] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!*line) return 0;
|
if (!*line) return 0;
|
||||||
|
|
||||||
LOG_DUMP("config_parse_line(): '%s'", line);
|
LOG_DUMP("config_parse_line(): '%s'", line);
|
||||||
|
|
|
@ -400,3 +400,51 @@ const char* get_timestamp(time_t now)
|
||||||
sprintf(ts, "[%02d:%02d]", t->tm_hour, t->tm_min);
|
sprintf(ts, "[%02d:%02d]", t->tm_hour, t->tm_min);
|
||||||
return ts;
|
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';
|
||||||
|
}
|
||||||
|
|
|
@ -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_encode(const unsigned char* buffer, size_t len, char* result);
|
||||||
extern void base32_decode(const char* src, unsigned char* dst, size_t len);
|
extern void base32_decode(const char* src, unsigned char* dst, size_t len);
|
||||||
extern char* strip_white_space(char* string);
|
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 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_itoa(int val);
|
||||||
extern const char* uhub_ulltoa(uint64_t val);
|
extern const char* uhub_ulltoa(uint64_t val);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue