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;
}
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 ();
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;
offset = 0;
// 正常なら0を返す
} else {
-#ifdef DEBUG
+#ifdef DEBUG2
std::cerr << "state:" << state << ", offset:" << offset << ", buflen:" << buflen << "\n";
#endif /* DEBUG */
switch (state) {
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);
} 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);
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;
}
} 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;
offset = ans;
}
} else {
-#ifdef DEBUG
+#ifdef DEBUG2
std::cerr << "open failed\n";
#endif /* DEBUG */
++ bp;
ans = bodyProviderText (buffer, buflen);
} else {
ubuf = uCRLF;
-#ifdef DEBUG
+#ifdef DEBUG2
std::cerr << "ubuf:CRLF\n";
#endif /* DEBUG */
ans = bodyProviderText (buffer, 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;
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) {