applicationmanagement/server/src/AMSmlHelper.cpp
changeset 42 aa33c2cb9a50
equal deleted inserted replaced
41:c742e1129640 42:aa33c2cb9a50
       
     1 /*
       
     2  * Copyright (c) 2000 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: Implementation of applicationmanagement components
       
    15  *
       
    16  */
       
    17 
       
    18 
       
    19 #include <SyncMLClientDM.h>
       
    20 #include <rconnmon.h> 
       
    21 #include "amsmlhelper.h"
       
    22 #include "debug.h"
       
    23 
       
    24 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    25 #include <es_sock.h>
       
    26 #else
       
    27 #include <es_sock.h>
       
    28 #include <es_enum_internal.h>
       
    29 #include <es_sock_partner.h>
       
    30 #endif
       
    31 #include <es_enum.h>
       
    32 
       
    33 const TUid KUidNSmlMediumTypeInternet =
       
    34     {
       
    35     0x101F99F0
       
    36     };
       
    37 const TUid KSosServerUid =
       
    38     {
       
    39     0x101F99FB
       
    40     };
       
    41 
       
    42 const TInt KBufSize32 = 32;
       
    43 
       
    44 using namespace NApplicationManagement;
       
    45 
       
    46 /*
       
    47  void CApplicationManagementServer::StartDMSessionL( )
       
    48  {
       
    49  RSyncMLSession ses;
       
    50  ses.OpenL() ;
       
    51  
       
    52  CleanupClosePushL( ses );
       
    53  TSmlJobId jid;
       
    54  TSmlUsageType jtype;
       
    55  ses.CurrentJobL(jid, jtype );
       
    56  RSyncMLDevManJob job;
       
    57  job.OpenL( ses, jid );
       
    58  CleanupClosePushL( job ) ;
       
    59  TSmlProfileId pid( job.Profile() );
       
    60  RSyncMLDevManProfile prof;
       
    61  prof.OpenL( ses, pid, ESmlOpenRead );
       
    62  
       
    63  TBuf<64> serverid;
       
    64  serverid.Copy( prof.ServerId()) ;
       
    65  prof.Close();
       
    66  
       
    67  CleanupStack::PopAndDestroy( &job )	;
       
    68  CleanupStack::PopAndDestroy( &ses )	;
       
    69  }
       
    70  */
       
    71 
       
    72 TInt SmlHelper::GetCurrentProfileIdL(TSmlProfileId &aProfile)
       
    73     {
       
    74     RSyncMLSession ses;
       
    75     ses.OpenL() ;
       
    76     CleanupClosePushL(ses);
       
    77     TSmlJobId jid;
       
    78     TSmlUsageType jtype;
       
    79     ses.CurrentJobL(jid, jtype);
       
    80     RSyncMLDevManJob job;
       
    81     job.OpenL(ses, jid);
       
    82     CleanupClosePushL(job) ;
       
    83     TSmlProfileId pid(job.Profile() );
       
    84     aProfile = pid;
       
    85 
       
    86     CleanupStack::PopAndDestroy( &job) ;
       
    87     CleanupStack::PopAndDestroy( &ses) ;
       
    88     return 0;
       
    89     }
       
    90 
       
    91 HBufC8* SmlHelper::GetCurrentServerIDL()
       
    92     {
       
    93     HBufC8 *serverid;
       
    94     //TBufC<256> serverid;
       
    95     RSyncMLSession ses;
       
    96     ses.OpenL() ;
       
    97     CleanupClosePushL(ses);
       
    98     TSmlJobId jid;
       
    99     TSmlUsageType jtype;
       
   100     ses.CurrentJobL(jid, jtype);
       
   101     RSyncMLDevManJob job;
       
   102     job.OpenL(ses, jid);
       
   103     CleanupClosePushL(job) ;
       
   104     TSmlProfileId pid(job.Profile() );
       
   105     //aProfile = pid;
       
   106     RSyncMLDevManProfile syncProfile;
       
   107     syncProfile.OpenL(ses, pid);
       
   108     RDEBUG("	5/8");
       
   109     CleanupClosePushL(syncProfile);
       
   110 
       
   111     serverid = syncProfile.ServerId().AllocLC();
       
   112 
       
   113     CleanupStack::Pop(); // serverid
       
   114 
       
   115     CleanupStack::PopAndDestroy( &syncProfile);
       
   116     CleanupStack::PopAndDestroy( &job) ;
       
   117     CleanupStack::PopAndDestroy( &ses) ;
       
   118 
       
   119     return serverid;
       
   120     }
       
   121 
       
   122 TInt SmlHelper::LaunchSessionL(TSmlProfileId &aProfile)
       
   123     {
       
   124     if (aProfile > -1)
       
   125         {
       
   126         RSyncMLSession syncSession;
       
   127         RSyncMLConnection conn;
       
   128         RSyncMLDevManJob dmJob;
       
   129         RSyncMLDevManProfile dmProfile;
       
   130 
       
   131         //TSmlProfileId id ;
       
   132         TSmlConnectionId cid;
       
   133         syncSession.OpenL();
       
   134         CleanupClosePushL(syncSession);
       
   135 
       
   136         TRAPD( err, dmProfile.OpenL( syncSession, aProfile, ESmlOpenRead ) )
       
   137         if (err == KErrNone)
       
   138             {
       
   139             CleanupClosePushL(dmProfile);
       
   140             conn.OpenL(dmProfile, KUidNSmlMediumTypeInternet.iUid);
       
   141             CleanupStack::PopAndDestroy( &dmProfile) ;
       
   142 #ifdef __TARM_SYMBIAN_CONVERGENCY
       
   143             cid = conn.Identifier();
       
   144 #else
       
   145             cid = conn.ConnectionId();
       
   146 #endif
       
   147             conn.Close();
       
   148             dmJob.CreateL(syncSession, aProfile, cid);
       
   149             dmJob.Close();
       
   150             }
       
   151         CleanupStack::PopAndDestroy( &syncSession) ; //
       
   152         return err;
       
   153         }
       
   154     else
       
   155         {
       
   156         return KErrArgument;
       
   157         }
       
   158     }
       
   159 
       
   160 void SmlHelper::GetDefaultIAPFromDMProfileL(TInt& aDefaultIAP)
       
   161     {
       
   162     RDEBUG("ApplicationManagementServer::GetDefaultIAPFromDMProfileL() - start");
       
   163 
       
   164     // first try to obtain the current profile id
       
   165     RSyncMLSession ses;
       
   166     ses.OpenL();
       
   167     RDEBUG("	1/8");
       
   168     CleanupClosePushL(ses);
       
   169 
       
   170     TSmlJobId jid;
       
   171     TSmlUsageType jtype;
       
   172     ses.CurrentJobL(jid, jtype);
       
   173     RDEBUG("	2/8");
       
   174     RSyncMLDevManJob job;
       
   175     job.OpenL(ses, jid);
       
   176     RDEBUG("	3/8");
       
   177     CleanupClosePushL(job);
       
   178     // get profile id
       
   179     TSmlProfileId pid(job.Profile() );
       
   180     CleanupStack::PopAndDestroy( &job);
       
   181 
       
   182     TBuf8<KBufSize32> key;
       
   183     TBuf<KBufSize32> value;
       
   184     TInt num = KErrNotFound;
       
   185 
       
   186     // get connection property name first
       
   187     GetConnectionPropertyNameL(ses, key, EPropertyIntenetAccessPoint);
       
   188     RDEBUG("	4/8");
       
   189     // we need to open sync profile in ordere to open the RSyncMLConnection
       
   190     RSyncMLDevManProfile syncProfile;
       
   191     syncProfile.OpenL(ses, pid);
       
   192     RDEBUG("	5/8");
       
   193     CleanupClosePushL(syncProfile);
       
   194 
       
   195     TSmlTransportId transport;
       
   196     RArray<TSmlTransportId> connections;
       
   197     _LIT8( KNSmlIAPId, "NSmlIapId" );
       
   198 
       
   199     // now open the syncML connection
       
   200     RSyncMLConnection syncConnection;
       
   201     syncProfile.ListConnectionsL(connections);
       
   202 
       
   203     transport = connections[0];
       
   204     syncConnection.OpenL(syncProfile, transport);
       
   205     RDEBUG("	6/8");
       
   206     CleanupClosePushL(syncConnection);
       
   207 
       
   208     const TDesC8& source(syncConnection.GetPropertyL(KNSmlIAPId) );
       
   209     RDEBUG("	7/8");
       
   210     value.Copy(source.Left(value.MaxLength() ) );
       
   211     User::LeaveIfError(StrToInt(value, num) );
       
   212     RDEBUG("	8/8");
       
   213 
       
   214     aDefaultIAP = num;
       
   215 
       
   216     // If there is no default Access point in DM profile then use
       
   217     // currently used access point by DM session
       
   218 
       
   219     if (aDefaultIAP == -2)
       
   220         {
       
   221 
       
   222         TInt sockIapid = -1;
       
   223 
       
   224         RSocketServ serv;
       
   225         CleanupClosePushL(serv);
       
   226         User::LeaveIfError(serv.Connect() );
       
   227 
       
   228         RConnection conn;
       
   229         CleanupClosePushL(conn);
       
   230         User::LeaveIfError(conn.Open(serv) );
       
   231 
       
   232         TUint count( 0);
       
   233         User::LeaveIfError(conn.EnumerateConnections(count) );
       
   234         // enumerate connections
       
   235         for (TUint idx=1; idx<=count; ++idx)
       
   236             {
       
   237             TConnectionInfo connectionInfo;
       
   238             TConnectionInfoBuf connInfo(connectionInfo);
       
   239 
       
   240             TInt err = conn.GetConnectionInfo(idx, connInfo); // iapid
       
   241             if (err != KErrNone)
       
   242                 {
       
   243                 CleanupStack::PopAndDestroy( 2); // conn, serv
       
   244                 User::Leave(err);
       
   245                 }
       
   246             // enumerate connectionclients
       
   247             TConnectionEnumArg conArg;
       
   248             conArg.iIndex = idx;
       
   249             TConnEnumArgBuf conArgBuf(conArg);
       
   250             err=conn.Control(KCOLConnection, KCoEnumerateConnectionClients,
       
   251                     conArgBuf);
       
   252             if (err != KErrNone)
       
   253                 {
       
   254                 CleanupStack::PopAndDestroy( 2); // conn, serv
       
   255                 User::Leave(err);
       
   256                 }
       
   257             TInt cliCount = conArgBuf().iCount;
       
   258             for (TUint j=1; j<=cliCount; ++j)
       
   259                 {
       
   260                 TConnectionGetClientInfoArg conCliInfo;
       
   261                 conCliInfo.iIndex = j;
       
   262                 TConnGetClientInfoArgBuf conCliInfoBuf(conCliInfo);
       
   263                 err=conn.Control(KCOLConnection, KCoGetConnectionClientInfo,
       
   264                         conCliInfoBuf);
       
   265 
       
   266                 if (err != KErrNone)
       
   267                     {
       
   268                     CleanupStack::PopAndDestroy( 2); // conn, serv
       
   269                     User::Leave(err);
       
   270                     }
       
   271                 TConnectionClientInfo conCliInf = conCliInfoBuf().iClientInfo;
       
   272                 TUid uid = conCliInf.iUid;
       
   273                 if (uid == KSosServerUid)
       
   274                     {
       
   275                     sockIapid = connInfo().iIapId;
       
   276 
       
   277                     }
       
   278 
       
   279                 }
       
   280             }
       
   281         CleanupStack::PopAndDestroy( 2); // conn, serv		
       
   282 
       
   283         aDefaultIAP = sockIapid;
       
   284 
       
   285         }
       
   286     // get profile's server id
       
   287     //aServerId = syncProfile.ServerId().AllocL();
       
   288 
       
   289     CleanupStack::PopAndDestroy( &syncConnection);
       
   290     CleanupStack::PopAndDestroy( &syncProfile);
       
   291 
       
   292     CleanupStack::PopAndDestroy( &ses);
       
   293     connections.Close();
       
   294     RDEBUG("ApplicationManagementServer::GetDefaultIAPFromDMProfileL() - end");
       
   295     }
       
   296 
       
   297 void SmlHelper::GetConnectionPropertyNameL(RSyncMLSession& aSyncSession,
       
   298         TDes8& aText, TInt aPropertyPos)
       
   299     {
       
   300     RDEBUG("ApplicationManagementServer::GetConnectionPropertyNameL() - start");
       
   301 
       
   302     // at the moment RSyncMLTransport is only needed
       
   303     // for internet connection settings
       
   304     RSyncMLTransport transport;
       
   305     CleanupClosePushL(transport);
       
   306     transport.OpenL(aSyncSession, KUidNSmlMediumTypeInternet.iUid);
       
   307 
       
   308     const CSyncMLTransportPropertiesArray& arr = transport.Properties();
       
   309 
       
   310     __ASSERT_DEBUG( arr.Count()> aPropertyPos, User::Panic(_L("invalid count"), KErrGeneral) );
       
   311 
       
   312     const TSyncMLTransportPropertyInfo& info = arr.At(aPropertyPos);
       
   313     aText = info.iName;
       
   314     CleanupStack::PopAndDestroy( &transport);
       
   315 
       
   316     RDEBUG("ApplicationManagementServer::GetConnectionPropertyNameL() - end");
       
   317     }
       
   318 
       
   319 TInt SmlHelper::StrToInt(const TDesC& aText, TInt& aNum)
       
   320     {
       
   321     TLex lex(aText);
       
   322     TInt err = lex.Val(aNum);
       
   323     return err;
       
   324     }
       
   325 
       
   326 // End of File