Merge branch 'master' into jwi-bcc64xsingletonwarning
[ACE_TAO.git] / ACE / apps / JAWS2 / JAWS / Headers.cpp
blob6ffc759b130b0fb11c150e197594b95bc819719c
1 #include "JAWS/Headers.h"
2 #include "ace/OS_NS_stdlib.h"
3 #include "ace/OS_NS_strings.h"
4 #include "ace/OS_NS_string.h"
6 // Header Data
8 JAWS_Header_Data::JAWS_Header_Data (const char *name, const char *value,
9 int type)
10 : header_name_ (name ? ACE_OS::strdup (name) : 0),
11 header_value_ (value ? ACE_OS::strdup (value) : 0),
12 header_type_ (type)
16 JAWS_Header_Data::JAWS_Header_Data (const char *name, int type,
17 const char *value)
18 : header_name_ (name ? ACE_OS::strdup (name) : 0),
19 header_value_ (value ? ACE_OS::strdup (value) : 0),
20 header_type_ (type)
24 JAWS_Header_Data::~JAWS_Header_Data ()
26 if ( this->header_name_ )
27 ACE_OS::free ((void *)this->header_name_);
28 if ( this->header_value_ )
29 ACE_OS::free ((void *)this->header_value_);
30 this->header_name_ = 0;
31 this->header_value_ = 0;
34 const char *
35 JAWS_Header_Data::header_name () const
37 return this->header_name_;
40 const char *
41 JAWS_Header_Data::header_value () const
43 return this->header_value_;
46 int
47 JAWS_Header_Data::header_type () const
49 return this->header_type_;
52 void
53 JAWS_Header_Data::header_name (const char *name)
55 if (this->header_name_)
56 ACE_OS::free ((void *)this->header_name_);
57 this->header_name_ = name ? ACE_OS::strdup (name) : 0;
60 void
61 JAWS_Header_Data::header_value (const char *value)
63 if (this->header_value_)
64 ACE_OS::free ((void *)this->header_value_);
65 this->header_value_ = value ? ACE_OS::strdup (value) : 0;
68 void
69 JAWS_Header_Data::header_type (int type)
71 this->header_type_ = type;
75 // Header Table
77 JAWS_Headers::JAWS_Headers ()
78 : iter_ (*this)
82 JAWS_Headers::~JAWS_Headers ()
86 JAWS_Header_Table_Iterator &
87 JAWS_Headers::iter ()
89 return this->iter_;
92 int
93 JAWS_Headers::insert (JAWS_Header_Data *new_data)
95 // Since there may be duplicate header entries, we don't worry about
96 // doing this find anymore. Make the application developer figure
97 // out how to interpret duplicate entries.
99 return (JAWS_Header_Table::insert_tail (new_data) ? 0 : -1);
102 JAWS_Header_Data *
103 JAWS_Headers::find (const char *const &header_name)
105 this->iter_.first ();
106 return this->find_next (header_name);
109 JAWS_Header_Data *
110 JAWS_Headers::find_next (const char *const &header_name)
112 JAWS_Header_Data *data = 0;
113 JAWS_Header_Table_Iterator &i = this->iter_;
115 while (! i.done ())
117 data = i.next ();
118 if (data != 0)
120 if (ACE_OS::strcasecmp (data->header_name (), header_name) != 0)
121 data = 0;
123 i.advance ();
124 if (data != 0)
125 break;
128 return data;
131 void
132 JAWS_Headers::remove_all (const char *const &header_name)
134 JAWS_Header_Data *data;
135 int done;
139 JAWS_Header_Table_Iterator i (*this);
140 i.first ();
141 done = 1;
142 while (! i.done ())
144 data = i.next ();
145 if (data != 0
146 && ACE_OS::strcasecmp (data->header_name (), header_name) == 0)
148 i.remove ();
149 delete data;
150 done = 0;
151 break;
153 else
154 i.advance ();
157 while (! done);