diff options
Diffstat (limited to 'src/daemon/postprocessor_test.c')
-rw-r--r-- | src/daemon/postprocessor_test.c | 159 |
1 files changed, 80 insertions, 79 deletions
diff --git a/src/daemon/postprocessor_test.c b/src/daemon/postprocessor_test.c index a931b300..6641fe1e 100644 --- a/src/daemon/postprocessor_test.c +++ b/src/daemon/postprocessor_test.c @@ -40,10 +40,10 @@ * Each series of checks should be terminated by * five NULL-entries. */ -const char * want[] = { +const char *want[] = { #define URL_DATA "abc=def&x=5" #define URL_START 0 - "abc", NULL, NULL, NULL, "def", + "abc", NULL, NULL, NULL, "def", "x", NULL, NULL, NULL, "5", #define URL_END (URL_START + 10) NULL, NULL, NULL, NULL, NULL, @@ -63,81 +63,80 @@ const char * want[] = { }; static int -mismatch(const char * a, const char * b) { - if (a == b) +mismatch (const char *a, const char *b) +{ + if (a == b) return 0; - if ( (a == NULL) || - (b == NULL) ) + if ((a == NULL) || (b == NULL)) return 1; - return 0 != strcmp(a, b); + return 0 != strcmp (a, b); } static int -value_checker(void * cls, - enum MHD_ValueKind kind, - const char * key, - const char * filename, - const char * content_type, - const char * transfer_encoding, - const char * data, - size_t off, - size_t size) { - int * want_off = cls; +value_checker (void *cls, + enum MHD_ValueKind kind, + const char *key, + const char *filename, + const char *content_type, + const char *transfer_encoding, + const char *data, size_t off, size_t size) +{ + int *want_off = cls; int idx = *want_off; #if 0 - fprintf(stderr, - "VC: `%s' `%s' `%s' `%s' `%.*s'\n", - key, filename, content_type, transfer_encoding, size, data); + fprintf (stderr, + "VC: `%s' `%s' `%s' `%s' `%.*s'\n", + key, filename, content_type, transfer_encoding, size, data); #endif if (size == 0) return MHD_YES; - if ( (idx < 0) || - (want[idx] == NULL) || - (0 != strcmp(key, want[idx])) || - (mismatch(filename, want[idx+1])) || - (mismatch(content_type, want[idx+2])) || - (mismatch(transfer_encoding, want[idx+3])) || - (0 != memcmp(data, &want[idx+4][off], size)) ) + if ((idx < 0) || + (want[idx] == NULL) || + (0 != strcmp (key, want[idx])) || + (mismatch (filename, want[idx + 1])) || + (mismatch (content_type, want[idx + 2])) || + (mismatch (transfer_encoding, want[idx + 3])) || + (0 != memcmp (data, &want[idx + 4][off], size))) { *want_off = -1; return MHD_NO; } - if (off + size == strlen(want[idx+4])) + if (off + size == strlen (want[idx + 4])) *want_off = idx + 5; return MHD_YES; - + } static int -test_urlencoding() { +test_urlencoding () +{ struct MHD_Connection connection; struct MHD_HTTP_Header header; - struct MHD_PostProcessor * pp; + struct MHD_PostProcessor *pp; unsigned int want_off = URL_START; int i; int delta; size_t size; - memset(&connection, 0, sizeof(struct MHD_Connection)); - memset(&header, 0, sizeof(struct MHD_HTTP_Header)); + memset (&connection, 0, sizeof (struct MHD_Connection)); + memset (&header, 0, sizeof (struct MHD_HTTP_Header)); connection.headers_received = &header; header.header = MHD_HTTP_HEADER_CONTENT_TYPE; header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED; header.kind = MHD_HEADER_KIND; - pp = MHD_create_post_processor(&connection, - 1024, - &value_checker, - &want_off); + pp = MHD_create_post_processor (&connection, + 1024, &value_checker, &want_off); i = 0; - size = strlen(URL_DATA); - while (i < size) { - delta = 1 + random() % (size - i); - MHD_post_process(pp, &URL_DATA[i], delta); - i += delta; - } - MHD_destroy_post_processor(pp); + size = strlen (URL_DATA); + while (i < size) + { + delta = 1 + random () % (size - i); + MHD_post_process (pp, &URL_DATA[i], delta); + i += delta; + } + MHD_destroy_post_processor (pp); if (want_off != URL_END) return 1; return 0; @@ -145,33 +144,34 @@ test_urlencoding() { static int -test_multipart() { +test_multipart () +{ struct MHD_Connection connection; struct MHD_HTTP_Header header; - struct MHD_PostProcessor * pp; + struct MHD_PostProcessor *pp; unsigned int want_off = FORM_START; int i; int delta; size_t size; - memset(&connection, 0, sizeof(struct MHD_Connection)); - memset(&header, 0, sizeof(struct MHD_HTTP_Header)); + memset (&connection, 0, sizeof (struct MHD_Connection)); + memset (&header, 0, sizeof (struct MHD_HTTP_Header)); connection.headers_received = &header; header.header = MHD_HTTP_HEADER_CONTENT_TYPE; - header.value = MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA ", boundary=AaB03x"; + header.value = + MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA ", boundary=AaB03x"; header.kind = MHD_HEADER_KIND; - pp = MHD_create_post_processor(&connection, - 1024, - &value_checker, - &want_off); + pp = MHD_create_post_processor (&connection, + 1024, &value_checker, &want_off); i = 0; - size = strlen(FORM_DATA); - while (i < size) { - delta = 1 + random() % (size - i); - MHD_post_process(pp, &FORM_DATA[i], delta); - i += delta; - } - MHD_destroy_post_processor(pp); + size = strlen (FORM_DATA); + while (i < size) + { + delta = 1 + random () % (size - i); + MHD_post_process (pp, &FORM_DATA[i], delta); + i += delta; + } + MHD_destroy_post_processor (pp); if (want_off != FORM_END) return 2; return 0; @@ -179,33 +179,34 @@ test_multipart() { static int -test_nested_multipart() { +test_nested_multipart () +{ struct MHD_Connection connection; struct MHD_HTTP_Header header; - struct MHD_PostProcessor * pp; + struct MHD_PostProcessor *pp; unsigned int want_off = FORM_NESTED_START; int i; int delta; size_t size; - memset(&connection, 0, sizeof(struct MHD_Connection)); - memset(&header, 0, sizeof(struct MHD_HTTP_Header)); + memset (&connection, 0, sizeof (struct MHD_Connection)); + memset (&header, 0, sizeof (struct MHD_HTTP_Header)); connection.headers_received = &header; header.header = MHD_HTTP_HEADER_CONTENT_TYPE; - header.value = MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA ", boundary=AaB03x"; + header.value = + MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA ", boundary=AaB03x"; header.kind = MHD_HEADER_KIND; - pp = MHD_create_post_processor(&connection, - 1024, - &value_checker, - &want_off); + pp = MHD_create_post_processor (&connection, + 1024, &value_checker, &want_off); i = 0; - size = strlen(FORM_NESTED_DATA); - while (i < size) { - delta = 1 + random() % (size - i); - MHD_post_process(pp, &FORM_NESTED_DATA[i], delta); - i += delta; - } - MHD_destroy_post_processor(pp); + size = strlen (FORM_NESTED_DATA); + while (i < size) + { + delta = 1 + random () % (size - i); + MHD_post_process (pp, &FORM_NESTED_DATA[i], delta); + i += delta; + } + MHD_destroy_post_processor (pp); if (want_off != FORM_NESTED_END) return 4; return 0; @@ -216,9 +217,9 @@ main (int argc, char *const *argv) { unsigned int errorCount = 0; - errorCount += test_urlencoding(); - errorCount += test_multipart(); - errorCount += test_nested_multipart(); + errorCount += test_urlencoding (); + errorCount += test_multipart (); + errorCount += test_nested_multipart (); if (errorCount != 0) fprintf (stderr, "Error (code: %u)\n", errorCount); return errorCount != 0; /* 0 == pass */ |