summaryrefslogtreecommitdiff
path: root/protocols/ace/INet/HeaderBase.inl
blob: a6661081b48cc36aee2946ef8f9973976ecd4105 (plain)
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
// -*- C++ -*-
//
// $Id$

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

namespace ACE
{
  namespace INet
  {

    ACE_INLINE
    int HeaderBase::get_content_length() const
      {
        ACE_CString lenstr;
        if (this->get (CONTENT_LENGTH, lenstr))
          {
            return ACE_OS::atoi (lenstr.c_str ());
          }
        return UNKNOWN_CONTENT_LENGTH;
      }

    ACE_INLINE
    void HeaderBase::set_content_type(const ACE_CString& mime_type)
      {
        if (mime_type == UNKNOWN_CONTENT_TYPE)
          {
            this->remove (CONTENT_TYPE);
          }
        else
          {
            this->set (CONTENT_TYPE, UNKNOWN_CONTENT_TYPE);
          }
      }

    ACE_INLINE
    ACE_CString HeaderBase::get_content_type() const
      {
        ACE_CString val = UNKNOWN_CONTENT_TYPE;
        this->get (CONTENT_TYPE, val);
        return val;
      }

    ACE_INLINE
    void HeaderBase::clear ()
      {
        this->header_values_.reset ();
      }

    ACE_INLINE
    void HeaderBase::add (const ACE_CString& name, const ACE_CString& value)
      {
        this->header_values_.insert (NVPair (name, value));
      }

    ACE_INLINE
    void HeaderBase::remove (const ACE_CString& name)
      {
        this->header_values_.remove (NVPair (name, EMPTY));
      }

    ACE_INLINE
    bool HeaderBase::get (const ACE_CString& name, ACE_CString& value) const
      {
        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;
      }

    ACE_INLINE
    bool HeaderBase::has (const ACE_CString& name) const
      {
        TNVMap::ITERATOR it (const_cast<TNVMap&> (this->header_values_));
        if (this->header_values_.find (NVPair (name), it) == 0)
          {
            return true;
          }
        return false;
      }

    ACE_INLINE
    int HeaderBase::read_field (std::istream& str, ACE_CString& var, size_t maxlen, char delim)
      {
        int ch = str.get ();
        while (ch != eof_ && ch != delim && ch != '\n' && var.length () < maxlen)
          {
            var += ch;
            ch = str.get ();
          }
        return ch;
      }

    ACE_INLINE
    int HeaderBase::read_ws_field (std::istream& str, ACE_CString& var, size_t maxlen)
      {
        int ch = str.get ();
        while (!ACE_OS::ace_isspace (ch) && ch != eof_ && var.length () < maxlen)
          {
            var += ch;
            ch = str.get ();
          }
        return ch;
      }

    ACE_INLINE
    NVPair& NVPair::operator =(const NVPair& pair)
      {
        this->first (pair.first ());
        this->second (pair.second ());
        return *this;
      }

    ACE_INLINE
    bool NVPair::operator ==(const NVPair& pair) const
      {
        return this->first_ == pair.first ();
      }

    ACE_INLINE
    bool NVPair::operator <(const NVPair& pair) const
      {
        return this->first_ < pair.first ();
      }

    ACE_INLINE
    const ACE_CString& NVPair::first (void) const
      {
        return this->first_;
      }

    ACE_INLINE
    void NVPair::first (const ACE_CString& t1)
      {
        this->first_ = t1;
      }

    ACE_INLINE
    const ACE_CString& NVPair::second (void) const
      {
        return this->second_;
      }

    ACE_INLINE
    void NVPair::second (const ACE_CString& t2)
      {
        this->second_ = t2;
      }

  }
}

ACE_END_VERSIONED_NAMESPACE_DECL