This file is indexed.

/usr/share/php/Horde/Kolab/Storage/Factory.php is in php-horde-kolab-storage 2.2.3-1ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<?php
/**
 * Copyright 2004-2016 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 *
 * @category Kolab
 * @package  Kolab_Storage
 * @author   Gunnar Wrobel <wrobel@pardus.de>
 * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 * @link     http://pear.horde.org/index.php?package=Kolab_Storage
 */

/**
 * A generic factory for the various Kolab_Storage classes.
 *
 * @category Kolab
 * @package  Kolab_Storage
 * @author   Gunnar Wrobel <wrobel@pardus.de>
 * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 * @link     http://pear.horde.org/index.php?package=Kolab_Storage
 */
class Horde_Kolab_Storage_Factory
{
    /**
     * A set of parameters for this factory.
     *
     * @var array
     */
    protected $_params;

    /**
     * Stores the driver once created.
     *
     * @todo Cleanup. Extract a driver factory to be placed in the driver
     * namespace and allow to inject the driver within the storage factory.
     *
     * @var Horde_Kolab_Storage_Driver
     */
    protected $_driver;

    /**
     * Constructor.
     *
     * @param array $params A set of parameters.
     * <pre>
     *  - storage:
     *  - cache:
     *  - queries:
     *  - queryset:
     *  - driver: (string) The type of backend driver. One of "mock", "php",
     *       "pear", "horde", "horde-socket", and "roundcube".
     *  - params: (array) Backend specific connection parameters.
     *  - logger: (Horde_Log_Logger) An optional log handler.
     *  - log: (array) An array of log decorators. Possible values include:
     *       'debug', 'driver_time', 'driver'.
     *  - format : (array)
     *     - factory: Name of the format parser factory class.
     *  - history: (Horde_History) A Horde_History driver.
     *  - history_prefix_generator: (Horde_Kolab_Storage_HistoryPrefix) An
     *        object that can provide prefix/collection mapping of the
     *        History system.
     * - sync_strategy: (Horde_Kolab_Storage_Synchronization) The strategy
     *         object to use for determining when we should synchronize
     *         with the Kolab backend. If omitted,
     *         Horde_Kolab_Storage_Synchronization_OncePerSession strategy is
     *         used.
     *  </pre>
     */
    public function __construct($params = array())
    {
        $this->_params = $params;
    }

    /**
     * Create the storage handler.
     *
     * @return Horde_Kolab_Storage The storage handler.
     */
    public function create()
    {
        if (isset($this->_params['storage'])) {
            $sparams = $this->_params['storage'];
        } else {
            $sparams = array();
        }
        if (isset($this->_params['queries'])) {
            $sparams['queries'] = $this->_params['queries'];
        }
        if (isset($this->_params['queryset'])) {
            $queryset = $this->_params['queryset'];
            $sparams['queryset'] = $this->_params['queryset'];
        } else {
            $queryset = array();
        }
        $cache = $this->createCache();
        if (!empty($this->_params['cache'])) {
            $storage = new Horde_Kolab_Storage_Cached(
                $this->createDriver(),
                new Horde_Kolab_Storage_QuerySet_Cached($this, $queryset, $cache),
                $this,
                $cache,
                $this->_params['logger'],
                $sparams
            );
        } else {
            $storage = new Horde_Kolab_Storage_Uncached(
                $this->createDriver(),
                new Horde_Kolab_Storage_QuerySet_Uncached($this, $queryset),
                $this,
                $cache,
                $this->_params['logger'],
                $sparams
            );
        }
        if (empty($this->_params['sync_strategy'])) {
            $strategy = new Horde_Kolab_Storage_Synchronization_OncePerSession();
        } else {
            $strategy = $this->_params['sync_strategy'];
        }
        $storage = new Horde_Kolab_Storage_Decorator_Synchronization(
            $storage, new Horde_Kolab_Storage_Synchronization($strategy)
        );

        return $storage;
    }

    /**
     * Create the storage backend driver.
     *
     * @param array $params Any parameters that should overwrite the default
     *                      parameters provided in the factory constructor.
     *
     * @return Horde_Kolab_Storage_Driver The storage handler.
     */
    public function createDriver($params = array())
    {
        $params = array_merge($this->_params, $params);
        if (!isset($params['driver'])) {
            throw new Horde_Kolab_Storage_Exception(
                Horde_Kolab_Storage_Translation::t(
                    'Missing "driver" parameter!'
                )
            );
        }
        if (isset($params['params'])) {
            $config = (array)$params['params'];
        } else {
            $config = array();
        }
        if (empty($config['host'])) {
            $config['host'] = 'localhost';
        }
        if (empty($config['port'])) {
            $config['port'] = 143;
        }
        if (isset($this->_params['log'])
            && (in_array('debug', $this->_params['log'])
                || in_array('driver_time', $this->_params['log']))) {
            $timer = new Horde_Support_Timer();
            $timer->push();
        }
        switch ($params['driver']) {
        case 'mock':
            if (!isset($config['data'])) {
                $config['data'] = array('user/test' => array());
            }
            $driver = new Horde_Kolab_Storage_Driver_Mock($this, $config);
            break;
        case 'horde':
        case 'horde-php':
            $driver = new Horde_Kolab_Storage_Driver_Imap($this, $config);
            break;
        case 'php':
            $driver = new Horde_Kolab_Storage_Driver_Cclient($this, $config);
            break;
        case 'pear':
            $driver = new Horde_Kolab_Storage_Driver_Pear($this, $config);
            break;
        case 'roundcube':
            $driver = new Horde_Kolab_Storage_Driver_Rcube($this, $config);
            break;
        default:
            throw new Horde_Kolab_Storage_Exception(
                sprintf(
                    Horde_Kolab_Storage_Translation::t(
                        'Invalid "driver" parameter "%s". Please use one of "mock", "php", "pear", "horde", "horde-php", and "roundcube"!'
                    ),
                    $params['driver']
                )
            );
        }

        if (isset($this->_params['log'])
            && (in_array('debug', $this->_params['log'])
                || in_array('driver', $this->_params['log']))) {
            $driver = new Horde_Kolab_Storage_Driver_Decorator_Log(
                $driver, $params['logger']
            );
        }

        if (isset($this->_params['log'])
            && (in_array('debug', $this->_params['log'])
                || in_array('driver_time', $this->_params['log']))) {
            $driver = new Horde_Kolab_Storage_Driver_Decorator_Timer(
                $driver, $timer, $params['logger']
            );
        }
        $this->_driver = $driver;
        return $driver;
    }

    /**
     * Create a namespace handler.
     *
     * @param string $type   The namespace type.
     * @param string $user   The current user.
     * @param array  $params The parameters for the namespace.
     *
     * @return Horde_Kolab_Storage_Folder_Namespace The namespace handler.
     */
    public function createNamespace($type, $user, array $params = array())
    {
        $class = 'Horde_Kolab_Storage_Folder_Namespace_' . Horde_String::ucfirst($type);
        if (!class_exists($class)) {
            throw new Horde_Kolab_Storage_Exception(
                sprintf(
                    Horde_Kolab_Storage_Translation::t(
                        'Invalid "namespace" type "%s"!'
                    ),
                    $type
                )
            );
        }
        return new $class($user, $params);
    }

    /**
     * Create the cache handler.
     *
     * @return Horde_Kolab_Storage_Cache The cache handler.
     */
    public function createCache()
    {
        if (isset($this->_params['cache'])) {
            $params = $this->_params['cache'];
        } else {
            $params = array();
        }
        if ($params instanceof Horde_Cache) {
            return new Horde_Kolab_Storage_Cache($params);
        } else {
            $cache = new Horde_Cache(
                new Horde_Cache_Storage_File($params),
                array('lifetime' => 0)
            );
        }
        return new Horde_Kolab_Storage_Cache(
            $cache
        );
    }

    /**
     * Create the history handler.
     *
     * @param string $user The current user.
     *
     * @return Horde_History The history handler.
     */
    public function createHistory($user)
    {
        if (isset($this->_params['history']) &&
            $this->_params['history'] instanceof Horde_History) {
            return $this->_params['history'];
        }
        return new Horde_History_Mock($user);
    }

    /**
     * Create a prefix factory.
     *
     * @todo This should probably be implemented by decorating/wrapping the
     *       Horde_History object but that can't be done in a clean BC way
     *       until Horde 6. So, until then implement a
     *       Horde_Kolab_Storage_History_Prefix interface.
     *
     * @return Horde_Kolab_Storage_HistoryPrefix|Horde_Support_Stub
     */
    public function getHistoryPrefixGenerator()
    {
        if (isset($this->_params['history_prefix_generator'])) {
            return $this->_params['history_prefix_generator'];
        }

        return new Horde_Support_Stub();
    }

    public function getDriver()
    {
        return $this->_driver;
    }
}