Further support for the principal-property-search REPORT.

This commit is contained in:
Andrew McMillan 2007-08-26 20:29:50 +12:00
parent c8b1ce8d81
commit 300f334728
7 changed files with 326 additions and 11 deletions

View File

@ -22,11 +22,11 @@ function principal_to_xml( $properties, $item ) {
$denied = array();
foreach( $properties AS $k => $v ) {
switch( $v ) {
case 'DAV::GETCONTENTTYPE':
$prop->NewElement("getcontenttype", "text/x-vcard" );
break;
// case 'DAV::GETCONTENTTYPE':
// $prop->NewElement("getcontenttype", "text/x-vcard" );
// break;
case 'DAV::RESOURCETYPE':
$prop->NewElement("resourcetype", new XMLElement("principal", false, array("xmlns" => "DAV:")) );
$prop->NewElement("resourcetype", new XMLElement("principal") );
break;
case 'DAV::DISPLAYNAME':
$prop->NewElement("displayname", $item->username );
@ -38,7 +38,24 @@ function principal_to_xml( $properties, $item ) {
$prop->NewElement("alternate-uri" );
break;
case 'DAV::GROUP-MEMBER-SET':
$prop->NewElement("group-member-set" );
$qry = new PgQuery("SELECT * FROM relationship LEFT JOIN usr ON (from_user = usr.user_no) LEFT JOIN role_member ON (to_user = role_member.user_no) LEFT JOIN roles USING (role_no) WHERE to_user = ? AND role_name = 'Group';", $item->user_no );
$group = array();
if ( $qry->Exec("REPORT-principal") && $qry->rows > 0 ) {
while( $membership = $qry->Fetch() ) {
$group[] = new XMLElement("href", sprintf( "%s/%s/", $c->protocol_server_port_script, $membership->username) );
}
}
$prop->NewElement("group-member-set", $group );
break;
case 'DAV::GROUP-MEMBERSHIP':
$qry = new PgQuery("SELECT * FROM relationship LEFT JOIN usr ON (to_user = user_no) LEFT JOIN role_member USING (user_no) LEFT JOIN roles USING (role_no) WHERE from_user = ? AND role_name = 'Group';", $item->user_no );
$group = array();
if ( $qry->Exec("REPORT-principal") && $qry->rows > 0 ) {
while( $membership = $qry->Fetch() ) {
$group[] = new XMLElement("href", sprintf( "%s/%s/", $c->protocol_server_port_script, $membership->username) );
}
}
$prop->NewElement("group-membership", $group );
break;
case 'URN:IETF:PARAMS:XML:NS:CALDAV:CALENDAR-HOME-SET':
$prop->NewElement("calendar-home-set", $home_calendar, array("xmlns" => "urn:ietf:params:xml:ns:caldav") );
@ -80,8 +97,8 @@ dbg_log_array( "principal", "SEARCH", $searches, true );
$where = "";
foreach( $searches AS $k => $search ) {
$qry_props = $search->GetPath('/DAV::PROPERTY-SEARCH/DAV::PROP/*');
$match = $search->GetPath('/DAV::PROPERTY-SEARCH/DAV::MATCH');
$qry_props = $search->GetPath('/DAV::PROPERTY-SEARCH/DAV::PROP/*'); // There may be many
$match = $search->GetPath('/DAV::PROPERTY-SEARCH/DAV::MATCH'); // There may only be one
dbg_log_array( "principal", "MATCH", $match, true );
$match = qpg($match[0]->GetContent());
$subwhere = "";
@ -95,17 +112,20 @@ foreach( $searches AS $k => $search ) {
printf("Unhandled tag '%s'\n", $v1->GetTag() );
}
}
$where .= sprintf( "%s(%s)", ($where == "" ? "" : " AND "), $subwhere );
if ( $subwhere != "" ) {
$where .= sprintf( "%s(%s)", ($where == "" ? "" : " AND "), $subwhere );
}
}
if ( $where != "" ) $where = "WHERE $where";
$sql = "SELECT * FROM usr $where";
$qry = new PgQuery($sql);
$get_props = $xmltree->GetPath('/DAV::PRINCIPAL-PROPERTY-SEARCH/DAV::PROP/*');
$properties = array();
foreach( $get_props AS $k1 => $v1 ) {
$properties[] = $v1->GetTag();
}
$sql = "SELECT * FROM usr WHERE $where";
$qry = new PgQuery($sql);
if ( $qry->Exec("REPORT",__LINE__,__FILE__) && $qry->rows > 0 ) {
while( $principal_object = $qry->Fetch() ) {

View File

@ -0,0 +1,139 @@
HTTP/1.1 207 Multi-Status
Date: Dow, 01 Jan 2000 00:00:00 GMT
ETag: "8ee6bd9a1b7e15f40e6e24f149c6bf20"
Content-Length: 3720
Content-Type: text/xml; charset="utf-8"
<?xml version="1.0" encoding="utf-8" ?>
<multistatus xmlns="DAV:">
<response>
<href/>
<propstat>
<prop>
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav">http://mycaldav/caldav.php/admin/home/</calendar-home-set>
<displayname>admin</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href/>
<propstat>
<prop>
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav">http://mycaldav/caldav.php/andrew/home/</calendar-home-set>
<displayname>andrew</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href/>
<propstat>
<prop>
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav">http://mycaldav/caldav.php/user1/home/</calendar-home-set>
<displayname>user1</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href/>
<propstat>
<prop>
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav">http://mycaldav/caldav.php/user2/home/</calendar-home-set>
<displayname>user2</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href/>
<propstat>
<prop>
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav">http://mycaldav/caldav.php/user3/home/</calendar-home-set>
<displayname>user3</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href/>
<propstat>
<prop>
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav">http://mycaldav/caldav.php/user4/home/</calendar-home-set>
<displayname>user4</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href/>
<propstat>
<prop>
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav">http://mycaldav/caldav.php/user5/home/</calendar-home-set>
<displayname>user5</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href/>
<propstat>
<prop>
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav">http://mycaldav/caldav.php/manager1/home/</calendar-home-set>
<displayname>manager1</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href/>
<propstat>
<prop>
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav">http://mycaldav/caldav.php/assistant1/home/</calendar-home-set>
<displayname>assistant1</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href/>
<propstat>
<prop>
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav">http://mycaldav/caldav.php/resource1/home/</calendar-home-set>
<displayname>resource1</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href/>
<propstat>
<prop>
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav">http://mycaldav/caldav.php/resource2/home/</calendar-home-set>
<displayname>resource2</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href/>
<propstat>
<prop>
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav">http://mycaldav/caldav.php/resmgr1/home/</calendar-home-set>
<displayname>resmgr1</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
<response>
<href/>
<propstat>
<prop>
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav">http://mycaldav/caldav.php/teamclient1/home/</calendar-home-set>
<displayname>teamclient1</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>

View File

@ -0,0 +1,29 @@
#
# Do a REPORT principal-property-search request
# - in this case we look for all principals
#
TYPE=REPORT
URL=http://mycaldav/caldav.php/
HEAD
HEADER=User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20061013 Thunderbird/1.5.0.7
HEADER=Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
HEADER=Accept-Language: en-us,en;q=0.5
HEADER=Accept-Encoding: gzip,deflate
HEADER=Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
HEADER=Content-Type: text/xml
BEGINDATA
<?xml version="1.0" encoding="utf-8" ?>
<principal-property-search xmlns="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<property-search>
<prop/>
<match/>
</property-search>
<prop>
<C:calendar-home-set/>
<displayname/>
</prop>
</principal-property-search>
ENDDATA

View File

@ -0,0 +1,29 @@
HTTP/1.1 207 Multi-Status
Date: Dow, 01 Jan 2000 00:00:00 GMT
ETag: "d8fe1f4720e6249cb2fb0711fbed9794"
Content-Length: 688
Content-Type: text/xml; charset="utf-8"
<?xml version="1.0" encoding="utf-8" ?>
<multistatus xmlns="DAV:">
<response>
<href/>
<propstat>
<prop>
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav">http://mycaldav/caldav.php/user1/home/</calendar-home-set>
<displayname>user1</displayname>
<resourcetype>
<principal/>
</resourcetype>
<principal-url>http://mycaldav/caldav.php/user1/</principal-url>
<alternate-uri/>
<group-member-set/>
<group-membership>
<href>http://mycaldav/caldav.php/resmgr1/</href>
<href>http://mycaldav/caldav.php/teamclient1/</href>
</group-membership>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>

View File

@ -0,0 +1,34 @@
#
# Do a REPORT request
TYPE=REPORT
URL=http://mycaldav/caldav.php/
HEAD
HEADER=User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20061013 Thunderbird/1.5.0.7
HEADER=Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
HEADER=Accept-Language: en-us,en;q=0.5
HEADER=Accept-Encoding: gzip,deflate
HEADER=Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
HEADER=Content-Type: text/xml
BEGINDATA
<?xml version="1.0" encoding="utf-8" ?>
<principal-property-search xmlns="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<property-search>
<prop>
<displayname/>
</prop>
<match>user1</match>
</property-search>
<prop>
<C:calendar-home-set/>
<displayname/>
<resourcetype/>
<principal-url/>
<alternate-uri/>
<group-member-set/>
<group-membership/>
</prop>
</principal-property-search>
ENDDATA

View File

@ -0,0 +1,30 @@
HTTP/1.1 207 Multi-Status
Date: Dow, 01 Jan 2000 00:00:00 GMT
ETag: "f9a0b07b2c7b0347a9ae26a412baef6b"
Content-Length: 743
Content-Type: text/xml; charset="utf-8"
<?xml version="1.0" encoding="utf-8" ?>
<multistatus xmlns="DAV:">
<response>
<href/>
<propstat>
<prop>
<calendar-home-set xmlns="urn:ietf:params:xml:ns:caldav">http://mycaldav/caldav.php/resmgr1/home/</calendar-home-set>
<displayname>resmgr1</displayname>
<resourcetype>
<principal/>
</resourcetype>
<principal-url>http://mycaldav/caldav.php/resmgr1/</principal-url>
<alternate-uri/>
<group-member-set>
<href>http://mycaldav/caldav.php/user1/</href>
<href>http://mycaldav/caldav.php/user2/</href>
<href>http://mycaldav/caldav.php/assistant1/</href>
</group-member-set>
<group-membership/>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
</response>
</multistatus>

View File

@ -0,0 +1,34 @@
#
# Do a REPORT request
TYPE=REPORT
URL=http://mycaldav/caldav.php/
HEAD
HEADER=User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20061013 Thunderbird/1.5.0.7
HEADER=Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
HEADER=Accept-Language: en-us,en;q=0.5
HEADER=Accept-Encoding: gzip,deflate
HEADER=Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
HEADER=Content-Type: text/xml
BEGINDATA
<?xml version="1.0" encoding="utf-8" ?>
<principal-property-search xmlns="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<property-search>
<prop>
<displayname/>
</prop>
<match>resmgr1</match>
</property-search>
<prop>
<C:calendar-home-set/>
<displayname/>
<resourcetype/>
<principal-url/>
<alternate-uri/>
<group-member-set/>
<group-membership/>
</prop>
</principal-property-search>
ENDDATA