OSDN Git Service

bug fix.
authorvisor <visor@users.sourceforge.jp>
Tue, 29 Sep 2015 13:21:21 +0000 (22:21 +0900)
committervisor <visor@users.sourceforge.jp>
Tue, 29 Sep 2015 13:21:21 +0000 (22:21 +0900)
modules/ml-neon.cc

index a96ade9..0f444d5 100644 (file)
@@ -82,7 +82,7 @@ ustring  NeonPostBodyProvider::textSeparator (const ustring& name) {
 ustring  NeonPostBodyProvider::fileSeparator (const ustring& name, const ustring& filename) {
     ustring  ans;
     ans.assign (CharConst ("--")).append (separator).append (uCRLF);
-    ans.append (CharConst (kRES_DISP ": form-data; name=" kQ2)).append (percentEncode (query->cv (name))).append (CharConst (kQ2 "; filename=" kQ2)).append (slashEncode (filename)).append (CharConst (kCRLF));
+    ans.append (CharConst (kRES_DISP ": form-data; name=" kQ2)).append (percentEncode (query->cv (name))).append (CharConst (kQ2 "; filename=" kQ2)).append (slashEncode (filename)).append (CharConst (kQ2 kCRLF));
     ans.append (CharConst (kRES_TYPE ": ")).append (mimetype (getExt (filename))).append (CharConst (kCRLF kCRLF));
     return ans;
 }
@@ -100,6 +100,12 @@ ne_off_t  NeonPostBodyProvider::calcLength () {
     off_t  s;
 
     tp = query->queryParam ();
+    bp = postFile.begin ();
+    ep = postFile.end ();
+    if (isCons (tp) || bp < ep) {
+    } else {
+        return ans;            // = 0
+    }
     if (isCons (tp)) {
        while (tp) {
            a = tp->car ();
@@ -109,16 +115,14 @@ ne_off_t  NeonPostBodyProvider::calcLength () {
            nextNode (tp);
        }
     }
-    bp = postFile.begin ();
-    ep = postFile.end ();
     for (; bp < ep; ++ bp) {
-       u = filePart_osSafe ((*bp).second);
-       if (! fileSize (u, s))
+       if (! fileSize ((*bp).second, s))
            s = 0;
+       u = filePart_osSafe ((*bp).second);
        ans += fileSeparator ((*bp).first, u).length () + s + 2;
     }
     ans += tailSeparator ().length ();
-#ifdef DEBUG
+#ifdef DEBUG2
     std::cerr << "calcLength(): " << ans << "\n";
 #endif /* DEBUG */
     return ans;
@@ -138,7 +142,7 @@ char*  NeonPostBodyProvider::bodyProvider (char* buffer, size_t buflen) {
        offset = 0;
        // 正常なら0を返す
     } else {
-#ifdef DEBUG
+#ifdef DEBUG2
        std::cerr << "state:" << state << ", offset:" << offset << ", buflen:" << buflen << "\n";
 #endif /* DEBUG */
        switch (state) {
@@ -149,7 +153,7 @@ char*  NeonPostBodyProvider::bodyProvider (char* buffer, size_t buflen) {
                MNode*  a = tp->car ();
                nextNode (tp);
                ubuf = textSeparator (to_string (a->car ())) + to_string (a->cdr ()) + uCRLF;
-#ifdef DEBUG
+#ifdef DEBUG2
                std::cerr << "ubuf:" << omitNonAscii (ubuf.substr (0, 8)) << "\n";
 #endif /* DEBUG */
                ans = bodyProviderText (buffer, buflen);
@@ -166,7 +170,7 @@ char*  NeonPostBodyProvider::bodyProvider (char* buffer, size_t buflen) {
            } else if (bp < ep) {
                ustring  u = filePart_osSafe ((*bp).second);
                ubuf = fileSeparator ((*bp).first, u);
-#ifdef DEBUG
+#ifdef DEBUG2
                std::cerr << "ubuf:" << omitNonAscii (ubuf.substr (0, 8)) << "\n";
 #endif /* DEBUG */
                ans = bodyProviderText (buffer, buflen);
@@ -180,12 +184,12 @@ char*  NeonPostBodyProvider::bodyProvider (char* buffer, size_t buflen) {
        case S_FILEBODY:
            if (offset > 0) {
                ans = fd.read (buffer, buflen);
-#ifdef DEBUG
+#ifdef DEBUG2
                std::cerr << "read\n";
 #endif /* DEBUG */
                if (ans <= 0) {
                    fd.close ();
-#ifdef DEBUG
+#ifdef DEBUG2
                    std::cerr << "close\n";
 #endif /* DEBUG */
                    offset = 0;
@@ -197,14 +201,14 @@ char*  NeonPostBodyProvider::bodyProvider (char* buffer, size_t buflen) {
                }
            } else {    // offset == 0
                ustring  u = filePart_osSafe ((*bp).second);
-#ifdef DEBUG
+#ifdef DEBUG2
                std::cerr << "open:" << (*bp).second << "\n";
 #endif /* DEBUG */
                if (fd.openRead ((*bp).second.c_str ())) {
                    ans = fd.read (buffer, buflen);
                    if (ans <= 0) {
                        fd.close ();
-#ifdef DEBUG
+#ifdef DEBUG2
                        std::cerr << "close\n";
 #endif /* DEBUG */
                        ++ bp;
@@ -214,7 +218,7 @@ char*  NeonPostBodyProvider::bodyProvider (char* buffer, size_t buflen) {
                        offset = ans;
                    }
                } else {
-#ifdef DEBUG
+#ifdef DEBUG2
                    std::cerr << "open failed\n";
 #endif /* DEBUG */
                    ++ bp;
@@ -228,7 +232,7 @@ char*  NeonPostBodyProvider::bodyProvider (char* buffer, size_t buflen) {
                ans = bodyProviderText (buffer, buflen);
            } else {
                ubuf = uCRLF;
-#ifdef DEBUG
+#ifdef DEBUG2
                std::cerr << "ubuf:CRLF\n";
 #endif /* DEBUG */
                ans = bodyProviderText (buffer, buflen);
@@ -257,7 +261,7 @@ char*  NeonPostBodyProvider::bodyProvider (char* buffer, size_t buflen) {
 
     if (ans > 0 && buflen > ans)
        return bodyProvider (buffer + ans, buflen - ans);
-#ifdef DEBUG
+#ifdef DEBUG2
     std::cerr << "bodyProvider ():" << ans << "\n";
 #endif /* DEBUG */
     return buffer + ans;
@@ -265,7 +269,7 @@ char*  NeonPostBodyProvider::bodyProvider (char* buffer, size_t buflen) {
 
 ssize_t  NeonPostBodyProvider::bodyProviderText (char* buffer, size_t buflen) {
     ssize_t  ans = ubuf.length () - offset;
-#ifdef DEBUG
+#ifdef DEBUG2
     std::cerr << "bodyProviderText: buflen:" << buflen << ", offset:" << offset << ", text:" << omitNonAsciiWord (ubuf.substr (offset, offset + 6)) << "\n";
 #endif /* DEBUG */
     if (ans <= buflen) {