--- /dev/null
+<b>Each File ONE</b><br>
--- /dev/null
+<b>Each File TWO</b><br>
--- /dev/null
+<b>Each File ZERO</b><br>
{{{ArrayValueThird}}}
{{{!FOREACH ArrayValueFourth}}}
{{{ArrayValueFourth}}}
+ {{{!FOREACH Each_FILE}}}
+ {{{Each_FILE}}}
+ {{{!ENDFOREACH}}}
{{{!ENDFOREACH}}}
{{{!ENDFOREACH}}}
{{{!ENDFOREACH}}}
EachTestMid='''Third Entry Mid'''
EachTestTail='''Third Entry Tail'''
+Each_FILE='''example_config/each_file_zero.html'''
+Each_FILE='''example_config/each_file_one.html'''
+Each_FILE='''example_config/each_file_two.html'''
+
PATH=/inner
HTML_FILE='''example_config/inner.html'''
VAR_FILE='''example_config/var.html'''
#include "helpers.h"
#include "http_template.h"
-int c_simple_http_internal_write_filenames_to_cache_file(void *data, void *ud) {
- char *filename = data;
+int c_simple_http_internal_write_filenames_to_cache_file(
+ const void *key,
+ __attribute__((unused)) size_t key_size,
+ __attribute__((unused)) const void *value,
+ void *ud) {
+ const char *filename = key;
FILE *cache_fd = ud;
const size_t filename_size = strlen(filename);
return -5;
}
- __attribute__((cleanup(simple_archiver_list_free)))
- SDArchiverLinkedList *used_filenames = NULL;
+ __attribute__((cleanup(simple_archiver_hash_map_free)))
+ SDArchiverHashMap *used_filenames = NULL;
size_t generated_html_size = 0;
return -4;
}
- if (simple_archiver_list_get(
- used_filenames,
- c_simple_http_internal_write_filenames_to_cache_file,
- cache_fd)) {
+ if (simple_archiver_hash_map_iter(
+ used_filenames,
+ c_simple_http_internal_write_filenames_to_cache_file,
+ cache_fd) != 0) {
fprintf(stderr, "ERROR Failed to write filenames to cache file!\n");
return -6;
} else if (fwrite("--- BEGIN HTML ---\n", 1, 19, cache_fd) != 19) {
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
-// TODO: Update files map.
-
#include "http_template.h"
// Standard library includes.
// Third party includes.
#include <SimpleArchiver/src/data_structures/linked_list.h>
+#include <SimpleArchiver/src/data_structures/hash_map.h>
#include <SimpleArchiver/src/helpers.h>
// Local includes.
SDArchiverHashMap *array_vars,
const C_SIMPLE_HTTP_ParsedConfig *wrapped_hash_map,
SDArchiverLinkedList *string_part_list,
- SDArchiverLinkedList **files_list_out);
+ SDArchiverHashMap **files_set_out);
+
+void c_simple_http_internal_set_out_insert(SDArchiverHashMap **set,
+ const char *str) {
+ if (set
+ && *set
+ && simple_archiver_hash_map_get(*set, str, strlen(str) + 1) == NULL) {
+ simple_archiver_hash_map_insert(
+ *set,
+ (void*)1,
+ strdup(str),
+ strlen(str) + 1,
+ simple_archiver_helper_datastructure_cleanup_nop,
+ NULL);
+ }
+}
void c_simple_http_internal_cleanup_ArrayVar(
C_SIMPLE_HTTP_ArrayVar **array_var) {
char **left_side_out,
char **right_side_out,
uint_fast8_t *is_equality_out,
- SDArchiverLinkedList **files_list_out) {
+ SDArchiverHashMap **files_set_out) {
if (!left_side_out || !right_side_out || !is_equality_out) {
fprintf(stderr, "ERROR Internal error! %s\n", var);
return 1;
}
c_simple_http_trim_end_whitespace(*left_side_out);
left_side_size = strlen(*left_side_out);
- if (files_list_out) {
- simple_archiver_list_add(*files_list_out,
- strdup(config_value->value),
- NULL);
- }
+ c_simple_http_internal_set_out_insert(files_set_out, config_value->value);
} else {
*left_side_out = strdup(config_value->value);
c_simple_http_trim_end_whitespace(*left_side_out);
const C_SIMPLE_HTTP_HashMapWrapper *wrapped_hash_map,
const char *var,
SDArchiverHashMap *array_vars,
- SDArchiverLinkedList *array_vars_keys) {
+ SDArchiverLinkedList *array_vars_keys,
+ SDArchiverHashMap **files_set_out) {
C_SIMPLE_HTTP_ConfigValue *config_value =
simple_archiver_hash_map_get(wrapped_hash_map->hash_map,
*for_each_var_name,
c_simple_http_internal_cleanup_ArrayVar(&array_var);
return 1;
}
+ c_simple_http_internal_set_out_insert(files_set_out, config_value->value);
} else {
array_var->value = strdup(config_value->value);
}
c_simple_http_internal_cleanup_ArrayVar(&array_var);
return 1;
}
+ c_simple_http_internal_set_out_insert(files_set_out,
+ config_value->value);
} else {
current_array_var->value = strdup(config_value->value);
}
SDArchiverHashMap *array_vars,
SDArchiverLinkedList *string_part_list,
const C_SIMPLE_HTTP_ParsedConfig *wrapped_hash_map,
- SDArchiverLinkedList **files_list_out) {
+ SDArchiverHashMap **files_set_out) {
C_SIMPLE_HTTP_String_Part string_part;
if (((*state) & 1) == 0) {
// Using 0x7B instead of left curly-brace due to bug in vim navigation.
array_vars,
wrapped_hash_map,
string_part_list,
- files_list_out) != 0) {
+ files_set_out) != 0) {
return 1;
}
}
SDArchiverHashMap *array_vars,
const C_SIMPLE_HTTP_ParsedConfig *wrapped_hash_map,
SDArchiverLinkedList *string_part_list,
- SDArchiverLinkedList **files_list_out) {
+ SDArchiverHashMap **files_set_out) {
C_SIMPLE_HTTP_String_Part string_part;
if (var_size == 0) {
fprintf(stderr, "ERROR No characters within delimeters!\n");
&left_side,
&right_side,
&is_equality,
- files_list_out)) {
+ files_set_out)) {
return 1;
} else if (!left_side || !right_side) {
fprintf(stderr, "ERROR Internal error! %s\n", var);
&left_side,
&right_side,
&is_equality,
- files_list_out)) {
+ files_set_out)) {
return 1;
} else if (!left_side || !right_side) {
fprintf(stderr, "ERROR Internal error! %s\n", var);
fprintf(stderr, "ERROR Failed to get value from FILE! %s\n", var);
return 1;
}
- if (files_list_out) {
- simple_archiver_list_add(*files_list_out,
- strdup(config_value->value),
- NULL);
- }
+ c_simple_http_internal_set_out_insert(files_set_out,
+ config_value->value);
} else {
value_contents = strdup(config_value->value);
value_contents_size = strlen(value_contents);
wrapped_hash_map,
var,
array_vars,
- for_state->array_vars_keys) != 0) {
+ for_state->array_vars_keys,
+ files_set_out) != 0) {
if (for_each_var_name) {
free(for_each_var_name);
}
wrapped_hash_map,
var,
array_vars,
- for_state->array_vars_keys) != 0) {
+ for_state->array_vars_keys,
+ files_set_out) != 0) {
if (for_each_var_name) {
free(for_each_var_name);
}
array_vars,
string_part_list,
wrapped_hash_map,
- files_list_out) != 0) {
+ files_set_out) != 0) {
return 1;
}
}
string_part.extra = html_buf_idx + 1;
string_part.buf[string_part.size - 1] = 0;
- if (files_list_out) {
- char *variable_filename = strdup(config_value->value);
- simple_archiver_list_add(*files_list_out, variable_filename, NULL);
- }
+ c_simple_http_internal_set_out_insert(files_set_out,
+ config_value->value);
} else {
// Variable data is "config_value->value".
string_part.size = strlen(config_value->value) + 1;
const char *path,
const C_SIMPLE_HTTP_HTTPTemplates *templates,
size_t *output_buf_size,
- SDArchiverLinkedList **files_list_out) {
+ SDArchiverHashMap **files_set_out) {
if (output_buf_size) {
*output_buf_size = 0;
}
- if (files_list_out) {
- *files_list_out = simple_archiver_list_init();
+ if (files_set_out) {
+ *files_set_out = simple_archiver_hash_map_init();
}
size_t path_len_size_t = strlen(path) + 1;
if (path_len_size_t > 0xFFFFFFFF) {
}
html_buf[html_file_size] = 0;
html_buf_size = (size_t)html_file_size;
- if (files_list_out) {
- char *html_filename_copy = malloc(strlen(html_file_value->value) + 1);
- strcpy(html_filename_copy, html_file_value->value);
- simple_archiver_list_add(*files_list_out, html_filename_copy, NULL);
- }
+ c_simple_http_internal_set_out_insert(files_set_out,
+ html_file_value->value);
} else {
C_SIMPLE_HTTP_ConfigValue *stored_html_config_value =
simple_archiver_hash_map_get(wrapped_hash_map->hash_map, "HTML", 5);
array_vars,
string_part_list,
wrapped_hash_map,
- files_list_out) != 0) {
+ files_set_out) != 0) {
return NULL;
}
}
#ifndef SEODISPARATE_COM_C_SIMPLE_HTTP_HTTP_TEMPLATE_H_
#define SEODISPARATE_COM_C_SIMPLE_HTTP_HTTP_TEMPLATE_H_
-#include "http.h"
// Standard library includes.
#include <stddef.h>
// Third-party includes.
#include <SimpleArchiver/src/data_structures/linked_list.h>
+#include <SimpleArchiver/src/data_structures/hash_map.h>
+
+// Local includes.
+#include "http.h"
// Returns non-NULL on success, which must be free'd after use. Takes a path
// string and templates and returns the generated HTML. If "output_buf_size" is
const char *path,
const C_SIMPLE_HTTP_HTTPTemplates *templates,
size_t *output_buf_size,
- SDArchiverLinkedList **files_list_out);
+ SDArchiverHashMap **files_set_out);
#endif
}
}
-int test_internal_check_matching_string_in_list(void *value, void *ud) {
- if (value && ud) {
- if (strcmp(value, ud) == 0) {
+int test_internal_check_matching_string_in_list(
+ const void *key,
+ __attribute__((unused)) size_t key_size,
+ __attribute__((unused)) const void *value,
+ void *ud) {
+ if (key && ud) {
+ if (strcmp(key, ud) == 0) {
return 1;
}
}
size_t output_buf_size;
- __attribute__((cleanup(simple_archiver_list_free)))
- SDArchiverLinkedList *filenames_list = NULL;
+ __attribute__((cleanup(simple_archiver_hash_map_free)))
+ SDArchiverHashMap *filenames_set = NULL;
__attribute__((cleanup(simple_archiver_helper_cleanup_c_string)))
char *buf = c_simple_http_path_to_generated(
- "/", &config, &output_buf_size, &filenames_list);
+ "/", &config, &output_buf_size, &filenames_set);
ASSERT_TRUE(buf != NULL);
ASSERT_TRUE(strcmp(buf, "<h1>Test</h1>") == 0);
CHECK_TRUE(output_buf_size == 13);
- CHECK_TRUE(filenames_list->count == 0);
+ CHECK_TRUE(filenames_set->count == 0);
simple_archiver_helper_cleanup_c_string(&buf);
- simple_archiver_list_free(&filenames_list);
+ simple_archiver_hash_map_free(&filenames_set);
__attribute__((cleanup(test_internal_cleanup_delete_temporary_file)))
const char *test_http_template_filename2 =
ASSERT_TRUE(config.paths != NULL);
buf = c_simple_http_path_to_generated(
- "/", &config, &output_buf_size, &filenames_list);
+ "/", &config, &output_buf_size, &filenames_set);
ASSERT_TRUE(buf != NULL);
//printf("%s\n", buf);
ASSERT_TRUE(
"<h1> Some text. </h1><br><h2> More text. </h2>")
== 0);
CHECK_TRUE(output_buf_size == 46);
- CHECK_TRUE(filenames_list->count == 0);
+ CHECK_TRUE(filenames_set->count == 0);
simple_archiver_helper_cleanup_c_string(&buf);
- simple_archiver_list_free(&filenames_list);
+ simple_archiver_hash_map_free(&filenames_set);
__attribute__((cleanup(test_internal_cleanup_delete_temporary_file)))
const char *test_http_template_filename3 =
ASSERT_TRUE(config.paths != NULL);
buf = c_simple_http_path_to_generated(
- "/", &config, &output_buf_size, &filenames_list);
+ "/", &config, &output_buf_size, &filenames_set);
ASSERT_TRUE(buf != NULL);
//printf("%s\n", buf);
ASSERT_TRUE(
"<h1> testVar text. </h1><br><h2> testVar2 text. </h2>")
== 0);
CHECK_TRUE(output_buf_size == 53);
- CHECK_TRUE(filenames_list->count == 1);
- CHECK_TRUE(simple_archiver_list_get(
- filenames_list,
+ CHECK_TRUE(filenames_set->count == 1);
+ CHECK_TRUE(simple_archiver_hash_map_iter(
+ filenames_set,
test_internal_check_matching_string_in_list,
(void*)test_http_template_html_filename)
- != NULL);
+ != 0);
simple_archiver_helper_cleanup_c_string(&buf);
- simple_archiver_list_free(&filenames_list);
+ simple_archiver_hash_map_free(&filenames_set);
__attribute__((cleanup(test_internal_cleanup_delete_temporary_file)))
const char *test_http_template_filename4 =
ASSERT_TRUE(config.paths != NULL);
buf = c_simple_http_path_to_generated(
- "/", &config, &output_buf_size, &filenames_list);
+ "/", &config, &output_buf_size, &filenames_set);
ASSERT_TRUE(buf != NULL);
//printf("%s\n", buf);
ASSERT_TRUE(
"<h1> some test text in test var file. </h1>")
== 0);
CHECK_TRUE(output_buf_size == 43);
- CHECK_TRUE(filenames_list->count == 2);
- CHECK_TRUE(simple_archiver_list_get(
- filenames_list,
+ CHECK_TRUE(filenames_set->count == 2);
+ CHECK_TRUE(simple_archiver_hash_map_iter(
+ filenames_set,
test_internal_check_matching_string_in_list,
(void*)test_http_template_html_filename2)
- != NULL);
- CHECK_TRUE(simple_archiver_list_get(
- filenames_list,
+ != 0);
+ CHECK_TRUE(simple_archiver_hash_map_iter(
+ filenames_set,
test_internal_check_matching_string_in_list,
(void*)test_http_template_html_var_filename)
- != NULL);
+ != 0);
simple_archiver_helper_cleanup_c_string(&buf);
}