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);
33 bool IsSpace(const xmlChar* str)
35 int charlen = xmlUTF8Size(str);
66 unsigned char c2 = *(str + 1);
67 unsigned char c3 = *(str + 2);
68 if ((c2 == 0x9a && c3 == 0x80) || (c2 == 0xa0 && c3 == 0x8e)) {
98 if (*(str + 2) == 0x9f) {
108 if (*(str + 1) == 0x80 && *(str + 2) == 0x80) {
123 bool CopyChar(xmlChar* out,
126 int size = xmlUTF8Size(in);
147 //TODO temporary fix until commits the rewrite of this functionality.
148 void NormalizeString(DPL::String& str)
150 DPL::Optional<DPL::String> opt = str;
151 NormalizeString(opt);
155 void NormalizeString (DPL::Optional<DPL::String>& txt, bool isTrimSpace)
158 std::string tmp = DPL::ToUTF8String(*txt);
159 const xmlChar* str = reinterpret_cast<const xmlChar*>(tmp.c_str());
160 if (!xmlCheckUTF8(str)) {
161 LogError("Not valid UTF8");
167 while ((c = const_cast<xmlChar*>(xmlUTF8Strpos(str, i))) != NULL) {
174 xmlChar* tmpnew = xmlUTF8Strndup(c, xmlUTF8Strlen(c) + 1);
177 while ((c = const_cast<xmlChar*>(xmlUTF8Strpos(str, i))) != NULL) {
185 if (first && !isTrimSpace) {
186 xmlChar space[6] = { 0x20 };
197 txt = DPL::FromUTF8String(reinterpret_cast<char*>(tmpnew));
202 void NormalizeAndTrimSpaceString(DPL::OptionalString& txt)
204 NormalizeString(txt, true);
207 bool ConfigParserData::Param::operator==(const Param& other) const
209 return name == other.name && value == other.value;
212 bool ConfigParserData::Param::operator!=(const Param& other) const
214 return name != other.name || value != other.value;
217 bool ConfigParserData::Param::operator >(const Param& other) const
219 if (name == other.name) {
220 return value > other.value;
222 return name > other.name;
226 bool ConfigParserData::Param::operator>=(const Param& other) const
228 if (name >= other.name) {
231 return value >= other.value;
235 bool ConfigParserData::Param::operator <(const Param& other) const
237 if (name == other.name) {
238 return value < other.value;
240 return name < other.name;
244 bool ConfigParserData::Param::operator<=(const Param& other) const
246 if (name <= other.name) {
249 return value <= other.value;
253 bool ConfigParserData::Feature::operator==(const Feature& other) const
255 return name == other.name && paramsList == other.paramsList;
258 bool ConfigParserData::Feature::operator!=(const Feature& other) const
260 return name != other.name || paramsList != other.paramsList;
263 bool ConfigParserData::Feature::operator >(const Feature& other) const
265 if (name > other.name) {
268 if (name < other.name) {
271 return paramsList > other.paramsList;
274 bool ConfigParserData::Feature::operator>=(const Feature& other) const
276 if (name > other.name) {
279 if (name < other.name) {
282 return paramsList >= other.paramsList;
285 bool ConfigParserData::Feature::operator <(const Feature& other) const
287 if (name < other.name) {
290 if (name > other.name) {
293 return paramsList < other.paramsList;
296 bool ConfigParserData::Feature::operator<=(const Feature& other) const
298 if (name < other.name) {
301 if (name > other.name) {
304 return paramsList <= other.paramsList;
307 bool ConfigParserData::Privilege::operator==(const Privilege& other) const
309 return name == other.name;
312 bool ConfigParserData::Privilege::operator!=(const Privilege& other) const
314 return name != other.name;
317 bool ConfigParserData::Privilege::operator >(const Privilege& other) const
319 return name > other.name;
322 bool ConfigParserData::Privilege::operator>=(const Privilege& other) const
324 return name >= other.name;
327 bool ConfigParserData::Privilege::operator <(const Privilege& other) const
329 return name < other.name;
332 bool ConfigParserData::Privilege::operator<=(const Privilege& other) const
334 return name < other.name;
337 bool ConfigParserData::Icon::operator==(const Icon& other) const
339 return src == other.src;
342 bool ConfigParserData::Icon::operator!=(const Icon& other) const
344 return src != other.src;
347 bool ConfigParserData::Icon::operator >(const Icon& other) const
349 return src > other.src;
352 bool ConfigParserData::Icon::operator>=(const Icon& other) const
354 return src >= other.src;
357 bool ConfigParserData::Icon::operator <(const Icon& other) const
359 return src < other.src;
362 bool ConfigParserData::Icon::operator<=(const Icon& other) const
364 return src <= other.src;
367 bool ConfigParserData::Preference::operator==(const Preference& other) const
369 return name == other.name;
372 bool ConfigParserData::Preference::operator!=(const Preference& other) const
374 return name != other.name;
377 bool ConfigParserData::Preference::operator >(const Preference& other) const
379 return name > other.name;
382 bool ConfigParserData::Preference::operator>=(const Preference& other) const
384 return name >= other.name;
387 bool ConfigParserData::Preference::operator <(const Preference& other) const
389 return name < other.name;
392 bool ConfigParserData::Preference::operator<=(const Preference& other) const
394 return name <= other.name;
397 bool ConfigParserData::AccessInfo::operator== (const AccessInfo& info) const
399 return m_strIRI == info.m_strIRI && m_bSubDomainAccess ==
400 info.m_bSubDomainAccess;
403 bool ConfigParserData::AccessInfo::operator!= (const AccessInfo& info) const
405 return m_strIRI != info.m_strIRI || m_bSubDomainAccess !=
406 info.m_bSubDomainAccess;
409 bool ConfigParserData::AccessInfo::operator <(const AccessInfo& info) const
411 if (m_strIRI == info.m_strIRI) {
412 return m_bSubDomainAccess < info.m_bSubDomainAccess;
414 return m_strIRI < info.m_strIRI;
418 bool ConfigParserData::Setting::operator==(const Setting& other) const
420 return m_name == other.m_name &&
421 m_value == other.m_value;
424 bool ConfigParserData::Setting::operator!=(const Setting& other) const
426 return m_name != other.m_name ||
427 m_value != other.m_value;
430 bool ConfigParserData::Setting::operator >(const Setting& other) const
432 return m_name > other.m_name;
435 bool ConfigParserData::Setting::operator>=(const Setting& other) const
437 return m_name >= other.m_name;
440 bool ConfigParserData::Setting::operator <(const Setting& other) const
442 return m_name < other.m_name;
445 bool ConfigParserData::Setting::operator<=(const Setting& other) const
447 return m_name <= other.m_name;
450 bool ConfigParserData::ServiceInfo::operator== (const ServiceInfo& info) const
452 return m_src == info.m_src &&
453 m_operation == info.m_operation &&
454 m_scheme == info.m_scheme &&
455 m_mime == info.m_mime;
458 bool ConfigParserData::ServiceInfo::operator!= (const ServiceInfo& info) const
460 return m_src != info.m_src &&
461 m_operation != info.m_operation &&
462 m_scheme != info.m_scheme &&
463 m_mime != info.m_mime;
466 bool ConfigParserData::LiveboxInfo::operator==(const LiveboxInfo& other) const
468 return m_liveboxId == other.m_liveboxId &&
469 m_autoLaunch == other.m_autoLaunch &&
470 m_updatePeriod == other.m_updatePeriod &&
471 m_primary == other.m_primary &&
472 m_label == other.m_label &&
473 m_icon == other.m_icon;
476 bool ConfigParserData::LiveboxInfo::operator!=(const LiveboxInfo& other) const
478 return m_liveboxId != other.m_liveboxId &&
479 m_autoLaunch != other.m_autoLaunch &&
480 m_updatePeriod != other.m_updatePeriod &&
481 m_primary != other.m_primary &&
482 m_label != other.m_label &&
483 m_icon != other.m_icon;