• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/web/HttpRequestBody.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #ifndef _httprequestbody_h
00018 #define _httprequestbody_h
00019 
00020 #include <spl/collection/Association.h>
00021 #include <spl/Memory.h>
00022 #include <spl/String.h>
00023 #include <spl/text/StringBuffer.h>
00024 #include <spl/io/TextStream.h>
00025 #include <spl/collection/Vector.h>
00026 
00032 class IHttpRequestBody : public IMemoryValidate
00033 {
00034 public:
00035         inline IHttpRequestBody() {}
00036         virtual ~IHttpRequestBody();
00037 
00038         virtual void Parse( const Array<byte>& cp, int pos, int len, int contentLen ) = 0;
00039 
00040         virtual int ByteCount() const = 0;
00041 
00042         virtual IHttpRequestBody *Clone() const = 0;
00043 
00044         virtual void Write( TextWriter& strm ) const = 0;
00045 
00046         virtual StringPtr ToString() const = 0;
00047 };
00048 
00049 class HttpRequestBodyGeneric : public IHttpRequestBody
00050 {
00051 protected:
00052         StringBuffer m_buf;
00053 
00054 public:
00055         HttpRequestBodyGeneric();
00056         HttpRequestBodyGeneric(const HttpRequestBodyGeneric& b);
00057         virtual ~HttpRequestBodyGeneric();
00058 
00059         virtual int ByteCount() const;
00060 
00061         virtual IHttpRequestBody *Clone() const;
00062 
00063         virtual void Parse( const Array<byte>& cp, int pos, int len, int contentLen );
00064 
00065         virtual void Write( TextWriter& strm ) const;
00066 
00067         virtual StringPtr ToString() const;
00068 
00069 #ifdef DEBUG
00070         virtual void ValidateMem() const;
00071         virtual void CheckMem() const;
00072 #endif
00073 };
00074 
00075 class HttpRequestBodyFormData : public IHttpRequestBody
00076 {
00077 protected:
00078         enum State
00079         {
00080                 HTTPBODY_STATE_NAME = 0,
00081                 HTTPBODY_STATE_VAL = 1
00082         };
00083 
00084         Vector<Association<String, String> > m_data;
00085         int m_byteCount;
00086         HttpRequestBodyFormData::State m_state;
00087         StringBuffer m_accum;
00088 
00089 public:
00090         HttpRequestBodyFormData();
00091         HttpRequestBodyFormData(const HttpRequestBodyFormData& body);
00092         virtual ~HttpRequestBodyFormData();
00093 
00094         HttpRequestBodyFormData& operator =(const HttpRequestBodyFormData& body);
00095 
00096         virtual int ByteCount() const;
00097 
00098         virtual IHttpRequestBody *Clone() const;
00099 
00100         virtual void Parse( const Array<byte>& cp, int pos, int len, int contentLen );
00101 
00102         inline int Count() const { return m_data.Count(); }
00103 
00104         inline Association<String, String>& Item(int idx) { return m_data.ElementAtRef(idx); }
00105 
00106         virtual void Write( TextWriter& strm ) const;
00107 
00108         virtual StringPtr ToString() const;
00109 
00110 #ifdef DEBUG
00111         virtual void ValidateMem() const;
00112         virtual void CheckMem() const;
00113 #endif
00114 };
00115 
00118 #endif