|
1 /* |
|
2 * Copyright (c) 2007 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: Part of SyncML Data Synchronization Plug In Adapter |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <hash.h> |
|
19 #include <utf.h> |
|
20 #include "snapshotitem.h" |
|
21 #include "logger.h" |
|
22 |
|
23 |
|
24 // ----------------------------------------------------------------------------- |
|
25 // TSnapshotItem::TSnapshotItem |
|
26 // C++ default constructor can NOT contain any code, that might leave |
|
27 // ----------------------------------------------------------------------------- |
|
28 TSnapshotItem::TSnapshotItem() : TNSmlSnapshotItem() |
|
29 { |
|
30 } |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // TSnapshotItem::TSnapshotItem |
|
34 // Constructor, takes item id as a parameter |
|
35 // ----------------------------------------------------------------------------- |
|
36 TSnapshotItem::TSnapshotItem( const TSmlDbItemUid& aItemId, |
|
37 const TSmlDbItemUid& aParent ) |
|
38 : TNSmlSnapshotItem( aItemId ) |
|
39 { |
|
40 SetParentId( aParent ); |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // TSnapshotItem::ExternalizeL |
|
45 // Writes the contents of this class and it's base to stream |
|
46 // ----------------------------------------------------------------------------- |
|
47 void TSnapshotItem::ExternalizeL( RWriteStream& aStream ) const |
|
48 { |
|
49 TNSmlSnapshotItem::ExternalizeL( aStream ); |
|
50 TPckgBuf<THashValue> nameBuf(iHash); |
|
51 aStream << nameBuf; |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // TSnapshotItem::InternalizeL |
|
56 // Reads the contents of this class and it's base from stream |
|
57 // ----------------------------------------------------------------------------- |
|
58 void TSnapshotItem::InternalizeL( RReadStream& aStream ) |
|
59 { |
|
60 TNSmlSnapshotItem::InternalizeL( aStream ); |
|
61 TPckgBuf<THashValue> nameBuf; |
|
62 aStream >> nameBuf; |
|
63 iHash = nameBuf(); |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // TSnapshotItem::CreateHashL |
|
68 // Create hash value from name and url |
|
69 // ----------------------------------------------------------------------------- |
|
70 |
|
71 void TSnapshotItem::CreateHashL( const TDesC& aName , const TDesC& aUrl ) |
|
72 { |
|
73 CMessageDigest* hash = CMessageDigestFactory::NewDigestLC( CMessageDigest::EMD5 ); |
|
74 HBufC8* tempBuf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( aName ); |
|
75 CleanupStack::PushL( tempBuf ); |
|
76 hash->Update( tempBuf->Des() ); |
|
77 CleanupStack::PopAndDestroy( tempBuf ); |
|
78 tempBuf = NULL; |
|
79 tempBuf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( aUrl ); |
|
80 hash->Update( tempBuf->Des() ); |
|
81 iHash.Copy( hash->Final() ); |
|
82 delete tempBuf; |
|
83 tempBuf = NULL; |
|
84 CleanupStack::PopAndDestroy( hash ); |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // TSnapshotItem::Hash |
|
89 // Gets Hash |
|
90 // ----------------------------------------------------------------------------- |
|
91 const TDesC8& TSnapshotItem::Hash() const |
|
92 { |
|
93 return iHash; |
|
94 } |