From b5fbd0879daeee44597bc8954c14e2d6d15ff571 Mon Sep 17 00:00:00 2001 From: visor Date: Thu, 11 Mar 2010 00:29:57 +0900 Subject: [PATCH] change the return value of input-text of file form. connection close header of response. --- lib/form.cc | 56 ++++++++++++++++++++++++++++++++++++--------------- lib/form.h | 10 +++++---- lib/formfile.cc | 24 +++++++++++++++++++--- lib/formfile.h | 8 ++++++-- lib/http.cc | 25 ++++++++++++++++++----- lib/http.h | 1 - lib/httpconst.h | 1 + modules/ml-formvar.cc | 19 ++++++++++------- 8 files changed, 106 insertions(+), 38 deletions(-) diff --git a/lib/form.cc b/lib/form.cc index 32627fd..5ac57ab 100644 --- a/lib/form.cc +++ b/lib/form.cc @@ -21,11 +21,11 @@ void CGIForm::read (const ustring& query) { e = query.find ('&', s); if (e == ustring::npos) { ie = query.end (); - insertNameValue (ib, ie); + insertNameValue (iarg, ib, ie); break; } else { ie = is + e; - insertNameValue (ib, ie); + insertNameValue (iarg, ib, ie); s = e + 1; } } @@ -87,10 +87,26 @@ void CGIForm::at (const ustring& name, ustring& ans) { } void CGIForm::at (const ustring& name, size_t i, ustring& ans) { + at (iarg, name, i, ans); +} + +size_t CGIForm::atSize (const ustring& name) { + return atSize (iarg, name); +} + +/* +void CGIForm::insert (const ustring& name, const ustring& value) { + insert (iarg, name, value); +} +*/ + +void CGIForm::at (map_t& mp, const ustring& name, size_t i, ustring& ans) { map_t::iterator it; - it = iarg.find (name); - if (it == iarg.end ()) { +// it = iarg.find (name); + it = mp.find (name); +// if (it == iarg.end ()) { + if (it == mp.end ()) { ans = uEmpty; } else { if (it->second < index.size ()) { @@ -109,11 +125,13 @@ void CGIForm::at (const ustring& name, size_t i, ustring& ans) { } } -size_t CGIForm::atSize (const ustring& name) { +size_t CGIForm::atSize (map_t& mp, const ustring& name) { map_t::iterator it; - it = iarg.find (name); - if (it == iarg.end ()) { +// it = iarg.find (name); + it = mp.find (name); +// if (it == iarg.end ()) { + if (it == mp.end ()) { } else { if (it->second < index.size ()) { std::vector* v = &index [it->second]; @@ -123,13 +141,16 @@ size_t CGIForm::atSize (const ustring& name) { return 0; } -void CGIForm::insert (const ustring& name, const ustring& value) { +void CGIForm::insert (map_t& mp, const ustring& name, const ustring& value) { if (checkName (name)) { - map_t::iterator it = iarg.find (name); +// map_t::iterator it = iarg.find (name); + map_t::iterator it = mp.find (name); std::vector* v; - if (it == iarg.end ()) { - v = insertName (name); +// if (it == iarg.end ()) { +// v = insertName (iarg, name); + if (it == mp.end ()) { + v = insertName (mp, name); } else { v = &index.at (it->second); } @@ -168,7 +189,7 @@ void CGIForm::dump (std::ostream& o) { } #endif /* DEBUG */ -void CGIForm::insertNameValue (uiterator& b, uiterator& e) { +void CGIForm::insertNameValue (map_t& mp, uiterator& b, uiterator& e) { uiterator it; if (b == e) @@ -181,7 +202,8 @@ void CGIForm::insertNameValue (uiterator& b, uiterator& e) { decode (name); decode (value); - insert (name, value); +// insert (name, value); + insert (mp, name, value); return; } } @@ -190,14 +212,16 @@ void CGIForm::insertNameValue (uiterator& b, uiterator& e) { ustring value; decode (name); - insert (name, value); +// insert (name, value); + insert (mp, name, value); } } -std::vector* CGIForm::insertName (const ustring& name) { +std::vector* CGIForm::insertName (map_t& mp, const ustring& name) { std::vector* ans = new std::vector; index.push_back (ans); - iarg.insert (map_t::value_type (name, index.size () - 1)); +// iarg.insert (map_t::value_type (name, index.size () - 1)); + mp.insert (map_t::value_type (name, index.size () - 1)); return ans; } diff --git a/lib/form.h b/lib/form.h index c0cf273..383c9fe 100644 --- a/lib/form.h +++ b/lib/form.h @@ -12,7 +12,6 @@ class CGIForm { public: typedef boost::unordered_map map_t; typedef boost::ptr_vector > indexary; -// typedef boost::ptr_vector pool_t; typedef std::vector pool_t; typedef enum { M_NONE, @@ -41,14 +40,17 @@ class CGIForm { virtual void at (const ustring& name, ustring& ans); virtual void at (const ustring& name, size_t i, ustring& ans); virtual size_t atSize (const ustring& name); +// virtual void insert (const ustring& name, const ustring& value); + virtual void at (map_t& mp, const ustring& name, size_t i, ustring& ans); + virtual size_t atSize (map_t& mp, const ustring& name); #ifdef DEBUG2 virtual void dump (std::ostream& o); #endif /* DEBUG */ - virtual void insert (const ustring& name, const ustring& value); + virtual void insert (map_t& mp, const ustring& name, const ustring& value); virtual void decode (ustring& key) = 0; virtual void fix (ustring& key) = 0; - virtual void insertNameValue (uiterator& b, uiterator& e); - virtual std::vector* insertName (const ustring& name); + virtual void insertNameValue (map_t& mp, uiterator& b, uiterator& e); + virtual std::vector* insertName (map_t& mp, const ustring& name); }; #endif /* FORM_H */ diff --git a/lib/formfile.cc b/lib/formfile.cc index c4cccec..dc94ca5 100644 --- a/lib/formfile.cc +++ b/lib/formfile.cc @@ -8,6 +8,18 @@ #include #include +void CGIFormFile::fileAt (const ustring& name, ustring& ans) { + fileAt (name, 0, ans); +} + +void CGIFormFile::fileAt (const ustring& name, size_t i, ustring& ans) { + at (filearg, name, i, ans); +} + +size_t CGIFormFile::fileAtSize (const ustring& name) { + return atSize (filearg, name); +} + void CGIFormFile::read_multipart (MotorEnv* env) { #ifdef DEBUG2 std::cerr << "boundary:" << boundary << "\n"; @@ -115,11 +127,13 @@ void CGIFormFile::searchPart (MotorEnv* env) { v = to_ustring (parts.size ()); // decode (name); fix (name); - insert (name, v); +// insert (name, v); + insert (filearg, name, v); parts.push_back (part (b, x)); // decode (filename); fix (filename); - filenames.push_back (filePart_osSafe (filename)); +// filenames.push_back (filePart_osSafe (filename)); + insert (iarg, name, filePart_osSafe (filename)); } else { size = x - b; if (size < env->appenv->postlimit) { @@ -128,7 +142,9 @@ void CGIFormFile::searchPart (MotorEnv* env) { fix (name); // decode (v); fix (v); - insert (name, v); +// insert (name, v); + insert (filearg, name, v); + // no filename } else { *env->log << "form variable '" << name << "': size limit.\n"; } @@ -210,6 +226,7 @@ void CGIFormFile::readMimeHead (char*& b, char* e, ustring& disp, ustring& name } } +#if 0 bool CGIFormFile::readFilename (int i, ustring& filename) { if (0 <= i && i < parts.size ()) { filename = filenames[i]; @@ -217,6 +234,7 @@ bool CGIFormFile::readFilename (int i, ustring& filename) { } return false; } +#endif bool CGIFormFile::saveFile (int i, const ustring& path, size_t max) { static size_t bsize = 65536; diff --git a/lib/formfile.h b/lib/formfile.h index ec7e3cf..759f8d6 100644 --- a/lib/formfile.h +++ b/lib/formfile.h @@ -11,6 +11,7 @@ class CGIFormFile: public CGIForm { public: typedef std::pair part; + map_t filearg; ustring tmpfile; ustring boundary; uregex re1; @@ -19,7 +20,7 @@ class CGIFormFile: public CGIForm { char* mapdata; size_t mapsize; std::vector parts; - std::vector filenames; +// std::vector filenames; CGIFormFile () { mapdata = NULL; @@ -28,6 +29,9 @@ class CGIFormFile: public CGIForm { unlinkTmpFile (); }; + virtual void fileAt (const ustring& name, ustring& ans); + virtual void fileAt (const ustring& name, size_t i, ustring& ans); + virtual size_t fileAtSize (const ustring& name); virtual void read_multipart (MotorEnv* env); virtual bool saveData (MotorEnv* env); virtual void unlinkTmpFile (); @@ -35,7 +39,7 @@ class CGIFormFile: public CGIForm { virtual void searchPart (MotorEnv* env); virtual void compileReg (); virtual void readMimeHead (char*& b, char* e, ustring& disp, ustring& name, ustring& filename, ustring& type); - virtual bool readFilename (int i, ustring& filename); +// virtual bool readFilename (int i, ustring& filename); virtual bool saveFile (int i, const ustring& path, size_t max); }; diff --git a/lib/http.cc b/lib/http.cc index 2723d6c..8d25efe 100644 --- a/lib/http.cc +++ b/lib/http.cc @@ -14,6 +14,8 @@ #include #include +#define NO_KEEPALIVE + void HTTPResponse::printNoCache (MotorOutput* out) { out->out_raw (CharConst ("Cache-Control: no-cache\n" "Pragma: no-cache\n")); @@ -30,11 +32,6 @@ void HTTPResponse::printCookie (MotorOutput* out, MotorEnv* env) { } } -void HTTPResponse::printLocation (MotorOutput* out, MotorEnv* env) { - throw (uErrorNotImpl); - /* *** */ -} - void HTTPResponse::setCookie (const ustring& key, const ustring& val, const ustring& path, time_t span, const ustring& domain, bool fsecure) { ustring ck; umatch m; @@ -148,6 +145,9 @@ void HTTPResponse::standardResponse (MotorOutput* out, const ustring& type, con if (fNoCache) printNoCache (out); printCookie (out, env); +#ifdef NO_KEEPALIVE + out->out_raw (CharConst (kRES_CONNECTION_CLOSE))->out_raw (uLF); +#endif out->out_raw (uLF); } @@ -159,6 +159,9 @@ void HTTPResponse::standardResponse_html (MotorOutput* out, MotorEnv* env) { if (fNoCache) printNoCache (out); printCookie (out, env); +#ifdef NO_KEEPALIVE + out->out_raw (CharConst (kRES_CONNECTION_CLOSE))->out_raw (uLF); +#endif out->out_raw (uLF); } @@ -200,6 +203,9 @@ void HTTPResponse::location (MotorOutput* out, const ustring& url, MotorEnv* en ->out_raw (CharConst ("\n" kRES_TYPE kMIME_TEXT "; " kCHARSET kCODE_UTF8 "\n")); printCookie (out, env); +#ifdef NO_KEEPALIVE + out->out_raw (CharConst (kRES_CONNECTION_CLOSE))->out_raw (uLF); +#endif out->out_raw (CharConst ("\n" "Location: ")) ->out_noCtrl (url) @@ -210,6 +216,9 @@ void HTTPResponse::location_html (MotorOutput* out, const ustring& url, MotorEn out->out_raw (CharConst (kRES_TYPE kMIME_HTML "; " kCHARSET kCODE_UTF8 "\n")); printNoCache (out); printCookie (out, env); +#ifdef NO_KEEPALIVE + out->out_raw (CharConst (kRES_CONNECTION_CLOSE))->out_raw (uLF); +#endif out->out_raw (CharConst ("\n" "\n" "\n" @@ -236,6 +245,9 @@ void HTTPResponse::noContentResponse (MotorOutput* out, MotorEnv* env) { kRES_TYPE kMIME_TEXT "; " kCHARSET kCODE_UTF8 "\n")); printNoCache (out); printCookie (out, env); +#ifdef NO_KEEPALIVE + out->out_raw (CharConst (kRES_CONNECTION_CLOSE))->out_raw (uLF); +#endif out->out_raw (CharConst ("\n" "No Content.\n")); } @@ -245,6 +257,9 @@ void HTTPResponse::forbiddenResponse (MotorOutput* out, MotorEnv* env) { kRES_TYPE kMIME_TEXT "; " kCHARSET kCODE_UTF8 "\n")); printNoCache (out); printCookie (out, env); +#ifdef NO_KEEPALIVE + out->out_raw (CharConst (kRES_CONNECTION_CLOSE))->out_raw (uLF); +#endif out->out_raw (CharConst ("\n" "Forbidden.\n")); } diff --git a/lib/http.h b/lib/http.h index 17edf45..8e1810e 100644 --- a/lib/http.h +++ b/lib/http.h @@ -23,7 +23,6 @@ class HTTPResponse { virtual ~HTTPResponse () {}; virtual void printNoCache (MotorOutput* out); virtual void printCookie (MotorOutput* out, MotorEnv* env); - virtual void printLocation (MotorOutput* out, MotorEnv* env); virtual void setCookie (const ustring& key, const ustring& val, const ustring& path, time_t span, const ustring& domain, bool fsecure); virtual void setCookiePair (uiterator& b, const uiterator& e); virtual void parseCookie (); diff --git a/lib/httpconst.h b/lib/httpconst.h index e06947e..507829b 100644 --- a/lib/httpconst.h +++ b/lib/httpconst.h @@ -60,6 +60,7 @@ #define kMIME_OCTET "application/octet-stream" #define kRES_TYPE "Content-type: " #define kRES_DISP "Content-Disposition: " +#define kRES_CONNECTION_CLOSE "Connection: close" #define kCHARSET "charset=" #define kATTACHMENT "attachment" #define kINLINE "inline" diff --git a/modules/ml-formvar.cc b/modules/ml-formvar.cc index 5efd84e..d15f948 100644 --- a/modules/ml-formvar.cc +++ b/modules/ml-formvar.cc @@ -377,11 +377,13 @@ MNode* ml_formvar_input_file (MNode* cell, MlEnv* mlenv) { if (mlenv->env->storedir.empty ()) { newStoreSerial (mlenv); } - mlenv->env->form->at (var, val); +// mlenv->env->form->at (var, val); + mlenv->env->form->fileAt (var, val); if (val.size () > 0) { i = strtoul (val); tgt = mlenv->env->path_store_file (fname); - if (mlenv->env->form->readFilename (i, filename)) { +// if (mlenv->env->form->readFilename (i, filename)) { + mlenv->env->form->at (var, filename); if (opt.filter.size () > 0) { boost::wsmatch m; if (wsearch_env (mlenv, filename, m, opt.filter)) { @@ -416,7 +418,7 @@ MNode* ml_formvar_input_file (MNode* cell, MlEnv* mlenv) { return NULL; } } - } +// } } else { if (opt.fvalue) { return NULL; @@ -460,14 +462,17 @@ MNode* ml_formvar_input_file_a (MNode* cell, MlEnv* mlenv) { } target0 = mlenv->env->path_store_file (prefix); - n = mlenv->env->form->atSize (name); +// n = mlenv->env->form->atSize (name); + n = mlenv->env->form->fileAtSize (name); for (i = 0; i < n; i ++) { - mlenv->env->form->at (name, i, val); +// mlenv->env->form->at (name, i, val); + mlenv->env->form->fileAt (name, i, val); if (val.size () > 0) { si.assign (to_ustring (i)); tgt.assign (target0).append (si); tgtname.assign (prefix).append (si); - if (mlenv->env->form->readFilename (i, filename)) { +// if (mlenv->env->form->readFilename (i, filename)) { + mlenv->env->form->at (name, filename); if (filename.length () > 0) { MNodeList l; mlenv->env->form->saveFile (i, tgt, 0); @@ -480,7 +485,7 @@ MNode* ml_formvar_input_file_a (MNode* cell, MlEnv* mlenv) { } #endif /* DEBUG */ } - } +// } } } return mlenv->retval = ans.release (); -- 2.11.0