summaryrefslogtreecommitdiff
path: root/src/HttpHeaderProcessor.h
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-06-23 17:34:20 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-06-23 17:34:20 +0900
commit5fc1b1ad297e78de9e0d596146780f05e0d643ab (patch)
tree4598d139b1a3e72352d72f584564f32287ea570a /src/HttpHeaderProcessor.h
parent5a0a62c5f43ef461897deb6615c73325b0c0e3ca (diff)
Rewritten HTTP header parser
Diffstat (limited to 'src/HttpHeaderProcessor.h')
-rw-r--r--src/HttpHeaderProcessor.h54
1 files changed, 27 insertions, 27 deletions
diff --git a/src/HttpHeaderProcessor.h b/src/HttpHeaderProcessor.h
index b352108f..dd8c2a51 100644
--- a/src/HttpHeaderProcessor.h
+++ b/src/HttpHeaderProcessor.h
@@ -2,7 +2,7 @@
/*
* aria2 - The high speed download utility
*
- * Copyright (C) 2006 Tatsuhiro Tsujikawa
+ * Copyright (C) 2012 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -47,51 +47,51 @@ namespace aria2 {
class HttpHeader;
class HttpHeaderProcessor {
-private:
- std::string buf_;
- size_t limit_;
-
- void checkHeaderLimit(size_t incomingLength);
-
public:
- HttpHeaderProcessor();
+ enum ParserMode {
+ CLIENT_PARSER,
+ SERVER_PARSER
+ };
- ~HttpHeaderProcessor();
-
- void update(const unsigned char* data, size_t length);
-
- void update(const std::string& data);
+ HttpHeaderProcessor(ParserMode mode);
+ ~HttpHeaderProcessor();
/**
- * Returns true if end of header is reached.
+ * Parses incoming data. Returns true if end of header is reached.
+ * This function stops processing data when end of header is
+ * reached.
*/
- bool eoh() const;
+ bool parse(const unsigned char* data, size_t length);
+ bool parse(const std::string& data);
/**
- * Retruns the number of bytes beyond the end of header.
+ * Retruns the number of bytes processed in the last invocation of
+ * parse().
*/
- size_t getPutBackDataLength() const;
+ size_t getLastBytesProcessed() const;
/**
* Processes the received header as a http response header and returns
* HttpHeader object.
*/
- SharedHandle<HttpHeader> getHttpResponseHeader();
-
- SharedHandle<HttpHeader> getHttpRequestHeader();
+ const SharedHandle<HttpHeader>& getResult() const;
std::string getHeaderString() const;
+ /**
+ * Resets internal status and ready for next header processing.
+ */
void clear();
-
- void setHeaderLimit(size_t limit)
- {
- limit_ = limit;
- }
+private:
+ ParserMode mode_;
+ int state_;
+ size_t lastBytesProcessed_;
+ std::string buf_;
+ std::string lastFieldName_;
+ SharedHandle<HttpHeader> result_;
+ std::string headers_;
};
-typedef SharedHandle<HttpHeaderProcessor> HttpHeaderProcessorHandle;
-
} // namespace aria2
#endif // D_HTTP_HEADER_PROCESSOR_H