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,112 +1,113 @@ | |||
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(); |