Shadowrun: Awakened 29 September 2011 - Build 871
HTTPConnection.h
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 #include "NativeFeatureIncludes.h"
00019 #if _RAKNET_SUPPORT_HTTPConnection==1 && _RAKNET_SUPPORT_TCPInterface==1
00020 
00021 #ifndef __HTTP_CONNECTION
00022 #define __HTTP_CONNECTION
00023 
00024 #include "Export.h"
00025 #include "RakString.h"
00026 #include "RakMemoryOverride.h"
00027 #include "RakNetTypes.h"
00028 #include "DS_Queue.h"
00029 
00030 namespace RakNet
00031 {
00033 class TCPInterface;
00034 struct SystemAddress;
00035 
00043 class RAK_DLL_EXPORT HTTPConnection
00044 {
00045 public:
00046     // GetInstance() and DestroyInstance(instance*)
00047     STATIC_FACTORY_DECLARATIONS(HTTPConnection)
00048 
00049     
00050     HTTPConnection();
00051     virtual ~HTTPConnection();
00052 
00054     void Init(TCPInterface *_tcp, const char *host, unsigned short port=80);
00055 
00063     void Post(const char *path, const char *data, const char *_contentType="application/x-www-form-urlencoded");
00064 
00067     void Get(const char *path);
00068     
00070     bool HasRead(void) const;
00071 
00074     RakNet::RakString Read(void);
00075 
00077     void Update(void);
00078 
00080     SystemAddress GetServerAddress(void) const;
00081 
00087    void ProcessTCPPacket(Packet *packet);
00088 
00091     enum ResponseCodes { NoBody=1001, OK=200, Deleted=1002 };
00092 
00093     HTTPConnection& operator=(const HTTPConnection& rhs){(void) rhs; return *this;}
00094    
00096     struct BadResponse
00097     {
00098     public:
00099         BadResponse() {code=0;}
00100         
00101         BadResponse(const unsigned char *_data, int _code)
00102             : data((const char *)_data), code(_code) {}
00103         
00104         BadResponse(const char *_data, int _code)
00105             : data(_data), code(_code) {}
00106 
00107         operator int () const { return code; }
00108 
00109         RakNet::RakString data;
00110         int code;  // ResponseCodes
00111     };
00112 
00114     bool HasBadResponse(int *code, RakNet::RakString *data);
00115 
00117     bool IsBusy(void) const;
00118 
00120     int GetState(void) const;
00121 
00122     struct OutgoingCommand
00123     {
00124         RakNet::RakString remotePath;
00125         RakNet::RakString data;
00126         RakNet::RakString contentType;
00127         bool isPost;
00128     };
00129 
00130      DataStructures::Queue<OutgoingCommand> outgoingCommand;
00131      OutgoingCommand currentProcessingCommand;
00132 
00133 private:
00134     SystemAddress server;
00135     TCPInterface *tcp;
00136     RakNet::RakString host;
00137     unsigned short port;
00138     DataStructures::Queue<BadResponse> badResponses;
00139 
00140     enum ConnectionState
00141     {
00142         CS_NONE,
00143         CS_DISCONNECTING,
00144         CS_CONNECTING,
00145         CS_CONNECTED,
00146         CS_PROCESSING,
00147     } connectionState;
00148 
00149     RakNet::RakString incomingData;
00150     DataStructures::Queue<RakNet::RakString> results;
00151 
00152     void CloseConnection();
00153     
00154     /*
00155     enum { RAK_HTTP_INITIAL,
00156         RAK_HTTP_STARTING,
00157         RAK_HTTP_CONNECTING,
00158         RAK_HTTP_ESTABLISHED,
00159         RAK_HTTP_REQUEST_SENT,
00160         RAK_HTTP_IDLE } state;
00161 
00162     RakNet::RakString outgoing, incoming, path, contentType;
00163     void Process(Packet *packet); // the workhorse
00164     
00165     // this helps check the various status lists in TCPInterface
00166     typedef SystemAddress (TCPInterface::*StatusCheckFunction)(void);
00167     bool InList(StatusCheckFunction func);
00168     */
00169 
00170 };
00171 
00172 } // namespace RakNet
00173 
00174 #endif
00175 
00176 #endif // _RAKNET_SUPPORT_*

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net