Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame^] | 1 | // Copyright (C) 2001-2005 Open Source Telecom Corporation. |
| 2 | // Copyright (C) 2006-2010 David Sugar, Tycho Softworks. |
| 3 | // |
| 4 | // This program is free software; you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation; either version 2 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program; if not, write to the Free Software |
| 16 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | // |
| 18 | // As a special exception, you may use this file as part of a free software |
| 19 | // library without restriction. Specifically, if other files instantiate |
| 20 | // templates or use macros or inline functions from this file, or you compile |
| 21 | // this file and link it with other files to produce an executable, this |
| 22 | // file does not by itself cause the resulting executable to be covered by |
| 23 | // the GNU General Public License. This exception does not however |
| 24 | // invalidate any other reasons why the executable file might be covered by |
| 25 | // the GNU General Public License. |
| 26 | // |
| 27 | // This exception applies only to the code released under the name GNU |
| 28 | // Common C++. If you copy code from other releases into a copy of GNU |
| 29 | // Common C++, as the General Public License permits, the exception does |
| 30 | // not apply to the code that you add in this way. To avoid misleading |
| 31 | // anyone as to the status of such modified files, you must delete |
| 32 | // this exception notice from them. |
| 33 | // |
| 34 | // If you write modifications of your own for GNU Common C++, it is your choice |
| 35 | // whether to permit this exception to apply to your modifications. |
| 36 | // If you do not wish that, delete this exception notice. |
| 37 | // |
| 38 | |
| 39 | /** |
| 40 | * @file mime.h |
| 41 | * @short MIME document abstractions. |
| 42 | **/ |
| 43 | |
| 44 | #ifndef COMMONCPP_MIME_H_ |
| 45 | #define COMMONCPP_MIME_H_ |
| 46 | |
| 47 | #ifndef COMMONCPP_CONFIG_H_ |
| 48 | #include <commoncpp/config.h> |
| 49 | #endif |
| 50 | |
| 51 | #ifndef COMMONCPP_SOCKET_H_ |
| 52 | #include <commoncpp/socket.h> |
| 53 | #endif |
| 54 | |
| 55 | NAMESPACE_COMMONCPP |
| 56 | |
| 57 | class MIMEMultipart; |
| 58 | class MIMEItemPart; |
| 59 | |
| 60 | /** |
| 61 | * A container class for multi-part MIME document objects which can |
| 62 | * be streamed to a std::ostream destination. |
| 63 | * |
| 64 | * @author David Sugar <dyfet@ostel.com> |
| 65 | * @short container for streamable multi-part MIME documents. |
| 66 | */ |
| 67 | class __EXPORT MIMEMultipart |
| 68 | { |
| 69 | protected: |
| 70 | friend class MIMEItemPart; |
| 71 | char boundry[8]; |
| 72 | char mtype[80]; |
| 73 | char *header[16]; |
| 74 | MIMEItemPart *first, *last; |
| 75 | |
| 76 | virtual ~MIMEMultipart(); |
| 77 | |
| 78 | public: |
| 79 | /** |
| 80 | * Contruct a multi-part document, and describe it's type. |
| 81 | * |
| 82 | * @param document (content) type. |
| 83 | */ |
| 84 | MIMEMultipart(const char *document); |
| 85 | |
| 86 | /** |
| 87 | * Stream the headers of the multi-part document. The headers |
| 88 | * of individual entities are streamed as part of the body. |
| 89 | * |
| 90 | * @param output to stream document header into. |
| 91 | */ |
| 92 | virtual void head(std::ostream *output); |
| 93 | |
| 94 | /** |
| 95 | * Stream the "body" of the multi-part document. This involves |
| 96 | * streaming the headers and body of each document part. |
| 97 | * |
| 98 | * @param output to stream document body into. |
| 99 | */ |
| 100 | virtual void body(std::ostream *output); |
| 101 | |
| 102 | /** |
| 103 | * Get a string array of the headers to use. This is used to |
| 104 | * assist URLStream::post. |
| 105 | * |
| 106 | * @return array of headers. |
| 107 | */ |
| 108 | char **getHeaders(void) |
| 109 | {return header;}; |
| 110 | }; |
| 111 | |
| 112 | /** |
| 113 | * The Multipart form is a MIME multipart document specific for the |
| 114 | * construction and delivery of form data to a web server through a |
| 115 | * post method. |
| 116 | * |
| 117 | * @author David Sugar <dyfet@ostel.com> |
| 118 | * @short deliver form results as multipart document. |
| 119 | */ |
| 120 | class __EXPORT MIMEMultipartForm : public MIMEMultipart |
| 121 | { |
| 122 | protected: |
| 123 | virtual ~MIMEMultipartForm(); |
| 124 | |
| 125 | public: |
| 126 | /** |
| 127 | * Construct a form result. This is a MIMEMultipart of type |
| 128 | * multipart/form-data. |
| 129 | */ |
| 130 | MIMEMultipartForm(); |
| 131 | }; |
| 132 | |
| 133 | /** |
| 134 | * This is used to attach an item part to a MIME multipart document |
| 135 | * that is being streamed. The base item part class is used by all |
| 136 | * derived items. |
| 137 | * |
| 138 | * @author David Sugar <dyfet@ostel.com> |
| 139 | * @short item or part of a multi-part object. |
| 140 | */ |
| 141 | class __EXPORT MIMEItemPart |
| 142 | { |
| 143 | protected: |
| 144 | friend class MIMEMultipart; |
| 145 | |
| 146 | MIMEMultipart *base; |
| 147 | MIMEItemPart *next; |
| 148 | const char *ctype; |
| 149 | |
| 150 | /** |
| 151 | * Stream the header(s) for the current document part. |
| 152 | * |
| 153 | * @param output to stream header into. |
| 154 | */ |
| 155 | virtual void head(std::ostream *output); |
| 156 | |
| 157 | /** |
| 158 | * Stream the content of this document part. |
| 159 | * |
| 160 | * @param output to stream document body into. |
| 161 | */ |
| 162 | virtual void body(std::ostream *output) = 0; |
| 163 | |
| 164 | /** |
| 165 | * Construct and attach a document part to a multipart document. |
| 166 | * |
| 167 | * @param top multipart document to attach to. |
| 168 | * @param ct Content-Type to use. |
| 169 | */ |
| 170 | MIMEItemPart(MIMEMultipart *top, const char *ct); |
| 171 | |
| 172 | virtual ~MIMEItemPart(); |
| 173 | }; |
| 174 | |
| 175 | /** |
| 176 | * This is a document part type for use in submitting multipart form |
| 177 | * data to a web server. |
| 178 | * |
| 179 | * @author David Sugar <dyfet@ostel.com> |
| 180 | * @short multipart document part for web form data field. |
| 181 | */ |
| 182 | class __EXPORT MIMEFormData : public MIMEItemPart |
| 183 | { |
| 184 | protected: |
| 185 | const char *content; |
| 186 | const char *name; |
| 187 | |
| 188 | virtual ~MIMEFormData(); |
| 189 | |
| 190 | public: |
| 191 | /** |
| 192 | * Stream header, Content-Disposition form-data. |
| 193 | * |
| 194 | * @param output stream to send header to. |
| 195 | */ |
| 196 | void head(std::ostream *output); |
| 197 | |
| 198 | /** |
| 199 | * Stream content (value) of this form data field. |
| 200 | * |
| 201 | * @param output stream to send body to. |
| 202 | */ |
| 203 | void body(std::ostream *output); |
| 204 | |
| 205 | /** |
| 206 | * Construct form data field part of multipart form. |
| 207 | * |
| 208 | * @param top multipart form this is part of |
| 209 | * @param name of form data field |
| 210 | * @param content of form data field |
| 211 | */ |
| 212 | MIMEFormData(MIMEMultipartForm *top, const char *name, const char *content); |
| 213 | }; |
| 214 | |
| 215 | END_NAMESPACE |
| 216 | |
| 217 | #endif |
| 218 | /** EMACS ** |
| 219 | * Local variables: |
| 220 | * mode: c++ |
| 221 | * c-basic-offset: 4 |
| 222 | * End: |
| 223 | */ |