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