UCommon
mime.h
Go to the documentation of this file.
1// Copyright (C) 2001-2005 Open Source Telecom Corporation.
2// Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
3// Copyright (C) 2015 Cherokees of Idaho.
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with this program. If not, see <http://www.gnu.org/licenses/>.
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
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
55namespace ost {
56
57class MIMEMultipart;
58class MIMEItemPart;
59
67class __EXPORT MIMEMultipart
68{
69private:
70 __DELETE_COPY(MIMEMultipart);
71
72protected:
73 friend class MIMEItemPart;
74 char boundry[8];
75 char mtype[80];
76 char *header[16];
77 MIMEItemPart *first, *last;
78
79 virtual ~MIMEMultipart();
80
81public:
87 MIMEMultipart(const char *document);
88
95 virtual void head(std::ostream *output);
96
103 virtual void body(std::ostream *output);
104
111 char **getHeaders(void) {
112 return header;
113 }
114};
115
124class __EXPORT MIMEMultipartForm : public MIMEMultipart
125{
126private:
127 __DELETE_COPY(MIMEMultipartForm);
128
129protected:
130 virtual ~MIMEMultipartForm();
131
132public:
138};
139
148class __EXPORT MIMEItemPart
149{
150private:
151 __DELETE_COPY(MIMEItemPart);
152
153protected:
154 friend class MIMEMultipart;
155
156 MIMEMultipart *base;
157 MIMEItemPart *next;
158 const char *ctype;
159
165 virtual void head(std::ostream *output);
166
172 virtual void body(std::ostream *output) = 0;
173
180 MIMEItemPart(MIMEMultipart *top, const char *ct);
181
182 virtual ~MIMEItemPart();
183};
184
192class __EXPORT MIMEFormData : public MIMEItemPart
193{
194private:
195 __DELETE_COPY(MIMEFormData);
196
197protected:
198 const char *content;
199 const char *name;
200
201 virtual ~MIMEFormData();
202
203public:
209 void head(std::ostream *output) __OVERRIDE;
210
216 void body(std::ostream *output) __OVERRIDE;
217
225 MIMEFormData(MIMEMultipartForm *top, const char *name, const char *content);
226};
227
228} // namespace ost
229
230#endif
A container class for multi-part MIME document objects which can be streamed to a std::ostream destin...
Definition mime.h:68
MIMEMultipart(const char *document)
Contruct a multi-part document, and describe it's type.
char ** getHeaders(void)
Get a string array of the headers to use.
Definition mime.h:111
virtual void body(std::ostream *output)
Stream the "body" of the multi-part document.
virtual void head(std::ostream *output)
Stream the headers of the multi-part document.
The Multipart form is a MIME multipart document specific for the construction and delivery of form da...
Definition mime.h:125
MIMEMultipartForm()
Construct a form result.
This is used to attach an item part to a MIME multipart document that is being streamed.
Definition mime.h:149
virtual void body(std::ostream *output)=0
Stream the content of this document part.
MIMEItemPart(MIMEMultipart *top, const char *ct)
Construct and attach a document part to a multipart document.
virtual void head(std::ostream *output)
Stream the header(s) for the current document part.
This is a document part type for use in submitting multipart form data to a web server.
Definition mime.h:193
MIMEFormData(MIMEMultipartForm *top, const char *name, const char *content)
Construct form data field part of multipart form.
void head(std::ostream *output)
Stream header, Content-Disposition form-data.
void body(std::ostream *output)
Stream content (value) of this form data field.
socket operations.