diff --git a/inc/caldav-REPORT-principal.php b/inc/caldav-REPORT-principal.php
index 2c174e01..0f9f11cb 100644
--- a/inc/caldav-REPORT-principal.php
+++ b/inc/caldav-REPORT-principal.php
@@ -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() ) {
diff --git a/testing/tests/regression-suite/861-Spec-REPORT-principal.result b/testing/tests/regression-suite/861-Spec-REPORT-principal.result
new file mode 100644
index 00000000..b68509fe
--- /dev/null
+++ b/testing/tests/regression-suite/861-Spec-REPORT-principal.result
@@ -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"
+
+
+
+
+
+
+
+ http://mycaldav/caldav.php/admin/home/
+ admin
+
+ HTTP/1.1 200 OK
+
+
+
+
+
+
+ http://mycaldav/caldav.php/andrew/home/
+ andrew
+
+ HTTP/1.1 200 OK
+
+
+
+
+
+
+ http://mycaldav/caldav.php/user1/home/
+ user1
+
+ HTTP/1.1 200 OK
+
+
+
+
+
+
+ http://mycaldav/caldav.php/user2/home/
+ user2
+
+ HTTP/1.1 200 OK
+
+
+
+
+
+
+ http://mycaldav/caldav.php/user3/home/
+ user3
+
+ HTTP/1.1 200 OK
+
+
+
+
+
+
+ http://mycaldav/caldav.php/user4/home/
+ user4
+
+ HTTP/1.1 200 OK
+
+
+
+
+
+
+ http://mycaldav/caldav.php/user5/home/
+ user5
+
+ HTTP/1.1 200 OK
+
+
+
+
+
+
+ http://mycaldav/caldav.php/manager1/home/
+ manager1
+
+ HTTP/1.1 200 OK
+
+
+
+
+
+
+ http://mycaldav/caldav.php/assistant1/home/
+ assistant1
+
+ HTTP/1.1 200 OK
+
+
+
+
+
+
+ http://mycaldav/caldav.php/resource1/home/
+ resource1
+
+ HTTP/1.1 200 OK
+
+
+
+
+
+
+ http://mycaldav/caldav.php/resource2/home/
+ resource2
+
+ HTTP/1.1 200 OK
+
+
+
+
+
+
+ http://mycaldav/caldav.php/resmgr1/home/
+ resmgr1
+
+ HTTP/1.1 200 OK
+
+
+
+
+
+
+ http://mycaldav/caldav.php/teamclient1/home/
+ teamclient1
+
+ HTTP/1.1 200 OK
+
+
+
diff --git a/testing/tests/regression-suite/861-Spec-REPORT-principal.test b/testing/tests/regression-suite/861-Spec-REPORT-principal.test
new file mode 100644
index 00000000..504baa53
--- /dev/null
+++ b/testing/tests/regression-suite/861-Spec-REPORT-principal.test
@@ -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
+
+
+
+
+
+
+
+
+
+
+
+ENDDATA
diff --git a/testing/tests/regression-suite/862-Spec-REPORT-principal.result b/testing/tests/regression-suite/862-Spec-REPORT-principal.result
new file mode 100644
index 00000000..718b1ae4
--- /dev/null
+++ b/testing/tests/regression-suite/862-Spec-REPORT-principal.result
@@ -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"
+
+
+
+
+
+
+
+ http://mycaldav/caldav.php/user1/home/
+ user1
+
+
+
+ http://mycaldav/caldav.php/user1/
+
+
+
+ http://mycaldav/caldav.php/resmgr1/
+ http://mycaldav/caldav.php/teamclient1/
+
+
+ HTTP/1.1 200 OK
+
+
+
diff --git a/testing/tests/regression-suite/862-Spec-REPORT-principal.test b/testing/tests/regression-suite/862-Spec-REPORT-principal.test
new file mode 100644
index 00000000..be6feab7
--- /dev/null
+++ b/testing/tests/regression-suite/862-Spec-REPORT-principal.test
@@ -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
+
+
+
+
+
+
+ user1
+
+
+
+
+
+
+
+
+
+
+
+ENDDATA
diff --git a/testing/tests/regression-suite/863-Spec-REPORT-principal.result b/testing/tests/regression-suite/863-Spec-REPORT-principal.result
new file mode 100644
index 00000000..d48a7cd4
--- /dev/null
+++ b/testing/tests/regression-suite/863-Spec-REPORT-principal.result
@@ -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"
+
+
+
+
+
+
+
+ http://mycaldav/caldav.php/resmgr1/home/
+ resmgr1
+
+
+
+ http://mycaldav/caldav.php/resmgr1/
+
+
+ http://mycaldav/caldav.php/user1/
+ http://mycaldav/caldav.php/user2/
+ http://mycaldav/caldav.php/assistant1/
+
+
+
+ HTTP/1.1 200 OK
+
+
+
diff --git a/testing/tests/regression-suite/863-Spec-REPORT-principal.test b/testing/tests/regression-suite/863-Spec-REPORT-principal.test
new file mode 100644
index 00000000..a62376cc
--- /dev/null
+++ b/testing/tests/regression-suite/863-Spec-REPORT-principal.test
@@ -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
+
+
+
+
+
+
+ resmgr1
+
+
+
+
+
+
+
+
+
+
+
+ENDDATA