Compare commits

..

No commits in common. "dd5934351e07b720bb95ec1c4777393988a645f1" and "676b98751d81ce0e7e77b64ddc2b90164a12bcbd" have entirely different histories.

3 changed files with 8 additions and 30 deletions

View file

@ -98,11 +98,7 @@ int c_simple_http_internal_ends_with_FILE(const char *c_string) {
char *c_simple_http_path_to_generated(
const char *path,
const C_SIMPLE_HTTP_HTTPTemplates *templates,
size_t *output_buf_size) {
if (output_buf_size) {
*output_buf_size = 0;
}
const C_SIMPLE_HTTP_HTTPTemplates *templates) {
C_SIMPLE_HTTP_ParsedConfig *wrapped_hash_map =
simple_archiver_hash_map_get(templates->hash_map, path, strlen(path) + 1);
if (!wrapped_hash_map) {
@ -145,7 +141,7 @@ char *c_simple_http_path_to_generated(
size_t stored_html_size = strlen(stored_html) + 1;
html_buf = malloc(stored_html_size);
memcpy(html_buf, stored_html, stored_html_size);
html_buf_size = stored_html_size - 1;
html_buf_size = stored_html_size;
}
// At this point, html_buf contains the raw HTML as a C-string.
@ -161,7 +157,7 @@ char *c_simple_http_path_to_generated(
size_t delimeter_count = 0;
// xxxx xxx0 - Initial state, no delimeter reached.
// xxxx xxx1 - Three left-curly-brace delimeters reached.
// xxxx xxx1 - Three "{" delimeters reached.
unsigned int state = 0;
for (; idx < html_buf_size; ++idx) {
@ -325,17 +321,11 @@ char *c_simple_http_path_to_generated(
return NULL;
}
to_fill.html[final_size] = 0;
if (output_buf_size) {
*output_buf_size = final_size;
}
return to_fill.html;
} else {
// Prevent cleanup fn from "free"ing html_buf and return it verbatim.
char *buf = html_buf;
html_buf = NULL;
if (output_buf_size) {
*output_buf_size = html_buf_size;
}
return buf;
}
}

View file

@ -19,17 +19,11 @@
#include "http.h"
// Standard library includes.
#include <stddef.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 non-NULL, it will be set to the size of the returned
// buffer.
char *c_simple_http_path_to_generated(
const char *path,
const C_SIMPLE_HTTP_HTTPTemplates *templates,
size_t *output_buf_size);
const C_SIMPLE_HTTP_HTTPTemplates *templates);
#endif

View file

@ -248,13 +248,10 @@ int main(void) {
);
ASSERT_TRUE(config.paths != NULL);
size_t output_buf_size;
__attribute__((cleanup(simple_archiver_helper_cleanup_c_string)))
char *buf = c_simple_http_path_to_generated("/", &config, &output_buf_size);
char *buf = c_simple_http_path_to_generated("/", &config);
ASSERT_TRUE(buf != NULL);
ASSERT_TRUE(strcmp(buf, "<h1>Test</h1>") == 0);
CHECK_TRUE(output_buf_size == 13);
simple_archiver_helper_cleanup_c_string(&buf);
__attribute__((cleanup(test_internal_cleanup_delete_temporary_file)))
@ -286,7 +283,7 @@ int main(void) {
);
ASSERT_TRUE(config.paths != NULL);
buf = c_simple_http_path_to_generated("/", &config, &output_buf_size);
buf = c_simple_http_path_to_generated("/", &config);
ASSERT_TRUE(buf != NULL);
printf("%s\n", buf);
ASSERT_TRUE(
@ -294,7 +291,6 @@ int main(void) {
buf,
"<h1> Some text. </h1><br><h2> More text. </h2>")
== 0);
CHECK_TRUE(output_buf_size == 46);
simple_archiver_helper_cleanup_c_string(&buf);
__attribute__((cleanup(test_internal_cleanup_delete_temporary_file)))
@ -349,7 +345,7 @@ int main(void) {
);
ASSERT_TRUE(config.paths != NULL);
buf = c_simple_http_path_to_generated("/", &config, &output_buf_size);
buf = c_simple_http_path_to_generated("/", &config);
ASSERT_TRUE(buf != NULL);
printf("%s\n", buf);
ASSERT_TRUE(
@ -357,7 +353,6 @@ int main(void) {
buf,
"<h1> testVar text. </h1><br><h2> testVar2 text. </h2>")
== 0);
CHECK_TRUE(output_buf_size == 53);
simple_archiver_helper_cleanup_c_string(&buf);
__attribute__((cleanup(test_internal_cleanup_delete_temporary_file)))
@ -432,7 +427,7 @@ int main(void) {
);
ASSERT_TRUE(config.paths != NULL);
buf = c_simple_http_path_to_generated("/", &config, &output_buf_size);
buf = c_simple_http_path_to_generated("/", &config);
ASSERT_TRUE(buf != NULL);
printf("%s\n", buf);
ASSERT_TRUE(
@ -440,7 +435,6 @@ int main(void) {
buf,
"<h1> some test text in test var file. </h1>")
== 0);
CHECK_TRUE(output_buf_size == 43);
simple_archiver_helper_cleanup_c_string(&buf);
}