All sorts of new crap and adjustments

This commit is contained in:
barant committed 2021-07-23 11:44:36 -07:00
1 parent 5bd9e9ca21
commit ff2c2b7432
84 files changed
+5935 -664

No files matched your search

+44 -51
View File
@@ -5,36 +5,27 @@
#include "Log.h"
namespace coreutils {
IMFMessage::IMFMessage() {
body = NULL;
IMFMessage::IMFMessage() : ZString() {
}
IMFMessage::IMFMessage(PString &in) {
parse(in);
}
bool IMFMessage::parse(PString &in) {
while (!in.ifNext("\r\n")) {
headers.emplace_back(in);
IMFMessage::IMFMessage(ZString &in) : ZString(in) {
while (!in.ifNext((char *)"\r\n")) {
headers.emplace_back(in);
}
std::string type = getHeader("Content-Type");
std::stringstream length(getHeader("Content-Length"));
int len = 0;
length >> len;
ZString type = getHeader((char *)"Content-Type");
int len = getHeader((char *)"Content-Length").asInteger();
if(len > 0) {
PString block = in.readBlock(len);
if(type == "multipart/form-data")
body = new IMFMultipart(block, getHeaderKeyPairValue("Content-Type", "boundary"));
else if(type == "text/plain")
body = new IMFPlainText(in);
ZString block = in.readBlock(len);
if(type.equals((char *)"multipart/form-data"))
body = new IMFMultipart(block, getHeaderKeyPairValue((char *)"Content-Type", (char *)"boundary"));
else if(type.equals((char *)"text/plain"))
body = new IMFPlainText(block);
else
body = new IMFBody();
body = new IMFBody(block);
}
return false;
}
void IMFMessage::output(std::stringstream &out) {
@@ -44,56 +35,58 @@ namespace coreutils {
out << "\r\n";
}
void IMFMessage::addHeader(std::string key, std::string value) {
void IMFMessage::addHeader(ZString key, ZString value) {
headers.emplace_back(key, value);
}
std::string IMFMessage::getHeader(std::string key, bool valueOnly) {
void IMFMessage::addHeader(const char *key, ZString value) {
headers.emplace_back(ZString(key), value);
}
ZString IMFMessage::getHeader(ZString key, bool valueOnly) {
for(IMFHeader header: headers) {
if(header.getKey() == key) {
std::string value = header.getValue();
if(valueOnly) {
std::vector<PString> split = PString(value).split(";");
value = split[0].str();
}
if(header.getKey().equals(key)) {
ZString value = header.getValue();
if(valueOnly) {
std::vector<ZString> split = ZString(value).split(ZString((char *)";"));
value = split[0];
}
return value;
}
}
return std::string("");
return ZString();
}
std::string IMFMessage::getHeaderKeyPairValue(std::string headerKey, std::string key) {
std::string value;
coreutils::PString psource(getHeader(headerKey, false));
std::vector<PString> sourcep = psource.split(";");
for(PString work: sourcep) {
ZString IMFMessage::getHeaderKeyPairValue(ZString headerKey, ZString key) {
ZString value;
ZString psource(getHeader(headerKey, false));
std::vector<ZString> sourcep = psource.split((char *)";");
for(ZString work: sourcep) {
work.skipWhitespace();
std::string token = work.getTokenExclude("=");
if(work.ifNext("=")) {
if(token == key) {
if(work.ifNext("\"")) {
value = work.getTokenExclude("\"");
ZString token = work.getTokenExclude((char *)"=");
if(work.ifNext((char *)"=")) {
if(token.equals(key)) {
if(work.ifNext((char *)"\"")) {
value = work.getTokenExclude((char *)"\"");
return value;
}
else {
value = work.str();
value = work;
return value;
}
}
else
continue;
} else if (work.ifNext(";") || work.ifNext(" ")) {
if(token == key)
return std::string("true");
} else if (work.ifNext((char *)";") || work.ifNext((char *)" ")) {
if(token.equals(key))
return ZString((char *)"true");
else
continue;
}
}
return std::string("false");
return ZString((char *)"false");
}
IMFBody * IMFMessage::getBody() {