calendarengines/caldav/inc/httpclient.h
branchRCL_3
changeset 31 97232defd20e
equal deleted inserted replaced
30:bd7edf625bdd 31:97232defd20e
       
     1 /*
       
     2 * Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributor:
       
    10 * Maximilian Odendahl
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef HTTPCLIENT_H
       
    19 #define HTTPCLIENT_H
       
    20 
       
    21 #include <http\MHTTPAuthenticationCallback.h>
       
    22 #include <http\mhttptransactioncallback.h>
       
    23 #include <http\mhttpdatasupplier.h>
       
    24 
       
    25 #include <es_sock.h>
       
    26 #include <extendedconnpref.h>
       
    27 
       
    28 struct TCalDAVOptions;
       
    29 
       
    30 _LIT8(KHTTP200,"http/1.1 200 ok");
       
    31 _LIT8(KHTTP201,"http/1.1 201 created");
       
    32 _LIT8(KHTTP404,"http/1.1 404 not found");
       
    33 
       
    34 #define ERROR 			0
       
    35 #define OK				200
       
    36 #define CREATED 		201
       
    37 #define NOCONTENT		204
       
    38 #define MULTISTATUS		207
       
    39 #define MUTIPLECHOICES	300
       
    40 #define BADREQUEST		400
       
    41 #define FORBIDDEN		403
       
    42 #define NOTFOUND		404
       
    43 #define NOTALLOWED		405
       
    44 #define CONFLICT		409
       
    45 #define PRECONDFAILED 	412
       
    46 
       
    47 enum THttpAction
       
    48 	{
       
    49 	EActionUpload, EActionDelete, EActionOption, EActionNone
       
    50 	};
       
    51 
       
    52 class CHttpClient : public CBase,
       
    53 		public MHTTPDataSupplier,
       
    54 		public MHTTPAuthenticationCallback,
       
    55 		public MHTTPTransactionCallback
       
    56 	{
       
    57 public:
       
    58 	virtual ~CHttpClient();
       
    59 	static CHttpClient* NewLC();
       
    60 	static CHttpClient* NewL();
       
    61 
       
    62 	TInt PutL(const TDesC8 &aUrl, const TDesC8 &aICS, CBufFlat *aResponse,
       
    63 			const TDesC8 &aEtag = KNullDesC8);
       
    64 	TInt MkCalendarL(const TDesC8 &aUrl, const TDesC8 &aBody,
       
    65 			CBufFlat *aResponse);
       
    66 	TInt DeleteL(const TDesC8 &aUrl, const TDesC8 &aETag = KNullDesC8);
       
    67 	TInt HeadL(const TDesC8 &aUrl);
       
    68 	TInt GetL(const TDesC8 &aUrl, CBufFlat *aResponse);
       
    69 	TInt PropfindL(const TDesC8 &aUrl, const TDesC8 &aBodyRequest,
       
    70 			CBufFlat *aResponse, TBool depth0 = ETrue);
       
    71 	TInt ReportL(const TDesC8 &aUrl, const TDesC8 &aBodyRequest,
       
    72 			CBufFlat *aResponse);
       
    73 	TInt ProppatchL(const TDesC8 &aUrl, const TDesC8 &aBodyRequest,
       
    74 			CBufFlat *aResponse);
       
    75 
       
    76 	TInt GetServerOptionsL(const TDesC8 &aUrl, TCalDAVOptions &aOptions);
       
    77 
       
    78 	// methods inherited from MHTTPDataSupplier
       
    79 	virtual TBool GetNextDataPart(TPtrC8& aDataPart);
       
    80 	virtual void ReleaseData();
       
    81 	virtual TInt OverallDataSize();
       
    82 	virtual TInt Reset();
       
    83 
       
    84 	TInt ReturnCode();
       
    85 	TPtrC8 ETag();
       
    86 
       
    87 	//
       
    88 	// methods from MHTTPTransactionCallback
       
    89 	//
       
    90 	virtual void MHFRunL(RHTTPTransaction aTransaction,
       
    91 			const THTTPEvent& aEvent);
       
    92 	virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction,
       
    93 			const THTTPEvent& aEvent);
       
    94 	
       
    95 	// methods inherited from MHTTPAuthenticationCallback
       
    96 	virtual TBool GetCredentialsL(const TUriC8& aURI, RString aRealm,
       
    97 			RStringF aAuthenticationType, RString& aUsername,
       
    98 			RString& aPassword);
       
    99 
       
   100 	TPtrC8 User();
       
   101 	void SetUserL(const TDesC8 &aUser);
       
   102 
       
   103 	void SetPasswordL(const TDesC8 &aPassword);
       
   104 	TPtrC8 Password();
       
   105 
       
   106 protected:
       
   107 	CHttpClient();
       
   108 	void ConstructL();
       
   109 private:
       
   110 
       
   111 	void InvokeHttpMethodL(const TDesC8& aUri, RStringF aMethod);
       
   112 	void SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField,
       
   113 			const TDesC8& aHdrValue);
       
   114 	void SetHeaderL(RHTTPHeaders aHeaders, const TDesC8 &aField,
       
   115 			const TDesC8 &aValue);
       
   116 	void GetEtagHeaderL(RHTTPTransaction& aTransaction);
       
   117 
       
   118 	void GetPostBodyManuallyL();
       
   119 
       
   120 	void OpenSessionL();
       
   121 
       
   122 private:
       
   123 	RHTTPSession iSess;
       
   124 	RHTTPTransaction iTrans;
       
   125 	TParse iParsedFileName;
       
   126 	CBufFlat* iBodyResponse;
       
   127 	HBufC8* iBodyRequest;
       
   128 
       
   129 	RSocketServ iSocketServ;
       
   130 	RConnection iRConnection;
       
   131 	TConnPrefList iPrefList;
       
   132 	TExtendedConnPref iExtPrefs;
       
   133 
       
   134 	HBufC8 *iUser;
       
   135 	HBufC8 *iPassword;
       
   136 
       
   137 	TCalDAVOptions *iOptions;
       
   138 	THttpAction iAction;
       
   139 
       
   140 	TInt iReturnCode;
       
   141 	HBufC8* iEtag;
       
   142 	TInt iCredentialCount;
       
   143 
       
   144 	};
       
   145 
       
   146 #endif