more IMF work.

This commit is contained in:
Brad Arant 2025-03-11 16:59:16 -07:00
parent fd7a9ed860
commit 2866056072
7 changed files with 11 additions and 38 deletions

View File

@ -10,7 +10,7 @@ namespace coreutils {
int rc = ::read(fd, &ch, 1); int rc = ::read(fd, &ch, 1);
while(ch != 'r') { while(ch != 'r') {
IMFHeaderField *headerField = new IMFHeaderField(ch, fd); IMFHeaderField *headerField = new IMFHeaderField(ch, fd);
headers.add(headerField); headers.push_back(headerField);
} }
rc = ::read(fd, &ch, 1); rc = ::read(fd, &ch, 1);
} }

View File

@ -12,7 +12,7 @@ namespace coreutils {
IMFHeader(int fd); IMFHeader(int fd);
private: private:
std::vector<IMFHeaderField> headers; std::vector<IMFHeaderField*> headers;
}; };

View File

@ -10,7 +10,7 @@ namespace coreutils {
int rc = 0; int rc = 0;
if((ch >= 'A') && (ch <= 'Z')) if((ch >= 'A') && (ch <= 'Z'))
key.write(); key.write(ch);
while(ch != ':') { while(ch != ':') {
rc = ::read(fd, &ch, 1); rc = ::read(fd, &ch, 1);

View File

@ -1,28 +1,26 @@
#include "IMFMultipart.h" #include "IMFMultipart.h"
#include "Log.h" #include "Log.h"
#include <unistd.h>
namespace coreutils { namespace coreutils {
IMFMultipart::IMFMultipart(int fd, ZString boundary) { IMFMultipart::IMFMultipart(int fd, MString boundary) {
int ch = 0; int ch = 0;
int rc = 0; int rc = 0;
while((ch != '\r') && (ch != '\n')) { while((ch != '\r') && (ch != '\n')) {
rc = ::read(fd, &ch, 1); rc = ::read(fd, &ch, 1);
--length;
if((ch != '\r') && (ch != '\n')) if((ch != '\r') && (ch != '\n'))
boundary.write(ch); boundary.write(ch);
} }
if(ch == '\r') { if(ch == '\r') {
rc = ::read(fd, &ch, 1); rc = ::read(fd, &ch, 1);
--length;
} }
while(1) { while(1) {
sections.emplace_back(fd, boundary); sections.emplace_back(fd, boundary);
rc = ::read(fd, &ch, 1); rc = ::read(fd, &ch, 1);
--length;
if(ch == '-') { if(ch == '-') {
rc = ::read(fd, &ch, 1); rc = ::read(fd, &ch, 1);
--length;
if(ch == '-') { if(ch == '-') {
break; break;
} }
@ -30,40 +28,14 @@ namespace coreutils {
} }
rc = ::read(fd, &ch, 1); rc = ::read(fd, &ch, 1);
--length;
if(ch == '\r') { if(ch == '\r') {
rc = ::read(fd, &ch, 1); rc = ::read(fd, &ch, 1);
--length;
if(ch == '\n') { 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() { std::string IMFMultipart::toString() {
return std::string(getData(), getLength()); return std::string(getData(), getLength());
} }

View File

@ -10,7 +10,7 @@ namespace coreutils {
class IMFMultipart { class IMFMultipart {
public: public:
IMFMultipart(int fd, ZString boundary); IMFMultipart(int fd, MString boundary);
private: private:
MString boundary; MString boundary;

View File

@ -18,12 +18,12 @@ namespace coreutils {
if(mode == LENGTH) { if(mode == LENGTH) {
sprintf(contentLength, "%li", content.str().length()); sprintf(contentLength, "%li", content.str().length());
ZString conlen(contentLength); ZString conlen(contentLength);
addHeader(IMFHeader("Content-Length", conlen)); // addHeader(IMFHeader("Content-Length", conlen));
} }
else else
addHeader(IMFHeader("Transfer-Encoding", "chunked")); addHeader(IMFHeader("Transfer-Encoding", "chunked"));
addHeader(IMFHeader("Server", "JETServer v0.0.1")); // addHeader(IMFHeader("Server", "JETServer v0.0.1"));
output(response); output(response);
response << content.str(); response << content.str();

View File

@ -87,6 +87,7 @@ namespace coreutils {
ZString code; ZString code;
ZString text; ZString text;
char contentLength[32];
const char *CRLF = "\r\n"; const char *CRLF = "\r\n";
}; };