Merge commit from develop
This commit is contained in:
commit
082263f5ea
100 files changed
+6215
-740
No files matched your search
+57
-75
@@ -6,100 +6,82 @@
|
||||
|
||||
namespace coreutils {
|
||||
|
||||
IMFMessage::IMFMessage() {
|
||||
body = NULL;
|
||||
}
|
||||
IMFMessage::IMFMessage() : ZString() {}
|
||||
|
||||
IMFMessage::IMFMessage(PString &in) {
|
||||
parse(in);
|
||||
}
|
||||
IMFMessage::IMFMessage(ZString &in) : ZString(in) {
|
||||
|
||||
bool IMFMessage::parse(PString &in) {
|
||||
while (!in.ifNext("\r\n"))
|
||||
headers.emplace_back(in);
|
||||
|
||||
Log(LOG_DEBUG_1) << "Parsing-------\n" << in.str();
|
||||
ZString type = getHeader("Content-Type");
|
||||
|
||||
while (!in.ifNext("\r\n")) {
|
||||
headers.emplace_back(in);
|
||||
}
|
||||
|
||||
std::string type = getHeader("Content-Type");
|
||||
std::stringstream length(getHeader("Content-Length"));
|
||||
int len = 0;
|
||||
length >> len;
|
||||
int len = getHeader("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(block);
|
||||
else
|
||||
body = new IMFBody(&block);
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
block = in.readBlock(len);
|
||||
if(type.equals("multipart/form-data")) {
|
||||
ZString boundary(getHeaderKeyPairValue("Content-Type", "boundary"));
|
||||
multipart = IMFMultipart(block, boundary);
|
||||
}
|
||||
}
|
||||
return std::string("");
|
||||
}
|
||||
|
||||
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) {
|
||||
IMFMessage::~IMFMessage() {}
|
||||
|
||||
void IMFMessage::output(std::stringstream &out) {
|
||||
// for(IMFHeader header: headers) {
|
||||
// out << header.getKey() << ": " << header.getValue() << "\r\n";
|
||||
// }
|
||||
out << newHeaders.str() << "\r\n";
|
||||
}
|
||||
|
||||
void IMFMessage::addHeader(IMFHeader header) {
|
||||
std::stringstream out;
|
||||
header.output(out);
|
||||
newHeaders << out.str() ;
|
||||
}
|
||||
|
||||
ZString IMFMessage::getHeader(ZString key, bool valueOnly) {
|
||||
for(IMFHeader header: headers) {
|
||||
if(header.getKey().equals(key)) {
|
||||
ZString value = header.getValue();
|
||||
if(valueOnly) {
|
||||
std::vector<ZString> split = ZString(value).split(";");
|
||||
value = split[0];
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return ZString();
|
||||
}
|
||||
|
||||
ZString IMFMessage::getHeaderKeyPairValue(const char *headerKey, const char *key) {
|
||||
return getHeaderKeyPairValue(ZString(headerKey), ZString(key));
|
||||
}
|
||||
|
||||
ZString IMFMessage::getHeaderKeyPairValue(ZString headerKey, ZString key) {
|
||||
ZString value;
|
||||
ZString psource(getHeader(headerKey, false));
|
||||
for(ZString work: psource.split(";")) {
|
||||
work.skipWhitespace();
|
||||
std::string token = work.getTokenExclude("=");
|
||||
ZString token = work.getTokenExclude("=");
|
||||
if(work.ifNext("=")) {
|
||||
if(token == key) {
|
||||
if(work.ifNext("\"")) {
|
||||
value = work.getTokenExclude("\"");
|
||||
return value;
|
||||
}
|
||||
else {
|
||||
value = work.str();
|
||||
return value;
|
||||
}
|
||||
if(token.equals(key)) {
|
||||
if(work.ifNext("\""))
|
||||
value = work.getTokenExclude("\"");
|
||||
else
|
||||
value = work;
|
||||
return value;
|
||||
}
|
||||
else
|
||||
continue;
|
||||
|
||||
|
||||
} else if (work.ifNext(";") || work.ifNext(" ")) {
|
||||
if(token == key)
|
||||
return std::string("true");
|
||||
if(token.equals(key))
|
||||
return ZString("true");
|
||||
else
|
||||
continue;
|
||||
|
||||
}
|
||||
}
|
||||
return std::string("false");
|
||||
}
|
||||
|
||||
IMFBody * IMFMessage::getBody() {
|
||||
return body;
|
||||
return ZString();
|
||||
}
|
||||
|
||||
void IMFMessage::setBody(PString *body) {
|
||||
|
||||
Reference in new issue
Block a user