#include <HeaderBase.h>


Public Member Functions | |
| HeaderBase () | |
| Constructor. | |
| virtual | ~HeaderBase () |
| Destructor. | |
| virtual void | set_content_length (int length) |
| virtual int | get_content_length () const |
| virtual void | set_content_type (const ACE_CString &mime_type) |
| virtual ACE_CString | get_content_type () const |
| void | clear () |
| virtual void | write (std::ostream &str) const |
| Writes the headers to the given stream. | |
| virtual bool | read (std::istream &str) |
| void | set (const ACE_CString &name, const ACE_CString &value) |
| Sets header <name> to . Overwrites existing vaues. | |
| void | add (const ACE_CString &name, const ACE_CString &value) |
| Adds header <name> with . Allows duplicates. | |
| void | remove (const ACE_CString &name) |
| Removes header <name> (first found). | |
| bool | get (const ACE_CString &name, ACE_CString &value) const |
| Retrieves value for header <name> into (first found). | |
| bool | has (const ACE_CString &name) const |
| Returns true if a header <name> exists (1 or more), false otherwise. | |
| void | get_values (const ACE_CString &name, ACE_Array< ACE_CString > &values) const |
| Retrieves values for all headers <name> into <values>. | |
Static Public Attributes | |
| static const int | UNKNOWN_CONTENT_LENGTH = -1 |
| static const ACE_CString | UNKNOWN_CONTENT_TYPE |
| static const ACE_CString | CONTENT_LENGTH = "Content-Length" |
| static const ACE_CString | CONTENT_TYPE = "Content-Type" |
| static const ACE_CString | EMPTY |
Protected Member Functions | |
| int | read_field (std::istream &str, ACE_CString &var, size_t maxlen, char delim) |
| int | read_ws_field (std::istream &str, ACE_CString &var, size_t maxlen) |
Static Protected Attributes | |
| static const int | eof_ = std::char_traits<char>::eof() |
Private Types | |
| enum | Limits { MAX_NAME_LENGTH = 256, MAX_VALUE_LENGTH = 4096 } |
Limits for reading a header. More... | |
Private Attributes | |
| TNVMap | header_values_ |
Definition at line 73 of file HeaderBase.h.
enum ACE::INet::HeaderBase::Limits [private] |
Limits for reading a header.
Reimplemented in ACE::HTTP::Request, and ACE::HTTP::Response.
Definition at line 145 of file HeaderBase.h.
{
MAX_NAME_LENGTH = 256,
MAX_VALUE_LENGTH = 4096
};
| ACE::INet::HeaderBase::HeaderBase | ( | ) |
| ACE::INet::HeaderBase::~HeaderBase | ( | ) | [virtual] |
| void ACE::INet::HeaderBase::add | ( | const ACE_CString & | name, | |
| const ACE_CString & | value | |||
| ) | [inline] |
Adds header <name> with . Allows duplicates.
Definition at line 51 of file HeaderBase.inl.
{
this->header_values_.insert (NVPair (name, value));
}
| void ACE::INet::HeaderBase::clear | ( | void | ) | [inline] |
Definition at line 45 of file HeaderBase.inl.
{
this->header_values_.reset ();
}
| bool ACE::INet::HeaderBase::get | ( | const ACE_CString & | name, | |
| ACE_CString & | value | |||
| ) | const [inline] |
Retrieves value for header <name> into (first found).
Definition at line 63 of file HeaderBase.inl.
{
TNVMap::ITERATOR it (const_cast<TNVMap&> (this->header_values_));
if (this->header_values_.find (NVPair (name), it) == 0)
{
value = (*it).second ();
return true;
}
return false;
}
| int ACE::INet::HeaderBase::get_content_length | ( | ) | const [inline, virtual] |
Returns the content length for this message. Returns UNKNOWN_CONTENT_LENGTH if no Content-Length header is present.
Definition at line 13 of file HeaderBase.inl.
{
ACE_CString lenstr;
if (this->get (CONTENT_LENGTH, lenstr))
{
return ACE_OS::atoi (lenstr.c_str ());
}
return UNKNOWN_CONTENT_LENGTH;
}
| ACE_CString ACE::INet::HeaderBase::get_content_type | ( | ) | const [inline, virtual] |
Returns the content type for this message. Returns UNKNOWN_CONTENT_TYPE if no Content-Type header is present.
Definition at line 37 of file HeaderBase.inl.
{
ACE_CString val = UNKNOWN_CONTENT_TYPE;
this->get (CONTENT_TYPE, val);
return val;
}
| void ACE::INet::HeaderBase::get_values | ( | const ACE_CString & | name, | |
| ACE_Array< ACE_CString > & | values | |||
| ) | const |
Retrieves values for all headers <name> into <values>.
Definition at line 138 of file HeaderBase.cpp.
{
TNVMap::ITERATOR it (const_cast<TNVMap&> (this->header_values_));
if (this->header_values_.find (name, it) == 0)
{
for (; !it.done () && ((*it).second () == name) ;it.advance ())
{
if (values.size (values.size ()+1) == 0)
{
values.set ((*it).second (), values.size ()-1);
}
}
}
}
| bool ACE::INet::HeaderBase::has | ( | const ACE_CString & | name | ) | const [inline] |
Returns true if a header <name> exists (1 or more), false otherwise.
Definition at line 75 of file HeaderBase.inl.
{
TNVMap::ITERATOR it (const_cast<TNVMap&> (this->header_values_));
if (this->header_values_.find (NVPair (name), it) == 0)
{
return true;
}
return false;
}
| bool ACE::INet::HeaderBase::read | ( | std::istream & | str | ) | [virtual] |
Reads the headers from the given stream.
Reimplemented in ACE::HTTP::Request, and ACE::HTTP::Response.
Definition at line 65 of file HeaderBase.cpp.
{
ACE_CString name (64, '\0');
ACE_CString value (128, '\0');
int ch = str.peek ();
while (ch != eof_ && ch != '\r' && ch != '\n')
{
name.fast_clear ();
value.fast_clear ();
// parse name
ch = this->read_field (str, name, MAX_NAME_LENGTH, ':');
if (ch == '\n')
{
ch = str.get ();
continue; // ignore invalid headers
}
if (ch != ':')
{
return false; // name too long/missing colon; cannot continue
}
// skip leading whitespace before next field
while (ACE_OS::ace_isspace (str.peek ()))
{
ch = str.get ();
}
// parse value
ch = this->read_field (str, value, MAX_VALUE_LENGTH, '\r');
if (ch == '\r')
ch = str.get (); // get lf
if (ch != '\n')
return false; // value too long/no crlf found; cannot continue
// followup lines starting with ws are continuations of the value
// and must be appended
ch = str.peek ();
while (ch == ' ' || ch == '\t')
{
ch = this->read_field (str, value, MAX_VALUE_LENGTH, '\r');
if (ch == '\r')
ch = str.get (); // get lf
if (ch != '\n')
return false; // multiline value too long/no crlf; cannot continue
ch = str.peek ();
}
this->add (name, value);
INET_DEBUG (9, (LM_DEBUG, DLINFO
ACE_TEXT ("ACE_INet_HTTP: <-+ %C: %C\n"),
name.c_str (),
value.c_str ()));
}
return true;
}
| int ACE::INet::HeaderBase::read_field | ( | std::istream & | str, | |
| ACE_CString & | var, | |||
| size_t | maxlen, | |||
| char | delim | |||
| ) | [inline, protected] |
Definition at line 86 of file HeaderBase.inl.
| int ACE::INet::HeaderBase::read_ws_field | ( | std::istream & | str, | |
| ACE_CString & | var, | |||
| size_t | maxlen | |||
| ) | [inline, protected] |
Definition at line 98 of file HeaderBase.inl.
{
int ch = str.get ();
while (!ACE_OS::ace_isspace (ch) && ch != eof_ && var.length () < maxlen)
{
var += ch;
ch = str.get ();
}
return ch;
}
| void ACE::INet::HeaderBase::remove | ( | const ACE_CString & | name | ) | [inline] |
Removes header <name> (first found).
Definition at line 57 of file HeaderBase.inl.
{
this->header_values_.remove (NVPair (name, EMPTY));
}
| void ACE::INet::HeaderBase::set | ( | const ACE_CString & | name, | |
| const ACE_CString & | value | |||
| ) |
Sets header <name> to . Overwrites existing vaues.
Definition at line 125 of file HeaderBase.cpp.
{
TNVMap::ITERATOR it (this->header_values_);
if (this->header_values_.find (NVPair (name), it) == 0)
{
(*it).second (value);
}
else
{
this->header_values_.insert (NVPair (name, value));
}
}
| void ACE::INet::HeaderBase::set_content_length | ( | int | length | ) | [virtual] |
Sets the Content-Length header. Removes the Content-Length header if length is UNKNOWN_CONTENT_LENGTH.
Definition at line 37 of file HeaderBase.cpp.
{
if (length == UNKNOWN_CONTENT_LENGTH)
{
this->remove (CONTENT_LENGTH);
}
else
{
char buf[32];
this->set (CONTENT_LENGTH,
ACE_OS::itoa (length, buf, 10));
}
}
| void ACE::INet::HeaderBase::set_content_type | ( | const ACE_CString & | mime_type | ) | [inline, virtual] |
Sets the content type for this message. Removes the Content-Type header if UNKNOWN_CONTENT_TYPE is specified.
Definition at line 24 of file HeaderBase.inl.
{
if (mime_type == UNKNOWN_CONTENT_TYPE)
{
this->remove (CONTENT_TYPE);
}
else
{
this->set (CONTENT_TYPE, UNKNOWN_CONTENT_TYPE);
}
}
| void ACE::INet::HeaderBase::write | ( | std::ostream & | str | ) | const [virtual] |
Writes the headers to the given stream.
Reimplemented in ACE::HTTP::Request, and ACE::HTTP::Response.
Definition at line 51 of file HeaderBase.cpp.
{
TNVMap::ITERATOR it (const_cast<TNVMap&> (this->header_values_));
for (it.first (); !it.done () ;it.advance ())
{
str << (*it).first ().c_str () << ": " << (*it).second ().c_str () << "\r\n";
INET_DEBUG (9, (LM_DEBUG, DLINFO
ACE_TEXT ("ACE_INet_HTTP: +-> %C: %C\n"),
(*it).first ().c_str (),
(*it).second ().c_str ()));
}
}
const ACE_CString ACE::INet::HeaderBase::CONTENT_LENGTH = "Content-Length" [static] |
Definition at line 114 of file HeaderBase.h.
const ACE_CString ACE::INet::HeaderBase::CONTENT_TYPE = "Content-Type" [static] |
Definition at line 115 of file HeaderBase.h.
const ACE_CString ACE::INet::HeaderBase::EMPTY [static] |
Definition at line 117 of file HeaderBase.h.
const int ACE::INet::HeaderBase::eof_ = std::char_traits<char>::eof() [static, protected] |
Definition at line 141 of file HeaderBase.h.
TNVMap ACE::INet::HeaderBase::header_values_ [private] |
Definition at line 151 of file HeaderBase.h.
const int ACE::INet::HeaderBase::UNKNOWN_CONTENT_LENGTH = -1 [static] |
Definition at line 111 of file HeaderBase.h.
const ACE_CString ACE::INet::HeaderBase::UNKNOWN_CONTENT_TYPE [static] |
Definition at line 112 of file HeaderBase.h.
1.7.0