From 31f9fdd505ef12d1d11289477ff370e8e97d524d Mon Sep 17 00:00:00 2001 From: Rob Ostensen Date: Sun, 29 Jan 2012 12:14:20 -0600 Subject: [PATCH] fix xml queries --- inc/caldav-POST.php | 19 ++++++++++++++++--- inc/iSchedule.php | 12 +++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/inc/caldav-POST.php b/inc/caldav-POST.php index 85936cad..5f5892a1 100644 --- a/inc/caldav-POST.php +++ b/inc/caldav-POST.php @@ -13,6 +13,7 @@ dbg_error_log("POST", "method handler"); require_once("XMLDocument.php"); include_once('caldav-PUT-functions.php'); include_once('freebusy-functions.php'); +include_once('iSchedule.php'); if ( ! $request->AllowedTo("CALDAV:schedule-send-freebusy") && ! $request->AllowedTo("CALDAV:schedule-send-invite") @@ -31,7 +32,7 @@ if ( ! ini_get('open_basedir') && (isset($c->dbg['ALL']) || isset($c->dbg['post' function handle_freebusy_request( $ic ) { - global $c, $session, $request; + global $c, $session, $request, $ical; $reply = new XMLDocument( array("DAV:" => "", "urn:ietf:params:xml:ns:caldav" => "C" ) ); $responses = array(); @@ -77,8 +78,20 @@ function handle_freebusy_request( $ic ) { $reply->CalDAVElement($response, "recipient", $reply->href($attendee->Value()) ); if ( $qry->rows() == 0 ) { - $reply->CalDAVElement($response, "request-status", "3.7;Invalid Calendar User" ); - $reply->CalDAVElement($response, "calendar-data" ); + $remote = new iSchedule (); + $answer = $remote->sendRequest ( $attendee->Value(), 'VFREEBUSY/REQUEST', $ical->Render() ); + if ( $answer === false ) { + $reply->CalDAVElement($response, "request-status", "3.7;Invalid Calendar User" ); + $reply->CalDAVElement($response, "calendar-data" ); + } + elseif ( substr( $answer, 0, 1 ) >= 1 ) { + $reply->CalDAVElement($response, "request-status", $answer ); + $reply->CalDAVElement($response, "calendar-data" ); + } + else { + $reply->CalDAVElement($response, "request-status", "2.0;Success" ); + $reply->CalDAVElement($response, "calendar-data", $answer ); + } $responses[] = $response; continue; } diff --git a/inc/iSchedule.php b/inc/iSchedule.php index 53901f07..8fef2daf 100644 --- a/inc/iSchedule.php +++ b/inc/iSchedule.php @@ -313,7 +313,7 @@ class iSchedule case 'VEVENT/COUNTER': case 'VEVENT/DECLINECOUNTER': dbg_error_log('ischedule', $this->domain . ' xml query' ); - $comp = $this->capabilities_xml->GetElements ( 'comp', true ); + $comp = $this->capabilities_xml->GetPath ( '/query-result/capability-set/supported-scheduling-message-set/comp' ); return true; list ( $component, $method ) = explode ( '/', $capability ); dbg_error_log('ischedule', $this->domain . ' quering for capability:' . count ( $c ) . ' ' . $component ); @@ -409,21 +409,23 @@ class iSchedule $headers['Content-Type'] = 'text/calendar; component=' . $component ; if ( $method ) $headers['Content-Type'] .= '; method=' . $method; - $headers['DKIM-Signature'] = $this->signDKIM ( $headers, $body ); + //$headers['DKIM-Signature'] = $this->signDKIM ( $headers, $body ); + $Signature = $this->signDKIM ( $headers, $body ); $request_headers = array ( ); foreach ( $headers as $k => $v ) $request_headers[] = $k . ':' . $v; - $request_headers[] = 'Expect:'; // supress expect header $curl = curl_init ( $this->remote_url ); curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true ); curl_setopt ( $curl, CURLOPT_HEADER, true ); - curl_setopt ( $curl, CURLOPT_CUSTOMREQUEST, 'POST' ); curl_setopt ( $curl, CURLOPT_HTTPHEADER, array() ); // start with no headers set curl_setopt ( $curl, CURLOPT_HTTPHEADER, $request_headers ); + curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt ( $curl, CURLOPT_POST, 1); curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data); + //curl_setopt ( $curl, CURLOPT_CUSTOMREQUEST, 'POST' ); $xmlresponse = curl_exec ( $curl ); $info = curl_getinfo ( $curl ); + error_log ( print_r ( $request_headers , true ) . print_r ( $data , true ) . $Signature ); curl_close ( $curl ); error_log($xmlresponse); $xml_parser = xml_parser_create_ns('UTF-8'); @@ -443,7 +445,7 @@ class iSchedule dbg_error_log( 'ERROR', 'iSchedule RESPONSE body is not valid XML data!' ); return false; } - $resp = $xmtree->GetPath ( 'response' ); + $resp = $xmtree->GetPath ( '/schedule-response/response' ); $result = array(); foreach ( $resp as $r ) {