|
|
|
@ -24,6 +24,8 @@
|
|
|
|
|
#include "file.h"
|
|
|
|
|
#include "parse.h"
|
|
|
|
|
|
|
|
|
|
#define FILE_MAX_LINE_BYTES 2048
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* returns error
|
|
|
|
|
returns 0 if everything is ok
|
|
|
|
@ -32,7 +34,7 @@ static int APP_CC
|
|
|
|
|
l_file_read_sections(int fd, int max_file_size, struct list *names)
|
|
|
|
|
{
|
|
|
|
|
struct stream *s;
|
|
|
|
|
char text[256];
|
|
|
|
|
char text[FILE_MAX_LINE_BYTES];
|
|
|
|
|
char c;
|
|
|
|
|
int in_it;
|
|
|
|
|
int in_it_index;
|
|
|
|
@ -44,7 +46,7 @@ l_file_read_sections(int fd, int max_file_size, struct list *names)
|
|
|
|
|
g_file_seek(fd, 0);
|
|
|
|
|
in_it_index = 0;
|
|
|
|
|
in_it = 0;
|
|
|
|
|
g_memset(text, 0, 256);
|
|
|
|
|
g_memset(text, 0, FILE_MAX_LINE_BYTES);
|
|
|
|
|
list_clear(names);
|
|
|
|
|
make_stream(s);
|
|
|
|
|
init_stream(s, max_file_size);
|
|
|
|
@ -67,7 +69,7 @@ l_file_read_sections(int fd, int max_file_size, struct list *names)
|
|
|
|
|
list_add_item(names, (tbus)g_strdup(text));
|
|
|
|
|
in_it = 0;
|
|
|
|
|
in_it_index = 0;
|
|
|
|
|
g_memset(text, 0, 256);
|
|
|
|
|
g_memset(text, 0, FILE_MAX_LINE_BYTES);
|
|
|
|
|
}
|
|
|
|
|
else if (in_it)
|
|
|
|
|
{
|
|
|
|
@ -86,8 +88,9 @@ l_file_read_sections(int fd, int max_file_size, struct list *names)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* returns error */
|
|
|
|
|
static int APP_CC
|
|
|
|
|
file_read_line(struct stream *s, char *text)
|
|
|
|
|
file_read_line(struct stream *s, char *text, int text_bytes)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int skip_to_end;
|
|
|
|
@ -108,6 +111,7 @@ file_read_line(struct stream *s, char *text)
|
|
|
|
|
|
|
|
|
|
while (c != 10 && c != 13)
|
|
|
|
|
{
|
|
|
|
|
/* these mean skip the rest of the line */
|
|
|
|
|
if (c == '#' || c == '!' || c == ';')
|
|
|
|
|
{
|
|
|
|
|
skip_to_end = 1;
|
|
|
|
@ -117,6 +121,10 @@ file_read_line(struct stream *s, char *text)
|
|
|
|
|
{
|
|
|
|
|
text[i] = c;
|
|
|
|
|
i++;
|
|
|
|
|
if (i >= text_bytes)
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (s_check_rem(s, 1))
|
|
|
|
@ -214,9 +222,10 @@ l_file_read_section(int fd, int max_file_size, const char *section,
|
|
|
|
|
struct list *names, struct list *values)
|
|
|
|
|
{
|
|
|
|
|
struct stream *s;
|
|
|
|
|
char text[512];
|
|
|
|
|
char name[512];
|
|
|
|
|
char value[512];
|
|
|
|
|
char *data;
|
|
|
|
|
char *text;
|
|
|
|
|
char *name;
|
|
|
|
|
char *value;
|
|
|
|
|
char *lvalue;
|
|
|
|
|
char c;
|
|
|
|
|
int in_it;
|
|
|
|
@ -224,12 +233,17 @@ l_file_read_section(int fd, int max_file_size, const char *section,
|
|
|
|
|
int len;
|
|
|
|
|
int index;
|
|
|
|
|
int file_size;
|
|
|
|
|
|
|
|
|
|
data = (char *) g_malloc(FILE_MAX_LINE_BYTES * 3, 0);
|
|
|
|
|
text = data;
|
|
|
|
|
name = text + FILE_MAX_LINE_BYTES;
|
|
|
|
|
value = name + FILE_MAX_LINE_BYTES;
|
|
|
|
|
|
|
|
|
|
file_size = 32 * 1024; /* 32 K file size limit */
|
|
|
|
|
g_file_seek(fd, 0);
|
|
|
|
|
in_it_index = 0;
|
|
|
|
|
in_it = 0;
|
|
|
|
|
g_memset(text, 0, 512);
|
|
|
|
|
g_memset(text, 0, FILE_MAX_LINE_BYTES);
|
|
|
|
|
list_clear(names);
|
|
|
|
|
list_clear(values);
|
|
|
|
|
make_stream(s);
|
|
|
|
@ -249,10 +263,13 @@ l_file_read_section(int fd, int max_file_size, const char *section,
|
|
|
|
|
in_uint8(s, c);
|
|
|
|
|
if ((c == '#') || (c == ';'))
|
|
|
|
|
{
|
|
|
|
|
file_read_line(s, text);
|
|
|
|
|
if (file_read_line(s, text, FILE_MAX_LINE_BYTES) != 0)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
in_it = 0;
|
|
|
|
|
in_it_index = 0;
|
|
|
|
|
g_memset(text, 0, 512);
|
|
|
|
|
g_memset(text, 0, FILE_MAX_LINE_BYTES);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (c == '[')
|
|
|
|
@ -263,8 +280,8 @@ l_file_read_section(int fd, int max_file_size, const char *section,
|
|
|
|
|
{
|
|
|
|
|
if (g_strcasecmp(section, text) == 0)
|
|
|
|
|
{
|
|
|
|
|
file_read_line(s, text);
|
|
|
|
|
while (file_read_line(s, text) == 0)
|
|
|
|
|
file_read_line(s, text, FILE_MAX_LINE_BYTES);
|
|
|
|
|
while (file_read_line(s, text, FILE_MAX_LINE_BYTES) == 0)
|
|
|
|
|
{
|
|
|
|
|
if (g_strlen(text) > 0)
|
|
|
|
|
{
|
|
|
|
@ -292,21 +309,27 @@ l_file_read_section(int fd, int max_file_size, const char *section,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free_stream(s);
|
|
|
|
|
g_free(data);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
in_it = 0;
|
|
|
|
|
in_it_index = 0;
|
|
|
|
|
g_memset(text, 0, 512);
|
|
|
|
|
g_memset(text, 0, FILE_MAX_LINE_BYTES);
|
|
|
|
|
}
|
|
|
|
|
else if (in_it)
|
|
|
|
|
{
|
|
|
|
|
text[in_it_index] = c;
|
|
|
|
|
in_it_index++;
|
|
|
|
|
if (in_it_index >= FILE_MAX_LINE_BYTES)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
free_stream(s);
|
|
|
|
|
g_free(data);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|