From 86f9fbefa58d91e151190c969216c751573bc664 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 4 Oct 2007 10:46:46 +0000 Subject: Discovered that the Bu::Client::disconnect() function didn't do anything. That has been fixed, it now safely disconnects after emptying the Client's outgoing buffer. Added some more helpers to Bu::FString. Added the beginings of ProtocolHttp using a new method for processing protocols that's based more strongly on an NFA state machine, this makes sense, but I never had the desire to actually try implementing it before. It's working pretty well. --- src/protocolhttp.h | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/protocolhttp.h (limited to 'src/protocolhttp.h') diff --git a/src/protocolhttp.h b/src/protocolhttp.h new file mode 100644 index 0000000..e10cb23 --- /dev/null +++ b/src/protocolhttp.h @@ -0,0 +1,63 @@ +#ifndef BU_PROTOCOL_HTTP_H +#define BU_PROTOCOL_HTTP_H + +#include +#include + +#include "bu/protocol.h" +#include "bu/client.h" +#include "bu/fstring.h" + +namespace Bu +{ + /** + * + */ + class ProtocolHttp : public Protocol + { + public: /* Types */ + typedef Bu::List TokenList; + + public: /* Interface */ + ProtocolHttp(); + virtual ~ProtocolHttp(); + + virtual void onNewConnection( Bu::Client *pClient ); + virtual void onNewData( Bu::Client *pClient ); + + private: + enum TokenType + { + ttOutOfData, + ttString, + ttNewline, + ttDoubleNewline, + ttSeperator + }; + /** + * Read an HTTP line, this is up to the first CRLF that isn't followed + * by a continuation character, converting it to one line as it reads. + *@param line All data read will be appended to line, even if no + * end-of-line is read. + *@returns True if an end-of-line is read and the line should be + * processed, false if the end-of-line has not been reached, and more + * data needs to be read before this operation can continue. + */ + TokenType getToken( Bu::FString &line ); + bool isWS( char buf ); + bool isSeperator( char buf ); + + private: /* state */ + Bu::Client *pClient; + TokenList lTokens; + + int iState; + + Bu::FString sMethod; + Bu::FString sPath; + int iMajor; + int iMinor; + }; +} + +#endif -- cgit v1.2.3