Permalink
Browse files

Add more debugging facilities.

  • Loading branch information...
1 parent 5fdd39b commit 3a4031cae732226ec7dfc24e49a3b267327ec593 @FooBarWidget committed Jul 6, 2010
Showing with 21 additions and 14 deletions.
  1. +1 −1 Makefile
  2. +1 −0 input.txt
  3. +19 −13 multipart.cpp
View
2 Makefile
@@ -1,2 +1,2 @@
multipart: multipart.cpp MultipartParser.h MultipartReader.h
- g++ -Wall multipart.cpp -o multipart
+ g++ -Wall -g multipart.cpp -o multipart
View
1 input.txt
@@ -1,5 +1,6 @@
--abcd
content-type: text/plain
+content-disposition: form-data; name="field1"; filename="field1"
foo-bar: abc
x: y
View
32 multipart.cpp
@@ -48,7 +48,7 @@ using namespace std;
}
void onPartData(const char *buffer, size_t size, void *userData) {
- printf("onPartData: (%s)\n", string(buffer, size).c_str());
+ //printf("onPartData: (%s)\n", string(buffer, size).c_str());
}
void onPartEnd(void *userData) {
@@ -63,31 +63,37 @@ using namespace std;
int
main() {
#ifdef TEST_PARSER
- MultipartParser parser("abcd");
+ MultipartParser parser;
parser.onPartBegin = onPartBegin;
parser.onHeaderField = onHeaderField;
parser.onHeaderValue = onHeaderValue;
parser.onPartData = onPartData;
parser.onPartEnd = onPartEnd;
parser.onEnd = onEnd;
#else
- MultipartReader parser("abcd");
+ MultipartReader parser;
parser.onPartBegin = onPartBegin;
parser.onPartData = onPartData;
parser.onPartEnd = onPartEnd;
parser.onEnd = onEnd;
#endif
- while (!parser.stopped() && !feof(stdin)) {
- char buf[100];
- size_t len = fread(buf, 1, sizeof(buf), stdin);
- size_t fed = 0;
- do {
- size_t ret = parser.feed(buf + fed, len - fed);
- fed += ret;
- //printf("accepted %d bytes\n", (int) ret);
- } while (fed < len && !parser.stopped());
+ for (int i = 0; i < 5; i++) {
+ parser.setBoundary("abcd");
+
+ FILE *f = fopen("input2.txt", "rb");
+ while (!parser.stopped() && !feof(f)) {
+ char buf[100];
+ size_t len = fread(buf, 1, sizeof(buf), f);
+ size_t fed = 0;
+ do {
+ size_t ret = parser.feed(buf + fed, len - fed);
+ fed += ret;
+ //printf("accepted %d bytes\n", (int) ret);
+ } while (fed < len && !parser.stopped());
+ }
+ printf("%s\n", parser.getErrorMessage());
+ fclose(f);
}
- printf("%s\n", parser.getErrorMessage());
return 0;
}

0 comments on commit 3a4031c

Please sign in to comment.