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

« back to all changes in this revision

Viewing changes to subversion/bindings/javahl/native/JNIUtil.h

  • 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:
37
37
#include <fstream>
38
38
#include <apr_time.h>
39
39
#include <string>
 
40
#include <vector>
 
41
 
40
42
struct svn_error_t;
41
 
 
42
 
#define JAVA_PACKAGE "org/apache/subversion/javahl"
43
 
 
44
43
struct svn_string_t;
45
44
 
 
45
#include "svn_error.h"
 
46
 
 
47
 
 
48
/**
 
49
 * The name of the package in which the JavaHL classes are defined.
 
50
 */
 
51
#define JAVAHL_PACKAGE "org/apache/subversion/javahl"
 
52
 
 
53
/**
 
54
 * Construct a JavaHL class name for JNIEnv::FindClass.
 
55
 */
 
56
#define JAVAHL_CLASS(name) JAVAHL_PACKAGE name
 
57
 
 
58
/**
 
59
 * Construct a JavaHL class parameter name for JNIEnv::GetMethodID & co.
 
60
 */
 
61
#define JAVAHL_ARG(name) "L" JAVAHL_PACKAGE name
 
62
 
 
63
 
46
64
/**
47
65
 * Class to hold a number of JNI related utility methods.  No Objects
48
66
 * of this class are ever created.
67
85
  static jbyteArray makeJByteArray(const void *data, int length);
68
86
  static jbyteArray makeJByteArray(const svn_string_t *str);
69
87
  static jobject createDate(apr_time_t time);
 
88
  static apr_time_t getDate(jobject jdate);
70
89
  static void logMessage(const char *message);
71
90
  static int getLogLevel();
72
 
  static char *getFormatBuffer();
73
91
  static void initLogFile(int level, jstring path);
74
92
  static jstring makeJString(const char *txt);
75
 
  static bool isJavaExceptionThrown();
76
93
  static JNIEnv *getEnv();
77
 
  static void setEnv(JNIEnv *);
78
94
 
79
95
  /**
80
96
   * @return Whether any Throwable has been raised.
81
97
   */
82
 
  static bool isExceptionThrown();
 
98
  static bool isExceptionThrown() { return isJavaExceptionThrown(); }
 
99
  static bool isJavaExceptionThrown()
 
100
    {
 
101
      return getEnv()->ExceptionCheck();
 
102
    }
 
103
 
 
104
  static svn_error_t *wrapJavaException();
 
105
  static jthrowable unwrapJavaException(const svn_error_t *err);
83
106
 
84
107
  static void handleAPRError(int error, const char *op);
85
108
 
107
130
  static const char *thrownExceptionToCString(SVN::Pool &in_pool);
108
131
 
109
132
  /**
 
133
   * Check if a Java exception was thrown and convert it to a
 
134
   * Subversion error, using @a errorcode as the generic error code.
 
135
   */
 
136
  static svn_error_t* checkJavaException(apr_status_t errorcode);
 
137
 
 
138
  /**
 
139
   * Create a Java exception corresponding to err, and run
 
140
   * svn_error_clear() on err.
 
141
   */
 
142
  static jthrowable createClientException(svn_error_t *err,
 
143
                                          jthrowable jcause = NULL);
 
144
 
 
145
  /**
110
146
   * Throw a Java exception corresponding to err, and run
111
147
   * svn_error_clear() on err.
112
148
   */
113
 
  static void handleSVNError(svn_error_t *err);
 
149
  static void handleSVNError(svn_error_t *err, jthrowable jcause = NULL);
114
150
 
115
 
  static jstring makeSVNErrorMessage(svn_error_t *err);
 
151
  static std::string makeSVNErrorMessage(svn_error_t *err,
 
152
                                         jstring *jerror_message,
 
153
                                         jobject *jmessage_stack);
116
154
 
117
155
  /**
118
156
   * Create and throw a java.lang.Throwable instance.
130
168
   */
131
169
  static void throwError(const char *message)
132
170
    {
133
 
      raiseThrowable(JAVA_PACKAGE"/JNIError", message);
 
171
      raiseThrowable(JAVAHL_CLASS("/JNIError"), message);
134
172
    }
135
173
 
136
174
  static apr_pool_t *getPool();
137
 
  static bool JNIGlobalInit(JNIEnv *env);
138
175
  static bool JNIInit(JNIEnv *env);
139
176
  static bool initializeJNIRuntime();
140
 
  enum { formatBufferSize = 2048 };
141
177
  enum { noLog, errorLog, exceptionLog, entryLog } LogLevel;
142
178
 
 
179
  /**
 
180
   * Mutex that secures the global configuration object.
 
181
   */
 
182
  static JNIMutex *g_configMutex;
 
183
 
143
184
 private:
144
 
  static void wrappedHandleSVNError(svn_error_t *err);
145
 
  static void assembleErrorMessage(svn_error_t *err, int depth,
146
 
                                   apr_status_t parent_apr_err,
147
 
                                   std::string &buffer);
 
185
  friend bool initialize_jni_util(JNIEnv *env);
 
186
  static bool JNIGlobalInit(JNIEnv *env);
 
187
 
 
188
  static jthrowable wrappedCreateClientException(svn_error_t *err,
 
189
                                                 jthrowable jcause);
148
190
  static void putErrorsInTrace(svn_error_t *err,
149
191
                               std::vector<jobject> &stackTrace);
150
 
  /**
151
 
   * Set the appropriate global or thread-local flag that an exception
152
 
   * has been thrown to @a flag.
153
 
   */
154
 
  static void setExceptionThrown(bool flag = true);
155
192
 
156
193
  /**
157
194
   * The log level of this module.
185
222
  static bool g_initException;
186
223
 
187
224
  /**
188
 
   * Flag, that one thread is in the init code.  Cannot use mutex
189
 
   * here since apr is not initialized yet.
190
 
   */
191
 
  static bool g_inInit;
192
 
 
193
 
  /**
194
 
   * The JNI environment used during initialization.
195
 
   */
196
 
  static JNIEnv *g_initEnv;
197
 
 
198
 
  /**
199
 
   * Fuffer the format error messages during initialization.
200
 
   */
201
 
  static char g_initFormatBuffer[formatBufferSize];
202
 
 
203
 
  /**
204
225
   * The stream to write log messages to.
205
226
   */
206
227
  static std::ofstream g_logStream;
270
291
    }                                   \
271
292
  while (0)
272
293
 
 
294
#define POP_AND_RETURN_EXCEPTION_AS_SVNERROR()                            \
 
295
  do                                                                      \
 
296
    {                                                                     \
 
297
      svn_error_t *svn__err_for_exception = JNIUtil::wrapJavaException(); \
 
298
                                                                          \
 
299
      env->PopLocalFrame(NULL);                                           \
 
300
      return svn__err_for_exception;                                      \
 
301
    }                                                                     \
 
302
  while (0)
 
303
 
273
304
 
274
305
/**
275
306
 * A useful macro.
284
315
    }                                                   \
285
316
  } while (0)
286
317
 
 
318
#define SVN_JNI_CATCH(statement, errorcode)             \
 
319
  do {                                                  \
 
320
    do { statement; } while(0);                         \
 
321
    SVN_ERR(JNIUtil::checkJavaException((errorcode)));  \
 
322
  } while(0)
 
323
 
 
324
#define SVN_JNI_CATCH_VOID(statement)                   \
 
325
  do {                                                  \
 
326
    do { statement; } while(0);                         \
 
327
    if (JNIUtil::getEnv()->ExceptionCheck()) {          \
 
328
      JNIUtil::getEnv()->ExceptionClear();              \
 
329
      return;                                           \
 
330
    }                                                   \
 
331
  } while(0)
 
332
 
287
333
#endif  // JNIUTIL_H