author | Michael Krelin <hacker@klever.net> | 2005-10-24 21:13:21 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2005-10-24 21:13:21 (UTC) |
commit | 03b321d88a199c6390eb8ce51ac4b1a96b3535dd (patch) (unidiff) | |
tree | db45823c37b204ec0d8028b26fede362b62cf4ac | |
parent | db69589bdc32c60b1fce6700a35d4126058bf7bc (diff) | |
download | kingate-03b321d88a199c6390eb8ce51ac4b1a96b3535dd.zip kingate-03b321d88a199c6390eb8ce51ac4b1a96b3535dd.tar.gz kingate-03b321d88a199c6390eb8ce51ac4b1a96b3535dd.tar.bz2 |
fixed compilation withouth mimetic support
-rw-r--r-- | src/cgi_gateway.cc | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/cgi_gateway.cc b/src/cgi_gateway.cc index 1706679..a2681aa 100644 --- a/src/cgi_gateway.cc +++ b/src/cgi_gateway.cc | |||
@@ -1,208 +1,209 @@ | |||
1 | #include <errno.h> | 1 | #include <errno.h> |
2 | #include <ctype.h> | 2 | #include <ctype.h> |
3 | #include <sstream> | 3 | #include <sstream> |
4 | #include "kingate/cgi_gateway.h" | 4 | #include "kingate/cgi_gateway.h" |
5 | #include "kingate/util.h" | 5 | #include "kingate/util.h" |
6 | #include "kingate/exception.h" | 6 | #include "kingate/exception.h" |
7 | #include "config.h" | 7 | #include "config.h" |
8 | #ifdef HAVE_MIMETIC | 8 | #ifdef HAVE_MIMETIC |
9 | # include <mimetic/mimeentity.h> | 9 | # include <mimetic/mimeentity.h> |
10 | # include <mimetic/parser/itparser.h> | 10 | # include <mimetic/parser/itparser.h> |
11 | #endif /* HAVE_MIMETIC */ | 11 | #endif /* HAVE_MIMETIC */ |
12 | 12 | ||
13 | namespace kingate { | 13 | namespace kingate { |
14 | using mimetic::MimeEntity; | ||
15 | 14 | ||
16 | #ifdef HAVE_MIMETIC | 15 | #ifdef HAVE_MIMETIC |
16 | using mimetic::MimeEntity; | ||
17 | |||
17 | struct TornMimeEntity : public MimeEntity { | 18 | struct TornMimeEntity : public MimeEntity { |
18 | typedef istreambuf_iterator<char> it_type; | 19 | typedef istreambuf_iterator<char> it_type; |
19 | typedef it_type::iterator_category it_cat; | 20 | typedef it_type::iterator_category it_cat; |
20 | struct IParser : public mimetic::IteratorParser<it_type,it_cat> { | 21 | struct IParser : public mimetic::IteratorParser<it_type,it_cat> { |
21 | typedef mimetic::IteratorParser<it_type,it_cat> BT; | 22 | typedef mimetic::IteratorParser<it_type,it_cat> BT; |
22 | IParser(MimeEntity& me) | 23 | IParser(MimeEntity& me) |
23 | : BT::IteratorParser<it_type,it_cat>(me) { } | 24 | : BT::IteratorParser<it_type,it_cat>(me) { } |
24 | void loadHeader(it_type bit,it_type eit) { | 25 | void loadHeader(it_type bit,it_type eit) { |
25 | m_bit = bit; m_eit = eit; | 26 | m_bit = bit; m_eit = eit; |
26 | BT::loadHeader(); | 27 | BT::loadHeader(); |
27 | } | 28 | } |
28 | void loadBody(it_type bit,it_type eit) { | 29 | void loadBody(it_type bit,it_type eit) { |
29 | m_bit = bit; m_eit = eit; | 30 | m_bit = bit; m_eit = eit; |
30 | BT::loadBody(); | 31 | BT::loadBody(); |
31 | } | 32 | } |
32 | }; | 33 | }; |
33 | void load(istream& hs,istream& bs,int mask=0) { | 34 | void load(istream& hs,istream& bs,int mask=0) { |
34 | IParser prs(*this); | 35 | IParser prs(*this); |
35 | prs.iMask(mask); | 36 | prs.iMask(mask); |
36 | prs.loadHeader(it_type(hs),it_type()); | 37 | prs.loadHeader(it_type(hs),it_type()); |
37 | prs.loadBody(it_type(bs),it_type()); | 38 | prs.loadBody(it_type(bs),it_type()); |
38 | } | 39 | } |
39 | }; | 40 | }; |
40 | #endif /* HAVE_MIMETIC */ | 41 | #endif /* HAVE_MIMETIC */ |
41 | 42 | ||
42 | static string empty_string; | 43 | static string empty_string; |
43 | 44 | ||
44 | cgi_gateway::basic_file_t::~basic_file_t() { } | 45 | cgi_gateway::basic_file_t::~basic_file_t() { } |
45 | 46 | ||
46 | class string_file_t : public cgi_gateway::basic_file_t { | 47 | class string_file_t : public cgi_gateway::basic_file_t { |
47 | public: | 48 | public: |
48 | string _file_name; | 49 | string _file_name; |
49 | string _content_type; | 50 | string _content_type; |
50 | stringstream _content; | 51 | stringstream _content; |
51 | 52 | ||
52 | string_file_t(const string& fn,const string& ct,const string& s) | 53 | string_file_t(const string& fn,const string& ct,const string& s) |
53 | : _file_name(fn), _content_type(ct), _content(s,ios::in) { } | 54 | : _file_name(fn), _content_type(ct), _content(s,ios::in) { } |
54 | const string& filename() const { return _file_name; } | 55 | const string& filename() const { return _file_name; } |
55 | const string& content_type() const { return _content_type; } | 56 | const string& content_type() const { return _content_type; } |
56 | istream& content() { return _content; } | 57 | istream& content() { return _content; } |
57 | }; | 58 | }; |
58 | 59 | ||
59 | cgi_gateway::cgi_gateway(cgi_interface& ci,bool parsebody) | 60 | cgi_gateway::cgi_gateway(cgi_interface& ci,bool parsebody) |
60 | : iface(ci), b_parsed_content(false) { | 61 | : iface(ci), b_parsed_content(false) { |
61 | // Fetch GET content | 62 | // Fetch GET content |
62 | try { | 63 | try { |
63 | string qs = get_meta("QUERY_STRING"); | 64 | string qs = get_meta("QUERY_STRING"); |
64 | parse_query(qs,get); | 65 | parse_query(qs,get); |
65 | }catch(exception_notfound& enf) { } | 66 | }catch(exception_notfound& enf) { } |
66 | if(parsebody) | 67 | if(parsebody) |
67 | parse_request_body(); | 68 | parse_request_body(); |
68 | // Parse cookies | 69 | // Parse cookies |
69 | try { | 70 | try { |
70 | cookies.parse_cookies(get_meta("HTTP_COOKIE")); | 71 | cookies.parse_cookies(get_meta("HTTP_COOKIE")); |
71 | }catch(exception_notfound& enf) { } | 72 | }catch(exception_notfound& enf) { } |
72 | } | 73 | } |
73 | 74 | ||
74 | cgi_gateway::~cgi_gateway() throw() { | 75 | cgi_gateway::~cgi_gateway() throw() { |
75 | for(files_t::iterator i=files.begin();i!=files.end();++i) | 76 | for(files_t::iterator i=files.begin();i!=files.end();++i) |
76 | delete i->second; | 77 | delete i->second; |
77 | files.clear(); | 78 | files.clear(); |
78 | } | 79 | } |
79 | 80 | ||
80 | void cgi_gateway::parse_request_body() { | 81 | void cgi_gateway::parse_request_body() { |
81 | if(b_parsed_content) | 82 | if(b_parsed_content) |
82 | throw konforka::exception(CODEPOINT,"request body is already parsed"); | 83 | throw konforka::exception(CODEPOINT,"request body is already parsed"); |
83 | // Fetch POST content | 84 | // Fetch POST content |
84 | if(!strncasecmp( | 85 | if(!strncasecmp( |
85 | content_type().c_str(), | 86 | content_type().c_str(), |
86 | "application/x-www-form-urlencoded", | 87 | "application/x-www-form-urlencoded", |
87 | sizeof("application/x-www-form-urlencoded")-1) ) { | 88 | sizeof("application/x-www-form-urlencoded")-1) ) { |
88 | unsigned long cl = content_length(); | 89 | unsigned long cl = content_length(); |
89 | if(cl) { | 90 | if(cl) { |
90 | char * tmp = new char[cl]; | 91 | char * tmp = new char[cl]; |
91 | iface.in().read(tmp,cl); | 92 | iface.in().read(tmp,cl); |
92 | string qs(tmp,cl); | 93 | string qs(tmp,cl); |
93 | delete tmp; | 94 | delete tmp; |
94 | parse_query(qs,post); | 95 | parse_query(qs,post); |
95 | } | 96 | } |
96 | b_parsed_content = true; | 97 | b_parsed_content = true; |
97 | } | 98 | } |
98 | #ifdef HAVE_MIMETIC | 99 | #ifdef HAVE_MIMETIC |
99 | else if(!strncasecmp( | 100 | else if(!strncasecmp( |
100 | content_type().c_str(), | 101 | content_type().c_str(), |
101 | "multipart/form-data", | 102 | "multipart/form-data", |
102 | sizeof("multipart/form-data")-1) ) { | 103 | sizeof("multipart/form-data")-1) ) { |
103 | stringstream h; | 104 | stringstream h; |
104 | h | 105 | h |
105 | << "Content-Type: " << content_type() << "\r\n" | 106 | << "Content-Type: " << content_type() << "\r\n" |
106 | << "Content-Length: " << content_length() << "\r\n\n"; | 107 | << "Content-Length: " << content_length() << "\r\n\n"; |
107 | TornMimeEntity me; | 108 | TornMimeEntity me; |
108 | me.load(h,iface.in(),0); | 109 | me.load(h,iface.in(),0); |
109 | mimetic::MimeEntityList& parts = me.body().parts(); | 110 | mimetic::MimeEntityList& parts = me.body().parts(); |
110 | for(mimetic::MimeEntityList::iterator i=parts.begin();i!=parts.end();++i) { | 111 | for(mimetic::MimeEntityList::iterator i=parts.begin();i!=parts.end();++i) { |
111 | MimeEntity *p = *i; | 112 | MimeEntity *p = *i; |
112 | const mimetic::ContentDisposition& cd = p->header().contentDisposition(); | 113 | const mimetic::ContentDisposition& cd = p->header().contentDisposition(); |
113 | string n = cd.param("name"); | 114 | string n = cd.param("name"); |
114 | string fn = cd.param("filename"); | 115 | string fn = cd.param("filename"); |
115 | if(fn.empty()) { | 116 | if(fn.empty()) { |
116 | post.insert(params_t::value_type(n,p->body())); | 117 | post.insert(params_t::value_type(n,p->body())); |
117 | }else{ | 118 | }else{ |
118 | const mimetic::ContentType& ct = p->header().contentType(); | 119 | const mimetic::ContentType& ct = p->header().contentType(); |
119 | files.insert(files_t::value_type(n,new string_file_t(fn,ct.str(),p->body()))); | 120 | files.insert(files_t::value_type(n,new string_file_t(fn,ct.str(),p->body()))); |
120 | } | 121 | } |
121 | } | 122 | } |
122 | b_parsed_content = true; | 123 | b_parsed_content = true; |
123 | } | 124 | } |
124 | #endif /* HAVE_MIMETIC */ | 125 | #endif /* HAVE_MIMETIC */ |
125 | } | 126 | } |
126 | 127 | ||
127 | bool cgi_gateway::has_GET(const string& n) const { | 128 | bool cgi_gateway::has_GET(const string& n) const { |
128 | return get.find(n) != get.end(); | 129 | return get.find(n) != get.end(); |
129 | } | 130 | } |
130 | const string& cgi_gateway::get_GET(const string& n) const { | 131 | const string& cgi_gateway::get_GET(const string& n) const { |
131 | params_t::const_iterator i = get.find(n); | 132 | params_t::const_iterator i = get.find(n); |
132 | if(i==get.end()) | 133 | if(i==get.end()) |
133 | throw exception_notfound(CODEPOINT,"no such parameter"); | 134 | throw exception_notfound(CODEPOINT,"no such parameter"); |
134 | return i->second; | 135 | return i->second; |
135 | } | 136 | } |
136 | bool cgi_gateway::has_POST(const string& n) const { | 137 | bool cgi_gateway::has_POST(const string& n) const { |
137 | return post.find(n) != post.end(); | 138 | return post.find(n) != post.end(); |
138 | } | 139 | } |
139 | const string& cgi_gateway::get_POST(const string& n) const { | 140 | const string& cgi_gateway::get_POST(const string& n) const { |
140 | params_t::const_iterator i = post.find(n); | 141 | params_t::const_iterator i = post.find(n); |
141 | if(i==post.end()) | 142 | if(i==post.end()) |
142 | throw exception_notfound(CODEPOINT,"no such parameter"); | 143 | throw exception_notfound(CODEPOINT,"no such parameter"); |
143 | return i->second; | 144 | return i->second; |
144 | } | 145 | } |
145 | bool cgi_gateway::has_param(const string& n) const { | 146 | bool cgi_gateway::has_param(const string& n) const { |
146 | return has_GET(n) || has_POST(n); | 147 | return has_GET(n) || has_POST(n); |
147 | } | 148 | } |
148 | const string& cgi_gateway::get_param(const string& n) const { | 149 | const string& cgi_gateway::get_param(const string& n) const { |
149 | params_t::const_iterator i = get.find(n); | 150 | params_t::const_iterator i = get.find(n); |
150 | if(i!=get.end()) | 151 | if(i!=get.end()) |
151 | return i->second; | 152 | return i->second; |
152 | i = post.find(n); | 153 | i = post.find(n); |
153 | if(i!=post.end()) | 154 | if(i!=post.end()) |
154 | return i->second; | 155 | return i->second; |
155 | throw exception_notfound(CODEPOINT,"no such parameter"); | 156 | throw exception_notfound(CODEPOINT,"no such parameter"); |
156 | } | 157 | } |
157 | bool cgi_gateway::has_file(const string& n) const { | 158 | bool cgi_gateway::has_file(const string& n) const { |
158 | return files.find(n) != files.end(); | 159 | return files.find(n) != files.end(); |
159 | } | 160 | } |
160 | const cgi_gateway::file_t cgi_gateway::get_file(const string& n) const { | 161 | const cgi_gateway::file_t cgi_gateway::get_file(const string& n) const { |
161 | files_t::const_iterator i = files.find(n); | 162 | files_t::const_iterator i = files.find(n); |
162 | if(i==files.end()) | 163 | if(i==files.end()) |
163 | throw exception_notfound(CODEPOINT,"no such parameter"); | 164 | throw exception_notfound(CODEPOINT,"no such parameter"); |
164 | return i->second; | 165 | return i->second; |
165 | } | 166 | } |
166 | cgi_gateway::file_t cgi_gateway::get_file(const string& n) { | 167 | cgi_gateway::file_t cgi_gateway::get_file(const string& n) { |
167 | files_t::const_iterator i = files.find(n); | 168 | files_t::const_iterator i = files.find(n); |
168 | if(i==files.end()) | 169 | if(i==files.end()) |
169 | throw exception_notfound(CODEPOINT,"no such parameter"); | 170 | throw exception_notfound(CODEPOINT,"no such parameter"); |
170 | return i->second; | 171 | return i->second; |
171 | } | 172 | } |
172 | 173 | ||
173 | /* | 174 | /* |
174 | * deprecated stuff. | 175 | * deprecated stuff. |
175 | */ | 176 | */ |
176 | const string& cgi_gateway::get_content_type() const { | 177 | const string& cgi_gateway::get_content_type() const { |
177 | if(!has_meta("CONTENT_TYPE")) | 178 | if(!has_meta("CONTENT_TYPE")) |
178 | return empty_string; | 179 | return empty_string; |
179 | return get_meta("CONTENT_TYPE"); | 180 | return get_meta("CONTENT_TYPE"); |
180 | } | 181 | } |
181 | unsigned long cgi_gateway::get_content_length() const { | 182 | unsigned long cgi_gateway::get_content_length() const { |
182 | if(!has_meta("CONTENT_LENGTH")) | 183 | if(!has_meta("CONTENT_LENGTH")) |
183 | return 0; | 184 | return 0; |
184 | string cl = get_meta("CONTENT_LENGTH"); | 185 | string cl = get_meta("CONTENT_LENGTH"); |
185 | return strtol(cl.c_str(),NULL,10); | 186 | return strtol(cl.c_str(),NULL,10); |
186 | } | 187 | } |
187 | /* | 188 | /* |
188 | * | 189 | * |
189 | */ | 190 | */ |
190 | 191 | ||
191 | const string& cgi_gateway::http_request_header(const string& hn) const { | 192 | const string& cgi_gateway::http_request_header(const string& hn) const { |
192 | string mvn = "HTTP_"; | 193 | string mvn = "HTTP_"; |
193 | for(const char* p=hn.c_str();*p;p++) { | 194 | for(const char* p=hn.c_str();*p;p++) { |
194 | if(*p=='-') | 195 | if(*p=='-') |
195 | mvn += '_'; | 196 | mvn += '_'; |
196 | else | 197 | else |
197 | mvn += toupper(*p); | 198 | mvn += toupper(*p); |
198 | } | 199 | } |
199 | return get_meta(mvn); | 200 | return get_meta(mvn); |
200 | } | 201 | } |
201 | 202 | ||
202 | const string& cgi_gateway::auth_type() const { | 203 | const string& cgi_gateway::auth_type() const { |
203 | try { | 204 | try { |
204 | return get_meta("AUTH_TYPE"); | 205 | return get_meta("AUTH_TYPE"); |
205 | }catch(exception_notfound& enf) { | 206 | }catch(exception_notfound& enf) { |
206 | return empty_string; | 207 | return empty_string; |
207 | } | 208 | } |
208 | } | 209 | } |