|
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 <rconnmon.h> |
|
21 #include <es_sock.h> |
|
22 #include <es_enum_internal.h> |
|
23 #include <es_sock_partner.h> |
|
24 #include <es_enum.h> |
|
25 #include "lawmodebug.h" |
|
26 |
|
27 const TUid KUidNSmlMediumTypeInternet = |
|
28 { |
|
29 0x101F99F0 |
|
30 }; |
|
31 const TUid KSosServerUid = |
|
32 { |
|
33 0x101F99FB |
|
34 }; |
|
35 |
|
36 const TInt KBufSize32 = 32; |
|
37 |
|
38 void SmlHelper::GetDefaultIAPFromDMProfileL(TInt& aDefaultIAP) |
|
39 { |
|
40 RLDEBUG("ApplicationManagementServer::GetDefaultIAPFromDMProfileL() - start"); |
|
41 |
|
42 // first try to obtain the current profile id |
|
43 RSyncMLSession ses; |
|
44 ses.OpenL(); |
|
45 RLDEBUG(" 1/8"); |
|
46 CleanupClosePushL(ses); |
|
47 |
|
48 TSmlJobId jid; |
|
49 TSmlUsageType jtype; |
|
50 ses.CurrentJobL(jid, jtype); |
|
51 RLDEBUG(" 2/8"); |
|
52 RSyncMLDevManJob job; |
|
53 job.OpenL(ses, jid); |
|
54 RLDEBUG(" 3/8"); |
|
55 CleanupClosePushL(job); |
|
56 // get profile id |
|
57 TSmlProfileId pid(job.Profile() ); |
|
58 CleanupStack::PopAndDestroy( &job); |
|
59 |
|
60 TBuf8<KBufSize32> key; |
|
61 TBuf<KBufSize32> value; |
|
62 TInt num = KErrNotFound; |
|
63 |
|
64 // get connection property name first |
|
65 GetConnectionPropertyNameL(ses, key, EPropertyIntenetAccessPoint); |
|
66 RLDEBUG(" 4/8"); |
|
67 // we need to open sync profile in ordere to open the RSyncMLConnection |
|
68 RSyncMLDevManProfile syncProfile; |
|
69 syncProfile.OpenL(ses, pid); |
|
70 RLDEBUG(" 5/8"); |
|
71 CleanupClosePushL(syncProfile); |
|
72 |
|
73 TSmlTransportId transport; |
|
74 RArray<TSmlTransportId> connections; |
|
75 _LIT8( KNSmlIAPId, "NSmlIapId" ); |
|
76 |
|
77 // now open the syncML connection |
|
78 RSyncMLConnection syncConnection; |
|
79 syncProfile.ListConnectionsL(connections); |
|
80 |
|
81 transport = connections[0]; |
|
82 syncConnection.OpenL(syncProfile, transport); |
|
83 RLDEBUG(" 6/8"); |
|
84 CleanupClosePushL(syncConnection); |
|
85 |
|
86 const TDesC8& source(syncConnection.GetPropertyL(KNSmlIAPId) ); |
|
87 RLDEBUG(" 7/8"); |
|
88 value.Copy(source.Left(value.MaxLength() ) ); |
|
89 User::LeaveIfError(StrToInt(value, num) ); |
|
90 RLDEBUG(" 8/8"); |
|
91 |
|
92 aDefaultIAP = num; |
|
93 |
|
94 // If there is no default Access point in DM profile then use |
|
95 // currently used access point by DM session |
|
96 |
|
97 if (aDefaultIAP == -1) |
|
98 { |
|
99 RLDEBUG("adefault iap -1"); |
|
100 TInt sockIapid = -1; |
|
101 |
|
102 RSocketServ serv; |
|
103 CleanupClosePushL(serv); |
|
104 User::LeaveIfError(serv.Connect() ); |
|
105 |
|
106 RConnection conn; |
|
107 CleanupClosePushL(conn); |
|
108 User::LeaveIfError(conn.Open(serv) ); |
|
109 RLDEBUG("RConnection opened"); |
|
110 |
|
111 TUint count( 0); |
|
112 User::LeaveIfError(conn.EnumerateConnections(count) ); |
|
113 RLDEBUG_2("RConnection count %d",count); |
|
114 // enumerate connections |
|
115 for (TUint idx=1; idx<=count; ++idx) |
|
116 { |
|
117 TConnectionInfo connectionInfo; |
|
118 TConnectionInfoBuf connInfo(connectionInfo); |
|
119 RLDEBUG("RConnection loop"); |
|
120 TInt err = conn.GetConnectionInfo(idx, connInfo); // iapid |
|
121 RLDEBUG("RConnection get conn info"); |
|
122 if (err != KErrNone) |
|
123 { |
|
124 CleanupStack::PopAndDestroy( 2); // conn, serv |
|
125 User::Leave(err); |
|
126 } |
|
127 // enumerate connectionclients |
|
128 TConnectionEnumArg conArg; |
|
129 conArg.iIndex = idx; |
|
130 TConnEnumArgBuf conArgBuf(conArg); |
|
131 RLDEBUG("RConnection control"); |
|
132 err=conn.Control(KCOLConnection, KCoEnumerateConnectionClients, |
|
133 conArgBuf); |
|
134 if (err != KErrNone) |
|
135 { |
|
136 CleanupStack::PopAndDestroy( 2); // conn, serv |
|
137 User::Leave(err); |
|
138 } |
|
139 TInt cliCount = conArgBuf().iCount; |
|
140 RLDEBUG("RConnection second loop"); |
|
141 for (TUint j=1; j<=cliCount; ++j) |
|
142 { |
|
143 TConnectionGetClientInfoArg conCliInfo; |
|
144 conCliInfo.iIndex = j; |
|
145 TConnGetClientInfoArgBuf conCliInfoBuf(conCliInfo); |
|
146 RLDEBUG("RConnection another control"); |
|
147 err=conn.Control(KCOLConnection, KCoGetConnectionClientInfo, |
|
148 conCliInfoBuf); |
|
149 |
|
150 if (err != KErrNone) |
|
151 { |
|
152 CleanupStack::PopAndDestroy( 2); // conn, serv |
|
153 User::Leave(err); |
|
154 } |
|
155 TConnectionClientInfo conCliInf = conCliInfoBuf().iClientInfo; |
|
156 TUid uid = conCliInf.iUid; |
|
157 RLDEBUG_2("RConnection check uid %d", uid.iUid); |
|
158 if (uid == KSosServerUid) |
|
159 { |
|
160 sockIapid = connInfo().iIapId; |
|
161 RLDEBUG("RConnection uid matched"); |
|
162 } |
|
163 |
|
164 } |
|
165 } |
|
166 CleanupStack::PopAndDestroy( 2); // conn, serv |
|
167 |
|
168 aDefaultIAP = sockIapid; |
|
169 RLDEBUG("RConnection out"); |
|
170 } |
|
171 // get profile's server id |
|
172 //aServerId = syncProfile.ServerId().AllocL(); |
|
173 RLDEBUG("RConnection total out"); |
|
174 |
|
175 CleanupStack::PopAndDestroy( &syncConnection); |
|
176 CleanupStack::PopAndDestroy( &syncProfile); |
|
177 |
|
178 CleanupStack::PopAndDestroy( &ses); |
|
179 connections.Close(); |
|
180 RLDEBUG("ApplicationManagementServer::GetDefaultIAPFromDMProfileL() - end"); |
|
181 } |
|
182 |
|
183 void SmlHelper::GetConnectionPropertyNameL(RSyncMLSession& aSyncSession, |
|
184 TDes8& aText, TInt aPropertyPos) |
|
185 { |
|
186 RLDEBUG("ApplicationManagementServer::GetConnectionPropertyNameL() - start"); |
|
187 |
|
188 // at the moment RSyncMLTransport is only needed |
|
189 // for internet connection settings |
|
190 RSyncMLTransport transport; |
|
191 CleanupClosePushL(transport); |
|
192 transport.OpenL(aSyncSession, KUidNSmlMediumTypeInternet.iUid); |
|
193 |
|
194 const CSyncMLTransportPropertiesArray& arr = transport.Properties(); |
|
195 RLDEBUG("GetConnectionPropertyNameL interior"); |
|
196 __ASSERT_DEBUG( arr.Count()> aPropertyPos, User::Panic(_L("invalid count"), KErrGeneral) ); |
|
197 |
|
198 const TSyncMLTransportPropertyInfo& info = arr.At(aPropertyPos); |
|
199 aText = info.iName; |
|
200 CleanupStack::PopAndDestroy( &transport); |
|
201 |
|
202 RLDEBUG("ApplicationManagementServer::GetConnectionPropertyNameL() - end"); |
|
203 } |
|
204 |
|
205 TInt SmlHelper::StrToInt(const TDesC& aText, TInt& aNum) |
|
206 { |
|
207 TLex lex(aText); |
|
208 TInt err = lex.Val(aNum); |
|
209 return err; |
|
210 } |
|
211 |
|
212 // End of File |