Remerge caldav + fixes (i.e. bug 208, bug 1908, bug 2129, bug 2221, bug 2801) RCL_3 PDK_3.0.1
authorDario Sestito <darios@symbian.org>
Mon, 12 Jul 2010 17:26:07 +0100
branchRCL_3
changeset 52 e3c9f8706792
parent 48 bf573002ff72 (current diff)
parent 43 51372538e3d3 (diff)
child 62 240da2698c91
Remerge caldav + fixes (i.e. bug 208, bug 1908, bug 2129, bug 2221, bug 2801)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/group/CalDavClient.mmp	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,34 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: This is the project specification file for the
+*				Caldav client library
+*/
+
+TARGET        CalDavClient.dll
+TARGETTYPE    dll
+UID 0 0x2002B71F
+
+SOURCEPATH    ..\src
+SOURCE        CalDavClient.cpp caldavsession.cpp caldavsessionimpl.cpp caldavutils.cpp
+
+USERINCLUDE   ..\inc
+APP_LAYER_SYSTEMINCLUDE
+
+LIBRARY       euser.lib
+LIBRARY       bafl.lib
+LIBRARY http.lib	
+
+EXPORTUNFROZEN
+
+CAPABILITY	CAP_APPLICATION NetworkControl
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/group/CalDavServer.mmp	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,40 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: This is the project specification file for the
+*				Caldav server
+*/ 
+
+TARGET        !CalDavServer.exe
+TARGETTYPE    exe
+UID           0	0x2002B71E
+
+SOURCEPATH    ../src
+SOURCE        CalDavServer.cpp caldavutils.cpp httpclient.cpp CalDavServerSession.cpp caldavengine.cpp caldavenginemgr.cpp
+
+USERINCLUDE   ../inc
+USERINCLUDE   ../../../calendarui/globaldata/inc
+
+APP_LAYER_SYSTEMINCLUDE
+
+LIBRARY			euser.lib apparc.lib cone.lib eikcore.lib avkon.lib charconv.lib
+LIBRARY			commonengine.lib efsrv.lib estor.lib eikcoctl.lib eikdlg.lib 
+LIBRARY			eikctl.lib bafl.lib fbscli.lib aknnotify.lib aknicon.lib
+LIBRARY			etext.lib gdi.lib egul.lib insock.lib
+LIBRARY			ecom.lib InetProtUtil.lib http.lib esock.lib xmlengineDOM.lib calinterimapi.lib calenimp.lib CalenInterimUtils2.lib commdb.lib calenglobaldata.lib
+LIBRARY			extendedconnpref.lib netmeta.lib
+
+EPOCHEAPSIZE        0x5000 0x400000
+EPOCSTACKSIZE        0x5000
+
+CAPABILITY ReadDeviceData ReadUserData WriteDeviceData WriteUserData ProtServ NetworkServices
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/group/CalDavTest.mmp	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,45 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: This is the project specification file for the
+*				Caldav test application
+*/
+
+TARGET		  CalDavTest.exe
+TARGETTYPE	  exe
+UID			 0 0x2002B81C
+
+USERINCLUDE	 ..\inc
+USERINCLUDE   ..\..\..\calendarui\globaldata\inc
+
+APP_LAYER_SYSTEMINCLUDE
+
+SOURCEPATH	  	..\src
+SOURCE			caldavengine.cpp httpclient.cpp caldavutils.cpp
+
+SOURCEPATH	  	..\tsrc
+SOURCE			CalDavTest.cpp
+
+LIBRARY			euser.lib apparc.lib cone.lib eikcore.lib avkon.lib charconv.lib
+LIBRARY			commonengine.lib efsrv.lib estor.lib eikcoctl.lib eikdlg.lib 
+LIBRARY			eikctl.lib bafl.lib fbscli.lib aknnotify.lib aknicon.lib
+LIBRARY			etext.lib gdi.lib egul.lib insock.lib
+LIBRARY			ecom.lib InetProtUtil.lib http.lib esock.lib xmlengineDOM.lib calinterimapi.lib calenimp.lib CalenInterimUtils2.lib commdb.lib flogger.lib 
+LIBRARY			caldavclient.lib
+LIBRARY			calenglobaldata.lib
+LIBRARY			extendedconnpref.lib netmeta.lib
+
+EPOCHEAPSIZE        0x5000 0x400000
+EPOCSTACKSIZE        0x5000
+
+CAPABILITY NetworkServices ReadDeviceData ReadUserData WriteDeviceData WriteUserData
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/group/bld.inf	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,27 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: provides the information required for building
+*				caldav engine
+*/
+
+PRJ_PLATFORMS
+DEFAULT
+
+PRJ_MMPFILES
+CalDavClient.mmp
+CalDavServer.mmp
+CalDavTest.mmp
+
+PRJ_EXPORTS
+../inc/caldavsession.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/inc/CalDavTest.h	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,103 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: Caldav Test Suite
+*
+*/
+
+#ifndef __CALDAVTEST_H__
+#define __CALDAVTEST_H__
+
+//  Include Files
+
+#include <e32base.h>
+#include <e32cons.h>			// Console
+#include <flogger.h>	
+
+class CCalDavEngine;
+class CCalDavSession;
+
+class CalDavTest
+	{
+public:
+	CalDavTest(CConsoleBase* console);
+	~CalDavTest();
+
+	void TestGeneralEngineL();
+	void TestEngineL(TInt aSucces, const TDesC8 &aUrl, const TDesC8 &aUser,
+			const TDesC8 &aPassword, TBool aWebdavsync, TBool aCtag,
+			TBool aEvent, TBool aTodo, TBool aFreeBusy, TBool aJournal);
+	void TestClientServerL(TInt aSucces, const TDesC8 &aUrl,
+			const TDesC8 &aUser, const TDesC8 &aPassword);
+private:
+	// test client server
+
+	TInt ConfigureSessionL(TInt aSucces, const TDesC8 &aUrl,
+			const TDesC8 &aUser, const TDesC8 &aPassword);
+	void OptionSession();
+
+	void Enabled(TBool aEnabled);
+
+	// test engine
+	TInt EnableL(TInt aSucces, const TDesC8 &aUrl, const TDesC8 &aUser,
+			const TDesC8 &aPassword);
+	// use caldav engine
+	void SendL(const unsigned long localuid);
+	// use http call
+	void SendL(TBool aVEvent);
+
+	void DownloadLGetL(const unsigned long localuid);
+	void DownloadLMultiGetL(const unsigned long localuid);
+
+	// use http call
+	void DeleteServerL();
+	// use caldav engine
+	void DeleteServerL(const unsigned long localuid);
+	void DeleteClientL(const TDesC8 &aUid);
+
+	void HeadL(TBool aExists, const TDesC8 &aUid);
+	void OptionsL();
+	void SyncL();
+	void DoesExistL(TBool aExists, const unsigned long localuid);
+	void DoesExistL(TBool aExists, const TDesC8 &aUID);
+	void CTagL(TBool aEqual);
+	void SynctokenL(TBool aEqual);
+
+	void MkCalendarL(TBool aSuccess, const TDesC8 &aName);
+	void DeleteCalendarL(const TDesC8 &aName);
+
+	void CalendarInfoL();
+	void GetUIDByUrl();
+	void GetBaseUrl();
+
+	void Write(const TDesC &aMessage);
+	void Write(TBool aSuccess, const char* aMessage);
+	void Write(TBool aSuccess, const TDesC &aMessage);
+
+	TBool iWebdavSync;
+	TBool iCtag;
+
+	TBool iVEVENT;
+	TBool iVTODO;
+	TBool iVJOURNAL;
+	TBool iVFREEBUSY;
+
+	CCalDavEngine* iEngine;
+	CCalDavSession* iSession;
+	CConsoleBase* iConsole;
+	RFileLogger iFileLogger;
+	};
+
+GLDEF_C TInt E32Main();
+
+#endif  // __CALDAVTEST_H__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/inc/caldavclient.h	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,74 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: provides a client API for Caldav server
+*
+*/
+
+#ifndef _CALDAVCLIENT_H
+#define _CALDAVCLIENT_H
+
+#include <e32base.h>
+
+//**********************************
+//RCalDavServer
+//**********************************
+
+static TInt StartServer();
+
+class RCalDavServer : public RSessionBase
+	{
+public:
+	RCalDavServer();
+	TInt Connect();
+
+	TInt Enable(const TDesC &aCalendar);
+	TInt Disable(const TDesC &aCalendar);
+
+	TInt EnabledSync(const TDesC &aCalendar, TBool &aEnabled);
+
+	TInt Sync(const TDesC &aCalendar);
+	TInt SyncAll();
+
+	TInt Url(const TDesC &aCalendar, TDes8 &aUrl);
+	TInt SetUrl(const TDesC &aCalendar, const TDesC8 &aUrl);
+
+	TInt Username(const TDesC &aCalendar, TDes8 &aUsername);
+	TInt SetUsername(const TDesC &aCalendar, const TDesC8 &aUsername);
+
+	TInt Password(const TDesC &aCalendar, TDes8 &aPassword);
+	TInt SetPassword(const TDesC &aCalendar, const TDesC8 &aPassword);
+
+	TInt SyncInterval(const TDesC &aCalendar,
+			TTimeIntervalMinutes& aSyncInterval);
+	TInt SetSyncInterval(const TDesC &aCalendar,
+			TTimeIntervalMinutes aSyncInterval);
+
+	TInt PastDays(const TDesC &aCalendar, TTimeIntervalDays &aDays);
+	TInt SetPastDays(const TDesC &aCalendar, TTimeIntervalDays aDays);
+
+	TInt ImmediateSync(const TDesC &aCalendar, TBool &aImmediateSyc);
+	TInt SetImmediateSync(const TDesC &aCalendar, TBool aImmediateSyc);
+
+	TInt KeepServerEntry(const TDesC &aCalendar, TBool &aKeepServerEntry);
+	TInt SetKeepServerEntry(const TDesC &aCalendar, TBool aKeepServerEntry);
+
+	TVersion Version() const;
+	TInt UnsupportedRequest();
+	void BadRequest();
+
+private:
+	};
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/inc/caldavengine.h	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,239 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: main Caldav class, all magic happens here
+*
+*/
+
+#ifndef _CALSTORE_H
+#define _CALSTORE_H
+
+#include <e32base.h>
+#include <BADESCA.H>
+
+#include <calchangecallback.h>
+#include <calprogresscallback.h>
+#include <calfilechangenotification.h>
+
+#include <xmlengdomimplementation.h>
+#include <xmlengdomparser.h>
+
+#include "caldavutils.h"
+
+class CCalSession;
+class CCalEntry;
+class CCalIter;
+class CCalEntryView;
+class CCalenExporter;
+class CCalenImporter;
+class CCalenInterimUtils2;
+
+class RXmlEngDOMImplementation;
+class RXmlEngDOMParser;
+class RXmlEngDocument;
+
+class CHttpClient;
+class CalDavTest;
+
+// sync interval of 0 correspons to one minute
+// 0 actually means to enable push connectivity once supported
+#define DEFAULT_SYNC_MINUTES 		0
+#define DEFAULT_PAST_DAYS			14
+#define DEFAULT_IMMEDIATE_SYNC		ETrue
+#define DEFAULT_KEEP_SERVER_ENTRY	EFalse
+
+
+enum TLocalLoopAction
+	{
+		ELoopActionUpload, ELoopActionFillArray, ELoopActionDeleteLocal
+	};
+
+/**
+ *  CCalDavEngine
+ * 
+ */
+class CCalDavEngine : public CBase, MCalProgressCallBack, MCalChangeCallBack2, MCalFileChangeObserver
+	{
+public:
+
+	friend class CalDavTest;
+
+	~CCalDavEngine();
+
+	static CCalDavEngine* NewL(const TDesC& aCalendar);
+	static CCalDavEngine* NewLC(const TDesC& aCalendar);
+
+	TInt EnableL();
+	void DisableL();
+	TBool EnabledSync();
+
+	TInt SyncL();
+
+	TInt MkcalendarL(const TDesC8 &aName);
+	TInt DeleteCalendarL(const TDesC8 &aName);
+
+	TPtrC CalendarName() const;
+	TPtrC8 Home() const;
+
+	TPtrC8 Url() const;
+	void SetUrlL(const TDesC8 &aUrl);
+
+	TPtrC8 User() const;
+	void SetUserL(const TDesC8 &aUser);
+
+	TPtrC8 Password() const;
+	void SetPasswordL(const TDesC8 &aPassword);
+
+	TTimeIntervalMinutes SyncInterval() const;
+	void SetSyncIntervalL(TTimeIntervalMinutes aSyncInterval);
+
+	TTimeIntervalDays PastDays() const;
+	void SetPastDaysL(TTimeIntervalDays aDays);
+
+	TBool ImmediateSync() const;
+	void SetImmediateSyncL(TBool aImmediateSyc);
+
+	TBool KeepServerEntry() const;
+	void SetKeepServerEntryL(TBool aKeepServerEntry);
+
+	CPeriodic* Timer();
+
+	TPtrC8 SyncToken();
+	TPtrC8 CTag();
+
+private:
+
+	CCalDavEngine();
+	void ConstructL(const TDesC& aCalendar);
+
+	void RegisterL();
+	HBufC8* GetCTagL();
+	HBufC8* GetSyncTokenL();
+
+	TInt InitL();
+
+	// Called during calendar entry view creation
+	void Progress(TInt aPercentageCompleted);
+	void Completed(TInt aError);
+	TBool NotifyProgress();
+	void CalChangeNotification(RArray<TCalChangeEntry> &aChangeItems);
+	void CalendarInfoChangeNotificationL(RPointerArray<CCalFileChangeInfo>& aCalendarInfoChangeEntries);
+
+	void CalendarInfoL();
+	void SetCalendarInfoL(const TDesC8 &aKey, const TDesC8 &aValue);
+
+	void HandleCalendarInfoChangeL();
+	void HandleChangeL(MCalChangeCallBack2::TChangeType &aChangeType,
+			MCalChangeCallBack2::TChangeEntryType &aEntryType,
+			TCalLocalUid &aUid);
+
+	TBool ManualSyncL();
+	TBool WebDavSyncL();
+	TInt WebDavSyncReportL(TBool aSynctoken);
+	TBool UploadModifiedSinceDateL();
+	TBool ClientChangesL();
+	TBool ServerChangesL();
+	TInt DeleteRemovedEntriesOnServerL();
+	TInt LocalLoopL(TLocalLoopAction aAction);
+	
+	TInt ListL();
+	TInt TimeReportL(TBool VEVENT, const TDesC8 &aStart, TBool aDelete = EFalse);
+
+	// server actions
+	TInt UploadEntryL(const TCalLocalUid &aUid,
+			MCalChangeCallBack2::TChangeType aChangeType,
+			MCalChangeCallBack2::TChangeEntryType aEntryType);
+	TInt UploadEntryL(CCalEntry* aEntry,
+			MCalChangeCallBack2::TChangeType aChangeType,
+			MCalChangeCallBack2::TChangeEntryType aEntryType);
+	TInt DownloadEntryL(const TDesC8 &aUrl);
+	TInt DownloadEntryL(CDesC8Array* aArray);
+	TInt DeleteEntryL(const TCalLocalUid &aUid);
+	TInt DeleteEntryL(const TDesC8 &aUid);
+	TInt HeadL(const TDesC8 &aUID);
+
+	// local actions
+	TInt AddModifyLocalEntryL(const TDesC8 &aUrl, const TDesC8 &aETag,
+			CDesC8ArrayFlat* aArray);
+	TInt DeleteLocalEntryL(const TDesC8 &aUID);
+
+	TInt ParseResponsesDeleteL(const TDesC8 &aDocument);
+	TInt ParseResponsesL(RXmlEngDocument &aDocument, TBool aMultiget = EFalse);
+	TInt ParseResponsesL(const TDesC8 &aDocument, TBool aMultiget = EFalse);
+	
+	unsigned long DoesEntryExistL(const TDesC8 &aUrl);
+	TPtrC8 GetUIDByUrl(const TDesC8 &aUrl);
+	TBool ETagMatchL(const TDesC8& aUrl, const TDesC8& aETag);
+	TInt StoreEntryL(const TDesC8 &aBuf, const TDesC8 &aEtag);
+
+	void SyncFailedL();
+	void SetLastSyncTimeL();
+	void SetSyncTokenL(HBufC8* aToken);
+	void SetCTagL(HBufC8* aToken);
+
+	void CheckCalendarInfoL(RXmlEngDocument &aDocument);
+	
+	TBool GetOptionsL();
+	TInt GetCalendarUrlsL(CDesC8ArrayFlat *aArray);
+	void FindUrlsL(const TDesC8 &aDes, HBufC8 *&home, HBufC8 *&inbox,
+			HBufC8 *&outbox);
+	void GetBaseUrl(const TDesC8 &aUrl);
+	HBufC8 * FindCalendarCollectionL(const TDesC8 &aUrl,
+			CDesC8ArrayFlat *aArray);
+	
+	void DeleteCalObjects();
+	TInt CreateCalObjectsL();
+	
+	CCalSession* iCalSession;
+	CCalIter* iCalIter;
+	CCalEntryView* iCalEntryView;
+	CCalenExporter* iCalExporter;
+	CCalenImporter* iCalImporter;
+	CCalenInterimUtils2* iCalIntermimUtils2;
+	HBufC *iCalendar;
+	HBufC8 *iUrl;
+	HBufC8 *iBaseUrl;
+	HBufC8 *iHome;
+
+	TCalDAVOptions iOptions;
+	CHttpClient* iHttp;
+
+	RXmlEngDOMImplementation iDomImpl;
+	RXmlEngDOMParser iDomParser;
+
+	// when we get a callback with a localuid, the corresponding entry is already deleted
+	// we therefore need a different way to map from localuid to global uid/filename
+	// this can be completly removed when introducing a new callback,
+	// which includes the to be deleted localuid
+	RArray<TCalLocalUid> iLocalUidArray;
+	RArray<TBuf8<100> > iGlobalUidArray;
+	//
+	RArray<TCalLocalUid> iDeletedEntries;
+
+	HBufC8 *iSynctoken;
+	HBufC8 *iCTag;
+	TBool iManualSync;
+	TCalTime iLastSyncTime;
+	TBool iFirstInit;
+
+	// Options
+	TTimeIntervalMinutes iSyncInterval;
+	TTimeIntervalDays iPastDays;
+	TBool iImmediateSync;
+	TBool iKeepServerEntry;
+	TBool iEnabled;
+
+	CPeriodic* iTimer;
+	};
+
+#endif // CALSTORE_H
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/inc/caldavenginemgr.h	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,86 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: provides a manager to keep track of all available engines
+*
+*/
+
+#ifndef CCALDAVENGINEMGR_H
+#define CCALDAVENGINEMGR_H
+
+// INCLUDES
+#include <e32std.h>
+#include <e32base.h>
+
+#include <calprogresscallback.h>
+
+class CCalDavEngine;
+/**
+ *  CCalDavEngineMgr
+ * 
+ */
+class CCalDavEngineMgr : public CBase, MCalProgressCallBack
+	{
+public:
+
+	~CCalDavEngineMgr();
+
+	static CCalDavEngineMgr* NewL();
+	static CCalDavEngineMgr* NewLC();
+	
+	void Progress(TInt aPercentageCompleted);
+	void Completed(TInt aError);
+	TBool NotifyProgress();
+
+	TInt SyncL(const TDesC &aCalendar);
+	TInt SyncAllL();
+
+	TInt EnableL(const TDesC &aCalendar);
+	TInt DisableL(const TDesC &aCalendar);
+
+	TBool EnabledSyncL(const TDesC &aCalendar);
+
+	TPtrC8 UrlL(const TDesC &aCalendar);
+	void SetUrlL(const TDesC &aCalendar, const TDesC8 &aUrl);
+
+	TPtrC8 UsernameL(const TDesC &aCalendar);
+	void SetUsernameL(const TDesC &aCalendar, const TDesC8 &aUsername);
+
+	TPtrC8 PasswordL(const TDesC &aCalendar);
+	void SetPasswordL(const TDesC &aCalendar, const TDesC8 &aPassword);
+
+	// TODO do also if enable was not called yet? if yes, create CalDavEngine and store settings
+	TTimeIntervalMinutes SyncIntervalL(const TDesC &aCalendar);
+	void SetSyncIntervalL(const TDesC &aCalendar,
+			TTimeIntervalMinutes aSyncInterval);
+
+	TTimeIntervalDays PastDaysL(const TDesC &aCalendar);
+	void SetPastDaysL(const TDesC &aCalendar, TTimeIntervalDays aDays);
+
+	TBool ImmediateSyncL(const TDesC &aCalendar);
+	void SetImmediateSyncL(const TDesC &aCalendar, TBool aImmediateSyc);
+
+	TBool KeepServerEntryL(const TDesC &aCalendar);
+	void SetKeepServerEntryL(const TDesC &aCalendar, TBool aKeepServerEntry);
+
+private:
+
+	CCalDavEngineMgr();
+	void ConstructL();
+
+	TInt FindEngineL(const TDesC &aName, TBool aCreate = EFalse);
+	RPointerArray<CCalDavEngine> iEngines;
+
+	};
+
+#endif // CCALDAVENGINEMGR_H
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/inc/caldavserver.h	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,88 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: Caldav server, follows Symbian client/server 
+*				architecture
+*/
+
+#ifndef CCALDAVSERVER_H
+#define CCALDAVSERVER_H
+
+#include <e32base.h>
+
+#include "caldavutils.h"
+
+class CCalDavEngineMgr;
+
+// needed for creating server thread.
+const TUint KDefaultHeapSize = 0x10000;
+
+//**********************************
+//CCalDavServer
+//**********************************
+class CCalDavServer : public CPolicyServer
+	{
+public:
+	static CCalDavServer* NewLC();
+	static TInt ThreadFunction(TAny* aStarted);
+	static void PanicServer(TCalDavServPanic aPanic);
+	CSession2
+			* NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const;
+public:
+
+	TInt EnableL(const TDesC &aCalendar);
+	TInt DisableL(const TDesC &aCalendar);
+
+	TBool EnabledSyncL(const TDesC &aCalendar) const;
+
+	// TODO: make these asynchronous
+	TInt SyncL(const TDesC &aCalendar);
+	TInt SyncAllL();
+
+	TPtrC8 UrlL(const TDesC &aCalendar);
+	void SetUrlL(const TDesC &aCalendar, const TDesC8 &aUrl);
+
+	TPtrC8 UsernameL(const TDesC &aCalendar);
+	void SetUsernameL(const TDesC &aCalendar, const TDesC8 &aUsername);
+
+	TPtrC8 PasswordL(const TDesC &aCalendar);
+	void SetPasswordL(const TDesC &aCalendar, const TDesC8 &aPassword);
+
+	TTimeIntervalMinutes SyncIntervalL(const TDesC &aCalendar) const;
+	void SetSyncIntervalL(const TDesC &aCalendar,
+			TTimeIntervalMinutes aSyncInterval);
+
+	TTimeIntervalDays PastDaysL(const TDesC &aCalendar) const;
+	void SetPastDaysL(const TDesC &aCalendar, TTimeIntervalDays aDays);
+
+	TBool ImmediateSyncL(const TDesC &aCalendar) const;
+	void SetImmediateSyncL(const TDesC &aCalendar, TBool aImmediateSyc);
+
+	TBool KeepServerEntryL(const TDesC &aCalendar) const;
+	void SetKeepServerEntryL(const TDesC &aCalendar, TBool aKeepServerEntry);
+
+private:
+
+private:
+	static void ThreadFunctionL();
+	~CCalDavServer();
+	CCalDavServer();
+
+	CCalDavEngineMgr* iMgr;
+
+protected:
+	void ConstructL();
+	CCalDavServer(CActive::TPriority aActiveObjectPriority);
+	};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/inc/caldavserversession.h	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,91 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: Caldav server session, follows Symbian 
+* 				client/server architecture
+*
+*/
+
+#ifndef CCALDAVSERVERSESSION_H
+#define CCALDAVSERVERSESSION_H
+
+#include <e32base.h>
+
+class CCalDavServer;
+
+//**********************************
+//CCalDavServerSession
+//**********************************
+/**
+ This class represents a session with the  server.
+ Functions are provided to respond appropriately to client messages.
+ */
+class CCalDavServerSession : public CSession2
+	{
+public:
+	CCalDavServerSession(CCalDavServer &aServer);
+	void ServiceL(const RMessage2& aMessage);
+
+	void EnableL(const RMessage2& aMessage);
+	void DisableL(const RMessage2& aMessage);
+
+	void SyncL(const RMessage2& aMessage);
+	void SyncAllL(const RMessage2& aMessage);
+
+	void UrlL(const RMessage2& aMessage);
+	void SetUrlL(const RMessage2& aMessage);
+
+	void UsernameL(const RMessage2& aMessage);
+	void SetUsernameL(const RMessage2& aMessage);
+
+	void PasswordL(const RMessage2& aMessage);
+	void SetPasswordL(const RMessage2& aMessage);
+
+	void SyncIntervalL(const RMessage2& aMessage);
+	void SetSyncIntervalL(const RMessage2& aMessage);
+
+	void PastDaysL(const RMessage2& aMessage);
+	void SetPastDaysL(const RMessage2& aMessage);
+
+	void ImmediateSyncL(const RMessage2& aMessage);
+	void SetImmediateSyncL(const RMessage2& aMessage);
+
+	void KeepServerEntryL(const RMessage2& aMessage);
+	void SetKeepServerEntryL(const RMessage2& aMessage);
+
+	void EnabledSyncL(const RMessage2& aMessage);
+
+	// still there from symbian count example, not part of caldav 
+	void SetFromStringL(const RMessage2& aMessage);
+	void Increase();
+	void Decrease();
+	void IncreaseBy(const RMessage2& aMessage);
+	void DecreaseBy(const RMessage2& aMessage);
+	void CounterValueL(const RMessage2& aMessage);
+	void Reset();
+	/********************************************************/
+
+protected:
+	// panic the client
+	void PanicClient(const RMessage2& aMessage, TInt aPanic) const;
+
+private:
+	void DispatchMessageL(const RMessage2& aMessage);
+
+	CCalDavServer& rServer;
+	TInt iCount;
+
+	};
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/inc/caldavsession.h	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,202 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: 	Client API to connect to Caldav server
+*				Wrapper around RCalDavServer
+*/
+
+#ifndef CCALDAVSESSION_H
+#define CCALDAVSESSION_H
+
+// INCLUDES
+#include <e32std.h>
+#include <e32base.h>
+
+class CCalDavSessionImpl;
+
+/**
+ * @class CCalenCustomisation 
+ * @brief Client API to connect to the CalDAV server.
+ */
+NONSHARABLE_CLASS( CCalDavSession ) : public CBase
+	{
+public:
+	/** Allocates and constructs a session to the Calendar server.
+	 * @return Pointer to the newly created session.
+	 */
+	IMPORT_C static CCalDavSession* NewL();
+	/** 	Allocates and constructs a session to the Calendar server.
+	 @return Pointer to the newly created session.
+	 */
+	IMPORT_C static CCalDavSession* NewLC();
+	
+	/**
+	 * 	standard destructor, close session with CalDavServer
+	 */
+	IMPORT_C ~CCalDavSession();
+
+	/**
+	 Enable access to a remote CalDAV server. At least url, 
+	 username and password need to be set first.
+	 
+	 @param aCalendar calendar to enable, must be internal filename in the form c:calendar
+	 */
+	IMPORT_C TInt Enable(const TDesC &aCalendar);
+	/**
+	 Disable access to a remote CalDAV server.
+	 
+	 @param aCalendar calendar to disable, must be internal filename in the form c:calendar
+	 */
+	IMPORT_C TInt Disable(const TDesC &aCalendar);
+
+	/**
+	 On demand syncing of an enabled connection of one calendar file
+	 
+	 @param aCalendar calendar to enable, must be internal filename in the form c:calendar
+	 */
+	IMPORT_C TInt SyncL(const TDesC &aCalendar);
+	/**
+	 On demand syncing of all enabled connections 
+	 */
+	IMPORT_C TInt SyncAllL();
+
+	/**
+	 Retrieve connection url
+	 
+	 @param aCalendar calendar for sync, must be internal filename in the form c:calendar
+	 @param aUrl url for the connection
+	 */
+	IMPORT_C TInt Url(const TDesC &aCalendar, TDes8 &aUrl);
+	/**
+	 Set connection url
+	 
+	 @param aCalendar calendar for sync, must be internal filename in the form c:calendar
+	 @param aUrl url for the url
+	 */
+	IMPORT_C TInt SetUrl(const TDesC &aCalendar, const TDesC8 &aUrl);
+
+	/**
+	 Retrieve connection username
+	 
+	 @param aCalendar calendar for sync, must be internal filename in the form c:calendar
+	 @param aUsername username for the connection
+	 */
+
+	IMPORT_C TInt Username(const TDesC &aCalendar, TDes8 &aUsername);
+	/**
+	 Set connection username
+	 
+	 @param aCalendar calendar for sync, must be internal filename in the form c:calendar
+	 @param aUsername username for the connection
+	 */
+	IMPORT_C TInt SetUsername(const TDesC &aCalendar, const TDesC8 &aUsername);
+
+	/**
+	 Retrieve connection password
+	 
+	 @param aCalendar calendar for sync, must be internal filename in the form c:calendar
+	 @param aPassword password for the connection
+	 */
+
+	IMPORT_C TInt Password(const TDesC &aCalendar, TDes8 &aPassword);
+	/**
+	 Set connection password
+	 
+	 @param aCalendar calendar for sync, must be internal filename in the form c:calendar
+	 @param aPassword password for the connection
+	 */
+	IMPORT_C TInt SetPassword(const TDesC &aCalendar, const TDesC8 &aPassword);
+	/**
+	 Retrieve synchonization interval
+	 
+	 @param aCalendar calendar for sync, must be internal filename in the form c:calendar
+	 @param aSyncInterval sync interval for the connection
+	 */
+
+	IMPORT_C TInt SyncInterval(const TDesC &aCalendar,
+			TTimeIntervalMinutes& aSyncInterval);
+	/**
+	 Set synchonization interval
+	 
+	 @param aCalendar calendar for sync, must be internal filename in the form c:calendar
+	 @param aSyncInterval sync interval for the connection, value of zero minutes meaning 
+	 continuous connection
+	 */
+	IMPORT_C TInt SetSyncInterval(const TDesC &aCalendar,
+			TTimeIntervalMinutes aSyncInterval);
+
+	/**
+	 Retrieve time range into past for synchronization
+	 
+	 @param aCalendar calendar for sync, must be internal filename in the form c:calendar
+	 @param aDays number of days into the past for the connection
+	 */
+	IMPORT_C TInt PastDays(const TDesC &aCalendar, TTimeIntervalDays &aDays);
+	/**
+	 Set time range into past for synchronization
+	 
+	 @param aCalendar calendar for sync, must be internal filename in the form c:calendar
+	 @param aDays number of days into the past for the connection
+	 */
+	IMPORT_C TInt SetPastDays(const TDesC &aCalendar, TTimeIntervalDays aDays);
+
+	/**
+	 Retrieve immediate push of client changes
+	 
+	 @param aCalendar calendar for sync, must be internal filename in the form c:calendar
+	 @param aImmediateSync push client changes immediatly
+	 */
+	IMPORT_C TInt ImmediateSync(const TDesC &aCalendar, TBool &aImmediateSyc);
+	/**
+	 Set immediate push of client changes
+	 
+	 @param aCalendar calendar for sync, must be internal filename in the form c:calendar
+	 @param aImmediateSync push client changes immediatly
+	 */
+	IMPORT_C TInt SetImmediateSync(const TDesC &aCalendar, TBool aImmediateSyc);
+
+	/**
+	 During a synchronisation conflict, either the server or client needs to win, default is the server
+	 
+	 @param aCalendar calendar for sync, must be internal filename in the form c:calendar
+	 @param aKeepServerEntry server or client wins during synchronisation
+	 */
+	IMPORT_C TInt KeepServerEntry(const TDesC &aCalendar,
+			TBool &aKeepServerEntry);
+	/**
+	 During a synchronisation conflict, either the server or client needs to win, which can be set here
+	 
+	 @param aCalendar calendar for sync, must be internal filename in the form c:calendar
+	 @param aKeepServerEntry server or client wins during synchronisation
+	 */
+	IMPORT_C TInt SetKeepServerEntry(const TDesC &aCalendar,
+			TBool aKeepServerEntry);
+
+	/**
+	 Retrieve connection status
+	 
+	 @param aCalendar calendar for sync, must be internal filename in the form c:calendar
+	 @param aEnabledSync connection status
+	 */
+	IMPORT_C TInt EnabledSync(const TDesC &aCalendar, TBool &aEnabledSync);
+
+private:
+
+	CCalDavSession();
+	void ConstructL();
+
+	CCalDavSessionImpl* iImpl;
+
+	};
+
+#endif // CCALDAVSESSION_H
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/inc/caldavsessionimpl.h	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,82 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: 	Client API implementation
+*				Wrapper around RCalDavServer
+*/
+
+#ifndef CCALDAVSESSIONIMPL_H
+#define CCALDAVSESSIONIMPL_H
+
+// INCLUDES
+#include <e32std.h>
+#include <e32base.h>
+
+class RCalDavServer;
+
+// CLASS DECLARATION
+
+/**
+ *  CCalDavSessionImpl
+ * 
+ */
+class CCalDavSessionImpl : public CBase
+	{
+public:
+
+	~CCalDavSessionImpl();
+
+	static CCalDavSessionImpl* NewL();
+	static CCalDavSessionImpl* NewLC();
+
+	TInt Enable(const TDesC &aCalendar);
+	TInt Disable(const TDesC &aCalendar);
+
+	TInt SyncL(const TDesC &aCalendar);
+	TInt SyncAllL();
+
+	TInt Url(const TDesC &aCalendar, TDes8 &aUrl);
+	TInt SetUrl(const TDesC &aCalendar, const TDesC8 &aUrl);
+
+	TInt Username(const TDesC &aCalendar, TDes8 &aUsername);
+	TInt SetUsername(const TDesC &aCalendar, const TDesC8 &aUsername);
+
+	TInt Password(const TDesC &aCalendar, TDes8 &aPassword);
+	TInt SetPassword(const TDesC &aCalendar, const TDesC8 &aPassword);
+
+	TInt SyncInterval(const TDesC &aCalendar,
+			TTimeIntervalMinutes& aSyncInterval);
+	TInt SetSyncInterval(const TDesC &aCalendar,
+			TTimeIntervalMinutes aSyncInterval);
+
+	TInt PastDays(const TDesC &aCalendar, TTimeIntervalDays &aDays);
+	TInt SetPastDays(const TDesC &aCalendar, TTimeIntervalDays aDays);
+
+	TInt ImmediateSync(const TDesC &aCalendar, TBool &aImmediateSyc);
+	TInt SetImmediateSync(const TDesC &aCalendar, TBool aImmediateSyc);
+
+	TInt KeepServerEntry(const TDesC &aCalendar, TBool &aKeepServerEntry);
+	TInt SetKeepServerEntry(const TDesC &aCalendar, TBool aKeepServerEntry);
+
+	TInt EnabledSync(const TDesC &aCalendar, TBool &aEnabledSync);
+
+private:
+
+	CCalDavSessionImpl();
+	void ConstructL();
+
+	RCalDavServer* iServer;
+
+	};
+
+#endif // CCALDAVSESSIONIMPL_H
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/inc/caldavutils.h	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,251 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: 	various utility classes and functions
+*				used in Caldav client and server code
+*/
+
+#ifndef CALDAVUTILS_H
+#define CALDAVUTILS_H
+
+// INCLUDES
+#include <e32std.h>
+#include <e32base.h>
+
+// CLASS DECLARATION
+class RHTTPTransaction;
+
+_LIT(KCalDavServerName,"!CalDavServer");
+_LIT(KCalDavServerFilename,"!CalDavServer.exe");
+_LIT8(KUserAgent, "Symbian 1.0");
+
+const TUint KCalDavServerMajorVersionNumber = 1;
+const TUint KCalDavServerMinorVersionNumber = 0;
+const TUint KCalDavServerBuildVersionNumber = 0;
+
+enum TCalDavServReq
+	{
+	ECalDavCreate = 1,
+	ECalDavClose,
+	ECalDavUnsupportedRequest,
+	ECalDavEnable,
+	ECalDavDisable,
+	ECalDavMkCalendar,
+	ECalDavDeleteCalendar,
+	ECalDavSyncAll,
+	ECalDavSync,
+	ECalDavUrl,
+	ECalDavSetUrl,
+	ECalDavUsername,
+	ECalDavSetUsername,
+	ECalDavPassword,
+	ECalDavSetPassword,
+	ECalDavSyncInterval,
+	ECalDavSetSyncInterval,
+	ECalDavPastDays,
+	ECalDavSetPastDays,
+	ECalDavImmediateSync,
+	ECalDavSetImmediateSync,
+	ECalDavKeepServer,
+	ECalDavSetKeepServer,
+	ECalDavEnabled
+	};
+
+enum TCalDavServLeave
+	{
+	ENonNumericString = 99
+	};
+
+// reasons for server panic
+enum TCalDavServPanic
+	{
+	EBadRequest = 1,
+	EBadDescriptor,
+	EMainSchedulerError,
+	ESvrCreateServer,
+	ESvrStartServer,
+	ECreateTrapCleanup,
+	ENotImplementedYet,
+	};
+
+struct TCalDAVOptions
+	{
+	// ALLOW header
+	TBool DELETE;
+	TBool GET;
+	TBool HEAD;
+	TBool MKCALENDAR;
+	TBool MKCOL;
+	TBool OPTIONS;
+	TBool PROPFIND;
+	TBool PROPPATCH;
+	TBool PUT;
+	TBool REPORT;
+	TBool COPY;
+	TBool POST;
+	TBool MOVE;
+	TBool ACL;
+	TBool LOCK;
+	TBool UNLOCK;
+	TBool MULTIGET;
+	TBool QUERY;
+
+	TBool VEVENT;
+	TBool VTODO;
+	TBool VFREEBUSY;
+	TBool VJOURNAL;
+
+	//DAV header
+	TBool ONE;
+	TBool TWO;
+	TBool THREE;
+	TBool access_control;
+	TBool calendar_access;
+	TBool calendar_schedule;
+	TBool calendar_auto_schedule;
+	TBool extended_mkcol;
+	TBool sync_collection;
+	TBool sync_ctag;
+	};
+_LIT8(colon,",");
+_LIT8(DAV,"DAV");
+_LIT8(ALLOW,"Allow");
+_LIT8(DELETE,"DELETE");
+_LIT8(GET,"GET");
+_LIT8(HEAD,"HEAD");
+_LIT8(MKCALENDAR,"MKCALENDAR");
+_LIT8(MKCOL,"MKCOL");
+_LIT8(OPTIONS,"OPTIONS");
+_LIT8(PROPFIND,"PROPFIND");
+_LIT8(PROPPATCH,"PROPPATCH");
+_LIT8(PUT,"PUT");
+_LIT8(REPORT,"REPORT");
+_LIT8(COPY,"COPY");
+_LIT8(POST,"POST");
+_LIT8(MOVE,"MOVE");
+_LIT8(ACL,"ACL");
+_LIT8(LOCK,"LOCK");
+_LIT8(UNLOCK,"UNLOCK");
+_LIT8(MULTIGET,"MULTIGET");
+//DAV header
+_LIT8(ZERO,"0");
+_LIT8(ONE,"1");
+_LIT8(TWO,"2");
+_LIT8(THREE,"3");
+_LIT8(access_control,"access-control");
+_LIT8(calendar_access,"calendar-access");
+_LIT8(calendar_schedule,"calendar-schedule");
+_LIT8(calendar_auto_schedule,"calendar-auto-schedule");
+_LIT8(sync_collection,"sync-collection");
+_LIT8(extended_mkcol,"extended-mkcol");
+_LIT8(KVEVENT,"VEVENT");
+_LIT8(KVTODO,"VTODO");
+_LIT8(KVJOURNAL,"VJOURNAL");
+_LIT8(KVFREBUSY,"VFREEBUSY");
+_LIT8(KDav,"DAV:");
+_LIT8(KMultistatus,"multistatus");
+_LIT8(LProp,"prop");
+_LIT8(KHref,"href");
+_LIT8(KResponse,"response");
+_LIT8(KStatus,"status");
+_LIT8(KOwner,"owner");
+_LIT8(KEtag,"getetag");
+_LIT8(KResourcetype,"resourcetype");
+_LIT8(KCalDav,"urn:ietf:params:xml:ns:caldav");
+_LIT8(KGetctag,"getctag");
+_LIT8(KSynctoken,"sync-token");
+_LIT8(KCalendarData,"calendar-data");
+_LIT8(KCalendar,"calendar");
+_LIT8(KCalendarHomeSet,"calendar-home-set");
+_LIT8(KOutbox,"schedule-outbox-URL");
+_LIT8(KInbox,"schedule-inbox-URL");
+_LIT8(KCalendarMultiget,"calendar-multiget");
+_LIT8(KCalendarQuery,"calendar-query");
+_LIT8(KDisplayname,"displayname");
+_LIT8(KSupportedCalendarComponentSet,"supported-calendar-component-set");
+_LIT8(KCalendar_Color,"calendar-color");
+
+// groupdav
+_LIT8(KVTodoCollection,"vtodo-collection");
+_LIT8(KVEventCollection,"vevent-collection");
+_LIT8(KIcs, ".ics");
+_LIT8(KUID,"UID:");
+_LIT8(KSlash,"/");
+_LIT8(KName,"name");
+_LIT8(KHrefstart,"<D:href xmlns:D=\"DAV:\">");
+_LIT8(KHrefend,"</D:href>");
+_LIT8(KMultistart,"<?xml version=\"1.0\" encoding=\"utf-8\" ?><C:calendar-multiget xmlns:C=\"urn:ietf:params:xml:ns:caldav\"><D:prop xmlns:D=\"DAV:\"><D:getetag/><C:calendar-data/></D:prop>");
+_LIT8(KMultiend,"</C:calendar-multiget>");
+_LIT8(KSync,"<?xml version=\"1.0\" encoding=\"utf-8\" ?><D:sync-collection xmlns:D=\"DAV:\"><D:sync-token>%S</D:sync-token><D:prop><D:getetag/></D:prop></D:sync-collection>");
+_LIT8(KCtag,"<?xml version=\"1.0\" encoding=\"utf-8\"?><D:propfind xmlns:C=\"urn:ietf:params:xml:ns:caldav\" xmlns:D=\"DAV:\"><D:prop><T:getctag xmlns:T=\"http://calendarserver.org/ns/\"/></D:prop></D:propfind>");
+_LIT8(KSupportedSet,"<?xml version=\"1.0\" encoding=\"utf-8\"?><D:propfind xmlns:C=\"urn:ietf:params:xml:ns:caldav\" xmlns:D=\"DAV:\"><D:prop><C:supported-calendar-component-set/><D:supported-report-set/><D:displayname/><A:calendar-color xmlns:A=\"http://apple.com/ns/ical/\"/></D:prop></D:propfind>");
+_LIT8(KCalendarurl,"<?xml version=\"1.0\" encoding=\"utf-8\"?><D:propfind xmlns:C=\"urn:ietf:params:xml:ns:caldav\" xmlns:D=\"DAV:\"><D:prop><D:owner/><D:resourcetype/></D:prop></D:propfind>");
+_LIT8(KPrincipalurl,"<?xml version=\"1.0\" encoding=\"utf-8\"?><D:propfind xmlns:C=\"urn:ietf:params:xml:ns:caldav\" xmlns:D=\"DAV:\"><D:prop><C:calendar-home-set/><C:schedule-inbox-URL/><C:schedule-outbox-URL/></D:prop></D:propfind>");
+_LIT8(KPropList,"<?xml version=\"1.0\" encoding=\"utf-8\"?><D:propfind xmlns:C=\"urn:ietf:params:xml:ns:caldav\" xmlns:D=\"DAV:\"><D:prop><D:getetag/></D:prop></D:propfind>");
+_LIT8(KTimeStartEVENT,"<?xml version=\"1.0\" encoding=\"UTF-8\"?><calendar-query xmlns:D=\"DAV:\" xmlns=\"urn:ietf:params:xml:ns:caldav\"><D:prop><D:getetag/></D:prop><filter><comp-filter name=\"VCALENDAR\"><comp-filter name=\"VEVENT\"><time-range start=");
+_LIT8(KTimeStartTODO,"<?xml version=\"1.0\" encoding=\"UTF-8\"?><calendar-query xmlns:D=\"DAV:\" xmlns=\"urn:ietf:params:xml:ns:caldav\"><D:prop><D:getetag/></D:prop><filter><comp-filter name=\"VCALENDAR\"><comp-filter name=\"VTODO\"><time-range start=");
+_LIT8(KTimeEnd," end=\"20200101T000000Z\"/></comp-filter></comp-filter></filter></calendar-query>");
+_LIT8(KTimeTest,"<?xml version=\"1.0\" encoding=\"UTF-8\"?><calendar-query xmlns:D=\"DAV:\" xmlns=\"urn:ietf:params:xml:ns:caldav\"><D:prop><D:getetag/></D:prop><filter><comp-filter name=\"VCALENDAR\"><comp-filter name=\"VEVENT\"><time-range start=\"20090509T220000Z\" end=\"20090509T220000Z\"/></comp-filter></comp-filter></filter></calendar-query>");
+
+_LIT8(KColorDisplayStart,"<?xml version=\"1.0\" encoding=\"utf-8\"?><D:propertyupdate xmlns:D=\"DAV:\"><D:set><D:prop><A:calendar-color xmlns:A=\"http://apple.com/ns/ical/\">");
+_LIT8(KColorDisplayMiddle,"</A:calendar-color><D:displayname>");
+_LIT8(KColorDisplayEnd,"</D:displayname></D:prop></D:set></D:propertyupdate>");
+
+// strings for CCalCalendarInfo Properties
+_LIT8(KCaldavEnabled,"caldavenabled");
+_LIT8(KCaldavFirstInit,"caldavfirstinit");
+_LIT8(KCaldavCtag,"caldavctag");
+_LIT8(KCaldavSynctoken,"caldavsynctoken");
+_LIT8(KCaldavManualSync,"caldavmanualsync");
+_LIT8(KCaldavTime,"caldavtime");
+_LIT8(KCaldavUser,"caldavuser");
+_LIT8(KCaldavPassword,"caldavpassword");
+_LIT8(KCaldavUrl,"caldavurl");
+_LIT8(KCaldavKeepServer,"caldavkeepserver");
+_LIT8(KCaldavImmediateSync,"caldavimmediatesync");
+_LIT8(KCaldavPastDays,"caldavpastdays");
+_LIT8(KCaldavSyncInterval,"caldavsyncinterval");
+
+class CalDavUtils : public CBase
+	{
+public:
+
+	~CalDavUtils();
+
+	static CalDavUtils* NewL();
+	static CalDavUtils* NewLC();
+
+	static void ScanDAVHeaderL(RHTTPTransaction &aTransaction,
+			TCalDAVOptions &aOptions);
+	static void ScanAllowHeaderL(RHTTPTransaction &aTransaction,
+			TCalDAVOptions &aOptions);
+	static void FixExportIssues(TDes8 &aDes);
+	static void FixImportIssues(TDes8 &aDes);
+	static void GetFileName(const TDesC8 &aIcs, TDes8 &aUrl);
+
+	static HBufC8* EnsureSlashL(HBufC8* aIn);
+	static HBufC8* CalDavUtils::EnsureSlashL(const TDesC8 &aIn);
+
+private:
+
+	CalDavUtils();
+	void ConstructL();
+
+	static void FindAndRemoveMethod(TDes8 &aDes);
+	static void FixBYMONTHDAY(TDes8 &aDes);
+	static void FixSameTime(TDes8 &aDes);
+	static void FixLineFeed(TDes8 &aDes);
+
+	};
+
+#endif // CALDAVUTILS_H
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/inc/httpclient.h	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,146 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: 
+*
+*/
+
+#ifndef HTTPCLIENT_H
+#define HTTPCLIENT_H
+
+#include <http\MHTTPAuthenticationCallback.h>
+#include <http\mhttptransactioncallback.h>
+#include <http\mhttpdatasupplier.h>
+
+#include <es_sock.h>
+#include <extendedconnpref.h>
+
+struct TCalDAVOptions;
+
+_LIT8(KHTTP200,"http/1.1 200 ok");
+_LIT8(KHTTP201,"http/1.1 201 created");
+_LIT8(KHTTP404,"http/1.1 404 not found");
+
+#define ERROR 			0
+#define OK				200
+#define CREATED 		201
+#define NOCONTENT		204
+#define MULTISTATUS		207
+#define MUTIPLECHOICES	300
+#define BADREQUEST		400
+#define FORBIDDEN		403
+#define NOTFOUND		404
+#define NOTALLOWED		405
+#define CONFLICT		409
+#define PRECONDFAILED 	412
+
+enum THttpAction
+	{
+	EActionUpload, EActionDelete, EActionOption, EActionNone
+	};
+
+class CHttpClient : public CBase,
+		public MHTTPDataSupplier,
+		public MHTTPAuthenticationCallback,
+		public MHTTPTransactionCallback
+	{
+public:
+	virtual ~CHttpClient();
+	static CHttpClient* NewLC();
+	static CHttpClient* NewL();
+
+	TInt PutL(const TDesC8 &aUrl, const TDesC8 &aICS, CBufFlat *aResponse,
+			const TDesC8 &aEtag = KNullDesC8);
+	TInt MkCalendarL(const TDesC8 &aUrl, const TDesC8 &aBody,
+			CBufFlat *aResponse);
+	TInt DeleteL(const TDesC8 &aUrl, const TDesC8 &aETag = KNullDesC8);
+	TInt HeadL(const TDesC8 &aUrl);
+	TInt GetL(const TDesC8 &aUrl, CBufFlat *aResponse);
+	TInt PropfindL(const TDesC8 &aUrl, const TDesC8 &aBodyRequest,
+			CBufFlat *aResponse, TBool depth0 = ETrue);
+	TInt ReportL(const TDesC8 &aUrl, const TDesC8 &aBodyRequest,
+			CBufFlat *aResponse);
+	TInt ProppatchL(const TDesC8 &aUrl, const TDesC8 &aBodyRequest,
+			CBufFlat *aResponse);
+
+	TInt GetServerOptionsL(const TDesC8 &aUrl, TCalDAVOptions &aOptions);
+
+	// methods inherited from MHTTPDataSupplier
+	virtual TBool GetNextDataPart(TPtrC8& aDataPart);
+	virtual void ReleaseData();
+	virtual TInt OverallDataSize();
+	virtual TInt Reset();
+
+	TInt ReturnCode();
+	TPtrC8 ETag();
+
+	//
+	// methods from MHTTPTransactionCallback
+	//
+	virtual void MHFRunL(RHTTPTransaction aTransaction,
+			const THTTPEvent& aEvent);
+	virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction,
+			const THTTPEvent& aEvent);
+	
+	// methods inherited from MHTTPAuthenticationCallback
+	virtual TBool GetCredentialsL(const TUriC8& aURI, RString aRealm,
+			RStringF aAuthenticationType, RString& aUsername,
+			RString& aPassword);
+
+	TPtrC8 User();
+	void SetUserL(const TDesC8 &aUser);
+
+	void SetPasswordL(const TDesC8 &aPassword);
+	TPtrC8 Password();
+
+protected:
+	CHttpClient();
+	void ConstructL();
+private:
+
+	void InvokeHttpMethodL(const TDesC8& aUri, RStringF aMethod);
+	void SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField,
+			const TDesC8& aHdrValue);
+	void SetHeaderL(RHTTPHeaders aHeaders, const TDesC8 &aField,
+			const TDesC8 &aValue);
+	void GetEtagHeaderL(RHTTPTransaction& aTransaction);
+
+	void GetPostBodyManuallyL();
+
+	void OpenSessionL();
+
+private:
+	RHTTPSession iSess;
+	RHTTPTransaction iTrans;
+	TParse iParsedFileName;
+	CBufFlat* iBodyResponse;
+	HBufC8* iBodyRequest;
+
+	RSocketServ iSocketServ;
+	RConnection iRConnection;
+	TConnPrefList iPrefList;
+	TExtendedConnPref iExtPrefs;
+
+	HBufC8 *iUser;
+	HBufC8 *iPassword;
+
+	TCalDAVOptions *iOptions;
+	THttpAction iAction;
+
+	TInt iReturnCode;
+	HBufC8* iEtag;
+	TInt iCredentialCount;
+
+	};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/src/caldavclient.cpp	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,329 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: provides a client API for Caldav server
+*
+*/
+
+#include "caldavclient.h"
+#include "caldavserver.h"
+#include "caldavutils.h"
+
+const TUint KDefaultMessageSlots = 4;
+
+// testing ************
+#include <e32base.h>
+#include <e32cons.h>
+#include <e32cmn.h>
+
+/**
+ * RCalDavServer::RCalDavServer
+ * default constructor
+ */
+EXPORT_C RCalDavServer::RCalDavServer()
+	{
+	}
+
+/**
+ * RCalDavServer::Connect
+ * connect to server
+ */
+EXPORT_C TInt RCalDavServer::Connect()
+	{
+	TInt retry = 2;
+	for (;;)
+		{
+		TInt r = CreateSession(KCalDavServerName, Version(),
+				KDefaultMessageSlots);
+
+		if ((KErrNotFound != r) && (KErrServerTerminated != r))
+			return (r);
+
+		if (--retry == 0)
+			return (r);
+
+		r = StartServer();
+		if ((KErrNone != r) && (KErrAlreadyExists != r))
+			return (r);
+		}
+	}
+
+/**
+ * RCalDavServer::Enable
+ * enable Caldav sync
+ */
+EXPORT_C TInt RCalDavServer::Enable(const TDesC &aCalendar)
+	{
+	TIpcArgs args(&aCalendar);
+	return SendReceive(ECalDavEnable, args);
+	}
+
+/**
+ * RCalDavServer::Disable
+ * disable Caldav sync
+ */
+EXPORT_C TInt RCalDavServer::Disable(const TDesC &aCalendar)
+	{
+	TIpcArgs args(&aCalendar);
+	return SendReceive(ECalDavDisable, args);
+	}
+
+/**
+ * RCalDavServer::EnabledSync
+ * check for enabled sync
+ */
+EXPORT_C TInt RCalDavServer::EnabledSync(const TDesC &aCalendar,
+		TBool &aEnabled)
+	{
+	TPckg<TBool> enabled(aEnabled);
+	TIpcArgs args(&aCalendar, &enabled);
+	return (SendReceive(ECalDavEnabled, args));
+	}
+
+/**
+ * RCalDavServer::Sync
+ * sync now a specific calendar
+ */
+EXPORT_C TInt RCalDavServer::Sync(const TDesC &aCalendar)
+	{
+	TIpcArgs args(&aCalendar);
+	return SendReceive(ECalDavSync, args);
+	}
+
+/**
+ * RCalDavServer::SyncAll
+ * sync now all calendars
+ */
+EXPORT_C TInt RCalDavServer::SyncAll()
+	{
+	return SendReceive(ECalDavSyncAll);
+	}
+
+/**
+ * RCalDavServer::Url
+ * get caldav sync url
+ */
+EXPORT_C TInt RCalDavServer::Url(const TDesC &aCalendar, TDes8 &aUrl)
+	{
+	TIpcArgs args(&aCalendar, &aUrl);
+	return SendReceive(ECalDavUrl, args);
+	}
+
+/**
+ * RCalDavServer::SetUrl
+ * set url
+ */
+EXPORT_C TInt RCalDavServer::SetUrl(const TDesC &aCalendar, const TDesC8 &aUrl)
+	{
+	TIpcArgs args(&aCalendar, &aUrl);
+	return SendReceive(ECalDavSetUrl, args);
+	}
+
+/**
+ * RCalDavServer::Username
+ * get username
+ */
+EXPORT_C TInt RCalDavServer::Username(const TDesC &aCalendar, TDes8 &aUsername)
+	{
+	TIpcArgs args(&aCalendar, &aUsername);
+	return SendReceive(ECalDavUsername, args);
+	}
+
+/**
+ * RCalDavServer::SetUsername
+ * set username
+ */
+EXPORT_C TInt RCalDavServer::SetUsername(const TDesC &aCalendar,
+		const TDesC8 &aUsername)
+	{
+	TIpcArgs args(&aCalendar, &aUsername);
+	return SendReceive(ECalDavSetUsername, args);
+	}
+
+/**
+ * RCalDavServer::Password
+ * get password
+ */
+EXPORT_C TInt RCalDavServer::Password(const TDesC &aCalendar, TDes8 &aPassword)
+	{
+	TIpcArgs args(&aCalendar, &aPassword);
+	return SendReceive(ECalDavPassword, args);
+	}
+
+/**
+ * RCalDavServer::SetPassword
+ * set password
+ */
+EXPORT_C TInt RCalDavServer::SetPassword(const TDesC &aCalendar,
+		const TDesC8 &aPassword)
+	{
+	TIpcArgs args(&aCalendar, &aPassword);
+	return SendReceive(ECalDavSetPassword, args);
+	}
+
+/**
+ * RCalDavServer::SyncInterval
+ * get SyncInterval
+ */
+EXPORT_C TInt RCalDavServer::SyncInterval(const TDesC &aCalendar,
+		TTimeIntervalMinutes& aSyncInterval)
+	{
+	TPckg<TTimeIntervalMinutes> syncinterval(aSyncInterval);
+	TIpcArgs args(&aCalendar, &syncinterval);
+	return (SendReceive(ECalDavSyncInterval, args));
+	}
+
+/**
+ * RCalDavServer::SetSyncInterval
+ * set SyncInterval
+ */
+EXPORT_C TInt RCalDavServer::SetSyncInterval(const TDesC &aCalendar,
+		TTimeIntervalMinutes aSyncInterval)
+	{
+	TPckg<TTimeIntervalMinutes> syncinterval(aSyncInterval);
+	TIpcArgs args(&aCalendar, &syncinterval);
+	return (SendReceive(ECalDavSetSyncInterval, args));
+	}
+
+/**
+ * RCalDavServer::PastDays
+ * get past days
+ */
+EXPORT_C TInt RCalDavServer::PastDays(const TDesC &aCalendar,
+		TTimeIntervalDays &aDays)
+	{
+	TPckg<TTimeIntervalDays> pastdays(aDays);
+	TIpcArgs args(&aCalendar, &pastdays);
+	return (SendReceive(ECalDavPastDays, args));
+	}
+
+/**
+ * RCalDavServer::SetPastDays
+ * set past days
+ */
+EXPORT_C TInt RCalDavServer::SetPastDays(const TDesC &aCalendar,
+		TTimeIntervalDays aDays)
+	{
+	TPckg<TTimeIntervalDays> pastdays(aDays);
+	TIpcArgs args(&aCalendar, &pastdays);
+	return (SendReceive(ECalDavSetPastDays, args));
+	}
+
+/**
+ * RCalDavServer::ImmediateSync
+ * get Immediate Sync
+ */
+EXPORT_C TInt RCalDavServer::ImmediateSync(const TDesC &aCalendar,
+		TBool &aImmediateSyc)
+	{
+	TPckg<TBool> syncimmediate(aImmediateSyc);
+	TIpcArgs args(&aCalendar, &syncimmediate);
+	return (SendReceive(ECalDavImmediateSync, args));
+	}
+
+/**
+ * RCalDavServer::SetImmediateSync
+ * set immediate Sync
+ */
+EXPORT_C TInt RCalDavServer::SetImmediateSync(const TDesC &aCalendar,
+		TBool aImmediateSyc)
+	{
+	TPckg<TBool> syncimmediate(aImmediateSyc);
+	TIpcArgs args(&aCalendar, &syncimmediate);
+	return SendReceive(ECalDavSetImmediateSync, args);
+	}
+
+/**
+ * RCalDavServer::KeepServerEntry
+ * get KeepServerEntry
+ */
+EXPORT_C TInt RCalDavServer::KeepServerEntry(const TDesC &aCalendar,
+		TBool &aKeepServerEntry)
+	{
+	TPckg<TBool> keepserverentry(aKeepServerEntry);
+	TIpcArgs args(&aCalendar, &keepserverentry);
+	return SendReceive(ECalDavKeepServer, args);
+	}
+
+/**
+ * RCalDavServer::SetKeepServerEntry
+ * set KeepServerEntry
+ */
+EXPORT_C TInt RCalDavServer::SetKeepServerEntry(const TDesC &aCalendar,
+		TBool aKeepServerEntry)
+	{
+	TPckg<TBool> keepserverentry(aKeepServerEntry);
+	TIpcArgs args(&aCalendar, &keepserverentry);
+	return SendReceive(ECalDavSetKeepServer, args);
+	}
+
+/**
+ * RCalDavServer::Version
+ * get version
+ */
+TVersion RCalDavServer::Version(void) const
+	{
+	return (TVersion(KCalDavServerMajorVersionNumber,
+			KCalDavServerMinorVersionNumber, KCalDavServerBuildVersionNumber));
+	}
+
+/**
+ * RCalDavServer::UnsupportedRequest()
+ *  A server request to stop the server.
+ *  This is a request that is NOT implemented by the server; it is here to show
+ *  the handling of non-implemented requests.
+ */
+TInt RCalDavServer::UnsupportedRequest()
+	{
+	return SendReceive(ECalDavUnsupportedRequest);
+	}
+
+/**
+ * RCalDavServer::BadRequest()
+ * A request that the server knows nothing about.
+ */
+void RCalDavServer::BadRequest()
+	{
+	SendReceive(9999);
+	}
+
+static TInt StartServer()
+	{
+	RProcess server;
+	TInt r = server.Create(KCalDavServerFilename, KNullDesC);
+	if (r != KErrNone)
+		return r;
+
+	TRequestStatus stat;
+	server.Rendezvous(stat);
+
+	if (stat != KRequestPending)
+		server.Kill(0); // abort startup
+	else
+		server.Resume(); // logon OK - start the server
+
+	User::WaitForRequest(stat); // wait for start or death
+
+	// Check the exit type.
+	// We can't use the 'exit reason' because if the server panicked this
+	// is set to the panic 'reason' (which may be '0' and cannot thus be distinguished
+	// from KErrNone)
+	r = server.ExitType();
+	if (EExitPanic == r)
+		r = KErrGeneral;
+	else
+		r = stat.Int();
+
+	server.Close(); // This is no longer needed
+	return r;
+	}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/src/caldavengine.cpp	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,2617 @@
+/*
+ * Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+ * All rights reserved.
+ * This component and the accompanying materials are made available
+ * under the terms of "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributor:
+ * Maximilian Odendahl
+ *
+ * Contributors:
+ * 
+ * Description:  main Caldav class, all magic happens here 
+ *				one engine for each configured Caldav calendar
+ */
+#include "caldavengine.h"
+#include <f32file.h> 
+#include <S32FILE.H>
+#include <S32MEM.H> 
+#include <avkon.rsg>
+#include <UTF.H>
+#include <agnexportobserver.h>
+#include <calsession.h>
+#include <caliterator.h>
+#include <calentry.h>
+#include <calentryview.h>
+#include <caltime.h>
+#include <calalarm.h>
+#include <calcategory.h>
+#include <caluser.h>
+#include <calrrule.h>
+#include <calinstance.h>
+#include <calinstanceview.h>
+#include <caleninterimutils2.h> 
+#include <calenexporter.h>
+#include <calenimporter.h>
+#include <calcalendarinfo.h>
+#include "calenglobaldata.h"
+#include <xmlengdocument.h>
+#include <xmlengnode.h>
+#include <xmlengelement.h>
+#include <xmlengnodelist.h>
+#include <xmlengtext.h>
+#include "httpclient.h"
+#include <e32math.h>	// divmod
+#define MULTIGETSPLIT 			100
+#define ARRAYEXPAND				4
+#define	URLMAX					500
+#define EXPANDSIZE_SMALL		512
+#define EXPANDSIZE_BIG			1024
+_LIT(KFormatString,"\"%F%Y%M%DT000000Z\"");
+
+/**
+ * SyncTickL
+ * timer for basic sync interval
+ */
+TInt SyncTickL(TAny *aObject)
+	{
+	CCalDavEngine* engine = ((CCalDavEngine*) aObject);
+	CPeriodic* timer = engine->Timer();
+	if (engine && timer)
+		{
+		timer->Cancel();
+		TRAP_IGNORE(engine->SyncL());
+		TInt ticktime = engine->SyncInterval().Int() == 0 ? 1
+				: engine->SyncInterval().Int();
+		const TUint64 tickInterval = 1000000 * 60 * ticktime;
+		timer->Start(tickInterval, tickInterval, TCallBack(SyncTickL, engine));
+		}
+	return 0;
+	}
+
+#ifdef _DEBUG
+void ExportToFileNameL(const TDesC8& aDes, const TDesC &aFilename)
+	{
+	RFs fsSession;
+	User::LeaveIfError(fsSession.Connect());
+	CleanupClosePushL(fsSession);
+
+	TInt err = fsSession.MkDirAll(aFilename);
+
+	RFile file;
+	User::LeaveIfError(file.Replace(fsSession, aFilename, EFileWrite));
+	CleanupClosePushL(file);
+
+	RFileWriteStream writeStream2;
+	writeStream2.Attach(file);
+	CleanupClosePushL(writeStream2);
+
+	writeStream2 << aDes;
+	writeStream2.CommitL();
+	CleanupStack::PopAndDestroy(&writeStream2);
+	CleanupStack::PopAndDestroy(&file);
+	CleanupStack::PopAndDestroy(&fsSession);
+	}
+
+void ExportToFileL(CCalEntry* aEntry, CCalenExporter *iCalExporter)
+	{
+	if (aEntry)
+		{
+		_LIT(KFileName, "C:\\logs\\caldav\\testing_export.txt");
+
+		RFs fsSession;
+		User::LeaveIfError(fsSession.Connect());
+		CleanupClosePushL(fsSession);
+
+		TInt err = fsSession.MkDirAll(KFileName);
+
+		RFile file;
+		User::LeaveIfError(file.Replace(fsSession, KFileName, EFileWrite));
+		CleanupClosePushL(file);
+
+		RFileWriteStream writeStream2;
+		writeStream2.Attach(file);
+		CleanupClosePushL(writeStream2);
+
+		iCalExporter->ExportICalL(*aEntry, writeStream2);
+		writeStream2.CommitL();
+		CleanupStack::PopAndDestroy(&writeStream2);
+		CleanupStack::PopAndDestroy(&file);
+		CleanupStack::PopAndDestroy(&fsSession);
+		}
+	}
+#endif
+
+/**
+ * SearchL
+ * search inside xml tree for a specific node
+ */
+void SearchL(TXmlEngNode &aTopNode, const TDesC8 &aName,
+		const TDesC8 &aNamespace, TXmlEngNode & aReturnNode)
+	{
+	RXmlEngNodeList<TXmlEngNode> List;
+	aTopNode.GetChildNodes(List);
+	while (List.HasNext() && aReturnNode.IsNull())
+		{
+		TXmlEngNode Node = List.Next();
+		TXmlEngNode::TXmlEngDOMNodeType Type = Node.NodeType();
+		if (Type == TXmlEngNode::EElement)
+			{
+			//todo: compare namespace ?
+			if (Node.Name() == aName)
+				{
+				aReturnNode = Node.CopyL();
+				return;
+				}
+			else
+				{
+				SearchL(Node, aName, aNamespace, aReturnNode);
+				if (!aReturnNode.IsNull())
+					return;
+				}
+			}
+		}
+	}
+
+/**
+ * SearchL
+ * search inside xml tree for a specific node
+ */
+void SearchL(TXmlEngNode &aTopNode, const TDesC8 &aName,
+		const TDesC8 &aNamespace, RBuf8 &aBuf)
+	{
+	RXmlEngNodeList<TXmlEngNode> List;
+	aTopNode.GetChildNodes(List);
+	while (List.HasNext())
+		{
+		TXmlEngNode Node = List.Next();
+		TXmlEngNode::TXmlEngDOMNodeType Type = Node.NodeType();
+		if (Type == TXmlEngNode::EElement)
+			{
+			//todo: compare namespace ?
+			if (Node.Name() == aName)
+				{
+				if (Node.IsSimpleTextContents())
+					aBuf.Create(Node.Value());
+				else
+					Node.WholeTextContentsCopyL(aBuf);
+				return;
+				}
+			else
+				{
+				SearchL(Node, aName, aNamespace, aBuf);
+				if (aBuf.Length())
+					return;
+				}
+			}
+		}
+	}
+
+/**
+ * SearchL
+ * search inside xml tree for a specific node
+ */
+TPtrC8 SearchL(TXmlEngNode &aTopNode, const TDesC8 &aName,
+		const TDesC8 &aNamespace)
+	{
+	RXmlEngNodeList<TXmlEngNode> List;
+	aTopNode.GetChildNodes(List);
+	while (List.HasNext())
+		{
+		TXmlEngNode Node = List.Next();
+		TXmlEngNode::TXmlEngDOMNodeType Type = Node.NodeType();
+		if (Type == TXmlEngNode::EElement)
+			{
+			//todo: compare namespace ?
+			if (Node.Name() == aName)
+				return Node.Value();
+			else
+				{
+				TPtrC8 Return = SearchL(Node, aName, aNamespace);
+				if (Return != KNullDesC8)
+					return Return;
+				}
+			}
+		}
+	return KNullDesC8();
+	}
+
+/**
+ * GetBoolFromPropertiesL
+ * get a boolean value from CCalCalendarInfo
+ */
+TBool GetBoolFromPropertiesL(CCalCalendarInfo* info, const TDesC8 &aKey)
+	{
+	TBool boolean;
+	TPckgC<TBool> pckgboolean(boolean);
+	pckgboolean.Set(info->PropertyValueL(aKey));
+	return pckgboolean();
+	}
+
+/**
+ * GetTimeFromPropertiesL
+ * get a time value from CCalCalendarInfo
+ */
+TCalTime GetTimeFromPropertiesL(CCalCalendarInfo* info, const TDesC8 &aKey)
+	{
+	TCalTime time;
+	TPckgC<TCalTime> pckgtime(time);
+	pckgtime.Set(info->PropertyValueL(aKey));
+	return pckgtime();
+	}
+
+/**
+ * PropertyExists
+ * finds a property from an array
+ */
+TBool PropertyExists(CDesC8Array* aArray, const TDesC8 &aKey)
+	{
+	TInt pos = 0;
+	return aArray->Find(aKey, pos, ECmpNormal) == KErrNone;
+	}
+
+/**
+ * CCalDavEngine::SetCalendarInfoL
+ * set key and value pair at calendar session info
+ */
+void CCalDavEngine::SetCalendarInfoL(const TDesC8 &aKey, const TDesC8 &aValue)
+	{
+	TBool createdelete = !iCalSession;
+	if (createdelete)
+		{
+		iCalSession = CCalSession::NewL();
+		TRAP_IGNORE(iCalSession->OpenL(*iCalendar));
+		}
+	CCalCalendarInfo* calendarInfo = iCalSession->CalendarInfoL();
+	CleanupStack::PushL(calendarInfo);
+	TPckgC<TBool> enabled(iEnabled);
+	calendarInfo->SetPropertyL(KCaldavEnabled, enabled);
+	if (aValue != KNullDesC8)
+		calendarInfo->SetPropertyL(aKey, aValue);
+	iCalSession->SetCalendarInfoL(*calendarInfo);
+	CleanupStack::PopAndDestroy(calendarInfo);
+
+	if (createdelete)
+		{
+		delete iCalSession;
+		iCalSession = NULL;
+		}
+	}
+
+/**
+ * CCalDavEngine::CCalDavEngine
+ * default constructor
+ */
+CCalDavEngine::CCalDavEngine() :
+	iCalSession(0), iCalIter(0), iCalEntryView(0), iCalExporter(0),
+			iCalImporter(0), iCalIntermimUtils2(0), iCalendar(0), iUrl(0),
+			iBaseUrl(0), iHome(0), iHttp(0), iSynctoken(0), iCTag(0),
+			iSyncInterval(DEFAULT_SYNC_MINUTES), iPastDays(DEFAULT_PAST_DAYS),
+			iImmediateSync(DEFAULT_IMMEDIATE_SYNC), iKeepServerEntry(
+					DEFAULT_KEEP_SERVER_ENTRY), iEnabled(EFalse), iTimer(0)
+	{
+	}
+
+/**
+ * CCalDavEngine::~CCalDavEngine
+ * default destructor
+ */
+CCalDavEngine::~CCalDavEngine()
+	{
+	iLocalUidArray.Close();
+	iGlobalUidArray.Close();
+	iDeletedEntries.Close();
+
+	iDomParser.Close();
+	iDomImpl.Close();
+
+	if (iCalendar)
+		delete iCalendar;
+
+	if (iUrl)
+		delete iUrl;
+
+	if (iBaseUrl)
+		delete iBaseUrl;
+
+	if (iHttp)
+		delete iHttp;
+
+	DeleteCalObjects();
+
+	if (iCalIntermimUtils2)
+		delete iCalIntermimUtils2;
+
+	if (iSynctoken)
+		delete iSynctoken;
+
+	if (iCTag)
+		delete iCTag;
+
+	if (iHome)
+		delete iHome;
+
+	if (iTimer)
+		delete iTimer;
+	}
+
+/**
+ * CCalDavEngine::NewLC
+ * first phase construction
+ */
+CCalDavEngine* CCalDavEngine::NewLC(const TDesC& aCalendar)
+	{
+	CCalDavEngine* self = new (ELeave) CCalDavEngine();
+	CleanupStack::PushL(self);
+	self->ConstructL(aCalendar);
+	return self;
+	}
+
+/**
+ * CCalDavEngine::NewL
+ * first phase construction
+ */
+CCalDavEngine* CCalDavEngine::NewL(const TDesC& aCalendar)
+	{
+	CCalDavEngine* self = CCalDavEngine::NewLC(aCalendar);
+	CleanupStack::Pop(self); // self;
+	return self;
+	}
+
+/**
+ * CCalDavEngine::
+ * second phase construction
+ */
+void CCalDavEngine::ConstructL(const TDesC& aCalendar)
+	{
+	iManualSync = EFalse;
+	iFirstInit = ETrue;
+	iCalendar = aCalendar.AllocL();
+
+	iHttp = CHttpClient::NewL();
+
+	iDomImpl.OpenL();
+	TInt err = iDomParser.Open(iDomImpl);
+	if (KErrNone != err)
+		User::Leave(err);
+
+	iTimer = CPeriodic::NewL(EPriorityNormal);
+	iCalIntermimUtils2 = CCalenInterimUtils2::NewL();
+	iCalSession = CCalSession::NewL();
+	TRAP_IGNORE(iCalSession->OpenL(aCalendar));
+	CalendarInfoL();
+	// we can't close the file, so delete it completly
+	delete iCalSession;
+	iCalSession = NULL;
+	}
+
+/**
+ * CCalDavEngine::Progress
+ * Progress callback
+ */
+void CCalDavEngine::Progress(TInt /*aPercentageCompleted*/)
+	{
+	}
+
+/**
+ * CCalDavEngine::RegisterL
+ * register all neccessary notification callback
+ */
+void CCalDavEngine::RegisterL()
+	{
+	TDateTime Start;
+	TDateTime End;
+	End.SetYear(2200);
+
+	TCalTime StartCal;
+	TCalTime EndCal;
+	StartCal.SetTimeLocalL(Start);
+	EndCal.SetTimeLocalL(End);
+	CalCommon::TCalTimeRange Range(StartCal, EndCal);
+	CCalChangeNotificationFilter *Filter = CCalChangeNotificationFilter::NewL(
+			MCalChangeCallBack2::EChangeEntryAll, true, Range);
+	iCalSession->StartChangeNotification(*this, *Filter);
+	iCalSession->StartFileChangeNotificationL(*this);
+	delete Filter;
+	}
+
+/**
+ * CCalDavEngine::CalendarInfoL
+ * load all properties from CalendarInfo
+ */
+void CCalDavEngine::CalendarInfoL()
+	{
+	CCalCalendarInfo* calendarInfo = iCalSession->CalendarInfoL();
+	if (calendarInfo->IsValid())
+		{
+		CleanupStack::PushL(calendarInfo);
+		CDesC8Array* propertyKeys = calendarInfo->PropertyKeysL();
+		CleanupStack::PushL(propertyKeys);
+		TInt pos = 0;
+		if (propertyKeys->Find(KCaldavEnabled, pos, ECmpNormal) == KErrNone)
+			{
+			iEnabled = GetBoolFromPropertiesL(calendarInfo, KCaldavEnabled);
+			if (PropertyExists(propertyKeys, KCaldavFirstInit))
+				iFirstInit = GetBoolFromPropertiesL(calendarInfo,
+						KCaldavFirstInit);
+			if (PropertyExists(propertyKeys, KCaldavSynctoken))
+				iSynctoken
+						= calendarInfo->PropertyValueL(KCaldavSynctoken).AllocL();
+			if (PropertyExists(propertyKeys, KCaldavCtag))
+				iCTag = calendarInfo->PropertyValueL(KCaldavCtag).AllocL();
+			if (PropertyExists(propertyKeys, KCaldavManualSync))
+				iManualSync = GetBoolFromPropertiesL(calendarInfo,
+						KCaldavManualSync);
+			if (PropertyExists(propertyKeys, KCaldavTime))
+				iLastSyncTime = GetTimeFromPropertiesL(calendarInfo,
+						KCaldavTime);
+			if (PropertyExists(propertyKeys, KCaldavUrl))
+				iUrl = calendarInfo->PropertyValueL(KCaldavUrl).AllocL();
+			if (PropertyExists(propertyKeys, KCaldavUser))
+				iHttp->SetUserL(calendarInfo->PropertyValueL(KCaldavUser));
+			if (PropertyExists(propertyKeys, KCaldavPassword))
+				iHttp->SetPasswordL(calendarInfo->PropertyValueL(
+						KCaldavPassword));
+			if (PropertyExists(propertyKeys, KCaldavKeepServer))
+				iKeepServerEntry = GetBoolFromPropertiesL(calendarInfo,
+						KCaldavKeepServer);
+			if (PropertyExists(propertyKeys, KCaldavImmediateSync))
+				iImmediateSync = GetBoolFromPropertiesL(calendarInfo,
+						KCaldavImmediateSync);
+			if (PropertyExists(propertyKeys, KCaldavPastDays))
+				{
+				TPckgC<TTimeIntervalDays> pastdays(iPastDays);
+				pastdays.Set(calendarInfo->PropertyValueL(KCaldavPastDays));
+				iPastDays = pastdays();
+				}
+			if (PropertyExists(propertyKeys, KCaldavSyncInterval))
+				{
+				TPckgC<TTimeIntervalMinutes> syncinterval(iSyncInterval);
+				syncinterval.Set(calendarInfo->PropertyValueL(
+						KCaldavSyncInterval));
+				iSyncInterval = syncinterval();
+				}
+			// access point	    
+			}
+
+		CleanupStack::PopAndDestroy(propertyKeys);
+		CleanupStack::Pop(calendarInfo);
+		}
+	delete calendarInfo;
+	}
+
+/**
+ * CCalDavEngine::InitL
+ * check for correct url
+ * load most Caldav url properties
+ * do inital sync
+ */
+TInt CCalDavEngine::InitL()
+	{
+	// this is only needed to find a GlobalUID from a LocalUID, used after an event was deleted
+	// also used now for uploading of local events when only GlobalUID is know 
+	LocalLoopL(ELoopActionFillArray);
+
+	if (iFirstInit)
+		{
+		TInt err = GetCalendarUrlsL(NULL);
+		if (err == KErrArgument)
+			return KErrArgument;
+		GetOptionsL();
+		SetLastSyncTimeL();
+
+		TBool success;
+		// get all server items
+		if (iOptions.sync_collection)
+			success = WebDavSyncL();
+		else
+			success = ListL() == KErrNone;
+
+		if (!success)
+			return KErrGeneral;
+
+		// upload all local entries of this calendar to server
+		LocalLoopL(ELoopActionUpload);
+
+		if (iOptions.sync_collection)
+			SetSyncTokenL(GetSyncTokenL());
+		else
+			SetCTagL(GetCTagL());
+
+		iFirstInit = EFalse;
+		iEnabled = ETrue;
+		TPckgC<TBool> firstInit(iFirstInit);
+		SetCalendarInfoL(KCaldavFirstInit, firstInit); // this will set iEnabled as well
+		}
+	else
+		{
+		TInt err = GetCalendarUrlsL(NULL);
+		if (err == KErrArgument)
+			return KErrArgument;
+		GetOptionsL();
+		SetLastSyncTimeL();
+		iEnabled = ETrue;
+		SetCalendarInfoL(KCaldavEnabled, KNullDesC8);
+		SyncL();
+		}
+
+	return KErrNone;
+	}
+
+/**
+ * CCalDavEngine::Completed
+ * Completed callback
+ */
+void CCalDavEngine::Completed(TInt aError)
+	{
+	if (aError == KErrNone)
+		{
+		CActiveScheduler::Stop();
+		}
+	else
+		iManualSync = true;
+	}
+
+/**
+ * CCalDavEngine::NotifyProgress
+ * NotifyProgress callback
+ */
+TBool CCalDavEngine::NotifyProgress()
+	{
+	return EFalse;
+	}
+
+/**
+ * CCalDavEngine::CalChangeNotification
+ * change item callback, sync to server
+ */
+void CCalDavEngine::CalChangeNotification(RArray<TCalChangeEntry> &aChangeItems)
+	{
+	for (TInt i = 0; i < aChangeItems.Count(); i++)
+		{
+		TRAP_IGNORE(HandleChangeL(aChangeItems[i].iChangeType, aChangeItems[i].iEntryType, aChangeItems[i].iEntryId));
+		}
+	}
+
+/**
+ * CCalDavEngine::CalendarInfoChangeNotificationL
+ * change callback, sync changed color or name to server
+ */
+void CCalDavEngine::CalendarInfoChangeNotificationL(RPointerArray<
+		CCalFileChangeInfo>& aCalendarInfoChangeEntries)
+	{
+	for (TInt i = 0; i < aCalendarInfoChangeEntries.Count(); i++)
+		{
+		if ((aCalendarInfoChangeEntries[i]->FileNameL() == *iCalendar)
+				&& (aCalendarInfoChangeEntries[i]->ChangeType()
+						== MCalFileChangeObserver::ECalendarInfoUpdated))
+			{
+			TRAP_IGNORE(HandleCalendarInfoChangeL());
+			}
+		}
+	}
+
+/**
+ * CCalDavEngine::HandleCalendarInfoChangeL
+ * sync changed color or name to server
+ */
+void CCalDavEngine::HandleCalendarInfoChangeL()
+	{
+	if (iHttp)
+		{
+		CBufFlat* response = CBufFlat::NewL(EXPANDSIZE_SMALL);
+		CleanupStack::PushL(response);
+		CCalCalendarInfo* info = iCalSession->CalendarInfoL();
+		CleanupStack::PushL(info);
+
+		HBufC8* name =
+				CnvUtfConverter::ConvertFromUnicodeToUtf8L(info->NameL());
+		CleanupStack::PushL(name);
+
+		TRgb color = info->Color();
+		_LIT8(KColorformat,"#%02x%02x%02xFF");
+		TBuf8<9> colorbuf;
+		colorbuf.Format(KColorformat, color.Red(), color.Green(), color.Blue());
+
+		HBufC8* patch = HBufC8::NewLC(KColorDisplayStart().Length()
+				+ colorbuf.Length() + KColorDisplayMiddle().Length()
+				+ name->Length() + KColorDisplayEnd().Length());
+		patch->Des().Append(KColorDisplayStart);
+		patch->Des().Append(colorbuf);
+		patch->Des().Append(KColorDisplayMiddle);
+		patch->Des().Append(*name);
+		patch->Des().Append(KColorDisplayEnd);
+		iHttp->ProppatchL(*iUrl, *patch, response);
+		CleanupStack::PopAndDestroy(4); // response, info, name, patch
+		}
+	}
+
+/**
+ * CCalDavEngine::HandleChangeL
+ * change item callback, sync to server
+ */
+void CCalDavEngine::HandleChangeL(
+		MCalChangeCallBack2::TChangeType &aChangeType,
+		MCalChangeCallBack2::TChangeEntryType &aEntryType, TCalLocalUid &aUid)
+	{
+	switch (aChangeType)
+		{
+		case MCalChangeCallBack2::EChangeAdd:
+		case MCalChangeCallBack2::EChangeModify:
+			{
+			if (iImmediateSync)
+				UploadEntryL(aUid, aChangeType, aEntryType);
+			else
+				// enable manual sync for the next sync interval
+				SyncFailedL();
+			break;
+			}
+		case MCalChangeCallBack2::EChangeDelete:
+			{
+			if (iImmediateSync)
+				DeleteEntryL(aUid);
+			else
+				{
+				iDeletedEntries.Append(aUid);
+				SyncFailedL();
+				}
+			break;
+			}
+		case MCalChangeCallBack2::EChangeUndefined:
+			{
+			// upload new and modified entries to server
+			UploadModifiedSinceDateL();
+
+			// Find locally deleted ones and delete on server
+			DeleteRemovedEntriesOnServerL();
+
+			break;
+			}
+		}
+	}
+
+/**
+ * CCalDavEngine::EnableL
+ * enable Caldav sync
+ */
+TInt CCalDavEngine::EnableL()
+	{
+	if (!iCalEntryView) //do not use iEnabled here,might be set already in ConstructL()
+		{
+		TInt aErr = CreateCalObjectsL();
+		if ((aErr == KErrNone) && (InitL() == KErrNone))
+			{
+			iTimer->Cancel();
+			TInt ticktime = iSyncInterval.Int() == 0 ? 1 : iSyncInterval.Int();
+			const TUint64 tickInterval = 1000000 * 60 * ticktime;
+			iTimer->Start(tickInterval, tickInterval,
+					TCallBack(SyncTickL, this));
+			// register change notification
+			RegisterL();
+			return KErrNone;
+			}
+		else
+			{
+			iEnabled = EFalse;
+			SetCalendarInfoL(KCaldavEnabled, KNullDesC8);
+			DeleteCalObjects();
+			return KErrArgument;
+			}
+		}
+	return KErrNone;
+	}
+
+/**
+ * CCalDavEngine::DeleteCalObjects
+ * delete all calendar objects
+ */
+void CCalDavEngine::DeleteCalObjects()
+	{
+	delete iCalIter;
+	iCalIter = NULL;
+	delete iCalEntryView;
+	iCalEntryView = NULL;
+	delete iCalImporter;
+	iCalImporter = NULL;
+	delete iCalExporter;
+	iCalExporter = NULL;
+	if (iCalSession)
+		{
+		iCalSession->StopChangeNotification();
+		iCalSession->StopFileChangeNotification();
+		delete iCalSession;
+		}
+	iCalSession = NULL;
+	}
+
+/**
+ * CCalDavEngine::CreateCalObjectsL
+ * create all calendar objects
+ */
+TInt CCalDavEngine::CreateCalObjectsL()
+	{
+	iCalSession = CCalSession::NewL();
+	TRAPD(aErr,iCalSession->OpenL(*iCalendar));
+	iCalExporter = CCalenExporter::NewL(*iCalSession);
+	iCalImporter = CCalenImporter::NewL(*iCalSession);
+	iCalEntryView = CCalEntryView::NewL(*iCalSession);
+	iCalIter = CCalIter::NewL(*iCalSession);
+	return aErr;
+	}
+
+/**
+ * CCalDavEngine::DisableL
+ * disable sync
+ */
+void CCalDavEngine::DisableL()
+	{
+	if (iEnabled)
+		{
+		iTimer->Cancel();
+		iEnabled = EFalse;
+		SetCalendarInfoL(KCaldavEnabled, KNullDesC8);
+		DeleteCalObjects();
+		}
+	}
+
+/**
+ * CCalDavEngine::EnabledSync
+ * check for enabled sync
+ */
+TBool CCalDavEngine::EnabledSync()
+	{
+	return iEnabled;
+	}
+
+/**
+ * CCalDavEngine::TimeReportL
+ * do a CalDav time report
+ */
+TInt CCalDavEngine::TimeReportL(TBool VEVENT, const TDesC8 &aStart,
+		TBool aDelete)
+	{
+	CBufFlat* body = CBufFlat::NewL(EXPANDSIZE_BIG);
+	CleanupStack::PushL(body);
+
+	body->InsertL(body->Size(), VEVENT ? KTimeStartEVENT() : KTimeStartTODO());
+	body->InsertL(body->Size(), aStart); // "20090509T220000Z"/>
+	body->InsertL(body->Size(), KTimeEnd);
+
+	CBufFlat* response = CBufFlat::NewL(EXPANDSIZE_BIG);
+	CleanupStack::PushL(response);
+	TInt ret = iHttp->ReportL(*iUrl, body->Ptr(0), response);
+
+	if (ret == MULTISTATUS)
+		ret = aDelete ? ParseResponsesDeleteL(response->Ptr(0))
+				: ParseResponsesL(response->Ptr(0));
+	else
+		ret = KErrGeneral;
+
+	CleanupStack::PopAndDestroy(response);
+	CleanupStack::PopAndDestroy(body);
+	return ret;
+	}
+
+/**
+ * CCalDavEngine::ListL
+ * get events either using time report or basic propfind
+ */
+TInt CCalDavEngine::ListL()
+	{
+	if (iOptions.calendar_access)
+		{
+		TTime syncstart;
+		syncstart.HomeTime();
+		syncstart = syncstart - iPastDays;
+		TBuf<100> nowStr;
+		syncstart.FormatL(nowStr, KFormatString);
+		TBuf8<100> nowStrAdd;
+		nowStrAdd.Append(nowStr);
+
+		TInt eventreturn = KErrNone;
+		if (iOptions.VEVENT)
+			eventreturn = TimeReportL(ETrue, nowStrAdd);
+
+		TInt todoreturn = KErrNone;
+		if (iOptions.VTODO)
+			todoreturn = TimeReportL(EFalse, nowStrAdd);
+
+		return (eventreturn == KErrNone) && (todoreturn == KErrNone) ? KErrNone
+				: KErrGeneral;
+		}
+	else
+		{
+		// use PROPFIND report
+		CBufFlat* response = CBufFlat::NewL(EXPANDSIZE_SMALL);
+		CleanupStack::PushL(response);
+		TInt ret = iHttp->PropfindL(*iUrl, KPropList, response, EFalse);
+		if (ret == MULTISTATUS)
+			ret = ParseResponsesL(response->Ptr(0));
+		else
+			ret = KErrGeneral;
+		CleanupStack::PopAndDestroy(response);
+		return ret;
+		}
+	}
+
+/**
+ * CCalDavEngine::SyncL
+ * sync a calendar
+ */
+TInt CCalDavEngine::SyncL()
+	{
+	if (iUrl)
+		{
+		if (iOptions.sync_collection)
+			return WebDavSyncL();
+		else
+			return ManualSyncL();
+		}
+	return KErrGeneral;
+	}
+
+/**
+ * CCalDavEngine::ManualSyncL
+ * if sync failed previously, try again manually
+ */
+TBool CCalDavEngine::ManualSyncL()
+	{
+	TBool client = ClientChangesL();
+	if (iOptions.sync_ctag)
+		{
+		HBufC8 *newCTag = GetCTagL();
+		TBool server = ETrue;
+		if ((CTag() != *newCTag) && (*newCTag != KNullDesC8))
+			{
+			server = ServerChangesL();
+			if (server)
+				SetCTagL(newCTag);
+			else
+				delete newCTag;
+			}
+		else
+			delete newCTag;
+
+		return client || server;
+		}
+	else
+		{
+		TBool server = ServerChangesL();
+		return client || server;
+		}
+	}
+
+/**
+ * CCalDavEngine::ServerChangesL
+ * sync server changes
+ */
+TBool CCalDavEngine::ServerChangesL()
+	{
+	// loop over all server items to find new and modified entries
+	// uses either propfind or calendar-query
+	TInt ret = ListL();
+
+	// loop over all local items to find deleted ones on the server
+	LocalLoopL(ELoopActionDeleteLocal);
+
+	return ret == KErrNone;
+	}
+
+/**
+ * CCalDavEngine::LocalLoopL
+ * loop over local calendar store
+ */
+TInt CCalDavEngine::LocalLoopL(TLocalLoopAction aAction)
+	{
+	TBuf8<URLMAX> iter = iCalIter->FirstL();
+	TBuf8<URLMAX> url;
+	while (iter != KNullDesC8)
+		{
+		url.Append(*iUrl);
+		url.Append(iter);
+		url.Append(KIcs);
+		switch (aAction)
+			{
+			case ELoopActionDeleteLocal:
+				{
+				if (HeadL(iter) == NOTFOUND)
+					DeleteLocalEntryL(url);
+				break;
+				}
+			case ELoopActionFillArray:
+				{
+				RPointerArray<CCalEntry> entryArray;
+				CleanupClosePushL(entryArray);
+				iCalEntryView->FetchL(iter, entryArray);
+				if (entryArray.Count())
+					{
+					iLocalUidArray.Append(entryArray[0]->LocalUidL());
+					iGlobalUidArray.Append(entryArray[0]->UidL());
+					}
+				entryArray.ResetAndDestroy();
+				CleanupStack::PopAndDestroy(&entryArray);
+
+				break;
+				}
+			case ELoopActionUpload:
+				{
+				TInt pos = iGlobalUidArray.Find(iter);
+				if ((pos != KErrNotFound) && (iLocalUidArray.Count() > pos))
+					UploadEntryL(iLocalUidArray[pos],
+							MCalChangeCallBack2::EChangeAdd,
+							MCalChangeCallBack2::EChangeEntryAll);
+				break;
+				}
+			}
+		url.Delete(0, url.Length());
+		iter = iCalIter->NextL();
+		}
+	return KErrNone;
+	}
+
+/**
+ * CCalDavEngine::ParseResponsesDeleteL
+ * process a recieved multistatus response
+ */
+TInt CCalDavEngine::ParseResponsesDeleteL(const TDesC8 &aDocument)
+	{
+	TInt ret = KErrNone;
+	RXmlEngDocument document = iDomParser.ParseL(aDocument);
+	CleanupClosePushL(document);
+	if (document.NotNull())
+		{
+		// this method works for response as well as sync-response
+		// do not use GetElementsByTagNameL for one specific responses directly	
+		TXmlEngElement ResponseListTop;
+		SearchL(document, KMultistatus, KNullDesC8, ResponseListTop);
+
+		RXmlEngNodeList<TXmlEngNode> ResponseList;
+		CleanupClosePushL(ResponseList);
+		ResponseListTop.GetChildNodes(ResponseList);
+
+		while (ResponseList.HasNext())
+			{
+			TXmlEngNode node = ResponseList.Next();
+			if (node.NodeType() == TXmlEngNode::EElement)
+				{
+				TPtrC8 href = SearchL(node, KHref, KNullDesC8);
+				// don't do anything with home itself
+				if ((href.Right(KIcs().Length()) == KIcs))
+					{
+					if (!DoesEntryExistL(href))
+						DeleteEntryL(href);
+					}
+				}
+			}
+		CleanupStack::PopAndDestroy(&ResponseList);
+
+		}
+	else
+		ret = KErrArgument;
+	CleanupStack::PopAndDestroy(&document);
+	return ret;
+	}
+
+/**
+ * CCalDavEngine::ParseResponsesL
+ * process a recieved multistatus response
+ */
+TInt CCalDavEngine::ParseResponsesL(RXmlEngDocument &aDocument, TBool aMultiget)
+	{
+	TInt ret = KErrNone;
+	if (aDocument.NotNull())
+		{
+		CDesC8ArrayFlat *multiget = NULL;
+		if (iOptions.MULTIGET)
+			{
+			multiget = new (ELeave) CDesC8ArrayFlat(ARRAYEXPAND);
+			CleanupStack::PushL(multiget);
+			}
+
+		// this method works for response as well as sync-response
+		// do not use GetElementsByTagNameL for one specific responses directly	
+		TXmlEngElement ResponseListTop;
+		SearchL(aDocument, KMultistatus, KNullDesC8, ResponseListTop);
+
+		RXmlEngNodeList<TXmlEngNode> ResponseList;
+		CleanupClosePushL(ResponseList);
+		ResponseListTop.GetChildNodes(ResponseList);
+
+		while (ResponseList.HasNext())
+			{
+			TXmlEngNode node = ResponseList.Next();
+			if (node.NodeType() == TXmlEngNode::EElement)
+				{
+				TPtrC8 href = SearchL(node, KHref, KNullDesC8);
+				//do not use Search, only looking for first childs,
+				//as D:propstat has D:status as well
+				RXmlEngNodeList<TXmlEngElement> statuslist;
+				CleanupClosePushL(statuslist);
+				node.AsElement().GetElementsByTagNameL(statuslist, KStatus,
+						KDav);
+				//only one or zero item
+				HBufC8* status =
+						statuslist.Count() ? statuslist.Next().Value().AllocL()
+								: KNullDesC8().AllocL();
+				CleanupStack::PopAndDestroy(&statuslist);
+				CleanupStack::PushL(status);
+				status->Des().LowerCase();
+				TPtrC8 etag = SearchL(node, KEtag, KNullDesC8);
+				RBuf8 calendardata;
+				SearchL(node, KCalendarData, KNullDesC8, calendardata);
+				calendardata.CleanupClosePushL();
+
+				// don't do anything with home itself
+				if (href.Right(KIcs().Length()) == KIcs)
+					{
+					if ((*status == KHTTP200) || (*status == KHTTP201) || (*status == KNullDesC8))
+						{
+						if ((calendardata == KNullDesC8))
+							{
+							if (aMultiget)
+								{
+								// ATTENTION: an empty response to a multiget should never happen
+								// data wrapped inside CDATA, e.g. bedework ??
+								}
+							else
+								//TOOD: if this is a webdav sync response, we should skip the etag check
+								AddModifyLocalEntryL(href, etag, multiget);
+							}
+						else
+							{
+							// response to a multiget or time-range report, we now already have everything we need
+							StoreEntryL(calendardata, etag);
+							}
+						}
+					else if (*status == KHTTP404)
+						{
+						if (iOptions.sync_collection)
+							{
+							// if this is an initial sync without token, 
+							// this should be ignored, Sun Server bug!!!
+							if (SyncToken() != KNullDesC8)
+								DeleteLocalEntryL(href);
+							}
+						else
+							{
+							//multiget answer, but deleted in the meantime, should delete locally as well
+							DeleteLocalEntryL(href);
+							}
+						}
+					}
+				CleanupStack::PopAndDestroy(&calendardata);
+				CleanupStack::PopAndDestroy(status);
+				}
+			}
+		CleanupStack::PopAndDestroy(&ResponseList);
+
+		if (iOptions.MULTIGET)
+			{
+			if (multiget->Count())
+				{
+				DownloadEntryL(multiget);
+				multiget->Reset();
+				}
+			CleanupStack::PopAndDestroy(multiget);
+			}
+		}
+	else
+		ret = KErrArgument;
+
+	return ret;
+	}
+
+/**
+ * CCalDavEngine::ParseResponsesL
+ * process a recieved multistatus response
+ */
+TInt CCalDavEngine::ParseResponsesL(const TDesC8 &aDocument, TBool aMultiget)
+	{
+#ifdef _DEBUG
+	_LIT(KFilename,"c:\\logs\\caldav\\parseresonseslatest.txt");
+	ExportToFileNameL(aDocument, KFilename);
+#endif
+
+	RXmlEngDocument document = iDomParser.ParseL(aDocument);
+	CleanupClosePushL(document);
+	TInt ret = ParseResponsesL(document, aMultiget);
+	CleanupStack::PopAndDestroy(&document);
+	return ret;
+	}
+
+/**
+ * CCalDavEngine::StoreEntryL
+ * store event in local store
+ */
+#ifdef ETAG
+TInt CCalDavEngine::StoreEntryL(const TDesC8 &aBuf, const TDesC8 &aEtag)
+#else
+TInt CCalDavEngine::StoreEntryL(const TDesC8 &aBuf, const TDesC8 &/*aEtag*/)
+#endif
+	{
+#ifdef _DEBUG
+	_LIT(KFileName2, "C:\\logs\\caldav\\testing_import.txt");
+	ExportToFileNameL(aBuf, KFileName2);
+#endif
+
+	HBufC8* buffer = HBufC8::NewL(aBuf.Length() + 500);
+	buffer->Des().Append(aBuf);
+	TPtr8 ptr = buffer->Des();
+	CalDavUtils::FixImportIssues(ptr);
+
+	RPointerArray<CCalEntry> Array;
+	CleanupClosePushL(Array);
+	RDesReadStream ReadStream;
+	ReadStream.Open(ptr);
+	CleanupClosePushL(ReadStream);
+#ifdef _DEBUG
+	_LIT(KFileName, "C:\\logs\\caldav\\testing_import_fixed.txt");
+	ExportToFileNameL(ptr, KFileName);
+#endif
+	TRAPD(error, iCalImporter->ImportICalendarL(ReadStream,Array));
+	CleanupStack::PopAndDestroy(&ReadStream); // calls close on rSteam												
+	if ((error == KErrNone) && (Array.Count()))
+		{
+		iCalIntermimUtils2->StoreL(*iCalEntryView, *Array[0], ETrue); // or should last one be EFalse??
+		TInt pos = iLocalUidArray.Find(Array[0]->LocalUidL());
+		if (pos == KErrNotFound)
+			{
+			iLocalUidArray.Append(Array[0]->LocalUidL());
+			iGlobalUidArray.Append(Array[0]->UidL());
+			}
+#ifdef ETAG
+		Array[0]->SetETag(aEtag);
+#endif
+		}
+	Array.ResetAndDestroy();
+	CleanupStack::PopAndDestroy(&Array);
+
+	delete buffer;
+	return error;
+	}
+
+/**
+ * CCalDavEngine::WebDavSyncReportL
+ * webdav sync report
+ * http://tools.ietf.org/html/draft-daboo-webdav-sync-02
+ */
+TInt CCalDavEngine::WebDavSyncReportL(TBool aSynctoken)
+	{
+	HBufC8 *Buf = HBufC8::NewL(KSync().Length() + SyncToken().Length());
+	TPtrC8 token = SyncToken();
+	if (aSynctoken)
+		Buf->Des().Format(KSync, &token);
+	else
+		Buf->Des().Format(KSync, &KNullDesC8());
+	CleanupStack::PushL(Buf);
+
+	CBufFlat* response = CBufFlat::NewL(EXPANDSIZE_BIG);
+	CleanupStack::PushL(response);
+	TInt ret = iHttp->ReportL(*iUrl, *Buf, response);
+
+	if (ret == MULTISTATUS)
+		{
+		RXmlEngDocument document = iDomParser.ParseL(response->Ptr(0));
+		CleanupClosePushL(document);
+		if (document.NotNull())
+			{
+			TPtrC8 Token = SearchL(document, KSynctoken, KNullDesC8);
+			if ((Token != KNullDesC8) && (Token != SyncToken()))
+				{
+				ret = ParseResponsesL(document);
+				//store newest token
+				if (ret == KErrNone)
+					SetSyncTokenL(Token.AllocL());
+				}
+			else
+				ret = KErrNone;
+			}
+		else
+			ret = KErrGeneral;
+		CleanupStack::PopAndDestroy(&document);
+		}
+	CleanupStack::PopAndDestroy(response);
+	CleanupStack::PopAndDestroy(Buf);
+	return ret;
+	}
+
+/**
+ * CCalDavEngine::WebDavSyncL
+ * sync using webdav sync
+ * http://tools.ietf.org/html/draft-daboo-webdav-sync-02
+ */
+TBool CCalDavEngine::WebDavSyncL()
+	{
+	if (iHttp)
+		{
+		// commit any left over client changes
+		TBool RetClient = ClientChangesL();
+		// get all changes from server
+		TInt ret = WebDavSyncReportL(ETrue);
+		if (ret == CONFLICT)
+			ret = WebDavSyncReportL(EFalse);
+		return (ret == KErrNone) && RetClient;
+		}
+	return EFalse;
+	}
+
+/**
+ * CCalDavEngine::GetUIDByUrl
+ * parse url to find UID
+ */
+TPtrC8 CCalDavEngine::GetUIDByUrl(const TDesC8 &aUrl)
+	{
+	TPtrC8 UID;
+	TInt Pos = aUrl.LocateReverse('/');
+	TInt Pos2 = aUrl.Find(KIcs);
+
+	if ((Pos != KErrNotFound) && (Pos2 != KErrNotFound))
+		UID.Set(aUrl.Mid(Pos + 1, Pos2 - Pos - 1));
+	else
+		{
+		if (Pos != KErrNotFound)
+			UID.Set(aUrl.Mid(Pos + 1, aUrl.Length() - Pos - 1));
+		else if (Pos2 != KErrNotFound)
+			UID.Set(aUrl.Left(aUrl.Length() - KIcs().Length()));
+		else
+			UID.Set(aUrl);
+		}
+
+	return UID;
+	}
+
+/**
+ * CCalDavEngine::DoesEntryExistL
+ * check if entry exists in local store
+ */
+unsigned long CCalDavEngine::DoesEntryExistL(const TDesC8 &aUrl)
+	{
+	// check if we already have it locally by uid
+	RPointerArray<CCalEntry> entryArray;
+	CleanupClosePushL(entryArray);
+	iCalEntryView->FetchL(GetUIDByUrl(aUrl), entryArray);
+	// get parent 
+	CCalEntry *entry = entryArray.Count() ? entryArray[0] : NULL;
+	TInt ret = entry ? entry->LocalUidL() : 0;
+	entryArray.ResetAndDestroy();
+	CleanupStack::PopAndDestroy(&entryArray);
+	return ret;
+	}
+
+/**
+ * CCalDavEngine::ETagMatchL
+ * checks for equal ETag
+ */
+TBool CCalDavEngine::ETagMatchL(const TDesC8& /*aUrl*/, const TDesC8& /*aETag*/)
+	{
+#ifdef ETAG
+	// check if we already have it locally by uid
+	RPointerArray<CCalEntry> entryArray;
+	CleanupClosePushL(entryArray);
+	iCalEntryView->FetchL(GetUIDByUrl(aUrl), entryArray);
+	// get parent 
+	CCalEntry *entry = entryArray.Count() ? entryArray[0] : NULL;
+	TBool ret = entry ? entry->ETag() == aETag : EFalse;
+	entryArray.ResetAndDestroy();
+	CleanupStack::PopAndDestroy(&entryArray);
+	return ret;
+#else
+	return EFalse;
+#endif
+	}
+
+/**
+ * CCalDavEngine::AddModifyLocalEntryL
+ * add or modify existing event
+ */
+TInt CCalDavEngine::AddModifyLocalEntryL(const TDesC8 &aUrl,
+		const TDesC8 &aETag, CDesC8ArrayFlat* aArray)
+	{
+	// check if we have the entry locally
+	// check for etag if we have the latest version, if not, download and import or add to multiget request
+	if (!ETagMatchL(aUrl, aETag))
+		{
+		if (aArray)
+			aArray->AppendL(aUrl);
+		else
+			DownloadEntryL(aUrl);
+		}
+	return KErrNone;
+	}
+
+/**
+ * CCalDavEngine::DownloadEntryL
+ * download entries using multiget from server
+ */
+TInt CCalDavEngine::DownloadEntryL(CDesC8Array* aArray)
+	{
+	TInt ret = KErrNone;
+	TInt64 remainder;
+	TInt64 result = Math::DivMod64(aArray->Count(), MULTIGETSPLIT, remainder);
+
+	// split large multigets request into several smaller ones
+	for (TInt64 l = 0; l <= result; l++)
+		{
+		// do the multiget request and pass it to parserepsonses again to read in the data
+		CBufFlat* body = CBufFlat::NewL(EXPANDSIZE_BIG);
+		CleanupStack::PushL(body);
+
+		body->InsertL(body->Size(), KMultistart);
+		for (TInt64 i = 0; i <= ((l == result) ? remainder - 1 : MULTIGETSPLIT
+				- 1); i++)
+			{
+			body->InsertL(body->Size(), KHrefstart);
+			body->InsertL(body->Size(), (*aArray)[MULTIGETSPLIT * l + i]);
+			body->InsertL(body->Size(), KHrefend);
+			}
+		body->InsertL(body->Size(), KMultiend);
+
+		CBufFlat* response = CBufFlat::NewL(EXPANDSIZE_BIG);
+		CleanupStack::PushL(response);
+		TInt Return = iHttp->ReportL(*iUrl, body->Ptr(0), response);
+
+		if (Return == MULTISTATUS)
+			{
+			TInt parsereturn = ParseResponsesL(response->Ptr(0), ETrue);
+			// if it failed before, we do not want to override this error
+			ret = (ret == KErrNone) ? parsereturn : ret;
+			}
+		else
+			ret = KErrGeneral;
+		CleanupStack::PopAndDestroy(response);
+		CleanupStack::PopAndDestroy(body);
+
+		}
+	return ret;
+	}
+
+/**
+ * CCalDavEngine::DownloadEntryL
+ * download entry from server
+ */
+TInt CCalDavEngine::DownloadEntryL(const TDesC8 &aUrl)
+	{
+	TBuf8<URLMAX> url;
+	url.Append(*iUrl);
+	url.Append(GetUIDByUrl(aUrl));
+	url.Append(KIcs);
+
+	CBufFlat* response = CBufFlat::NewL(EXPANDSIZE_SMALL);
+	CleanupStack::PushL(response);
+	TInt ret = iHttp->GetL(url, response);
+	if (ret == OK)
+		ret = StoreEntryL(response->Ptr(0), iHttp->ETag());
+	else
+		ret = KErrGeneral;
+	CleanupStack::PopAndDestroy(response);
+	return ret;
+	}
+
+/**
+ * CCalDavEngine::DeleteLocalEntryL
+ * delete an event from local store
+ */
+TInt CCalDavEngine::DeleteLocalEntryL(const TDesC8 &aUID)
+	{
+	CDesC8ArrayFlat * Array = new (ELeave) CDesC8ArrayFlat(ARRAYEXPAND);
+	CleanupStack::PushL(Array);
+	Array->AppendL(GetUIDByUrl(aUID));
+	// we could have delete it ourselves, so it is already gone
+	TRAPD(error, iCalEntryView->DeleteL(*Array));
+	Array->Reset();
+	CleanupStack::PopAndDestroy(Array);
+	return error;
+	}
+
+/**
+ * CCalDavEngine::DeleteRemovedEntriesOnServerL
+ * check for removed entries on server
+ */
+TInt CCalDavEngine::DeleteRemovedEntriesOnServerL()
+	{
+	if (iOptions.calendar_access)
+		{
+		TTime syncstart;
+		syncstart.HomeTime();
+		syncstart = syncstart - iPastDays;
+		TBuf<100> nowStr;
+		syncstart.FormatL(nowStr, KFormatString);
+		TBuf8<100> nowStrAdd;
+		nowStrAdd.Append(nowStr);
+
+		TInt eventreturn = KErrNone;
+		if (iOptions.VEVENT)
+			eventreturn = TimeReportL(ETrue, nowStrAdd, ETrue);
+
+		TInt todoreturn = KErrNone;
+		if (iOptions.VTODO)
+			todoreturn = TimeReportL(EFalse, nowStrAdd, ETrue);
+
+		return (eventreturn == KErrNone) && (todoreturn == KErrNone) ? KErrNone
+				: KErrGeneral;
+		}
+	else
+		{
+		// use PROPFIND report
+		CBufFlat* response = CBufFlat::NewL(EXPANDSIZE_SMALL);
+		CleanupStack::PushL(response);
+		TInt ret = iHttp->PropfindL(*iUrl, KPropList, response, EFalse);
+		if (ret == MULTISTATUS)
+			ret = ParseResponsesDeleteL(response->Ptr(0));
+		else
+			ret = KErrGeneral;
+		CleanupStack::PopAndDestroy(response);
+		return ret;
+		}
+
+	}
+
+/**
+ * CCalDavEngine::UploadModifiedSinceDateL
+ * check for any modified data after last sync time
+ */
+TBool CCalDavEngine::UploadModifiedSinceDateL()
+	{
+	TBool manualsync = EFalse;
+	// upload modified and newly create ones 
+	RArray<TCalLocalUid> *Ids = new (ELeave) RArray<TCalLocalUid> (ARRAYEXPAND);
+	iCalEntryView->GetIdsModifiedSinceDateL(iLastSyncTime, *Ids);
+	for (TInt i = 0; i < Ids->Count(); i++)
+		{
+		TCalLocalUid id = (*Ids)[i];
+		TInt ret = UploadEntryL(id, MCalChangeCallBack2::EChangeUndefined,
+				MCalChangeCallBack2::EChangeEntryAll);
+		// TOOD: if it fails during upload, ignore
+		// if it fails due to internet connection, try again
+		if (ret != KErrNone)
+			manualsync = ETrue;
+		}
+	Ids->Reset();
+	delete Ids;
+	return manualsync;
+	}
+
+/**
+ * CCalDavEngine::ClientChangesL
+ * check for left over local client changes
+ */
+TBool CCalDavEngine::ClientChangesL()
+	{
+	if (iCalEntryView && iManualSync)
+		{
+		iManualSync = EFalse;
+
+		// upload modified and newly create ones 
+		iManualSync = UploadModifiedSinceDateL();
+
+		// delete locally deleted entries on server 
+		for (TInt i = iDeletedEntries.Count() - 1; i >= 0; --i)
+			{
+			TInt ret = DeleteEntryL(iDeletedEntries[i]);
+			if (ret == KErrNone)
+				iDeletedEntries.Remove(i);
+
+			}
+
+		iManualSync = iDeletedEntries.Count() ? ETrue : EFalse;
+
+		TPckgC<TBool> manualSync(iManualSync);
+		SetCalendarInfoL(KCaldavManualSync, manualSync);
+		}
+
+	return ETrue;
+	}
+
+/**
+ * CCalDavEngine::MkcalendarL
+ * create a new calendar on the server
+ */
+TInt CCalDavEngine::MkcalendarL(const TDesC8 &aName)
+	{
+	if (iOptions.MKCALENDAR)
+		{
+		TBuf8<URLMAX> url;
+		url.Append(*iHome);
+		url.Append(aName);
+		url.Append(KSlash);
+
+		CBufFlat* response = CBufFlat::NewL(EXPANDSIZE_SMALL);
+		CleanupStack::PushL(response);
+
+		// TOOD: initialize with name, body etc.
+		TInt ret = iHttp->MkCalendarL(url, KNullDesC8, response);
+
+		if ((ret == CREATED) || (ret == OK))
+			ret = KErrNone;
+		else if ((ret == NOTALLOWED) || (ret == FORBIDDEN))
+			ret = KErrArgument;
+		else
+			ret = KErrGeneral;
+		CleanupStack::PopAndDestroy(response);
+		return ret;
+		}
+	else
+		return KErrNotSupported;
+	}
+
+/**
+ * CCalDavEngine::DeleteCalendarL
+ * delete a calendar on the server
+ */
+TInt CCalDavEngine::DeleteCalendarL(const TDesC8 &aName)
+	{
+	if (iOptions.MKCALENDAR)
+		{
+		TBuf8<URLMAX> url;
+		url.Append(*iHome);
+		url.Append(aName);
+		url.Append(KSlash);
+
+		CBufFlat* response = CBufFlat::NewL(EXPANDSIZE_SMALL);
+		CleanupStack::PushL(response);
+		TInt ret = iHttp->DeleteL(url);
+		if ((ret == NOCONTENT) || (ret == OK))
+			ret = KErrNone;
+		else
+			ret = KErrGeneral;
+		CleanupStack::PopAndDestroy(response);
+		return ret;
+		}
+	else
+		return KErrNotSupported;
+	}
+
+/**
+ * CCalDavEngine::HeadL
+ * check for existence of an entry on server
+ */
+TInt CCalDavEngine::HeadL(const TDesC8 &aUID)
+	{
+	// special handing for yahoo neccessary
+	// after deleting an event, it is still there and findable with HEAD
+	_LIT8(KYahoo,"yahoo");
+	_LIT8(KTrash,"trash");
+
+	TBuf8<URLMAX> url;
+	url.Append(*iUrl);
+	url.Append(aUID);
+	url.Append(KIcs);
+	if (iUrl->Find(KYahoo) == KErrNotFound)
+		{
+		TInt head = iHttp->HeadL(url);
+		return (head == NOCONTENT) || (head == OK) ? OK : head;
+		}
+	else
+		{
+		CBufFlat* response = CBufFlat::NewL(EXPANDSIZE_SMALL);
+		CleanupStack::PushL(response);
+		TInt ret = iHttp->PropfindL(url, KNullDesC8, response);
+
+		if (ret == MULTISTATUS)
+			{
+			RXmlEngDocument document = iDomParser.ParseL(response->Ptr(0));
+			CleanupClosePushL(document);
+			if (document.NotNull())
+				{
+				HBufC8* href = SearchL(document, KHref, KNullDesC8).AllocL();
+				href->Des().LowerCase();
+				ret = href->Find(KTrash) == KErrNotFound ? OK : NOTFOUND;
+				delete href;
+				}
+			CleanupStack::PopAndDestroy(&document);
+			CleanupStack::PopAndDestroy(response);
+			return ret;
+			}
+		else
+			{
+			CleanupStack::PopAndDestroy(response);
+			return NOTFOUND;
+			}
+		}
+	}
+
+/**
+ * CCalDavEngine::DeleteEntryL
+ * delete entry on server
+ */
+TInt CCalDavEngine::DeleteEntryL(const TDesC8 &aUid)
+	{
+	TBuf8<URLMAX> url;
+	url.Append(*iBaseUrl);
+	url.Append(aUid);
+	return iHttp->DeleteL(url);
+	}
+
+/**
+ * CCalDavEngine::DeleteEntryL
+ * delete entry on server
+ */
+TInt CCalDavEngine::DeleteEntryL(const TCalLocalUid &aUid)
+	{
+	TInt Ret = KErrNone;
+	// find the filename for a given local UID
+	TInt aPos = iLocalUidArray.Find(aUid);
+	if (aPos != KErrNotFound)
+		{
+		TBuf8<URLMAX> url;
+		url.Append(*iUrl);
+		url.Append(iGlobalUidArray[aPos]);
+		url.Append(KIcs);
+
+#ifdef ETAG
+		CCalEntry* entry = iCalEntryView->FetchL(aUid);
+		CleanupStack::PushL(entry);
+		TInt Return = entry ? iHttp->DeleteL(url, entry->ETag())
+		: iHttp->DeleteL(url);
+		CleanupStack::PopAndDestroy(entry);
+#else
+		TInt Return = iHttp->DeleteL(url);
+#endif
+
+		if ((Return == NOCONTENT) || (Return == OK))
+			{
+			SetLastSyncTimeL();
+			}
+		else if (Return == PRECONDFAILED)
+			{
+			// someone modified this in the meantime
+			// ask user if he wants the new event or still delete it
+			TBool modify = EFalse;
+			if (modify)
+				DownloadEntryL(url);
+			else
+				iHttp->DeleteL(url);
+			}
+		else if (Return == NOTFOUND)
+			{
+			// someone deleted this already
+			Ret = KErrGeneral;
+			}
+		else if (Return == FORBIDDEN)
+			{
+			// event read-only
+			Ret = KErrGeneral;
+			}
+		else
+			{
+			Ret = KErrGeneral;
+			SyncFailedL();
+			TInt pos = iDeletedEntries.Find(aUid);
+			if (pos == KErrNotFound)
+				iDeletedEntries.Append(aUid);
+			}
+		}
+	else
+		Ret = KErrGeneral;
+	return Ret;
+	}
+
+/**
+ * CCalDavEngine::UploadEntryL
+ * upload entry to server
+ */
+TInt CCalDavEngine::UploadEntryL(CCalEntry* aEntry,
+		MCalChangeCallBack2::TChangeType aChangeType,
+		MCalChangeCallBack2::TChangeEntryType aEntryType)
+	{
+	if (aEntry)
+		{
+		TInt ret = KErrNone;
+		TBool upload = EFalse;
+		switch (aEntryType)
+			{
+			case MCalChangeCallBack2::EChangeEntryEvent:
+			case MCalChangeCallBack2::EChangeEntryTodo:
+				{
+				upload = aEntry && ((MCalChangeCallBack2::EChangeEntryEvent
+						&& iOptions.VEVENT)
+						|| (MCalChangeCallBack2::EChangeEntryTodo
+								&& iOptions.VTODO));
+				break;
+				}
+			case MCalChangeCallBack2::EChangeEntryAll:
+				{
+				if (aEntry)
+					{
+					switch (aEntry->EntryTypeL())
+						{
+						case CCalEntry::EAppt:
+						case CCalEntry::EAnniv:
+						case CCalEntry::EEvent:
+						case CCalEntry::EReminder:
+							{
+							upload = iOptions.VEVENT;
+							break;
+							}
+						case CCalEntry::ETodo:
+							{
+							upload = iOptions.VTODO;
+							break;
+							}
+						}
+					}
+
+				}
+			}
+		if (upload)
+			{
+			CBufFlat* BufFlat = CBufFlat::NewL(EXPANDSIZE_SMALL);
+			CleanupStack::PushL(BufFlat);
+			RBufWriteStream writeStream(*BufFlat);
+			CleanupClosePushL(writeStream);
+			iCalExporter->ExportICalL(*aEntry, writeStream);
+			writeStream.CommitL();
+			CleanupStack::PopAndDestroy(&writeStream);
+
+			HBufC8* buffer = BufFlat->Ptr(0).AllocL();
+			CleanupStack::PopAndDestroy(BufFlat);
+			CleanupStack::PushL(buffer);
+			TPtr8 ptr = buffer->Des();
+			CalDavUtils::FixExportIssues(ptr);
+
+#ifdef _DEBUG
+			ExportToFileL(aEntry, iCalExporter);
+			_LIT(KFileName, "C:\\logs\\caldav\\testing_export_fixed.txt");
+			ExportToFileNameL(ptr, KFileName);
+#endif
+
+			TBuf8<URLMAX> url;
+			url.Append(*iUrl);
+			url.Append(aEntry->UidL());
+			url.Append(KIcs);
+
+			CBufFlat* response = CBufFlat::NewL(EXPANDSIZE_SMALL);
+			CleanupStack::PushL(response);
+
+#ifdef ETAG
+			TPtrC8 etag = aEntry->GetETag();
+			TBool newentry = (aChangeType == MCalChangeCallBack2::EChangeAdd)
+			|| ((aChangeType == MCalChangeCallBack2::EChangeUndefined)
+					&& (etag == KNullDesC8));
+			TInt Ret = newentry ? iHttp->PutL(url, *buffer, response)
+			: iHttp->PutL(url, *buffer, response, etag);
+#else
+			TBool newentry = (aChangeType == MCalChangeCallBack2::EChangeAdd)
+					|| (aChangeType == MCalChangeCallBack2::EChangeUndefined);
+			TInt Ret = newentry ? iHttp->PutL(url, *buffer, response)
+					: iHttp->PutL(url, *buffer, response, _L8("ETAG"));
+#endif
+			if ((Ret == CREATED) || (Ret == NOCONTENT) || (Ret == OK))
+				{
+				if (newentry)
+					{
+					iLocalUidArray.Append(aEntry->LocalUidL());
+					iGlobalUidArray.Append(aEntry->UidL());
+					}
+#ifdef ETAG
+				aEntry->SetETag(iHttp->ETag());
+#endif
+				SetLastSyncTimeL();
+				}
+			else if (Ret == PRECONDFAILED)
+				{
+				if (newentry)// same filename already exists, use a different one and upload again
+					{
+					TBuf8<URLMAX> nextUrl;
+					nextUrl.Append(*iUrl);
+					nextUrl.Append(aEntry->UidL());
+					TTime time;
+					time.HomeTime();
+					_LIT(KTimeFormat,"%H%T%S");
+					TBuf<20> StringTime;
+					time.FormatL(StringTime, KTimeFormat);
+					nextUrl.Append(StringTime);
+					nextUrl.Append(_L8(".ics"));
+					response->Reset();
+					TInt Ret = iHttp->PutL(nextUrl, *buffer, response);
+					if ((Ret == CREATED) || (Ret == OK))
+						{
+						iLocalUidArray.Append(aEntry->LocalUidL());
+						iGlobalUidArray.Append(aEntry->UidL());
+#ifdef ETAG
+						aEntry->SetETag(iHttp->ETag());
+#endif
+						SetLastSyncTimeL();
+						}
+					else
+						{
+						SyncFailedL();
+						ret = KErrAbort;
+						}
+					}
+				else
+					{
+					if (!iKeepServerEntry)
+						{
+						response->Reset();
+						// upload again without ETAG to overwrite server entry
+						TInt Ret = iHttp->PutL(url, *buffer, response);
+						if ((Ret == CREATED) || (Ret == OK))
+							{
+#ifdef ETAG
+							aEntry->SetETag(iHttp->ETag());
+#endif
+							SetLastSyncTimeL();
+							}
+						else
+							{
+							SyncFailedL();
+							ret = KErrAbort;
+							}
+						}
+					else
+						{
+						// download the server event and update local store
+						ret = DownloadEntryL(url);
+						if (ret == KErrNone)
+							SetLastSyncTimeL();
+						else
+							{
+							SyncFailedL();
+							ret = KErrAbort;
+							}
+						}
+					}
+				}
+			else
+				{
+				SyncFailedL();
+				ret = KErrAbort;
+				}
+			CleanupStack::PopAndDestroy(response);
+			CleanupStack::PopAndDestroy(buffer);
+			}
+		return ret;
+		}
+	return KErrArgument;
+	}
+
+/**
+ * CCalDavEngine::UploadEntryL
+ * upload entry to server
+ */
+TInt CCalDavEngine::UploadEntryL(const TCalLocalUid &aUid,
+		MCalChangeCallBack2::TChangeType aChangeType,
+		MCalChangeCallBack2::TChangeEntryType aEntryType)
+	{
+	CCalEntry * aEntry = iCalEntryView->FetchL(aUid);
+	CleanupStack::PushL(aEntry);
+	TInt ret = UploadEntryL(aEntry, aChangeType, aEntryType);
+	CleanupStack::PopAndDestroy(aEntry);
+	return ret;
+	}
+
+/**
+ * CCalDavEngine::GetSyncTokenL
+ * get latest Webdav Sync token
+ */
+HBufC8* CCalDavEngine::GetSyncTokenL()
+	{
+	HBufC8 *aBuf = HBufC8::NewL(KSync().Length());
+	aBuf->Des().Format(KSync, &KNullDesC8());
+	CleanupStack::PushL(aBuf);
+
+	CBufFlat* response = CBufFlat::NewL(EXPANDSIZE_SMALL);
+	CleanupStack::PushL(response);
+	TInt RetServer = iHttp->ReportL(*iUrl, *aBuf, response);
+
+	if (RetServer)
+		{
+		RXmlEngDocument document = iDomParser.ParseL(response->Ptr(0));
+		CleanupClosePushL(document);
+		if (document.NotNull())
+			{
+			HBufC8* ret = SearchL(document, KSynctoken, KNullDesC8).AllocL();
+			CleanupStack::PopAndDestroy(&document);
+			CleanupStack::PopAndDestroy(response);
+			CleanupStack::PopAndDestroy(aBuf);
+			return ret;
+			}
+		CleanupStack::PopAndDestroy(&document);
+		}
+	CleanupStack::PopAndDestroy(response);
+	CleanupStack::PopAndDestroy(aBuf);
+	return KNullDesC8().AllocL();
+	}
+
+/**
+ * CCalDavEngine::CheckCalendarInfoL
+ * check for new calendar displayname and color
+ */
+void CCalDavEngine::CheckCalendarInfoL(RXmlEngDocument &aDocument)
+	{
+	TBool change = EFalse;
+	CCalCalendarInfo* info = iCalSession->CalendarInfoL();
+	CleanupStack::PushL(info);
+
+	HBufC8* color = SearchL(aDocument, KCalendar_Color, KNullDesC8).AllocLC();
+	if ((*color != KNullDesC8) && (color->Length() > 6))
+		{
+		TLex8 lexred(color->Des().Mid(1, 2));
+		TInt red;
+		lexred.Val(red);
+		TLex8 lexgreen(color->Des().Mid(3, 2));
+		TInt green;
+		lexgreen.Val(green);
+		TLex8 lexblue(color->Des().Mid(5, 2));
+		TInt blue;
+		lexblue.Val(blue);
+		TRgb newcolor(red, green, blue);
+		if (info->Color() != newcolor)
+			{
+			info->SetColor(newcolor);
+			change = ETrue;
+			}
+		}
+	CleanupStack::PopAndDestroy(color);
+
+	HBufC8* displayname =
+			SearchL(aDocument, KDisplayname, KNullDesC8).AllocLC();
+	if (*displayname != KNullDesC8)
+		{
+		HBufC16* name =
+				CnvUtfConverter::ConvertToUnicodeFromUtf8L(*displayname);
+		CleanupStack::PushL(name);
+		if (info->NameL() != *name)
+			{
+			info->SetNameL(*name);
+			change = ETrue;
+			}
+		CleanupStack::PopAndDestroy(name);
+		change = ETrue;
+		}
+	CleanupStack::PopAndDestroy(displayname);
+
+	if (change)
+		iCalSession->SetCalendarInfoL(*info);
+	CleanupStack::PopAndDestroy(info);
+
+	}
+
+/**
+ * CCalDavEngine::GetCTagL
+ * get latest CTag
+ * https://trac.calendarserver.org/browser/CalendarServer/trunk/doc/Extensions/caldav-ctag.txt
+ */
+HBufC8* CCalDavEngine::GetCTagL()
+	{
+	if (iHttp)
+		{
+		CBufFlat* response = CBufFlat::NewL(EXPANDSIZE_SMALL);
+		CleanupStack::PushL(response);
+		TInt ret = iHttp->PropfindL(*iUrl, KCtag, response);
+
+		if (ret == MULTISTATUS)
+			{
+			RXmlEngDocument document = iDomParser.ParseL(response->Ptr(0));
+			CleanupClosePushL(document);
+			if (document.NotNull())
+				{
+				HBufC8* status =
+						SearchL(document, KStatus, KNullDesC8).AllocLC();
+				HBufC8* ctag =
+						SearchL(document, KGetctag, KNullDesC8).AllocLC();
+				status->Des().LowerCase();
+				if ((*ctag != KNullDesC8) && (*status == KHTTP200))
+					{
+					CleanupStack::Pop(ctag);
+					CleanupStack::PopAndDestroy(status);
+					CleanupStack::PopAndDestroy(&document);
+					CleanupStack::PopAndDestroy(response);
+					return ctag;
+					}
+				else
+					CleanupStack::PopAndDestroy(ctag);
+				CleanupStack::PopAndDestroy(status);
+				}
+			CleanupStack::PopAndDestroy(&document);
+
+			}
+		CleanupStack::PopAndDestroy(response);
+		}
+	return KNullDesC8().AllocL();
+	}
+
+/**
+ * CCalDavEngine::GetOptionsL
+ * get OPTIONS from server
+ */
+TBool CCalDavEngine::GetOptionsL()
+	{
+	if (iHttp)
+		{
+		// check DAV and allow headers
+		iHttp->GetServerOptionsL(*iUrl, iOptions);
+
+		// check ctag extension
+		HBufC8* ctag = GetCTagL();
+		if (*ctag != KNullDesC8)
+			iOptions.sync_ctag = true;
+		delete ctag;
+
+		// check supported elements
+		CBufFlat* response = CBufFlat::NewL(EXPANDSIZE_SMALL);
+		CleanupStack::PushL(response);
+		TInt Ret = iHttp->PropfindL(*iUrl, KSupportedSet, response);
+
+		if (Ret == MULTISTATUS)
+			{
+			RXmlEngDocument document = iDomParser.ParseL(response->Ptr(0));
+			CleanupClosePushL(document);
+			if (document.NotNull())
+				{
+				CheckCalendarInfoL(document);
+
+				//<C:supported-calendar-component-set/>
+				TXmlEngElement supportedelement;
+				SearchL(document, KSupportedCalendarComponentSet, KNullDesC8,
+						supportedelement);
+				if (supportedelement.NotNull())
+					{
+					RXmlEngNodeList<TXmlEngElement> supportedelements;
+					CleanupClosePushL(supportedelements);
+					supportedelement.GetChildElements(supportedelements);
+					while (supportedelements.HasNext())
+						{
+						TXmlEngElement element = supportedelements.Next();
+						TPtrC8 value = element.AttributeValueL(KName);
+						if (value == KNullDesC8)
+							value.Set(element.AttributeValueL(KName, KCalDav));
+						if (value == KVEVENT)
+							iOptions.VEVENT = ETrue;
+						else if (value == KVTODO)
+							iOptions.VTODO = ETrue;
+						else if (value == KVFREBUSY)
+							iOptions.VFREEBUSY = ETrue;
+						else if (value == KVJOURNAL)
+							iOptions.VJOURNAL = ETrue;
+						}
+					CleanupStack::PopAndDestroy(&supportedelements);
+					}
+				}
+			CleanupStack::PopAndDestroy(&document);
+			}
+		CleanupStack::PopAndDestroy(response);
+		}
+	return ETrue;
+	}
+
+/**
+ * CCalDavEngine::SetSyncTokenL
+ * set sync token
+ */
+void CCalDavEngine::SetSyncTokenL(HBufC8* aToken)
+	{
+	if (iSynctoken)
+		{
+		delete iSynctoken;
+		iSynctoken = NULL;
+		}
+	iSynctoken = aToken;
+	SetCalendarInfoL(KCaldavSynctoken, *iSynctoken);
+	}
+
+/**
+ * CCalDavEngine::SyncToken
+ * get synctoken
+ */
+TPtrC8 CCalDavEngine::SyncToken()
+	{
+	return iSynctoken ? *iSynctoken : KNullDesC8();
+	}
+
+/**
+ * CCalDavEngine::SetCTagL
+ * set ctag
+ */
+void CCalDavEngine::SetCTagL(HBufC8* aToken)
+	{
+	if (iCTag)
+		{
+		delete iCTag;
+		iCTag = NULL;
+		}
+	iCTag = aToken;
+	SetCalendarInfoL(KCaldavCtag, *iCTag);
+	}
+
+/**
+ * CCalDavEngine::CTag
+ * get ctag
+ */
+TPtrC8 CCalDavEngine::CTag()
+	{
+	return iCTag ? *iCTag : KNullDesC8();
+	}
+
+/**
+ * CCalDavEngine::SetLastSyncTimeL
+ * set last sync time
+ */
+void CCalDavEngine::SetLastSyncTimeL()
+	{
+	// only set a new last sync time, if we did not have a failed one before
+	// otherwise, the old one would be lost
+	if (!iManualSync)
+		{
+		TTime time;
+		time.UniversalTime();
+		iLastSyncTime.SetTimeUtcL(time);
+		TPckgC<TCalTime> lasttime(iLastSyncTime);
+		SetCalendarInfoL(KCaldavTime, lasttime);
+		}
+	}
+
+/**
+ * CCalDavEngine::SyncFailedL
+ * sync failed, enable manual sync
+ */
+void CCalDavEngine::SyncFailedL()
+	{
+	if (!iManualSync)
+		{
+		iManualSync = ETrue;
+		TPckgC<TBool> manualSync(iManualSync);
+		SetCalendarInfoL(KCaldavManualSync, manualSync);
+		}
+	}
+
+/**
+ * CCalDavEngine::GetBaseUrl
+ * get base domain url
+ */
+void CCalDavEngine::GetBaseUrl(const TDesC8 &aUrl)
+	{
+	_LIT8(http,"http://");
+	_LIT8(https,"https://");
+
+	if (iBaseUrl)
+		{
+		delete iBaseUrl;
+		iBaseUrl = NULL;
+		}
+
+	if (aUrl.Length() > http().Length())
+		{
+		TInt length = aUrl.Find(https) != KErrNotFound ? https().Length()
+				: http().Length();
+		TInt pos = aUrl.Mid(length).Locate('/');
+		iBaseUrl = aUrl.Left(pos + length).Alloc();
+		}
+	}
+
+/**
+ * CCalDavEngine::FindUrlsL
+ * find home, inbox and outbox property
+ */
+void CCalDavEngine::FindUrlsL(const TDesC8 &aDes, HBufC8 *&home,
+		HBufC8 *&inbox, HBufC8 *&outbox)
+	{
+	RXmlEngDocument document = iDomParser.ParseL(aDes);
+	CleanupClosePushL(document);
+	if (document.NotNull())
+		{
+		HBufC8* status = SearchL(document, KStatus, KNullDesC8).AllocLC();
+		status->Des().LowerCase();
+		if (*status == KHTTP200)
+			{
+			TXmlEngElement calendarhome, inboxhome, outboxhome;
+
+			SearchL(document, KCalendarHomeSet, KNullDesC8, calendarhome);
+			if (calendarhome.NotNull())
+				{
+				TPtrC8 homeend = SearchL(calendarhome, KHref, KNullDesC8);
+				home = HBufC8::NewL(iBaseUrl->Length() + homeend.Length());
+				home->Des().Append(*iBaseUrl);
+				home->Des().Append(homeend);
+				}
+
+			SearchL(document, KInbox, KNullDesC8, inboxhome);
+			if (inboxhome.NotNull())
+				{
+				TPtrC8 inboxend = SearchL(inboxhome, KHref, KNullDesC8);
+				inbox = HBufC8::NewL(iBaseUrl->Length() + inboxend.Length());
+				inbox->Des().Append(*iBaseUrl);
+				inbox->Des().Append(inboxend);
+				}
+
+			SearchL(document, KOutbox, KNullDesC8, outboxhome);
+			if (outboxhome.NotNull())
+				{
+				TPtrC8 outboxend = SearchL(outboxhome, KHref, KNullDesC8);
+				outbox = HBufC8::NewL(iBaseUrl->Length() + outboxend.Length());
+				outbox->Des().Append(*iBaseUrl);
+				outbox->Des().Append(outboxend);
+				}
+			}
+		CleanupStack::PopAndDestroy(status);
+		}
+	CleanupStack::PopAndDestroy(&document);
+	}
+
+/**
+ * CCalDavEngine::FindCalendarCollectionL
+ * find all calendar collections under home url
+ */
+HBufC8* CCalDavEngine::FindCalendarCollectionL(const TDesC8 &aUrl,
+		CDesC8ArrayFlat *aArray)
+	{
+	HBufC8* homecalendar = 0;
+
+	// do propfind depth:1 and find all calendar collections
+	// right now, take the first one as default
+	CBufFlat* response = CBufFlat::NewL(EXPANDSIZE_SMALL);
+	CleanupStack::PushL(response);
+	TInt retcode = iHttp->PropfindL(aUrl, KCalendarurl, response, EFalse);
+	if (retcode == MULTISTATUS)
+		{
+		RXmlEngDocument document = iDomParser.ParseL(response->Ptr(0));
+		CleanupClosePushL(document);
+		if (document.NotNull() && document.DocumentElement().NotNull())
+			{
+			RXmlEngNodeList<TXmlEngElement> ResponseList;
+			CleanupClosePushL(ResponseList);
+			document.DocumentElement().GetElementsByTagNameL(ResponseList,
+					KResponse, KDav);
+			TBool FirstOneDone = EFalse;
+			while (ResponseList.HasNext())
+				{
+				TXmlEngElement node = ResponseList.Next();
+				TPtrC8 href = SearchL(node, KHref, KNullDesC8);
+				TPtrC8 status = SearchL(node, KStatus, KNullDesC8);
+
+				TXmlEngElement calendar;
+				TXmlEngElement vevent_collection;
+				TXmlEngElement vtodo_collection;
+				SearchL(node, KCalendar, KNullDesC8, calendar);
+				SearchL(node, KVEventCollection, KNullDesC8, vevent_collection);
+				SearchL(node, KVTodoCollection, KNullDesC8, vtodo_collection);
+
+				if (calendar.NotNull() || vevent_collection.NotNull()
+						|| vtodo_collection.NotNull())
+					{
+					if (!FirstOneDone)
+						{
+						homecalendar = HBufC8::NewL(iBaseUrl->Length()
+								+ href.Length());
+						homecalendar->Des().Append(*iBaseUrl);
+						homecalendar->Des().Append(href);
+
+						iOptions.VEVENT = vevent_collection.NotNull();
+						iOptions.VTODO = vtodo_collection.NotNull();
+
+						FirstOneDone = ETrue;
+						}
+
+					if (aArray)
+						{
+						TBuf8<URLMAX> url;
+						url.Append(*iBaseUrl);
+						url.Append(href);
+						aArray->AppendL(url);
+						}
+					}
+				}
+			CleanupStack::PopAndDestroy(&ResponseList);
+			}
+		CleanupStack::PopAndDestroy(&document);
+		}
+	CleanupStack::PopAndDestroy(response);
+	return homecalendar;
+	}
+
+/**
+ * CCalDavEngine::GetCalendarUrlsL
+ * find calendar url based on any url
+ * could be principal url, home or direct calendar url
+ */
+TInt CCalDavEngine::GetCalendarUrlsL(CDesC8ArrayFlat *aArray)
+	{
+	if (iHttp && iUrl)
+		{
+		HBufC8 *principal = 0;
+		HBufC8 *home = 0;
+		HBufC8 *homecalendar = 0;
+		HBufC8 *inbox = 0;
+		HBufC8 *outbox = 0;
+
+		GetBaseUrl(*iUrl);
+
+		// TODO: does this really find groupdav collection?
+
+		// find out if this is a caldav or groupdav calendar collection
+		CBufFlat* response = CBufFlat::NewL(EXPANDSIZE_SMALL);
+		CleanupStack::PushL(response);
+		TInt retcode = iHttp->PropfindL(*iUrl, KCalendarurl, response);
+		if (retcode == MULTISTATUS)
+			{
+			RXmlEngDocument document = iDomParser.ParseL(response->Ptr(0));
+			CleanupClosePushL(document);
+			if (document.NotNull())
+				{
+				HBufC8* status =
+						SearchL(document, KStatus, KNullDesC8).AllocLC();
+				status->Des().LowerCase();
+				TXmlEngElement calendar;
+				SearchL(document, KCalendar, KNullDesC8, calendar);
+				// it should be <owner><href>value</href></owner>
+				// but oracle beehive server does <owner>value</owner>
+				TXmlEngElement owner;
+				SearchL(document, KOwner, KNullDesC8, owner);
+				TPtrC8 ownerref1 = SearchL(owner, KHref, KNullDesC8);
+				TPtrC8 ownerref2 = owner.Value();
+				TPtrC8 ownerref;
+				ownerref.Set(ownerref1 != KNullDesC8 ? ownerref1 : ownerref2);
+
+				if (calendar.NotNull() && (ownerref != KNullDesC8) && (*status
+						== KHTTP200))
+					{
+					// this is a calendar collection and we know the principal as well now
+					homecalendar = iUrl->AllocL();
+					_LIT8(KHTTP,"http");
+					HBufC8* http = ownerref.Left(KHTTP().Length()).AllocLC();
+					if (*http == KHTTP)
+						{
+						// sogo server does not return relative, but principal url
+						principal = ownerref.AllocL();
+						}
+					else
+						{
+						principal = HBufC8::NewL(iBaseUrl->Length()
+								+ ownerref.Length());
+						principal->Des().Append(*iBaseUrl);
+						principal->Des().Append(ownerref);
+						}
+					CleanupStack::PopAndDestroy(http);
+					}
+				CleanupStack::PopAndDestroy(status);
+				}
+			CleanupStack::PopAndDestroy(&document);
+			}
+
+		// if we have principal, ask for home, otherwise see if principal was given in the first place
+		if (principal)
+			{
+			response->Reset();
+			TInt retcode =
+					iHttp->PropfindL(*principal, KPrincipalurl, response);
+			if (retcode == MULTISTATUS)
+				{
+				FindUrlsL(response->Ptr(0), home, inbox, outbox);
+				}
+			}
+		else
+			{
+			response->Reset();
+			TInt retcode = iHttp->PropfindL(*iUrl, KPrincipalurl, response);
+			if (retcode == MULTISTATUS)
+				{
+				FindUrlsL(response->Ptr(0), home, inbox, outbox);
+				}
+			}
+
+		home = CalDavUtils::EnsureSlashL(home);
+		inbox = CalDavUtils::EnsureSlashL(inbox);
+		outbox = CalDavUtils::EnsureSlashL(outbox);
+
+		// find out all calendar collections under home
+		if (home)
+			{
+			// TODO: temporary? we already have homecalendar...
+			if (!homecalendar)
+				{
+				homecalendar = FindCalendarCollectionL(*home, aArray);
+				}
+			}
+		else
+			{
+			// have not found out home nor a groupdav collection, maybe we are home ourselves
+			homecalendar = FindCalendarCollectionL(*iUrl, aArray);
+			if (homecalendar)
+				home = iUrl->AllocL();
+			}
+
+		CleanupStack::PopAndDestroy(response);
+		delete principal;
+		delete inbox;
+		delete outbox;
+
+		if (home)
+			iHome = CalDavUtils::EnsureSlashL(home);
+		if (homecalendar)
+			{
+			delete iUrl;
+			iUrl = NULL;
+			iUrl = CalDavUtils::EnsureSlashL(homecalendar);
+			return KErrNone;
+			}
+		else
+			return KErrArgument;
+		}
+	return KErrArgument;
+	}
+
+/**
+ * CCalDavEngine::CalendarName
+ * get calendar name
+ */
+TPtrC CCalDavEngine::CalendarName() const
+	{
+	return iCalendar ? *iCalendar : KNullDesC();
+	}
+
+/**
+ * CCalDavEngine::Home
+ * get home
+ */
+TPtrC8 CCalDavEngine::Home() const
+	{
+	return iHome ? *iHome : KNullDesC8();
+	}
+
+/**
+ * CCalDavEngine::Url
+ * get url
+ */
+TPtrC8 CCalDavEngine::Url() const
+	{
+	return iUrl ? *iUrl : KNullDesC8();
+	}
+
+/**
+ * CCalDavEngine::SetUrlL
+ * set url
+ */
+void CCalDavEngine::SetUrlL(const TDesC8 &aUrl)
+	{
+	if (iUrl ? *iUrl != aUrl : ETrue)
+		{
+		DisableL();
+
+		if (iUrl)
+			{
+			delete iUrl;
+			iUrl = NULL;
+			}
+
+		iUrl = CalDavUtils::EnsureSlashL(aUrl);
+		SetCalendarInfoL(KCaldavUrl, *iUrl);
+		}
+	}
+
+/**
+ * CCalDavEngine::User
+ * get user
+ */
+TPtrC8 CCalDavEngine::User() const
+	{
+	return iHttp->User();
+	}
+
+/**
+ * CCalDavEngine::SetUserL
+ * set user
+ */
+void CCalDavEngine::SetUserL(const TDesC8 &aUser)
+	{
+	if (iHttp->User() != aUser)
+		{
+		DisableL();
+		SetCalendarInfoL(KCaldavUser, aUser);
+		iHttp->SetUserL(aUser);
+		}
+	}
+
+/**
+ * CCalDavEngine::Password
+ * get password
+ */
+TPtrC8 CCalDavEngine::Password() const
+	{
+	return iHttp->Password();
+	}
+
+/**
+ * CCalDavEngine::SetPasswordL
+ * set password
+ */
+void CCalDavEngine::SetPasswordL(const TDesC8 &aPassword)
+	{
+	if (iHttp->Password() != aPassword)
+		{
+		DisableL();
+		iHttp->SetPasswordL(aPassword);
+		SetCalendarInfoL(KCaldavPassword, aPassword);
+		}
+	}
+
+/**
+ * CCalDavEngine::SyncInterval
+ * get SyncInterval
+ */
+TTimeIntervalMinutes CCalDavEngine::SyncInterval() const
+	{
+	return iSyncInterval;
+	}
+
+/**
+ * CCalDavEngine::SetSyncIntervalL
+ * set SetSyncIntervalL
+ */
+void CCalDavEngine::SetSyncIntervalL(TTimeIntervalMinutes aSyncInterval)
+	{
+	iSyncInterval = aSyncInterval;
+	TPckgC<TTimeIntervalMinutes> minutes(iSyncInterval);
+	SetCalendarInfoL(KCaldavSyncInterval, minutes);
+	}
+
+/**
+ * CCalDavEngine::PastDays
+ * get past days
+ */
+TTimeIntervalDays CCalDavEngine::PastDays() const
+	{
+	return iPastDays;
+	}
+
+/**
+ * CCalDavEngine::SetPastDaysL
+ * Set PastDaysL
+ */
+void CCalDavEngine::SetPastDaysL(TTimeIntervalDays aDays)
+	{
+	iPastDays = aDays;
+	TPckgC<TTimeIntervalDays> days(iPastDays);
+	SetCalendarInfoL(KCaldavPastDays, days);
+	}
+
+/**
+ * CCalDavEngine::ImmediateSync
+ * get ImmediateSyncL
+ */
+TBool CCalDavEngine::ImmediateSync() const
+	{
+	return iImmediateSync;
+	}
+
+/**
+ * CCalDavEngine::SetImmediateSyncL
+ * Set ImmediateSyncL
+ */
+void CCalDavEngine::SetImmediateSyncL(TBool aImmediateSyc)
+	{
+	iImmediateSync = aImmediateSyc;
+	TPckgC<TBool> immediatesync(iImmediateSync);
+	SetCalendarInfoL(KCaldavImmediateSync, immediatesync);
+	}
+
+/**
+ * CCalDavEngine::KeepServerEntry
+ * get KeepServerEntryL
+ */
+TBool CCalDavEngine::KeepServerEntry() const
+	{
+	return iKeepServerEntry;
+	}
+
+/**
+ * CCalDavEngine::SetKeepServerEntryL
+ * Set KeepServerEntryL
+ */
+void CCalDavEngine::SetKeepServerEntryL(TBool aKeepServerEntry)
+	{
+	iKeepServerEntry = aKeepServerEntry;
+	TPckgC<TBool> keepserver(iKeepServerEntry);
+	SetCalendarInfoL(KCaldavKeepServer, keepserver);
+	}
+
+/**
+ * CCalDavEngine::Timer
+ * get timer
+ */
+CPeriodic* CCalDavEngine::Timer()
+	{
+	return iTimer;
+	}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/src/caldavenginemgr.cpp	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,372 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: provides a manager to keep track of all available engines
+*
+*/
+
+#include "caldavenginemgr.h"
+#include "caldavengine.h"
+
+#include <calsession.h>
+#include <calcalendarinfo.h>
+#include "calenglobaldata.h"
+
+/**
+ * CCalDavEngineMgr::CCalDavEngineMgr()
+ * default constructor
+ */
+CCalDavEngineMgr::CCalDavEngineMgr()
+	{
+	}
+
+/**
+ * CCalDavEngineMgr::~CCalDavEngineMgr()
+ * default destructor
+ */
+CCalDavEngineMgr::~CCalDavEngineMgr()
+	{
+	for (TInt i = iEngines.Count() - 1; i >= 0; --i)
+		delete iEngines[i];
+	iEngines.Close();
+	}
+
+/**
+ * CCalDavEngineMgr::NewLC()
+ * first phase construction
+ */
+CCalDavEngineMgr* CCalDavEngineMgr::NewLC()
+	{
+	CCalDavEngineMgr* self = new (ELeave) CCalDavEngineMgr();
+	CleanupStack::PushL(self);
+	self->ConstructL();
+	return self;
+	}
+
+/**
+ * CCalDavEngineMgr::NewL()
+ * first phase construction
+ */
+CCalDavEngineMgr* CCalDavEngineMgr::NewL()
+	{
+	CCalDavEngineMgr* self = CCalDavEngineMgr::NewLC();
+	CleanupStack::Pop(); // self;
+	return self;
+	}
+
+/**
+ * CCalDavEngineMgr::Progress()
+ * progress callback
+ */
+void CCalDavEngineMgr::Progress(TInt /*aPercentageCompleted*/)
+	{
+	}
+
+/**
+ * CCalDavEngineMgr::Completed()
+ * completed callback
+ */
+void CCalDavEngineMgr::Completed(TInt /*aError*/)
+	{
+	}
+
+/**
+ * CCalDavEngineMgr::NotifyProgress()
+ * NotifyProgress callback
+ */
+TBool CCalDavEngineMgr::NotifyProgress()
+	{
+	return EFalse;
+	}
+
+/**
+ * CCalDavEngineMgr::ConstructL()
+ * second phase construction
+ * check all calendar files, for each one which has caldav sync enabled, 
+ * create a CCalDavengine and enable sync
+ */
+void CCalDavEngineMgr::ConstructL()
+	{
+	RPointerArray<CCalCalendarInfo> calendarInfoList;
+	CCalenGlobalData* data = CCalenGlobalData::NewL(*this);
+	data->InitializeGlobalDataL();
+	CleanupStack::PushL(data);
+	data->GetAllCalendarInfoL(calendarInfoList);
+	CleanupClosePushL(calendarInfoList);
+
+	for (TInt i = 0; i < calendarInfoList.Count(); i++)
+		{
+		CDesC8Array* propertyKeys = calendarInfoList[i]->PropertyKeysL();
+		CleanupStack::PushL(propertyKeys);
+		TInt pos = 0;
+		if (propertyKeys->Find(KCaldavEnabled, pos, ECmpNormal) == KErrNone)
+			{
+			CCalDavEngine* engine = CCalDavEngine::NewL(
+					calendarInfoList[i]->FileNameL());
+			iEngines.Append(engine);
+			if (engine->EnabledSync())
+				engine->EnableL();
+			}
+		CleanupStack::PopAndDestroy(propertyKeys);
+		}
+	CleanupStack::PopAndDestroy(&calendarInfoList);
+	CleanupStack::PopAndDestroy(data);
+	}
+
+/**
+ * CCalDavEngineMgr::FindEngineL()
+ * find engines inside engine array, create if neccessary
+ */
+TInt CCalDavEngineMgr::FindEngineL(const TDesC &aName, TBool aCreate)
+	{
+	CCalSession* session = CCalSession::NewL();
+	TRAPD(error,session->OpenL(aName));
+	delete session;
+	if (error != KErrNone)
+		return KErrNotFound;
+		
+	for (TInt i = 0; i <= iEngines.Count() - 1; i++)
+		{
+		if (iEngines[i]->CalendarName() == aName)
+			return i;
+		}
+
+	if (aCreate)
+		{
+		iEngines.Append(CCalDavEngine::NewL(aName));
+		return iEngines.Count() - 1;
+		}
+	else
+		return KErrNotFound;
+	}
+
+/**
+ * CCalDavEngineMgr::SyncL()
+ * sync specific calendar
+ */
+TInt CCalDavEngineMgr::SyncL(const TDesC &aCalendar)
+	{
+	TInt pos = FindEngineL(aCalendar);
+	if (pos != KErrNotFound)
+		return iEngines[pos]->SyncL();
+	else
+		return KErrNotFound;
+	}
+
+/**
+ * CCalDavEngineMgr::SyncAllL()
+ * sync all calendars
+ */
+TInt CCalDavEngineMgr::SyncAllL()
+	{
+	// sync all caldav enabled calendars
+	for (TInt i = 0; i <= iEngines.Count() - 1; i++)
+		iEngines[i]->SyncL();
+	return KErrNone;
+	}
+
+/**
+ * CCalDavEngineMgr::DisableL()
+ * 
+ */
+TInt CCalDavEngineMgr::DisableL(const TDesC &aCalendar)
+	{
+	TInt pos = FindEngineL(aCalendar);
+
+	if (pos != KErrNotFound)
+		iEngines[pos]->DisableL();
+
+	return pos == KErrNotFound ? KErrNotFound : KErrNone;
+	}
+
+/**
+ * CCalDavEngineMgr::EnableL()
+ * 
+ */
+TInt CCalDavEngineMgr::EnableL(const TDesC &aCalendar)
+	{
+	TInt pos = FindEngineL(aCalendar);
+	if (pos != KErrNotFound)
+		{
+		return iEngines[pos]->EnableL();
+		}
+
+	return KErrArgument;
+	}
+
+/**
+ * CCalDavEngineMgr::UrlL()
+ * 
+ */
+TPtrC8 CCalDavEngineMgr::UrlL(const TDesC &aCalendar)
+	{
+	TInt pos = FindEngineL(aCalendar);
+	return (pos != KErrNotFound) ? iEngines[pos]->Url() : KNullDesC8();
+	}
+
+/**
+ * CCalDavEngineMgr::SetUrlL()
+ * 
+ */
+void CCalDavEngineMgr::SetUrlL(const TDesC &aCalendar, const TDesC8 &aUrl)
+	{
+	TInt pos = FindEngineL(aCalendar, ETrue);
+	if (pos != KErrNotFound)
+		iEngines[pos]->SetUrlL(aUrl);
+	}
+
+/**
+ * CCalDavEngineMgr::UsernameL()
+ * 
+ */
+TPtrC8 CCalDavEngineMgr::UsernameL(const TDesC &aCalendar)
+	{
+	TInt pos = FindEngineL(aCalendar);
+	return (pos != KErrNotFound) ? iEngines[pos]->User() : KNullDesC8();
+	}
+
+/**
+ * CCalDavEngineMgr::SetUsernameL()
+ * 
+ */
+void CCalDavEngineMgr::SetUsernameL(const TDesC &aCalendar,
+		const TDesC8 &aUsername)
+	{
+	TInt pos = FindEngineL(aCalendar, ETrue);
+	if (pos != KErrNotFound)
+		iEngines[pos]->SetUserL(aUsername);
+	}
+
+/**
+ * CCalDavEngineMgr::PasswordL()
+ * 
+ */
+TPtrC8 CCalDavEngineMgr::PasswordL(const TDesC &aCalendar)
+	{
+	TInt pos = FindEngineL(aCalendar);
+	return (pos != KErrNotFound) ? iEngines[pos]->Password() : KNullDesC8();
+	}
+
+/**
+ * CCalDavEngineMgr::SetPasswordL()
+ * 
+ */
+void CCalDavEngineMgr::SetPasswordL(const TDesC &aCalendar,
+		const TDesC8 &aPassword)
+	{
+	TInt pos = FindEngineL(aCalendar, ETrue);
+	if (pos != KErrNotFound)
+		iEngines[pos]->SetPasswordL(aPassword);
+	}
+
+/**
+ * CCalDavEngineMgr::SyncIntervalL()
+ * 
+ */
+TTimeIntervalMinutes CCalDavEngineMgr::SyncIntervalL(const TDesC &aCalendar)
+	{
+	TInt pos = FindEngineL(aCalendar);
+	return (pos != KErrNotFound) ? iEngines[pos]->SyncInterval()
+			: TTimeIntervalMinutes(DEFAULT_SYNC_MINUTES);
+	}
+
+/**
+ * CCalDavEngineMgr::SetSyncIntervalL()
+ * 
+ */
+void CCalDavEngineMgr::SetSyncIntervalL(const TDesC &aCalendar,
+		TTimeIntervalMinutes aSyncInterval)
+	{
+	TInt pos = FindEngineL(aCalendar, ETrue);
+	if (pos != KErrNotFound)
+		iEngines[pos]->SetSyncIntervalL(aSyncInterval);
+	}
+
+/**
+ * CCalDavEngineMgr::PastDaysL()
+ * 
+ */
+TTimeIntervalDays CCalDavEngineMgr::PastDaysL(const TDesC &aCalendar)
+	{
+	TInt pos = FindEngineL(aCalendar);
+	return (pos != KErrNotFound) ? iEngines[pos]->PastDays()
+			: TTimeIntervalDays(DEFAULT_PAST_DAYS);
+	}
+
+/**
+ * CCalDavEngineMgr::SetPastDaysL()
+ * 
+ */
+void CCalDavEngineMgr::SetPastDaysL(const TDesC &aCalendar,
+		TTimeIntervalDays aDays)
+	{
+	TInt pos = FindEngineL(aCalendar, ETrue);
+	if (pos != KErrNotFound)
+		iEngines[pos]->SetPastDaysL(aDays);
+	}
+
+/**
+ * CCalDavEngineMgr::ImmediateSyncL()
+ * 
+ */
+TBool CCalDavEngineMgr::ImmediateSyncL(const TDesC &aCalendar)
+	{
+	TInt pos = FindEngineL(aCalendar);
+	return pos != KErrNotFound ? iEngines[pos]->ImmediateSync()
+			: DEFAULT_IMMEDIATE_SYNC;
+	}
+
+/**
+ * CCalDavEngineMgr::SetImmediateSyncL()
+ * 
+ */
+void CCalDavEngineMgr::SetImmediateSyncL(const TDesC &aCalendar,
+		TBool aImmediateSyc)
+	{
+	TInt pos = FindEngineL(aCalendar, ETrue);
+	if (pos != KErrNotFound)
+		iEngines[pos]->SetImmediateSyncL(aImmediateSyc);
+	}
+
+/**
+ * CCalDavEngineMgr::KeepServerEntryL()
+ * 
+ */
+TBool CCalDavEngineMgr::KeepServerEntryL(const TDesC &aCalendar)
+	{
+	TInt pos = FindEngineL(aCalendar);
+	return pos != KErrNotFound ? iEngines[pos]->KeepServerEntry()
+			: DEFAULT_KEEP_SERVER_ENTRY;
+	}
+
+/**
+ * CCalDavEngineMgr::SetKeepServerEntryL()
+ * 
+ */
+void CCalDavEngineMgr::SetKeepServerEntryL(const TDesC &aCalendar,
+		TBool aKeepServerEntry)
+	{
+	TInt pos = FindEngineL(aCalendar, ETrue);
+	if (pos != KErrNotFound)
+		iEngines[pos]->SetKeepServerEntryL(aKeepServerEntry);
+	}
+
+/**
+ * CCalDavEngineMgr::EnabledSyncL()
+ * 
+ */
+TBool CCalDavEngineMgr::EnabledSyncL(const TDesC &aCalendar)
+	{
+	TInt pos = FindEngineL(aCalendar);
+	return (pos != KErrNotFound) ? iEngines[pos]->EnabledSync() : EFalse;
+	}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/src/caldavserver.cpp	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,373 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: Caldav server, follows Symbian client/server 
+*				architecture
+*/
+
+#include <e32svr.h>
+#include <e32uid.h>
+#include <S32MEM.H> 
+
+#include <xmlengdocument.h>
+#include <xmlengtext.h>
+
+#include "caldavserver.h"
+#include "caldavenginemgr.h"
+#include "caldavserverSession.h"
+#include "httpclient.h"
+
+const TUint KServerPolicyRangeCount = 2;
+
+const TInt KServerPolicyRanges[KServerPolicyRangeCount] =
+	{
+	0, // range is 0 inclusive
+			200
+	// range is 1-KMaxTInt inclusive
+		};
+
+const TUint8 KServerPolicyElementsIndex[KServerPolicyRangeCount] =
+	{
+	0, // applies to 0th range
+			CPolicyServer::ENotSupported
+	// applies to 1st range
+		};
+
+/**
+ * CPolicyServer::TPolicyElement()
+ * 
+ */
+const CPolicyServer::TPolicyElement
+		KServerPolicyElements[] =
+			{
+						{
+								_INIT_SECURITY_POLICY_C5(ECapabilityWriteDeviceData,ECapabilityWriteUserData, ECapabilityReadDeviceData,ECapabilityReadUserData,ECapabilityNetworkServices), CPolicyServer::EFailClient
+						}
+			};
+
+const CPolicyServer::TPolicy KServerPolicy =
+	{
+	CPolicyServer::EAlwaysPass, // specifies all connect attempts should pass
+			KServerPolicyRangeCount,
+			KServerPolicyRanges,
+			KServerPolicyElementsIndex,
+			KServerPolicyElements
+	};
+
+/**
+ * CCalDavServer::CCalDavServer
+ * default constructor
+ */
+CCalDavServer::CCalDavServer(CActive::TPriority aActiveObjectPriority) :
+	CPolicyServer(aActiveObjectPriority, KServerPolicy)
+	{
+	}
+
+/**
+ * CCalDavServer::NewSessionL
+ * Creates a new session with the server.
+ */
+CSession2* CCalDavServer::NewSessionL(const TVersion& aVersion,
+		const RMessage2& /*aMessage*/) const
+	{
+	// Check that the version is OK
+	TVersion v(KCalDavServerMajorVersionNumber,
+			KCalDavServerMinorVersionNumber, KCalDavServerBuildVersionNumber);
+	if (!User::QueryVersionSupported(v, aVersion))
+		User::Leave(KErrNotSupported);
+
+	// CAN USE THE aMessage argument to check client's security and identity
+	// can make use of this later but for now ignore. AH 4/5/05
+	// the connect message is delivered via the RMessage2 object passed. 
+
+	// do something with this later (and move it to the start of the function?)
+
+	// Create the session.
+	return new (ELeave) CCalDavServerSession(*const_cast<CCalDavServer*> (this));
+	}
+
+/**
+* CCalDavServer::PanicServer
+ A utility function to panic the server.
+ */
+void CCalDavServer::PanicServer(TCalDavServPanic aPanic)
+	{
+	_LIT(KTxtServerPanic,"CalDav server panic");
+	User::Panic(KTxtServerPanic, aPanic);
+	}
+
+/**
+ * CCalDavServer::ThreadFunction
+ * The count server thread function that initialises the server.
+ */
+TInt CCalDavServer::ThreadFunction(TAny* /**aStarted*/)
+	{
+	CTrapCleanup* cleanupStack = CTrapCleanup::New();
+	if (!(cleanupStack))
+		{
+		PanicServer(ECreateTrapCleanup);
+		}
+	TRAPD( err, ThreadFunctionL() );
+	if (err != KErrNone)
+		{
+		PanicServer(ESvrCreateServer);
+		}
+
+	delete cleanupStack;
+	cleanupStack = NULL;
+
+	return KErrNone;
+
+	}
+
+/**
+ * CCalDavServer::NewLC
+ * first phase construction
+ */
+CCalDavServer* CCalDavServer::NewLC()
+	{
+	CCalDavServer* self =
+			new (ELeave) CCalDavServer(CActive::EPriorityStandard);
+	CleanupStack::PushL(self);
+	self->ConstructL();
+	return self;
+	}
+
+/**
+ * CCalDavServer::ConstructL
+ * second phase construction
+ */
+void CCalDavServer::ConstructL()
+	{
+	StartL(KCalDavServerName);
+
+	iMgr = CCalDavEngineMgr::NewL();
+	}
+
+/**
+ * CCalDavServer::ThreadFunctionL
+ * start scheduler and construct function
+ */
+void CCalDavServer::ThreadFunctionL()
+	{
+	// Construct active scheduler
+	CActiveScheduler* activeScheduler = new (ELeave) CActiveScheduler;
+	CleanupStack::PushL(activeScheduler);
+
+	// Install active scheduler
+	// We don't need to check whether an active scheduler is already installed
+	// as this is a new thread, so there won't be one
+	CActiveScheduler::Install(activeScheduler);
+
+	// Construct our server, leave it on clean-up stack
+	CCalDavServer::NewLC();
+
+	// Naming the server thread after the server helps to debug panics
+	User::LeaveIfError(User::RenameThread(KCalDavServerName));
+
+	RProcess::Rendezvous(KErrNone);
+
+	// Start handling requests
+	CActiveScheduler::Start();
+
+	CleanupStack::PopAndDestroy(2, activeScheduler); //Anonymous CCalDavServer
+	}
+
+/**
+ * CCalDavServer::~CCalDavServer
+ * default destructor
+ */
+CCalDavServer::~CCalDavServer()
+	{
+	if (iMgr)
+		delete iMgr;
+	}
+
+/**
+ * CCalDavServer::SyncL
+ * 
+ */
+TInt CCalDavServer::SyncL(const TDesC &aCalendar)
+	{
+	return iMgr->SyncL(aCalendar);
+	}
+
+/**
+ * CCalDavServer::SyncAllL
+ * 
+ */
+TInt CCalDavServer::SyncAllL()
+	{
+	return iMgr->SyncAllL();
+	}
+
+/**
+ * CCalDavServer::EnableL
+ * 
+ */
+TInt CCalDavServer::EnableL(const TDesC &aCalendar)
+	{
+	return iMgr->EnableL(aCalendar);
+	}
+
+/**
+ * CCalDavServer::DisableL
+ * 
+ */
+TInt CCalDavServer::DisableL(const TDesC &aCalendar)
+	{
+	return iMgr->DisableL(aCalendar);
+	}
+
+/**
+ * CCalDavServer::UrlL
+ * 
+ */
+TPtrC8 CCalDavServer::UrlL(const TDesC &aCalendar)
+	{
+	return iMgr->UrlL(aCalendar);
+	}
+
+/**
+ * CCalDavServer::SetUrlL
+ * 
+ */
+void CCalDavServer::SetUrlL(const TDesC &aCalendar, const TDesC8 &aUrl)
+	{
+	return iMgr->SetUrlL(aCalendar, aUrl);
+	}
+
+/**
+ * CCalDavServer::UsernameL
+ * 
+ */
+TPtrC8 CCalDavServer::UsernameL(const TDesC &aCalendar)
+	{
+	return iMgr->UsernameL(aCalendar);
+	}
+
+/**
+ * CCalDavServer::SetUsernameL
+ * 
+ */
+void CCalDavServer::SetUsernameL(const TDesC &aCalendar, const TDesC8 &aUsername)
+	{
+	return iMgr->SetUsernameL(aCalendar, aUsername);
+	}
+
+/**
+ * CCalDavServer::PasswordL
+ * 
+ */
+TPtrC8 CCalDavServer::PasswordL(const TDesC &aCalendar)
+	{
+	return iMgr->PasswordL(aCalendar);
+	}
+
+/**
+ * CCalDavServer::SetPasswordL
+ * 
+ */
+void CCalDavServer::SetPasswordL(const TDesC &aCalendar, const TDesC8 &aPassword)
+	{
+	return iMgr->SetPasswordL(aCalendar, aPassword);
+	}
+
+/**
+ * CCalDavServer::SyncIntervalL
+ * 
+ */
+TTimeIntervalMinutes CCalDavServer::SyncIntervalL(const TDesC &aCalendar) const
+	{
+	return iMgr->SyncIntervalL(aCalendar);
+	}
+
+/**
+ * CCalDavServer::SetSyncIntervalL
+ * 
+ */
+void CCalDavServer::SetSyncIntervalL(const TDesC &aCalendar,
+		TTimeIntervalMinutes aSyncInterval)
+	{
+	iMgr->SetSyncIntervalL(aCalendar, aSyncInterval);
+	}
+
+/**
+ * CCalDavServer::EnabledSyncL
+ * 
+ */
+TBool CCalDavServer::EnabledSyncL(const TDesC &aCalendar) const
+	{
+	return iMgr->EnabledSyncL(aCalendar);
+	}
+
+/**
+ * CCalDavServer::PastDaysL
+ * 
+ */
+TTimeIntervalDays CCalDavServer::PastDaysL(const TDesC &aCalendar) const
+	{
+	return iMgr->PastDaysL(aCalendar);
+	}
+
+/**
+ * CCalDavServer::SetPastDaysL
+ * 
+ */
+void CCalDavServer::SetPastDaysL(const TDesC &aCalendar, TTimeIntervalDays aDays)
+	{
+	iMgr->SetPastDaysL(aCalendar, aDays);
+	}
+
+/**
+ * CCalDavServer::ImmediateSyncL
+ * 
+ */
+TBool CCalDavServer::ImmediateSyncL(const TDesC &aCalendar) const
+	{
+	return iMgr->ImmediateSyncL(aCalendar);
+	}
+
+/**
+ * CCalDavServer::SetImmediateSyncL
+ * 
+ */
+void CCalDavServer::SetImmediateSyncL(const TDesC &aCalendar,
+		TBool aImmediateSyc)
+	{
+	iMgr->SetImmediateSyncL(aCalendar, aImmediateSyc);
+	}
+
+/**
+ * CCalDavServer::KeepServerEntryL
+ * 
+ */
+TBool CCalDavServer::KeepServerEntryL(const TDesC &aCalendar) const
+	{
+	return iMgr->KeepServerEntryL(aCalendar);
+	}
+
+/**
+ * CCalDavServer::SetKeepServerEntryL
+ * 
+ */
+void CCalDavServer::SetKeepServerEntryL(const TDesC &aCalendar,
+		TBool aKeepServerEntry)
+	{
+	iMgr->SetKeepServerEntryL(aCalendar, aKeepServerEntry);
+	}
+
+TInt E32Main()
+	{
+	return CCalDavServer::ThreadFunction(NULL);
+	}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/src/caldavserversession.cpp	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,400 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: Caldav server session, follows Symbian 
+* 				client/server architecture
+*/
+
+#include <e32cmn.h>
+
+#include "caldavserversession.h"
+#include "caldavserver.h"
+#include "caldavutils.h"
+
+#define MAXLENGTH	500
+
+CCalDavServerSession::CCalDavServerSession(CCalDavServer &aServer) :
+	rServer(aServer)
+	{
+	}
+
+/**
+ Services a client request.
+ */
+void CCalDavServerSession::ServiceL(const RMessage2& aMessage)
+	{
+	TRAP_IGNORE(DispatchMessageL(aMessage));
+	}
+
+/**
+ Called by ServiceL()
+
+ It tests the function code and then delegates to
+ the appropriate function.
+ */
+void CCalDavServerSession::DispatchMessageL(const RMessage2& aMessage)
+	{
+	switch (aMessage.Function())
+		{
+		case ECalDavEnable:
+			EnableL(aMessage);
+			return;
+		case ECalDavDisable:
+			DisableL(aMessage);
+			return;
+		case ECalDavSyncAll:
+			SyncAllL(aMessage);
+			return;
+		case ECalDavSync:
+			SyncL(aMessage);
+			return;
+		case ECalDavUrl:
+			UrlL(aMessage);
+			return;
+		case ECalDavSetUrl:
+			SetUrlL(aMessage);
+			return;
+		case ECalDavUsername:
+			UsernameL(aMessage);
+			return;
+		case ECalDavSetUsername:
+			SetUsernameL(aMessage);
+			return;
+		case ECalDavPassword:
+			PasswordL(aMessage);
+			return;
+		case ECalDavSetPassword:
+			SetPasswordL(aMessage);
+			return;
+		case ECalDavSyncInterval:
+			SyncIntervalL(aMessage);
+			return;
+		case ECalDavSetSyncInterval:
+			SetSyncIntervalL(aMessage);
+			return;
+		case ECalDavPastDays:
+			PastDaysL(aMessage);
+			return;
+		case ECalDavSetPastDays:
+			SetPastDaysL(aMessage);
+			return;
+		case ECalDavImmediateSync:
+			ImmediateSyncL(aMessage);
+			return;
+		case ECalDavSetImmediateSync:
+			SetImmediateSyncL(aMessage);
+			return;
+		case ECalDavKeepServer:
+			KeepServerEntryL(aMessage);
+			return;
+		case ECalDavSetKeepServer:
+			SetKeepServerEntryL(aMessage);
+			return;
+		case ECalDavEnabled:
+			EnabledSyncL(aMessage);
+			return;
+		case ECalDavUnsupportedRequest:
+			User::Leave(KErrNotSupported);
+			//  Requests that we don't understand at all are a different matter.
+			//  This is considered a client programming error, so we panic the 
+			//  client - this also completes the message.
+		default:
+			PanicClient(aMessage, EBadRequest);
+			return;
+		}
+	}
+
+/**
+ Panics the client
+ */
+void CCalDavServerSession::PanicClient(const RMessage2& aMessage, TInt aPanic) const
+	{
+	_LIT(KTxtServer,"CalDav server");
+	aMessage.Panic(KTxtServer, aPanic);
+	}
+
+void CCalDavServerSession::EnableL(const RMessage2& aMessage)
+	{
+	TUint length = aMessage.GetDesLength(0);
+	HBufC* calendar = HBufC::NewLC(length);
+	TPtr calendarPtr(calendar->Des());
+	aMessage.ReadL(0, calendarPtr);
+
+	TInt result = rServer.EnableL(*calendar);
+
+	CleanupStack::PopAndDestroy(calendar);
+	aMessage.Complete(result);
+	}
+
+void CCalDavServerSession::DisableL(const RMessage2& aMessage)
+	{
+	TUint length = aMessage.GetDesLength(0);
+	HBufC* calendar = HBufC::NewLC(length);
+	TPtr calendarPtr(calendar->Des());
+	aMessage.ReadL(0, calendarPtr);
+
+	TInt result = rServer.DisableL(*calendar);
+	CleanupStack::PopAndDestroy(calendar);
+	aMessage.Complete(result);
+	}
+
+void CCalDavServerSession::SyncL(const RMessage2& aMessage)
+	{
+	TUint length = aMessage.GetDesLength(0);
+	HBufC* calendar = HBufC::NewLC(length);
+	TPtr calendarPtr(calendar->Des());
+	aMessage.ReadL(0, calendarPtr);
+
+	TInt result = rServer.SyncL(*calendar);
+	CleanupStack::PopAndDestroy(calendar);
+	aMessage.Complete(result);
+	}
+
+void CCalDavServerSession::SyncAllL(const RMessage2& aMessage)
+	{
+	TInt result = rServer.SyncAllL();
+	aMessage.Complete(result);
+	}
+
+void CCalDavServerSession::UrlL(const RMessage2& aMessage)
+	{
+	TUint length = aMessage.GetDesLength(0);
+	HBufC* calendar = HBufC::NewLC(length);
+	TPtr calendarPtr(calendar->Des());
+	aMessage.ReadL(0, calendarPtr);
+
+	aMessage.WriteL(1, rServer.UrlL(*calendar));
+	CleanupStack::PopAndDestroy(calendar);
+	aMessage.Complete(KErrNone);
+	}
+
+void CCalDavServerSession::SetUrlL(const RMessage2& aMessage)
+	{
+	TUint length = aMessage.GetDesLength(0);
+	HBufC* calendar = HBufC::NewLC(length);
+	TPtr calendarPtr(calendar->Des());
+	aMessage.ReadL(0, calendarPtr);
+
+	length = aMessage.GetDesLength(1);
+	HBufC8* url = HBufC8::NewLC(length);
+	TPtr8 urlPtr(url->Des());
+	aMessage.ReadL(1, urlPtr);
+
+	rServer.SetUrlL(*calendar, *url);
+	CleanupStack::PopAndDestroy(url);
+	CleanupStack::PopAndDestroy(calendar);
+
+	aMessage.Complete(KErrNone);
+	}
+
+void CCalDavServerSession::UsernameL(const RMessage2& aMessage)
+	{
+	TUint length = aMessage.GetDesLength(0);
+	HBufC* calendar = HBufC::NewLC(length);
+	TPtr calendarPtr(calendar->Des());
+	aMessage.ReadL(0, calendarPtr);
+
+	aMessage.WriteL(1, rServer.UsernameL(*calendar));
+	CleanupStack::PopAndDestroy(calendar);
+	aMessage.Complete(KErrNone);
+	}
+
+void CCalDavServerSession::SetUsernameL(const RMessage2& aMessage)
+	{
+	TUint length = aMessage.GetDesLength(0);
+	HBufC* calendar = HBufC::NewLC(length);
+	TPtr calendarPtr(calendar->Des());
+	aMessage.ReadL(0, calendarPtr);
+
+	length = aMessage.GetDesLength(1);
+	HBufC8* username = HBufC8::NewLC(length);
+	TPtr8 usernamePtr(username->Des());
+	aMessage.ReadL(1, usernamePtr);
+
+	rServer.SetUsernameL(*calendar, *username);
+	CleanupStack::PopAndDestroy(username);
+	CleanupStack::PopAndDestroy(calendar);
+
+	aMessage.Complete(KErrNone);
+	}
+
+void CCalDavServerSession::PasswordL(const RMessage2& aMessage)
+	{
+	TUint length = aMessage.GetDesLength(0);
+	HBufC* calendar = HBufC::NewLC(length);
+	TPtr calendarPtr(calendar->Des());
+	aMessage.ReadL(0, calendarPtr);
+
+	aMessage.WriteL(1, rServer.PasswordL(*calendar));
+	CleanupStack::PopAndDestroy(calendar);
+	aMessage.Complete(KErrNone);
+	}
+
+void CCalDavServerSession::SetPasswordL(const RMessage2& aMessage)
+	{
+	TUint length = aMessage.GetDesLength(0);
+	HBufC* calendar = HBufC::NewLC(length);
+	TPtr calendarPtr(calendar->Des());
+	aMessage.ReadL(0, calendarPtr);
+
+	length = aMessage.GetDesLength(1);
+	HBufC8* password = HBufC8::NewLC(length);
+	TPtr8 passwordPtr(password->Des());
+	aMessage.ReadL(1, passwordPtr);
+
+	rServer.SetPasswordL(*calendar, *password);
+	CleanupStack::PopAndDestroy(password);
+	CleanupStack::PopAndDestroy(calendar);
+
+	aMessage.Complete(KErrNone);
+	}
+
+void CCalDavServerSession::SyncIntervalL(const RMessage2& aMessage)
+	{
+	TUint length = aMessage.GetDesLength(0);
+	HBufC* calendar = HBufC::NewLC(length);
+	TPtr calendarPtr(calendar->Des());
+	aMessage.ReadL(0, calendarPtr);
+
+	TTimeIntervalMinutes interval = rServer.SyncIntervalL(*calendar);
+	TPckg<TTimeIntervalMinutes> intervalDes(interval);
+	aMessage.WriteL(1, intervalDes);
+
+	CleanupStack::PopAndDestroy(calendar);
+	aMessage.Complete(KErrNone);
+	}
+
+void CCalDavServerSession::SetSyncIntervalL(const RMessage2& aMessage)
+	{
+	TUint length = aMessage.GetDesLength(0);
+	HBufC* calendar = HBufC::NewLC(length);
+	TPtr calendarPtr(calendar->Des());
+	aMessage.ReadL(0, calendarPtr);
+
+	TTimeIntervalMinutes interval;
+	;
+	TPckg<TTimeIntervalMinutes> intervalDes(interval);
+	aMessage.ReadL(1, intervalDes);
+
+	rServer.SetSyncIntervalL(*calendar, interval);
+	CleanupStack::PopAndDestroy(calendar);
+	aMessage.Complete(KErrNone);
+	}
+
+void CCalDavServerSession::PastDaysL(const RMessage2& aMessage)
+	{
+	TUint length = aMessage.GetDesLength(0);
+	HBufC* calendar = HBufC::NewLC(length);
+	TPtr calendarPtr(calendar->Des());
+	aMessage.ReadL(0, calendarPtr);
+
+	TTimeIntervalDays days = rServer.PastDaysL(*calendar);
+	TPckg<TTimeIntervalDays> daysDes(days);
+	aMessage.WriteL(1, daysDes);
+
+	CleanupStack::PopAndDestroy(calendar);
+	aMessage.Complete(KErrNone);
+	}
+
+void CCalDavServerSession::SetPastDaysL(const RMessage2& aMessage)
+	{
+	TUint length = aMessage.GetDesLength(0);
+	HBufC* calendar = HBufC::NewLC(length);
+	TPtr calendarPtr(calendar->Des());
+	aMessage.ReadL(0, calendarPtr);
+
+	TTimeIntervalDays days;
+	TPckg<TTimeIntervalDays> daysDes(days);
+	aMessage.ReadL(1, daysDes);
+
+	rServer.SetPastDaysL(*calendar, days);
+	CleanupStack::PopAndDestroy(calendar);
+	aMessage.Complete(KErrNone);
+	}
+
+void CCalDavServerSession::ImmediateSyncL(const RMessage2& aMessage)
+	{
+	TUint length = aMessage.GetDesLength(0);
+	HBufC* calendar = HBufC::NewLC(length);
+	TPtr calendarPtr(calendar->Des());
+	aMessage.ReadL(0, calendarPtr);
+
+	TBool immediate = rServer.ImmediateSyncL(*calendar);
+	TPckg<TBool> immediateDes(immediate);
+	aMessage.WriteL(1, immediateDes);
+
+	CleanupStack::PopAndDestroy(calendar);
+	aMessage.Complete(KErrNone);
+	}
+
+void CCalDavServerSession::SetImmediateSyncL(const RMessage2& aMessage)
+	{
+	TUint length = aMessage.GetDesLength(0);
+	HBufC* calendar = HBufC::NewLC(length);
+	TPtr calendarPtr(calendar->Des());
+	aMessage.ReadL(0, calendarPtr);
+
+	TBool immediate;
+	TPckg<TBool> immediateDes(immediate);
+	aMessage.ReadL(1, immediateDes);
+	rServer.SetImmediateSyncL(*calendar, immediate);
+
+	CleanupStack::PopAndDestroy(calendar);
+	aMessage.Complete(KErrNone);
+	}
+
+void CCalDavServerSession::KeepServerEntryL(const RMessage2& aMessage)
+	{
+	TUint length = aMessage.GetDesLength(0);
+	HBufC* calendar = HBufC::NewLC(length);
+	TPtr calendarPtr(calendar->Des());
+	aMessage.ReadL(0, calendarPtr);
+
+	TBool keepserver = rServer.ImmediateSyncL(*calendar);
+	TPckg<TBool> keepserverDes(keepserver);
+	aMessage.WriteL(1, keepserverDes);
+
+	CleanupStack::PopAndDestroy(calendar);
+	aMessage.Complete(KErrNone);
+	}
+
+void CCalDavServerSession::EnabledSyncL(const RMessage2& aMessage)
+	{
+	TUint length = aMessage.GetDesLength(0);
+	HBufC* calendar = HBufC::NewLC(length);
+	TPtr calendarPtr(calendar->Des());
+	aMessage.ReadL(0, calendarPtr);
+
+	TBool enabledsync = rServer.EnabledSyncL(*calendar);
+	TPckg<TBool> enabledsyncDes(enabledsync);
+	aMessage.WriteL(1, enabledsyncDes);
+
+	CleanupStack::PopAndDestroy(calendar);
+	aMessage.Complete(KErrNone);
+	}
+
+void CCalDavServerSession::SetKeepServerEntryL(const RMessage2& aMessage)
+	{
+	TUint length = aMessage.GetDesLength(0);
+	HBufC* calendar = HBufC::NewLC(length);
+	TPtr calendarPtr(calendar->Des());
+	aMessage.ReadL(0, calendarPtr);
+
+	TBool keepserver;
+	TPckg<TBool> keepserverDes(keepserver);
+	aMessage.ReadL(1, keepserverDes);
+	rServer.SetImmediateSyncL(*calendar, keepserver);
+
+	CleanupStack::PopAndDestroy(calendar);
+	aMessage.Complete(KErrNone);
+	}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/src/caldavsession.cpp	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,154 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: 	Client API to connect to Caldav server
+*				Wrapper around RCalDavServer
+*/
+
+#include "caldavsession.h"
+#include "caldavsessionimpl.h"
+
+CCalDavSession::CCalDavSession()
+	{
+	}
+
+EXPORT_C CCalDavSession::~CCalDavSession()
+	{
+	delete iImpl;
+	}
+
+EXPORT_C CCalDavSession* CCalDavSession::NewLC()
+	{
+	CCalDavSession* self = new (ELeave) CCalDavSession();
+	CleanupStack::PushL(self);
+	self->ConstructL();
+	return self;
+	}
+
+EXPORT_C CCalDavSession* CCalDavSession::NewL()
+	{
+	CCalDavSession* self = CCalDavSession::NewLC();
+	CleanupStack::Pop(self);
+	return self;
+	}
+
+void CCalDavSession::ConstructL()
+	{
+	iImpl = CCalDavSessionImpl::NewL();
+	}
+
+EXPORT_C TInt CCalDavSession::Enable(const TDesC &aCalendar)
+	{
+	return iImpl->Enable(aCalendar);
+	}
+
+EXPORT_C TInt CCalDavSession::Disable(const TDesC &aCalendar)
+	{
+	return iImpl->Disable(aCalendar);
+	}
+
+EXPORT_C TInt CCalDavSession::SyncL(const TDesC &aCalendar)
+	{
+	return iImpl->SyncL(aCalendar);
+	}
+
+EXPORT_C TInt CCalDavSession::SyncAllL()
+	{
+	return iImpl->SyncAllL();
+	}
+
+EXPORT_C TInt CCalDavSession::Url(const TDesC &aCalendar, TDes8 &aUrl)
+	{
+	return iImpl->Url(aCalendar, aUrl);
+	}
+
+EXPORT_C TInt CCalDavSession::SetUrl(const TDesC &aCalendar, const TDesC8 &aUrl)
+	{
+	return iImpl->SetUrl(aCalendar, aUrl);
+	}
+
+EXPORT_C TInt CCalDavSession::Username(const TDesC &aCalendar, TDes8 &aUsername)
+	{
+	return iImpl->Username(aCalendar, aUsername);
+	}
+
+EXPORT_C TInt CCalDavSession::SetUsername(const TDesC &aCalendar,
+		const TDesC8 &aUsername)
+	{
+	return iImpl->SetUsername(aCalendar, aUsername);
+	}
+
+EXPORT_C TInt CCalDavSession::Password(const TDesC &aCalendar, TDes8 &aPassword)
+	{
+	return iImpl->Password(aCalendar, aPassword);
+	}
+
+EXPORT_C TInt CCalDavSession::SetPassword(const TDesC &aCalendar,
+		const TDesC8 &aPassword)
+	{
+	return iImpl->SetPassword(aCalendar, aPassword);
+	}
+
+EXPORT_C TInt CCalDavSession::SyncInterval(const TDesC &aCalendar,
+		TTimeIntervalMinutes& aSyncInterval)
+	{
+	return iImpl->SyncInterval(aCalendar, aSyncInterval);
+	}
+
+EXPORT_C TInt CCalDavSession::SetSyncInterval(const TDesC &aCalendar,
+		TTimeIntervalMinutes aSyncInterval)
+	{
+	return iImpl->SetSyncInterval(aCalendar, aSyncInterval);
+	}
+
+EXPORT_C TInt CCalDavSession::PastDays(const TDesC &aCalendar,
+		TTimeIntervalDays &aDays)
+	{
+	return iImpl->PastDays(aCalendar, aDays);
+	}
+
+EXPORT_C TInt CCalDavSession::SetPastDays(const TDesC &aCalendar,
+		TTimeIntervalDays aDays)
+	{
+	return iImpl->SetPastDays(aCalendar, aDays);
+	}
+
+EXPORT_C TInt CCalDavSession::ImmediateSync(const TDesC &aCalendar,
+		TBool &aImmediateSyc)
+	{
+	return iImpl->ImmediateSync(aCalendar, aImmediateSyc);
+	}
+
+EXPORT_C TInt CCalDavSession::SetImmediateSync(const TDesC &aCalendar,
+		TBool aImmediateSyc)
+	{
+	return iImpl->SetImmediateSync(aCalendar, aImmediateSyc);
+	}
+
+EXPORT_C TInt CCalDavSession::KeepServerEntry(const TDesC &aCalendar,
+		TBool &aKeepServerEntry)
+	{
+	return iImpl->KeepServerEntry(aCalendar, aKeepServerEntry);
+	}
+
+EXPORT_C TInt CCalDavSession::SetKeepServerEntry(const TDesC &aCalendar,
+		TBool aKeepServerEntry)
+	{
+	return iImpl->SetKeepServerEntry(aCalendar, aKeepServerEntry);
+	}
+
+EXPORT_C TInt CCalDavSession::EnabledSync(const TDesC &aCalendar,
+		TBool &aEnabledSync)
+	{
+	return iImpl->EnabledSync(aCalendar, aEnabledSync);
+	}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/src/caldavsessionimpl.cpp	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,160 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: 	Client API implementation
+*				Wrapper around RCalDavServer
+*/
+
+#include "caldavsessionimpl.h"
+#include "caldavclient.h"
+
+CCalDavSessionImpl::CCalDavSessionImpl()
+	{
+	// No implementation required
+	}
+
+CCalDavSessionImpl::~CCalDavSessionImpl()
+	{
+	if (iServer)
+		{
+		iServer->Close();
+		delete iServer;
+		}
+	}
+
+CCalDavSessionImpl* CCalDavSessionImpl::NewLC()
+	{
+	CCalDavSessionImpl* self = new (ELeave) CCalDavSessionImpl();
+	CleanupStack::PushL(self);
+	self->ConstructL();
+	return self;
+	}
+
+CCalDavSessionImpl* CCalDavSessionImpl::NewL()
+	{
+	CCalDavSessionImpl* self = CCalDavSessionImpl::NewLC();
+	CleanupStack::Pop(self);
+	return self;
+	}
+
+void CCalDavSessionImpl::ConstructL()
+	{
+	iServer = new (ELeave) RCalDavServer();
+	User::LeaveIfError(iServer->Connect());
+	}
+
+TInt CCalDavSessionImpl::Enable(const TDesC &aCalendar)
+	{
+	return iServer->Enable(aCalendar);
+	}
+
+TInt CCalDavSessionImpl::Disable(const TDesC &aCalendar)
+	{
+	return iServer->Disable(aCalendar);
+	}
+
+TInt CCalDavSessionImpl::SyncL(const TDesC &aCalendar)
+	{
+	return iServer->Sync(aCalendar);
+	}
+
+TInt CCalDavSessionImpl::SyncAllL()
+	{
+	return iServer->SyncAll();
+	}
+
+TInt CCalDavSessionImpl::Url(const TDesC &aCalendar, TDes8 &aUrl)
+	{
+	return iServer->Url(aCalendar, aUrl);
+	}
+
+TInt CCalDavSessionImpl::SetUrl(const TDesC &aCalendar, const TDesC8 &aUrl)
+	{
+	return iServer->SetUrl(aCalendar, aUrl);
+	}
+
+TInt CCalDavSessionImpl::Username(const TDesC &aCalendar, TDes8 &aUsername)
+	{
+	return iServer->Username(aCalendar, aUsername);
+	}
+
+TInt CCalDavSessionImpl::SetUsername(const TDesC &aCalendar,
+		const TDesC8 &aUsername)
+	{
+	return iServer->SetUsername(aCalendar, aUsername);
+	}
+
+TInt CCalDavSessionImpl::Password(const TDesC &aCalendar, TDes8 &aPassword)
+	{
+	return iServer->Password(aCalendar, aPassword);
+	}
+
+TInt CCalDavSessionImpl::SetPassword(const TDesC &aCalendar,
+		const TDesC8 &aPassword)
+	{
+	return iServer->SetPassword(aCalendar, aPassword);
+	}
+
+TInt CCalDavSessionImpl::SyncInterval(const TDesC &aCalendar,
+		TTimeIntervalMinutes& aSyncInterval)
+	{
+	return iServer->SyncInterval(aCalendar, aSyncInterval);
+	}
+
+TInt CCalDavSessionImpl::SetSyncInterval(const TDesC &aCalendar,
+		TTimeIntervalMinutes aSyncInterval)
+	{
+	return iServer->SetSyncInterval(aCalendar, aSyncInterval);
+	}
+
+TInt CCalDavSessionImpl::PastDays(const TDesC &aCalendar,
+		TTimeIntervalDays &aDays)
+	{
+	return iServer->PastDays(aCalendar, aDays);
+	}
+
+TInt CCalDavSessionImpl::SetPastDays(const TDesC &aCalendar,
+		TTimeIntervalDays aDays)
+	{
+	return iServer->SetPastDays(aCalendar, aDays);
+	}
+
+TInt CCalDavSessionImpl::ImmediateSync(const TDesC &aCalendar,
+		TBool &aImmediateSyc)
+	{
+	return iServer->ImmediateSync(aCalendar, aImmediateSyc);
+	}
+
+TInt CCalDavSessionImpl::SetImmediateSync(const TDesC &aCalendar,
+		TBool aImmediateSyc)
+	{
+	return iServer->SetImmediateSync(aCalendar, aImmediateSyc);
+	}
+
+TInt CCalDavSessionImpl::KeepServerEntry(const TDesC &aCalendar,
+		TBool &aKeepServerEntry)
+	{
+	return iServer->KeepServerEntry(aCalendar, aKeepServerEntry);
+	}
+
+TInt CCalDavSessionImpl::SetKeepServerEntry(const TDesC &aCalendar,
+		TBool aKeepServerEntry)
+	{
+	return iServer->SetKeepServerEntry(aCalendar, aKeepServerEntry);
+	}
+
+TInt CCalDavSessionImpl::EnabledSync(const TDesC &aCalendar,
+		TBool &aEnabledSync)
+	{
+	return iServer->EnabledSync(aCalendar, aEnabledSync);
+	}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/src/caldavutils.cpp	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,375 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: 	various utility classes and functions
+*				used in Caldav client and server code
+*/
+
+#include "caldavutils.h"
+
+#include <http\MHTTPAuthenticationCallback.h>
+#include <http\mhttptransactioncallback.h>
+#include <http\mhttpdatasupplier.h>
+#include <http\rhttpheaders.h> 
+
+/**
+ * CalDavUtils::CalDavUtils
+ * default constructor
+ */
+CalDavUtils::CalDavUtils()
+	{
+	// No implementation required
+	}
+
+/**
+ * CalDavUtils::~CalDavUtils
+ * default destructor
+ */
+CalDavUtils::~CalDavUtils()
+	{
+	}
+
+/**
+ * CalDavUtils::NewLC
+ * first phase construction
+ */
+CalDavUtils* CalDavUtils::NewLC()
+	{
+	CalDavUtils* self = new (ELeave) CalDavUtils();
+	CleanupStack::PushL(self);
+	self->ConstructL();
+	return self;
+	}
+
+/**
+ * CalDavUtils::NewL
+ * first phase construction
+ */
+CalDavUtils* CalDavUtils::NewL()
+	{
+	CalDavUtils* self = CalDavUtils::NewLC();
+	CleanupStack::Pop(self); // self;
+	return self;
+	}
+
+/**
+ * CalDavUtils::ConstructL
+ * second phase construction
+ */
+void CalDavUtils::ConstructL()
+	{
+	}
+
+/**
+ * CalDavUtils::FixImportIssues
+ * fix import issues
+ */
+void CalDavUtils::FixImportIssues(TDes8 &aDes)
+	{
+	const TUint KICalCarriageReturnChar('\r');
+	_LIT8(KICalNewlineChar,"\n");
+	_LIT8(KICalCarriageReturnLineFeed,"\r\n");
+
+	TInt ret = aDes.Find(KICalNewlineChar);
+
+	while ((ret != KErrNotFound) && (ret == 0 ? ETrue : (aDes[ret - 1]
+			!= KICalCarriageReturnChar)))
+		{
+		aDes.Replace(ret, 1, KICalCarriageReturnLineFeed);
+		TInt mid = aDes.Mid(ret + 2).Find(KICalNewlineChar);
+		ret = mid != KErrNone ? mid + ret + 2 : KErrNotFound;
+		}
+	}
+
+/**
+ * CalDavUtils::FixExportIssues
+ * fix export issues, hopefully can be removed in the future
+ */
+void CalDavUtils::FixExportIssues(TDes8 &aDes)
+	{
+	FixSameTime(aDes);
+	FindAndRemoveMethod(aDes);
+	FixBYMONTHDAY(aDes);
+	FixLineFeed(aDes);
+	//TODO: using public, nothing is exported
+	}
+
+/**
+ * CalDavUtils::FixLineFeed
+ * fix lidne feed
+ */
+void CalDavUtils::FixLineFeed(TDes8 &aDes)
+	{
+	_LIT8(lf1,"
");
+	_LIT8(KBackSlashN,"\\n");
+	TInt ret = aDes.Find(lf1);
+	while (ret != KErrNotFound)
+		{
+		aDes.Replace(ret, lf1().Length(), KBackSlashN);
+		ret = aDes.Find(lf1);
+		}
+	}
+
+/**
+ * CalDavUtils::FixSameTime
+ * fix same time
+ */
+void CalDavUtils::FixSameTime(TDes8 &aDes)
+	{
+#define DATELENGTH	15
+	_LIT8(DTSTART,"DTSTART:");
+	_LIT8(DTEND,"DTEND:");
+	_LIT8(DUE,"DUE:");
+	_LIT8(nine,"9");
+	_LIT8(five,"5");
+	_LIT8(VEVENT,"VEVENT");
+	_LIT8(VTODO,"VTODO");
+
+	// add one second if DTSTART and DTEND is the same
+	// ATTENTION: works only for very simple cases right now
+	// DTSTART:20090630T000000
+	// DTEND:20090630T000000
+	if (aDes.Find(VEVENT) != KErrNone)
+		{
+		TInt PosStart = aDes.Find(DTSTART);
+		TInt PosDue = aDes.Find(DTEND);
+
+		if ((PosStart != KErrNone) && (PosDue != KErrNone))
+			{
+			TPtrC8 PtrStart = aDes.Mid(PosStart + DTSTART().Length(),
+					DATELENGTH);
+			TPtrC8 PtrStop = aDes.Mid(PosDue + DTEND().Length(), DATELENGTH);
+
+			if (PtrStart == PtrStop)
+				{
+				aDes.Replace(PosDue + DTEND().Length() + DATELENGTH - 1, 1,
+						nine);
+				aDes.Replace(PosDue + DTEND().Length() + DATELENGTH - 2, 1,
+						five);
+				aDes.Replace(PosDue + DTEND().Length() + DATELENGTH - 3, 1,
+						nine);
+				}
+			}
+		}
+
+	// add one second if DTSTART and DUE is the same
+	// ATTENTION: works only for very simple cases right now
+	// DTSTART:20090630T000000
+	// DUE:20090630T000000
+
+	if (aDes.Find(VTODO) != KErrNone)
+		{
+		TInt PosStart = aDes.Find(DTSTART);
+		TInt PosDue = aDes.Find(DUE);
+
+		if ((PosStart != KErrNone) && (PosDue != KErrNone))
+			{
+			TPtrC8 PtrStart = aDes.Mid(PosStart + DTSTART().Length(),
+					DATELENGTH);
+			TPtrC8 PtrStop = aDes.Mid(PosDue + DUE().Length(), DATELENGTH);
+
+			if (PtrStart == PtrStop)
+				{
+				aDes.Replace(PosDue + DUE().Length() + DATELENGTH - 1, 1, nine);
+				aDes.Replace(PosDue + DUE().Length() + DATELENGTH - 2, 1, five);
+				aDes.Replace(PosDue + DUE().Length() + DATELENGTH - 3, 1, nine);
+				}
+			}
+		}
+	}
+
+/**
+ * CalDavUtils::FindAndRemoveMethod
+ * fix wrong method export
+ */
+void CalDavUtils::FindAndRemoveMethod(TDes8 &aDes)
+	{
+	_LIT8(method,"METHOD:PUBLISH\r\n");
+	TInt Ret = aDes.Find(method);
+	while (Ret != KErrNotFound)
+		{
+		aDes.Delete(Ret, method().Length());
+		Ret = aDes.Find(method);
+		}
+	}
+
+/**
+ * CalDavUtils::FixBYMONTHDAY
+ * fix wrong BYMONTHDAY export
+ */
+void CalDavUtils::FixBYMONTHDAY(TDes8 &aDes)
+	{
+	_LIT8(method0,"BYMONTHDAY=0");
+	_LIT8(method1,"BYMONTHDAY=1");
+	TInt ret = aDes.Find(method0);
+	while (ret != KErrNotFound)
+		{
+		aDes.Replace(ret, method1().Length(), method1);
+		ret = aDes.Find(method0);
+		}
+	}
+
+/**
+ * CalDavUtils::ScanAllowHeaderL
+ * fix scan allow header
+ */
+void CalDavUtils::ScanAllowHeaderL(RHTTPTransaction &aTransaction,
+		TCalDAVOptions &aOptions)
+	{
+	RStringF Header = aTransaction.Session().StringPool().OpenFStringL(ALLOW);
+	THTTPHdrVal HeaderVal;
+	if (aTransaction.Response().GetHeaderCollection().GetField(Header, 0,
+			HeaderVal) == KErrNone)
+		{
+		RStringF FieldValStr = aTransaction.Session().StringPool().StringF(
+				HeaderVal.StrF());
+		const TDesC8 &FieldValDesC = FieldValStr.DesC();
+		HBufC8 *FieldVal = FieldValDesC.AllocLC();
+		// delete all colons
+		TInt Pos = FieldVal->Find(colon);
+		while (Pos != KErrNotFound)
+			{
+			FieldVal->Des().Delete(Pos, 1);
+			Pos = FieldVal->Find(colon);
+			}
+		TLex8 Lex(FieldVal->Des());
+		TBool stop = EFalse;
+		while (!stop)
+			{
+			TPtrC8 Ptr = Lex.NextToken();
+			stop = Ptr.Length() == 0;
+			if (Ptr == DELETE)
+				aOptions.DELETE = ETrue;
+			else if (Ptr == GET)
+				aOptions.GET = ETrue;
+			else if (Ptr == HEAD)
+				aOptions.HEAD = ETrue;
+			else if (Ptr == MKCALENDAR)
+				aOptions.MKCALENDAR = ETrue;
+			else if (Ptr == MKCOL)
+				aOptions.MKCOL = ETrue;
+			else if (Ptr == OPTIONS)
+				aOptions.OPTIONS = ETrue;
+			else if (Ptr == PROPFIND)
+				aOptions.PROPFIND = ETrue;
+			else if (Ptr == PROPPATCH)
+				aOptions.PROPPATCH = ETrue;
+			else if (Ptr == PUT)
+				aOptions.PUT = ETrue;
+			else if (Ptr == REPORT)
+				aOptions.REPORT = ETrue;
+			else if (Ptr == COPY)
+				aOptions.COPY = ETrue;
+			else if (Ptr == POST)
+				aOptions.POST = ETrue;
+			else if (Ptr == MOVE)
+				aOptions.MOVE = ETrue;
+			else if (Ptr == ACL)
+				aOptions.ACL = ETrue;
+			else if (Ptr == LOCK)
+				aOptions.LOCK = ETrue;
+			else if (Ptr == UNLOCK)
+				aOptions.UNLOCK = ETrue;
+			}
+		CleanupStack::PopAndDestroy(FieldVal);
+		}
+	Header.Close();
+	}
+
+/**
+ * CalDavUtils::ScanDAVHeaderL
+ * scan DAV header
+ */
+void CalDavUtils::ScanDAVHeaderL(RHTTPTransaction &aTransaction,
+		TCalDAVOptions &aOptions)
+	{
+	RStringF Header = aTransaction.Session().StringPool().OpenFStringL(DAV);
+	THTTPHdrVal aHeaderVal;
+	if (aTransaction.Response().GetHeaderCollection().GetField(Header, 0,
+			aHeaderVal) == KErrNone)
+		{
+		RStringF FieldValStr = aTransaction.Session().StringPool().StringF(
+				aHeaderVal.StrF());
+		const TDesC8 &FieldValDesC = FieldValStr.DesC();
+		HBufC8 *FieldVal = FieldValDesC.AllocLC();
+		// delete all colons
+		TInt Pos = FieldVal->Find(colon);
+		while (Pos != KErrNotFound)
+			{
+			FieldVal->Des().Delete(Pos, 1);
+			Pos = FieldVal->Find(colon);
+			}
+		TLex8 Lex(FieldVal->Des());
+		TBool stop = EFalse;
+		while (!stop)
+			{
+			TPtrC8 Ptr = Lex.NextToken();
+			stop = Ptr.Length() == 0;
+			if (Ptr == ONE)
+				aOptions.ONE = ETrue;
+			else if (Ptr == TWO)
+				aOptions.TWO = ETrue;
+			else if (Ptr == THREE)
+				aOptions.THREE = ETrue;
+			else if (Ptr == access_control)
+				aOptions.access_control = ETrue;
+			else if (Ptr == calendar_access)
+				{
+				aOptions.calendar_access = ETrue;
+				// this is a CalDAV server for sure, MULTIGET and calendar-query is required
+				// we do not check for this anymore in CCaldavEngine::GetOptions()
+				aOptions.MULTIGET = ETrue;
+				aOptions.QUERY = ETrue;
+				}
+			else if (Ptr == calendar_schedule)
+				aOptions.calendar_schedule = ETrue;
+			else if (Ptr == calendar_auto_schedule)
+				aOptions.calendar_auto_schedule = ETrue;
+			else if (Ptr == sync_collection)
+				aOptions.sync_collection = ETrue;
+			else if (Ptr == extended_mkcol)
+				aOptions.extended_mkcol = ETrue;
+			}
+		CleanupStack::PopAndDestroy(FieldVal);
+		}
+	Header.Close();
+	}
+
+/**
+ * CalDavUtils::EnsureSlashL
+ * ensure trailing slash
+ */
+HBufC8* CalDavUtils::EnsureSlashL(HBufC8* aIn)
+	{
+	if ((aIn == NULL) || (aIn->Right(KSlash().Length()) == KSlash))
+		return aIn;
+	else
+		{
+		HBufC8 *out = HBufC8::NewL(aIn->Length() + KSlash().Length());
+		out->Des().Append(*aIn);
+		out->Des().Append(KSlash);
+		delete aIn;
+		aIn = NULL;
+		return out;
+		}
+	}
+
+/**
+ * CalDavUtils::EnsureSlashL
+ * ensure trailing slash
+ */
+HBufC8* CalDavUtils::EnsureSlashL(const TDesC8 &aIn)
+	{
+	HBufC8 *out = aIn.AllocL();
+	return CalDavUtils::EnsureSlashL(out);
+	}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/src/httpclient.cpp	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,687 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: 	basic http/webdav functionality
+*				handles all needed internet access for Caldav
+*/
+
+#include "httpclient.h"
+#include "caldavutils.h"
+#include <uri8.h>
+#include <http.h>
+#include <EIKENV.H>
+
+_LIT8(KTextXml,"text/xml");
+_LIT8(KTextCalendar,"text/calendar");
+_LIT8(KDepth,"depth");
+
+/**
+ * CHttpClient::CHttpClient
+ * default constructor
+ */
+CHttpClient::CHttpClient() :
+	iUser(0), iPassword(0), iEtag(0), iCredentialCount(0)
+	{
+	}
+
+/**
+ * CHttpClient::~CHttpClient
+ * default destructor
+ */
+CHttpClient::~CHttpClient()
+	{
+	delete iUser;
+	delete iPassword;
+	delete iEtag;
+
+	iSess.Close();
+	iRConnection.Close();
+	iSocketServ.Close();
+
+	}
+
+/**
+ * CHttpClient::NewLC
+ * first phase constructor
+ */
+CHttpClient* CHttpClient::NewLC()
+	{
+	CHttpClient* me = new (ELeave) CHttpClient;
+	CleanupStack::PushL(me);
+	me->ConstructL();
+	return me;
+	}
+
+/**
+ * CHttpClient::NewL
+ * first phase construction
+ */
+CHttpClient* CHttpClient::NewL()
+	{
+	CHttpClient* me = NewLC();
+	CleanupStack::Pop(me);
+	return me;
+	}
+
+/**
+ * CHttpClient::OpenSessionL
+ * open session and instal authentification
+ */
+void CHttpClient::OpenSessionL()
+	{
+	TRAPD(err, iSess.OpenL());
+
+	if (err != KErrNone)
+		{
+		_LIT(KErrMsg, "Cannot create session. Is internet access point configured?");
+		_LIT(KExitingApp, "Exiting app.");
+		CEikonEnv::Static()->InfoWinL(KErrMsg, KExitingApp);
+		User::Leave(err);
+		}
+
+	// Install this class as the callback for authentication requests
+	InstallAuthenticationL(iSess);
+
+	// Set the session's connection info...
+	RHTTPConnectionInfo connInfo = iSess.ConnectionInfo();
+	// ...to use the socket server
+	connInfo.SetPropertyL(iSess.StringPool().StringF(HTTP::EHttpSocketServ,
+			RHTTPSession::GetTable()), THTTPHdrVal(iSocketServ.Handle()));
+	// ...to use the connection
+	connInfo.SetPropertyL(
+			iSess.StringPool().StringF(HTTP::EHttpSocketConnection,
+					RHTTPSession::GetTable()),
+			THTTPHdrVal(REINTERPRET_CAST(TInt, &(iRConnection))));
+
+	}
+
+/**
+ * CHttpClient::ConstructL
+ * second phase construction
+ */
+void CHttpClient::ConstructL()
+	{
+	User::LeaveIfError(iSocketServ.Connect());
+	User::LeaveIfError(iRConnection.Open(iSocketServ));
+	
+	iExtPrefs.SetSnapPurpose( CMManager::ESnapPurposeInternet );
+	iExtPrefs.SetNoteBehaviour( TExtendedConnPref::ENoteBehaviourConnDisableNotes);
+	iPrefList.AppendL(&iExtPrefs);
+	iRConnection.Start(iPrefList);
+
+	OpenSessionL();
+	}
+
+/**
+ * CHttpClient::DeleteL
+ * HTTP DELETE
+ */
+TInt CHttpClient::DeleteL(const TDesC8 &aUrl, const TDesC8 &aETag)
+	{
+	iReturnCode = ERROR;
+
+	TUriParser8 uri;
+	uri.Parse(aUrl);
+
+	iTrans = iSess.OpenTransactionL(uri, *this, iSess.StringPool().StringF(
+			HTTP::EDELETE, RHTTPSession::GetTable()));
+	if (aETag != KNullDesC8)
+		SetHeaderL(iTrans.Request().GetHeaderCollection(), HTTP::EIfMatch,
+				aETag);
+	SetHeaderL(iTrans.Request().GetHeaderCollection(), HTTP::EUserAgent,
+			KUserAgent);
+	iTrans.SubmitL();
+
+	CActiveScheduler::Start();
+	return iReturnCode;
+	}
+
+/**
+ * CHttpClient::HeadL
+ * HTTP HEAD
+ */
+TInt CHttpClient::HeadL(const TDesC8 &aUrl)
+	{
+	iReturnCode = ERROR;
+
+	TUriParser8 uri;
+	uri.Parse(aUrl);
+
+	iTrans = iSess.OpenTransactionL(uri, *this, iSess.StringPool().StringF(
+			HTTP::EHEAD, RHTTPSession::GetTable()));
+	SetHeaderL(iTrans.Request().GetHeaderCollection(), HTTP::EUserAgent,
+			KUserAgent);
+	iTrans.SubmitL();
+	CActiveScheduler::Start();
+	return iReturnCode;
+	}
+
+/**
+ * CHttpClient::GetL
+ * HTTP Get
+ */
+TInt CHttpClient::GetL(const TDesC8 &aUrl, CBufFlat *aResponse)
+	{
+	iReturnCode = ERROR;
+
+	iBodyResponse = aResponse;
+
+	TUriParser8 uri;
+	uri.Parse(aUrl);
+
+	iTrans = iSess.OpenTransactionL(uri, *this, iSess.StringPool().StringF(
+			HTTP::EGET, RHTTPSession::GetTable()));
+	SetHeaderL(iTrans.Request().GetHeaderCollection(), HTTP::EUserAgent,
+			KUserAgent);
+	iTrans.SubmitL();
+	CActiveScheduler::Start();
+	iBodyResponse = NULL;
+	return iReturnCode;
+	}
+
+/**
+ * CHttpClient::MkCalendarL
+ * Caldav MKCALENDAR
+ */
+TInt CHttpClient::MkCalendarL(const TDesC8 &aUrl, const TDesC8 &aBody,
+		CBufFlat *aResponse)
+	{
+	iReturnCode = ERROR;
+
+	if (aBody != KNullDesC8)
+		{
+		iBodyRequest = aBody.Alloc();
+		iTrans.Request().SetBody(*this);
+		}
+
+	iBodyResponse = aResponse;
+
+	TUriParser8 uri;
+	uri.Parse(aUrl);
+
+	RStringF mkcalendar = iSess.StringPool().OpenFStringL(MKCALENDAR);
+	iTrans = iSess.OpenTransactionL(uri, *this, mkcalendar);
+	RHTTPHeaders hdr = iTrans.Request().GetHeaderCollection();
+
+	SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
+	SetHeaderL(hdr, HTTP::EContentType, KTextXml);
+
+	iTrans.SubmitL();
+	CActiveScheduler::Start();
+
+	mkcalendar.Close();
+	if (iBodyRequest)
+		{
+		delete iBodyRequest;
+		iBodyRequest = NULL;
+		}
+	iBodyResponse = NULL;
+
+	return iReturnCode;
+	}
+
+/**
+ * CHttpClient::PutL
+ * HTTP PUT
+ */
+TInt CHttpClient::PutL(const TDesC8 &aUrl, const TDesC8 &aIcs,
+		CBufFlat *aResponse, const TDesC8 &aEtag)
+	{
+	iReturnCode = ERROR;
+
+	iBodyRequest = aIcs.Alloc();
+	iBodyResponse = aResponse;
+
+	TUriParser8 uri;
+	uri.Parse(aUrl);
+
+	iTrans = iSess.OpenTransactionL(uri, *this, iSess.StringPool().StringF(
+			HTTP::EPUT, RHTTPSession::GetTable()));
+	RHTTPHeaders hdr = iTrans.Request().GetHeaderCollection();
+
+	iTrans.Request().SetBody(*this);
+
+	if (aEtag == KNullDesC8)
+		{
+		_LIT8(KStar, "*");
+		SetHeaderL(hdr, HTTP::EIfNoneMatch, KStar);
+		}
+	else
+		{
+#ifdef ETAG
+		 SetHeaderL(hdr,HTTP::EIfMatch,aEtag);
+#endif
+		}
+
+	SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
+	SetHeaderL(hdr, HTTP::EContentType, KTextCalendar);
+
+	iTrans.SubmitL();
+	CActiveScheduler::Start();
+
+	delete iBodyRequest;
+	iBodyRequest = NULL;
+	iBodyResponse = NULL;
+
+	return iReturnCode;
+	}
+
+/**
+ * CHttpClient::ReportL
+ * Caldav REPORT 
+ */
+TInt CHttpClient::ReportL(const TDesC8 &aUrl, const TDesC8 &aBodyRequest,
+		CBufFlat *aResponse)
+	{
+	iReturnCode = ERROR;
+	iBodyResponse = aResponse;
+
+	TUriParser8 uri;
+	uri.Parse(aUrl);
+
+	RStringF report = iSess.StringPool().OpenFStringL(REPORT);
+	iTrans = iSess.OpenTransactionL(uri, *this, report);
+	if (aBodyRequest.Length())
+		{
+		iBodyRequest = aBodyRequest.Alloc();
+		iTrans.Request().SetBody(*this);
+		}
+
+	RHTTPHeaders hdr = iTrans.Request().GetHeaderCollection();
+	SetHeaderL(hdr, HTTP::EContentType, KTextXml);
+	SetHeaderL(hdr, KDepth, ONE);
+	SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
+	iTrans.SubmitL();
+	CActiveScheduler::Start();
+
+	report.Close();
+
+	delete iBodyRequest;
+	iBodyRequest = NULL;
+	iBodyResponse = NULL;
+
+	return iReturnCode;
+	}
+
+/**
+ * CHttpClient::PropfindL
+ * WebDAV PROPFIND
+ */
+TInt CHttpClient::PropfindL(const TDesC8 &aUrl, const TDesC8 &aBodyRequest,
+		CBufFlat *aResponse, TBool depth)
+	{
+	iReturnCode = ERROR;
+	iBodyResponse = aResponse;
+
+	TUriParser8 uri;
+	uri.Parse(aUrl);
+
+	RStringF propfind = iSess.StringPool().OpenFStringL(PROPFIND);
+	iTrans = iSess.OpenTransactionL(uri, *this, propfind);
+	if (aBodyRequest.Length())
+		{
+		iBodyRequest = aBodyRequest.Alloc();
+		iTrans.Request().SetBody(*this);
+		}
+
+	RHTTPHeaders hdr = iTrans.Request().GetHeaderCollection();
+	SetHeaderL(hdr, HTTP::EContentType, KTextXml);
+	SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
+	if (depth)
+		SetHeaderL(hdr, KDepth, ZERO);
+	else
+		SetHeaderL(hdr, KDepth, ONE);
+
+	iTrans.SubmitL();
+	CActiveScheduler::Start();
+
+	propfind.Close();
+
+	delete iBodyRequest;
+	iBodyRequest = NULL;
+	iBodyResponse = NULL;
+
+	return iReturnCode;
+	}
+
+/**
+ * CHttpClient::ProppatchL
+ * Webdav PROPPATCH
+ */
+TInt CHttpClient::ProppatchL(const TDesC8 &aUrl, const TDesC8 &aBodyRequest, CBufFlat *aResponse)
+	{
+	iReturnCode = ERROR;
+	iBodyResponse = aResponse;
+
+	TUriParser8 uri;
+	uri.Parse(aUrl);
+
+	RStringF proppatch = iSess.StringPool().OpenFStringL(PROPPATCH);
+	iTrans = iSess.OpenTransactionL(uri, *this, proppatch);
+	RHTTPHeaders hdr = iTrans.Request().GetHeaderCollection();
+	SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
+	SetHeaderL(hdr, HTTP::EContentType, KTextXml);
+	
+	iBodyRequest = aBodyRequest.Alloc();
+	iTrans.Request().SetBody(*this);
+	
+	iTrans.SubmitL();
+	CActiveScheduler::Start();
+
+	proppatch.Close();
+
+	delete iBodyRequest;
+	iBodyRequest = NULL;
+	iBodyResponse = NULL;
+
+	return iReturnCode;
+	}
+
+/**
+ * CHttpClient::GetServerOptionsL
+ * HTTP OPTIONS
+ */
+TInt CHttpClient::GetServerOptionsL(const TDesC8 &aUrl,
+		TCalDAVOptions &aOptions)
+	{
+	iReturnCode = ERROR;
+	iAction = EActionOption;
+	iOptions = &aOptions;
+
+	TUriParser8 uri;
+	uri.Parse(aUrl);
+
+	RStringF options = iSess.StringPool().OpenFStringL(OPTIONS);
+	iTrans = iSess.OpenTransactionL(uri, *this, options);
+	SetHeaderL(iTrans.Request().GetHeaderCollection(), HTTP::EUserAgent,
+			KUserAgent);
+	iTrans.SubmitL();
+
+	CActiveScheduler::Start();
+
+	options.Close();
+
+	iAction = EActionNone;
+	return iReturnCode;
+	}
+
+/**
+ * CHttpClient::GetNextDataPart
+ * GetNextDataPart callback
+ */
+TBool CHttpClient::GetNextDataPart(TPtrC8& aDataPart)
+	{
+	aDataPart.Set(iBodyRequest->Des());
+	return ETrue;
+	}
+
+/**
+ * CHttpClient::ReleaseData
+ * ReleaseData callback
+ */
+void CHttpClient::ReleaseData()
+	{
+	}
+
+/**
+ * CHttpClient::OverallDataSize
+ * OverallDataSize callback
+ */
+TInt CHttpClient::OverallDataSize()
+	{
+	if (iBodyRequest)
+		return iBodyRequest->Length();
+	else
+		return 0;
+	}
+
+/**
+ * CHttpClient::Reset
+ * Reset callback
+ */
+TInt CHttpClient::Reset()
+	{
+	return KErrNone;
+	}
+
+/**
+ * CHttpClient::SetHeaderL
+ * sets int header at session headers 
+ */
+void CHttpClient::SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField,
+		const TDesC8& aHdrValue)
+	{
+	RStringF valStr = iSess.StringPool().OpenFStringL(aHdrValue);
+	CleanupClosePushL(valStr);
+	THTTPHdrVal val(valStr);
+	aHeaders.SetFieldL(iSess.StringPool().StringF(aHdrField,
+			RHTTPSession::GetTable()), val);
+	CleanupStack::PopAndDestroy(&valStr);
+	}
+
+/**
+ * CHttpClient::SetHeaderL
+ * set string header at session headers
+ */
+void CHttpClient::SetHeaderL(RHTTPHeaders aHeaders, const TDesC8 &aField,
+		const TDesC8 &aValue)
+	{
+	RStringF FieldVal = iSess.StringPool().OpenFStringL(aField);
+	CleanupClosePushL(FieldVal);
+	RStringF valStr = iSess.StringPool().OpenFStringL(aValue);
+	CleanupClosePushL(valStr);
+	THTTPHdrVal val(valStr);
+	aHeaders.SetFieldL(FieldVal, val);
+	CleanupStack::PopAndDestroy(&valStr);
+	CleanupStack::PopAndDestroy(&FieldVal);
+	}
+
+/**
+ * CHttpClient::GetCredentialsL
+ * ask for username and password for authentification
+ */
+TBool CHttpClient::GetCredentialsL(const TUriC8& /*aURI*/, RString aRealm,
+		RStringF /*aAuthenticationType*/, RString& aUsername,
+		RString& aPassword)
+	{
+	if (iCredentialCount)
+		{
+		iCredentialCount = 0;
+		User::Leave(KErrAccessDenied);
+		}
+	iCredentialCount++;
+	aUsername = aRealm.Pool().OpenStringL(*iUser);
+	aPassword = aRealm.Pool().OpenStringL(*iPassword);
+	return ETrue;
+	}
+
+/**
+ * CHttpClient::GetEtagHeaderL
+ * check for ETag and save it
+ */
+void CHttpClient::GetEtagHeaderL(RHTTPTransaction &aTransaction)
+	{
+	RStringF Header = aTransaction.Session().StringPool().StringF(HTTP::EETag,
+			RHTTPSession::GetTable());
+	THTTPHdrVal HeaderVal;
+	if (aTransaction.Response().GetHeaderCollection().GetField(Header, 0,
+			HeaderVal) == KErrNone)
+		{
+		RStringF FieldValStr = aTransaction.Session().StringPool().StringF(
+				HeaderVal.StrF());
+		const TDesC8 &FieldValDesC = FieldValStr.DesC();
+		delete iEtag;
+		iEtag = NULL;
+		iEtag = FieldValDesC.AllocL();
+		}
+	}
+
+/**
+ * CHttpClient::MHFRunL
+ * http state machine callback
+ */
+void CHttpClient::MHFRunL(RHTTPTransaction aTransaction,
+		const THTTPEvent& aEvent)
+	{
+	switch (aEvent.iStatus)
+		{
+		case THTTPEvent::EGotResponseHeaders:
+			{
+			// HTTP response headers have been received. We can determine now if there is
+			// going to be a response body to save.
+			RHTTPResponse resp = aTransaction.Response();
+			iReturnCode = resp.StatusCode();
+
+			if (iAction == EActionOption)
+				{
+				CalDavUtils::ScanAllowHeaderL(aTransaction, *iOptions);
+				CalDavUtils::ScanDAVHeaderL(aTransaction, *iOptions);
+				}
+
+			GetEtagHeaderL(aTransaction);
+			
+			TBool cancelling = ETrue;
+			if (resp.HasBody() && (iReturnCode >= OK) && (iReturnCode
+					< MUTIPLECHOICES))
+				cancelling = EFalse;
+
+			if (cancelling)
+				{
+				aTransaction.Close();
+				CActiveScheduler::Stop();
+				}
+			}
+			break;
+		case THTTPEvent::EGotResponseBodyData:
+			{
+			// Get the body data supplier
+			MHTTPDataSupplier* body = aTransaction.Response().Body();
+			TPtrC8 dataChunk;
+			TBool isLast = body->GetNextDataPart(dataChunk);
+			if (iBodyResponse)
+				iBodyResponse->InsertL(iBodyResponse->Size(), dataChunk);
+			// Done with that bit of body data
+			body->ReleaseData();
+			}
+			break;
+		case THTTPEvent::EResponseComplete:
+			{
+			// The transaction's response is complete
+			}
+			break;
+		case THTTPEvent::ESucceeded:
+			{
+			aTransaction.Close();
+			CActiveScheduler::Stop();
+			}
+			break;
+		case THTTPEvent::EFailed:
+			{
+			aTransaction.Close();
+			CActiveScheduler::Stop();
+			}
+			break;
+		case THTTPEvent::ERedirectedPermanently:
+			{
+			}
+			break;
+		case THTTPEvent::ERedirectedTemporarily:
+			{
+			}
+			break;
+		default:
+			{
+			// close off the transaction if it's an error
+			if (aEvent.iStatus < 0)
+				{
+				iReturnCode = aEvent.iStatus;
+				aTransaction.Close();
+				CActiveScheduler::Stop();
+				}
+			}
+			break;
+		}
+	}
+
+/**
+ * CHttpClient::MHFRunError
+ * http stack erros
+ */
+TInt CHttpClient::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/,
+		const THTTPEvent& /*aEvent*/)
+	{
+	iReturnCode = aError;
+	return KErrNone;
+	}
+
+/**
+ * CHttpClient::SetUserL
+ * set username for authentification
+ */
+void CHttpClient::SetUserL(const TDesC8 &aUser)
+	{
+	if (iUser)
+		delete iUser;
+	iUser = aUser.Alloc();
+	iSess.Close();
+	OpenSessionL();
+	}
+
+/**
+ * CHttpClient::SetPasswordL
+ * Set Password for authentification
+ */
+void CHttpClient::SetPasswordL(const TDesC8 &aPassword)
+	{
+	if (iPassword)
+		delete iPassword;
+	iPassword = aPassword.Alloc();
+	iSess.Close();
+	OpenSessionL();
+	}
+
+/**
+ * CHttpClient::User
+ * get username
+ */
+TPtrC8 CHttpClient::User()
+	{
+	return iUser ? *iUser : KNullDesC8();
+	}
+
+/**
+ * CHttpClient::Password
+ * get password
+ */
+TPtrC8 CHttpClient::Password()
+	{
+	return iPassword ? *iPassword : KNullDesC8();
+	}
+
+/**
+ * CHttpClient::ReturnCode
+ * get returned HTTP code
+ */
+TInt CHttpClient::ReturnCode()
+	{
+	return iReturnCode;
+	}
+
+/**
+ * CHttpClient::ETag
+ * get ETag
+ */
+TPtrC8 CHttpClient::ETag()
+	{
+	return iEtag ? *iEtag : KNullDesC8();
+	}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarengines/caldav/tsrc/CalDavTest.cpp	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,936 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: Caldav Test Suite 
+*
+*/
+
+#include "CalDavTest.h"
+#include <e32base.h>
+#include <e32std.h>
+#include <e32base.h>
+#include <calentry.h>
+#include <calentryview.h>
+#include <caleninterimutils2.h>
+#include <calcalendarinfo.h>
+#include <calsession.h>
+#include "caldavengine.h"
+#include "httpclient.h"
+#include <caldavsession.h>
+_LIT(KTextConsoleTitle, "Console");
+_LIT(KTextFailed, " failed, leave code = %d");
+_LIT(KTextPressAnyKey, " [press any key]\n");
+//  Global Variables
+LOCAL_D CConsoleBase* console; // write all messages to this
+
+_LIT8(urlAries,"http://aries.demo.sun.com:3080/davserver/dav/home/modendahl@demo.sun.com/calendar/");
+_LIT8(urlAriesPrincipal,"http://aries.demo.sun.com:3080/davserver/dav/principals/modendahl/");
+_LIT8(urlAriesHome,"http://aries.demo.sun.com:3080/davserver/dav/home/modendahl@demo.sun.com/");
+_LIT8(urlWN,"http://whatsnew.demo.iplanet.com:3080/dav/home/modendahl/calendar/");
+_LIT8(userSUN,"modendahl");
+_LIT8(passwordSUN,"secret");
+_LIT8(urlGoogle,"https://www.google.com/calendar/dav/maximilian.odendahl@sun.com/events/");
+_LIT8(urlGooglePrincipal,"https://www.google.com/calendar/dav/maximilian.odendahl@sun.com/user/");
+_LIT8(userGoogle,"maximilian.odendahl@sun.com");
+_LIT8(passwordGoogle,"iplanetiplanet");
+_LIT8(urlChandler,"https://hub.chandlerproject.org/dav/mod/f16c9eb0-6373-11de-979e-cdd32d46e10a11111/");
+_LIT8(urlChandlerPrincipal,"https://hub.chandlerproject.org/dav/users/mod/");
+_LIT8(userChandler,"mod");
+_LIT8(passwordChandler,"modmod");
+_LIT8(urlBedework,"http://bedework.org:8585/ucaldav/user/testuser29/calendar/");
+_LIT8(urlBedeWorkPrincipal,"http://bedework.org:8585/ucaldav/principals/users/testuser29");
+_LIT8(userBedework,"testuser29");
+_LIT8(passwordbedework,"bedework");
+_LIT8(urlYahoo,"https://caldav.calendar.yahoo.com/dav/lkz633/Calendar/lkz633/");
+_LIT8(urlYahooPrincipal,"https://caldav.calendar.yahoo.com/principals/users/lkz633/");
+_LIT8(userYahoo,"lkz633");
+_LIT8(passwordYahoo,"iplanetiplanet");
+_LIT8(urlOracle,"http://kingsknight.sfbay.sun.com:7777/caldav/Sun/home/7B7B.65E6.user.6FCA54EE73AD4821811999F4D7679F6E000000000070%40email.invalid/calendars/MyCalendar");
+_LIT8(urlOraclePrincipal,"http://kingsknight.sfbay.sun.com:7777/caldav/Sun/principals/individuals/7B7B.65E6.user.6FCA54EE73AD4821811999F4D7679F6E000000000070%40email.invalid");
+_LIT8(userOracle,"symbian");
+_LIT8(passwordOracle,"Secret12");
+_LIT8(urlSogo,"http://sogo-demo.inverse.ca/SOGo/dav/sogo3/Calendar/personal/");
+_LIT8(userSogo,"sogo3");
+_LIT8(passwordSogo,"sogo3");
+_LIT8(urlDAV,"http://dhcp-usca15-127-168.red.iplanet.com/dav/calendar/");
+_LIT8(userDAV,"max");
+_LIT8(passwordDAV,"max");
+_LIT8(urlApple,"http://zeta.macosforge.org:8008/calendars/__uids__/1E872019-0078-412D-8EE0-85A5680365C2/calendar/");
+_LIT8(principalAplle,"http://zeta.macosforge.org:8008/calendars/__uids__/1E872019-0078-412D-8EE0-85A5680365C2/calendar/");
+_LIT8(userApple,"trial1");
+_LIT8(passwordApple,"lompywickets");
+_LIT8(urlKerio,"http://iop.test.kerio.com/calendars/iop.test.kerio.com/user1/Calendar");
+_LIT8(principalKerio,"http://iop.test.kerio.com/caldav/iop.test.kerio.com/user1/");
+_LIT8(userKerio,"user1");
+_LIT8(passwordkerio,"x");
+_LIT8(urlDaviCal,"http://dev.davical.org:8008/caldav.php/user1/home/");
+_LIT8(principalDaviCal,"http://dev.davical.org:8008/caldav.php/user1/");
+_LIT8(userDaviCal,"user1");
+_LIT8(passwordDaviCal,"user1");
+_LIT8(urlblabla,"http://www.blablabalbalabal.com/calendar/");
+_LIT8(passwordblabla,"bla");
+_LIT8(userblabla,"blabla");
+_LIT(calendar, "c:calendar12345");
+_LIT8(KFixedUIDics,"123456.ics");
+
+#define TWOSECONDS TTimeIntervalMicroSeconds32(2000000)
+
+void CreateCalFileL()
+	{
+	CCalSession* session = CCalSession::NewL();
+	CleanupStack::PushL(session);
+	TRAPD(err, session->CreateCalFileL(calendar));
+	if (err == KErrAlreadyExists)
+		{
+		session->DeleteCalFileL(calendar);
+		session->CreateCalFileL(calendar);
+		}
+	CleanupStack::PopAndDestroy(session);
+	}
+
+void DeleteCalFileL()
+	{
+	CCalSession* session = CCalSession::NewL();
+	CleanupStack::PushL(session);
+	session->DeleteCalFileL(calendar);
+	CleanupStack::PopAndDestroy(session);
+	}
+
+TBool GetBoolFromProperties2(CCalCalendarInfo* info, const TDesC8 &aKey)
+	{
+	TBool boolean;
+	TPckgC<TBool> pckgboolean(boolean);
+	pckgboolean.Set(info->PropertyValueL(aKey));
+	return pckgboolean();
+	}
+
+TCalTime GetTimeFromProperties2(CCalCalendarInfo* info, const TDesC8 &aKey)
+	{
+	TCalTime time;
+	TPckgC<TCalTime> pckgtime(time);
+	pckgtime.Set(info->PropertyValueL(aKey));
+	return pckgtime();
+	}
+
+void NewApptL(HBufC8* aUid, TBool aEvent, CCalEntryView* iCalEntryView)
+	{
+	CCalEntry* appt = CCalEntry::NewL(aEvent ? CCalEntry::EEvent
+			: CCalEntry::ETodo, aUid, CCalEntry::EMethodNone, 0);
+	CleanupStack::PushL(appt);
+
+	//Some data
+	TBuf16<100> summary;
+	summary.Copy(*aUid);
+	appt->SetSummaryL(summary);
+	appt->SetLocationL(_L("Location2"));
+	appt->SetDescriptionL(_L("Description3"));
+
+	//Start / end date
+	TTime start;
+	start.UniversalTime();
+	TTime end;
+	end.UniversalTime();
+	TCalTime startCalTime;
+	startCalTime.SetTimeUtcL(start);
+	TCalTime endCalTime;
+	endCalTime.SetTimeUtcL(end);
+
+	//Set it
+	appt->SetStartAndEndTimeL(startCalTime, endCalTime);
+
+	//Store this new Entry
+
+	RPointerArray<CCalEntry> entryArray;
+	CleanupClosePushL(entryArray);
+	entryArray.AppendL(appt);
+	TInt success(0);
+	iCalEntryView->StoreL(entryArray, success);
+	entryArray.Reset();
+	CleanupStack::PopAndDestroy(&entryArray);
+	CleanupStack::PopAndDestroy(appt);
+	}
+
+CalDavTest::CalDavTest(CConsoleBase* console)
+	{
+	iConsole = console;
+	TInt connect = iFileLogger.Connect();
+	TTime home;
+	home.UniversalTime();
+	_LIT(KDateFormat,"%H%T%S");
+	TBuf<20> StringTime;
+	home.FormatL(StringTime, KDateFormat);
+	StringTime.Append(_L(".txt"));
+	iFileLogger.CreateLog(_L("CalDav"),StringTime, EFileLoggingModeOverwrite);
+	}
+
+CalDavTest::~CalDavTest()
+	{
+	iFileLogger.CloseLog();
+	iFileLogger.Close();
+	}
+
+void CalDavTest::Write(TBool aSuccess, const char* aMessage)
+	{
+	TBuf<500> buffer;
+	TPtrC8 ptr(reinterpret_cast<const TUint8*> (aMessage));
+	buffer.Copy(ptr);
+
+	Write(aSuccess, buffer);
+	}
+
+void CalDavTest::Write(TBool aSuccess, const TDesC &aMessage)
+	{
+	// convert char* into tbug
+	TBuf<500> buffer;
+	buffer.Append(aMessage);
+
+	if (aSuccess)
+		buffer.Append(_L("....PASSED\n"));
+	else
+		buffer.Append(_L("....FAILED\n"));
+
+	// write to console and file
+	Write(buffer);
+	}
+
+void CalDavTest::TestClientServerL(TInt aSucces, const TDesC8 &aUrl,
+		const TDesC8 &aUser, const TDesC8 &aPassword)
+	{
+	TBuf16<500> url;
+	url.Copy(aUrl);
+	Write(_L("\n\nStarting CalDav client-server test..."));
+	Write(url);
+
+	CreateCalFileL();
+
+	CCalDavSession *server = CCalDavSession::NewLC();
+	iSession = server;
+
+	if (ConfigureSessionL(aSucces, aUrl, aUser, aPassword) == KErrNone)
+		{
+		OptionSession();
+		}
+
+	CleanupStack::PopAndDestroy(server);
+	iSession = NULL;
+	DeleteCalFileL();
+
+	Write(_L("\nFinished CalDav client-server test..."));
+	Write(_L("\n\n"));
+	}
+
+void CalDavTest::TestGeneralEngineL()
+	{
+	CreateCalFileL();
+	CCalDavEngine* store = CCalDavEngine::NewLC(calendar);
+	iEngine = store;
+
+	CalendarInfoL();
+	GetUIDByUrl();
+	GetBaseUrl();
+
+	CleanupStack::PopAndDestroy(store);
+	iEngine = NULL;
+	DeleteCalFileL();
+	}
+
+void CalDavTest::TestEngineL(TInt aSucces, const TDesC8 &aUrl,
+		const TDesC8 &aUser, const TDesC8 &aPassword, TBool aWebdavsync,
+		TBool aCtag, TBool aEvent, TBool aTodo, TBool aFreeBusy, TBool aJournal)
+	{
+	Write(_L("\n\nStarting CalDav Engine test..."));
+	TBuf16<500> url;
+	url.Copy(aUrl);
+	Write(url);
+	Write(_L("\n"));
+
+	CreateCalFileL();
+
+	CCalDavEngine* store = CCalDavEngine::NewLC(calendar);
+
+	iEngine = store;
+	iWebdavSync = aWebdavsync;
+	iCtag = aCtag;
+
+	iVEVENT = aEvent;
+	iVTODO = aTodo;
+	iVFREEBUSY = aFreeBusy;
+	iVJOURNAL = aJournal;
+
+	Write(_L("\n\nStarting init and option tests...\n"));
+
+	Enabled(EFalse);
+	if (EnableL(aSucces, aUrl, aUser, aPassword) == KErrNone)
+		{
+		Enabled(ETrue);
+		OptionsL();
+		CTagL(ETrue);
+		SynctokenL(ETrue);
+
+		/******* Test events ******/
+		Write(_L("\nStarting VEvent engine tests...\n\n"));
+
+		HBufC8* newuid = iEngine->iCalIntermimUtils2->GlobalUidL();
+		// need to save it, as it will be destroyed by CCalEntry::NewL
+		TBuf8<100> uid;
+		uid.Append(*newuid);
+		// does entry exists locally
+		DoesExistL(EFalse, uid);
+		// add new local event with UID
+		NewApptL(newuid, ETrue, iEngine->iCalEntryView);
+		// does entry exists locally
+		DoesExistL(ETrue, uid);
+
+		// send to server using handle	 
+		unsigned long local = iEngine->DoesEntryExistL(uid);
+		// send existing event to server
+		SendL(local);
+		// available on server
+		if (iEngine->iOptions.VEVENT)
+			{
+			HeadL(ETrue, uid);
+			//download from server
+			DownloadLGetL(local);
+			DownloadLMultiGetL(local);
+			// delete on server 
+			DeleteServerL(local);
+			// available on server
+			HeadL(EFalse, uid);
+			}
+		else
+			HeadL(EFalse, uid);
+
+		// delete locally 
+		DeleteClientL(uid);
+		// should be gone now
+		DoesExistL(EFalse, uid);
+		/**************************/
+
+		CTagL(!iEngine->iOptions.VEVENT);
+		SynctokenL(!iEngine->iOptions.VEVENT);
+
+		User::After(TWOSECONDS);
+		SyncL();
+
+		CTagL(ETrue);
+		SynctokenL(ETrue);
+
+		// test synchronization method, put/delete on server using http calls		
+		if (iEngine->iOptions.VEVENT)
+			{
+			Write(_L("\nStarting VEvent http and sync tests...\n\n"));
+			// create directly on server using only http calls
+			SendL(ETrue);
+			// we should not have this yet
+			DoesExistL(EFalse, KFixedUIDics);
+			User::After(TWOSECONDS);
+			SyncL();
+			// now we should
+			DoesExistL(ETrue, KFixedUIDics);
+			// delete directly on server
+			DeleteServerL();
+			// we should still have it
+			DoesExistL(ETrue, KFixedUIDics);
+			User::After(TWOSECONDS);
+			SyncL();
+			// now it should be gone locally
+			DoesExistL(EFalse, KFixedUIDics);
+			}
+
+		/******* Test VTodo ******/
+
+		Write(_L("\n\nStarting VTodo tests...\n\n"));
+
+		HBufC8* newuid2 = iEngine->iCalIntermimUtils2->GlobalUidL();
+		// need to save it, as it will be destroyed by CCalEntry::NewL
+		TBuf8<100> uid2;
+		uid2.Append(*newuid2);
+		// does entry exists locally
+		DoesExistL(EFalse, uid2);
+		// add new local event with UID
+		NewApptL(newuid2, EFalse, iEngine->iCalEntryView);
+		// does entry exists locally
+		DoesExistL(ETrue, uid2);
+
+		// send to server using handle	 
+		unsigned long local2 = iEngine->DoesEntryExistL(uid2);
+		// send existing event to server
+		SendL(local2);
+
+		if (iEngine->iOptions.VTODO)
+			{
+			// available on server
+			HeadL(ETrue, uid2);
+			//download from server
+			DownloadLGetL(local2);
+			DownloadLMultiGetL(local2);
+			// delete on server 
+			DeleteServerL(local2);
+			// available on server
+			HeadL(EFalse, uid2);
+			}
+		else
+			HeadL(EFalse, uid2);
+		// delete locally 
+		DeleteClientL(uid2);
+		// should be gone now
+		DoesExistL(EFalse, uid2);
+		/**************************/
+
+		CTagL(!iEngine->iOptions.VTODO);
+		SynctokenL(!iEngine->iOptions.VTODO);
+
+		// test synchronization method, put/delete on server using http calls		
+		if (iEngine->iOptions.VTODO)
+			{
+			Write(_L("\nStarting VTodo http and sync tests...\n\n"));
+			// create directly on server using only http calls
+			SendL(EFalse);
+			// we should not have this yet
+			DoesExistL(EFalse, KFixedUIDics);
+			User::After(TWOSECONDS);
+			SyncL();
+			// now we should
+			DoesExistL(ETrue, KFixedUIDics);
+			// delete directly on server
+			DeleteServerL();
+			// we should still have it
+			DoesExistL(ETrue, KFixedUIDics);
+			User::After(TWOSECONDS);
+			SyncL();
+			// now it should be gone locally as well
+			DoesExistL(EFalse, KFixedUIDics);
+			}
+
+		/**** Test Calendar ******/
+		/*
+		 // creating calendars under home calendar should not be allowed
+		 if (iEngine->iOptions.MKCALENDAR)
+		 {
+		 Write(_L("\n\nStarting Calendar tests...\n\n"));
+		 _LIT8(howareyou, "howareyoudoingtoday");
+		 MkCalendarL(KErrNone, howareyou);
+		 MkCalendarL(KErrArgument, howareyou);
+		 DeleteCalendarL(howareyou);
+		 }
+		 */
+		/**************************/
+		iEngine->DisableL();
+		}
+
+	CleanupStack::PopAndDestroy(store);
+	iEngine = NULL;
+	DeleteCalFileL();
+	
+	Write(_L("\n\nFinished CalDav Engine test..."));
+	Write(_L("\n\n"));
+	}
+
+void CalDavTest::Write(const TDesC &aMessage)
+	{
+	iConsole->Write(aMessage);
+	iFileLogger.Write(aMessage);
+	}
+
+void CalDavTest::Enabled(TBool aEnabled)
+	{
+	Write(iEngine->EnabledSync() == aEnabled, __FUNCTION__);
+	}
+
+void CalDavTest::DoesExistL(TBool aExists, const unsigned long localuid)
+	{
+	CCalEntry* entry = iEngine->iCalEntryView->FetchL(localuid);
+	CleanupStack::PushL(entry);
+	unsigned long uid = iEngine->DoesEntryExistL(entry->UidL());
+	Write(aExists ? uid > 0 : uid == 0, __FUNCTION__);
+
+	CleanupStack::PopAndDestroy(entry);
+	}
+
+void CalDavTest::DoesExistL(TBool aExists, const TDesC8 &aUID)
+	{
+	unsigned long uid = iEngine->DoesEntryExistL(aUID);
+	Write(aExists ? uid > 0 : uid == 0, __FUNCTION__);
+	}
+
+void CalDavTest::HeadL(TBool aExists, const TDesC8 &aUid)
+	{
+	TBool del = iEngine->HeadL(aUid) == OK;
+	Write(aExists == del, __FUNCTION__);
+	}
+
+void CalDavTest::MkCalendarL(TInt aSuccess, const TDesC8 &aName)
+	{
+	TInt ret = iEngine->MkcalendarL(aName);
+	Write(ret == aSuccess, __FUNCTION__);
+	}
+
+void CalDavTest::DeleteCalendarL(const TDesC8 &aName)
+	{
+	Write(iEngine->DeleteCalendarL(aName) == KErrNone, __FUNCTION__);
+	}
+
+void CalDavTest::OptionsL()
+	{
+	TBuf<500> message;
+	message.Append(_L("Options Displayname "));
+	CCalCalendarInfo* info = iEngine->iCalSession->CalendarInfoL();
+	TBuf<500> display;
+	display.Copy(info->NameL());
+	message.Append(display);
+	delete info;
+	Write(display != KNullDesC, message);
+	Write(iEngine->iOptions.sync_collection == iWebdavSync, _L("Options Webdav Sync"));
+	Write(iEngine->iOptions.sync_ctag == iCtag, _L("Options Ctag"));
+	Write(iEngine->iOptions.VEVENT == iVEVENT, _L("Options VEVENT"));
+	Write(iEngine->iOptions.VTODO == iVTODO, _L("Options VTODO"));
+	Write(iEngine->iOptions.VFREEBUSY == iVFREEBUSY, _L("FREEBUSY"));
+	Write(iEngine->iOptions.VJOURNAL == iVJOURNAL, _L("VJOURNAL"));
+	}
+
+void CalDavTest::CalendarInfoL()
+	{
+	_LIT8(user,"user");
+	_LIT8(password,"pass");
+	_LIT8(url,"http://neindanke/");
+	iEngine->SetUserL(user);
+	iEngine->SetUrlL(url);
+	iEngine->SetPasswordL(password);
+	iEngine->SetSyncIntervalL(TTimeIntervalMinutes(5));
+	iEngine->SetPastDaysL(TTimeIntervalDays(10));
+	iEngine->SetKeepServerEntryL(EFalse);
+	iEngine->SetImmediateSyncL(ETrue);
+	iEngine->EnableL();
+
+	iEngine->iCalSession = CCalSession::NewL();
+	iEngine->iCalSession->OpenL(calendar);
+
+	CCalCalendarInfo* calendarInfo = iEngine->iCalSession->CalendarInfoL();
+	CleanupStack::PushL(calendarInfo);
+
+	Write(!GetBoolFromProperties2(calendarInfo, KCaldavEnabled), _L("CalendarInfo: enabled"));
+	Write(!GetBoolFromProperties2(calendarInfo, KCaldavKeepServer), _L("CalendarInfo: Keepserver"));
+	Write(GetBoolFromProperties2(calendarInfo, KCaldavImmediateSync), _L("CalendarInfo: ImmediateSync"));
+	Write(calendarInfo->PropertyValueL(KCaldavUrl) == url, _L("CalendarInfo: url"));
+	Write(calendarInfo->PropertyValueL(KCaldavUser) == user, _L("CalendarInfo: user"));
+	Write(calendarInfo->PropertyValueL(KCaldavPassword) == password, _L("CalendarInfo: password"));
+
+	TTimeIntervalDays pastday;
+	TPckgC<TTimeIntervalDays> pastdays(pastday);
+	pastdays.Set(calendarInfo->PropertyValueL(KCaldavPastDays));
+	Write(TTimeIntervalDays(10) == pastdays(), _L("CalendarInfo: pastdays"));
+
+	TTimeIntervalMinutes syncintervals;
+	TPckgC<TTimeIntervalMinutes> syncinterval(syncintervals);
+	syncinterval.Set(calendarInfo->PropertyValueL(KCaldavSyncInterval));
+	Write(TTimeIntervalMinutes(5) == syncinterval(), _L("CalendarInfo: syncinterval"));
+
+	/*
+	 Write(calendarInfo->PropertyValueL(KCaldavSynctoken) ==KNullDesC8, _L("CalendarInfo: SyncToken"));
+	 Write(calendarInfo->PropertyValueL(KCaldavCtag) == KNullDesC8, _L("CalendarInfo: CTag"));
+	 Write(GetTimeFromProperties2(calendarInfo,KCaldavTime).TimeUtcL()==  TCalTime().TimeUtcL(), _L("CalendarInfo: LastTime"));		
+	 */
+
+	// access point	    
+	CleanupStack::PopAndDestroy(calendarInfo);
+
+	delete iEngine->iCalSession;
+	iEngine->iCalSession = NULL;
+	}
+
+void CalDavTest::GetUIDByUrl()
+	{
+	_LIT8(url,"1234");
+	_LIT8(url1,"/hi/1234.ics");
+	_LIT8(url2,"/1234.ics");
+	_LIT8(url3,"1234.ics");
+	_LIT8(url4,"1234");
+
+	Write(iEngine->GetUIDByUrl(url1) == url, __FUNCTION__);
+	Write(iEngine->GetUIDByUrl(url2) == url, __FUNCTION__);
+	Write(iEngine->GetUIDByUrl(url3) == url, __FUNCTION__);
+	Write(iEngine->GetUIDByUrl(url4) == url, __FUNCTION__);
+	}
+
+void CalDavTest::GetBaseUrl()
+	{
+	_LIT8(url1,"http://www.ok.de/1234.ics");
+	_LIT8(url,"http://www.ok.de");
+	_LIT8(url2,"https://www.ok.de:80/123444444.ics");
+	_LIT8(urlport,"https://www.ok.de:80");
+
+	iEngine->GetBaseUrl(url1);
+	Write(*iEngine->iBaseUrl == url, __FUNCTION__);
+
+	iEngine->GetBaseUrl(url2);
+	Write(*iEngine->iBaseUrl == urlport, __FUNCTION__);
+	}
+
+void CalDavTest::CTagL(TBool aEqual)
+	{
+	if (iEngine->iOptions.sync_ctag && !iEngine->iOptions.sync_collection)
+		{
+		HBufC8* tag = iEngine->GetCTagL();
+		Write(aEqual ? *tag == *iEngine->iCTag : *tag != *iEngine->iCTag, _L("CTag"));
+		if (aEqual && (*tag != *iEngine->iCTag))
+			{
+			TBuf<500> name;
+			name.Append(_L("saved cTag: "));
+			TBuf<100> one;
+			one.Copy(*iEngine->iCTag);
+			name.Append(one);
+			name.Append(_L(" current server cTag: "));
+			TBuf<100> two;
+			two.Copy(*tag);
+			name.Append(two);
+			Write(ETrue, name);
+			}
+		delete tag;
+		}
+	}
+
+void CalDavTest::SynctokenL(TBool aEqual)
+	{
+	if (iEngine->iOptions.sync_collection)
+		{
+		HBufC8* tag = iEngine->GetSyncTokenL();
+		Write(aEqual ? *tag == *iEngine->iSynctoken : *tag
+				!= *iEngine->iSynctoken, _L("SyncToken"));
+		if (aEqual && (*tag != *iEngine->iSynctoken))
+			{
+			TBuf<500> name;
+			name.Append(_L("saved Syntoken: "));
+			TBuf<100> one;
+			one.Copy(*iEngine->iSynctoken);
+			name.Append(one);
+			name.Append(_L(" current server Synctoken: "));
+			TBuf<100> two;
+			two.Copy(*tag);
+			name.Append(two);
+			Write(ETrue, name);
+			}
+		delete tag;
+		}
+	}
+
+void CalDavTest::SendL(const unsigned long localuid)
+	{
+	Write(iEngine->UploadEntryL(localuid, MCalChangeCallBack2::EChangeAdd,
+			MCalChangeCallBack2::EChangeEntryAll) == KErrNone, __FUNCTION__);
+	}
+
+void CalDavTest::SendL(TBool aVEvent)
+	{
+	TBuf8<500> url;
+	url.Append(*iEngine->iUrl);
+	url.Append(KFixedUIDics);
+	_LIT8(KEntry1, "BEGIN:VCALENDAR\r\n"
+			"PRODID:Symbian\r\n"
+			"VERSION:2.0\r\n"
+			"BEGIN:VEVENT\r\n"
+			"UID:123456\r\n"
+			"SUMMARY:first entry\r\n"
+			"DESCRIPTION:a description\r\n"
+			"DTSTAMP:20100411T100000Z\r\n"
+			"DTSTART:20100411T100000Z\r\n"
+			"DTEND:20100412T120000Z\r\n"
+			"END:VEVENT\r\n"
+			"END:VCALENDAR\r\n");
+	_LIT8(KEntry2, "BEGIN:VCALENDAR\r\n"
+			"PRODID:Symbian\r\n"
+			"VERSION:2.0\r\n"
+			"BEGIN:VTODO\r\n"
+			"DTSTAMP:20100205T235335Z\r\n"
+			"DUE;VALUE=DATE:20110104\r\n"
+			"SUMMARY:Task #1\r\n"
+			"UID:123456\r\n"
+			"END:VTODO\r\n"
+			"END:VCALENDAR\r\n");
+
+	CBufFlat* response = CBufFlat::NewL(500);
+	CleanupStack::PushL(response);
+	TInt Ret = iEngine->iHttp->PutL(url, aVEvent ? KEntry1() : KEntry2(),
+			response);
+	CleanupStack::PopAndDestroy(response);
+	
+	if (Ret==PRECONDFAILED)
+	{	
+		//might be still there from an older run
+		TBuf8<500> url;
+		url.Append(*iEngine->iUrl);
+		url.Append(KFixedUIDics);
+		iEngine->iHttp->DeleteL(url);
+		
+		CBufFlat* response = CBufFlat::NewL(500);
+		CleanupStack::PushL(response);
+		Ret = iEngine->iHttp->PutL(url, aVEvent ? KEntry1() : KEntry2(),
+				response);
+		CleanupStack::PopAndDestroy(response);
+		
+		// locally as well maybe:
+		iEngine->DeleteLocalEntryL(KFixedUIDics);
+	}
+	Write((Ret == CREATED) || (Ret == NOCONTENT) || (Ret == OK), __FUNCTION__);
+	}
+
+void CalDavTest::SyncL()
+	{
+	Write(iEngine->SyncL(), __FUNCTION__);
+	}
+
+void CalDavTest::DownloadLGetL(const unsigned long localuid)
+	{
+	TInt aPos = iEngine->iLocalUidArray.Find(localuid);
+	if (aPos != KErrNotFound)
+		Write(iEngine->DownloadEntryL(iEngine->iGlobalUidArray[aPos])
+				== KErrNone, __FUNCTION__);
+	else
+		Write(EFalse, __FUNCTION__);
+	}
+void CalDavTest::DownloadLMultiGetL(const unsigned long localuid)
+	{
+	if (iEngine->iOptions.MULTIGET)
+		{
+		TInt aPos = iEngine->iLocalUidArray.Find(localuid);
+		if (aPos != KErrNotFound)
+			{
+			TBuf8<500> url;
+			url.Append(iEngine->iUrl->Mid(iEngine->iBaseUrl->Length()));
+			url.Append(iEngine->iGlobalUidArray[aPos]);
+			url.Append(KIcs);
+			CDesC8ArrayFlat *multiget = new (ELeave) CDesC8ArrayFlat(4);
+			CleanupStack::PushL(multiget);
+			multiget->AppendL(url);
+			multiget->AppendL(url);
+			Write(iEngine->DownloadEntryL(multiget) == KErrNone, __FUNCTION__);
+			multiget->Reset();
+			CleanupStack::PopAndDestroy(multiget);
+			}
+		else
+			Write(EFalse, __FUNCTION__);
+		}
+	}
+
+TInt CalDavTest::ConfigureSessionL(TInt aSucces, const TDesC8 &aUrl,
+		const TDesC8 &aUser, const TDesC8 &aPassword)
+	{
+	iSession->SetUrl(calendar, aUrl);
+	iSession->SetUsername(calendar, aUser);
+	iSession->SetPassword(calendar, aPassword);
+	TInt ret = iSession->Enable(calendar);
+	Write(ret == aSucces, __FUNCTION__);
+	return ret;
+	}
+
+void CalDavTest::OptionSession()
+	{
+	TTimeIntervalDays pastdays = 0;
+	TTimeIntervalMinutes syncinterval = 0;
+	TBool immediatesync = EFalse;
+	TBool keepserverentry = EFalse;
+	TBuf8<500> url, username, password;
+
+	// retreive standard values
+	iSession->PastDays(calendar, pastdays);
+	iSession->SyncInterval(calendar, syncinterval);
+	iSession->ImmediateSync(calendar, immediatesync);
+	iSession->KeepServerEntry(calendar, keepserverentry);
+	iSession->Url(calendar, url);
+	iSession->Username(calendar, username);
+	iSession->Password(calendar, password);
+
+	Write(pastdays.Int() == DEFAULT_PAST_DAYS, __FUNCTION__);
+	Write(syncinterval.Int() == DEFAULT_SYNC_MINUTES, __FUNCTION__);
+	Write(immediatesync, __FUNCTION__);
+	Write(keepserverentry, __FUNCTION__);
+	Write(url == urlAries, __FUNCTION__);
+	Write(password == passwordSUN, __FUNCTION__);
+	Write(username == userSUN, __FUNCTION__);
+
+	// set new values
+	pastdays = TTimeIntervalDays(100);
+	syncinterval = TTimeIntervalMinutes(4);
+	immediatesync = EFalse;
+	keepserverentry = EFalse;
+	iSession->SetPastDays(calendar, pastdays);
+	iSession->SetSyncInterval(calendar, syncinterval);
+	iSession->SetImmediateSync(calendar, immediatesync);
+	iSession->SetKeepServerEntry(calendar, keepserverentry);
+	iSession->SetUrl(calendar, urlGooglePrincipal);
+	iSession->SetUsername(calendar, userGoogle);
+	iSession->SetPassword(calendar, passwordGoogle);
+
+	// check if new values are set correctly
+	TTimeIntervalDays pastdays1(10000);
+	TTimeIntervalMinutes syncinterval1(4000);
+	TBool immediatesync1 = ETrue;
+	TBool keepserverentry1 = ETrue;
+	TBuf8<500> url1, username1, password1;
+
+	iSession->PastDays(calendar, pastdays1);
+	iSession->SyncInterval(calendar, syncinterval1);
+	iSession->ImmediateSync(calendar, immediatesync1);
+	iSession->KeepServerEntry(calendar, keepserverentry1);
+	iSession->Url(calendar, url1);
+	iSession->Username(calendar, username1);
+	iSession->Password(calendar, password1);
+
+	Write(pastdays1.Int() == 100, __FUNCTION__);
+	Write(syncinterval1.Int() == 4, __FUNCTION__);
+	Write(!immediatesync1, __FUNCTION__);
+	Write(!keepserverentry1, __FUNCTION__);
+	Write(url1 == urlGooglePrincipal, __FUNCTION__);
+	Write(username1 == userGoogle, __FUNCTION__);
+	Write(password1 == passwordGoogle, __FUNCTION__);
+	}
+
+TInt CalDavTest::EnableL(TInt aSucces, const TDesC8 &aUrl, const TDesC8 &aUser,
+		const TDesC8 &aPassword)
+	{
+	iEngine->SetUrlL(aUrl);
+	iEngine->SetUserL(aUser);
+	iEngine->SetPasswordL(aPassword);
+	TInt ret = iEngine->EnableL();
+	Write(ret == aSucces, __FUNCTION__);
+	return ret;
+	}
+
+void CalDavTest::DeleteServerL(const unsigned long localuid)
+	{
+	Write(iEngine->DeleteEntryL(localuid) == KErrNone, __FUNCTION__);
+	}
+
+void CalDavTest::DeleteServerL()
+	{
+	TBuf8<500> url;
+	url.Append(*iEngine->iUrl);
+	url.Append(KFixedUIDics);
+	TInt Return = iEngine->iHttp->DeleteL(url);
+	Write((Return == NOCONTENT) || (Return == OK), __FUNCTION__);
+	}
+
+void CalDavTest::DeleteClientL(const TDesC8 &aUid)
+	{
+	Write(iEngine->DeleteLocalEntryL(aUid) == KErrNone, __FUNCTION__);
+	}
+
+LOCAL_C void DoStartL()
+	{
+
+	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
+	CleanupStack::PushL(scheduler);
+	CActiveScheduler::Install(scheduler);
+
+	for (TInt i = 0; i <= 10; i++)
+		{
+		CalDavTest* aTest = new (ELeave) CalDavTest(console);
+		 
+		aTest->TestClientServerL(KErrNone, urlAries, userSUN, passwordSUN);
+		aTest->TestClientServerL(KErrArgument, urlblabla, userblabla,
+				passwordblabla);
+		
+		aTest->TestGeneralEngineL();
+		
+		//Test syntax: (url, username,password,webdav sync,ctag,  aEvent, aTodo, aFreeBusy, aJournal)
+
+		aTest->TestEngineL(KErrNone, urlWN, userSUN, passwordSUN, ETrue, ETrue,
+				ETrue, ETrue, ETrue, EFalse);
+
+		aTest->TestEngineL(KErrNone, urlAriesHome, userSUN, passwordSUN, ETrue,
+				ETrue, ETrue, ETrue, ETrue, EFalse);
+		aTest->TestEngineL(KErrNone, urlAries, userSUN, passwordSUN, ETrue,
+				ETrue, ETrue, ETrue, ETrue, EFalse);
+		aTest->TestEngineL(KErrNone, urlAriesPrincipal, userSUN, passwordSUN,
+				ETrue, ETrue, ETrue, ETrue, ETrue, EFalse);
+
+		aTest->TestEngineL(KErrNone, urlApple, userApple, passwordApple,
+				EFalse, ETrue, ETrue, ETrue, ETrue, ETrue);
+		aTest->TestEngineL(KErrNone, principalAplle, userApple, passwordApple,
+				EFalse, ETrue, ETrue, ETrue, ETrue, ETrue);
+
+		aTest->TestEngineL(KErrNone, urlGoogle, userGoogle, passwordGoogle,
+				EFalse, ETrue, ETrue, EFalse, EFalse, EFalse);
+		aTest->TestEngineL(KErrNone, urlGooglePrincipal, userGoogle,
+				passwordGoogle, EFalse, ETrue, ETrue, EFalse, EFalse, EFalse);
+
+		aTest->TestEngineL(KErrNone, urlChandler, userChandler,
+				passwordChandler, EFalse, ETrue, ETrue, ETrue, ETrue, ETrue);
+		aTest->TestEngineL(KErrNone, urlChandlerPrincipal, userChandler,
+				passwordChandler, EFalse, ETrue, ETrue, ETrue, ETrue, ETrue);
+
+		aTest->TestEngineL(KErrNone, urlOracle, userOracle, passwordOracle,
+				EFalse, ETrue, ETrue, ETrue, EFalse, EFalse);
+		aTest->TestEngineL(KErrNone, urlOraclePrincipal, userOracle,
+				passwordOracle, EFalse, ETrue, ETrue, ETrue, EFalse, EFalse);
+
+		aTest->TestEngineL(KErrNone, urlSogo, userSogo, passwordSogo, EFalse,
+				ETrue, ETrue, ETrue, EFalse, EFalse);
+		aTest->TestEngineL(KErrNone, urlDAV, userDAV, passwordDAV, EFalse,
+				EFalse, ETrue, ETrue, EFalse, EFalse);
+		
+		aTest->TestEngineL(KErrNone, urlYahoo, userYahoo, passwordYahoo,
+				EFalse, ETrue, ETrue, EFalse, ETrue, EFalse);
+		aTest->TestEngineL(KErrNone, urlYahooPrincipal, userYahoo,
+				passwordYahoo, EFalse, ETrue, ETrue, EFalse, ETrue, EFalse);
+		
+		aTest->TestEngineL(KErrNone, urlDaviCal, userDaviCal, passwordDaviCal,
+				EFalse, ETrue, ETrue, ETrue, ETrue, ETrue);
+		aTest->TestEngineL(KErrNone, principalDaviCal, userDaviCal,
+				passwordDaviCal, EFalse, ETrue, ETrue, ETrue, ETrue, ETrue);
+
+		aTest->TestEngineL(KErrNone, urlKerio, userKerio, passwordkerio,
+				EFalse, ETrue, ETrue, ETrue, ETrue, EFalse);
+		aTest->TestEngineL(KErrNone, principalKerio, userKerio, passwordkerio,
+				EFalse, ETrue, ETrue, ETrue, ETrue, EFalse);
+
+		aTest->TestEngineL(KErrNone, urlBedework, userBedework,
+				passwordbedework, EFalse, ETrue, ETrue, ETrue,
+				EFalse, EFalse);
+		aTest->TestEngineL(KErrNone, urlBedeWorkPrincipal, userBedework,
+				passwordbedework, EFalse, ETrue, ETrue, ETrue,
+				EFalse, EFalse);
+
+		aTest->TestEngineL(KErrArgument, urlAries, userSUN, passwordblabla,
+				ETrue, ETrue, ETrue, ETrue, ETrue, EFalse);
+
+		aTest->TestEngineL(KErrArgument, urlblabla, userblabla, passwordblabla,
+				EFalse, EFalse, ETrue, ETrue, EFalse, EFalse);
+
+		delete aTest;
+		}
+
+	// Delete active scheduler
+	CleanupStack::PopAndDestroy(scheduler);
+	}
+
+//  Global Functions
+GLDEF_C TInt E32Main()
+	{
+	__UHEAP_MARK;
+	CTrapCleanup* cleanup = CTrapCleanup::New();
+	TRAPD(createError, console = Console::NewL(KTextConsoleTitle, TSize(
+							KConsFullScreen, KConsFullScreen)));
+	if (createError)
+		return createError;
+	TRAPD(mainError, DoStartL());
+	if (mainError)
+		console->Printf(KTextFailed, mainError);
+	console->Printf(KTextPressAnyKey);
+	console->Getch();
+
+	delete console;
+	delete cleanup;
+	__UHEAP_MARKEND;
+	return KErrNone;
+	}
+
--- a/calendarengines/group/bld.inf	Mon Jun 21 15:38:59 2010 +0300
+++ b/calendarengines/group/bld.inf	Mon Jul 12 17:26:07 2010 +0100
@@ -27,6 +27,7 @@
 #include "../caleninterimutils/group/bld.inf"
 #include "../calenimp/group/bld.inf"
 #include "../calenlauncher/group/bld.inf"
+#include "../caldav/group/bld.inf"
 
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarui/caldav/data/2002B503.rss	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,52 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: registration file for Caldav ECOM plugin
+*
+*/
+
+#ifndef CALENCALDAVPLUGINREG_H
+#define CALENCALDAVPLUGINREG_H
+
+
+#include "CalDavUids.h"
+#include "caldav.loc"
+
+#include <ecom/registryinfo.rh>
+#include <calendar.loc>
+
+RESOURCE REGISTRY_INFO registry_info
+    {
+    dll_uid = CALENCALDAVPLUGIN_DLL_UID;
+    interfaces =
+        {
+        INTERFACE_INFO
+            {
+            interface_uid = CALENUIPLUGININTERFACE_ECOM_INTERFACE_UID;
+            implementations =
+                {
+                IMPLEMENTATION_INFO 
+                    {
+                    implementation_uid = CALEN_CALDAV_IMPLEMENTATION_UID;
+                    version_no = 1;
+                    display_name = qtn_caldav;
+                    default_data = "language(*)";
+                    opaque_data  = "";
+                    }
+                };
+            }
+        };
+    }
+
+#endif
+// End of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarui/caldav/data/caldav.loc	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,55 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: caldav user interface strings
+*
+*/
+
+#define qtn_caldav						"CalDAV Synchronisation"
+
+#define qtn_caldav_query_disconnect		"This change will disable synchronisation. Do you want to continue?"
+#define qtn_caldav_query_fail			"Synchronization could not be enabled. Please check url, username and password"
+#define qtn_caldav_query_success		"Synchronization was enabled successfully."
+
+#define qtn_caldav_access_point			"Access Point"
+
+#define qtn_caldav_username				"Username"
+#define qtn_caldav_url					"Url"
+#define qtn_caldav_password				"Password"
+#define qtn_caldav_syncinterval 		"Sync Interval"
+
+#define qtn_caldav_conflictaction 		"Conflict resolution"
+#define qtn_caldav_keep_server 			"Keep server"
+#define qtn_caldav_keep_device 			"Keep device"
+
+#define qtn_caldav_immediatesync 		"New entries"
+#define qtn_caldav_immediatesync_yes 	"Sync immediatly"
+#define qtn_caldav_immediatesync_no 	"Wait until next sync"
+
+#define qtn_caldav_enable 				"Enabled synchronization"
+#define qtn_caldav_yes					"Yes"
+#define qtn_caldav_no					"No"
+
+#define qtn_caldav_range				"Time range"
+#define qtn_caldav_range_two			"2 weeks back"
+#define qtn_caldav_range_three			"3 month back"
+#define qtn_caldav_range_six			"6 month back"
+#define qtn_caldav_range_all			"all events"
+
+#define qtn_caldav_time					"Sync interval"
+
+#define qtn_caldav_time_always			"Always on"
+#define qtn_caldav_time_one				"One minute"
+#define qtn_caldav_time_five			"Five minutes"
+#define qtn_caldav_time_fifteen			"Fifteen minutes"
+#define qtn_caldav_time_thirty 			"Thirty minutes"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarui/caldav/data/calencaldavpluginData.rss	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,351 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: Caldav ECOM plugin resource file
+*
+*/
+
+#include <eikon.rh>
+#include <avkon.hrh>
+#include <avkon.rh>
+#include <avkon.rsg>
+
+#include <Calendar.loc>
+#include "caldav.loc"
+
+NAME CLU2
+
+RESOURCE RSS_SIGNATURE { }
+
+
+
+RESOURCE TBUF r_caldav
+    {
+    buf = qtn_caldav;
+    }
+
+RESOURCE TBUF r_caldav_query_disconnect
+    {
+    buf = qtn_caldav_query_disconnect;
+    }
+
+RESOURCE TBUF r_caldav_query_fail
+    {
+    buf = qtn_caldav_query_fail;
+    }
+
+RESOURCE TBUF r_caldav_query_success
+    {
+    buf = qtn_caldav_query_success;
+    }
+
+RESOURCE DIALOG r_query
+    {
+    flags = EGeneralQueryFlags;
+    buttons = R_AVKON_SOFTKEYS_YES_NO;
+    title = qtn_caldav;
+    items =
+        {
+        DLG_LINE
+            {
+            type = EAknCtQuery;
+            id = EGeneralQuery;
+            control = AVKON_CONFIRMATION_QUERY
+                {
+                layout = EConfirmationQueryLayout;
+                animation = R_QGN_NOTE_INFO_ANIM;   
+                };
+            }
+        };
+    }
+
+RESOURCE TBUF r_caldav_access_point
+    {
+    buf = qtn_caldav_access_point;
+    }
+
+RESOURCE TBUF r_caldav_username
+    {
+    buf = qtn_caldav_username;
+    }
+
+RESOURCE TBUF r_caldav_url
+    {
+    buf = qtn_caldav_url;
+    }
+
+RESOURCE TBUF r_caldav_password
+    {
+    buf = qtn_caldav_password;
+    }
+
+RESOURCE TBUF r_caldav_syncinterval
+    {
+    buf = qtn_caldav_syncinterval;
+    }
+
+RESOURCE AVKON_SETTING_PAGE r_url_setting_page
+{
+	type = EEikCtEdwin;
+	editor_resource_id = r_url_editor_resource;
+}
+
+RESOURCE EDWIN r_url_editor_resource
+	{
+	maxlength = 255;
+	default_case = EAknEditorTextCase;
+	allowed_case_modes = EAknEditorAllCaseModes;
+	numeric_keymap = EAknEditorStandardNumberModeKeymap;
+	default_input_mode = EAknEditorTextInputMode;
+	allowed_input_modes = EAknEditorTextInputMode 
+	| EAknEditorNumericInputMode 
+	| EAknEditorSecretAlphaInputMode 
+	| EAknEditorKatakanaInputMode 
+	| EAknEditorFullWidthTextInputMode 
+	| EAknEditorFullWidthNumericInputMode 
+	| EAknEditorFullWidthKatakanaInputMode 
+	| EAknEditorHiraganaKanjiInputMode 
+	| EAknEditorHalfWidthTextInputMode;
+	special_character_table = R_AVKON_URL_SPECIAL_CHARACTER_TABLE_DIALOG;
+	lines = 0;
+	}
+
+RESOURCE AVKON_SETTING_PAGE r_username_setting_page
+{
+	type = EEikCtEdwin;
+	editor_resource_id = r_username_editor_resource;
+}
+
+RESOURCE EDWIN r_username_editor_resource
+{
+	maxlength = 255;
+	default_case = EAknEditorTextCase;
+	allowed_case_modes = EAknEditorAllCaseModes;
+	numeric_keymap = EAknEditorStandardNumberModeKeymap;
+	default_input_mode = EAknEditorTextInputMode;
+	allowed_input_modes = EAknEditorTextInputMode | EAknEditorNumericInputMode | EAknEditorSecretAlphaInputMode | EAknEditorKatakanaInputMode | EAknEditorFullWidthTextInputMode | EAknEditorFullWidthNumericInputMode | EAknEditorFullWidthKatakanaInputMode | EAknEditorHiraganaKanjiInputMode | EAknEditorHalfWidthTextInputMode;
+	lines = 0;
+}
+
+RESOURCE AVKON_SETTING_PAGE r_password_setting_page
+{
+	//type = EEikCtEdwin;
+	//editor_resource_id = r_password_editor_resource;
+	type = EEikCtSecretEd;
+	editor_resource_id = r_settinglist_alpha_password;
+}
+
+RESOURCE EDWIN r_password_editor_resource
+	{
+	maxlength = 255;
+	default_case = EAknEditorTextCase;
+	allowed_case_modes = EAknEditorAllCaseModes;
+	numeric_keymap = EAknEditorStandardNumberModeKeymap;
+	default_input_mode = EAknEditorTextInputMode;
+	allowed_input_modes = EAknEditorTextInputMode | EAknEditorNumericInputMode | EAknEditorSecretAlphaInputMode | EAknEditorKatakanaInputMode | EAknEditorFullWidthTextInputMode | EAknEditorFullWidthNumericInputMode | EAknEditorFullWidthKatakanaInputMode | EAknEditorHiraganaKanjiInputMode | EAknEditorHalfWidthTextInputMode;
+	lines = 0;
+	}
+
+RESOURCE SECRETED r_settinglist_alpha_password
+    {
+    num_letters = 100;
+    }
+
+
+RESOURCE TBUF r_caldav_time
+    {
+    buf = qtn_caldav_time;
+   }
+
+RESOURCE AVKON_SETTING_PAGE r_caldav_time_page
+
+    {
+    number = 1;
+    type = EEikCtTimeOffsetEditor;
+    editor_resource_id = r_caldav_time_editor;
+    }
+
+RESOURCE TIME_OFFSET_EDITOR r_caldav_time_editor
+    {
+    minTimeOffset = TIME_OFFSET { seconds = 0; };
+    maxTimeOffset = TIME_OFFSET { seconds = 43200; };
+    flags = EEikTimeWithoutSecondsField | EEikTimeZoneOffsetFormat;
+    }
+
+RESOURCE AVKON_SETTING_PAGE r_caldav_binary_page
+{
+	label = "";
+	type = EAknCtPopupSettingList;
+	editor_resource_id = r_cl_setting_list_ed;
+}
+
+RESOURCE POPUP_SETTING_LIST r_cl_setting_list_ed
+{
+	flags = 0;
+}
+
+RESOURCE TBUF r_caldav_conflictaction
+    {
+    buf = qtn_caldav_conflictaction;
+   }
+
+RESOURCE AVKON_POPUP_SETTING_TEXTS r_caldav_conflictaction_texts
+    {
+    flags = 0;
+    setting_texts_resource = r_caldav_conflictaction_setting_array;
+    popped_up_texts_resource = r_caldav_conflictaction_popup_array;
+    }
+
+RESOURCE ARRAY r_caldav_conflictaction_setting_array
+    {
+    items =
+        {
+        AVKON_ENUMERATED_TEXT { value = 1; text = qtn_caldav_keep_server; },
+        AVKON_ENUMERATED_TEXT { value = 0; text = qtn_caldav_keep_device; }
+        };
+    }
+
+RESOURCE ARRAY r_caldav_conflictaction_popup_array
+    {
+    items =
+        {
+        LBUF { txt = qtn_caldav_keep_server; },
+        LBUF { txt = qtn_caldav_keep_device; }
+        };
+    }
+
+RESOURCE TBUF r_caldav_immediatesync
+    {
+    buf = qtn_caldav_immediatesync;
+   }
+
+RESOURCE AVKON_POPUP_SETTING_TEXTS r_caldav_immediatesync_texts
+    {
+    flags = 0;
+    setting_texts_resource = r_caldav_immediatesync_setting_array;
+    popped_up_texts_resource = r_caldav_immediatesync_popup_array;
+    }
+
+RESOURCE ARRAY r_caldav_immediatesync_setting_array
+    {
+    items =
+        {
+        AVKON_ENUMERATED_TEXT { value = 1; text = qtn_caldav_immediatesync_yes; },
+        AVKON_ENUMERATED_TEXT { value = 0; text = qtn_caldav_immediatesync_no; }
+        };
+    }
+
+RESOURCE ARRAY r_caldav_immediatesync_popup_array
+    {
+    items =
+        {
+        LBUF { txt = qtn_caldav_immediatesync_yes; },
+        LBUF { txt = qtn_caldav_immediatesync_no; }
+        };
+    }
+
+RESOURCE TBUF r_caldav_enable
+    {
+    buf = qtn_caldav_enable;
+   }
+
+RESOURCE AVKON_POPUP_SETTING_TEXTS r_caldav_enable_texts
+    {
+    flags = 0;
+    setting_texts_resource = r_caldav_enable_setting_array;
+    popped_up_texts_resource = r_caldav_enable_popup_array;
+    }
+
+RESOURCE ARRAY r_caldav_enable_setting_array
+    {
+    items =
+        {
+        AVKON_ENUMERATED_TEXT { value = 1; text = qtn_caldav_yes; },
+        AVKON_ENUMERATED_TEXT { value = 0; text = qtn_caldav_no; }
+        };
+    }
+
+RESOURCE ARRAY r_caldav_enable_popup_array
+    {
+    items =
+        {
+        LBUF { txt = qtn_caldav_yes; },
+        LBUF { txt = qtn_caldav_no; }
+        };
+    }
+
+RESOURCE TBUF r_caldav_range
+   {
+    buf = qtn_caldav_range;
+  }
+
+RESOURCE AVKON_POPUP_SETTING_TEXTS r_caldav_range_texts
+    {
+    flags = 0;
+    setting_texts_resource = r_caldav_range_setting_array;
+    popped_up_texts_resource = r_caldav_range_popup_array;
+    }
+
+RESOURCE ARRAY r_caldav_range_setting_array
+    {
+    items =
+        {
+        AVKON_ENUMERATED_TEXT { value = 0; text = qtn_caldav_range_two; },
+        AVKON_ENUMERATED_TEXT { value = 1; text = qtn_caldav_range_three; },
+        AVKON_ENUMERATED_TEXT { value = 2; text = qtn_caldav_range_six; },
+        AVKON_ENUMERATED_TEXT { value = 3; text = qtn_caldav_range_all; }
+        };
+    }
+
+RESOURCE ARRAY r_caldav_range_popup_array
+    {
+    items =
+        {
+        LBUF { txt = qtn_caldav_range_two; },
+        LBUF { txt = qtn_caldav_range_three; },
+        LBUF { txt = qtn_caldav_range_six; },
+        LBUF { txt = qtn_caldav_range_all; }
+
+        };
+    }
+
+RESOURCE AVKON_POPUP_SETTING_TEXTS r_caldav_time_texts
+    {
+    flags = 0;
+    setting_texts_resource = r_caldav_time_setting_array;
+    popped_up_texts_resource = r_caldav_time_popup_array;
+    }
+
+RESOURCE ARRAY r_caldav_time_setting_array
+    {
+    items =
+        {
+        AVKON_ENUMERATED_TEXT { value = 0; text = qtn_caldav_time_always; },
+        AVKON_ENUMERATED_TEXT { value = 1; text = qtn_caldav_time_one; },
+        AVKON_ENUMERATED_TEXT { value = 2; text = qtn_caldav_time_five; },
+        AVKON_ENUMERATED_TEXT { value = 3; text = qtn_caldav_time_fifteen; },
+        AVKON_ENUMERATED_TEXT { value = 4; text = qtn_caldav_time_thirty; }
+        };
+    }
+
+RESOURCE ARRAY r_caldav_time_popup_array
+    {
+    items =
+        {
+        LBUF { txt = qtn_caldav_time_always; },
+        LBUF { txt = qtn_caldav_time_one; },
+        LBUF { txt = qtn_caldav_time_five; },
+        LBUF { txt = qtn_caldav_time_fifteen; },
+        LBUF { txt = qtn_caldav_time_thirty; }
+        };
+    }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarui/caldav/group/bld.inf	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,27 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: provides the information required for building
+*				caldav ecom plugin, integrates into calendar
+*/
+
+#include <platform_paths.hrh>
+
+PRJ_PLATFORMS
+DEFAULT
+
+
+PRJ_MMPFILES
+calencaldavplugin.mmp
+
+// End of File
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarui/caldav/group/calencaldavplugin.mmp	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,78 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: This is the project specification file for the
+*				Caldav ECOM plugin, integrates into calendar app
+*/
+
+#include <platform_paths.hrh>
+#include <data_caging_paths.hrh>
+#include "../inc/CalDavUids.h"
+				
+TARGET          calencaldavplugin.dll
+TARGETTYPE      PLUGIN
+UID             SYMBIAN_ECOM_PLUGIN_UID CALENCALDAVPLUGIN_DLL_UID
+
+CAPABILITY      CAP_APPLICATION NetworkControl
+
+//Includes
+USERINCLUDE     ../inc
+USERINCLUDE     ../../inc
+
+APP_LAYER_SYSTEMINCLUDE
+SYSTEMINCLUDE   ../../../inc
+SYSTEMINCLUDE   /epoc32/include/
+SYSTEMINCLUDE   /epoc32/include/ecom
+
+SOURCEPATH      ../src
+SOURCE          calencaldavplugin.cpp
+SOURCE 			calencaldavpluginProxy.cpp
+SOURCE 			caldavsettingitems.cpp
+
+USERINCLUDE     ../../settings/settingsui/inc
+SOURCEPATH ../../settings/settingsui/src
+SOURCE calennestedsettingitem.cpp
+SOURCE calennestedsettingdialog.cpp
+
+// Resources
+SOURCEPATH      ../data
+START RESOURCE 2002B503.rss
+	TARGET calencaldavplugin.rsc
+END
+
+START RESOURCE  ../data/calencaldavplugindata.rss
+HEADER
+TARGETPATH      RESOURCE_FILES_DIR
+LANGUAGE_IDS
+END
+
+LIBRARY			avkon.lib
+LIBRARY         calinterimapi.lib
+LIBRARY         cone.lib
+LIBRARY         ecom.lib
+LIBRARY         eikcoctl.lib
+LIBRARY         eikcore.lib
+LIBRARY         euser.lib
+LIBRARY         bafl.lib
+LIBRARY         CommonEngine.lib
+LIBRARY			eikdlg.lib 
+LIBRARY			hlplch.lib 
+LIBRARY			FeatMgr.lib
+LIBRARY         aknskins.lib
+LIBRARY         aknicon.lib
+LIBRARY         flogger.lib 
+LIBRARY         caldavclient.lib 
+LIBRARY         commdb.lib
+LIBRARY         cmmanager.lib
+LIBRARY			charconv.lib
+LIBRARY			esock.lib calenglobaldata.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarui/caldav/inc/CalDavUids.h	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,27 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: Caldav UIDs
+*
+*/
+
+#ifndef CALDAVUIDS_H_
+#define CALDAVUIDS_H_
+
+#define SYMBIAN_ECOM_PLUGIN_UID               			0x10009D8D
+#define CALENUIPLUGININTERFACE_ECOM_INTERFACE_UID       0x1028336F
+
+#define CALENCALDAVPLUGIN_DLL_UID              	0x2002B503
+#define CALEN_CALDAV_IMPLEMENTATION_UID			0x2002B81E
+
+#endif /* CALDAVUIDS_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarui/caldav/inc/caldavsettingitems.h	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,158 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: Caldav setting items
+*
+*/
+
+#ifndef SETTINGITEMS_H
+#define SETTINGITEMS_H
+
+// INCLUDES
+#include <e32std.h>
+#include <e32base.h>
+ 
+#include <aknsettingitemlist.h>
+
+class CCalDavSession;
+
+class CCalDavTextSettingItem : public CAknTextSettingItem
+    {
+    public:
+        
+        static CCalDavTextSettingItem* NewL(TInt aId, CCalDavSession* aSession, const TDesC &aCalendar);
+        static CCalDavTextSettingItem* NewLC(TInt aId,CCalDavSession* aSession, const TDesC &aCalendar);
+        ~CCalDavTextSettingItem();
+        
+        void SetEnableSettingItem(CAknSettingItem* aItem);
+        
+    private:
+    	CCalDavTextSettingItem(TInt aId, CCalDavSession* aSession);
+        
+        void ConstructL(const TDesC &aCalendar);
+   
+    protected:// From base classes
+        void EditItemL( TBool aCalledFromMenu );
+        virtual void StoreL();
+        virtual void LoadL();
+           
+    private:
+    	TBuf<500> iInternalValue;
+    	CCalDavSession* iSession;
+    	HBufC* 	iCalendar;
+    	CAknSettingItem* iEnableSettingItem;	// not owned
+    };
+
+class CCalDavPasswordSettingItem : public CAknPasswordSettingItem
+    {
+    public:
+        
+        static CCalDavPasswordSettingItem* NewL(TInt aId, CCalDavSession* aSession, const TDesC &aCalendar);
+        static CCalDavPasswordSettingItem* NewLC(TInt aId, CCalDavSession* aSession, const TDesC &aCalendar);
+        ~CCalDavPasswordSettingItem();
+        
+        void SetEnableSettingItem(CAknSettingItem* aItem);
+        
+    private:
+    	CCalDavPasswordSettingItem(TInt aId, CCalDavSession* aSession);
+        
+        void ConstructL(const TDesC &aCalendar);
+   
+    protected:// From base classes
+        void EditItemL( TBool aCalledFromMenu );
+        virtual void StoreL();
+        virtual void LoadL();
+           
+    private:
+    	TBuf<500> iInternalValue;
+    	CCalDavSession* iSession;
+    	HBufC* 	iCalendar;
+    	CAknSettingItem* iEnableSettingItem;	// not owned
+    };
+
+class CCalDavBooleanSettingItem : public CAknBinaryPopupSettingItem
+    {
+    public:
+			
+        static CCalDavBooleanSettingItem* NewL(TInt aId, CCalDavSession* aSession, const TDesC &aCalendar);
+        static CCalDavBooleanSettingItem* NewLC(TInt aId, CCalDavSession* aSession, const TDesC &aCalendar);
+        ~CCalDavBooleanSettingItem();
+        
+    private:
+    	CCalDavBooleanSettingItem(TInt aId, CCalDavSession* aSession);
+        
+        void ConstructL(const TDesC &aCalendar);
+   
+    protected:// From base classes
+        void EditItemL( TBool aCalledFromMenu );
+        virtual void StoreL();
+        virtual void LoadL();
+           
+    private:
+    	TBool iInternalValue;
+    	CCalDavSession* iSession;
+    	HBufC* 	iCalendar;
+    };
+
+class CCalDavEnumeratedTextSettingItem : public CAknEnumeratedTextPopupSettingItem
+    {
+    public:
+			
+        static CCalDavEnumeratedTextSettingItem* NewL(TInt aId, CCalDavSession* aSession, const TDesC &aCalendar);
+        static CCalDavEnumeratedTextSettingItem* NewLC(TInt aId, CCalDavSession* aSession, const TDesC &aCalendar);
+        ~CCalDavEnumeratedTextSettingItem();
+        
+    private:
+    	CCalDavEnumeratedTextSettingItem(TInt aId, CCalDavSession* aSession);
+        
+        void ConstructL(const TDesC &aCalendar);
+   
+    protected:// From base classes
+        void EditItemL( TBool aCalledFromMenu );
+        virtual void StoreL();
+        virtual void LoadL();
+           
+    private:
+    	TInt iInternalValue;
+    	CCalDavSession* iSession;
+    	HBufC* 	iCalendar;
+    };
+
+class CCalDavAccessPointSettingItem : public CAknSettingItem
+    	{
+    	public:
+            static CCalDavAccessPointSettingItem*
+             CCalDavAccessPointSettingItem::NewL( TInt aSettingId, CCalDavSession* aSession, const TDesC &aCalendar);
+     	    ~CCalDavAccessPointSettingItem();
+     	private:
+     	    CCalDavAccessPointSettingItem ( TInt aSettingId, CCalDavSession* aSession);
+     	    void ConstructL(const TDesC &aCalendar);
+     
+     
+     	protected:	// from CAknSettingItem
+     		void EditItemL( TBool aCalledFromMenu );
+     		virtual void StoreL();
+            virtual void LoadL();
+            
+     		const TDesC& SettingTextL();
+     
+     	private:
+     	    TBool EditAccessPointItemL();
+     
+         private:
+             HBufC* iSettingText;
+         	CCalDavSession* iSession;
+     	};
+
+
+#endif // SETTINGITEMS_H
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarui/caldav/inc/calencaldavplugin.h	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,105 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: CalDav ECOM plugin
+*
+*/
+ 
+#ifndef __CALENLUNARPLUGIN_H__
+#define __CALENLUNARPLUGIN_H__
+
+//SYSTEM INCLUDES
+#include <e32base.h>
+#include <ecom.h> 
+
+//CALENDAR INCLUDES
+#include <calencommandhandler.h>
+#include <calennotificationhandler.h>
+#include "calencustomisation.h"
+#include "CalendarVariant.hrh"
+
+//FORWARD DECLARE
+class CEikonEnv;
+class CCalenLunarInfoProvider;
+class CEikLabel;
+class CCoeControl;
+class TRect;
+class CEikMenuPane;
+class CCalDavSession;
+
+enum TCalDavSettingItem
+{
+	ECalDavSettingUrl = 0,
+	ECalDavSettingUser,
+	ECalDavSettingPassword,
+	ECalDavSettingEnable,	
+	ECalDavSettingKeepServer, 
+	ECalDavSettingSyncImmediate, 
+	ECalDavSettingSyncInterval,
+	ECalDavSettingSyncRange,
+	ECalDavSettingAccess
+};
+	
+//CLASS DECLARATION
+NONSHARABLE_CLASS(CCalenCalDavPlugin) : 	public CCalenCustomisation,
+												public MCalenCommandHandler,
+												public MCalenNotificationHandler
+									
+	{
+	public:
+	    
+	    static CCalenCalDavPlugin* NewL( MCalenServices* aServices );
+	    virtual ~CCalenCalDavPlugin();
+    
+	private:
+		CCalenCalDavPlugin( MCalenServices* aServices);
+		void ConstructL();
+		
+	public: //From CCalenCustomisation
+		void GetCustomViewsL(  RPointerArray<CCalenView>& aCustomViewArray );
+		void GetCustomSettingsL( RPointerArray<CAknSettingItem>& aCustomSettingArray );
+        CCoeControl* InfobarL( const TRect& aRect );
+        const TDesC& InfobarL();
+	  MCalenPreview* CustomPreviewPaneL( TRect& aRect );
+        CCoeControl* PreviewPaneL(  TRect& aRect );
+        MCalenCommandHandler* CommandHandlerL( TInt aCommand );
+        void RemoveViewsFromCycle( RArray<TInt>& aViews );
+        TBool CustomiseMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane );
+        TBool CanBeEnabledDisabled();
+        TAny* CalenCustomisationExtensionL( TUid aExtensionUid );        
+        
+    public:// From MCalenCommandHandler
+        TBool HandleCommandL( const TCalenCommand& aCommand );
+        TAny* CalenCommandHandlerExtensionL( TUid aExtensionUid );
+    
+    public://From MCalenNotificationHandler 
+        void HandleNotification( const TCalenNotification aNotification );
+        
+    private:
+        
+		MCalenServices* iServices;
+	
+		TInt iStart;
+	    TInt iEnd;
+	    TRect iRect;
+	    TInt  iResourceFileOffset;
+	    
+    	CCalDavSession* iSession;
+	    
+	};
+	
+#endif //__CALENLUNARPLUGIN_H__
+
+
+
+ 									
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarui/caldav/sis/caldavplugin.pkg	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,43 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: sis file to package all Caldav components
+*
+*/
+ 
+; Languages
+&EN
+
+; Header
+#{"CalDAV plugin"}, (0x2002B775), 1, 0, 0
+
+; Localised Vendor name
+%{"Sun Microsystems"}
+
+; Unique Vendor name
+:"Sun Microsystems"
+
+;Platform Dependency
+[0x1028315f],0 ,0 ,0,{"S60ProductID"}
+
+; ------ files -----
+
+; caldav client-server
+"\epoc32\release\armv5\urel\CalDavServer.exe "-"!:\sys\bin\CalDavServer.exe"
+"\epoc32\release\armv5\urel\CalDavClient.dll "-"!:\sys\bin\CalDavClient.dll"
+
+;caldav calendarui ecom plugin
+"\epoc32\release\armv5\urel\calencaldavplugin.dll"-"!:\sys\Bin\calencaldavplugin.dll"
+"\epoc32\data\z\resource\calencaldavplugindata.rsc"-"!:\resource\plugins\calencaldavplugindata.rsc"
+"\epoc32\data\z\resource\calencaldavplugindata.r01" - "!:\resource\calencaldavplugindata.r01"
+"\epoc32\data\z\resource\plugins\calencaldavplugin.rsc"-"!:\resource\plugins\calencaldavplugin.rsc" 
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarui/caldav/src/caldavsettingitems.cpp	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,887 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: Caldav setting items
+*
+*/
+
+#include "caldavsettingitems.h"
+
+#include <StringLoader.h>
+#include <aknnotewrappers.h>
+#include <cmapplicationsettingsui.h>
+#include <CommDbConnPref.h>
+#include <UTF.H>
+
+#include <caldavsession.h>
+#include "calencaldavplugin.h"
+#include <calencaldavplugindata.rsg>
+
+#define KMAXSETTINGLENGTH	500
+
+#define KTIMETWOWEEKS 	14
+#define KTIMETHREEMONTH	30*3
+#define KTIMESIXMONTH	30*6
+#define KTIMEALL		1000
+
+#define KTIMEALWAYSON		0
+#define	KTIMEONEMINUTE		1
+#define	KTIMEFIVEMINUTES	5
+#define	KTIMEFIFTEENMINUTES	15
+#define KTIMETHIRTYMINUTES	30
+
+/**
+ * show a global info note
+ */
+void ShowNoteL(TInt aResource)
+	{
+	HBufC* text = StringLoader::LoadLC(aResource);
+	CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote();
+	note->ExecuteLD(*text);
+	CleanupStack::PopAndDestroy(text);
+	}
+
+/**
+ * CCalDavTextSettingItem::CCalDavTextSettingItem 
+ * default constructor
+ */
+CCalDavTextSettingItem::CCalDavTextSettingItem(TInt aId,
+		CCalDavSession* aSession) :
+	CAknTextSettingItem(aId, iInternalValue), iSession(aSession)
+	{
+
+	}
+
+/**
+ * CCalDavTextSettingItem::~CCalDavTextSettingItem 
+ * destructor
+ */
+CCalDavTextSettingItem::~CCalDavTextSettingItem()
+	{
+	delete iCalendar;
+	}
+
+/**
+ * CCalDavTextSettingItem::NewLC 
+ * 1st-phase construction
+ */
+CCalDavTextSettingItem* CCalDavTextSettingItem::NewLC(TInt aId,
+		CCalDavSession* aSession, const TDesC &aCalendar)
+	{
+	CCalDavTextSettingItem* self = new (ELeave) CCalDavTextSettingItem(aId,
+			aSession);
+	CleanupStack::PushL(self);
+	self->ConstructL(aCalendar);
+	return self;
+	}
+
+/**
+ * CCalDavTextSettingItem::NewL
+ *  1st-phase construction
+ */
+CCalDavTextSettingItem* CCalDavTextSettingItem::NewL(TInt aId,
+		CCalDavSession* aSession, const TDesC &aCalendar)
+	{
+	CCalDavTextSettingItem* self = CCalDavTextSettingItem::NewLC(aId, aSession,
+			aCalendar);
+	CleanupStack::Pop(); // self;
+	return self;
+	}
+
+/**
+ * CCalDavTextSettingItem::ConstructL
+ * 2nd-phase construction
+ */
+void CCalDavTextSettingItem::ConstructL(const TDesC &aCalendar)
+	{
+	iCalendar = aCalendar.AllocL();
+	HBufC* title = NULL;
+	TInt page = 0;
+	switch (Identifier())
+		{
+		case ECalDavSettingUrl:
+			title = StringLoader::LoadLC(R_CALDAV_URL);
+			page = R_URL_SETTING_PAGE;
+			break;
+		case ECalDavSettingUser:
+			title = StringLoader::LoadLC(R_CALDAV_USERNAME);
+			page = R_USERNAME_SETTING_PAGE;
+			break;
+		case ECalDavSettingPassword:
+			title = StringLoader::LoadLC(R_CALDAV_PASSWORD);
+			page = R_PASSWORD_SETTING_PAGE;
+			break;
+		}
+	SetEmptyItemTextL(KNullDesC);
+	CAknTextSettingItem::ConstructL(EFalse, 0, *title, NULL,page, -1);
+	CleanupStack::PopAndDestroy(title);
+	}
+
+/**
+ * CCalDavTextSettingItem::EditItemL
+ * Edits the item
+ */
+void CCalDavTextSettingItem::EditItemL(TBool aCalledFromMenu)
+	{
+	TBool enabled;
+	iSession->EnabledSync(*iCalendar, enabled);
+	if (enabled)
+		{
+		HBufC* text = StringLoader::LoadLC(R_CALDAV_QUERY_DISCONNECT);
+		CAknQueryDialog* dlg = CAknQueryDialog::NewL();
+		if (dlg->ExecuteLD(R_QUERY, *text))
+			{
+			CAknTextSettingItem::EditItemL(aCalledFromMenu);
+			// TODO: disable Enabled-Setting-Item	
+			}
+		CleanupStack::PopAndDestroy(text);
+		}
+	else
+		CAknTextSettingItem::EditItemL(aCalledFromMenu);
+	}
+
+/**
+ * CCalDavTextSettingItem::StoreL
+ * Stores the item
+ */
+void CCalDavTextSettingItem::StoreL()
+	{
+	CAknTextSettingItem::StoreL();
+
+	HBufC8* text = CnvUtfConverter::ConvertFromUnicodeToUtf8L(iInternalValue);
+	CleanupStack::PushL(text);
+	
+	switch (Identifier())
+		{
+		case ECalDavSettingUrl:
+			iSession->SetUrl(*iCalendar, *text);
+			break;
+		case ECalDavSettingUser:
+			iSession->SetUsername(*iCalendar, *text);
+			break;
+		case ECalDavSettingPassword:
+			iSession->SetPassword(*iCalendar, *text);
+			break;
+		}
+	CleanupStack::PopAndDestroy(text);
+	
+	if (iEnableSettingItem)
+		{
+		iEnableSettingItem->LoadL();
+		iEnableSettingItem->UpdateListBoxTextL();
+		}
+	}
+
+/**
+ * CCalDavTextSettingItem::LoadL
+ * loades the item
+ */
+void CCalDavTextSettingItem::LoadL()
+	{
+	HBufC8* buf = HBufC8::NewL(KMAXSETTINGLENGTH);
+	TPtr8 ptr(buf->Des());
+	switch (Identifier())
+		{
+		case ECalDavSettingUrl:
+			iSession->Url(*iCalendar, ptr);
+			break;
+		case ECalDavSettingUser:
+			iSession->Username(*iCalendar, ptr);
+			break;
+		case ECalDavSettingPassword:
+			iSession->Password(*iCalendar, ptr);
+			break;
+		}
+	CnvUtfConverter::ConvertToUnicodeFromUtf8(iInternalValue, ptr);
+	delete buf;
+	CAknTextSettingItem::LoadL();
+	}
+
+/**
+ * CCalDavTextSettingItem::StoreL
+ * Save a pointer to the Enable Item, this is used to set current
+ * enable/disable state
+ */
+void CCalDavTextSettingItem::SetEnableSettingItem(CAknSettingItem* aItem)
+	{
+	iEnableSettingItem = aItem;
+	}
+
+/**
+ * CCalDavPasswordSettingItem::CCalDavPasswordSettingItem
+ * default constructor
+ */
+CCalDavPasswordSettingItem::CCalDavPasswordSettingItem(TInt aId,
+		CCalDavSession* aSession) :
+	CAknPasswordSettingItem(aId, CAknPasswordSettingItem::EAlpha,
+			iInternalValue), iSession(aSession)
+	{
+
+	}
+
+/**
+ * CCalDavPasswordSettingItem::~CCalDavPasswordSettingItem
+ * default destructor
+ */
+CCalDavPasswordSettingItem::~CCalDavPasswordSettingItem()
+	{
+	delete iCalendar;
+	}
+
+/**
+ * CCalDavPasswordSettingItem::NewLC
+ * first phase construction
+ */
+CCalDavPasswordSettingItem* CCalDavPasswordSettingItem::NewLC(TInt aId,
+		CCalDavSession* aSession, const TDesC &aCalendar)
+	{
+	CCalDavPasswordSettingItem* self = new (ELeave) CCalDavPasswordSettingItem(
+			aId, aSession);
+	CleanupStack::PushL(self);
+	self->ConstructL(aCalendar);
+	return self;
+	}
+
+/**
+ * CCalDavPasswordSettingItem::NewL
+ * first phase construction
+ */
+CCalDavPasswordSettingItem* CCalDavPasswordSettingItem::NewL(TInt aId,
+		CCalDavSession* aSession, const TDesC &aCalendar)
+	{
+	CCalDavPasswordSettingItem* self = CCalDavPasswordSettingItem::NewLC(aId,
+			aSession, aCalendar);
+	CleanupStack::Pop(); // self;
+	return self;
+	}
+
+/**
+ * CCalDavPasswordSettingItem::SetEnableSettingItem
+ * Save a pointer to the Enable Item, this is used to set current
+ * enable/disable state
+ */
+void CCalDavPasswordSettingItem::SetEnableSettingItem(CAknSettingItem* aItem)
+	{
+	iEnableSettingItem = aItem;
+	}
+
+/**
+ * CCalDavPasswordSettingItem::ConstructL
+ * second phase construction
+ */
+void CCalDavPasswordSettingItem::ConstructL(const TDesC &aCalendar)
+	{
+	iCalendar = aCalendar.AllocL();
+	HBufC* title = NULL;
+	TInt page = 0;
+	switch (Identifier())
+		{
+		case ECalDavSettingPassword:
+			title = StringLoader::LoadLC(R_CALDAV_PASSWORD);
+			page = R_PASSWORD_SETTING_PAGE;
+			break;
+		}
+	SetEmptyItemTextL(KNullDesC);
+	CAknPasswordSettingItem::ConstructL(EFalse, 0, *title, NULL,page, -1);
+	CleanupStack::PopAndDestroy(title);
+	}
+
+/**
+ * CCalDavPasswordSettingItem::EditItemL
+ * edits the item
+ */
+void CCalDavPasswordSettingItem::EditItemL(TBool aCalledFromMenu)
+	{
+	TBool enabled;
+	iSession->EnabledSync(*iCalendar, enabled);
+	if (enabled)
+		{
+		HBufC* text = StringLoader::LoadLC(R_CALDAV_QUERY_DISCONNECT);
+		CAknQueryDialog* dlg = CAknQueryDialog::NewL();
+		if (dlg->ExecuteLD(R_QUERY, *text))
+			CAknPasswordSettingItem::EditItemL(aCalledFromMenu);
+		CleanupStack::PopAndDestroy(text);
+		}
+	else
+		CAknPasswordSettingItem::EditItemL(aCalledFromMenu);
+	CAknSettingItem::UpdateListBoxTextL();
+	}
+
+/**
+ * CCalDavPasswordSettingItem::StoreL
+ * stores the item
+ */
+void CCalDavPasswordSettingItem::StoreL()
+	{
+	CAknPasswordSettingItem::StoreL();
+	
+	HBufC8* text = CnvUtfConverter::ConvertFromUnicodeToUtf8L(iInternalValue);
+	CleanupStack::PushL(text);
+
+	switch (Identifier())
+		{
+		case ECalDavSettingPassword:
+			iSession->SetPassword(*iCalendar, *text);
+			break;
+		}
+	CleanupStack::PopAndDestroy(text);
+	}
+
+/**
+ * CCalDavPasswordSettingItem::LoadL
+ * loads the item
+ */
+void CCalDavPasswordSettingItem::LoadL()
+	{
+	HBufC8* buf = HBufC8::NewL(KMAXSETTINGLENGTH);
+	TPtr8 ptr(buf->Des());
+	switch (Identifier())
+		{
+		case ECalDavSettingPassword:
+			iSession->Password(*iCalendar, ptr);
+			break;
+		}
+	CnvUtfConverter::ConvertToUnicodeFromUtf8(iInternalValue, ptr);
+	delete buf;
+	CAknPasswordSettingItem::LoadL();
+	}
+
+/**
+ * CCalDavBooleanSettingItem::CCalDavBooleanSettingItem
+ * default constructor
+ */
+CCalDavBooleanSettingItem::CCalDavBooleanSettingItem(TInt aId,
+		CCalDavSession* aSession) :
+	CAknBinaryPopupSettingItem(aId, iInternalValue), iSession(aSession)
+	{
+
+	}
+
+/**
+ * CCalDavBooleanSettingItem::~CCalDavBooleanSettingItem
+ * default destructor
+ */
+CCalDavBooleanSettingItem::~CCalDavBooleanSettingItem()
+	{
+	delete iCalendar;
+	}
+
+/**
+ * CCalDavBooleanSettingItem::NewLC
+ * first phase construction
+ */
+CCalDavBooleanSettingItem* CCalDavBooleanSettingItem::NewLC(TInt aId,
+		CCalDavSession* aSession, const TDesC &aCalendar)
+	{
+	CCalDavBooleanSettingItem* self = new (ELeave) CCalDavBooleanSettingItem(
+			aId, aSession);
+	CleanupStack::PushL(self);
+	self->ConstructL(aCalendar);
+	return self;
+	}
+
+/**
+ * CCalDavBooleanSettingItem::NewLC
+ * first phase construction
+ */
+CCalDavBooleanSettingItem* CCalDavBooleanSettingItem::NewL(TInt aId,
+		CCalDavSession* aSession, const TDesC &aCalendar)
+	{
+	CCalDavBooleanSettingItem* self = CCalDavBooleanSettingItem::NewLC(aId,
+			aSession, aCalendar);
+	CleanupStack::Pop(); // self;
+	return self;
+	}
+
+/**
+ * CCalDavBooleanSettingItem::ConstructL
+ * second phase construction
+ */
+void CCalDavBooleanSettingItem::ConstructL(const TDesC &aCalendar)
+	{
+	iCalendar = aCalendar.AllocL();
+	HBufC* title = NULL;
+	TInt text = 0;
+	TInt page = R_CALDAV_BINARY_PAGE;
+	switch (Identifier())
+		{
+		case ECalDavSettingKeepServer:
+			title = StringLoader::LoadLC(R_CALDAV_CONFLICTACTION);
+			text = R_CALDAV_CONFLICTACTION_TEXTS;
+			break;
+		case ECalDavSettingSyncImmediate:
+			title = StringLoader::LoadLC(R_CALDAV_IMMEDIATESYNC);
+			text = R_CALDAV_IMMEDIATESYNC_TEXTS;
+			break;
+		case ECalDavSettingEnable:
+			title = StringLoader::LoadLC(R_CALDAV_ENABLE);
+			text = R_CALDAV_ENABLE_TEXTS;
+			break;
+		}
+	SetEmptyItemTextL(KNullDesC);
+	CAknBinaryPopupSettingItem::ConstructL(EFalse, 0, *title, NULL,page,
+			EAknCtPopupSettingList, NULL, text);
+	CleanupStack::PopAndDestroy(title);
+	}
+
+/**
+ * CCalDavBooleanSettingItem::EditItemL
+ * edits the item
+ */
+void CCalDavBooleanSettingItem::EditItemL(TBool aCalledFromMenu)
+	{
+	if (Identifier() == ECalDavSettingEnable)
+		{
+		TBool enabled_old;
+		iSession->EnabledSync(*iCalendar, enabled_old);
+		if (enabled_old)
+			{
+			HBufC* text = StringLoader::LoadLC(R_CALDAV_QUERY_DISCONNECT);
+			CAknQueryDialog* dlg = CAknQueryDialog::NewL();
+			if (dlg->ExecuteLD(R_QUERY, *text))
+				{
+				iSession->Disable(*iCalendar);
+				CAknBinaryPopupSettingItem::EditItemL(aCalledFromMenu);
+				}
+			CleanupStack::PopAndDestroy(text);
+			}
+		else
+			{
+			iSession->Enable(*iCalendar);
+			// TODO: progressbar
+			TBool enabled_new;
+			iSession->EnabledSync(*iCalendar, enabled_new);
+			if (!enabled_new)
+				{
+				ShowNoteL(R_CALDAV_QUERY_FAIL);
+				}
+			else
+				{
+				ShowNoteL(R_CALDAV_QUERY_SUCCESS);
+				CAknBinaryPopupSettingItem::EditItemL(aCalledFromMenu);
+				}
+			}
+		}
+	else
+		CAknBinaryPopupSettingItem::EditItemL(aCalledFromMenu);
+	}
+
+/**
+ * CCalDavBooleanSettingItem::StoreL
+ * stores the item
+ */
+void CCalDavBooleanSettingItem::StoreL()
+	{
+	CAknBinaryPopupSettingItem::StoreL();
+
+	switch (Identifier())
+		{
+		case ECalDavSettingKeepServer:
+			iSession->SetKeepServerEntry(*iCalendar, iInternalValue);
+			break;
+		case ECalDavSettingSyncImmediate:
+			iSession->SetImmediateSync(*iCalendar, iInternalValue);
+			break;
+		}
+	}
+
+/**
+ * CCalDavBooleanSettingItem::LoadL
+ * loads the item
+ */
+void CCalDavBooleanSettingItem::LoadL()
+	{
+	switch (Identifier())
+		{
+		case ECalDavSettingKeepServer:
+			iSession->KeepServerEntry(*iCalendar, iInternalValue);
+			break;
+		case ECalDavSettingSyncImmediate:
+			iSession->ImmediateSync(*iCalendar, iInternalValue);
+			break;
+		case ECalDavSettingEnable:
+			iSession->EnabledSync(*iCalendar, iInternalValue);
+			break;
+		}
+	CAknBinaryPopupSettingItem::LoadL();
+	}
+
+/**
+ * CCalDavEnumeratedTextSettingItem::CCalDavEnumeratedTextSettingItem
+ * default constructor
+ */
+CCalDavEnumeratedTextSettingItem::CCalDavEnumeratedTextSettingItem(TInt aId,
+		CCalDavSession* aSession) :
+	CAknEnumeratedTextPopupSettingItem(aId, iInternalValue), iSession(aSession)
+	{
+
+	}
+
+/**
+ * CCalDavEnumeratedTextSettingItem::~CCalDavEnumeratedTextSettingItem
+ * default destructor
+ */
+CCalDavEnumeratedTextSettingItem::~CCalDavEnumeratedTextSettingItem()
+	{
+	delete iCalendar;
+	}
+
+/**
+ * CCalDavEnumeratedTextSettingItem::NewLC
+ * first phase construction
+ */
+CCalDavEnumeratedTextSettingItem* CCalDavEnumeratedTextSettingItem::NewLC(
+		TInt aId, CCalDavSession* aSession, const TDesC &aCalendar)
+	{
+	CCalDavEnumeratedTextSettingItem* self =
+			new (ELeave) CCalDavEnumeratedTextSettingItem(aId, aSession);
+	CleanupStack::PushL(self);
+	self->ConstructL(aCalendar);
+	return self;
+	}
+
+/**
+ * CCalDavEnumeratedTextSettingItem::NewL
+ * first phase construction
+ */
+CCalDavEnumeratedTextSettingItem* CCalDavEnumeratedTextSettingItem::NewL(
+		TInt aId, CCalDavSession* aSession, const TDesC &aCalendar)
+	{
+	CCalDavEnumeratedTextSettingItem* self =
+			CCalDavEnumeratedTextSettingItem::NewLC(aId, aSession, aCalendar);
+	CleanupStack::Pop(); // self;
+	return self;
+	}
+
+/**
+ * CCalDavEnumeratedTextSettingItem::ConstructL
+ * second phase construction
+ */
+void CCalDavEnumeratedTextSettingItem::ConstructL(const TDesC &aCalendar)
+	{
+	iCalendar = aCalendar.AllocL();
+	HBufC* title = NULL;
+	TInt text = 0;
+	TInt page = R_CALDAV_BINARY_PAGE;
+	switch (Identifier())
+		{
+		case ECalDavSettingSyncRange:
+			title = StringLoader::LoadLC(R_CALDAV_RANGE);
+			text = R_CALDAV_RANGE_TEXTS;
+			break;
+		case ECalDavSettingSyncInterval:
+			title = StringLoader::LoadLC(R_CALDAV_TIME);
+			text = R_CALDAV_TIME_TEXTS;
+			break;
+
+		}
+	SetEmptyItemTextL(KNullDesC);
+	CAknEnumeratedTextSettingItem::ConstructL(EFalse, 0, *title, NULL,page,
+			EAknCtPopupSettingList, NULL, text);
+	CleanupStack::PopAndDestroy(title);
+	}
+
+/**
+ * CCalDavEnumeratedTextSettingItem::EditItemL
+ * edits the item
+ */
+void CCalDavEnumeratedTextSettingItem::EditItemL(TBool aCalledFromMenu)
+	{
+	CAknEnumeratedTextPopupSettingItem::EditItemL(aCalledFromMenu);
+	}
+
+/**
+ * CCalDavEnumeratedTextSettingItem::StoreL
+ * stores the item
+ */
+void CCalDavEnumeratedTextSettingItem::StoreL()
+	{
+	CAknEnumeratedTextPopupSettingItem::StoreL();
+
+	switch (iInternalValue)
+		{
+		case 0:
+			{
+			if (Identifier() == ECalDavSettingSyncRange)
+				iSession->SetPastDays(*iCalendar, TTimeIntervalDays(
+						KTIMETWOWEEKS));
+			else
+				iSession->SetSyncInterval(*iCalendar, TTimeIntervalMinutes(
+						KTIMEALWAYSON));
+			break;
+			}
+		case 1:
+			{
+			if (Identifier() == ECalDavSettingSyncRange)
+				iSession->SetPastDays(*iCalendar, TTimeIntervalDays(
+						KTIMETHREEMONTH));
+			else
+				iSession->SetSyncInterval(*iCalendar, TTimeIntervalMinutes(
+						KTIMEONEMINUTE));
+			break;
+			}
+		case 2:
+			{
+			if (Identifier() == ECalDavSettingSyncRange)
+				iSession->SetPastDays(*iCalendar, TTimeIntervalDays(
+						KTIMESIXMONTH));
+			else
+				iSession->SetSyncInterval(*iCalendar, TTimeIntervalMinutes(
+						KTIMEFIVEMINUTES));
+			break;
+			}
+		case 3:
+			{
+			if (Identifier() == ECalDavSettingSyncRange)
+				iSession->SetPastDays(*iCalendar, TTimeIntervalDays(KTIMEALL));
+			else
+				iSession->SetSyncInterval(*iCalendar, TTimeIntervalMinutes(
+						KTIMEFIFTEENMINUTES));
+			break;
+			}
+		case 4:
+			{
+			if (Identifier() == ECalDavSettingSyncInterval)
+				iSession->SetSyncInterval(*iCalendar, TTimeIntervalMinutes(
+						KTIMETHIRTYMINUTES));
+			break;
+			}
+		default:
+			if (Identifier() == ECalDavSettingSyncRange)
+				iSession->SetPastDays(*iCalendar, TTimeIntervalDays(
+						KTIMETWOWEEKS));
+			else
+				iSession->SetSyncInterval(*iCalendar, TTimeIntervalMinutes(
+						KTIMEALWAYSON));
+
+			break;
+		}
+	}
+
+/**
+ * CCalDavEnumeratedTextSettingItem::LoadL
+ * loads the item
+ */
+void CCalDavEnumeratedTextSettingItem::LoadL()
+	{
+	switch (Identifier())
+		{
+		case ECalDavSettingSyncRange:
+			{
+			TTimeIntervalDays days;
+			iSession->PastDays(*iCalendar, days);
+			switch (days.Int())
+				{
+				case KTIMETWOWEEKS:
+					{
+					iInternalValue = 0;
+					break;
+					}
+				case KTIMETHREEMONTH:
+					{
+					iInternalValue = 1;
+					break;
+					}
+				case KTIMESIXMONTH:
+					{
+					iInternalValue = 2;
+					break;
+					}
+				case KTIMEALL:
+					{
+					iInternalValue = 3;
+					break;
+					}
+				default:
+					iInternalValue = 0;
+					break;
+				}
+			break;
+			}
+		case ECalDavSettingSyncInterval:
+			{
+			TTimeIntervalMinutes minutes;
+			iSession->SyncInterval(*iCalendar, minutes);
+			switch (minutes.Int())
+				{
+				case KTIMEALWAYSON:
+					{
+					iInternalValue = 0;
+					break;
+					}
+				case KTIMEONEMINUTE:
+					{
+					iInternalValue = 1;
+					break;
+					}
+				case KTIMEFIVEMINUTES:
+					{
+					iInternalValue = 2;
+					break;
+					}
+				case KTIMEFIFTEENMINUTES:
+					{
+					iInternalValue = 3;
+					break;
+					}
+				case KTIMETHIRTYMINUTES:
+					{
+					iInternalValue = 4;
+					break;
+					}
+				default:
+					iInternalValue = 0;
+					break;
+				}
+			break;
+			}
+		}
+	CAknEnumeratedTextPopupSettingItem::LoadL();
+	}
+
+/**
+ * CCalDavAccessPointSettingItem::NewL
+ * first phase construction
+ */
+CCalDavAccessPointSettingItem* CCalDavAccessPointSettingItem::NewL(
+		TInt aSettingId, CCalDavSession* aSession, const TDesC &aCalendar)
+	{
+	CCalDavAccessPointSettingItem * item =
+			new (ELeave) CCalDavAccessPointSettingItem(aSettingId, aSession);
+	CleanupStack::PushL(item);
+	item->ConstructL(aCalendar);
+	CleanupStack::Pop(item);
+	return item;
+	}
+
+/**
+ * CCalDavAccessPointSettingItem::CCalDavAccessPointSettingItem
+ * default constructor
+ */
+CCalDavAccessPointSettingItem::CCalDavAccessPointSettingItem(TInt aSettingId,
+		CCalDavSession* aSession) :
+	CAknSettingItem(aSettingId), iSession(aSession)
+	{
+	}
+
+/**
+ * CCalDavAccessPointSettingItem::~CCalDavAccessPointSettingItem
+ * default destructor
+ */
+CCalDavAccessPointSettingItem::~CCalDavAccessPointSettingItem()
+	{
+	delete iSettingText;
+	}
+
+/**
+ * CCalDavAccessPointSettingItem::ConstructL
+ * second phase construction
+ */
+void CCalDavAccessPointSettingItem::ConstructL(const TDesC &/*aCalendar*/)
+	{
+	SetEmptyItemTextL(KNullDesC);
+	HBufC* title = StringLoader::LoadLC(R_CALDAV_ACCESS_POINT);
+	CAknSettingItem::ConstructL(EFalse, 0, *title, NULL,0, 0);
+	CleanupStack::PopAndDestroy(title);
+
+	_LIT(hi,"Default Connection");
+	iSettingText = hi().Alloc();
+	}
+
+/**
+ * CCalDavAccessPointSettingItem::EditItemL
+ * edits the item
+ */
+void CCalDavAccessPointSettingItem::EditItemL(TBool /*aCalledFromMenu*/)
+	{
+	delete iSettingText;
+	iSettingText = NULL;
+
+	TCmSettingSelection userSelection;
+	userSelection.iId = 0;
+	userSelection.iResult = CMManager::EDefaultConnection;
+
+	CCmApplicationSettingsUi* settings = CCmApplicationSettingsUi::NewL();
+	CleanupStack::PushL(settings);
+	TUint listedItems = CMManager::EShowDefaultConnection
+			| CMManager::EShowDestinations | CMManager::EShowConnectionMethods;
+	TBearerFilterArray filter;
+	settings->RunApplicationSettingsL(userSelection, listedItems, filter);
+	CleanupStack::PopAndDestroy(settings);
+
+	switch (userSelection.iResult)
+		{
+		case CMManager::EDestination:
+			{
+			TConnSnapPref prefs;
+			prefs.SetSnap(userSelection.iId);
+			// iSettingText =
+			// iConnection.Start( prefs, iStatus );
+			break;
+			}
+		case CMManager::EConnectionMethod:
+			{
+			TCommDbConnPref prefs;
+			prefs.SetIapId(userSelection.iId);
+			prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
+
+			// iConnection.Start( prefs, iStatus );
+			// iSettingText =
+			break;
+			}
+		case CMManager::EDefaultConnection:
+			{
+			// iConnection.Start( iStatus );
+			// iSettingText = 
+			break;
+			}
+		}
+	UpdateListBoxTextL();
+	}
+
+/**
+ * CCalDavAccessPointSettingItem::SettingTextL
+ * returns the setting text
+ */
+const TDesC& CCalDavAccessPointSettingItem::SettingTextL()
+	{
+	if (!iSettingText)
+		{
+		return CAknSettingItem::SettingTextL();
+		}
+	else if (iSettingText->Length() == 0)
+		{
+		return CAknSettingItem::SettingTextL();
+		}
+
+	return *iSettingText;
+	}
+
+/**
+ * CCalDavAccessPointSettingItem::StoreL
+ * stores the item
+ */
+void CCalDavAccessPointSettingItem::StoreL()
+	{
+	CAknSettingItem::StoreL();
+	}
+
+/**
+ * CCalDavAccessPointSettingItem::LoadL
+ * loads the item
+ */
+void CCalDavAccessPointSettingItem::LoadL()
+	{
+	//CAknSettingItem::Load();
+	}
+//  End of File  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarui/caldav/src/calencaldavplugin.cpp	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,343 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: CalDav ECOM plugin
+*
+*/
+
+#include <eikenv.h>
+#include <aknutils.h>
+#include <eiklabel.h>
+#include <avkon.hrh>
+#include <StringLoader.h>
+#include <AknMessageQueryDialog.h>
+#include <data_caging_path_literals.hrh>
+#include <bautils.h>
+#include <aknbiditextutils.h>
+#include <aknsettingitemlist.h>
+
+#include <caldavsession.h>
+#include <calcalendarinfo.h>
+#include <calenservices.h>
+#include <calendar.rsg>
+
+#include <CalenCaldavPluginData.rsg>
+#include <calencommands.hrh>
+#include "caldavsettingitems.h"
+#include "calennestedsettingitem.h"
+#include "calendarui_debug.h" 
+#include "CalenCaldavPlugin.h"
+
+_LIT( KResourceCCalDavPluginFile, "calencaldavplugindata.rsc" );
+
+#define KResourcePath KDC_RESOURCE_FILES_DIR
+
+/**
+ * CCalenCalDavPlugin::CCalenCalDavPlugin
+ * default constructor
+ */
+CCalenCalDavPlugin::CCalenCalDavPlugin(MCalenServices* aServices) :
+	iServices(aServices), iResourceFileOffset(NULL)
+
+	{
+	TRACE_ENTRY_POINT;TRACE_EXIT_POINT;
+	}
+
+/**
+ * CCalenCalDavPlugin::NewL
+ * first phase construction
+ */
+CCalenCalDavPlugin* CCalenCalDavPlugin::NewL(MCalenServices* aServices)
+	{
+	TRACE_ENTRY_POINT;
+	CCalenCalDavPlugin* self = new (ELeave) CCalenCalDavPlugin(aServices);
+	CleanupStack::PushL(self);
+	self->ConstructL();
+	CleanupStack::Pop(self);TRACE_EXIT_POINT;
+	return self;
+	}
+
+/**
+ * CCalenCalDavPlugin::~CCalenCalDavPlugin
+ * default destructor
+ */
+CCalenCalDavPlugin::~CCalenCalDavPlugin()
+	{
+	TRACE_ENTRY_POINT;
+
+	delete iSession;
+
+	if (iServices)
+		{
+		iServices->CancelNotifications(this);
+		iServices->Release();
+		}
+
+	if (iResourceFileOffset)
+		{
+		CCoeEnv::Static()->DeleteResourceFile(iResourceFileOffset);
+		}TRACE_EXIT_POINT;
+	}
+
+/**
+ * CCalenCalDavPlugin::ConstructL
+ * second phase construction
+ */
+void CCalenCalDavPlugin::ConstructL()
+	{
+	TRACE_ENTRY_POINT;
+
+	TFileName dllName;
+	// Get the complate path of the DLL from where it is currently loaded
+	Dll::FileName(dllName);
+
+	TFileName resourceFilename;
+	resourceFilename.Append(dllName.Mid(0, 2));
+	resourceFilename.Append(KResourcePath);
+	resourceFilename.Append(KResourceCCalDavPluginFile);
+	BaflUtils::NearestLanguageFile(CEikonEnv::Static()->FsSession(),
+			resourceFilename);
+	// Add the resource file.
+	iResourceFileOffset = CEikonEnv::Static()->AddResourceFileL(
+			resourceFilename);
+
+	iServices->GetCommandRange(iStart, iEnd);
+
+	iSession = CCalDavSession::NewL();
+
+	TRACE_EXIT_POINT;
+	}
+
+/**
+ * CCalenCalDavPlugin::InfobarL
+ * show an additional infobar
+ */
+CCoeControl* CCalenCalDavPlugin::InfobarL(const TRect& /*aRect*/)
+	{
+	TRACE_ENTRY_POINT;
+	return NULL;TRACE_EXIT_POINT;
+	}
+
+/**
+ * CCalenCalDavPlugin::InfobarL
+ * show an additional infobar
+ */
+const TDesC& CCalenCalDavPlugin::InfobarL()
+	{
+	TRACE_ENTRY_POINT;
+	return KNullDesC;
+	TRACE_EXIT_POINT;
+	}
+
+/**
+ * CCalenCalDavPlugin::PreviewPaneL
+ * show an additional preview pabe
+ */
+CCoeControl* CCalenCalDavPlugin::PreviewPaneL(TRect& /* aRect */)
+	{
+	TRACE_ENTRY_POINT;
+	return NULL;
+	TRACE_EXIT_POINT;
+	}
+
+/**
+ * CCalenCalDavPlugin::CustomPreviewPaneL
+ * show an additional custom preview pane
+ */
+MCalenPreview* CCalenCalDavPlugin::CustomPreviewPaneL(TRect& /* aRect */)
+	{
+	TRACE_ENTRY_POINT;
+	return NULL;
+	TRACE_EXIT_POINT;
+	}
+
+/**
+ * CCalenCalDavPlugin::CustomiseMenuPaneL
+ * customize menu pane
+ */
+TBool CCalenCalDavPlugin::CustomiseMenuPaneL(TInt /*aResourceId*/,
+		CEikMenuPane* /*aMenuPane*/)
+	{
+	TRACE_ENTRY_POINT;
+	return EFalse;
+	TRACE_EXIT_POINT;
+	}
+
+/**
+ * CCalenCalDavPlugin::HandleCommandL
+ * let this plugin handle its own commands
+ */
+TBool CCalenCalDavPlugin::HandleCommandL(const TCalenCommand& /*aCommand*/)
+	{
+	TRACE_ENTRY_POINT;TRACE_EXIT_POINT;
+	return EFalse;
+	}
+
+/**
+ * CCalenCalDavPlugin::CommandHandlerL
+ * let this plugin handle its own commands
+ */
+MCalenCommandHandler* CCalenCalDavPlugin::CommandHandlerL(TInt /*aCommand*/)
+	{
+	TRACE_ENTRY_POINT;
+	MCalenCommandHandler* commandHandler = NULL;
+	return commandHandler;TRACE_EXIT_POINT;
+	}
+
+/**
+ * CCalenCalDavPlugin::RemoveViewsFromCycle
+ * remove added views from cycle
+ */
+void CCalenCalDavPlugin::RemoveViewsFromCycle(RArray<TInt>& /*aViews*/)
+	{
+	TRACE_ENTRY_POINT;TRACE_EXIT_POINT;
+	}
+
+/**
+ * CCalenCalDavPlugin::GetCustomSettingsL
+ * add custom settings to calendar setting pane
+ * all CalDav settings are added here into UI
+ */
+void CCalenCalDavPlugin::GetCustomSettingsL(
+		RPointerArray<CAknSettingItem>& aCustomSettingArray)
+	{
+	TRACE_ENTRY_POINT
+
+	RPointerArray<CCalCalendarInfo> calendarInfoList;
+	iServices->GetAllCalendarInfoL(calendarInfoList);
+	CleanupClosePushL(calendarInfoList);
+
+	TInt count = calendarInfoList.Count();
+	for (TInt i = 0; i < count; i++)
+		{
+		TPtrC calendar = calendarInfoList[i]->FileNameL();
+
+		RPointerArray<CAknSettingItem> settings;
+
+		CCalDavBooleanSettingItem * enable = CCalDavBooleanSettingItem::NewL(
+				ECalDavSettingEnable, iSession, calendar);
+
+		CCalDavTextSettingItem* url = CCalDavTextSettingItem::NewL(
+				ECalDavSettingUrl, iSession, calendar);
+		url->SetEnableSettingItem(enable);
+		settings.Append(url);
+
+		CCalDavTextSettingItem* user = CCalDavTextSettingItem::NewL(
+				ECalDavSettingUser, iSession, calendar);
+		user->SetEnableSettingItem(enable);
+		settings.Append(user);
+
+		CCalDavPasswordSettingItem* password = CCalDavPasswordSettingItem::NewL(
+				ECalDavSettingPassword, iSession, calendar);
+		password->SetEnableSettingItem(enable);
+		settings.Append(password);
+
+		CCalDavBooleanSettingItem * keepserver =
+				CCalDavBooleanSettingItem::NewL(ECalDavSettingKeepServer,
+						iSession, calendar);
+		settings.Append(keepserver);
+
+		//    CCalDavBooleanSettingItem * immediatesync = CCalDavBooleanSettingItem::NewL(ECalDavSettingSyncImmediate,iSession, calendar);
+		//    settings.Append(immediatesync);
+
+		CCalDavEnumeratedTextSettingItem* range =
+				CCalDavEnumeratedTextSettingItem::NewL(ECalDavSettingSyncRange,
+						iSession, calendar);
+		settings.Append(range);
+
+		CCalDavEnumeratedTextSettingItem* time =
+				CCalDavEnumeratedTextSettingItem::NewL(
+						ECalDavSettingSyncInterval, iSession, calendar);
+		settings.Append(time);
+		settings.Append(enable);
+
+		CCalenNestedSettingItem* item = new (ELeave) CCalenNestedSettingItem(0,
+				settings, calendarInfoList[i]->NameL());
+		CleanupStack::PushL(item);
+
+		item->SetEmptyItemTextL(KNullDesC);
+
+		if (count == 1)
+			{
+			HBufC16* name = StringLoader::LoadLC(R_CALDAV);
+			item->ConstructL(EFalse, 0, *name, NULL,
+			R_CALEN_EMPTY_SETTING_PAGE, EAknSetListBox, NULL,
+			R_CALEN_EMPTY_POPUP_SETTING_TEXTS );
+			CleanupStack::PopAndDestroy(name);
+			}
+		else
+			{
+			item->ConstructL(EFalse, 0, calendarInfoList[i]->NameL(), NULL,
+			R_CALEN_EMPTY_SETTING_PAGE, EAknSetListBox, NULL,
+			R_CALEN_EMPTY_POPUP_SETTING_TEXTS );
+			}
+		aCustomSettingArray.Append(item);
+		CleanupStack::Pop(item);
+		}
+	CleanupStack::PopAndDestroy(&calendarInfoList);
+
+	TRACE_EXIT_POINT;
+	}
+
+/**
+ * CCalenCalDavPlugin::GetCustomViewsL
+ * add custom views
+ */
+void CCalenCalDavPlugin::GetCustomViewsL(RPointerArray<CCalenView>&
+/*aCustomViewArray*/)
+	{
+	TRACE_ENTRY_POINT;
+	TRACE_EXIT_POINT;
+	}
+
+/**
+ * CCalenCalDavPlugin::HandleNotification
+ * handle received notifications in this plugin
+ */
+void CCalenCalDavPlugin::HandleNotification(const TCalenNotification /*aNotification*/)
+	{
+	TRACE_ENTRY_POINT;
+	TRACE_EXIT_POINT;
+	}
+
+/**
+ * CCalenCalDavPlugin::CanBeEnabledDisabled
+ * can the plugin be disabled or enabled, called by customization manager
+ */
+TBool CCalenCalDavPlugin::CanBeEnabledDisabled()
+	{
+	return EFalse;
+	}
+
+/**
+ * CCalenCalDavPlugin::CalenCustomisationExtensionL
+ * add custom extensions
+ */
+TAny* CCalenCalDavPlugin::CalenCustomisationExtensionL(TUid /*aExtensionUid*/)
+	{
+	TRACE_ENTRY_POINT;
+	TRACE_EXIT_POINT;
+	return NULL;
+	}
+
+/**
+ * CCalenCalDavPlugin::CalenCommandHandlerExtensionL
+ * CalenCommandHandlerExtensionL
+ */
+TAny* CCalenCalDavPlugin::CalenCommandHandlerExtensionL(TUid /*aExtensionUid*/)
+	{
+	TRACE_ENTRY_POINT;
+	TRACE_EXIT_POINT;
+	return NULL;
+	}
+//EOF
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarui/caldav/src/calencaldavpluginProxy.cpp	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,47 @@
+/*
+* Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributor:
+* Maximilian Odendahl
+*
+* Contributors:
+* 
+* Description: calav ecom plugin proxy implementation
+*
+*/ 
+
+#include <implementationproxy.h>
+
+#include "CalDavUids.h"
+#include "calencaldavplugin.h"
+
+
+// ----------------------------------------------------------------------------
+// ImplementationTable
+// ----------------------------------------------------------------------------
+const TImplementationProxy ImplementationTable[] =
+    {
+    IMPLEMENTATION_PROXY_ENTRY( CALEN_CALDAV_IMPLEMENTATION_UID,
+                                CCalenCalDavPlugin::NewL )
+    
+    };
+
+
+// ----------------------------------------------------------------------------
+// ImplementationGroupProxy
+// ----------------------------------------------------------------------------
+EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
+    {
+    aTableCount = sizeof(ImplementationTable) / sizeof (TImplementationProxy);
+    return ImplementationTable;
+    }
+
+// ----------------------------------------------------------------------------
+// End of file
+// ----------------------------------------------------------------------------
+
--- a/calendarui/group/bld.inf	Mon Jun 21 15:38:59 2010 +0300
+++ b/calendarui/group/bld.inf	Mon Jul 12 17:26:07 2010 +0100
@@ -15,9 +15,6 @@
 *
 */
 
-
-
-
 PRJ_PLATFORMS
 DEFAULT
 
@@ -59,6 +56,8 @@
 ../rom/CalenLunarVietnamese_Variant.iby CUSTOMER_APP_LAYER_IBY_EXPORT_PATH(CalenLunarVietnamese_Variant.iby)
 ../rom/CalenLunarChinese_Variant.iby CUSTOMER_APP_LAYER_IBY_EXPORT_PATH(CalenLunarChinese_Variant.iby)
 
+//caldav plugin
+../rom/caldav.iby 						CORE_APP_LAYER_IBY_EXPORT_PATH(caldav.iby)
 
 //stubsis is added to provide IAD
 ../stubsis/calendar_stub.sis   										/epoc32/data/z/system/install/calendar_stub.sis
@@ -132,4 +131,7 @@
 // Calendar aiw provider.
 #include "../calenaiwprovider/group/bld.inf"
 
+//caldav ecom plugin
+#include "../caldav/group/bld.inf"
+
 //EOF
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calendarui/rom/caldav.iby	Mon Jul 12 17:26:07 2010 +0100
@@ -0,0 +1,29 @@
+/*
+ * This component and the accompanying materials are made available
+ * under the terms of the License "Eclipse Public License v1.0"
+ * which accompanies this distribution, and is available
+ * at the URL "http://www.eclipse.org/legal/epl-v10.html".
+ *
+ * Initial Contributors:
+ * Maximilian Odendahl, Sun Microsystems, Inc.
+ *
+ * Contributors:
+ *
+ * Description: iby file to include Caldav into rom
+ * 
+ */
+
+
+
+#ifndef CALDAV_IBY
+#define CALDAV_IBY
+
+file=ABI_DIR\BUILD_DIR\CalDavClient.dll   	SHARED_LIB_DIR\CalDavClient.dll
+file=ABI_DIR\BUILD_DIR\!CalDavServer.exe	PROGRAMS_DIR\!CalDavServer.exe
+
+ECOM_PLUGIN( calencaldavplugin.dll , calencaldavplugin.rsc )
+
+
+#endif // CALDAV_IBY
+
+//  End of File
\ No newline at end of file