From f5c34a222b6e57549e28553f26ed55c7db4b5284 Mon Sep 17 00:00:00 2001 From: Max Christian Pohle Date: Fri, 19 Nov 2021 17:09:39 +0100 Subject: Looks promising --- .gitignore | 2 ++ main.c | 25 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1a94556 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +main + diff --git a/main.c b/main.c index 5395ab2..da67e45 100644 --- a/main.c +++ b/main.c @@ -223,19 +223,36 @@ void * next_customer(size_t new_socket) { while(1) { size_t size_remaining = (size_t) output_buffer_length - (p - output_buffer) - 1; printf("%ld remaining.\n", size_remaining); fflush(stdout); - if(size_remaining <= 0) + + if(size_remaining <= 0) { + verbose("> not even the boundary would fit in that what is left.\n"); break; + } p = (char *) memchr( (void *) p, '-', size_remaining); + + if(!p) { + verbose("> no further minus found.\n"); + break; + } + + end = p; + if(end[-1] == '\n') end--; + if(end[-1] == '\r') end--; p += strspn(p, "-"); - if(0 >= strcmp(p, http_header.boundary)) { - verbose("content ends here"); + if(0 == strncmp(p, http_header.boundary, http_header.boundary_size)) { + verbose("> Content ends here, size of the last file is %ld\n", end - start); + + fwrite(start, 20, 1, stdout); + puts(" <[first 20 bytes]\n"); + fwrite(end - 20, 20, 1, stdout); + puts(" <[last 20 bytes]\n"); break; } else { - printf("[%ld] kack: %c\n", size_remaining, p[0]); fflush(stdout); + // printf("[%ld] kack: %c\n", size_remaining, p[0]); fflush(stdout); p = p + 1; } } -- cgit v1.2.3