|
1 /* |
|
2 * Copyright (c) 2005 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: Codec to code attribute type and presence id. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "PEngAttributeStoreIDCodec.h" |
|
20 #include <E32Base.h> |
|
21 |
|
22 |
|
23 //CONSTS |
|
24 const TUint32 KAttributeLibraryUid = 0x101FB0E2; |
|
25 |
|
26 |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 // ----------------------------------------------------------------------------- |
|
30 // PEngAttributeStoreIDCodec::GenerateStoreIdL() |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 HBufC* PEngAttributeStoreIDCodec::GenerateStoreIdL( TUint32 aAttributeType, |
|
34 const TDesC& aPresenceId ) |
|
35 { |
|
36 TInt storeIdLength = aPresenceId.Length() + 4; //2 x TUInt32 ==> 4 x 16bytes |
|
37 HBufC* storeIdBuf = HBufC::NewL( storeIdLength ); |
|
38 TPtr storeId( storeIdBuf->Des() ); |
|
39 |
|
40 |
|
41 storeId.Append( ( TUint16* ) &KAttributeLibraryUid, 2 ); //TUInt32 ==> 2 x 16bytes |
|
42 storeId.Append( ( TUint16* ) &aAttributeType, 2 ); //TUInt32 ==> 2 x 16bytes |
|
43 storeId.Append( aPresenceId ); |
|
44 return storeIdBuf; |
|
45 } |
|
46 |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // PEngAttributeStoreIDCodec::ResolveStoreId() |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 TInt PEngAttributeStoreIDCodec::ResolveStoreId( const TDesC& aStoreId, |
|
53 TUint32& aAttributeType, |
|
54 TPtrC& aPresenceId ) |
|
55 |
|
56 { |
|
57 if ( aStoreId.Length() < 4 ) |
|
58 { |
|
59 return KErrCorrupt; |
|
60 } |
|
61 |
|
62 TUint32 sidUid = *( TUint32* ) aStoreId.Ptr(); |
|
63 if ( sidUid != KAttributeLibraryUid ) |
|
64 { |
|
65 return KErrCorrupt; |
|
66 } |
|
67 |
|
68 |
|
69 aAttributeType = *( TUint32* ) aStoreId.Mid( 2 ).Ptr(); |
|
70 aPresenceId.Set( aStoreId.Mid( 4 ) ); |
|
71 |
|
72 return KErrNone; |
|
73 } |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // PEngAttributeStoreIDCodec::AttributeTypePresentInStoreId() |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 TBool PEngAttributeStoreIDCodec::AttributeTypePresentInStoreId( const TDesC& aStoreId, |
|
83 TUint32 aAttributeType ) |
|
84 { |
|
85 if ( aStoreId.Length() >= 4 ) |
|
86 { |
|
87 //valid store id |
|
88 TUint32 sidUid = *( TUint32* ) aStoreId.Ptr(); |
|
89 if ( sidUid == KAttributeLibraryUid ) |
|
90 { |
|
91 TUint32 attributeType = *( TUint32* ) aStoreId.Mid( 2 ).Ptr(); |
|
92 if ( attributeType == aAttributeType ) |
|
93 { |
|
94 return ETrue; |
|
95 } |
|
96 } |
|
97 } |
|
98 |
|
99 return EFalse; |
|
100 } |
|
101 |
|
102 |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // PEngAttributeStoreIDCodec::PresenceIdPresentInStoreId() |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 TBool PEngAttributeStoreIDCodec::PresenceIdPresentInStoreId( const TDesC& aStoreId, |
|
109 const TDesC& aPresenceId ) |
|
110 { |
|
111 if ( aStoreId.Length() >= 4 ) |
|
112 { |
|
113 //valid store id |
|
114 TPtrC storeIdPresenceIdPart = aStoreId.Mid( 4 ); |
|
115 if ( aPresenceId.Compare( storeIdPresenceIdPart ) == 0 ) |
|
116 { |
|
117 return ETrue; |
|
118 } |
|
119 } |
|
120 |
|
121 return EFalse; |
|
122 } |
|
123 |
|
124 |
|
125 |
|
126 // End of File |
|
127 |
|
128 |