[content] Change secure log
[platform/framework/native/content.git] / src / FCnt_DownloadRequestImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FCnt_DownloadRequestImpl.cpp
20  * @brief       This is the implementation file for the _DownloadRequestImpl class.
21  *
22  */
23
24 #include <unique_ptr.h>
25
26 #include <FBaseLog.h>
27 #include <FBaseSysLog.h>
28 #include <FCntDownloadRequest.h>
29
30 #include "FCnt_DownloadRequestImpl.h"
31
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace std;
35
36 namespace Tizen { namespace Content
37 {
38
39 _DownloadRequestImpl::_DownloadRequestImpl(void)
40         : __notification(true)
41         , __networkType(DOWNLOAD_NETWORK_ALL)
42 {
43         __notifyExtraData.Construct();
44         __requestHeader.Construct();
45 }
46
47 _DownloadRequestImpl::_DownloadRequestImpl(const String& url)
48         : __url(url)
49         , __notification(true)
50         , __networkType(DOWNLOAD_NETWORK_ALL)
51 {
52         __notifyExtraData.Construct();
53         __requestHeader.Construct();
54 }
55
56 _DownloadRequestImpl::_DownloadRequestImpl(const String& url, const String& dirPath)
57         : __url(url)
58         , __dirPath(dirPath)
59         , __notification(true)
60         , __networkType(DOWNLOAD_NETWORK_ALL)
61 {
62         __notifyExtraData.Construct();
63         __requestHeader.Construct();
64 }
65
66 _DownloadRequestImpl::_DownloadRequestImpl(const _DownloadRequestImpl& rhs)
67         : __url(rhs.__url)
68         , __dirPath(rhs.__dirPath)
69         , __fileName(rhs.__fileName)
70         , __notification(rhs.__notification)
71         , __networkType(rhs.__networkType)
72 {
73         __notifyExtraData.Construct(rhs.__notifyExtraData);
74         __requestHeader.Construct(rhs.__requestHeader);
75 }
76
77 _DownloadRequestImpl::~_DownloadRequestImpl(void)
78 {
79 }
80
81
82 _DownloadRequestImpl&
83 _DownloadRequestImpl::operator =(const _DownloadRequestImpl& rhs)
84 {
85         __url = rhs.__url;
86         __dirPath = rhs.__dirPath;
87         __fileName = rhs.__fileName;
88         __notification = rhs.__notification;
89         __networkType = rhs.__networkType;
90         __notifyExtraData.RemoveAll();
91         __notifyExtraData.Construct(rhs.__notifyExtraData);
92         __requestHeader.RemoveAll();
93         __requestHeader.Construct(rhs.__requestHeader);
94
95         return *this;
96 }
97
98 bool
99 _DownloadRequestImpl::operator ==(const _DownloadRequestImpl& rhs) const
100 {
101         if (&rhs == this)
102         {
103                 return true;
104         }
105
106         if (__url == rhs.__url
107                 && __dirPath == rhs.__dirPath
108                 && __fileName == rhs.__fileName)
109         {
110                 return true;
111         }
112
113         return false;
114 }
115
116 bool
117 _DownloadRequestImpl::Equals(const Object& obj) const
118 {
119         const _DownloadRequestImpl* pOther = dynamic_cast< const _DownloadRequestImpl* >(&obj);
120         if (pOther == null)
121         {
122                 return false;
123         }
124
125         return (*this == *pOther);
126 }
127
128 int
129 _DownloadRequestImpl::GetHashCode(void) const
130 {
131         String hashCode;
132
133         hashCode.Append(__url);
134         hashCode.Append(__dirPath);
135         hashCode.Append(__fileName);
136
137         return hashCode.GetHashCode();
138 }
139
140 void
141 _DownloadRequestImpl::SetDirectoryPath(const String& dirPath)
142 {
143         __dirPath = dirPath;
144 }
145
146 void
147 _DownloadRequestImpl::SetFileName(const String& fileName)
148 {
149         __fileName = fileName;
150 }
151
152 String
153 _DownloadRequestImpl::GetUrl(void) const
154 {
155         return __url;
156 }
157
158 String
159 _DownloadRequestImpl::GetDirectoryPath(void) const
160 {
161         return __dirPath;
162 }
163
164 String
165 _DownloadRequestImpl::GetFileName(void) const
166 {
167         return __fileName;
168 }
169
170 void
171 _DownloadRequestImpl::SetNotification(bool enable)
172 {
173         __notification = enable;
174 }
175
176 result
177 _DownloadRequestImpl::SetNotificationExtraData(const IMap* pExtraData)
178 {
179         String* pKey = null;
180         String* pValue = null;
181         result r = E_SUCCESS;
182
183         std::unique_ptr<IMapEnumerator> pMapEnum(const_cast< IMap* >(pExtraData)->GetMapEnumeratorN());
184         while (pMapEnum->MoveNext() == E_SUCCESS)
185         {
186                 pKey = dynamic_cast< String* >(pMapEnum->GetKey());
187                 SysTryReturnResult(NID_CNT, pKey != null, E_INVALID_ARG, "The object is not a String class.");
188
189                 pValue = dynamic_cast< String* >(pMapEnum->GetValue());
190                 SysTryReturnResult(NID_CNT, pValue != null, E_INVALID_ARG, "The object is not a String class.");
191
192                 r = __notifyExtraData.Add(new String(*pKey), new String(*pValue));
193         }
194         return r;
195 }
196
197 void
198 _DownloadRequestImpl::SetNetworkType(DownloadNetworkType type)
199 {
200         __networkType = type;
201 }
202
203 bool
204 _DownloadRequestImpl::IsNotificationEnabled(void) const
205 {
206         return __notification;
207 }
208
209 const IMap*
210 _DownloadRequestImpl::GetNotificationExtraData(void) const
211 {
212         return &__notifyExtraData;
213 }
214
215 DownloadNetworkType
216 _DownloadRequestImpl::GetNetworkType(void) const
217 {
218         return __networkType;
219 }
220
221 result
222 _DownloadRequestImpl::AddRequestHeader(const String& field, const String& value)
223 {
224         SysTryReturnResult(NID_CNT, !field.IsEmpty(), E_INVALID_ARG, "The field is empty.");
225         SysTryReturnResult(NID_CNT, !__requestHeader.ContainsKey(field), E_INVALID_ARG, "The field already exist.");
226         return __requestHeader.Add(new String(field), new String(value));
227 }
228
229 result
230 _DownloadRequestImpl::SetRequestHeader(const String& field, const String& value)
231 {
232         SysTryReturnResult(NID_CNT, !field.IsEmpty(), E_INVALID_ARG, "The field is empty.");
233         SysTryReturnResult(NID_CNT, __requestHeader.ContainsKey(field), E_INVALID_ARG, "The field does not exist.");
234         return __requestHeader.SetValue(field, new String(value));
235 }
236
237 result
238 _DownloadRequestImpl::RemoveRequestHeader(const String& field)
239 {
240         SysTryReturnResult(NID_CNT, !field.IsEmpty(), E_INVALID_ARG, "The field is empty.");
241         SysTryReturnResult(NID_CNT, __requestHeader.ContainsKey(field), E_INVALID_ARG, "The field does not exist.");
242         return __requestHeader.Remove(field);
243 }
244
245 String*
246 _DownloadRequestImpl::GetRequestHeaderN(const String& field)
247 {
248         String* pValue = null;
249         String* pKey = null;
250         IMapEnumerator* pMapEnum = null;
251
252         pMapEnum = __requestHeader.GetMapEnumeratorN();
253         while (pMapEnum->MoveNext() == E_SUCCESS)
254         {
255                 pKey = static_cast< String* > (pMapEnum->GetKey());
256                 if (*pKey == field)
257                 {
258                         pValue = new String (*(static_cast< String* > (pMapEnum->GetValue())));
259                         SysTryReturn(NID_CNT, pValue != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
260                         break;
261                 }
262         }
263
264         delete pMapEnum;
265         return pValue; 
266 }
267
268 _DownloadRequestImpl*
269 _DownloadRequestImpl::GetInstance(const DownloadRequest* pRequest)
270 {
271         return pRequest->__pDownloadRequestImpl;
272 }
273
274 IMap*
275 _DownloadRequestImpl::GetRequestHeader(void)
276 {
277         return &__requestHeader;
278 }
279
280 } } // Tizen::Content