/* return error */ static int l_file_read_section(int fd, int max_file_size, const char *section, xrdpList *names, xrdpList *values) { struct stream *s; char text[512]; char name[512]; char value[512]; char *lvalue; char c; int in_it; int in_it_index; int len; int index; int file_size; 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); list_clear(names); list_clear(values); make_stream(s); init_stream(s, file_size); len = g_file_read(fd, s->data, file_size); if (len > 0) { s->end = s->p + len; for (index = 0; index < len; index++) { if (!s_check_rem(s, 1)) { break; } in_uint8(s, c); if ((c == '#') || (c == ';')) { file_read_line(s, text); in_it = 0; in_it_index = 0; g_memset(text, 0, 512); continue; } if (c == '[') { in_it = 1; } else if (c == ']') { if (g_strcasecmp(section, text) == 0) { file_read_line(s, text); while (file_read_line(s, text) == 0) { if (g_strlen(text) > 0) { file_split_name_value(text, name, value); list_add_item(names, (tbus) g_strdup(name)); if (value[0] == '$') { lvalue = g_getenv(value + 1); if (lvalue != 0) { list_add_item(values, (tbus) g_strdup(lvalue)); } else { list_add_item(values, (tbus) g_strdup("")); } } else { list_add_item(values, (tbus) g_strdup(value)); } } } free_stream(s); return 0; } in_it = 0; in_it_index = 0; g_memset(text, 0, 512); } else if (in_it) { text[in_it_index] = c; in_it_index++; } } } free_stream(s); return 1; }
/* return error */ static int APP_CC l_file_read_section(int fd, int max_file_size, const char *section, struct list *names, struct list *values) { struct stream *s; char *data; char *text; char *name; char *value; char *lvalue; char c; int in_it; int in_it_index; 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, FILE_MAX_LINE_BYTES); list_clear(names); list_clear(values); make_stream(s); init_stream(s, file_size); len = g_file_read(fd, s->data, file_size); if (len > 0) { s->end = s->p + len; for (index = 0; index < len; index++) { if (!s_check_rem(s, 1)) { break; } in_uint8(s, c); if ((c == '#') || (c == ';')) { if (file_read_line(s, text, FILE_MAX_LINE_BYTES) != 0) { break; } in_it = 0; in_it_index = 0; g_memset(text, 0, FILE_MAX_LINE_BYTES); continue; } if (c == '[') { in_it = 1; } else if (c == ']') { if (g_strcasecmp(section, 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) { file_split_name_value(text, name, value); list_add_item(names, (tbus)g_strdup(name)); if (value[0] == '$') { lvalue = g_getenv(value + 1); if (lvalue != 0) { list_add_item(values, (tbus)g_strdup(lvalue)); } else { list_add_item(values, (tbus)g_strdup("")); } } else { list_add_item(values, (tbus)g_strdup(value)); } } } free_stream(s); g_free(data); return 0; } in_it = 0; in_it_index = 0; 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; }