/src/logging-log4cxx/src/main/cpp/system.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
3 | | * contributor license agreements. See the NOTICE file distributed with |
4 | | * this work for additional information regarding copyright ownership. |
5 | | * The ASF licenses this file to You under the Apache License, Version 2.0 |
6 | | * (the "License"); you may not use this file except in compliance with |
7 | | * the License. You may obtain a copy of the License at |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | */ |
17 | | |
18 | | #include <log4cxx/logstring.h> |
19 | | #include <log4cxx/helpers/system.h> |
20 | | |
21 | | #include <log4cxx/helpers/transcoder.h> |
22 | | #include <log4cxx/helpers/pool.h> |
23 | | #include <apr_file_io.h> |
24 | | #include <apr_user.h> |
25 | | #include <apr_env.h> |
26 | | |
27 | | |
28 | | using namespace LOG4CXX_NS; |
29 | | using namespace LOG4CXX_NS::helpers; |
30 | | |
31 | | |
32 | | LogString System::getProperty(const LogString& lkey) |
33 | 0 | { |
34 | 0 | if (lkey.empty()) |
35 | 0 | { |
36 | 0 | throw IllegalArgumentException(LOG4CXX_STR("key is empty")); |
37 | 0 | } |
38 | | |
39 | 0 | LogString rv; |
40 | |
|
41 | 0 | if (lkey == LOG4CXX_STR("java.io.tmpdir")) |
42 | 0 | { |
43 | 0 | Pool p; |
44 | 0 | const char* dir = NULL; |
45 | 0 | apr_status_t stat = apr_temp_dir_get(&dir, p.getAPRPool()); |
46 | |
|
47 | 0 | if (stat == APR_SUCCESS) |
48 | 0 | { |
49 | 0 | Transcoder::decode(dir, rv); |
50 | 0 | } |
51 | |
|
52 | 0 | return rv; |
53 | 0 | } |
54 | | |
55 | 0 | if (lkey == LOG4CXX_STR("user.dir")) |
56 | 0 | { |
57 | 0 | Pool p; |
58 | 0 | char* dir = NULL; |
59 | 0 | apr_status_t stat = apr_filepath_get(&dir, APR_FILEPATH_NATIVE, |
60 | 0 | p.getAPRPool()); |
61 | |
|
62 | 0 | if (stat == APR_SUCCESS) |
63 | 0 | { |
64 | 0 | Transcoder::decode(dir, rv); |
65 | 0 | } |
66 | |
|
67 | 0 | return rv; |
68 | 0 | } |
69 | | |
70 | 0 | #if APR_HAS_USER |
71 | | |
72 | 0 | if (lkey == LOG4CXX_STR("user.home") || lkey == LOG4CXX_STR("user.name")) |
73 | 0 | { |
74 | 0 | Pool pool; |
75 | 0 | apr_uid_t userid; |
76 | 0 | apr_gid_t groupid; |
77 | 0 | apr_pool_t* p = pool.getAPRPool(); |
78 | 0 | apr_status_t stat = apr_uid_current(&userid, &groupid, p); |
79 | |
|
80 | 0 | if (stat == APR_SUCCESS) |
81 | 0 | { |
82 | 0 | char* username = NULL; |
83 | 0 | stat = apr_uid_name_get(&username, userid, p); |
84 | |
|
85 | 0 | if (stat == APR_SUCCESS) |
86 | 0 | { |
87 | 0 | if (lkey == LOG4CXX_STR("user.name")) |
88 | 0 | { |
89 | 0 | Transcoder::decode(username, rv); |
90 | 0 | } |
91 | 0 | else |
92 | 0 | { |
93 | 0 | char* dirname = NULL; |
94 | 0 | stat = apr_uid_homepath_get(&dirname, username, p); |
95 | |
|
96 | 0 | if (stat == APR_SUCCESS) |
97 | 0 | { |
98 | 0 | Transcoder::decode(dirname, rv); |
99 | 0 | } |
100 | 0 | } |
101 | 0 | } |
102 | 0 | } |
103 | |
|
104 | 0 | return rv; |
105 | 0 | } |
106 | | |
107 | 0 | #endif |
108 | | |
109 | 0 | LOG4CXX_ENCODE_CHAR(key, lkey); |
110 | 0 | Pool p; |
111 | 0 | char* value = NULL; |
112 | 0 | apr_status_t stat = apr_env_get(&value, key.c_str(), |
113 | 0 | p.getAPRPool()); |
114 | |
|
115 | 0 | if (stat == APR_SUCCESS) |
116 | 0 | { |
117 | 0 | Transcoder::decode((const char*) value, rv); |
118 | 0 | } |
119 | |
|
120 | 0 | return rv; |
121 | 0 | } |
122 | | |