realtimenetprots/sipfw/SIP/sipapi/src/siphttpdigest.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name          : SIPHttpDigest.cpp
       
    15 // Part of       : SIP API
       
    16 // Version       : SIP/5.0
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include <badesca.h>
       
    22 #include "siperr.h"
       
    23 #include "sip.h"
       
    24 #include "SipImplementation.h"
       
    25 #include "sipclient.h"
       
    26 #include "siphttpdigest.h"
       
    27 #include "sipclienttransaction.h"
       
    28 #include "siprefresh.h"
       
    29 
       
    30 #ifdef CPPUNIT_TEST
       
    31 
       
    32 #include "TestCleanupStack.h"
       
    33 
       
    34 #endif
       
    35 
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CSIPHttpDigest::NewL
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 EXPORT_C CSIPHttpDigest*
       
    42 CSIPHttpDigest::NewL(CSIP& aSIP, MSIPHttpDigestChallengeObserver& aObserver)
       
    43     {
       
    44     CSIPHttpDigest* self = CSIPHttpDigest::NewLC(aSIP, aObserver);
       
    45     CleanupStack::Pop(self);
       
    46     return self;
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CSIPHttpDigest::NewLC
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 EXPORT_C CSIPHttpDigest*
       
    54 CSIPHttpDigest::NewLC(CSIP& aSIP, MSIPHttpDigestChallengeObserver& aObserver)
       
    55     {
       
    56     CSIPHttpDigest* self = new (ELeave) CSIPHttpDigest(aSIP);
       
    57     CleanupStack::PushL(self);
       
    58     self->ConstructL(aObserver);
       
    59     return self;
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CSIPHttpDigest::NewL
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 EXPORT_C CSIPHttpDigest*
       
    67 CSIPHttpDigest::NewL(CSIP& aSIP, MSIPHttpDigestChallengeObserver2& aObserver2)
       
    68     {
       
    69     CSIPHttpDigest* self = CSIPHttpDigest::NewLC(aSIP, aObserver2);
       
    70     CleanupStack::Pop(self);
       
    71     return self;
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CSIPHttpDigest::NewLC
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 EXPORT_C CSIPHttpDigest*
       
    79 CSIPHttpDigest::NewLC(CSIP& aSIP, MSIPHttpDigestChallengeObserver2& aObserver2)
       
    80     {
       
    81     CSIPHttpDigest* self = new (ELeave) CSIPHttpDigest(aSIP);
       
    82     CleanupStack::PushL(self);
       
    83     self->ConstructL(aObserver2);
       
    84     return self;
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CSIPHttpDigest::CSIPHttpDigest
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 CSIPHttpDigest::CSIPHttpDigest(CSIP& aSIP) : iSIP(&aSIP)
       
    92 	{
       
    93 	}
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CSIPHttpDigest::ConstructL
       
    97 // -----------------------------------------------------------------------------
       
    98 //	
       
    99 void CSIPHttpDigest::ConstructL(MSIPHttpDigestChallengeObserver& aObserver)
       
   100 	{
       
   101 	TInt err =
       
   102 		iSIP->Implementation().SIPClient().SetHttpDigestObserver(aObserver);
       
   103 	if (err != KErrNone)
       
   104 		{
       
   105 		User::Leave(err);
       
   106 		}
       
   107 
       
   108 	iSIP->Implementation().AddDigestL(*this);
       
   109 	}
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CSIPHttpDigest::ConstructL
       
   113 // -----------------------------------------------------------------------------
       
   114 //	
       
   115 void CSIPHttpDigest::ConstructL(MSIPHttpDigestChallengeObserver2& aObserver2)
       
   116 	{
       
   117 	TInt err =
       
   118 		iSIP->Implementation().SIPClient().SetHttpDigestObserver(aObserver2);
       
   119 	if (err != KErrNone)
       
   120 		{
       
   121 		User::Leave(err);
       
   122 		}
       
   123 		
       
   124 	iSIP->Implementation().AddDigestL(*this);
       
   125 	}
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CSIPHttpDigest::~CSIPHttpDigest
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 EXPORT_C CSIPHttpDigest::~CSIPHttpDigest()
       
   132 	{
       
   133 	if (iSIP)
       
   134 		{
       
   135 		iSIP->Implementation().SIPClient().RemoveHttpDigestObserver();
       
   136 		iSIP->Implementation().RemoveDigest(*this);
       
   137 		}
       
   138 	}
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CSIPHttpDigest::operator=
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 CSIPHttpDigest& CSIPHttpDigest::operator=(const CSIPHttpDigest& /*aHttpDigest*/)
       
   145     {
       
   146 	//lint -e1529, -e1745
       
   147     return *this;
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CSIPHttpDigest::SetCredentialsL
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 EXPORT_C void CSIPHttpDigest::SetCredentialsL(const TDesC8& aOutboundProxy,
       
   155 				                              const TDesC8& aRealm,
       
   156 			                          		  const TDesC8& aUsername,
       
   157 			                          		  const TDesC8& aPasswd)
       
   158     {
       
   159     __ASSERT_ALWAYS(aOutboundProxy.Length() > 0, User::Leave(KErrArgument));
       
   160 
       
   161     SetCredentialParamsL(0, 0, aOutboundProxy, aRealm, aUsername, aPasswd);    
       
   162     }
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CSIPHttpDigest::SetCredentialsL
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 EXPORT_C void CSIPHttpDigest::SetCredentialsL(const TDesC8& aRealm,
       
   169 			                           		  const TDesC8& aUsername,
       
   170 			                          		  const TDesC8& aPasswd)
       
   171 	{
       
   172 	SetCredentialParamsL(0, 0, KNullDesC8, aRealm, aUsername, aPasswd);	
       
   173 	}
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // CSIPHttpDigest::SetCredentialsL
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 EXPORT_C void CSIPHttpDigest::SetCredentialsL(
       
   180     const CSIPClientTransaction& aTransaction,
       
   181     const TDesC8& aOutboundProxy,
       
   182     const TDesC8& aRealm,
       
   183     const TDesC8& aUsername,
       
   184     const TDesC8& aPasswd)
       
   185     {
       
   186     SetCredentialParamsL(aTransaction.RequestId(), 0, aOutboundProxy, 
       
   187                          aRealm, aUsername, aPasswd);
       
   188     }
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CSIPHttpDigest::SetCredentialsL
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 EXPORT_C void CSIPHttpDigest::SetCredentialsL(
       
   195     const CSIPRefresh& aRefresh,
       
   196     const TDesC8& aOutboundProxy,
       
   197     const TDesC8& aRealm,
       
   198     const TDesC8& aUsername,
       
   199     const TDesC8& aPasswd)
       
   200     {
       
   201     SetCredentialParamsL(0, aRefresh.RefreshId(), aOutboundProxy, 
       
   202                          aRealm, aUsername, aPasswd);
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CSIPHttpDigest::RemoveCredentials
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 EXPORT_C TInt CSIPHttpDigest::RemoveCredentials(const TDesC8& aRealm)
       
   210 	{
       
   211 	if (aRealm.Length() == 0)
       
   212 		{
       
   213 		return KErrArgument;
       
   214 		}
       
   215 
       
   216 	return RemoveCredentialParams(aRealm);    
       
   217     }
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CSIPHttpDigest::RemoveCredentials
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 EXPORT_C TInt CSIPHttpDigest::RemoveCredentials()
       
   224 	{
       
   225 	return RemoveCredentialParams(KNullDesC8);
       
   226 	}
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // CSIPHttpDigest::RemoveCredentialParams
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 TInt CSIPHttpDigest::RemoveCredentialParams(const TDesC8& aRealm) const
       
   233 	{
       
   234     if (iSIP)
       
   235 		{
       
   236 		return iSIP->Implementation().SIPClient().RemoveCredentials(aRealm);
       
   237 		}
       
   238 
       
   239 	return KErrSIPResourceNotAvailable;
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CSIPHttpDigest::SetObserver
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 EXPORT_C void CSIPHttpDigest::SetObserver(
       
   247     MSIPHttpDigestChallengeObserver& aObserver)
       
   248 	{
       
   249 	if (iSIP)
       
   250 		{
       
   251 		iSIP->Implementation().SIPClient().SetHttpDigestObserver(aObserver);
       
   252 		}
       
   253 	}
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CSIPHttpDigest::SetObserver
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 EXPORT_C void CSIPHttpDigest::SetObserver(
       
   260     MSIPHttpDigestChallengeObserver2& aObserver)
       
   261 	{
       
   262 	if (iSIP)
       
   263 		{
       
   264 		iSIP->Implementation().SIPClient().SetHttpDigestObserver(aObserver);
       
   265 		}
       
   266 	}
       
   267 		
       
   268 // -----------------------------------------------------------------------------
       
   269 // CSIPHttpDigest::IgnoreChallenge
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 EXPORT_C TInt CSIPHttpDigest::IgnoreChallenge(const TDesC8& aRealm)
       
   273 	{
       
   274 	return IgnoreChallenge(0,0,aRealm);
       
   275 	}
       
   276 	
       
   277 // -----------------------------------------------------------------------------
       
   278 // CSIPHttpDigest::IgnoreChallenge
       
   279 // -----------------------------------------------------------------------------
       
   280 //
       
   281 EXPORT_C TInt CSIPHttpDigest::IgnoreChallenge(
       
   282     const CSIPClientTransaction& aTransaction,
       
   283     const TDesC8& aRealm)
       
   284     {
       
   285     return IgnoreChallenge(aTransaction.RequestId(),0,aRealm);
       
   286     }
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // CSIPHttpDigest::IgnoreChallenge
       
   290 // -----------------------------------------------------------------------------
       
   291 //
       
   292 EXPORT_C TInt CSIPHttpDigest::IgnoreChallenge(
       
   293     const CSIPRefresh& aRefresh,
       
   294     const TDesC8& aRealm)
       
   295     {
       
   296     return IgnoreChallenge(0,aRefresh.RefreshId(),aRealm);
       
   297     }
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // CSIPHttpDigest::CSIPDeleted
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 void CSIPHttpDigest::CSIPDeleted()
       
   304 	{
       
   305 	iSIP = NULL;
       
   306 	}
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // CSIPHttpDigest::SetCredentialParamsL
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 void CSIPHttpDigest::SetCredentialParamsL(TUint32 aRequestId,
       
   313                                           TUint32 aRefreshId,
       
   314                                           const TDesC8& aOutboundProxy,
       
   315                                           const TDesC8& aRealm,
       
   316 				                          const TDesC8& aUsername,
       
   317 				                          const TDesC8& aPasswd) const
       
   318 	{
       
   319 	__ASSERT_ALWAYS(aRealm.Length() > 0 &&
       
   320 					aUsername.Length() > 0 &&
       
   321 					aPasswd.Length() > 0, User::Leave(KErrArgument));
       
   322 	if (!iSIP)
       
   323 		{
       
   324 		User::Leave(KErrSIPResourceNotAvailable);
       
   325 		}
       
   326 	
       
   327 	iSIP->Implementation().SIPClient().SetCredentialsL(aRequestId,
       
   328 	                                                   aRefreshId,
       
   329 	                                                   aRealm,
       
   330 		             								   aUsername,
       
   331 		             								   aPasswd,
       
   332 		             								   aOutboundProxy);
       
   333 	}
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 // CSIPHttpDigest::IgnoreChallenge
       
   337 // -----------------------------------------------------------------------------
       
   338 //	
       
   339 TInt CSIPHttpDigest::IgnoreChallenge(
       
   340     TUint32 aRequestId,
       
   341     TUint32 aRefreshId,
       
   342     const TDesC8& aRealm)
       
   343     {
       
   344 	if (aRealm.Length() == 0)
       
   345 		{
       
   346 		return KErrArgument;
       
   347 		}
       
   348 
       
   349 	if (iSIP)
       
   350 		{
       
   351 		return iSIP->Implementation().SIPClient().IgnoreChallenge(aRequestId,
       
   352 		                                                          aRefreshId,
       
   353 		                                                          aRealm);
       
   354 		}
       
   355 
       
   356 	return KErrSIPResourceNotAvailable;
       
   357     }