Panda3D
|
00001 #ifndef HttpConnection_H 00002 #define HttpConnection_H 00003 //////////////////////////////////////////////////////////////////// 00004 //////////////////////////////////////////////////////////////////// 00005 #include "parsedhttprequest.h" 00006 #include "baseincomingset.h" 00007 00008 #include "bufferedwriter_growable.h" 00009 #include "http_bufferedreader.h" 00010 00011 00012 class HttpConnection : public Socket_TCP 00013 { 00014 protected: 00015 Http_BufferedReader _Reader; 00016 BufferedWriter_Growable _writer; 00017 Socket_Address _MyAddress; 00018 00019 Time_Out _Timer; 00020 00021 enum STATE_CONNECTIONS { 00022 READING_HEADER =1, 00023 READING_POST =2, 00024 WAITING_TO_FINALIZE =3, 00025 WRITING_DATA =4, 00026 ABORTING = 5, 00027 }; 00028 00029 00030 STATE_CONNECTIONS _state; 00031 00032 00033 ParsedHttpRequest _parser; 00034 00035 StrTargetBuffer _bodyDetail; 00036 std::string _headerDetail; 00037 00038 int CloseStateWriter(Time_Clock ¤tTime); 00039 00040 public: 00041 virtual ~HttpConnection(void); 00042 const Socket_Address & GetMyAddress(void); 00043 virtual bool BuildPage( BufferedWriter_Growable &_writer, ParsedHttpRequest &parser) = 0; 00044 HttpConnection(SOCKET sck,Socket_Address &inaddr) ; 00045 00046 CloseState ProcessMessage(char * message,Time_Clock ¤tTime); 00047 int DoReadHeader(char * message, int buffersize,Time_Clock ¤tTime); 00048 int DoReadBody(char * message, int buffersize,Time_Clock ¤tTime); 00049 int ReadIt(char * message, int buffersize,Time_Clock ¤tTime); 00050 void Reset(); 00051 00052 virtual CloseState TryAndFinalize() { _state = WRITING_DATA; ;return ConnectionDoNotClose; }; 00053 00054 std::string GetFullmessage() { return _headerDetail + _bodyDetail; }; 00055 00056 public: 00057 static TypeHandle get_class_type() { 00058 return _type_handle; 00059 } 00060 static void init_type() { 00061 Socket_TCP::init_type(); 00062 register_type(_type_handle, "HttpConnection", 00063 Socket_TCP::get_class_type()); 00064 } 00065 virtual TypeHandle get_type() const { 00066 return get_class_type(); 00067 } 00068 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00069 00070 private: 00071 static TypeHandle _type_handle; 00072 }; 00073 00074 00075 #endif // HttpConnection_H 00076 00077 00078