2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file config_parser_data.cpp
18 * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
23 #include <dpl/wrt-dao-ro/config_parser_data.h>
24 #include <dpl/log/log.h>
25 #include <libxml/xmlreader.h>
26 #include <libxml/xmlstring.h>
29 bool IsSpace(const xmlChar* str);
30 bool CopyChar(xmlChar* out, xmlChar* in);
32 bool IsSpace(const xmlChar* str)
34 int charlen = xmlUTF8Size(str);
65 unsigned char c2 = *(str + 1);
66 unsigned char c3 = *(str + 2);
67 if ((c2 == 0x9a && c3 == 0x80) || (c2 == 0xa0 && c3 == 0x8e)) {
97 if (*(str + 2) == 0x9f) {
107 if (*(str + 1) == 0x80 && *(str + 2) == 0x80) {
122 bool CopyChar(xmlChar* out,
125 int size = xmlUTF8Size(in);
146 //TODO temporary fix until commits the rewrite of this functionality.
147 void NormalizeString(DPL::String& str)
149 DPL::Optional<DPL::String> opt = str;
150 NormalizeString(opt);
154 void NormalizeString (DPL::Optional<DPL::String>& txt, bool isTrimSpace)
157 std::string tmp = DPL::ToUTF8String(*txt);
158 const xmlChar* str = reinterpret_cast<const xmlChar*>(tmp.c_str());
159 if (!xmlCheckUTF8(str)) {
160 LogError("Not valid UTF8");
166 while ((c = const_cast<xmlChar*>(xmlUTF8Strpos(str, i))) != NULL) {
173 xmlChar* tmpnew = xmlUTF8Strndup(c, xmlUTF8Strlen(c) + 1);
176 while ((c = const_cast<xmlChar*>(xmlUTF8Strpos(str, i))) != NULL) {
184 if (first && !isTrimSpace) {
185 xmlChar space[6] = { 0x20 };
196 txt = DPL::FromUTF8String(reinterpret_cast<char*>(tmpnew));
201 void NormalizeAndTrimSpaceString(DPL::OptionalString& txt)
203 NormalizeString(txt, true);
206 bool ConfigParserData::Feature::operator==(const Feature& other) const
208 return name == other.name;
211 bool ConfigParserData::Feature::operator!=(const Feature& other) const
213 return name != other.name;
216 bool ConfigParserData::Feature::operator >(const Feature& other) const
218 return name > other.name;
221 bool ConfigParserData::Feature::operator>=(const Feature& other) const
223 return name >= other.name;
226 bool ConfigParserData::Feature::operator <(const Feature& other) const
228 return name < other.name;
231 bool ConfigParserData::Feature::operator<=(const Feature& other) const
233 return name <= other.name;
236 bool ConfigParserData::Privilege::operator==(const Privilege& other) const
238 return name == other.name;
241 bool ConfigParserData::Privilege::operator!=(const Privilege& other) const
243 return name != other.name;
246 bool ConfigParserData::Privilege::operator >(const Privilege& other) const
248 return name > other.name;
251 bool ConfigParserData::Privilege::operator>=(const Privilege& other) const
253 return name >= other.name;
256 bool ConfigParserData::Privilege::operator <(const Privilege& other) const
258 return name < other.name;
261 bool ConfigParserData::Privilege::operator<=(const Privilege& other) const
263 return name < other.name;
266 bool ConfigParserData::Icon::operator==(const Icon& other) const
268 return src == other.src;
271 bool ConfigParserData::Icon::operator!=(const Icon& other) const
273 return src != other.src;
276 bool ConfigParserData::Icon::operator >(const Icon& other) const
278 return src > other.src;
281 bool ConfigParserData::Icon::operator>=(const Icon& other) const
283 return src >= other.src;
286 bool ConfigParserData::Icon::operator <(const Icon& other) const
288 return src < other.src;
291 bool ConfigParserData::Icon::operator<=(const Icon& other) const
293 return src <= other.src;
296 bool ConfigParserData::Preference::operator==(const Preference& other) const
298 return name == other.name;
301 bool ConfigParserData::Preference::operator!=(const Preference& other) const
303 return name != other.name;
306 bool ConfigParserData::Preference::operator >(const Preference& other) const
308 return name > other.name;
311 bool ConfigParserData::Preference::operator>=(const Preference& other) const
313 return name >= other.name;
316 bool ConfigParserData::Preference::operator <(const Preference& other) const
318 return name < other.name;
321 bool ConfigParserData::Preference::operator<=(const Preference& other) const
323 return name <= other.name;
326 bool ConfigParserData::AccessInfo::operator== (const AccessInfo& info) const
328 return m_strIRI == info.m_strIRI && m_bSubDomainAccess ==
329 info.m_bSubDomainAccess;
332 bool ConfigParserData::AccessInfo::operator!= (const AccessInfo& info) const
334 return m_strIRI != info.m_strIRI || m_bSubDomainAccess !=
335 info.m_bSubDomainAccess;
338 bool ConfigParserData::AccessInfo::operator <(const AccessInfo& info) const
340 if (m_strIRI == info.m_strIRI) {
341 return m_bSubDomainAccess < info.m_bSubDomainAccess;
343 return m_strIRI < info.m_strIRI;
347 bool ConfigParserData::Setting::operator==(const Setting& other) const
349 return m_name == other.m_name &&
350 m_value == other.m_value;
353 bool ConfigParserData::Setting::operator!=(const Setting& other) const
355 return m_name != other.m_name ||
356 m_value != other.m_value;
359 bool ConfigParserData::Setting::operator >(const Setting& other) const
361 return m_name > other.m_name;
364 bool ConfigParserData::Setting::operator>=(const Setting& other) const
366 return m_name >= other.m_name;
369 bool ConfigParserData::Setting::operator <(const Setting& other) const
371 return m_name < other.m_name;
374 bool ConfigParserData::Setting::operator<=(const Setting& other) const
376 return m_name <= other.m_name;
379 bool ConfigParserData::AppControlInfo::operator== (const AppControlInfo& info) const
381 return m_src == info.m_src &&
382 m_operation == info.m_operation &&
383 m_uriList == info.m_uriList &&
384 m_mimeList == info.m_mimeList &&
385 m_disposition == info.m_disposition;
388 bool ConfigParserData::AppControlInfo::operator!= (const AppControlInfo& info) const
390 return m_src != info.m_src ||
391 m_operation != info.m_operation ||
392 m_uriList != info.m_uriList ||
393 m_mimeList != info.m_mimeList ||
394 m_disposition != info.m_disposition;
397 bool ConfigParserData::LiveboxInfo::operator==(const LiveboxInfo& other) const
399 return m_liveboxId == other.m_liveboxId &&
400 m_autoLaunch == other.m_autoLaunch &&
401 m_updatePeriod == other.m_updatePeriod &&
402 m_primary == other.m_primary &&
403 m_label == other.m_label &&
404 m_icon == other.m_icon;
407 bool ConfigParserData::LiveboxInfo::operator!=(const LiveboxInfo& other) const
409 return m_liveboxId != other.m_liveboxId &&
410 m_autoLaunch != other.m_autoLaunch &&
411 m_updatePeriod != other.m_updatePeriod &&
412 m_primary != other.m_primary &&
413 m_label != other.m_label &&
414 m_icon != other.m_icon;
417 bool ConfigParserData::Metadata::operator== (const Metadata& other) const
419 return key == other.key && value == other.value;
422 bool ConfigParserData::Metadata::operator!= (const Metadata& other) const
424 return key != other.key || value != other.value;