00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef TNT_MULTIPART_H
00031 #define TNT_MULTIPART_H
00032
00033 #include <tnt/messageheader.h>
00034 #include <tnt/contentdisposition.h>
00035 #include <vector>
00036 #include <iterator>
00037
00038 namespace tnt
00039 {
00041 class Partheader : public Messageheader
00042 {
00043 Contentdisposition cd;
00044
00045 protected:
00046 return_type onField(const char* name, const char* value);
00047
00048 public:
00049 const Contentdisposition& getContentDisposition() const
00050 { return cd; }
00051 std::string getMimetype() const;
00052 };
00053
00055 class Part
00056 {
00057 public:
00058 typedef std::string::const_iterator const_iterator;
00059 typedef std::string::const_iterator iterator;
00060 typedef std::string::size_type size_type;
00061 typedef std::string::value_type value_type;
00062 typedef std::string::pointer pointer;
00063 typedef std::string::reference reference;
00064 typedef std::string::const_reference const_reference;
00065 typedef std::string::difference_type difference_type;
00066
00067 private:
00068 Partheader header;
00069 const_iterator bodyBegin;
00070 const_iterator bodyEnd;
00071
00072 public:
00073 Part()
00074 #if defined(_RWSTDDEBUG) && !defined(_RWSTD_NO_DEBUG_ITER)
00075 : bodyBegin(), bodyEnd()
00076 { bodyBegin._C_iter = bodyEnd._C_iter = 0;}
00077 #else
00078 : bodyBegin(0), bodyEnd(0)
00079 { }
00080 #endif
00081
00082 Part(const_iterator b, const_iterator e);
00083
00085 const Partheader& getHeader() const { return header; }
00087 std::string getHeader(const std::string& key) const;
00088
00090 const std::string& getType() const
00091 { return header.getContentDisposition().getType(); }
00093 std::string getMimetype() const
00094 { return header.getMimetype(); }
00096 const std::string& getName() const
00097 { return header.getContentDisposition().getName(); }
00099 const std::string& getFilename() const
00100 { return header.getContentDisposition().getFilename(); }
00102 const_iterator getBodyBegin() const
00103 { return bodyBegin; }
00105 const_iterator getBodyEnd() const
00106 { return bodyEnd; }
00108 std::string getBody() const
00109 { return std::string(getBodyBegin(), getBodyEnd()); }
00110 bool isEmpty() const
00111 { return getBodyBegin() == getBodyEnd(); }
00112 size_type getSize() const
00113 { return getBodyEnd() - getBodyBegin(); }
00114
00115
00116 const_iterator begin() const { return getBodyBegin(); }
00117 const_iterator end() const { return getBodyEnd(); }
00118 size_type size() const { return getSize(); }
00119 bool empty() const { return isEmpty(); }
00120 };
00121
00123 class Multipart
00124 {
00125 public:
00126 typedef Part part_type;
00127 typedef std::vector<part_type> parts_type;
00128 typedef parts_type::const_iterator const_iterator;
00129 typedef parts_type::value_type value_type;
00130
00131 private:
00132 std::string body;
00133 parts_type parts;
00134
00135 public:
00136 Multipart()
00137 { }
00138 void set(const std::string& boundary, const std::string& body);
00139
00140 const_iterator begin() const { return parts.begin(); }
00141 const_iterator end() const { return parts.end(); }
00142 const_iterator find(const std::string& partName,
00143 const_iterator start) const;
00144 const_iterator find(const std::string& partName) const
00145 { return find(partName, begin()); }
00146 };
00147
00148 }
00149
00150 #endif // TNT_MULTIPART_H
00151