From 286605607265c6ac7f1cd40b6dfd3eb1ab7a61f3 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Tue, 11 Mar 2025 16:59:16 -0700 Subject: [PATCH] more IMF work. --- IMFHeader.cpp | 2 +- IMFHeader.h | 2 +- IMFHeaderField.cpp | 2 +- IMFMultipart.cpp | 36 ++++-------------------------------- IMFMultipart.h | 2 +- IMFResponse.cpp | 4 ++-- IMFResponse.h | 1 + 7 files changed, 11 insertions(+), 38 deletions(-) diff --git a/IMFHeader.cpp b/IMFHeader.cpp index 4edcb2e..0c18226 100644 --- a/IMFHeader.cpp +++ b/IMFHeader.cpp @@ -10,7 +10,7 @@ namespace coreutils { int rc = ::read(fd, &ch, 1); while(ch != 'r') { IMFHeaderField *headerField = new IMFHeaderField(ch, fd); - headers.add(headerField); + headers.push_back(headerField); } rc = ::read(fd, &ch, 1); } diff --git a/IMFHeader.h b/IMFHeader.h index bcfb173..72501b9 100644 --- a/IMFHeader.h +++ b/IMFHeader.h @@ -12,7 +12,7 @@ namespace coreutils { IMFHeader(int fd); private: - std::vector headers; + std::vector headers; }; diff --git a/IMFHeaderField.cpp b/IMFHeaderField.cpp index 7b607a8..c5572ba 100644 --- a/IMFHeaderField.cpp +++ b/IMFHeaderField.cpp @@ -10,7 +10,7 @@ namespace coreutils { int rc = 0; if((ch >= 'A') && (ch <= 'Z')) - key.write(); + key.write(ch); while(ch != ':') { rc = ::read(fd, &ch, 1); diff --git a/IMFMultipart.cpp b/IMFMultipart.cpp index ffa261d..d936b25 100644 --- a/IMFMultipart.cpp +++ b/IMFMultipart.cpp @@ -1,28 +1,26 @@ #include "IMFMultipart.h" #include "Log.h" +#include + namespace coreutils { - IMFMultipart::IMFMultipart(int fd, ZString boundary) { + IMFMultipart::IMFMultipart(int fd, MString boundary) { int ch = 0; int rc = 0; while((ch != '\r') && (ch != '\n')) { rc = ::read(fd, &ch, 1); - --length; if((ch != '\r') && (ch != '\n')) boundary.write(ch); } if(ch == '\r') { rc = ::read(fd, &ch, 1); - --length; } while(1) { sections.emplace_back(fd, boundary); rc = ::read(fd, &ch, 1); - --length; if(ch == '-') { rc = ::read(fd, &ch, 1); - --length; if(ch == '-') { break; } @@ -30,40 +28,14 @@ namespace coreutils { } rc = ::read(fd, &ch, 1); - --length; if(ch == '\r') { rc = ::read(fd, &ch, 1); - --length; if(ch == '\n') { } } } - - - - - - - - - - - IMFMultipart::IMFMultipart(ZString &in, ZString &boundary) { - Log(LOG_DEBUG_1) << in; - std::stringstream temp; - temp << "--" << boundary; - sections = in.split(temp.str().c_str()); - for(int ix = 0; ix < sections.size(); ++ix) { - sections[ix].ifNext("\r\n"); - sections[ix].trimCRLF(); - Log(LOG_DEBUG_1) << "[" << sections[ix] << "]."; - if(sections[ix].equals("--")) - sections[ix] = ZString(""); - sections[ix].ifNext("\r\n"); - } - } - + std::string IMFMultipart::toString() { return std::string(getData(), getLength()); } diff --git a/IMFMultipart.h b/IMFMultipart.h index 27fa2b6..e8c673a 100644 --- a/IMFMultipart.h +++ b/IMFMultipart.h @@ -10,7 +10,7 @@ namespace coreutils { class IMFMultipart { public: - IMFMultipart(int fd, ZString boundary); + IMFMultipart(int fd, MString boundary); private: MString boundary; diff --git a/IMFResponse.cpp b/IMFResponse.cpp index dc8e1e0..a023e09 100644 --- a/IMFResponse.cpp +++ b/IMFResponse.cpp @@ -18,12 +18,12 @@ namespace coreutils { if(mode == LENGTH) { sprintf(contentLength, "%li", content.str().length()); ZString conlen(contentLength); - addHeader(IMFHeader("Content-Length", conlen)); +// addHeader(IMFHeader("Content-Length", conlen)); } else addHeader(IMFHeader("Transfer-Encoding", "chunked")); - addHeader(IMFHeader("Server", "JETServer v0.0.1")); +// addHeader(IMFHeader("Server", "JETServer v0.0.1")); output(response); response << content.str(); diff --git a/IMFResponse.h b/IMFResponse.h index 000ef56..242709a 100644 --- a/IMFResponse.h +++ b/IMFResponse.h @@ -87,6 +87,7 @@ namespace coreutils { ZString code; ZString text; + char contentLength[32]; const char *CRLF = "\r\n"; };