|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 |
|
17 #include "ineturiimpl.h" |
|
18 #include "ineturiproperties.h" |
|
19 #include <uri8.h> |
|
20 #include <uriutils.h> |
|
21 |
|
22 CInetUriImpl* CInetUriImpl::NewL () |
|
23 { |
|
24 CInetUriImpl* self = new ( ELeave ) CInetUriImpl (); |
|
25 CleanupStack::PushL ( self ); |
|
26 self->ConstructL (); |
|
27 CleanupStack::Pop (); |
|
28 return self; |
|
29 } |
|
30 |
|
31 CInetUriImpl::CInetUriImpl () |
|
32 : iUriId ( -1 ) |
|
33 { |
|
34 } |
|
35 |
|
36 CInetUriImpl::~CInetUriImpl () |
|
37 { |
|
38 delete iUri; |
|
39 iUri = NULL; |
|
40 delete iProperties; |
|
41 iProperties = NULL; |
|
42 } |
|
43 |
|
44 CInetUriImpl* CInetUriImpl::NewL ( const TDesC8& aUri, InetUriList::TServiceType aServiceType, InetUriList::TListType aUriType ) |
|
45 { |
|
46 CInetUriImpl* self = new ( ELeave ) CInetUriImpl (); |
|
47 CleanupStack::PushL ( self ); |
|
48 self->ConstructL ( aUri, aServiceType, aUriType ); |
|
49 CleanupStack::Pop (); |
|
50 return self; |
|
51 } |
|
52 |
|
53 void CInetUriImpl::ConstructL () |
|
54 { |
|
55 iProperties = new ( ELeave ) CInetUriProperties; |
|
56 } |
|
57 |
|
58 void CInetUriImpl::ConstructL ( const TDesC8& aUri, InetUriList::TServiceType aServiceType, InetUriList::TListType aUriType ) |
|
59 { |
|
60 TUriParser8 uriParser; |
|
61 User::LeaveIfError ( uriParser.Parse ( aUri ) ); |
|
62 // Do a syntax based normalisation |
|
63 iUri = UriUtils::NormaliseUriL ( uriParser ); |
|
64 ConstructL ( aServiceType, aUriType ); |
|
65 } |
|
66 |
|
67 void CInetUriImpl::ConstructL ( InetUriList::TServiceType aServiceType, InetUriList::TListType aUriType ) |
|
68 { |
|
69 iProperties = CInetUriProperties::NewL ( aServiceType, aUriType ); |
|
70 } |
|
71 |
|
72 /** |
|
73 Returns the underlying CUri8 object |
|
74 */ |
|
75 const CUri8& CInetUriImpl::Uri () const |
|
76 { |
|
77 return *iUri; |
|
78 } |
|
79 |
|
80 /** |
|
81 Set the URI Id |
|
82 */ |
|
83 void CInetUriImpl::SetUriId ( TInt aId ) |
|
84 { |
|
85 iUriId = aId; |
|
86 } |
|
87 |
|
88 /** |
|
89 Returns the URI Id |
|
90 */ |
|
91 TInt CInetUriImpl::UriId () const |
|
92 { |
|
93 return iUriId; |
|
94 } |
|
95 |
|
96 /** |
|
97 Returns the properties object |
|
98 */ |
|
99 CInetUriProperties& CInetUriImpl::Properties () const |
|
100 { |
|
101 return *iProperties; |
|
102 } |
|
103 |
|
104 /** |
|
105 Leaves with KErrUriReadOnly value if the URI is read-only |
|
106 */ |
|
107 void CInetUriImpl::LeaveIfReadOnlyL () const |
|
108 { |
|
109 if ( iProperties->Permission() == InetUriList::EReadOnly ) |
|
110 { |
|
111 User::Leave ( InetUriList::KErrUriReadOnly ); |
|
112 } |
|
113 } |
|
114 |
|
115 /** |
|
116 Clears the URI object by deleting the underlying CUri8 object |
|
117 */ |
|
118 void CInetUriImpl::Clear () |
|
119 { |
|
120 delete iUri; |
|
121 iUri = NULL; |
|
122 iProperties->Clear (); |
|
123 } |
|
124 |
|
125 TBool CInetUriImpl::IsDirty () const |
|
126 { |
|
127 return ( iUri == NULL ); |
|
128 } |
|
129 |
|
130 void CInetUriImpl::SetUri ( CUri8& aUri ) |
|
131 { |
|
132 iUri = &aUri; |
|
133 } |
|
134 |
|
135 /** |
|
136 Set the URI and parses the URI |
|
137 */ |
|
138 void CInetUriImpl::SetUriL ( const TDesC8& aUri ) |
|
139 { |
|
140 // The handle must be open and attached to a concrete inernet uri object |
|
141 __ASSERT_ALWAYS( !iUri, User::Panic( InetUriList::KInetUriListErrHandleNotOpen, InetUriList::KErrNotOpen ) ); |
|
142 |
|
143 TUriParser8 uriParser; |
|
144 User::LeaveIfError ( uriParser.Parse ( aUri ) ); |
|
145 iUri = CUri8::NewL ( uriParser ); |
|
146 } |
|
147 |
|
148 const TDesC8& CInetUriImpl::UriDes () const |
|
149 { |
|
150 // The handle must be open and attached to a concrete inernet uri object |
|
151 __ASSERT_ALWAYS( iUri, User::Panic( InetUriList::KInetUriListErrHandleNotOpen, InetUriList::KErrNotOpen ) ); |
|
152 |
|
153 return iUri->Uri().UriDes(); |
|
154 } |
|
155 |
|
156 /** |
|
157 Calculates total size of the IPC data buffer |
|
158 */ |
|
159 TInt CInetUriImpl::Size () const |
|
160 { |
|
161 return ( sizeof ( TInt ) * 2 + iUri->Uri ().UriDes ().Length () + iProperties->Size() ); |
|
162 } |
|
163 |
|
164 /** |
|
165 Packs the URI object to send it via IPC |
|
166 */ |
|
167 void CInetUriImpl::PackL ( RWriteStream& aStream ) |
|
168 { |
|
169 aStream.WriteInt32L ( iUriId ); |
|
170 const TDesC8& uriDes ( iUri->Uri ().UriDes () ); |
|
171 aStream.WriteInt32L ( uriDes.Length() ); |
|
172 aStream.WriteL ( uriDes ); |
|
173 |
|
174 // Pack the properties |
|
175 iProperties->PackL ( aStream ); |
|
176 } |
|
177 |
|
178 /** |
|
179 Unpacks the stream and assign to respective values |
|
180 */ |
|
181 void CInetUriImpl::UnpackL ( RReadStream& aStream ) |
|
182 { |
|
183 SetUriId ( aStream.ReadInt32L() ); |
|
184 TInt uriSize = aStream.ReadInt32L (); |
|
185 HBufC8* uri = HBufC8::NewLC ( uriSize ); |
|
186 TPtr8 ptr ( uri->Des () ); |
|
187 aStream.ReadL ( ptr, uriSize ); |
|
188 SetUriL ( ptr ); |
|
189 CleanupStack::PopAndDestroy ( ); // uri |
|
190 |
|
191 // Unpack the properties |
|
192 iProperties->UnpackL ( aStream ); |
|
193 } |