Panda3D
parsedhttprequest.h
1 #ifndef __PARSEDHTTPREQUEST_GM_H__
2 #define __PARSEDHTTPREQUEST_GM_H__
3 
4 #include "string"
5 #include "map"
6 #include "stdlib.h"
7 
8 
10 {
11 protected:
12  std::string _Raw_Text;
13  std::string _RequestType;
14  std::string _RequestText;
15  std::string _Requestoptions;
16  std::string _BodyText;
17 
18 
19  std::map<std::string,std::string> _parameters;
20  std::map<std::string,std::string> _header_Lines;
21 
22  std::string deCanonicalize(std::string &inval);
23  size_t PullCR(std::string &src, std::string &dst);
24 
25 public:
26  void clear(void);
27  const std::string GetRequestOptionString() { return _Requestoptions; };
28  const std::string * GetOption(const std::string & query);
29  bool GetOption(const std::string & query, std::string & out_value);
30  bool ParseThis(char * request);
31  std::string & GetRequestURL(void);
32  const std::string & GetRawRequest(void) const { return _Raw_Text; };
33  const std::string & GetRequestType(void) const { return _RequestType; };
34  bool ProcessOptionString(std::string str);
35  bool ProcessParamSet(std::string &str);
36 
37 
38  void SetBodyText(const std::string & text)
39  {
40  _BodyText = text;
41  }
42 
43  const std::string & getBodyText() { return _BodyText; };
44 
45  int getContentLength()
46  {
47  int answer = 0;
48  std::map<std::string,std::string>::iterator ii = _header_Lines.find("Content-Length");
49  if(ii != _header_Lines.end())
50  answer = atol(ii->second.c_str());
51 
52  return answer;
53  };
54 };
55 
56 /*
57 class ParsedHttpResponse
58 {
59  std::string _Raw_Text;
60  std::string _response_header;
61 
62  std::map<std::string,std::string> _header_Lines;
63 
64 
65 public:
66 
67  std::string GetresponseCode()
68  {
69  std::string answer;
70 
71  size_t pos = _response_header.find_first_of(" ");
72  if(pos != std::string::npos)
73  answer = support::trim_tonew(_response_header.substr(pos,100));
74 
75 
76  pos = answer.find_first_of(" \t\n\r\0");
77  if(pos != std::string::npos)
78  answer = support::trim_tonew(answer.substr(0,pos));
79 
80 
81  return answer;
82  }
83 
84  bool ParseThis(const std::string &response)
85  {
86  _Raw_Text = response;
87 
88  int line_number = 0;
89  std::string work1(_Raw_Text);
90  for(size_t pos = work1.find_first_of("\n\r\0") ; pos != std::string::npos ; pos = work1.find_first_of("\n\r\0") )
91  {
92  std::string line1 = work1.substr(0,pos);
93  work1 = work1.substr(pos+1);
94  if(line1.size() > 2)
95  {
96 
97  if(line_number == 0 && line1.substr(0,4) == "HTTP")
98  {
99  // the first line...
100  _response_header = line1;
101 // printf("[%s]\n",line1.c_str());
102  }
103 
104  size_t i_pos = line1.find(':');
105  if(i_pos != std::string::npos && i_pos > 1)
106  {
107  std::string noune = support::trim_tonew(line1.substr(0,i_pos));
108  std::string verb = support::trim_tonew(line1.substr(i_pos+1));
109  _header_Lines[noune] = verb;
110  }
111  line_number++;
112  }
113  }
114 
115 
116  return !_response_header.empty();
117  }
118 
119  size_t PullCR(std::string &src, std::string &dst)
120  {
121  size_t offset = src.find(' ');
122  if(offset >= 0 )
123  {
124  dst = src.substr(0,offset);
125  src = src.substr(offset+1);
126  }
127  return offset;
128  }
129 
130  int getContentLength()
131  {
132  int answer = 0;
133  std::map<std::string,std::string>::iterator ii = _header_Lines.find("Content-Length");
134  if(ii != _header_Lines.end())
135  answer = atol(ii->second.c_str());
136 
137  return answer;
138  };
139 
140 };
141 */
142 
143 #endif //__PARSEDHTTPREQUEST_GM_H__
144