blob: 4ff9c205ebe99be230a42c9d293a81374551a05a [file] [log] [blame]
Emeric Vigier2f625822012-08-06 11:09:52 -04001// 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 CCXX_MIME_H_
45#define CCXX_MIME_H_
46
47#ifndef CCXX_CONFIG_H_
48#include <cc++/config.h>
49#endif
50
51#ifndef CCXX_SOCKET_H_
52#include <cc++/socket.h>
53#endif
54
55#ifdef CCXX_NAMESPACES
56namespace ost {
57#endif
58
59class __EXPORT MIMEMultipart;
60class __EXPORT MIMEItemPart;
61
62/**
63 * A container class for multi-part MIME document objects which can
64 * be streamed to a std::ostream destination.
65 *
66 * @author David Sugar <dyfet@ostel.com>
67 * @short container for streamable multi-part MIME documents.
68 */
69class __EXPORT MIMEMultipart
70{
71protected:
72 friend class __EXPORT MIMEItemPart;
73 char boundry[8];
74 char mtype[80];
75 char *header[16];
76 MIMEItemPart *first, *last;
77
78 virtual ~MIMEMultipart();
79
80public:
81 /**
82 * Contruct a multi-part document, and describe it's type.
83 *
84 * @param document (content) type.
85 */
86 MIMEMultipart(const char *document);
87
88 /**
89 * Stream the headers of the multi-part document. The headers
90 * of individual entities are streamed as part of the body.
91 *
92 * @param output to stream document header into.
93 */
94 virtual void head(std::ostream *output);
95
96 /**
97 * Stream the "body" of the multi-part document. This involves
98 * streaming the headers and body of each document part.
99 *
100 * @param output to stream document body into.
101 */
102 virtual void body(std::ostream *output);
103
104 /**
105 * Get a string array of the headers to use. This is used to
106 * assist URLStream::post.
107 *
108 * @return array of headers.
109 */
110 char **getHeaders(void)
111 {return header;};
112};
113
114/**
115 * The Multipart form is a MIME multipart document specific for the
116 * construction and delivery of form data to a web server through a
117 * post method.
118 *
119 * @author David Sugar <dyfet@ostel.com>
120 * @short deliver form results as multipart document.
121 */
122class __EXPORT MIMEMultipartForm : public MIMEMultipart
123{
124protected:
125 virtual ~MIMEMultipartForm();
126
127public:
128 /**
129 * Construct a form result. This is a MIMEMultipart of type
130 * multipart/form-data.
131 */
132 MIMEMultipartForm();
133};
134
135/**
136 * This is used to attach an item part to a MIME multipart document
137 * that is being streamed. The base item part class is used by all
138 * derived items.
139 *
140 * @author David Sugar <dyfet@ostel.com>
141 * @short item or part of a multi-part object.
142 */
143class __EXPORT MIMEItemPart
144{
145protected:
146 friend class __EXPORT MIMEMultipart;
147
148 MIMEMultipart *base;
149 MIMEItemPart *next;
150 const char *ctype;
151
152 /**
153 * Stream the header(s) for the current document part.
154 *
155 * @param output to stream header into.
156 */
157 virtual void head(std::ostream *output);
158
159 /**
160 * Stream the content of this document part.
161 *
162 * @param output to stream document body into.
163 */
164 virtual void body(std::ostream *output) = 0;
165
166 /**
167 * Construct and attach a document part to a multipart document.
168 *
169 * @param top multipart document to attach to.
170 * @param ct Content-Type to use.
171 */
172 MIMEItemPart(MIMEMultipart *top, const char *ct);
173
174 virtual ~MIMEItemPart();
175};
176
177/**
178 * This is a document part type for use in submitting multipart form
179 * data to a web server.
180 *
181 * @author David Sugar <dyfet@ostel.com>
182 * @short multipart document part for web form data field.
183 */
184class __EXPORT MIMEFormData : public MIMEItemPart
185{
186protected:
187 const char *content;
188 const char *name;
189
190 virtual ~MIMEFormData();
191
192public:
193 /**
194 * Stream header, Content-Disposition form-data.
195 *
196 * @param output stream to send header to.
197 */
198 void head(std::ostream *output);
199
200 /**
201 * Stream content (value) of this form data field.
202 *
203 * @param output stream to send body to.
204 */
205 void body(std::ostream *output);
206
207 /**
208 * Construct form data field part of multipart form.
209 *
210 * @param top multipart form this is part of
211 * @param name of form data field
212 * @param content of form data field
213 */
214 MIMEFormData(MIMEMultipartForm *top, const char *name, const char *content);
215};
216
217#ifdef CCXX_NAMESPACES
218}
219#endif
220
221#endif
222/** EMACS **
223 * Local variables:
224 * mode: c++
225 * c-basic-offset: 4
226 * End:
227 */