Continued work.
This commit is contained in:
1 parent
4286a7b449
commit
947eef21e2
12 files changed
+323
-95
No files matched your search
+34
-32
@@ -2,61 +2,64 @@
|
||||
#include "IMFHeader.h"
|
||||
#include "IMFMultipart.h"
|
||||
#include "IMFPlainText.h"
|
||||
#include "Log.h"
|
||||
|
||||
namespace coreutils {
|
||||
|
||||
|
||||
IMFMessage::IMFMessage() {}
|
||||
|
||||
|
||||
IMFMessage::IMFMessage(PString &in) {
|
||||
parse(in);
|
||||
}
|
||||
|
||||
void IMFMessage::parse(PString &in) {
|
||||
coreutils::Log(coreutils::LOG_DEBUG_4) << "[" << in.str() << "]";
|
||||
if(in.size() == 0)
|
||||
return;
|
||||
|
||||
while(!in.ifNext("\r\n"))
|
||||
headers.emplace_back(in);
|
||||
|
||||
while(!in.ifNext("\r\n") && !in.eod()) {
|
||||
headers.emplace_back(in);
|
||||
}
|
||||
|
||||
std::string type = getHeader("Content-Type");
|
||||
|
||||
if(type.size() == 0)
|
||||
type = "text/plain";
|
||||
|
||||
if(type.size() == 0)
|
||||
type = "text/plain";
|
||||
|
||||
if(type == "multipart/form-data")
|
||||
body = new IMFMultipart(in, getHeaderKeyPairValue("Content-Type", "boundary"));
|
||||
else if(type == "text/plain")
|
||||
body = new IMFPlainText(in);
|
||||
body = new IMFMultipart(in, getHeaderKeyPairValue("Content-Type", "boundary"));
|
||||
else if(type == "text/plain")
|
||||
body = new IMFPlainText(in);
|
||||
else
|
||||
body = new IMFBody();
|
||||
body = new IMFBody();
|
||||
}
|
||||
|
||||
|
||||
void IMFMessage::output(std::stringstream &out) {
|
||||
for(IMFHeader header: headers) {
|
||||
out << header.getKey() << ": " << header.getValue() << "\r\n";
|
||||
}
|
||||
out << "\r\n";
|
||||
}
|
||||
|
||||
|
||||
void IMFMessage::addHeader(std::string key, std::string value) {
|
||||
headers.emplace_back(key, value);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::string IMFMessage::getHeader(std::string 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();
|
||||
}
|
||||
return value;
|
||||
std::string value = header.getValue();
|
||||
if(valueOnly) {
|
||||
std::vector<PString> split = PString(value).split(";");
|
||||
value = split[0].str();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return std::string("");
|
||||
}
|
||||
|
||||
|
||||
std::string IMFMessage::getHeaderKeyPairValue(std::string headerKey, std::string key) {
|
||||
std::string value;
|
||||
coreutils::PString psource(getHeader(headerKey, false));
|
||||
@@ -77,22 +80,21 @@ namespace coreutils {
|
||||
}
|
||||
else
|
||||
continue;
|
||||
|
||||
|
||||
|
||||
|
||||
} else if (work.ifNext(";") || work.ifNext(" ")) {
|
||||
if(token == key)
|
||||
return std::string("true");
|
||||
else
|
||||
continue;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return std::string("false");
|
||||
}
|
||||
|
||||
IMFBody * IMFMessage::getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
|
||||
|
||||
IMFBody * IMFMessage::getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user