diff --git a/CoreUtils.mk b/CoreUtils.mk index bd0a2f2..c5a364f 100644 --- a/CoreUtils.mk +++ b/CoreUtils.mk @@ -5,22 +5,22 @@ ## Debug ProjectName :=CoreUtils ConfigurationName :=Debug -WorkspacePath :=/home/bradarant/barant -ProjectPath :=/home/bradarant/barant/CoreUtils +WorkspacePath :=/home/barant/Development/BMA/server_core +ProjectPath :=/home/barant/Development/BMA/server_core/CoreUtils IntermediateDirectory :=./Debug OutDir := $(IntermediateDirectory) CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=Brad Arant -Date :=18/07/19 -CodeLitePath :=/home/bradarant/.codelite -LinkerName :=/usr/bin/x86_64-linux-gnu-g++ -SharedObjectLinkerName :=/usr/bin/x86_64-linux-gnu-g++ -shared -fPIC +Date :=02/08/19 +CodeLitePath :=/home/barant/.codelite +LinkerName :=g++ +SharedObjectLinkerName :=g++ -shared -fPIC ObjectSuffix :=.o DependSuffix :=.o.d -PreprocessSuffix :=.i -DebugSwitch :=-g +PreprocessSuffix :=.o.i +DebugSwitch :=-gstab IncludeSwitch :=-I LibrarySwitch :=-l OutputSwitch :=-o @@ -31,7 +31,7 @@ OutputFile :=$(IntermediateDirectory)/lib$(ProjectName).a Preprocessors := ObjectSwitch :=-o ArchiveOutputSwitch := -PreprocessOnlySwitch :=-E +PreprocessOnlySwitch :=-E ObjectsFileList :="CoreUtils.txt" PCHCompileFlags := MakeDirCommand :=mkdir -p @@ -47,20 +47,20 @@ LibPath := $(LibraryPathSwitch). ## Common variables ## AR, CXX, CC, AS, CXXFLAGS and CFLAGS can be overriden using an environment variables ## -AR := /usr/bin/x86_64-linux-gnu-ar rcu -CXX := /usr/bin/x86_64-linux-gnu-g++ -CC := /usr/bin/x86_64-linux-gnu-gcc +AR := ar rcus +CXX := g++ +CC := gcc CXXFLAGS := -g $(Preprocessors) CFLAGS := -g $(Preprocessors) ASFLAGS := -AS := /usr/bin/x86_64-linux-gnu-as +AS := as ## ## User defined environment variables ## CodeLiteDir:=/usr/share/codelite -Objects0=$(IntermediateDirectory)/IMFHeader.cpp$(ObjectSuffix) $(IntermediateDirectory)/PString.cpp$(ObjectSuffix) $(IntermediateDirectory)/IMFMultipart.cpp$(ObjectSuffix) $(IntermediateDirectory)/IMFMessage.cpp$(ObjectSuffix) $(IntermediateDirectory)/IMFRequest.cpp$(ObjectSuffix) $(IntermediateDirectory)/IMFResponse.cpp$(ObjectSuffix) +Objects0=$(IntermediateDirectory)/IMFHeader.cpp$(ObjectSuffix) $(IntermediateDirectory)/PString.cpp$(ObjectSuffix) $(IntermediateDirectory)/IMFMultipart.cpp$(ObjectSuffix) $(IntermediateDirectory)/IMFMessage.cpp$(ObjectSuffix) $(IntermediateDirectory)/IMFRequest.cpp$(ObjectSuffix) $(IntermediateDirectory)/IMFResponse.cpp$(ObjectSuffix) $(IntermediateDirectory)/IMFFormData.cpp$(ObjectSuffix) $(IntermediateDirectory)/IMFPlainText.cpp$(ObjectSuffix) @@ -77,8 +77,8 @@ $(OutputFile): $(Objects) @echo "" > $(IntermediateDirectory)/.d @echo $(Objects0) > $(ObjectsFileList) $(AR) $(ArchiveOutputSwitch)$(OutputFile) @$(ObjectsFileList) $(ArLibs) - @$(MakeDirCommand) "/home/bradarant/barant/.build-debug" - @echo rebuilt > "/home/bradarant/barant/.build-debug/CoreUtils" + @$(MakeDirCommand) "/home/barant/Development/BMA/server_core/.build-debug" + @echo rebuilt > "/home/barant/Development/BMA/server_core/.build-debug/CoreUtils" MakeIntermediateDirs: @test -d ./Debug || $(MakeDirCommand) ./Debug @@ -94,7 +94,7 @@ PreBuild: ## Objects ## $(IntermediateDirectory)/IMFHeader.cpp$(ObjectSuffix): IMFHeader.cpp $(IntermediateDirectory)/IMFHeader.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/bradarant/barant/CoreUtils/IMFHeader.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/IMFHeader.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/CoreUtils/IMFHeader.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/IMFHeader.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/IMFHeader.cpp$(DependSuffix): IMFHeader.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/IMFHeader.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/IMFHeader.cpp$(DependSuffix) -MM IMFHeader.cpp @@ -102,7 +102,7 @@ $(IntermediateDirectory)/IMFHeader.cpp$(PreprocessSuffix): IMFHeader.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/IMFHeader.cpp$(PreprocessSuffix) IMFHeader.cpp $(IntermediateDirectory)/PString.cpp$(ObjectSuffix): PString.cpp $(IntermediateDirectory)/PString.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/bradarant/barant/CoreUtils/PString.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/PString.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/CoreUtils/PString.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/PString.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/PString.cpp$(DependSuffix): PString.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/PString.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/PString.cpp$(DependSuffix) -MM PString.cpp @@ -110,7 +110,7 @@ $(IntermediateDirectory)/PString.cpp$(PreprocessSuffix): PString.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/PString.cpp$(PreprocessSuffix) PString.cpp $(IntermediateDirectory)/IMFMultipart.cpp$(ObjectSuffix): IMFMultipart.cpp $(IntermediateDirectory)/IMFMultipart.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/bradarant/barant/CoreUtils/IMFMultipart.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/IMFMultipart.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/CoreUtils/IMFMultipart.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/IMFMultipart.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/IMFMultipart.cpp$(DependSuffix): IMFMultipart.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/IMFMultipart.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/IMFMultipart.cpp$(DependSuffix) -MM IMFMultipart.cpp @@ -118,7 +118,7 @@ $(IntermediateDirectory)/IMFMultipart.cpp$(PreprocessSuffix): IMFMultipart.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/IMFMultipart.cpp$(PreprocessSuffix) IMFMultipart.cpp $(IntermediateDirectory)/IMFMessage.cpp$(ObjectSuffix): IMFMessage.cpp $(IntermediateDirectory)/IMFMessage.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/bradarant/barant/CoreUtils/IMFMessage.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/IMFMessage.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/CoreUtils/IMFMessage.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/IMFMessage.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/IMFMessage.cpp$(DependSuffix): IMFMessage.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/IMFMessage.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/IMFMessage.cpp$(DependSuffix) -MM IMFMessage.cpp @@ -126,7 +126,7 @@ $(IntermediateDirectory)/IMFMessage.cpp$(PreprocessSuffix): IMFMessage.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/IMFMessage.cpp$(PreprocessSuffix) IMFMessage.cpp $(IntermediateDirectory)/IMFRequest.cpp$(ObjectSuffix): IMFRequest.cpp $(IntermediateDirectory)/IMFRequest.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/bradarant/barant/CoreUtils/IMFRequest.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/IMFRequest.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/CoreUtils/IMFRequest.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/IMFRequest.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/IMFRequest.cpp$(DependSuffix): IMFRequest.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/IMFRequest.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/IMFRequest.cpp$(DependSuffix) -MM IMFRequest.cpp @@ -134,13 +134,29 @@ $(IntermediateDirectory)/IMFRequest.cpp$(PreprocessSuffix): IMFRequest.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/IMFRequest.cpp$(PreprocessSuffix) IMFRequest.cpp $(IntermediateDirectory)/IMFResponse.cpp$(ObjectSuffix): IMFResponse.cpp $(IntermediateDirectory)/IMFResponse.cpp$(DependSuffix) - $(CXX) $(IncludePCH) $(SourceSwitch) "/home/bradarant/barant/CoreUtils/IMFResponse.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/IMFResponse.cpp$(ObjectSuffix) $(IncludePath) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/CoreUtils/IMFResponse.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/IMFResponse.cpp$(ObjectSuffix) $(IncludePath) $(IntermediateDirectory)/IMFResponse.cpp$(DependSuffix): IMFResponse.cpp @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/IMFResponse.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/IMFResponse.cpp$(DependSuffix) -MM IMFResponse.cpp $(IntermediateDirectory)/IMFResponse.cpp$(PreprocessSuffix): IMFResponse.cpp $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/IMFResponse.cpp$(PreprocessSuffix) IMFResponse.cpp +$(IntermediateDirectory)/IMFFormData.cpp$(ObjectSuffix): IMFFormData.cpp $(IntermediateDirectory)/IMFFormData.cpp$(DependSuffix) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/CoreUtils/IMFFormData.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/IMFFormData.cpp$(ObjectSuffix) $(IncludePath) +$(IntermediateDirectory)/IMFFormData.cpp$(DependSuffix): IMFFormData.cpp + @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/IMFFormData.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/IMFFormData.cpp$(DependSuffix) -MM IMFFormData.cpp + +$(IntermediateDirectory)/IMFFormData.cpp$(PreprocessSuffix): IMFFormData.cpp + $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/IMFFormData.cpp$(PreprocessSuffix) IMFFormData.cpp + +$(IntermediateDirectory)/IMFPlainText.cpp$(ObjectSuffix): IMFPlainText.cpp $(IntermediateDirectory)/IMFPlainText.cpp$(DependSuffix) + $(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/CoreUtils/IMFPlainText.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/IMFPlainText.cpp$(ObjectSuffix) $(IncludePath) +$(IntermediateDirectory)/IMFPlainText.cpp$(DependSuffix): IMFPlainText.cpp + @$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/IMFPlainText.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/IMFPlainText.cpp$(DependSuffix) -MM IMFPlainText.cpp + +$(IntermediateDirectory)/IMFPlainText.cpp$(PreprocessSuffix): IMFPlainText.cpp + $(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/IMFPlainText.cpp$(PreprocessSuffix) IMFPlainText.cpp + -include $(IntermediateDirectory)/*$(DependSuffix) ## diff --git a/CoreUtils.project b/CoreUtils.project index 8a6855c..2de35b0 100644 --- a/CoreUtils.project +++ b/CoreUtils.project @@ -17,6 +17,12 @@ + + + + + + diff --git a/CoreUtils.txt b/CoreUtils.txt index 935d9a4..ec4192f 100644 --- a/CoreUtils.txt +++ b/CoreUtils.txt @@ -1 +1 @@ -./Debug/IMFHeader.cpp.o ./Debug/PString.cpp.o ./Debug/IMFMultipart.cpp.o ./Debug/IMFMessage.cpp.o ./Debug/IMFRequest.cpp.o ./Debug/IMFResponse.cpp.o +./Debug/IMFHeader.cpp.o ./Debug/PString.cpp.o ./Debug/IMFMultipart.cpp.o ./Debug/IMFMessage.cpp.o ./Debug/IMFRequest.cpp.o ./Debug/IMFResponse.cpp.o ./Debug/IMFFormData.cpp.o ./Debug/IMFPlainText.cpp.o diff --git a/Debug/IMFHeader.cpp.o b/Debug/IMFHeader.cpp.o index 2261bab..9d9eb6b 100644 Binary files a/Debug/IMFHeader.cpp.o and b/Debug/IMFHeader.cpp.o differ diff --git a/Debug/IMFMessage.cpp.o b/Debug/IMFMessage.cpp.o index 7d29cbb..a22fa05 100644 Binary files a/Debug/IMFMessage.cpp.o and b/Debug/IMFMessage.cpp.o differ diff --git a/Debug/IMFMessage.cpp.o.d b/Debug/IMFMessage.cpp.o.d index 193c8cf..09abbf5 100644 --- a/Debug/IMFMessage.cpp.o.d +++ b/Debug/IMFMessage.cpp.o.d @@ -1,5 +1,5 @@ Debug/IMFMessage.cpp.o: IMFMessage.cpp IMFMessage.h PString.h includes \ - IMFHeader.h IMFRequest.h IMFBody.h IMFMultipart.h + IMFHeader.h IMFRequest.h IMFBody.h IMFMultipart.h IMFPlainText.h IMFMessage.h: @@ -14,3 +14,5 @@ IMFRequest.h: IMFBody.h: IMFMultipart.h: + +IMFPlainText.h: diff --git a/Debug/IMFMultipart.cpp.o b/Debug/IMFMultipart.cpp.o index 4bd58f4..be73442 100644 Binary files a/Debug/IMFMultipart.cpp.o and b/Debug/IMFMultipart.cpp.o differ diff --git a/Debug/IMFRequest.cpp.o b/Debug/IMFRequest.cpp.o index 393c9ba..015c4b5 100644 Binary files a/Debug/IMFRequest.cpp.o and b/Debug/IMFRequest.cpp.o differ diff --git a/Debug/IMFResponse.cpp.o b/Debug/IMFResponse.cpp.o index 3b76176..94e2fca 100644 Binary files a/Debug/IMFResponse.cpp.o and b/Debug/IMFResponse.cpp.o differ diff --git a/Debug/PString.cpp.o b/Debug/PString.cpp.o index 02cbf5a..0af81b1 100644 Binary files a/Debug/PString.cpp.o and b/Debug/PString.cpp.o differ diff --git a/Debug/libCoreUtils.a b/Debug/libCoreUtils.a index 5da9d19..410d258 100644 Binary files a/Debug/libCoreUtils.a and b/Debug/libCoreUtils.a differ diff --git a/Directory.h b/Directory.h new file mode 100644 index 0000000..83b7ded --- /dev/null +++ b/Directory.h @@ -0,0 +1,36 @@ +#ifndef __Directory_h__ +#define __Directory_h__ + +#include "includes" +#include "DirectoryEntry.h" + +namespace coreutils { + + class Directory { + + public: + Directory(std::string path) { + dir = opendir(path); + if(dir) { + struct dirent entry = readdir(dir); + while(entry) { + directory.emplace(std::string(entry->d_name), entry); + entry = readdir(dir) + } + } + + ~Directory() {} + + + private: + DIR *dir; + std::map directory; + + + + + }; + +} + +#endif diff --git a/DirectoryEntry.h b/DirectoryEntry.h new file mode 100644 index 0000000..70dd873 --- /dev/null +++ b/DirectoryEntry.h @@ -0,0 +1,28 @@ +#ifndef __DirectoryEntry_h__ +#define __DirectoryEntry_h__ + +#include "includes" + +namespace coreutils { + + class DirectoryEntry { + + public: + DirectoryEntry(struct dirent *entry) { + memcpy(this->entry, entry, sizeof(struct dirent)); + } + + ~DirectoryEntry() {} + + std::string getName() { + return std::string(entry->d_name); + } + + private: + struct dirent entry; + + }; + +} + +#endif diff --git a/IMFFormData.cpp b/IMFFormData.cpp new file mode 100644 index 0000000..c3ce49c --- /dev/null +++ b/IMFFormData.cpp @@ -0,0 +1,21 @@ +#include "IMFFormData.h" +#include "IMFMessage.h" +#include "IMFPlainText.h" + +namespace coreutils { + + IMFFormData::IMFFormData(PString &in, std::string boundary) : IMFMultipart(in, boundary) { + + } + + std::string IMFFormData::getByName(std::string name) { + std::string value; + for(PString section: sections) { + IMFMessage message(section); + IMFPlainText *text = (IMFPlainText *)message.getBody(); + std::cout << text->toString(); + } + return value; + } + +} diff --git a/IMFFormData.h b/IMFFormData.h new file mode 100644 index 0000000..a97162b --- /dev/null +++ b/IMFFormData.h @@ -0,0 +1,20 @@ +#ifndef __IMFFormData_h__ +#define __IMFFormData_h__ + +#include "IMFMultipart.h" + +namespace coreutils { + + class IMFFormData: public IMFMultipart { + + public: + IMFFormData(); + IMFFormData(PString &in, std::string boundary); + + std::string getByName(std::string name); + + }; + +} + +#endif diff --git a/IMFMessage.cpp b/IMFMessage.cpp index 3f91943..b1f85ec 100644 --- a/IMFMessage.cpp +++ b/IMFMessage.cpp @@ -1,6 +1,7 @@ #include "IMFMessage.h" #include "IMFHeader.h" #include "IMFMultipart.h" +#include "IMFPlainText.h" namespace coreutils { @@ -16,9 +17,14 @@ namespace coreutils { std::string type = getHeader("Content-Type"); + if(type.size() == 0) + type = "text/plain"; + if(type == "multipart/form-data") body = new IMFMultipart(in, getHeaderKeyPairValue("Content-Type", "boundary")); - else + else if(type == "text/plain") + body = new IMFPlainText(in); + else body = new IMFBody(); } @@ -39,8 +45,8 @@ namespace coreutils { if(header.getKey() == key) { std::string value = header.getValue(); if(valueOnly) { - std::vector split = PString(value).split(";"); - value = split[0]; + std::vector split = PString(value).split(";"); + value = split[0].str(); } return value; } @@ -50,9 +56,8 @@ namespace coreutils { std::string IMFMessage::getHeaderKeyPairValue(std::string headerKey, std::string key) { coreutils::PString psource(getHeader(headerKey, false)); - std::vector sourcep = psource.split(";"); - for(std::string keyx: sourcep) { - PString work(keyx); + std::vector sourcep = psource.split(";"); + for(PString work: sourcep) { work.skipWhitespace(); std::string token = work.getTokenExclude("="); if(work.ifNext("=")) { @@ -72,4 +77,9 @@ namespace coreutils { return std::string("false"); } + IMFBody * IMFMessage::getBody() { + return body; + } + + } diff --git a/IMFMessage.h b/IMFMessage.h index 0b52c6d..904edd3 100644 --- a/IMFMessage.h +++ b/IMFMessage.h @@ -24,10 +24,11 @@ namespace coreutils { std::string getHeader(std::string key, bool valueOnly = true); std::string getHeaderKeyPairValue(std::string headerKey, std::string key); - IMFBody *body; + IMFBody *getBody(); protected: std::vector headers; + IMFBody *body; }; diff --git a/IMFMultipart.cpp b/IMFMultipart.cpp index a7253ef..7b8f41a 100644 --- a/IMFMultipart.cpp +++ b/IMFMultipart.cpp @@ -3,13 +3,26 @@ namespace coreutils { IMFMultipart::IMFMultipart() { - + buffer = ""; } IMFMultipart::IMFMultipart(PString &in, std::string boundary) { + buffer = in.str(); in.cursor -= 2; - section = in.split("\r\n--" + boundary); - + sections = in.split("\r\n--" + boundary); + } + + std::string IMFMultipart::toString() { + return buffer; + } + + int IMFMultipart::getCount() { + return sections.size(); + } + + PString IMFMultipart::getSectionAt(int index) { + return sections[index]; + } } diff --git a/IMFMultipart.h b/IMFMultipart.h index dfc7a08..2dce763 100644 --- a/IMFMultipart.h +++ b/IMFMultipart.h @@ -12,10 +12,17 @@ namespace coreutils { IMFMultipart(); IMFMultipart(PString &in, std::string boundary); + std::string toString(); + int getCount(); + PString getSectionAt(int index); + + protected: + std::vector sections; + private: std::string boundary; - std::vector section; + std::string buffer; }; } diff --git a/IMFPlainText.cpp b/IMFPlainText.cpp new file mode 100644 index 0000000..6e256f8 --- /dev/null +++ b/IMFPlainText.cpp @@ -0,0 +1,17 @@ +#include "IMFPlainText.h" + +namespace coreutils { + + IMFPlainText::IMFPlainText() { + text = ""; + } + + IMFPlainText::IMFPlainText(PString &in) : IMFBody() { + text = in.str(); + } + + std::string IMFPlainText::toString() { + return text; + } + +} diff --git a/IMFPlainText.h b/IMFPlainText.h new file mode 100644 index 0000000..931ae18 --- /dev/null +++ b/IMFPlainText.h @@ -0,0 +1,24 @@ +#ifndef __IMFPlainText_h__ +#define __IMFPlainText_h__ + +#include "PString.h" +#include "IMFBody.h" + +namespace coreutils { + + class IMFPlainText: public IMFBody { + + public: + IMFPlainText(); + IMFPlainText(PString &in); + + std::string toString(); + + protected: + std::string text; + + }; + +} + +#endif diff --git a/PString.cpp b/PString.cpp index a2db255..6dea212 100644 --- a/PString.cpp +++ b/PString.cpp @@ -14,21 +14,21 @@ namespace coreutils { return pstring.substr(cursor); } - std::vector PString::split(std::string delimiter, int maxSize) { - std::vector list; + std::vector PString::split(std::string delimiter, int maxSize) { + std::vector list; size_t end, pos = cursor; while(pos < pstring.length()) { end = pstring.find(delimiter, pos); if(end == std::string::npos) end = pstring.length(); - list.push_back(pstring.substr(pos, end - pos)); + list.push_back(PString(pstring.substr(pos, end - pos))); pos = end + delimiter.size(); if(pos > pstring.size()) break; if(maxSize != 0) { if(list.size() >= maxSize) { - list.push_back(pstring.substr(pos)); + list.push_back(PString(pstring.substr(pos))); break; } } diff --git a/PString.h b/PString.h index 5f685c0..b9d0aa5 100644 --- a/PString.h +++ b/PString.h @@ -12,7 +12,7 @@ namespace coreutils { PString(std::string pstring); std::string str(); - std::vector split(std::string delimiter, int maxSize = 0); + std::vector split(std::string delimiter, int maxSize = 0); std::string getTokenInclude(std::string include); std::string getTokenExclude(std::string exclude); bool ifNext(std::string value); diff --git a/includes b/includes index 1ddcaf7..0c4b0ca 100644 --- a/includes +++ b/includes @@ -32,5 +32,7 @@ #include #include #include +#include + \ No newline at end of file