16
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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: Utility functions for managing mount configurations
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// INCLUDES
|
|
19 |
|
|
20 |
#include <s32file.h>
|
|
21 |
#include <uri8.h>
|
|
22 |
#include <utf.h>
|
|
23 |
#include <ecom/ecom.h>
|
|
24 |
#include <ecom/implementationinformation.h>
|
|
25 |
#include <rsfwmountentry.h>
|
|
26 |
|
|
27 |
#include "rsfwmountutils.h"
|
|
28 |
#include "rsfwremoteaccess.h"
|
|
29 |
|
|
30 |
|
|
31 |
// CONSTANTS
|
|
32 |
// These keywords must match with the entry items
|
|
33 |
_LIT(KKId, "Fname");
|
|
34 |
_LIT(KKDrive, "Fdrv");
|
|
35 |
_LIT(KKUri, "Furi");
|
|
36 |
_LIT(KKUserName, "Fuid");
|
|
37 |
_LIT(KKPassword, "Fpsw");
|
|
38 |
|
|
39 |
_LIT(KMountMessagePrefix, "//vnd.nokia.s60.mount.config\n");
|
|
40 |
|
|
41 |
// ============================ MEMBER FUNCTIONS ==============================
|
|
42 |
|
|
43 |
// ----------------------------------------------------------------------------
|
|
44 |
// RsfwMountUtils::ImportMountEntryL
|
|
45 |
// ----------------------------------------------------------------------------
|
|
46 |
//
|
|
47 |
EXPORT_C void RsfwMountUtils::ImportMountEntryL(const TDesC& aMsg,
|
|
48 |
CRsfwMountEntry** aEntry)
|
|
49 |
{
|
|
50 |
// Expected to start with
|
|
51 |
// //vnd.nokia.s60.mount.config\n
|
|
52 |
|
|
53 |
TPtrC prefix = aMsg.Left(KMountMessagePrefixLength);
|
|
54 |
if (prefix.Compare(KMountMessagePrefix) != 0)
|
|
55 |
{
|
|
56 |
User::Leave(KErrNotFound);
|
|
57 |
}
|
|
58 |
|
|
59 |
// It is a mount configuration message
|
|
60 |
CRsfwMountEntry* entry = CRsfwMountEntry::NewLC();
|
|
61 |
|
|
62 |
TInt lineNumber = 0;
|
|
63 |
|
|
64 |
// SMS rich text messages may be have trailing characters -
|
|
65 |
// that looks like ')' characters
|
|
66 |
TInt i = aMsg.Length() - 1;
|
|
67 |
while (i > 0)
|
|
68 |
{
|
|
69 |
TUint8 c = static_cast<TUint8>(aMsg[i]);
|
|
70 |
if (c != ')')
|
|
71 |
{
|
|
72 |
break;
|
|
73 |
}
|
|
74 |
i--;
|
|
75 |
}
|
|
76 |
TPtrC msg = aMsg.Left(i + 1);
|
|
77 |
|
|
78 |
TLex lex(msg);
|
|
79 |
while (!lex.Eos())
|
|
80 |
{
|
|
81 |
lineNumber++;
|
|
82 |
lex.SkipSpaceAndMark();
|
|
83 |
while (lex.Peek() != '\n' && !lex.Eos())
|
|
84 |
{
|
|
85 |
lex.Inc();
|
|
86 |
}
|
|
87 |
// The marked token is now the whole line
|
|
88 |
TPtrC line = lex.MarkedToken();
|
|
89 |
ParseLineL(line, *entry);
|
|
90 |
if (!lex.Eos())
|
|
91 |
{
|
|
92 |
// Skip the '\n'
|
|
93 |
lex.Inc();
|
|
94 |
}
|
|
95 |
}
|
|
96 |
|
|
97 |
CleanupStack::Pop(entry);
|
|
98 |
*aEntry = entry;
|
|
99 |
}
|
|
100 |
|
|
101 |
// ----------------------------------------------------------------------------
|
|
102 |
// RsfwMountUtils::ImportMountEntryFromStreamL
|
|
103 |
// ----------------------------------------------------------------------------
|
|
104 |
//
|
|
105 |
EXPORT_C void RsfwMountUtils::ImportMountEntryFromStreamL(RReadStream& aReadStream,
|
|
106 |
TInt aSize,
|
|
107 |
CRsfwMountEntry** aEntry)
|
|
108 |
{
|
|
109 |
// the string is assumed to be 8-bit in stream,
|
|
110 |
// and should be converted to Unicode
|
|
111 |
*aEntry = NULL;
|
|
112 |
HBufC8* tempbuf = HBufC8::NewLC(aSize);
|
|
113 |
TPtr8 tbufPtr = tempbuf->Des();
|
|
114 |
tbufPtr.Zero();
|
|
115 |
TRAPD(err, aReadStream.ReadL(tbufPtr));
|
|
116 |
|
|
117 |
HBufC* buf = HBufC::NewLC(aSize);
|
|
118 |
TPtr bufPtr = buf->Des();
|
|
119 |
CnvUtfConverter::ConvertToUnicodeFromUtf8(bufPtr, tbufPtr);
|
|
120 |
if ((err == KErrNone) || (err == KErrEof))
|
|
121 |
{
|
|
122 |
ImportMountEntryL(bufPtr, aEntry);
|
|
123 |
}
|
|
124 |
CleanupStack::PopAndDestroy(2, tempbuf); // buf, tempbuf
|
|
125 |
}
|
|
126 |
|
|
127 |
// ----------------------------------------------------------------------------
|
|
128 |
// RsfwMountUtils::ExportMountEntryL
|
|
129 |
// ----------------------------------------------------------------------------
|
|
130 |
//
|
|
131 |
EXPORT_C void RsfwMountUtils::ExportMountEntryL(const CRsfwMountEntry& aEntry,
|
|
132 |
TBool aSendCredentials,
|
|
133 |
TDes& aBuf)
|
|
134 |
{
|
|
135 |
aBuf.Copy(KMountMessagePrefix);
|
|
136 |
TInt i;
|
|
137 |
// smart messaging sends:
|
|
138 |
// EMountEntryItemName
|
|
139 |
// EMountEntryItemUri
|
|
140 |
// if aSendCredentials sends also:
|
|
141 |
// EMountEntryItemUserName
|
|
142 |
// EMountEntryItemPassword
|
|
143 |
TInt lastToExport;
|
|
144 |
if (aSendCredentials)
|
|
145 |
{
|
|
146 |
lastToExport = EMountEntryItemPassword;
|
|
147 |
}
|
|
148 |
else
|
|
149 |
{
|
|
150 |
lastToExport = EMountEntryItemUri;
|
|
151 |
}
|
|
152 |
|
|
153 |
for (i = EMountEntryItemName; i < lastToExport + 1; i++)
|
|
154 |
{
|
|
155 |
if (i != EMountEntryItemDrive)
|
|
156 |
{
|
|
157 |
const HBufC* item = aEntry.Item(i);
|
|
158 |
if (item && item->Length())
|
|
159 |
{
|
|
160 |
aBuf.Append(GetKeyWord(i));
|
|
161 |
aBuf.Append(':');
|
|
162 |
const TPtrC ip(*item);
|
|
163 |
aBuf.Append(ip);
|
|
164 |
aBuf.Append('\n');
|
|
165 |
}
|
|
166 |
}
|
|
167 |
}
|
|
168 |
}
|
|
169 |
|
|
170 |
// ----------------------------------------------------------------------------
|
|
171 |
// RsfwMountUtils::IsFriendlyNameValid
|
|
172 |
// ----------------------------------------------------------------------------
|
|
173 |
//
|
|
174 |
EXPORT_C TBool RsfwMountUtils::IsFriendlyNameValid(const TDesC& aFriendlyName)
|
|
175 |
{
|
|
176 |
TInt err;
|
|
177 |
TBool retValue = ETrue;
|
|
178 |
RFs fsSession;
|
|
179 |
err = fsSession.Connect();
|
|
180 |
if (err)
|
|
181 |
{
|
|
182 |
return retValue;
|
|
183 |
}
|
|
184 |
retValue = fsSession.IsValidName(aFriendlyName);
|
|
185 |
fsSession.Close();
|
|
186 |
|
|
187 |
// Some names are acceptable by RFs.IsValidName(),
|
|
188 |
// but not acceptable by RFs.SetDriveName()
|
|
189 |
// Those are checked below:
|
|
190 |
|
|
191 |
// solely period characters ( e.g. "...")
|
|
192 |
if (retValue)
|
|
193 |
{
|
|
194 |
retValue = EFalse;
|
|
195 |
TChar period(46); // period (".") character
|
|
196 |
TInt i;
|
|
197 |
for (i = 0; i < aFriendlyName.Length(); i++)
|
|
198 |
{
|
|
199 |
if (aFriendlyName[i] != period)
|
|
200 |
{
|
|
201 |
retValue = ETrue;
|
|
202 |
break;
|
|
203 |
}
|
|
204 |
}
|
|
205 |
}
|
|
206 |
|
|
207 |
// period as the last character ( e.g. "myDrive.")
|
|
208 |
if (retValue)
|
|
209 |
{
|
|
210 |
TChar period(46); // period (".") character
|
|
211 |
TInt nameLength = aFriendlyName.Length();
|
|
212 |
if (nameLength > 0 && aFriendlyName[nameLength-1] == period)
|
|
213 |
{
|
|
214 |
retValue = EFalse;
|
|
215 |
}
|
|
216 |
}
|
|
217 |
|
|
218 |
return retValue;
|
|
219 |
}
|
|
220 |
|
|
221 |
// ----------------------------------------------------------------------------
|
|
222 |
// RsfwMountUtils::IsDriveAddressValid
|
|
223 |
// ----------------------------------------------------------------------------
|
|
224 |
//
|
|
225 |
EXPORT_C TBool RsfwMountUtils::IsDriveAddressValid(const TDesC8& aDriveAddress)
|
|
226 |
{
|
|
227 |
// extract the protocol
|
|
228 |
TInt err;
|
|
229 |
TUriParser8 parser;
|
|
230 |
err = parser.Parse(aDriveAddress);
|
|
231 |
if (err)
|
|
232 |
{
|
|
233 |
return EFalse;
|
|
234 |
}
|
|
235 |
TPtrC8 protocol = parser.Extract(EUriScheme);
|
|
236 |
|
|
237 |
|
|
238 |
TBuf8<KMaxMatchStringSize> matchString;
|
|
239 |
_LIT8(KRemoteMatchPrefix, "remoteaccess/");
|
|
240 |
matchString.Copy(KRemoteMatchPrefix);
|
|
241 |
|
|
242 |
// Both "http" and "https" are handled by davaccess module
|
|
243 |
_LIT8(KHttps, "https");
|
|
244 |
if (protocol.Compare(KHttps) == 0)
|
|
245 |
{
|
|
246 |
_LIT8(KHttp, "http");
|
|
247 |
matchString.Append(KHttp);
|
|
248 |
}
|
|
249 |
else
|
|
250 |
{
|
|
251 |
matchString.Append(protocol);
|
|
252 |
}
|
|
253 |
TEComResolverParams resolverParams;
|
|
254 |
resolverParams.SetDataType(matchString);
|
|
255 |
// Disable wildcard matching
|
|
256 |
resolverParams.SetWildcardMatch(EFalse);
|
|
257 |
|
|
258 |
|
|
259 |
// check whether there is a remote access plugin implementation for that protocol
|
|
260 |
RImplInfoPtrArray implinfo;
|
|
261 |
TRAP(err, REComSession::ListImplementationsL(
|
|
262 |
KCRemoteAccessUid,
|
|
263 |
resolverParams,
|
|
264 |
implinfo));
|
|
265 |
|
|
266 |
if (err != KErrNone)
|
|
267 |
{
|
|
268 |
// if fetching the list of implemenations fail,'
|
|
269 |
// (for example a temporary out of memory situation)
|
|
270 |
// just accept the string
|
|
271 |
implinfo.ResetAndDestroy();
|
|
272 |
return ETrue;
|
|
273 |
}
|
|
274 |
|
|
275 |
// we assume that protocol used for remote access
|
|
276 |
// represents hierarchical relationships within the namespace. This
|
|
277 |
// "generic URI" syntax consists of a sequence of four main components:
|
|
278 |
// <scheme>://<authority><path>?<query>
|
|
279 |
// check that scheme is followed by "://"
|
|
280 |
_LIT8(KDelimiter, "://");
|
|
281 |
if (aDriveAddress.Length() < protocol.Length()+3)
|
|
282 |
{
|
|
283 |
implinfo.ResetAndDestroy();
|
|
284 |
return EFalse;
|
|
285 |
}
|
|
286 |
|
|
287 |
TPtrC8 test = aDriveAddress.Mid(protocol.Length(), 3);
|
|
288 |
if (!(test.Compare(KDelimiter) == 0))
|
|
289 |
{
|
|
290 |
implinfo.ResetAndDestroy();
|
|
291 |
return EFalse;
|
|
292 |
}
|
|
293 |
|
|
294 |
TInt count = implinfo.Count();
|
|
295 |
implinfo.ResetAndDestroy();
|
|
296 |
if (count > 0)
|
|
297 |
{
|
|
298 |
return ETrue;
|
|
299 |
}
|
|
300 |
else
|
|
301 |
{
|
|
302 |
return EFalse;
|
|
303 |
}
|
|
304 |
}
|
|
305 |
|
|
306 |
// ----------------------------------------------------------------------------
|
|
307 |
// RsfwMountUtils::ParseLineL
|
|
308 |
// ----------------------------------------------------------------------------
|
|
309 |
//
|
|
310 |
void RsfwMountUtils::ParseLineL(const TDesC& aLine,
|
|
311 |
CRsfwMountEntry& aEntry)
|
|
312 |
{
|
|
313 |
TLex lex(aLine);
|
|
314 |
// Extract Line i.e "leftToken:RightToken<LF>", then asign to TLex object
|
|
315 |
while (lex.Peek() != ':' && lex.Peek() != '\n' && !lex.Eos())
|
|
316 |
{
|
|
317 |
lex.Inc();
|
|
318 |
}
|
|
319 |
|
|
320 |
// We are only interested in lines containing a colon delimeter ':'
|
|
321 |
// other text lines are ignored i.e "Welcome !<LF>"
|
|
322 |
if(lex.Peek() != ':')
|
|
323 |
{
|
|
324 |
// It was not a name value pair
|
|
325 |
return;
|
|
326 |
}
|
|
327 |
if (lex.TokenLength() == 0)
|
|
328 |
{
|
|
329 |
User::Leave(KErrNotFound);
|
|
330 |
}
|
|
331 |
// Get the keyword
|
|
332 |
HBufC* keyWord = lex.MarkedToken().AllocLC();
|
|
333 |
// Go past the ':'
|
|
334 |
lex.Inc();
|
|
335 |
lex.SkipSpaceAndMark();
|
|
336 |
while (lex.Peek() != '\n' && lex.Peek() != '\r' && !lex.Eos())
|
|
337 |
{
|
|
338 |
lex.Inc();
|
|
339 |
}
|
|
340 |
|
|
341 |
TInt i;
|
|
342 |
// Keyword matching
|
|
343 |
// password is the last possible entry that is transferred
|
|
344 |
for (i = EMountEntryItemName; i < EMountEntryItemPassword + 1; i++)
|
|
345 |
{
|
|
346 |
if (GetKeyWord(i).Compare(*keyWord) == 0)
|
|
347 |
{
|
|
348 |
aEntry.SetItemL(i, lex.MarkedToken());
|
|
349 |
}
|
|
350 |
}
|
|
351 |
CleanupStack::PopAndDestroy(keyWord);
|
|
352 |
}
|
|
353 |
|
|
354 |
// ----------------------------------------------------------------------------
|
|
355 |
// RsfwMountUtils::GetKeyWord
|
|
356 |
// ----------------------------------------------------------------------------
|
|
357 |
//
|
|
358 |
const TDesC& RsfwMountUtils::GetKeyWord(TInt iItem)
|
|
359 |
{
|
|
360 |
switch (iItem)
|
|
361 |
{
|
|
362 |
case EMountEntryItemName:
|
|
363 |
return KKId;
|
|
364 |
|
|
365 |
case EMountEntryItemDrive:
|
|
366 |
return KKDrive;
|
|
367 |
|
|
368 |
case EMountEntryItemUri:
|
|
369 |
return KKUri;
|
|
370 |
|
|
371 |
case EMountEntryItemUserName:
|
|
372 |
return KKUserName;
|
|
373 |
|
|
374 |
case EMountEntryItemPassword:
|
|
375 |
return KKPassword;
|
|
376 |
|
|
377 |
default:
|
|
378 |
return KKId;
|
|
379 |
}
|
|
380 |
}
|
|
381 |
// End of File
|