2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Name : siphttpdigest.h
16 * Part of : SIP Client
17 * Interface : SDK API, SIP Client API
24 #ifndef CSIPHTTPDIGEST_H
25 #define CSIPHTTPDIGEST_H
30 // FORWARD DECLARATIONS
32 class MSIPHttpDigestChallengeObserver;
33 class MSIPHttpDigestChallengeObserver2;
34 class CSIPClientTransaction;
43 * Class for managing SIP HTTP Digest security settings.
44 * Class provides functions for setting/removing
45 * HTTP Digest security mechanism related parameters.
46 * If the user does not use the class for the providing credentials for the
47 * received challenges, an error will be returned to the original request in
48 * case it was challenged.
50 * Note that the user will be asked to provide credentials one realm
55 class CSIPHttpDigest : public CBase
57 public: // Constructors and destructor
60 * Two-phased constructor.
61 * @param aSIP a handle to SIP server
62 * @param aObserver an observer for the received challenges
63 * @return New object, ownership is transferred.
65 IMPORT_C static CSIPHttpDigest*
67 MSIPHttpDigestChallengeObserver& aObserver);
70 * Two-phased constructor.
71 * @param aSIP a handle to SIP server
72 * @param aObserver an observer for the received challenges
73 * @return New object, ownership is transferred.
75 IMPORT_C static CSIPHttpDigest*
77 MSIPHttpDigestChallengeObserver& aObserver);
80 * Two-phased constructor.
81 * @param aSIP a handle to SIP server
82 * @param aObserver2 an observer for the received challenges
83 * @return New object, ownership is transferred.
85 IMPORT_C static CSIPHttpDigest*
87 MSIPHttpDigestChallengeObserver2& aObserver2);
90 * Two-phased constructor.
91 * @param aSIP a handle to SIP server
92 * @param aObserver2 an observer for the received challenges
93 * @return New object, ownership is transferred.
95 IMPORT_C static CSIPHttpDigest*
97 MSIPHttpDigestChallengeObserver2& aObserver2);
99 IMPORT_C ~CSIPHttpDigest();
101 public: // New functions
104 * Sets credentials for the realm of the outbound proxy.
105 * Must be used in case the realm is the realm of the outbound proxy and
106 * the request for credentials was received from callback
107 * MSIPHttpDigestChallengeObserver::ChallengeReceived.
108 * The user can set credentials only upon request from the
109 * SIP implementation.
110 * @pre aOutboundProxy, aRealm, aUsername and aPasswd must not be empty
112 * @param aOutboundProxy an outbound proxy (FQDN or IP address)
113 * @param aRealm servers's realm
114 * @param aUsername user's name
115 * @param aPasswd user's password for the given server's realm
116 * @leave KErrNoMemory if out of memory
117 * @leave KErrArgument if some of the parameters is an empty descriptor
118 * @leave KErrSIPResourceNotAvailable if a required object has been
121 IMPORT_C void SetCredentialsL(const TDesC8& aOutboundProxy,
122 const TDesC8& aRealm,
123 const TDesC8& aUsername,
124 const TDesC8& aPasswd);
126 * Sets parameters for the realm.
127 * Should be used in case the realm is not a realm of an outbound proxy
128 * and the request for credentials was received from callback
129 * MSIPHttpDigestChallengeObserver::ChallengeReceived.
130 * The user can set credentials only upon request from the
131 * SIP implementation.
132 * @pre aRealm, aUsername and aPasswd must not be empty descriptors.
133 * @param aRealm servers's realm
134 * @param aUsername user's name
135 * @param aPasswd user's password for the given server's realm
136 * @leave KErrNoMemory if out of memory
137 * @leave KErrArgument if some of the parameters is an empty descriptor
138 * @leave KErrSIPResourceNotAvailable if a required object has been
141 IMPORT_C void SetCredentialsL(const TDesC8& aRealm,
142 const TDesC8& aUsername,
143 const TDesC8& aPasswd);
146 * Sets credentials for the realm for the specific transaction.
147 * Must be used when the request for credentials was received
148 * from callback MSIPHttpDigestChallengeObserver2::ChallengeReceived with
149 * CSIPClientTransaction as the parameter.
150 * @pre aRealm, aUsername and aPasswd must not be empty descriptors.
151 * @param aTransaction the transaction that was passed as a parameter
152 * to MSIPHttpDigestChallengeObserver2::ChallengeReceived
153 * @param aOutboundProxy an outbound proxy (FQDN or IP address) if
154 * the challenge received had Proxy-Authenticate-header(s).
155 * Otherwise KNullDesC8 should passed.
156 * @param aRealm servers's realm
157 * @param aUsername user's name
158 * @param aPasswd user's password for the given server's realm
159 * @leave KErrNoMemory if out of memory
160 * @leave KErrArgument if some of the parameters is an empty descriptor
161 * @leave KErrSIPResourceNotAvailable if a required object has been
164 IMPORT_C void SetCredentialsL(const CSIPClientTransaction& aTransaction,
165 const TDesC8& aOutboundProxy,
166 const TDesC8& aRealm,
167 const TDesC8& aUsername,
168 const TDesC8& aPasswd);
171 * Sets credentials for the realm for the specific refresh.
172 * Must be used when the request for credentials was received
173 * from callback MSIPHttpDigestChallengeObserver2::ChallengeReceived with
174 * CSIPRefresh as the parameter.
175 * @pre aRealm, aUsername and aPasswd must not be empty descriptors.
176 * @param aRefresh the refresh that was passed as a parameter
177 * to MSIPHttpDigestChallengeObserver2::ChallengeReceived
178 * @param aOutboundProxy an outbound proxy (FQDN or IP address) if
179 * the challenge received had Proxy-Authenticate-header(s).
180 * Otherwise KNullDesC8 should passed.
181 * @param aRealm servers's realm
182 * @param aUsername user's name
183 * @param aPasswd user's password for the given server's realm
184 * @leave KErrNoMemory if out of memory
185 * @leave KErrArgument if some of the parameters is an empty descriptor
186 * @leave KErrSIPResourceNotAvailable if a required object has been
189 IMPORT_C void SetCredentialsL(const CSIPRefresh& aRefresh,
190 const TDesC8& aOutboundProxy,
191 const TDesC8& aRealm,
192 const TDesC8& aUsername,
193 const TDesC8& aPasswd);
196 * Removes all set credentials for the realm.
197 * Must not be used if the user implements
198 * MSIPHttpDigestChallengeObserver2.
199 * @pre aRealm must not be an empty descriptor
200 * @param aRealm servers's realm
201 * @return KErrNone if no error
202 * KErrArgument if aRealm is an empty descriptor
203 * KErrNoMemory if out of memory
204 * KErrNotFound if the given realm was not found
206 IMPORT_C TInt RemoveCredentials(const TDesC8& aRealm);
209 * Removes all set credentials by the user.
210 * Must not be used if the user implements
211 * MSIPHttpDigestChallengeObserver2.
212 * @return KErrNone if succesful; KErrNoMemory if out of memory
214 IMPORT_C TInt RemoveCredentials();
217 * Sets the observer to listen for the possible received challenges.
218 * Replaces the existing MSIPHttpDigestChallengeObserver or
219 * MSIPHttpDigestChallengeObserver2.
220 * @param aObserver an observer for the received challenges.
222 IMPORT_C void SetObserver(MSIPHttpDigestChallengeObserver& aObserver);
225 * Sets the observer to listen for the possible received challenges.
226 * Replaces the existing MSIPHttpDigestChallengeObserver or
227 * MSIPHttpDigestChallengeObserver2.
228 * @param aObserver an observer for the received challenges.
230 IMPORT_C void SetObserver(MSIPHttpDigestChallengeObserver2& aObserver);
233 * Ignores the challenge for the realm. As a result the error will be
234 * generated to the original SIP request.
235 * @pre aRealm must not be an empty descriptor
236 * @param aRealm a realm for which the challenge was ignored
237 * @return KErrNone if no error
238 * KErrNotFound if the given realm was not found
239 * KErrArgument if aRealm is an empty descriptor
241 IMPORT_C TInt IgnoreChallenge(const TDesC8& aRealm);
244 * Ignores the challenge for the realm for the specific transaction.
245 * As a result KErrForbidden will be generated
246 * to the original SIP request.
247 * @pre aRealm must not be an empty descriptor
248 * @param aTransaction the transaction that was passed as a parameter
249 * to MSIPHttpDigestChallengeObserver2::ChallengeReceived
250 * @param aRealm a realm for which the challenge was ignored
251 * @return KErrNone if no error
252 * KErrNotFound if the given realm was not found
253 * KErrArgument if aRealm is an empty descriptor
255 IMPORT_C TInt IgnoreChallenge(const CSIPClientTransaction& aTransaction,
256 const TDesC8& aRealm);
259 * Ignores the challenge for the realm for the specific refresh.
260 * As a result the error will be generated
261 * to the original SIP request.
262 * @pre aRealm must not be an empty descriptor
263 * @param aRefresh the refresh that was passed as a parameter
264 * to MSIPHttpDigestChallengeObserver2::ChallengeReceived
265 * @param aRealm a realm for which the challenge was ignored
266 * @return KErrNone if no error
267 * KErrNotFound if the given realm was not found
268 * KErrArgument if aRealm is an empty descriptor
270 IMPORT_C TInt IgnoreChallenge(const CSIPRefresh& aRefresh,
271 const TDesC8& aRealm);
273 public: // New functions, for internal use
277 private: // Constructors
279 CSIPHttpDigest(CSIP& aSIP);
280 CSIPHttpDigest(const CSIPHttpDigest& aHttpDigest);
281 CSIPHttpDigest& operator=(const CSIPHttpDigest& aHttpDigest);
283 void ConstructL(MSIPHttpDigestChallengeObserver& aObserver);
285 void ConstructL(MSIPHttpDigestChallengeObserver2& aObserver2);
287 private: // New functions
289 TInt RemoveCredentialParams(const TDesC8& aRealm) const;
291 void SetCredentialParamsL(TUint32 aRequestId,
293 const TDesC8& aOutboundProxy,
294 const TDesC8& aRealm,
295 const TDesC8& aUsername,
296 const TDesC8& aPasswd) const;
298 TInt IgnoreChallenge(TUint32 aRequestId,
300 const TDesC8& aRealm);
306 private: // For testing purposes
308 friend class CSIP_Test;
312 #endif // CSIPHTTPDIGEST_H