Code review and stylistic changes. Better error reporting.

This commit is contained in:
Andrew McMillan 2006-10-11 14:01:19 +13:00
parent b84f7987b5
commit 424c6ada91

View File

@ -4,29 +4,43 @@ dbg_error_log("get", "GET method handler");
// The GET method is not sent with any wrapping XML so we simply fetch it // The GET method is not sent with any wrapping XML so we simply fetch it
$get_path = $_SERVER['PATH_INFO']; $qry = new PgQuery( "SELECT * FROM caldav_data WHERE user_no = ? AND dav_name = ? ;", $session->user_no, $request_path);
$qry = new PgQuery( "SELECT * FROM caldav_data WHERE user_no = ? AND dav_name = ? ;", $session->user_no, $get_path);
dbg_error_log("get", "%s", $qry->querystring ); dbg_error_log("get", "%s", $qry->querystring );
if ( $qry->Exec("GET") && $qry->rows == 1 ) { if ( $qry->Exec("GET") && $qry->rows == 1 ) {
$event = $qry->Fetch(); $event = $qry->Fetch();
/**
* FIXME: There may be some circumstances where someone wants to send
* an If-Match or If-None-Match header. I'm not sure what that means here,
* so we will leave it unimplemented at this point.
*/
header("HTTP/1.1 200 OK"); header("HTTP/1.1 200 OK");
header("ETag: \"$event->dav_etag\""); header("ETag: \"$event->dav_etag\"");
header("Content-Type: text/calendar"); header("Content-type: text/calendar");
print $event->caldav_data; echo $event->caldav_data;
dbg_error_log( "GET", "User: %d, ETag: %s, Path: %s", $session->user_no, $event->dav_etag, $get_path); dbg_error_log( "GET", "User: %d, ETag: %s, Path: %s", $session->user_no, $event->dav_etag, $get_path);
} }
else if ( $qry->rows != 1 ) { else if ( $qry->rows < 1 ) {
header("HTTP/1.1 404 Not Found");
header("Content-type: text/plain");
echo "Calendar Resource Not Found.";
dbg_error_log("ERROR", "No rows match for User: %d, ETag: %s, Path: %s", $session->user_no, $event->dav_etag, $get_path);
}
else if ( $qry->rows > 1 ) {
header("HTTP/1.1 500 Internal Server Error"); header("HTTP/1.1 500 Internal Server Error");
header("Content-type: text/plain");
echo "Database Error - Multiple Rows Match";
dbg_error_log("ERROR", "Multiple rows match for User: %d, ETag: %s, Path: %s", $session->user_no, $event->dav_etag, $get_path); dbg_error_log("ERROR", "Multiple rows match for User: %d, ETag: %s, Path: %s", $session->user_no, $event->dav_etag, $get_path);
} }
else { else {
header("HTTP/1.1 500 Infernal Server Error"); header("HTTP/1.1 500 Infernal Server Error");
dbg_error_log("get", "Infernal Server Error"); header("Content-type: text/plain");
echo "Database Error";
dbg_error_log("get", "Database Error");
} }
?> ?>