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

« back to all changes in this revision

Viewing changes to subversion/bindings/javahl/native/jniwrapper/jni_object.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_JAVAHL_JNIWRAPPER_OBJECT_HPP
 
25
#define SVN_JAVAHL_JNIWRAPPER_OBJECT_HPP
 
26
 
 
27
#include "jni_env.hpp"
 
28
#include "jni_globalref.hpp"
 
29
 
 
30
namespace Java {
 
31
 
 
32
/**
 
33
 * An abstract wrapper for a @c java.lang.Object instance.
 
34
 *
 
35
 * This is the base class for all concrete object wrapper classes. It
 
36
 * is self-contained in the sense that it heeps its own JVM
 
37
 * environment, class and object reference; Java object methods are
 
38
 * expected to be exposed as methods of derived classes.
 
39
 *
 
40
 * The associated JNI class reference is stored for the lifetime of
 
41
 * the JVM in the global class cache.
 
42
 *
 
43
 * @since New in 1.9.
 
44
 */
 
45
class Object
 
46
{
 
47
public:
 
48
  /**
 
49
   * Returns the wrapped JNI object reference.
 
50
   */
 
51
  jobject get() const
 
52
    {
 
53
      return m_jthis;
 
54
    }
 
55
 
 
56
  /**
 
57
   * Returns the wrapped JNI class reference.
 
58
   */
 
59
  jclass get_class() const
 
60
    {
 
61
      return m_impl->get_class();
 
62
    }
 
63
 
 
64
  /**
 
65
   * Returns the wrapped enviromnment reference.
 
66
   */
 
67
  Env get_env() const
 
68
    {
 
69
      return m_env;
 
70
    }
 
71
 
 
72
  /**
 
73
   * This object's implementation details.
 
74
   */
 
75
  class ClassImpl
 
76
  {
 
77
  public:
 
78
    jclass get_class() const
 
79
      {
 
80
        return m_class.get();
 
81
      }
 
82
 
 
83
    virtual ~ClassImpl();
 
84
 
 
85
  protected:
 
86
    explicit ClassImpl(Env env, jclass cls)
 
87
      : m_class(env, cls)
 
88
      {}
 
89
 
 
90
  private:
 
91
    friend class ClassCacheImpl;
 
92
 
 
93
    GlobalClass m_class;  ///< Class reference for this object wrapper
 
94
 
 
95
    // Non-copyable
 
96
    ClassImpl(const ClassImpl&);
 
97
    ClassImpl& operator=(const ClassImpl&);
 
98
  };
 
99
 
 
100
protected:
 
101
  /**
 
102
   * constructs an object wrapper given the class @a impl and an
 
103
   * object reference @a jthis.
 
104
   */
 
105
  Object(Env env, const ClassImpl* impl, jobject jthis = NULL)
 
106
    : m_env(env),
 
107
      m_impl(impl),
 
108
      m_jthis(jthis)
 
109
    {}
 
110
 
 
111
  const Env m_env;               ///< JVM environment wrapper
 
112
  const ClassImpl* const m_impl; ///< Class implementation details
 
113
  const jobject m_jthis;         ///< @c this object reference
 
114
 
 
115
  /**
 
116
   * Certain subclasses need a fully constructed base Object before
 
117
   * they can create the wrapped JNI object. They can use this
 
118
   * function to oveerride the constness of @c m_jthis, but only if
 
119
   * they're changing a @c NULL @c m_jthis to a concrete value.
 
120
   */
 
121
  void set_this(jobject jthis)
 
122
    {
 
123
      if (!m_jthis && jthis)
 
124
        *const_cast<jobject*>(&m_jthis) = jthis;
 
125
    }
 
126
 
 
127
private:
 
128
  friend class ClassCacheImpl;
 
129
  static const char* const m_class_name;
 
130
};
 
131
 
 
132
// Forward declaration
 
133
class ClassCacheImpl;
 
134
 
 
135
/**
 
136
 * A singleton cache for global class references.
 
137
 *
 
138
 * The instance is created when the native library is loaded by the
 
139
 * JVM, and destroyed when it is unloaded. It creates global
 
140
 * references for a number of classes and calls said classes'
 
141
 * single-threded static initializers, which usually find and store
 
142
 * method and field IDs (which are usually only valid until the
 
143
 * associated class is garbage-collected).
 
144
 *
 
145
 * Be aware that as long as the global references exist, these classes
 
146
 * cannot be garbage-collected. The number of classes stored in this
 
147
 * cache should therefore be kept to a reasonable minimum.
 
148
 *
 
149
 * @since New in 1.9.
 
150
 */
 
151
class ClassCache
 
152
{
 
153
  // Cannot create instances of this type.
 
154
  ClassCache();
 
155
  ~ClassCache();
 
156
 
 
157
  static ClassCacheImpl* m_impl;
 
158
 
 
159
public:
 
160
  /* This static initializer must only be called by JNI_OnLoad */
 
161
  static void create();
 
162
 
 
163
  /* This static finalizer must only be called by JNI_OnUnload */
 
164
  static void destroy();
 
165
 
 
166
#define JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(M)     \
 
167
  static const Object::ClassImpl* get_##M(Env env);
 
168
 
 
169
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(object);
 
170
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(classtype);
 
171
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(throwable);
 
172
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(string);
 
173
 
 
174
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(exc_index_out_of_bounds);
 
175
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(exc_no_such_element);
 
176
 
 
177
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(list);
 
178
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(array_list);
 
179
 
 
180
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(map);
 
181
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(set);
 
182
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(iterator);
 
183
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(map_entry);
 
184
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(hash_map);
 
185
 
 
186
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(input_stream);
 
187
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(output_stream);
 
188
 
 
189
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(byte_buffer);
 
190
 
 
191
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(subversion_exception);
 
192
 
 
193
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(authn_cb);
 
194
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(authn_result);
 
195
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(authn_ssl_server_cert_failures);
 
196
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(authn_ssl_server_cert_info);
 
197
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(user_passwd_cb);
 
198
 
 
199
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(credential);
 
200
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(credential_kind);
 
201
 
 
202
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(external_item);
 
203
 
 
204
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(editor_provide_base_cb);
 
205
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(editor_provide_base_cb_ret);
 
206
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(editor_provide_props_cb);
 
207
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(editor_provide_props_cb_ret);
 
208
  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(editor_get_kind_cb);
 
209
#undef JNIWRAPPER_DECLARE_CACHED_CLASS
 
210
};
 
211
 
 
212
 
 
213
/**
 
214
 * Object wrapper for @c java.lang.Class.
 
215
 *
 
216
 * The associated JNI class reference is stored for the lifetime of
 
217
 * the JVM in the global class cache.
 
218
 *
 
219
 * @since New in 1.9.
 
220
 */
 
221
class Class
 
222
{
 
223
public:
 
224
  /**
 
225
   * Constructs class instance wrapper for @a obj.
 
226
   */
 
227
  explicit Class(Env env, jobject obj);
 
228
 
 
229
  /**
 
230
   * Constructs class instance wrapper for @a obj.
 
231
   */
 
232
  explicit Class(const Object& obj);
 
233
 
 
234
  /**
 
235
   * Wrapper for the Java @c getName() method.
 
236
   */
 
237
  jstring get_name() const;
 
238
 
 
239
  /**
 
240
   * Returns the wrapped class instance.
 
241
   */
 
242
  jobject get() const
 
243
    {
 
244
      return m_jthis;
 
245
    }
 
246
 
 
247
  /**
 
248
   * Returns the wrapped enviromnment reference.
 
249
   */
 
250
  Env get_env() const
 
251
    {
 
252
      return m_env;
 
253
    }
 
254
 
 
255
private:
 
256
  /**
 
257
   * This object's implementation details.
 
258
   */
 
259
  class ClassImpl : public Object::ClassImpl
 
260
  {
 
261
    friend class ClassCacheImpl;
 
262
 
 
263
  protected:
 
264
    explicit ClassImpl(Env env, jclass cls)
 
265
      : Object::ClassImpl(env, cls)
 
266
      {}
 
267
 
 
268
  public:
 
269
    virtual ~ClassImpl();
 
270
  };
 
271
 
 
272
  const Env m_env;        ///< JVM environment wrapper
 
273
  const jobject m_jthis;  ///< Class instance
 
274
 
 
275
  friend class ClassCacheImpl;
 
276
  static const char* const m_class_name;
 
277
  static void static_init(Env env, jclass class_type);
 
278
 
 
279
  static MethodID m_mid_get_class;
 
280
  static MethodID m_mid_get_name;
 
281
};
 
282
 
 
283
} // namespace Java
 
284
 
 
285
#endif // SVN_JAVAHL_JNIWRAPPER_OBJECT_HPP