OSDN Git Service

bug fix.
authorvisor <visor@users.sourceforge.jp>
Thu, 9 Jul 2015 14:26:05 +0000 (23:26 +0900)
committervisor <visor@users.sourceforge.jp>
Thu, 9 Jul 2015 14:26:05 +0000 (23:26 +0900)
lib/form.cc
lib/formfile.cc
lib/http-iconv.cc
lib/motoroutput-iconv.cc
lib/motoroutput-iconv.h
lib/util_string.cc
lib/util_string.h
modules/ml-neon.cc
modules/ml-sendmail.cc
modules/ml-store.cc

index f49b121..5c2c29b 100644 (file)
@@ -120,7 +120,7 @@ size_t  CGIForm::postSize () {
 
     if (e == NULL)
        return 0;
-    return strtoul (e, NULL, 10);
+    return boost::lexical_cast <size_t> (e);
 }
 
 int  CGIForm::at (const ustring& name, ustring& ans) {
index 7dfe8c7..b7e48be 100644 (file)
@@ -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";
index 31693c5..b5c4ea9 100644 (file)
@@ -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);
 }
index 7efb575..e7733c7 100644 (file)
@@ -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;
index eb1a3ee..79d2077 100644 (file)
@@ -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;
     };
index dd6b103..ef31ebf 100644 (file)
@@ -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';
 }
index e150226..feb6777 100644 (file)
@@ -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);
index e4af960..a96ade9 100644 (file)
@@ -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;
     }
index f9d215d..208037a 100644 (file)
@@ -86,6 +86,9 @@ static void  sendmail (const ustring& text, const ustring& faddr, std::vector<us
        motor.compile (text);
        motor.output (&out, mlenv->env);
     }
+#ifdef UTF8JP
+    out.flush ();
+#endif
     SplitterNL  sp (out.ans);
     line.resize (0);
     while (sp.next ()) {
index 2ae7107..b144f1a 100644 (file)
@@ -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);