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)
|
public function get_freebusy_list($email, $start, $end)
|
||||||
{
|
{
|
||||||
require_once('HTTP/Request2.php');
|
|
||||||
|
|
||||||
if (empty($email)/* || $end < time()*/)
|
if (empty($email)/* || $end < time()*/)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -888,14 +886,11 @@ class kolab_driver extends calendar_driver
|
||||||
|
|
||||||
// ask kolab server first
|
// ask kolab server first
|
||||||
try {
|
try {
|
||||||
$rcmail = rcube::get_instance();
|
$request_config = array(
|
||||||
$request = new HTTP_Request2(kolab_storage::get_freebusy_url($email));
|
|
||||||
$request->setConfig(array(
|
|
||||||
'store_body' => true,
|
'store_body' => true,
|
||||||
'follow_redirects' => 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();
|
$response = $request->send();
|
||||||
|
|
||||||
// authentication required
|
// authentication required
|
||||||
|
|
|
@ -581,27 +581,14 @@ class kolab_files_engine
|
||||||
$url = $this->url . '/api/';
|
$url = $this->url . '/api/';
|
||||||
|
|
||||||
if (!$this->request) {
|
if (!$this->request) {
|
||||||
require_once 'HTTP/Request2.php';
|
$config = array(
|
||||||
|
|
||||||
try {
|
|
||||||
$request = new HTTP_Request2();
|
|
||||||
$request->setConfig(array(
|
|
||||||
'store_body' => true,
|
'store_body' => true,
|
||||||
'follow_redirects' => 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 = libkolab::http_request($url, 'GET', $config);
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
else {
|
||||||
rcube::raise_error($e, true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// proxy User-Agent string
|
|
||||||
$this->request->setHeader('user-agent', $_SERVER['HTTP_USER_AGENT']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
try {
|
try {
|
||||||
$this->request->setBody('');
|
$this->request->setBody('');
|
||||||
|
@ -611,6 +598,7 @@ class kolab_files_engine
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
rcube::raise_error($e, true, true);
|
rcube::raise_error($e, true, true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($token) {
|
if ($token) {
|
||||||
$this->request->setHeader('X-Session-Token', $token);
|
$this->request->setHeader('X-Session-Token', $token);
|
||||||
|
|
|
@ -68,6 +68,10 @@
|
||||||
<pearinstaller>
|
<pearinstaller>
|
||||||
<min>1.7.0</min>
|
<min>1.7.0</min>
|
||||||
</pearinstaller>
|
</pearinstaller>
|
||||||
|
<package>
|
||||||
|
<name>libkolab</name>
|
||||||
|
<uri>http://kolabsys.com</uri>
|
||||||
|
</package>
|
||||||
</required>
|
</required>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<phprelease/>
|
<phprelease/>
|
||||||
|
|
|
@ -12,9 +12,6 @@ $rcmail_config['kolab_format_version'] = '3.0';
|
||||||
// Defaults to https://<imap-server->/freebusy
|
// Defaults to https://<imap-server->/freebusy
|
||||||
$rcmail_config['kolab_freebusy_server'] = 'https://<some-host>/<freebusy-path>';
|
$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
|
// Enables listing of only subscribed folders. This e.g. will limit
|
||||||
// folders in calendar view or available addressbooks
|
// folders in calendar view or available addressbooks
|
||||||
$rcmail_config['kolab_use_subscriptions'] = false;
|
$rcmail_config['kolab_use_subscriptions'] = false;
|
||||||
|
@ -23,4 +20,7 @@ $rcmail_config['kolab_use_subscriptions'] = false;
|
||||||
// for displaying resource folder names (experimental!)
|
// for displaying resource folder names (experimental!)
|
||||||
$rcmail_config['kolab_custom_display_names'] = false;
|
$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');
|
require_once('HTTP/Request2.php');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$rcmail = rcube::get_instance();
|
$request = libkolab::http_request($url);
|
||||||
$request = new HTTP_Request2($url);
|
|
||||||
$request->setConfig(array('ssl_verify_peer' => $rcmail->config->get('kolab_ssl_verify_peer', true)));
|
|
||||||
|
|
||||||
// set authentication credentials
|
// set authentication credentials
|
||||||
if ($auth_user && $auth_passwd)
|
if ($auth_user && $auth_passwd)
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
|
|
||||||
class libkolab extends rcube_plugin
|
class libkolab extends rcube_plugin
|
||||||
{
|
{
|
||||||
|
static $http_requests = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Required startup method of a Roundcube plugin
|
* 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');
|
$p['fetch_headers'] = trim($p['fetch_headers'] .' X-KOLAB-TYPE X-KOLAB-MIME-VERSION');
|
||||||
return $p;
|
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