OLD | NEW |
| (Empty) |
1 /* Licensed to the Apache Software Foundation (ASF) under one or more | |
2 * contributor license agreements. See the NOTICE file distributed with | |
3 * this work for additional information regarding copyright ownership. | |
4 * The ASF licenses this file to You under the Apache License, Version 2.0 | |
5 * (the "License"); you may not use this file except in compliance with | |
6 * the License. You may obtain a copy of the License at | |
7 * | |
8 * http://www.apache.org/licenses/LICENSE-2.0 | |
9 * | |
10 * Unless required by applicable law or agreed to in writing, software | |
11 * distributed under the License is distributed on an "AS IS" BASIS, | |
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 * See the License for the specific language governing permissions and | |
14 * limitations under the License. | |
15 */ | |
16 | |
17 /* | |
18 * | |
19 * @author Mladen Turk | |
20 * @version $Id: misc.c 1442587 2013-02-05 13:49:48Z rjung $ | |
21 */ | |
22 | |
23 #include "tcn.h" | |
24 #include "apr_time.h" | |
25 | |
26 TCN_IMPLEMENT_CALL(void, Time, sleep)(TCN_STDARGS, jlong t) | |
27 { | |
28 | |
29 UNREFERENCED_STDARGS; | |
30 apr_sleep((apr_interval_time_t)t); | |
31 } | |
32 | |
33 TCN_IMPLEMENT_CALL(jint, OS, random)(TCN_STDARGS, jbyteArray buf, | |
34 jint len) | |
35 { | |
36 #if APR_HAS_RANDOM | |
37 apr_status_t rv; | |
38 jbyte *b = (*e)->GetPrimitiveArrayCritical(e, buf, NULL); | |
39 | |
40 UNREFERENCED(o); | |
41 if ((rv = apr_generate_random_bytes((unsigned char *)b, | |
42 (apr_size_t)len)) == APR_SUCCESS) | |
43 (*e)->ReleasePrimitiveArrayCritical(e, buf, b, 0); | |
44 else | |
45 (*e)->ReleasePrimitiveArrayCritical(e, buf, b, JNI_ABORT); | |
46 | |
47 if ((*e)->ExceptionCheck(e)) { | |
48 (*e)->ExceptionClear(e); | |
49 rv = APR_EGENERAL; | |
50 } | |
51 return (jint)rv; | |
52 #else | |
53 return APR_ENOTIMPL; | |
54 #endif | |
55 } | |
56 | |
57 TCN_IMPLEMENT_CALL(jlong, Time, now)(TCN_STDARGS) | |
58 { | |
59 UNREFERENCED_STDARGS; | |
60 return (jlong)apr_time_now(); | |
61 } | |
62 | |
63 TCN_IMPLEMENT_CALL(jstring, Time, rfc822)(TCN_STDARGS, jlong t) | |
64 { | |
65 char ts[APR_RFC822_DATE_LEN]; | |
66 UNREFERENCED(o); | |
67 if (apr_rfc822_date(ts, J2T(t)) == APR_SUCCESS) | |
68 return AJP_TO_JSTRING(ts); | |
69 else | |
70 return NULL; | |
71 } | |
72 | |
73 TCN_IMPLEMENT_CALL(jstring, Time, ctime)(TCN_STDARGS, jlong t) | |
74 { | |
75 char ts[APR_CTIME_LEN]; | |
76 UNREFERENCED(o); | |
77 if (apr_ctime(ts, J2T(t)) == APR_SUCCESS) | |
78 return AJP_TO_JSTRING(ts); | |
79 else | |
80 return NULL; | |
81 } | |
OLD | NEW |