Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

/home/tommi/tntnet/framework/common/tnt/multipart.h

00001 /*
00002  * Copyright (C) 2003 Tommi Maekitalo
00003  * 
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  * 
00009  * As a special exception, you may use this file as part of a free
00010  * software library without restriction. Specifically, if other files
00011  * instantiate templates or use macros or inline functions from this
00012  * file, or you compile this file and link it with other files to
00013  * produce an executable, this file does not by itself cause the
00014  * resulting executable to be covered by the GNU General Public
00015  * License. This exception does not however invalidate any other
00016  * reasons why the executable file might be covered by the GNU Library
00017  * General Public License.
00018  * 
00019  * This library is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  * Lesser General Public License for more details.
00023  * 
00024  * You should have received a copy of the GNU Lesser General Public
00025  * License along with this library; if not, write to the Free Software
00026  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
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       // stl-style accessors
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 
Copyright © 2008 The Tntnet Development Team
Tntnet 1.6