Implemented unified cross-plugin HTTP_Request2 object configuration (Request #2149)
This commit is contained in:
parent
83edac179a
commit
5327dfc641
6 changed files with 87 additions and 38 deletions
|
@ -874,8 +874,6 @@ class kolab_driver extends calendar_driver
|
|||
*/
|
||||
public function get_freebusy_list($email, $start, $end)
|
||||
{
|
||||
require_once('HTTP/Request2.php');
|
||||
|
||||
if (empty($email)/* || $end < time()*/)
|
||||
return false;
|
||||
|
||||
|
@ -888,14 +886,11 @@ class kolab_driver extends calendar_driver
|
|||
|
||||
// ask kolab server first
|
||||
try {
|
||||
$rcmail = rcube::get_instance();
|
||||
$request = new HTTP_Request2(kolab_storage::get_freebusy_url($email));
|
||||
$request->setConfig(array(
|
||||
$request_config = array(
|
||||
'store_body' => true,
|
||||
'follow_redirects' => true,
|
||||
'ssl_verify_peer' => $rcmail->config->get('kolab_ssl_verify_peer', true),
|
||||
));
|
||||
|
||||
);
|
||||
$request = libkolab::http_request(kolab_storage::get_freebusy_url($email), 'GET', $request_config);
|
||||
$response = $request->send();
|
||||
|
||||
// authentication required
|
||||
|
|
|
@ -581,35 +581,23 @@ class kolab_files_engine
|
|||
$url = $this->url . '/api/';
|
||||
|
||||
if (!$this->request) {
|
||||
require_once 'HTTP/Request2.php';
|
||||
$config = array(
|
||||
'store_body' => true,
|
||||
'follow_redirects' => true,
|
||||
);
|
||||
|
||||
$this->request = libkolab::http_request($url, 'GET', $config);
|
||||
}
|
||||
else {
|
||||
// cleanup
|
||||
try {
|
||||
$request = new HTTP_Request2();
|
||||
$request->setConfig(array(
|
||||
'store_body' => true,
|
||||
'follow_redirects' => true,
|
||||
'ssl_verify_peer' => $this->rc->config->get('kolab_ssl_verify_peer', true),
|
||||
'ssl_verify_host' => $this->rc->config->get('kolab_ssl_verify_host', true),
|
||||
));
|
||||
|
||||
$this->request = $request;
|
||||
$this->request->setBody('');
|
||||
$this->request->setUrl($url);
|
||||
$this->request->setMethod(HTTP_Request2::METHOD_GET);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
rcube::raise_error($e, true, true);
|
||||
}
|
||||
|
||||
// proxy User-Agent string
|
||||
$this->request->setHeader('user-agent', $_SERVER['HTTP_USER_AGENT']);
|
||||
}
|
||||
|
||||
// cleanup
|
||||
try {
|
||||
$this->request->setBody('');
|
||||
$this->request->setUrl($url);
|
||||
$this->request->setMethod(HTTP_Request2::METHOD_GET);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
rcube::raise_error($e, true, true);
|
||||
}
|
||||
|
||||
if ($token) {
|
||||
|
|
|
@ -68,6 +68,10 @@
|
|||
<pearinstaller>
|
||||
<min>1.7.0</min>
|
||||
</pearinstaller>
|
||||
<package>
|
||||
<name>libkolab</name>
|
||||
<uri>http://kolabsys.com</uri>
|
||||
</package>
|
||||
</required>
|
||||
</dependencies>
|
||||
<phprelease/>
|
||||
|
|
|
@ -12,9 +12,6 @@ $rcmail_config['kolab_format_version'] = '3.0';
|
|||
// Defaults to https://<imap-server->/freebusy
|
||||
$rcmail_config['kolab_freebusy_server'] = 'https://<some-host>/<freebusy-path>';
|
||||
|
||||
// Set this option to disable SSL certificate checks when triggering Free/Busy (enabled by default)
|
||||
$rcmail_config['kolab_ssl_verify_peer'] = false;
|
||||
|
||||
// Enables listing of only subscribed folders. This e.g. will limit
|
||||
// folders in calendar view or available addressbooks
|
||||
$rcmail_config['kolab_use_subscriptions'] = false;
|
||||
|
@ -23,4 +20,7 @@ $rcmail_config['kolab_use_subscriptions'] = false;
|
|||
// for displaying resource folder names (experimental!)
|
||||
$rcmail_config['kolab_custom_display_names'] = false;
|
||||
|
||||
?>
|
||||
// Configuration of HTTP requests.
|
||||
// See http://pear.php.net/manual/en/package.http.http-request2.config.php
|
||||
// for list of supported configuration options (array keys)
|
||||
$rcmail_config['kolab_http_request'] = array();
|
||||
|
|
|
@ -1110,9 +1110,7 @@ class kolab_storage_folder
|
|||
require_once('HTTP/Request2.php');
|
||||
|
||||
try {
|
||||
$rcmail = rcube::get_instance();
|
||||
$request = new HTTP_Request2($url);
|
||||
$request->setConfig(array('ssl_verify_peer' => $rcmail->config->get('kolab_ssl_verify_peer', true)));
|
||||
$request = libkolab::http_request($url);
|
||||
|
||||
// set authentication credentials
|
||||
if ($auth_user && $auth_passwd)
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
|
||||
class libkolab extends rcube_plugin
|
||||
{
|
||||
static $http_requests = array();
|
||||
|
||||
/**
|
||||
* Required startup method of a Roundcube plugin
|
||||
*/
|
||||
|
@ -59,4 +61,66 @@ class libkolab extends rcube_plugin
|
|||
$p['fetch_headers'] = trim($p['fetch_headers'] .' X-KOLAB-TYPE X-KOLAB-MIME-VERSION');
|
||||
return $p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper function to load and initalize the HTTP_Request2 Object
|
||||
*
|
||||
* @param string|Net_Url2 Request URL
|
||||
* @param string Request method ('OPTIONS','GET','HEAD','POST','PUT','DELETE','TRACE','CONNECT')
|
||||
* @param array Configuration for this Request instance, that will be merged
|
||||
* with default configuration
|
||||
*
|
||||
* @return HTTP_Request2 Request object
|
||||
*/
|
||||
public static function http_request($url = '', $method = 'GET', $config = array())
|
||||
{
|
||||
$rcube = rcube::get_instance();
|
||||
$http_config = (array) $rcube->config->get('kolab_http_request');
|
||||
|
||||
// deprecated configuration options
|
||||
if (empty($$http_config)) {
|
||||
foreach (array('ssl_verify_peer', 'ssl_verify_host') as $option) {
|
||||
$value = $rcube->config->get('kolab_' . $option, true);
|
||||
if (is_bool($value)) {
|
||||
$http_config[$option] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($config)) {
|
||||
$http_config = array_merge($http_config, $config);
|
||||
}
|
||||
|
||||
$key = md5(serialize($http_config));
|
||||
|
||||
if (!($request = self::$http_requests[$key])) {
|
||||
// load HTTP_Request2
|
||||
require_once 'HTTP/Request2.php';
|
||||
|
||||
try {
|
||||
$request = new HTTP_Request2();
|
||||
$request->setConfig($http_config);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
rcube::raise_error($e, true, true);
|
||||
}
|
||||
|
||||
// proxy User-Agent string
|
||||
$request->setHeader('user-agent', $_SERVER['HTTP_USER_AGENT']);
|
||||
|
||||
self::$http_requests[$key] = $request;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
try {
|
||||
$request->setBody('');
|
||||
$request->setUrl($url);
|
||||
$request->setMethod($method);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
rcube::raise_error($e, true, true);
|
||||
}
|
||||
|
||||
return $request;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue