Browse files

Add ability to retrieve the error message.

  • Loading branch information...
1 parent c1136ee commit a5fd57cdd1c3afa70a2665f8c6d058ae65b0365c @FooBarWidget committed Jun 21, 2010
Showing with 10 additions and 2 deletions.
  1. +10 −2 multipart.cpp
View
12 multipart.cpp
@@ -46,6 +46,7 @@ class MultipartParser {
size_t headerFieldMark;
size_t headerValueMark;
size_t partDataMark;
+ const char *errorReason;
void callback(Callback cb, const char *buffer = NULL, size_t start = UNMARKED, size_t end = UNMARKED) {
if (start != UNMARKED && start == end) {
@@ -89,6 +90,7 @@ class MultipartParser {
void setError(const char *message) {
state = ERROR;
+ errorReason = message;
}
public:
@@ -124,6 +126,7 @@ class MultipartParser {
headerFieldMark = UNMARKED;
headerValueMark = UNMARKED;
partDataMark = UNMARKED;
+ errorReason = NULL;
onPartBegin = NULL;
onHeaderField = NULL;
@@ -354,6 +357,10 @@ class MultipartParser {
bool stopped() const {
return state == ERROR || state == END;
}
+
+ const char *getErrorMessage() const {
+ return errorReason;
+ }
};
#include <stdio.h>
@@ -399,8 +406,8 @@ main() {
parser.onPartEnd = onPartEnd;
parser.onEnd = onEnd;
- while (!feof(stdin)) {
- char buf[1024 * 16];
+ while (!parser.stopped() && !feof(stdin)) {
+ char buf[5];
size_t len = fread(buf, 1, sizeof(buf), stdin);
size_t fed = 0;
do {
@@ -409,5 +416,6 @@ main() {
printf("accepted %d bytes\n", (int) ret);
} while (fed < len && !parser.stopped());
}
+ printf("%s\n", parser.getErrorMessage());
return 0;
}

0 comments on commit a5fd57c

Please sign in to comment.