Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / protocols / ace / INet / HeaderBase.h
blobed1c26317ac91fc94f83e6dc9024112e6c0f7a51
1 /**
2 * @file HeaderBase.h
4 * @author Martin Corino <mcorino@remedy.nl>
5 */
7 #ifndef ACE_INET_HEADER_BASE_H
8 #define ACE_INET_HEADER_BASE_H
10 #include /**/ "ace/pre.h"
12 #include /**/ "ace/config-all.h"
14 #if !defined (ACE_LACKS_PRAGMA_ONCE)
15 # pragma once
16 #endif /* ACE_LACKS_PRAGMA_ONCE */
18 #include "ace/SString.h"
19 #include "ace/Containers_T.h"
20 #include "ace/Containers_T.h"
21 #include "ace/OS_NS_ctype.h"
22 #include "ace/INet/INet_Export.h"
23 #include <iostream>
25 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
27 namespace ACE
29 namespace INet
31 /**
32 * @class ACE_INet_NVPair
34 * @brief Name/Value pair holder class.
37 class ACE_INET_Export NVPair
39 public:
40 NVPair ();
41 NVPair (const ACE_CString& first);
42 NVPair (const ACE_CString& first, const ACE_CString& second);
43 NVPair (const NVPair& pair);
44 virtual ~NVPair ();
45 NVPair& operator =(const NVPair& pair);
46 bool operator ==(const NVPair& pair) const;
47 bool operator <(const NVPair& pair) const;
49 const ACE_CString& first () const;
51 void first (const ACE_CString& t1);
53 const ACE_CString& second () const;
55 void second (const ACE_CString& t2);
57 private:
58 ACE_CString first_;
59 ACE_CString second_;
62 typedef ACE_Ordered_MultiSet<NVPair> TNVMap;
65 /**
66 * @class ACE_INet_HeaderBase
68 * @brief Encapsulates message header.
71 class ACE_INET_Export HeaderBase
73 public:
74 /// Constructor
75 HeaderBase();
77 /// Destructor
78 virtual ~HeaderBase();
80 /// Sets the Content-Length header.
81 /// Removes the Content-Length header if
82 /// length is UNKNOWN_CONTENT_LENGTH.
83 virtual void set_content_length(int length);
85 /// Returns the content length for this message.
86 /// Returns UNKNOWN_CONTENT_LENGTH if no
87 /// Content-Length header is present.
88 virtual int get_content_length() const;
90 /// Sets the content type for this message.
91 /// Removes the Content-Type header if
92 /// UNKNOWN_CONTENT_TYPE is specified.
93 virtual void set_content_type(const ACE_CString& mime_type);
95 /// Returns the content type for this message.
96 /// Returns UNKNOWN_CONTENT_TYPE if
97 /// no Content-Type header is present.
98 virtual ACE_CString get_content_type() const;
100 void clear ();
102 /// Writes the headers to the given stream
103 virtual void write(std::ostream& str) const;
105 /// Reads the headers from the
106 /// given stream.
107 virtual bool read(std::istream& str);
109 static const int UNKNOWN_CONTENT_LENGTH;
110 static const ACE_CString UNKNOWN_CONTENT_TYPE;
112 static const ACE_CString CONTENT_LENGTH;
113 static const ACE_CString CONTENT_TYPE;
115 static const ACE_CString EMPTY;
117 /// Sets header @a name to @a value. Overwrites existing vaues.
118 void set (const ACE_CString& name, const ACE_CString& value);
120 /// Adds header @a name with @a value. Allows duplicates.
121 void add (const ACE_CString& name, const ACE_CString& value);
123 /// Removes header @a name (first found).
124 void remove (const ACE_CString& name);
126 /// Retrieves value for header @a name into @a value (first found).
127 bool get (const ACE_CString& name, ACE_CString& value) const;
129 /// Returns true if a header @a name exists (1 or more), false otherwise.
130 bool has (const ACE_CString& name) const;
132 /// Retrieves values for all headers @a name into @a values.
133 void get_values (const ACE_CString& name, ACE_Array<ACE_CString>& values) const;
135 protected:
136 int read_field (std::istream& str, ACE_CString& var, size_t maxlen, char delim);
137 int read_ws_field (std::istream& str, ACE_CString& var, size_t maxlen);
139 static const int eof_;
141 private:
142 /// Limits for reading a header
143 enum Limits
145 MAX_NAME_LENGTH = 256,
146 MAX_VALUE_LENGTH = 4096
149 TNVMap header_values_;
154 ACE_END_VERSIONED_NAMESPACE_DECL
156 #if defined (__ACE_INLINE__)
157 #include "ace/INet/HeaderBase.inl"
158 #endif
160 #include /**/ "ace/post.h"
161 #endif /* ACE_INET_HEADER_BASE_H */