forked from 1afa/sabre-zarafa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZarafaWebaccessSettings.php
118 lines (106 loc) · 3.47 KB
/
ZarafaWebaccessSettings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/*
* Copyright 2013 Bokxing IT, http://www.bokxing-it.nl
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* "Zarafa" is a registered trademark of Zarafa B.V.
*
* This software use SabreDAV, an open source software distributed
* with New BSD License. Please see <http://code.google.com/p/sabredav/>
* for more information about SabreDAV
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Project page: <http://github.com/bokxing-it/sabre-zarafa/>
*
*/
namespace SabreZarafa;
require_once 'common.inc.php';
require_once 'ZarafaLogger.php';
class Zarafa_Webaccess_Settings
{
private $logger = false;
private $handle = false;
private $settings = false;
public function
__construct ($private_store_handle)
{
$this->logger = new Logger(__CLASS__);
// Need a handle to the private store in order to do our lookups:
$this->handle = $private_store_handle;
}
public function
by_path ($path)
{
$this->logger->trace(__FUNCTION__);
if (($settings = $this->get_settings()) === false) {
return false;
}
if (!isset($settings['settings'])) {
return false;
}
$path = explode('/', $path);
$tmp = $settings['settings'];
foreach ($path as $pointer) {
if (empty($pointer)) {
continue;
}
if (!isset($tmp[$pointer])) {
return false;
}
$tmp = $tmp[$pointer];
}
return $tmp;
}
private function
get_settings ()
{
$this->logger->trace(__FUNCTION__);
// Return cached version if available:
if ($this->settings !== false) {
return $this->settings;
}
if ($this->handle === false) {
$this->logger->warn(__FUNCTION__.': no handle to private store');
return false;
}
// First check if property exist and we can open that using mapi_openproperty():
if (($storeProps = mapi_getprops($this->handle, array(PR_EC_WEBACCESS_SETTINGS_JSON))) === false) {
$this->logger->warn(__FUNCTION__.': failed to get store properties');
return false;
}
if (!(isset($storeProps[PR_EC_WEBACCESS_SETTINGS_JSON]) || propIsError(PR_EC_WEBACCESS_SETTINGS_JSON, $storeProps) == MAPI_E_NOT_ENOUGH_MEMORY)) {
$this->logger->warn(__FUNCTION__.': failed to find PR_EC_WEBACCESS_SETTINGS_JSON property');
return false;
}
// Read the settings property:
if (($stream = mapi_openproperty($this->handle, PR_EC_WEBACCESS_SETTINGS_JSON, IID_IStream, 0, 0)) === false) {
$this->logger->warn(__FUNCTION__.': failed to open stream');
return false;
}
$stat = mapi_stream_stat($stream);
if (mapi_stream_seek($stream, 0, STREAM_SEEK_SET) === false) {
$this->logger->warn(__FUNCTION__.': failed to seek stream');
return false;
}
$settings_string = '';
for ($i = 0; $i < $stat['cb']; $i += 1024) {
$settings_string .= mapi_stream_read($stream, 1024);
}
$settings = json_decode($settings_string, true);
if (!is_array($settings) || !isset($settings['settings']) || !is_array($settings['settings'])) {
$this->logger->warn(__FUNCTION__.': failed to decode JSON settings string');
return false;
}
return $this->settings = $settings;
}
}