From 18d0d7f3f62216898c76a7404f16743f4086726d Mon Sep 17 00:00:00 2001 From: Raghuram Subramani Date: Sun, 22 Jun 2025 12:55:58 +0530 Subject: (engine): maintain a list of content headers --- src/engine.c | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'src/engine.c') diff --git a/src/engine.c b/src/engine.c index 1cb3ae7..3d46373 100644 --- a/src/engine.c +++ b/src/engine.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -13,6 +14,11 @@ void ingest(char **buffer) { key_match_t *match; + list_t *content_headers = list_create(sizeof(contentfor_operand_t)); + if (content_headers == NULL) { + printf("Could not create content_headers\n"); + return; + } while (true) { match = find_next_key(*buffer); @@ -29,7 +35,7 @@ ingest(char **buffer) switch (directive->type) { case INCLUDE: { - char *operand = (char *) directive->operands; + char *operand = directive->operands; char *partial_path; asprintf(&partial_path, "%s/%s/%s", DIRECTORY, PARTIALS, operand); @@ -57,12 +63,27 @@ ingest(char **buffer) break; } case CONTENTFOR: { - contentfor_operands_t *operand - = (contentfor_operands_t *) directive->operands; - printf("CONTENTFOR: %s\n", operand->key); - printf("CONTENT: %s\n", operand->content); + contentfor_operand_t *operand = directive->operands; + list_add(content_headers, operand); + + /* printf("CONTENTFOR: %s\n", operand->key); */ + /* printf("CONTENT: %s\n", operand->content); */ + + /* printf("CONTENT: %.*s\n", operand->length, *buffer + match->offset); + */ + + char *temp_buffer; + asprintf(&temp_buffer, "%s", *buffer); - return; + free(*buffer); + asprintf(buffer, + "%.*s%s", + match->offset, + temp_buffer, + temp_buffer + operand->length); + + free(temp_buffer); + /* free(operand); */ break; } @@ -77,4 +98,12 @@ ingest(char **buffer) if (match != NULL) free(match); } + + for (size_t i = 0; i < content_headers->size; i++) { + contentfor_operand_t *op = list_get(content_headers, i); + free(op->content); + free(op->key); + } + + list_delete(content_headers); } -- cgit v1.2.3