source: XMLIO_V2/external/include/Poco/Net/MessageHeader.h @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

  • Property svn:eol-style set to native
File size: 5.2 KB
Line 
1//
2// MessageHeader.h
3//
4// $Id: //poco/1.3/Net/include/Poco/Net/MessageHeader.h#1 $
5//
6// Library: Net
7// Package: Messages
8// Module:  MessageHeader
9//
10// Definition of the MessageHeader class.
11//
12// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
13// and Contributors.
14//
15// Permission is hereby granted, free of charge, to any person or organization
16// obtaining a copy of the software and accompanying documentation covered by
17// this license (the "Software") to use, reproduce, display, distribute,
18// execute, and transmit the Software, and to prepare derivative works of the
19// Software, and to permit third-parties to whom the Software is furnished to
20// do so, all subject to the following:
21//
22// The copyright notices in the Software and this entire statement, including
23// the above license grant, this restriction and the following disclaimer,
24// must be included in all copies of the Software, in whole or in part, and
25// all derivative works of the Software, unless such copies or derivative
26// works are solely in the form of machine-executable object code generated by
27// a source language processor.
28//
29// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35// DEALINGS IN THE SOFTWARE.
36//
37
38
39#ifndef Net_MessageHeader_INCLUDED
40#define Net_MessageHeader_INCLUDED
41
42
43#include "Poco/Net/Net.h"
44#include "Poco/Net/NameValueCollection.h"
45#include <ostream>
46#include <istream>
47#include <vector>
48
49
50namespace Poco {
51namespace Net {
52
53
54class Net_API MessageHeader: public NameValueCollection
55        /// A collection of name-value pairs that are used in
56        /// various internet protocols like HTTP and SMTP.
57        ///
58        /// The name is case-insensitive.
59        ///
60        /// There can be more than one name-value pair with the
61        /// same name.
62        ///
63        /// MessageHeader supports writing and reading the
64        /// header data in RFC 2822 format.
65{
66public:
67        MessageHeader();
68                /// Creates the MessageHeader.
69
70        MessageHeader(const MessageHeader& messageHeader);
71                /// Creates the MessageHeader by copying
72                /// another one.
73
74        virtual ~MessageHeader();
75                /// Destroys the MessageHeader.
76
77        MessageHeader& operator = (const MessageHeader& messageHeader);
78                /// Assigns the content of another MessageHeader.
79
80        virtual void write(std::ostream& ostr) const;
81                /// Writes the message header to the given output stream.
82                ///
83                /// The format is one name-value pair per line, with
84                /// name and value separated by a colon and lines
85                /// delimited by a carriage return and a linefeed
86                /// character. See RFC 2822 for details.
87               
88        virtual void read(std::istream& istr);
89                /// Reads the message header from the given input stream.
90                ///
91                /// See write() for the expected format.
92                /// Also supported is folding of field content, according
93                /// to section 2.2.3 of RFC 2822.
94                ///
95                /// Reading stops at the first empty line (a line only
96                /// containing \r\n or \n), as well as at the end of
97                /// the stream.
98                ///
99                /// Some basic sanity checking of the input stream is
100                /// performed.
101                ///
102                /// Throws a MessageException if the input stream is
103                /// malformed.
104               
105        static void splitElements(const std::string& s, std::vector<std::string>& elements, bool ignoreEmpty = true);
106                /// Splits the given string into separate elements. Elements are expected
107                /// to be separated by commas.
108                ///
109                /// For example, the string
110                ///   text/plain; q=0.5, text/html, text/x-dvi; q=0.8
111                /// is split into the elements
112                ///   text/plain; q=0.5
113                ///   text/html
114                ///   text/x-dvi; q=0.8
115                ///
116                /// Commas enclosed in double quotes do not split elements.
117                ///
118                /// If ignoreEmpty is true, empty elements are not returned.
119               
120        static void splitParameters(const std::string& s, std::string& value, NameValueCollection& parameters);
121                /// Splits the given string into a value and a collection of parameters.
122                /// Parameters are expected to be separated by semicolons.
123                ///
124                /// Enclosing quotes of parameter values are removed.
125                ///
126                /// For example, the string
127                ///   multipart/mixed; boundary="MIME_boundary_01234567"
128                /// is split into the value
129                ///   multipart/mixed
130                /// and the parameter
131                ///   boundary -> MIME_boundary_01234567
132
133        static void splitParameters(const std::string::const_iterator& begin, const std::string::const_iterator& end, NameValueCollection& parameters);
134                /// Splits the given string into a collection of parameters.
135                /// Parameters are expected to be separated by semicolons.
136                ///
137                /// Enclosing quotes of parameter values are removed.
138
139        static void quote(const std::string& value, std::string& result, bool allowSpace = false);
140                /// Checks if the value must be quoted. If so, the value is
141                /// appended to result, enclosed in double-quotes.
142                /// Otherwise. the value is appended to result as-is.
143               
144private:
145        enum Limits
146                /// Limits for basic sanity checks when reading a header
147        {
148                MAX_NAME_LENGTH  = 256,
149                MAX_VALUE_LENGTH = 4096
150        };
151};
152
153
154} } // namespace Poco::Net
155
156
157#endif // Net_MessageHeader_INCLUDED
Note: See TracBrowser for help on using the repository browser.