/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 | 17.3k | { |
34 | 17.3k | if (lkey.empty()) |
35 | 0 | { |
36 | 0 | throw IllegalArgumentException(LOG4CXX_STR("key is empty")); |
37 | 0 | } |
38 | | |
39 | 17.3k | LogString rv; |
40 | | |
41 | 17.3k | if (lkey == LOG4CXX_STR("java.io.tmpdir")) |
42 | 159 | { |
43 | 159 | Pool p; |
44 | 159 | const char* dir = NULL; |
45 | 159 | apr_status_t stat = apr_temp_dir_get(&dir, p.getAPRPool()); |
46 | | |
47 | 159 | if (stat == APR_SUCCESS) |
48 | 159 | { |
49 | 159 | Transcoder::decode(dir, rv); |
50 | 159 | } |
51 | | |
52 | 159 | return rv; |
53 | 159 | } |
54 | | |
55 | 17.1k | if (lkey == LOG4CXX_STR("user.dir")) |
56 | 173 | { |
57 | 173 | Pool p; |
58 | 173 | char* dir = NULL; |
59 | 173 | apr_status_t stat = apr_filepath_get(&dir, APR_FILEPATH_NATIVE, |
60 | 173 | p.getAPRPool()); |
61 | | |
62 | 173 | if (stat == APR_SUCCESS) |
63 | 173 | { |
64 | 173 | Transcoder::decode(dir, rv); |
65 | 173 | } |
66 | | |
67 | 173 | return rv; |
68 | 173 | } |
69 | | |
70 | 17.0k | #if APR_HAS_USER |
71 | | |
72 | 17.0k | if (lkey == LOG4CXX_STR("user.home") || lkey == LOG4CXX_STR("user.name")) |
73 | 49 | { |
74 | 49 | Pool pool; |
75 | 49 | apr_uid_t userid; |
76 | 49 | apr_gid_t groupid; |
77 | 49 | apr_pool_t* p = pool.getAPRPool(); |
78 | 49 | apr_status_t stat = apr_uid_current(&userid, &groupid, p); |
79 | | |
80 | 49 | if (stat == APR_SUCCESS) |
81 | 49 | { |
82 | 49 | char* username = NULL; |
83 | 49 | stat = apr_uid_name_get(&username, userid, p); |
84 | | |
85 | 49 | if (stat == APR_SUCCESS) |
86 | 49 | { |
87 | 49 | if (lkey == LOG4CXX_STR("user.name")) |
88 | 27 | { |
89 | 27 | Transcoder::decode(username, rv); |
90 | 27 | } |
91 | 22 | else |
92 | 22 | { |
93 | 22 | char* dirname = NULL; |
94 | 22 | stat = apr_uid_homepath_get(&dirname, username, p); |
95 | | |
96 | 22 | if (stat == APR_SUCCESS) |
97 | 22 | { |
98 | 22 | Transcoder::decode(dirname, rv); |
99 | 22 | } |
100 | 22 | } |
101 | 49 | } |
102 | 49 | } |
103 | | |
104 | 49 | return rv; |
105 | 49 | } |
106 | | |
107 | 16.9k | #endif |
108 | | |
109 | 16.9k | LOG4CXX_ENCODE_CHAR(key, lkey); |
110 | 16.9k | Pool p; |
111 | 16.9k | char* value = NULL; |
112 | 16.9k | apr_status_t stat = apr_env_get(&value, key.c_str(), |
113 | 16.9k | p.getAPRPool()); |
114 | | |
115 | 16.9k | if (stat == APR_SUCCESS) |
116 | 15.7k | { |
117 | 15.7k | Transcoder::decode((const char*) value, rv); |
118 | 15.7k | } |
119 | | |
120 | 16.9k | return rv; |
121 | 17.0k | } |
122 | | |