1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
/* $Id: Headers.cpp 80826 2008-03-04 14:51:23Z wotte $ */
#include "JAWS/Headers.h"
#include "ace/OS_NS_stdlib.h"
#include "ace/OS_NS_strings.h"
#include "ace/OS_NS_string.h"
// Header Data
JAWS_Header_Data::JAWS_Header_Data (const char *name, const char *value,
int type)
: header_name_ (name ? ACE_OS::strdup (name) : 0),
header_value_ (value ? ACE_OS::strdup (value) : 0),
header_type_ (type)
{
}
JAWS_Header_Data::JAWS_Header_Data (const char *name, int type,
const char *value)
: header_name_ (name ? ACE_OS::strdup (name) : 0),
header_value_ (value ? ACE_OS::strdup (value) : 0),
header_type_ (type)
{
}
JAWS_Header_Data::~JAWS_Header_Data (void)
{
if ( this->header_name_ )
ACE_OS::free ((void *)this->header_name_);
if ( this->header_value_ )
ACE_OS::free ((void *)this->header_value_);
this->header_name_ = 0;
this->header_value_ = 0;
}
const char *
JAWS_Header_Data::header_name (void) const
{
return this->header_name_;
}
const char *
JAWS_Header_Data::header_value (void) const
{
return this->header_value_;
}
int
JAWS_Header_Data::header_type (void) const
{
return this->header_type_;
}
void
JAWS_Header_Data::header_name (const char *name)
{
if (this->header_name_)
ACE_OS::free ((void *)this->header_name_);
this->header_name_ = name ? ACE_OS::strdup (name) : 0;
}
void
JAWS_Header_Data::header_value (const char *value)
{
if (this->header_value_)
ACE_OS::free ((void *)this->header_value_);
this->header_value_ = value ? ACE_OS::strdup (value) : 0;
}
void
JAWS_Header_Data::header_type (int type)
{
this->header_type_ = type;
}
// Header Table
JAWS_Headers::JAWS_Headers (void)
: iter_ (*this)
{
}
JAWS_Headers::~JAWS_Headers (void)
{
}
JAWS_Header_Table_Iterator &
JAWS_Headers::iter (void)
{
return this->iter_;
}
int
JAWS_Headers::insert (JAWS_Header_Data *new_data)
{
// Since there may be duplicate header entries, we don't worry about
// doing this find anymore. Make the application developer figure
// out how to interpret duplicate entries.
return (JAWS_Header_Table::insert_tail (new_data) ? 0 : -1);
}
JAWS_Header_Data *
JAWS_Headers::find (const char *const &header_name)
{
this->iter_.first ();
return this->find_next (header_name);
}
JAWS_Header_Data *
JAWS_Headers::find_next (const char *const &header_name)
{
JAWS_Header_Data *data = 0;
JAWS_Header_Table_Iterator &i = this->iter_;
while (! i.done ())
{
data = i.next ();
if (data != 0)
{
if (ACE_OS::strcasecmp (data->header_name (), header_name) != 0)
data = 0;
}
i.advance ();
if (data != 0)
break;
}
return data;
}
void
JAWS_Headers::remove_all (const char *const &header_name)
{
JAWS_Header_Data *data;
int done;
do
{
JAWS_Header_Table_Iterator i (*this);
i.first ();
done = 1;
while (! i.done ())
{
data = i.next ();
if (data != 0
&& ACE_OS::strcasecmp (data->header_name (), header_name) == 0)
{
i.remove ();
delete data;
done = 0;
break;
}
else
i.advance ();
}
}
while (! done);
}
|