00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00027 #include "platform.h"
00028 #include "microhttpd.h"
00029 #include "internal.h"
00030
00031 #ifndef WINDOWS
00032 #include <unistd.h>
00033 #endif
00034
00035 static int
00036 value_checker (void *cls,
00037 enum MHD_ValueKind kind,
00038 const char *key,
00039 const char *filename,
00040 const char *content_type,
00041 const char *transfer_encoding,
00042 const char *data, uint64_t off, size_t size)
00043 {
00044 unsigned int *pos = cls;
00045 #if 0
00046 fprintf (stderr,
00047 "VC: %llu %u `%s' `%s' `%s' `%s' `%.*s'\n",
00048 off, size,
00049 key, filename, content_type, transfer_encoding, size, data);
00050 #endif
00051 if (size == 0)
00052 return MHD_YES;
00053 *pos += size;
00054 return MHD_YES;
00055
00056 }
00057
00058
00059 static int
00060 test_simple_large ()
00061 {
00062 struct MHD_Connection connection;
00063 struct MHD_HTTP_Header header;
00064 struct MHD_PostProcessor *pp;
00065 int i;
00066 int delta;
00067 size_t size;
00068 char data[102400];
00069 unsigned int pos;
00070
00071 pos = 0;
00072 memset (data, 'A', sizeof (data));
00073 memcpy (data, "key=", 4);
00074 data[sizeof (data) - 1] = '\0';
00075 memset (&connection, 0, sizeof (struct MHD_Connection));
00076 memset (&header, 0, sizeof (struct MHD_HTTP_Header));
00077 connection.headers_received = &header;
00078 header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
00079 header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED;
00080 header.kind = MHD_HEADER_KIND;
00081 pp = MHD_create_post_processor (&connection, 1024, &value_checker, &pos);
00082 i = 0;
00083 size = strlen (data);
00084 while (i < size)
00085 {
00086 delta = 1 + RANDOM () % (size - i);
00087 MHD_post_process (pp, &data[i], delta);
00088 i += delta;
00089 }
00090 MHD_destroy_post_processor (pp);
00091 if (pos != sizeof (data) - 5)
00092 return 1;
00093 return 0;
00094 }
00095
00096 int
00097 main (int argc, char *const *argv)
00098 {
00099 unsigned int errorCount = 0;
00100
00101 errorCount += test_simple_large ();
00102 if (errorCount != 0)
00103 fprintf (stderr, "Error (code: %u)\n", errorCount);
00104 return errorCount != 0;
00105 }