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

« back to all changes in this revision

Viewing changes to subversion/bindings/javahl/native/org_apache_subversion_javahl_util_ConfigImpl_Category.cpp

  • 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
 * @file org_apache_subversion_javahl_util_ConfigImpl_Category.cpp
 
24
 * @brief Implementation of the native methods in the Java class
 
25
 *        util.ConfigImpl.Category.
 
26
 */
 
27
 
 
28
#include <string>
 
29
#include <vector>
 
30
 
 
31
#include "../include/org_apache_subversion_javahl_util_ConfigImpl_Category.h"
 
32
#include "JNIUtil.h"
 
33
#include "JNIStackElement.h"
 
34
#include "JNIStringHolder.h"
 
35
#include "OperationContext.h"
 
36
#include "CreateJ.h"
 
37
#include "EnumMapper.h"
 
38
 
 
39
#include "svn_config.h"
 
40
#include "svn_hash.h"
 
41
#include "svn_private_config.h"
 
42
 
 
43
namespace {
 
44
struct ImplContext
 
45
{
 
46
  ImplContext(JNIEnv* env, jobject jthis,
 
47
              jstring jcategory, jlong jcontext,
 
48
              jstring jsection, jstring joption) : m_config(NULL)
 
49
    {
 
50
      OperationContext* const context(
 
51
          reinterpret_cast<OperationContext*>(jcontext));
 
52
      CPPADDR_NULL_PTR(context,);
 
53
 
 
54
      JNIStringHolder category(jcategory);
 
55
      if (JNIUtil::isJavaExceptionThrown())
 
56
        return;
 
57
      if (category.c_str())
 
58
        {
 
59
          apr_hash_t* cfgdata = context->getConfigData();
 
60
          if (cfgdata)
 
61
            m_config = static_cast<svn_config_t*>(
 
62
                svn_hash_gets(cfgdata, category.c_str()));
 
63
          else
 
64
            JNIUtil::throwNullPointerException("getConfigData");
 
65
        }
 
66
      if (!m_config)
 
67
        JNIUtil::throwNullPointerException("category");
 
68
 
 
69
      JNIStringHolder section(jsection);
 
70
      if (JNIUtil::isJavaExceptionThrown())
 
71
        return;
 
72
      if (section.c_str())
 
73
        m_section = section.c_str();
 
74
 
 
75
      JNIStringHolder option(joption);
 
76
      if (JNIUtil::isJavaExceptionThrown())
 
77
        return;
 
78
      if (option.c_str())
 
79
        m_option = option.c_str();
 
80
    }
 
81
 
 
82
  svn_config_t* m_config;
 
83
  std::string m_section;
 
84
  std::string m_option;
 
85
};
 
86
} // anonymous namespace
 
87
 
 
88
 
 
89
 
 
90
JNIEXPORT jstring JNICALL
 
91
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_get_1str(
 
92
    JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext,
 
93
    jstring jsection, jstring joption, jstring jdefault_value)
 
94
{
 
95
  JNIEntry(ConfigImpl$Category, get_str);
 
96
  const ImplContext ctx(env, jthis, jcategory, jcontext, jsection, joption);
 
97
 
 
98
  JNIStringHolder default_value(jdefault_value);
 
99
  if (JNIUtil::isJavaExceptionThrown())
 
100
    return NULL;
 
101
 
 
102
  const char* value;
 
103
  svn_config_get(ctx.m_config, &value,
 
104
                 ctx.m_section.c_str(), ctx.m_option.c_str(),
 
105
                 default_value.c_str());
 
106
  return JNIUtil::makeJString(value);
 
107
}
 
108
 
 
109
JNIEXPORT jboolean JNICALL
 
110
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_get_1bool(
 
111
    JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext,
 
112
    jstring jsection, jstring joption, jboolean jdefault_value)
 
113
{
 
114
  JNIEntry(ConfigImpl$Category, get_bool);
 
115
  const ImplContext ctx(env, jthis, jcategory, jcontext, jsection, joption);
 
116
 
 
117
  svn_boolean_t value;
 
118
  SVN_JNI_ERR(svn_config_get_bool(ctx.m_config, &value,
 
119
                                  ctx.m_section.c_str(), ctx.m_option.c_str(),
 
120
                                  bool(jdefault_value)),
 
121
              jdefault_value);
 
122
  return jboolean(value);
 
123
}
 
124
 
 
125
JNIEXPORT jlong JNICALL
 
126
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_get_1long(
 
127
    JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext,
 
128
    jstring jsection, jstring joption, jlong jdefault_value)
 
129
{
 
130
  JNIEntry(ConfigImpl$Category, get_long);
 
131
  const ImplContext ctx(env, jthis, jcategory, jcontext, jsection, joption);
 
132
 
 
133
  apr_int64_t value;
 
134
  SVN_JNI_ERR(svn_config_get_int64(ctx.m_config, &value,
 
135
                                   ctx.m_section.c_str(), ctx.m_option.c_str(),
 
136
                                   apr_int64_t(jdefault_value)),
 
137
              jdefault_value);
 
138
  return jlong(value);
 
139
}
 
140
 
 
141
JNIEXPORT jobject JNICALL
 
142
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_get_1tri(
 
143
    JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext,
 
144
    jstring jsection, jstring joption,
 
145
    jstring junknown, jobject jdefault_value)
 
146
{
 
147
  JNIEntry(ConfigImpl$Category, get_tri);
 
148
  const ImplContext ctx(env, jthis, jcategory, jcontext, jsection, joption);
 
149
 
 
150
  JNIStringHolder unknown(junknown);
 
151
  if (JNIUtil::isJavaExceptionThrown())
 
152
    return NULL;
 
153
 
 
154
  svn_tristate_t value;
 
155
  SVN_JNI_ERR(svn_config_get_tristate(ctx.m_config, &value,
 
156
                                      ctx.m_section.c_str(),
 
157
                                      ctx.m_option.c_str(),
 
158
                                      unknown.c_str(),
 
159
                                      EnumMapper::toTristate(jdefault_value)),
 
160
              NULL);
 
161
  return EnumMapper::mapTristate(value);
 
162
}
 
163
 
 
164
JNIEXPORT jstring JNICALL
 
165
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_get_1yna(
 
166
    JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext,
 
167
    jstring jsection, jstring joption, jstring jdefault_value)
 
168
{
 
169
  JNIEntry(ConfigImpl$Category, get_yna);
 
170
  const ImplContext ctx(env, jthis, jcategory, jcontext, jsection, joption);
 
171
 
 
172
  JNIStringHolder default_value(jdefault_value);
 
173
  if (JNIUtil::isJavaExceptionThrown())
 
174
    return NULL;
 
175
 
 
176
  const char* value;
 
177
  SVN_JNI_ERR(svn_config_get_yes_no_ask(
 
178
                  ctx.m_config, &value,
 
179
                  ctx.m_section.c_str(), ctx.m_option.c_str(),
 
180
                  default_value.c_str()),
 
181
              NULL);
 
182
  return JNIUtil::makeJString(value);
 
183
}
 
184
 
 
185
JNIEXPORT void JNICALL
 
186
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_set_1str(
 
187
    JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext,
 
188
    jstring jsection, jstring joption, jstring jvalue)
 
189
{
 
190
  JNIEntry(ConfigImpl$Category, set_str);
 
191
  const ImplContext ctx(env, jthis, jcategory, jcontext, jsection, joption);
 
192
 
 
193
  JNIStringHolder value(jvalue);
 
194
  if (JNIUtil::isJavaExceptionThrown())
 
195
    return;
 
196
 
 
197
  svn_config_set(ctx.m_config,
 
198
                 ctx.m_section.c_str(), ctx.m_option.c_str(),
 
199
                 value.c_str());
 
200
}
 
201
 
 
202
JNIEXPORT void JNICALL
 
203
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_set_1bool(
 
204
    JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext,
 
205
    jstring jsection, jstring joption, jboolean jvalue)
 
206
{
 
207
  JNIEntry(ConfigImpl$Category, set_bool);
 
208
  const ImplContext ctx(env, jthis, jcategory, jcontext, jsection, joption);
 
209
 
 
210
  svn_config_set_bool(ctx.m_config,
 
211
                      ctx.m_section.c_str(), ctx.m_option.c_str(),
 
212
                      bool(jvalue));
 
213
}
 
214
 
 
215
JNIEXPORT void JNICALL
 
216
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_set_1long(
 
217
    JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext,
 
218
    jstring jsection, jstring joption, jlong jvalue)
 
219
{
 
220
  JNIEntry(ConfigImpl$Category, set_long);
 
221
  const ImplContext ctx(env, jthis, jcategory, jcontext, jsection, joption);
 
222
 
 
223
  svn_config_set_int64(ctx.m_config,
 
224
                       ctx.m_section.c_str(), ctx.m_option.c_str(),
 
225
                       apr_int64_t(jvalue));
 
226
}
 
227
 
 
228
JNIEXPORT jobject JNICALL
 
229
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_sections(
 
230
    JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext)
 
231
{
 
232
  JNIEntry(ConfigImpl$Category, sections);
 
233
  const ImplContext ctx(env, jthis, jcategory, jcontext, NULL, NULL);
 
234
 
 
235
  struct enumerator_t
 
236
  {
 
237
    static svn_boolean_t process(const char* name, void* baton,
 
238
                                 apr_pool_t *pool)
 
239
      {
 
240
        jstring jname = JNIUtil::makeJString(name);
 
241
        if (JNIUtil::isJavaExceptionThrown())
 
242
          return false;
 
243
        static_cast<enumerator_t*>(baton)
 
244
          ->m_sections.push_back(jobject(jname));
 
245
        return true;
 
246
      }
 
247
    std::vector<jobject> m_sections;
 
248
  } enumerator;
 
249
 
 
250
  SVN::Pool requestPool;
 
251
  svn_config_enumerate_sections2(ctx.m_config, enumerator.process, &enumerator,
 
252
                                 requestPool.getPool());
 
253
  if (JNIUtil::isJavaExceptionThrown())
 
254
    return NULL;
 
255
  return CreateJ::Set(enumerator.m_sections);
 
256
}
 
257
 
 
258
JNIEXPORT void JNICALL
 
259
Java_org_apache_subversion_javahl_util_ConfigImpl_00024Category_enumerate(
 
260
    JNIEnv* env, jobject jthis, jstring jcategory, jlong jcontext,
 
261
    jstring jsection, jobject jhandler)
 
262
{
 
263
  JNIEntry(ConfigImpl$Category, sections);
 
264
  const ImplContext ctx(env, jthis, jcategory, jcontext, jsection, NULL);
 
265
 
 
266
  struct enumerator_t
 
267
  {
 
268
    static svn_boolean_t process(const char* name, const char* value,
 
269
                                 void* baton, apr_pool_t *pool)
 
270
      {
 
271
        enumerator_t* enmr = static_cast<enumerator_t*>(baton);
 
272
        JNIEnv* const e = enmr->m_env;
 
273
        const jobject jh = enmr->m_jhandler;;
 
274
 
 
275
        static jmethodID mid = 0;
 
276
        if (0 == mid)
 
277
          {
 
278
            jclass cls = e->FindClass(JAVAHL_CLASS("/ISVNConfig$Enumerator"));
 
279
            if (JNIUtil::isJavaExceptionThrown())
 
280
              return false;
 
281
            mid = e->GetMethodID(cls, "option",
 
282
                                   "(Ljava/lang/String;Ljava/lang/String;)V");
 
283
            if (JNIUtil::isJavaExceptionThrown())
 
284
              return false;
 
285
          }
 
286
 
 
287
        jstring jname = JNIUtil::makeJString(name);
 
288
        if (JNIUtil::isJavaExceptionThrown())
 
289
          return false;
 
290
        jstring jvalue = JNIUtil::makeJString(value);
 
291
        if (JNIUtil::isJavaExceptionThrown())
 
292
          return false;
 
293
 
 
294
        e->CallVoidMethod(jh, mid, jname, jvalue);
 
295
        if (JNIUtil::isJavaExceptionThrown())
 
296
          return false;
 
297
 
 
298
        e->DeleteLocalRef(jname);
 
299
        e->DeleteLocalRef(jvalue);
 
300
        return true;
 
301
      }
 
302
 
 
303
    JNIEnv* m_env;
 
304
    jobject m_jhandler;
 
305
  } enumerator;
 
306
 
 
307
  enumerator.m_env = env;
 
308
  enumerator.m_jhandler = jhandler;
 
309
 
 
310
  SVN::Pool requestPool;
 
311
  svn_config_enumerate2(ctx.m_config, ctx.m_section.c_str(),
 
312
                        enumerator.process, &enumerator,
 
313
                        requestPool.getPool());
 
314
}