Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/CalDAVClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function __construct( $base_url, $user, $pass, $options = array()) {
CURLOPT_MAXREDIRS => 2,
CURLOPT_FORBID_REUSE => FALSE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0,
CURLOPT_HTTPAUTH =>
isset($options['auth']) ? $options['auth'] :
(CURLAUTH_BASIC | CURLAUTH_DIGEST),
Expand Down Expand Up @@ -344,7 +344,7 @@ function GetHttpResultCode() {
*
* @return bool|string The content of the response from the server
*/
function DoRequest( $url = null ) {
function DoRequest( $url = null, $forceBody = false ) {
if (is_null($url)) {
$url = $this->full_url;
}
Expand All @@ -357,7 +357,7 @@ function DoRequest( $url = null ) {
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, $this->requestMethod);

// Empty body. If not used, cURL will spend ~5s on this request
if ($this->requestMethod == 'HEAD' || empty($this->body) ) {
if (!$forceBody && ($this->requestMethod == 'HEAD' || empty($this->body)) ) {
curl_setopt($this->ch, CURLOPT_NOBODY, TRUE);
} else {
curl_setopt($this->ch, CURLOPT_NOBODY, FALSE);
Expand All @@ -383,10 +383,11 @@ function DoRequest( $url = null ) {
$response = curl_exec($this->ch);

if (FALSE === $response) {
// TODO better error handling
log_message('ERROR', 'Error requesting ' . $url . ': '
. curl_error($this->ch));
return false;
throw new CalDAVException(
'curl error: ' . curl_error($this->ch) .
', request method: ' . $this->requestMethod .
', url: ' . $url, $this
);
}

$info = curl_getinfo($this->ch);
Expand Down Expand Up @@ -460,10 +461,10 @@ function DoXMLRequest( $request_method, $xml, $url = null ) {
*
* @param string $url The URL to GET
*/
function DoGETRequest( $url ) {
function DoGETRequest( $url, $forceBody = false ) {
$this->body = "";
$this->requestMethod = "GET";
return $this->DoRequest( $url );
return $this->DoRequest( $url, $forceBody );
}


Expand Down Expand Up @@ -506,7 +507,7 @@ function DoPUTRequest( $url, $icalendar, $etag = null ) {
$save_request = $this->httpRequest;
$save_response_headers = $this->httpResponseHeaders;
$save_http_result = $this->httpResultCode;
$this->DoHEADRequest( $url );
$this->DoGETRequest( $url );
if ( preg_match( '{^Etag:\s+"([^"]*)"\s*$}im', $this->httpResponseHeaders, $matches ) ) $etag = $matches[1];
else if ( preg_match( '{^ETag:\s+([^\s]*)\s*$}im', $this->httpResponseHeaders, $matches ) ) $etag = $matches[1];
/*
Expand Down Expand Up @@ -1106,9 +1107,9 @@ function GetEntryByUid( $uid, $relative_url = null ) {
*
* @return string The iCalendar of the calendar entry
*/
function GetEntryByHref( $href ) {
function GetEntryByHref( $href, $forceBody = false ) {
//$href = str_replace( rawurlencode('/'),'/',rawurlencode($href));
$response = $this->DoGETRequest( $href );
$response = $this->DoGETRequest( $href, $forceBody );

$report = array();

Expand Down Expand Up @@ -1136,7 +1137,7 @@ function GetEntryByHref( $href ) {
$this->httpResultCode = $save_http_result;
}

$report = array(array('etag'=>$etag));
$report = array(array('etag' => $etag, 'body' => $this->httpResponseBody));

return $report;
}
Expand Down
18 changes: 17 additions & 1 deletion src/SimpleCalDAVClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function change ( $href, $new_data, $etag )
$newEtag = $this->client->DoPUTRequest( $href, $new_data, $etag );

// PUT-request successfull?
if ( $this->client->GetHttpResultCode() != '204' && $this->client->GetHttpResultCode() != '200' )
if ( $this->client->GetHttpResultCode() != '204' && $this->client->GetHttpResultCode() != '200' && $this->client->GetHttpResultCode() != '201' )
{
throw new CalDAVException('Recieved unknown HTTP status', $this->client);
}
Expand Down Expand Up @@ -413,6 +413,22 @@ function getCustomReport ( $filterXML )

return $report;
}

function getEntryByHref($href)
{
// Connection and calendar set?
if(!isset($this->client)) throw new Exception('No connection. Try connect().');
if(!isset($this->client->calendar_url)) throw new Exception('No calendar selected. Try findCalendars() and setCalendar().');

// Does $href exist?
$result = $this->client->GetEntryByHref($href, true);
if ( $this->client->GetHttpResultCode() == '200' );
else if ( $this->client->GetHttpResultCode() == '404' ) throw new CalDAVException('Can\'t find '.$href.' on the server', $this->client);
else throw new CalDAVException('Recieved unknown HTTP status', $this->client);

$entry = array_shift($result);
return $entry;
}
}

?>