Matrix Science header

ms_http_client_mime.hpp

00001 /*
00002 ##############################################################################
00003 # file: ms_http_client_mime.hpp                                                  #
00004 # 'msparser' toolkit                                                         #
00005 # Builds a MIME string from the boundary separator and the element values    #
00006 ##############################################################################
00007 # COPYRIGHT NOTICE                                                           #
00008 # Copyright 1998-2013 Matrix Science Limited  All Rights Reserved.           #
00009 #                                                                            #
00010 ##############################################################################
00011  * @(#)$Source: /vol/cvsroot/parser/inc/ms_http_client_mime.hpp,v $
00012  * @(#)$Revision: 1.2 $
00013  * @(#)$Date: 2015/06/16 15:30:11 $
00014 ##############################################################################
00015  */
00016 
00017 #ifndef MS_HTTP_CLIENT_MIME_HPP
00018 #define MS_HTTP_CLIENT_MIME_HPP
00019 
00020 #ifdef _WIN32
00021 #pragma warning(disable:4251)   // Don't want all classes to be exported
00022 #pragma warning(disable:4786)   // Debug symbols too long
00023 #   ifndef _MATRIX_USE_STATIC_LIB
00024 #       ifdef MS_MASCOTRESFILE_EXPORTS
00025 #           define MS_MASCOTRESFILE_API __declspec(dllexport)
00026 #       else
00027 #           define MS_MASCOTRESFILE_API __declspec(dllimport)
00028 #       endif
00029 #   else
00030 #       define MS_MASCOTRESFILE_API
00031 #   endif
00032 #else
00033 #   define MS_MASCOTRESFILE_API
00034 #endif
00035 
00036 #include <string>
00037 #include <vector>
00038 
00039 namespace matrix_science
00040 {
00046     // for internal use
00047     class MS_MASCOTRESFILE_API ms_http_client_mime_item
00048     {
00049         public:
00050             ms_http_client_mime_item();
00051             ms_http_client_mime_item(const std::string & name, const std::string & value);
00052             ms_http_client_mime_item(const std::string & name, const std::string & value, const std::string & filename, const std::string & contentType);
00053 
00054             std::string name() const;
00055             std::string value() const;
00056             bool hasFilename() const;
00057             std::string filename() const;
00058             std::string contentType() const;
00059 
00060             void setName(const std::string & name);
00061             void setValue(const std::string & value);
00062             void setValueWithFilename(const std::string & value, const std::string & filename, const std::string & contentType);
00063 
00064         private:
00065             std::string name_;
00066             std::string value_;
00067             bool        hasFilename_;
00068             std::string filename_;
00069             std::string contentType_;
00070     };
00071 
00073 
00081     class MS_MASCOTRESFILE_API ms_http_client_mime
00082     {
00083         public:
00084             enum ContentType {
00085                 CT_MIXED,
00086                 CT_FORMDATA
00087             };
00088 
00089             enum Continuation {
00090                 CONTENT_CONTINUES,
00091                 CONTENT_TERMINATES
00092             };
00093 
00095             static std::string formatHeader(
00096                     const std::string & boundary,
00097                     ContentType contentType);
00098 
00100             virtual ~ms_http_client_mime();
00101 
00103             void append(const std::string & name, const std::string & value);
00104 
00106             void appendFile(const std::string & name, const std::string & filename, const std::string & contentType, const std::string & prefixData = "");
00107 
00108 
00110             int getCount() const;
00111             int count() const { return getCount(); }   // Deprecated. Released with 2.5.2
00112 
00113             // index 1..count inclusive (not zero based!)
00115             std::string getName(int oneBasedIndex) const;
00116             std::string name(int oneBasedIndex) const { return getName(oneBasedIndex); }  // Deprecated. Released with 2.5.2
00117 
00119             std::string getValue(int oneBasedIndex) const;
00120             std::string value(int oneBasedIndex) const { return getValue(oneBasedIndex); } // Deprecated. Released with 2.5.2
00121 
00123             bool hasFilename(int oneBasedIndex) const;
00124 
00126             std::string getFilename(int oneBasedIndex) const;
00127             std::string filename(int oneBasedIndex) const { return getFilename(oneBasedIndex); } // Deprecated. Released with 2.5.2
00128 
00129             // index 1..count inclusive (not zero based!)
00131             void setValue(int oneBasedIndex, const std::string & value);
00132 
00134             void setValueWithFilename(int oneBasedIndex, const std::string & value, const std::string & filename, const std::string & contentType);
00135 
00136             // index 1..count inclusive (not zero based!)
00138             void erase(int oneBasedIndex);
00139 
00141             std::string format(
00142                     const std::string & boundary,
00143                     matrix_science::ms_http_client_mime::Continuation continuation) const;
00144 
00145         private:
00146             std::vector<ms_http_client_mime_item> items_;
00147     };
00148  // end of http_client_group
00150 
00151 } // namespace matrix_science
00152 
00153 #endif // MS_HTTP_CLIENT_MIME_HPP
00154 
00155 /*------------------------------- End of File -------------------------------*/
Copyright © 2016 Matrix Science Ltd.  All Rights Reserved. Generated on Fri Jun 2 2017 01:44:51