From 6726a464fbb5f11868f50aef3ee26a80e4760686 Mon Sep 17 00:00:00 2001 From: mguessan Date: Thu, 19 Mar 2009 14:07:49 +0000 Subject: [PATCH] Caldav: Improve principal error handling git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@467 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/caldav/CaldavConnection.java | 59 +++++++++++-------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/src/java/davmail/caldav/CaldavConnection.java b/src/java/davmail/caldav/CaldavConnection.java index 3136754d..dd1127d3 100644 --- a/src/java/davmail/caldav/CaldavConnection.java +++ b/src/java/davmail/caldav/CaldavConnection.java @@ -529,37 +529,43 @@ public class CaldavConnection extends AbstractConnection { actualPrincipal = session.getEmail(); } - CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS); - response.startMultistatus(); - response.startResponse("/principals/users/" + principal); - response.startPropstat(); + if (!session.getEmail().equals(principal)) { + String message = "Invalid principal path, try /principals/users/" + session.getEmail(); + DavGatewayTray.error(message); + sendErr(HttpStatus.SC_NOT_FOUND, message); + } else { + CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS); + response.startMultistatus(); + response.startResponse("/principals/users/" + principal); + response.startPropstat(); - if (request.hasProperty("calendar-home-set")) { - response.appendProperty("C:calendar-home-set", "/users/" + actualPrincipal + "/calendar"); - } + if (request.hasProperty("calendar-home-set")) { + response.appendProperty("C:calendar-home-set", "/users/" + actualPrincipal + "/calendar"); + } - if (request.hasProperty("calendar-user-address-set")) { - response.appendProperty("C:calendar-user-address-set", "mailto:" + actualPrincipal + ""); - } + if (request.hasProperty("calendar-user-address-set")) { + response.appendProperty("C:calendar-user-address-set", "mailto:" + actualPrincipal + ""); + } - if (request.hasProperty("schedule-inbox-URL")) { - response.appendProperty("C:schedule-inbox-URL", "/users/" + actualPrincipal + "/inbox"); - } + if (request.hasProperty("schedule-inbox-URL")) { + response.appendProperty("C:schedule-inbox-URL", "/users/" + actualPrincipal + "/inbox"); + } - if (request.hasProperty("schedule-outbox-URL")) { - response.appendProperty("C:schedule-outbox-URL", "/users/" + actualPrincipal + "/outbox"); - } + if (request.hasProperty("schedule-outbox-URL")) { + response.appendProperty("C:schedule-outbox-URL", "/users/" + actualPrincipal + "/outbox"); + } - if (request.hasProperty("displayname")) { - response.appendProperty("D:displayname", actualPrincipal); + if (request.hasProperty("displayname")) { + response.appendProperty("D:displayname", actualPrincipal); + } + if (request.hasProperty("resourcetype")) { + response.appendProperty("D:resourcetype", ""); + } + response.endPropStatOK(); + response.endResponse(); + response.endMultistatus(); + response.close(); } - if (request.hasProperty("resourcetype")) { - response.appendProperty("D:resourcetype", ""); - } - response.endPropStatOK(); - response.endResponse(); - response.endMultistatus(); - response.close(); } public void sendFreeBusy(String body) throws IOException { @@ -832,8 +838,9 @@ public class CaldavConnection extends AbstractConnection { public void write(int b) throws IOException { throw new UnsupportedOperationException(); } + @Override - public void close() throws IOException{ + public void close() throws IOException { sendClient("0"); sendClient(""); }