ncdengine/provider/server/src/ncdhttputils.cpp
changeset 4 32704c33136d
equal deleted inserted replaced
-1:000000000000 4:32704c33136d
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation 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 Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncdhttputils.h"
       
    20 #include "ncdconnectionmethod.h"
       
    21 
       
    22 #include "catalogsdebug.h"
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 // 
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 CNcdHttpUtils::CNcdHttpUtils(         
       
    29     MCatalogsAccessPointManager& aAccessPointManager ) : 
       
    30     iAccessPointManager( aAccessPointManager )
       
    31     {    
       
    32     }
       
    33     
       
    34     
       
    35 // ---------------------------------------------------------------------------
       
    36 // 
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 void CNcdHttpUtils::CreateTransactionL( 
       
    40     MCatalogsHttpSession& aSession,
       
    41     MCatalogsHttpOperation*& aOperation,
       
    42     const TDesC& aUri,
       
    43     MCatalogsHttpObserver& aObserver,
       
    44     const TDesC8& aBody )
       
    45     {
       
    46     DLTRACEIN((""));
       
    47     if ( aOperation ) 
       
    48         {
       
    49         aOperation->Release();
       
    50         aOperation = NULL;
       
    51         }
       
    52     
       
    53     aOperation = aSession.CreateTransactionL( 
       
    54         aUri,
       
    55         &aObserver );
       
    56                 
       
    57     aOperation->SetBodyL( aBody );    
       
    58     
       
    59     // Try to get and set fixed AP
       
    60     TUint32 ap = 0;
       
    61     iAccessPointManager.GetFixedApL( ap );
       
    62     if ( ap ) 
       
    63         {
       
    64         SetAccessPoint( *aOperation, KErrNone, ap );
       
    65         }
       
    66     }
       
    67     
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // 
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 void CNcdHttpUtils::CreateTransactionL( 
       
    74     MCatalogsHttpSession& aSession,
       
    75     MCatalogsHttpOperation*& aOperation,
       
    76     const TDesC& aUri,
       
    77     MCatalogsHttpObserver& aObserver,
       
    78     const TDesC8& aBody,
       
    79     const TDesC& aNamespace,
       
    80     const MCatalogsAccessPointManager::TAction& aAction, 
       
    81     const TUid& aClientUid )
       
    82     {
       
    83     DLTRACEIN((""));
       
    84     CreateTransactionL( aSession, aOperation, aUri, aObserver, aBody );
       
    85     
       
    86     TUint32 ap = 0;
       
    87     TInt error = iAccessPointManager.AccessPointIdL(
       
    88         aNamespace, 
       
    89         aAction, 
       
    90         aClientUid, 
       
    91         ap );
       
    92 
       
    93     SetAccessPoint( *aOperation, error, ap );
       
    94     }
       
    95 
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // 
       
    99 // ---------------------------------------------------------------------------
       
   100 //
       
   101 void CNcdHttpUtils::CreateTransactionL( 
       
   102     MCatalogsHttpSession& aSession,
       
   103     MCatalogsHttpOperation*& aOperation,
       
   104     const TDesC& aUri,
       
   105     MCatalogsHttpObserver& aObserver,
       
   106     const TDesC8& aBody,
       
   107     const TDesC& aNamespace,
       
   108     const TDesC& aCatalogId,
       
   109     const MCatalogsAccessPointManager::TAction& aAction, 
       
   110     const TUid& aClientUid )
       
   111     {
       
   112     DLTRACEIN((""));
       
   113     CreateTransactionL( aSession, aOperation, aUri, aObserver, aBody );
       
   114     
       
   115     TUint32 ap = 0;
       
   116     TInt error = iAccessPointManager.AccessPointIdL(
       
   117         aNamespace, 
       
   118         aCatalogId,
       
   119         aAction, 
       
   120         aClientUid, 
       
   121         ap );
       
   122 
       
   123     SetAccessPoint( *aOperation, error, ap );
       
   124 
       
   125     }
       
   126 
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // 
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 void CNcdHttpUtils::CreateTransactionL( 
       
   133     MCatalogsHttpSession& aSession,
       
   134     MCatalogsHttpOperation*& aOperation,
       
   135     const TDesC& aUri,
       
   136     MCatalogsHttpObserver& aObserver,
       
   137     const TDesC8& aBody,
       
   138     const CNcdNodeIdentifier& aNodeIdentifier,
       
   139     const MCatalogsAccessPointManager::TAction& aAction, 
       
   140     const TUid& aClientUid )
       
   141     {
       
   142     DLTRACEIN((""));
       
   143     CreateTransactionL( aSession, aOperation, aUri, aObserver, aBody );
       
   144     
       
   145     TUint32 ap = 0;
       
   146     TInt error = iAccessPointManager.AccessPointIdL(
       
   147         aNodeIdentifier, 
       
   148         aAction, 
       
   149         aClientUid, 
       
   150         ap );
       
   151 
       
   152     SetAccessPoint( *aOperation, error, ap );
       
   153     }
       
   154 
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // Set access point
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 void CNcdHttpUtils::CreateTransactionL( 
       
   161     MCatalogsHttpSession& aSession,
       
   162     MCatalogsHttpOperation*& aOperation,
       
   163     const TDesC& aUri,
       
   164     MCatalogsHttpObserver& aObserver,
       
   165     const TDesC8& aBody,
       
   166     const CNcdNodeIdentifier& aNodeIdentifier,
       
   167     const CNcdNodeIdentifier& aBackupNodeIdentifier,
       
   168     const MCatalogsAccessPointManager::TAction& aAction, 
       
   169     const TUid& aClientUid )
       
   170     {
       
   171     DLTRACEIN((""));
       
   172     CreateTransactionL( aSession, aOperation, aUri, aObserver, aBody );
       
   173     
       
   174     TUint32 ap = 0;
       
   175     TInt error = iAccessPointManager.AccessPointIdL(
       
   176         aNodeIdentifier, 
       
   177         aAction, 
       
   178         aClientUid, 
       
   179         ap );
       
   180 
       
   181     if ( error != KErrNone ) 
       
   182         {
       
   183         DLTRACE(("First node id failed, try backup"));
       
   184         ap = 0;
       
   185         error = iAccessPointManager.AccessPointIdL(
       
   186             aBackupNodeIdentifier, 
       
   187             aAction, 
       
   188             aClientUid, 
       
   189             ap );
       
   190         }
       
   191     SetAccessPoint( *aOperation, error, ap );
       
   192     }
       
   193 
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // 
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 void CNcdHttpUtils::ConvertConnectionMethod(
       
   200     const TNcdConnectionMethod& aSource,
       
   201     TCatalogsConnectionMethod& aTarget ) const
       
   202     {
       
   203     aTarget = TCatalogsConnectionMethod( 
       
   204         aSource.iId,
       
   205         static_cast<TCatalogsConnectionMethodType>( aSource.iType ) );
       
   206     }
       
   207 
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // Set access point
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 void CNcdHttpUtils::SetAccessPoint(
       
   214     MCatalogsHttpOperation& aOperation,
       
   215     TInt aError,
       
   216     TUint32 aAp ) 
       
   217     {
       
   218     if ( aError == KErrNone ) 
       
   219         {
       
   220         DLTRACE(("Setting accesspoint id"));        
       
   221         TCatalogsConnectionMethod method( 
       
   222             aAp, 
       
   223             ECatalogsConnectionMethodTypeAccessPoint );
       
   224     
       
   225         aOperation.Config().SetConnectionMethod( method );
       
   226         }    
       
   227     }
       
   228 
       
   229