httpObject.h

Engine/source/app/net/httpObject.h

More...

Classes:

Detailed Description

 1
 2//-----------------------------------------------------------------------------
 3// Copyright (c) 2012 GarageGames, LLC
 4//
 5// Permission is hereby granted, free of charge, to any person obtaining a copy
 6// of this software and associated documentation files (the "Software"), to
 7// deal in the Software without restriction, including without limitation the
 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22//-----------------------------------------------------------------------------
23
24#ifndef _HTTPOBJECT_H_
25#define _HTTPOBJECT_H_
26
27#ifndef _TVECTOR_H_
28#include "core/util/tVector.h"
29#endif
30#ifndef _TCPOBJECT_H_
31#include "app/net/tcpObject.h"
32#endif
33
34class HTTPObject : public TCPObject
35{
36private:
37   typedef TCPObject Parent;
38protected:
39   enum ParseState {
40      ParsingStatusLine,
41      ParsingHeader,
42      ParsingChunkHeader,
43      ProcessingBody,
44      ProcessingDone,
45   };
46   ParseState mParseState;
47   U32 mTotalBytes;
48   U32 mBytesRemaining;
49 public:
50   U32 mStatus;
51   F32 mVersion;
52   U32 mContentLength;
53   bool mChunkedEncoding;
54   U32 mChunkSize;
55   const char *mContentType;
56   char *mHostName;
57   char *mPath;
58   char *mQuery;
59   char *mPost;
60   U8 *mBufferSave;
61   U32 mBufferSaveSize;
62public:
63   static void expandPath(char *dest, const char *path, U32 destSize);
64   void get(const char *hostName, const char *urlName, const char *query);
65   void post(const char *host, const char *path, const char *query, const char *post);
66   HTTPObject();
67   ~HTTPObject();
68
69   //static HTTPObject *find(U32 tag);
70
71   virtual U32 onDataReceive(U8 *buffer, U32 bufferLen);
72   virtual U32 onReceive(U8 *buffer, U32 bufferLen); // process a buffer of raw packet data
73   virtual void onConnected();
74   virtual void onConnectFailed();
75   virtual void onDisconnect();
76   bool processLine(UTF8 *line);
77
78   DECLARE_CONOBJECT(HTTPObject);
79};
80
81
82#endif  // _H_HTTPOBJECT_
83