~ubuntu-branches/debian/sid/subversion/sid

« back to all changes in this revision

Viewing changes to subversion/bindings/cxxhl/src/aprwrap/array.hpp

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2015-08-07 21:32:47 UTC
  • mfrom: (0.2.15) (4.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20150807213247-ozyewtmgsr6tkewl
Tags: 1.9.0-1
* Upload to unstable
* New upstream release.
  + Security fixes
    - CVE-2015-3184: Mixed anonymous/authenticated path-based authz with
      httpd 2.4
    - CVE-2015-3187: svn_repos_trace_node_locations() reveals paths hidden
      by authz
* Add >= 2.7 requirement for python-all-dev Build-Depends, needed to run
  tests.
* Remove Build-Conflicts against ruby-test-unit.  (Closes: #791844)
* Remove patches/apache_module_dependency in favor of expressing the
  dependencies in authz_svn.load/dav_svn.load.
* Build-Depend on apache2-dev (>= 2.4.16) to ensure ap_some_authn_required()
  is available when building mod_authz_svn and Depend on apache2-bin (>=
  2.4.16) for runtime support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @copyright
 
3
 * ====================================================================
 
4
 *    Licensed to the Apache Software Foundation (ASF) under one
 
5
 *    or more contributor license agreements.  See the NOTICE file
 
6
 *    distributed with this work for additional information
 
7
 *    regarding copyright ownership.  The ASF licenses this file
 
8
 *    to you under the Apache License, Version 2.0 (the
 
9
 *    "License"); you may not use this file except in compliance
 
10
 *    with the License.  You may obtain a copy of the License at
 
11
 *
 
12
 *      http://www.apache.org/licenses/LICENSE-2.0
 
13
 *
 
14
 *    Unless required by applicable law or agreed to in writing,
 
15
 *    software distributed under the License is distributed on an
 
16
 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 
17
 *    KIND, either express or implied.  See the License for the
 
18
 *    specific language governing permissions and limitations
 
19
 *    under the License.
 
20
 * ====================================================================
 
21
 * @endcopyright
 
22
 */
 
23
 
 
24
#ifndef SVN_CXXHL_PRIVATE_APRWRAP_ARRAY_H
 
25
#define SVN_CXXHL_PRIVATE_APRWRAP_ARRAY_H
 
26
 
 
27
#include <stdexcept>
 
28
 
 
29
#include <apr_tables.h>
 
30
#include "pool.hpp"
 
31
 
 
32
#include "svn_private_config.h"
 
33
 
 
34
namespace apache {
 
35
namespace subversion {
 
36
namespace cxxhl {
 
37
namespace apr {
 
38
 
 
39
/**
 
40
 * Proxy for an APR array.
 
41
 *
 
42
 * This class does not own the array. The array's lifetime is tied to
 
43
 * its pool. The caller is responsible for making sure that the
 
44
 * array's lifetime is longer than this proxy object's.
 
45
 */
 
46
template<typename T> class Array
 
47
{
 
48
public:
 
49
  typedef T value_type;
 
50
  typedef int size_type;
 
51
 
 
52
  /**
 
53
   * Create and proxy a new APR array allocated from @a pool.
 
54
   * Reserve space for @a nelts array elements.
 
55
   */
 
56
  explicit Array(const Pool& pool, size_type nelts = 0) throw()
 
57
    : m_array(apr_array_make(pool.get(), nelts, sizeof(value_type)))
 
58
    {}
 
59
 
 
60
  /**
 
61
   * Create a new proxy for the APR array @a array.
 
62
   */
 
63
  explicit Array(apr_array_header_t* array)
 
64
    : m_array(array)
 
65
    {
 
66
      if (m_array->elt_size != sizeof(value_type))
 
67
        throw std::invalid_argument(
 
68
            _("APR array element size does not match template parameter"));
 
69
    }
 
70
 
 
71
  /**
 
72
   * @return The wrapped APR array.
 
73
   */
 
74
  apr_array_header_t* array() const throw()
 
75
    {
 
76
      return m_array;
 
77
    }
 
78
 
 
79
  /**
 
80
   * @return the number of elements in the wrapped APR array.
 
81
   */
 
82
  size_type size() const throw()
 
83
    {
 
84
      return m_array->nelts;
 
85
    }
 
86
 
 
87
  /**
 
88
   * @return An immutable reference to the array element at @a index.
 
89
   */
 
90
  const value_type& operator[](size_type index) const throw()
 
91
    {
 
92
      return APR_ARRAY_IDX(m_array, index, value_type);
 
93
    }
 
94
 
 
95
  /**
 
96
   * @return An immutable reference to the array element at @a index.
 
97
   * Like operator[] but perfoms a range check on the index.
 
98
   */
 
99
  const value_type& at(size_type index) const
 
100
    {
 
101
      if (index < 0 || index >= size())
 
102
        throw std::out_of_range(_("APR array index is out of range"));
 
103
      return (*this)[index];
 
104
    }
 
105
 
 
106
  /**
 
107
   * @return A mutable reference to the array element at @a index.
 
108
   */
 
109
  value_type& operator[](size_type index) throw()
 
110
    {
 
111
      return APR_ARRAY_IDX(m_array, index, value_type);
 
112
    }
 
113
 
 
114
  /**
 
115
   * @return A mutable reference to the array element at @a index.
 
116
   * Like operator[] but perfoms a range check on the index.
 
117
   */
 
118
  value_type& at(size_type index)
 
119
    {
 
120
      if (index < 0 || index >= size())
 
121
        throw std::out_of_range(_("APR array index is out of range"));
 
122
      return (*this)[index];
 
123
    }
 
124
 
 
125
  /**
 
126
   * Push @a value onto the end of the APR array.
 
127
   */
 
128
  void push(const value_type& value) throw()
 
129
    {
 
130
      APR_ARRAY_PUSH(m_array, value_type) = value;
 
131
    }
 
132
 
 
133
  /**
 
134
   * Pop a value from the end of the array.
 
135
   * @return A pointer to the value that was removed, or @c NULL if
 
136
   * the array was empty.
 
137
   */
 
138
  value_type* pop() throw()
 
139
    {
 
140
      return static_cast<value_type*>(apr_array_pop(m_array));
 
141
    }
 
142
 
 
143
  /**
 
144
   * Abstract base class for mutable iteration callback functors.
 
145
   */
 
146
  struct Iteration
 
147
  {
 
148
    /**
 
149
     * Called by Array::iterate for every value in the array.
 
150
     * @return @c false to terminate the iteration, @c true otherwise.
 
151
     */
 
152
    virtual bool operator() (value_type& value) = 0;
 
153
  };
 
154
 
 
155
  /**
 
156
   * Iterate over all the values pairs in the array, invoking
 
157
   * @a callback for each one.
 
158
   */
 
159
  void iterate(Iteration& callback)
 
160
    {
 
161
      for (size_type n = 0; n < size(); ++n)
 
162
        if (!callback((*this)[n]))
 
163
          break;
 
164
    }
 
165
 
 
166
  /**
 
167
   * Abstract base class for immutable iteration callback functors.
 
168
   */
 
169
  struct ConstIteration
 
170
  {
 
171
    /**
 
172
     * Called by Array::iterate for every value in the array.
 
173
     * @return @c false to terminate the iteration, @c true otherwise.
 
174
     */
 
175
    virtual bool operator() (const value_type& value) = 0;
 
176
  };
 
177
 
 
178
  /**
 
179
   * Iterate over all the values pairs in the array, invoking
 
180
   * @a callback for each one.
 
181
   */
 
182
  void iterate(ConstIteration& callback) const
 
183
    {
 
184
      for (size_type n = 0; n < size(); ++n)
 
185
        if (!callback((*this)[n]))
 
186
          break;
 
187
    }
 
188
 
 
189
private:
 
190
  apr_array_header_t* const m_array; ///< The wrapperd APR array.
 
191
};
 
192
 
 
193
 
 
194
/**
 
195
 * Proxy for an immutable APR array.
 
196
 */
 
197
template<typename T>
 
198
class ConstArray : private Array<T>
 
199
{
 
200
  typedef Array<T> inherited;
 
201
 
 
202
public:
 
203
  typedef typename inherited::value_type value_type;
 
204
  typedef typename inherited::size_type size_type;
 
205
 
 
206
  /**
 
207
   * Create a new proxy for the APR array wrapped by @a that.
 
208
   */
 
209
  ConstArray(const ConstArray& that) throw()
 
210
    : inherited(that)
 
211
    {}
 
212
 
 
213
  /**
 
214
   * Create a new proxy for the APR array wrapped by @a that.
 
215
   */
 
216
  explicit ConstArray(const inherited& that) throw()
 
217
    : inherited(that)
 
218
    {}
 
219
 
 
220
  /**
 
221
   * Create a new proxy for the APR array @a array.
 
222
   */
 
223
  explicit ConstArray(const apr_array_header_t* array)
 
224
    : inherited(const_cast<apr_array_header_t*>(array))
 
225
    {}
 
226
 
 
227
  /**
 
228
   * @return The wrapped APR array.
 
229
   */
 
230
  const apr_array_header_t* array() const throw()
 
231
    {
 
232
      return inherited::array();
 
233
    }
 
234
 
 
235
  /**
 
236
   * @return The number of elements in the wrapped APR array.
 
237
   */
 
238
  size_type size() const throw()
 
239
    {
 
240
      return inherited::size();
 
241
    }
 
242
 
 
243
  /**
 
244
   * @return An immutable reference to the array element at @a index.
 
245
   */
 
246
  const value_type& operator[](size_type index) const throw()
 
247
    {
 
248
      return inherited::operator[](index);
 
249
    }
 
250
 
 
251
  /**
 
252
   * @return An immutable reference to the array element at @a index.
 
253
   * Like operator[] but perfoms a range check on the index.
 
254
   */
 
255
  const value_type& at(size_type index) const
 
256
    {
 
257
      return inherited::at(index);
 
258
    }
 
259
 
 
260
  /**
 
261
   * Abstract base class for immutable iteration callback functors.
 
262
   */
 
263
  typedef typename inherited::ConstIteration Iteration;
 
264
 
 
265
  /**
 
266
   * Iterate over all the values pairs in the array, invoking
 
267
   * @a callback for each one.
 
268
   */
 
269
  void iterate(Iteration& callback) const
 
270
    {
 
271
      inherited::iterate(callback);
 
272
    }
 
273
};
 
274
 
 
275
} // namespace apr
 
276
} // namespace cxxhl
 
277
} // namespace subversion
 
278
} // namespace apache
 
279
 
 
280
#endif // SVN_CXXHL_PRIVATE_APRWRAP_HASH_H