Exemple #1
0
 public function parseMultiStatus($body)
 {
     $body = str_replace('<D:', '<d:', $body);
     $body = str_replace('</D:', '</d:', $body);
     $body = str_replace(':D=', ':d=', $body);
     return parent::parseMultiStatus($body);
 }
Exemple #2
0
    function testMultiGet()
    {
        $request = new HTTP\Request(array('REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/addressbooks/user1/book1'));
        $request->setBody('<?xml version="1.0"?>
<c:addressbook-multiget xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
    <d:prop>
      <d:getetag />
      <c:address-data />
    </d:prop>
    <d:href>/addressbooks/user1/book1/card1</d:href>
</c:addressbook-multiget>');
        $response = new HTTP\ResponseMock();
        $this->server->httpRequest = $request;
        $this->server->httpResponse = $response;
        $this->server->exec();
        $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body);
        // using the client for parsing
        $client = new DAV\Client(array('baseUri' => '/'));
        $result = $client->parseMultiStatus($response->body);
        $this->assertEquals(array('/addressbooks/user1/book1/card1' => array(200 => array('{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD"))), $result);
    }
Exemple #3
0
    function testMultiGetVCard4()
    {
        $request = HTTP\Sapi::createFromServerArray(['REQUEST_METHOD' => 'REPORT', 'REQUEST_URI' => '/addressbooks/user1/book1']);
        $request->setBody('<?xml version="1.0"?>
<c:addressbook-multiget xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
    <d:prop>
      <d:getetag />
      <c:address-data content-type="text/vcard" version="4.0" />
    </d:prop>
    <d:href>/addressbooks/user1/book1/card1</d:href>
</c:addressbook-multiget>');
        $response = new HTTP\ResponseMock();
        $this->server->httpRequest = $request;
        $this->server->httpResponse = $response;
        $this->server->exec();
        $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
        // using the client for parsing
        $client = new DAV\Client(['baseUri' => '/']);
        $result = $client->parseMultiStatus($response->body);
        $prodId = "PRODID:-//Sabre//Sabre VObject " . \Sabre\VObject\Version::VERSION . "//EN";
        $this->assertEquals(['/addressbooks/user1/book1/card1' => [200 => ['{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:4.0\r\n{$prodId}\r\nUID:12345\r\nEND:VCARD\r\n"]]], $result);
    }
    function testVCard4()
    {
        $request = new HTTP\Request('REPORT', '/addressbooks/user1/book1/card1', ['Depth' => '0']);
        $request->setBody('<?xml version="1.0"?>
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
    <d:prop>
      <c:address-data content-type="text/vcard" version="4.0" />
      <d:getetag />
    </d:prop>
</c:addressbook-query>');
        $response = new HTTP\ResponseMock();
        $this->server->httpRequest = $request;
        $this->server->httpResponse = $response;
        $this->server->exec();
        $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
        // using the client for parsing
        $client = new DAV\Client(['baseUri' => '/']);
        $result = $client->parseMultiStatus($response->body);
        $vobjVersion = \Sabre\VObject\Version::VERSION;
        $this->assertEquals(['/addressbooks/user1/book1/card1' => [200 => ['{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:4.0\r\nPRODID:-//Sabre//Sabre VObject {$vobjVersion}//EN\r\nUID:12345\r\nEND:VCARD\r\n"]]], $result);
    }
 /**
  * Parses a WebDAV multistatus response body
  *
  * @param string $body xml body
  * @return array
  */
 public function parseMultiStatus($body)
 {
     $oldSetting = libxml_use_internal_errors(true);
     try {
         $result = parent::parseMultiStatus($body);
         if (count($xmlErrors = libxml_get_errors()) > 0) {
             if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) {
                 Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' XML errors occured: ' . print_r($xmlErrors, true));
             }
         }
         libxml_clear_errors();
         libxml_use_internal_errors($oldSetting);
     } catch (InvalidArgumentException $e) {
         libxml_clear_errors();
         libxml_use_internal_errors($oldSetting);
         // remove possible broken chars here to avoid simplexml_load_string errors
         // this line may throw an Exception again! thats why the libxml_* functions are called in try and catch!
         $result = parent::parseMultiStatus(Tinebase_Helper::removeIllegalXMLChars($body));
     }
     return $result;
 }