From e621df88d6e54943c3c5b5a7926ef4f22729ee02 Mon Sep 17 00:00:00 2001 From: visor Date: Thu, 9 Jul 2015 23:26:05 +0900 Subject: [PATCH] bug fix. --- lib/form.cc | 2 +- lib/formfile.cc | 9 +++------ lib/http-iconv.cc | 4 ++-- lib/motoroutput-iconv.cc | 8 ++++++++ lib/motoroutput-iconv.h | 1 + lib/util_string.cc | 10 +++++++++- lib/util_string.h | 2 +- modules/ml-neon.cc | 4 ++-- modules/ml-sendmail.cc | 3 +++ modules/ml-store.cc | 6 +++--- 10 files changed, 33 insertions(+), 16 deletions(-) diff --git a/lib/form.cc b/lib/form.cc index f49b121..5c2c29b 100644 --- a/lib/form.cc +++ b/lib/form.cc @@ -120,7 +120,7 @@ size_t CGIForm::postSize () { if (e == NULL) return 0; - return strtoul (e, NULL, 10); + return boost::lexical_cast (e); } int CGIForm::at (const ustring& name, ustring& ans) { diff --git a/lib/formfile.cc b/lib/formfile.cc index 7dfe8c7..b7e48be 100644 --- a/lib/formfile.cc +++ b/lib/formfile.cc @@ -70,15 +70,12 @@ bool CGIFormFile::saveData (MotorEnv* env) { s = std::cin.read (&b[0], s).gcount (); if (s <= 0) break; - s = ::write (fp.fd, &b[0], s); + ::write (fp.fd, &b[0], s); size -= s; mapsize += s; - if (size > 0) { - std::cerr << "post-file[" << mypid << ":" << env->scriptName << "]: reading " << mapsize << "Bytes...\n"; // cerrはバッファリングされない - } } -// fp.close (); - std::cerr << "post-file[" << mypid << ":" << env->scriptName << "]: done " << mapsize << "Bytes\n"; +// fp.close (); mmapした後にクローズする。 +// std::cerr << "post-file[" << mypid << ":" << env->scriptName << "]: done " << mapsize << "Bytes\n"; // 出力サイズが大きいと、デッドロックする。 mapdata = (char*)mmap (NULL, mapsize, PROT_READ, MAP_PRIVATE, fp.fd, 0); #ifdef DEBUG2 std::cerr << (void*) mapdata << ": " << mapsize << "\n"; diff --git a/lib/http-iconv.cc b/lib/http-iconv.cc index 31693c5..b5c4ea9 100644 --- a/lib/http-iconv.cc +++ b/lib/http-iconv.cc @@ -4,10 +4,10 @@ ustring HTTPSendIConv::cv (const ustring& text) { // 出力側 - return cd_out.cv (text); + return cd_out.cv (text, true); } ustring HTTPSendIConv::rcv (const ustring& text) { // 入力側 - return cd_in.cv (text); + return cd_in.cv (text, true); } diff --git a/lib/motoroutput-iconv.cc b/lib/motoroutput-iconv.cc index 7efb575..e7733c7 100644 --- a/lib/motoroutput-iconv.cc +++ b/lib/motoroutput-iconv.cc @@ -14,6 +14,14 @@ MotorOutput* MotorOutputIConv::out_templateText (const ustring& str) { return out_toText (str); } +MotorOutput* MotorOutputIConv::flush () { + ustring o; + + o = cd.cv (uEmpty, true); // flush + out (o.data (), o.length ()); + return this; +} + MotorOutput* MotorOutputIConvOStream::out (const ustring::value_type* s, size_t len) { std::cout.write (s, len); return this; diff --git a/lib/motoroutput-iconv.h b/lib/motoroutput-iconv.h index eb1a3ee..79d2077 100644 --- a/lib/motoroutput-iconv.h +++ b/lib/motoroutput-iconv.h @@ -17,6 +17,7 @@ class MotorOutputIConv: public MotorOutput { virtual MotorOutput* out_toText (const ustring& str); virtual MotorOutput* out_templateText (const ustring& str); + virtual MotorOutput* flush (); virtual const ustring charset () { return code; }; diff --git a/lib/util_string.cc b/lib/util_string.cc index dd6b103..ef31ebf 100644 --- a/lib/util_string.cc +++ b/lib/util_string.cc @@ -25,7 +25,7 @@ UIConv::UIConv (const char* in, const char* out) { } } -ustring UIConv::cv (const ustring& text) { +ustring UIConv::cv (const ustring& text, bool flush) { ustring ans; if (cd != ICONV_ERR) { @@ -58,11 +58,19 @@ ustring UIConv::cv (const ustring& text) { if (obuf > buf) ans.append (buf, obuf - buf); } + if (flush) { + obuf = buf; + osize = 4096; + rsize = ::iconv (cd, NULL, NULL, &obuf, &osize); + if (obuf > buf) + ans.append (buf, obuf - buf); + } delete buf; } return ans; } +/////////////////////////////////////////////////////////////////////// static bool isDigit (int c) { return '0' <= c && c <= '9'; } diff --git a/lib/util_string.h b/lib/util_string.h index e150226..feb6777 100644 --- a/lib/util_string.h +++ b/lib/util_string.h @@ -21,7 +21,7 @@ class UIConv { cd = ICONV_ERR; } }; - virtual ustring cv (const ustring& text); + virtual ustring cv (const ustring& text, bool flush = false); }; ustring c3 (const ustring& str); diff --git a/modules/ml-neon.cc b/modules/ml-neon.cc index e4af960..a96ade9 100644 --- a/modules/ml-neon.cc +++ b/modules/ml-neon.cc @@ -509,7 +509,7 @@ ustring NeonQuery::buildMimeSeparator_file (const ustring& name, const ustring& ustring NeonQuery::cv (const ustring& src) { if (cv_out.get ()) { - return cv_out->cv (src); + return cv_out->cv (src, true); } else { return src; } @@ -517,7 +517,7 @@ ustring NeonQuery::cv (const ustring& src) { ustring NeonQuery::rcv (const ustring& src) { if (cv_in.get ()) { - return cv_in->cv (src); + return cv_in->cv (src, true); } else { return src; } diff --git a/modules/ml-sendmail.cc b/modules/ml-sendmail.cc index f9d215d..208037a 100644 --- a/modules/ml-sendmail.cc +++ b/modules/ml-sendmail.cc @@ -86,6 +86,9 @@ static void sendmail (const ustring& text, const ustring& faddr, std::vectorenv); } +#ifdef UTF8JP + out.flush (); +#endif SplitterNL sp (out.ans); line.resize (0); while (sp.next ()) { diff --git a/modules/ml-store.cc b/modules/ml-store.cc index 2ae7107..b144f1a 100644 --- a/modules/ml-store.cc +++ b/modules/ml-store.cc @@ -91,7 +91,7 @@ ustring StoreType::read () { if (readFile (src (param), ans, cPOSTLIMITHARD)) { if (encoding.size () > 0 && ans.size () > 0) { UIConv cd (kCODE_UTF8, encoding.c_str ()); - ans = cd.cv (ans); + ans = cd.cv (ans, true); } ans = fixUTF8 (ans); } @@ -613,7 +613,7 @@ MNode* ml_read_file (MNode* cell, MlEnv* mlenv) { if (readFile (src, data, cPOSTLIMITHARD)) { if (encoding.size () > 0 && data.size () > 0) { UIConv cd (kCODE_UTF8, encoding.c_str ()); - data = cd.cv (data); + data = cd.cv (data, true); } data = fixUTF8 (data); return newMNode_str (new ustring (data)); @@ -662,7 +662,7 @@ MNode* ml_write_file (MNode* cell, MlEnv* mlenv) { if (encoding.size () > 0 && data.size () > 0) { UIConv cd (encoding.c_str (), kCODE_UTF8); - data = cd.cv (data); + data = cd.cv (data, true); } if (fcrlf) data = toCRLF (data); -- 2.11.0