Panda3D
 All Classes Functions Variables Enumerations
parsedhttprequest.h
00001 #ifndef __PARSEDHTTPREQUEST_GM_H__
00002 #define __PARSEDHTTPREQUEST_GM_H__
00003 
00004 #include "string"
00005 #include "map"
00006 #include "stdlib.h"
00007 
00008 
00009 class ParsedHttpRequest
00010 {
00011 protected:
00012     std::string             _Raw_Text;
00013     std::string             _RequestType;
00014     std::string             _RequestText;
00015     std::string             _Requestoptions;
00016     std::string             _BodyText;
00017 
00018 
00019     std::map<std::string,std::string>   _parameters;
00020     std::map<std::string,std::string>   _header_Lines;
00021 
00022     std::string deCanonicalize(std::string &inval);
00023     size_t  PullCR(std::string &src, std::string &dst);
00024 
00025 public:
00026     void clear(void);
00027     const std::string   GetRequestOptionString() { return _Requestoptions; };
00028     const std::string * GetOption(const std::string & query);
00029     bool GetOption(const std::string & query, std::string & out_value);
00030     bool ParseThis(char * request);
00031     std::string & GetRequestURL(void);
00032     const std::string & GetRawRequest(void) const { return _Raw_Text; };
00033     const std::string & GetRequestType(void) const { return _RequestType; };
00034     bool ProcessOptionString(std::string str);
00035     bool ProcessParamSet(std::string &str);
00036 
00037 
00038     void SetBodyText(const std::string &  text)
00039     {
00040         _BodyText = text;
00041     }
00042 
00043     const std::string & getBodyText() { return _BodyText; };
00044 
00045     int getContentLength()
00046     {
00047         int answer = 0;
00048         std::map<std::string,std::string>::iterator ii = _header_Lines.find("Content-Length");
00049         if(ii != _header_Lines.end())
00050             answer = atol(ii->second.c_str());
00051 
00052         return answer;
00053     };
00054 };
00055 
00056 /*
00057 class ParsedHttpResponse
00058 {
00059     std::string             _Raw_Text;
00060     std::string             _response_header;
00061     
00062     std::map<std::string,std::string>   _header_Lines;
00063 
00064 
00065 public:
00066 
00067     std::string GetresponseCode()
00068     {
00069         std::string answer;
00070 
00071         size_t pos = _response_header.find_first_of(" ");
00072         if(pos != std::string::npos)
00073             answer =   support::trim_tonew(_response_header.substr(pos,100));
00074 
00075 
00076         pos = answer.find_first_of(" \t\n\r\0");
00077         if(pos != std::string::npos)
00078             answer =   support::trim_tonew(answer.substr(0,pos));
00079 
00080 
00081         return answer;
00082     }
00083 
00084     bool ParseThis(const std::string &response)
00085     {   
00086         _Raw_Text = response;
00087 
00088         int line_number = 0;
00089         std::string work1(_Raw_Text);
00090         for(size_t pos = work1.find_first_of("\n\r\0") ; pos != std::string::npos ;   pos = work1.find_first_of("\n\r\0") )
00091         {
00092             std::string  line1 = work1.substr(0,pos);
00093             work1 = work1.substr(pos+1);
00094             if(line1.size() > 2)
00095             {
00096 
00097                 if(line_number == 0 && line1.substr(0,4) == "HTTP")
00098                 {
00099                     // the first line...
00100                     _response_header = line1;
00101 //                    printf("[%s]\n",line1.c_str());
00102                 }
00103 
00104                 size_t i_pos = line1.find(':');
00105                 if(i_pos != std::string::npos && i_pos > 1)
00106                 {
00107                     std::string noune = support::trim_tonew(line1.substr(0,i_pos));
00108                     std::string verb  = support::trim_tonew(line1.substr(i_pos+1));
00109                     _header_Lines[noune] = verb;
00110                 }
00111                 line_number++;
00112             }
00113         }
00114 
00115 
00116         return !_response_header.empty();
00117     }
00118 
00119     size_t  PullCR(std::string &src, std::string &dst)
00120     {
00121         size_t offset = src.find(' ');
00122         if(offset >= 0 )
00123         {
00124             dst = src.substr(0,offset);
00125             src = src.substr(offset+1);
00126         }
00127         return offset;
00128     }
00129 
00130     int getContentLength()
00131     {
00132         int answer = 0;
00133         std::map<std::string,std::string>::iterator ii = _header_Lines.find("Content-Length");
00134         if(ii != _header_Lines.end())
00135             answer = atol(ii->second.c_str());
00136 
00137         return answer;
00138     };
00139 
00140 };
00141 */
00142 
00143 #endif //__PARSEDHTTPREQUEST_GM_H__
00144 
 All Classes Functions Variables Enumerations