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::Param::operator==(const Param& other) const
208 return name == other.name && value == other.value;
211 bool ConfigParserData::Param::operator!=(const Param& other) const
213 return name != other.name || value != other.value;
216 bool ConfigParserData::Param::operator >(const Param& other) const
218 if (name == other.name) {
219 return value > other.value;
221 return name > other.name;
225 bool ConfigParserData::Param::operator>=(const Param& other) const
227 if (name >= other.name) {
230 return value >= other.value;
234 bool ConfigParserData::Param::operator <(const Param& other) const
236 if (name == other.name) {
237 return value < other.value;
239 return name < other.name;
243 bool ConfigParserData::Param::operator<=(const Param& other) const
245 if (name <= other.name) {
248 return value <= other.value;
252 bool ConfigParserData::Feature::operator==(const Feature& other) const
254 return name == other.name && paramsList == other.paramsList;
257 bool ConfigParserData::Feature::operator!=(const Feature& other) const
259 return name != other.name || paramsList != other.paramsList;
262 bool ConfigParserData::Feature::operator >(const Feature& other) const
264 if (name > other.name) {
267 if (name < other.name) {
270 return paramsList > other.paramsList;
273 bool ConfigParserData::Feature::operator>=(const Feature& other) const
275 if (name > other.name) {
278 if (name < other.name) {
281 return paramsList >= other.paramsList;
284 bool ConfigParserData::Feature::operator <(const Feature& other) const
286 if (name < other.name) {
289 if (name > other.name) {
292 return paramsList < other.paramsList;
295 bool ConfigParserData::Feature::operator<=(const Feature& other) const
297 if (name < other.name) {
300 if (name > other.name) {
303 return paramsList <= other.paramsList;
306 bool ConfigParserData::Privilege::operator==(const Privilege& other) const
308 return name == other.name;
311 bool ConfigParserData::Privilege::operator!=(const Privilege& other) const
313 return name != other.name;
316 bool ConfigParserData::Privilege::operator >(const Privilege& other) const
318 return name > other.name;
321 bool ConfigParserData::Privilege::operator>=(const Privilege& other) const
323 return name >= other.name;
326 bool ConfigParserData::Privilege::operator <(const Privilege& other) const
328 return name < other.name;
331 bool ConfigParserData::Privilege::operator<=(const Privilege& other) const
333 return name < other.name;
336 bool ConfigParserData::Icon::operator==(const Icon& other) const
338 return src == other.src;
341 bool ConfigParserData::Icon::operator!=(const Icon& other) const
343 return src != other.src;
346 bool ConfigParserData::Icon::operator >(const Icon& other) const
348 return src > other.src;
351 bool ConfigParserData::Icon::operator>=(const Icon& other) const
353 return src >= other.src;
356 bool ConfigParserData::Icon::operator <(const Icon& other) const
358 return src < other.src;
361 bool ConfigParserData::Icon::operator<=(const Icon& other) const
363 return src <= other.src;
366 bool ConfigParserData::Preference::operator==(const Preference& other) const
368 return name == other.name;
371 bool ConfigParserData::Preference::operator!=(const Preference& other) const
373 return name != other.name;
376 bool ConfigParserData::Preference::operator >(const Preference& other) const
378 return name > other.name;
381 bool ConfigParserData::Preference::operator>=(const Preference& other) const
383 return name >= other.name;
386 bool ConfigParserData::Preference::operator <(const Preference& other) const
388 return name < other.name;
391 bool ConfigParserData::Preference::operator<=(const Preference& other) const
393 return name <= other.name;
396 bool ConfigParserData::AccessInfo::operator== (const AccessInfo& info) const
398 return m_strIRI == info.m_strIRI && m_bSubDomainAccess ==
399 info.m_bSubDomainAccess;
402 bool ConfigParserData::AccessInfo::operator!= (const AccessInfo& info) const
404 return m_strIRI != info.m_strIRI || m_bSubDomainAccess !=
405 info.m_bSubDomainAccess;
408 bool ConfigParserData::AccessInfo::operator <(const AccessInfo& info) const
410 if (m_strIRI == info.m_strIRI) {
411 return m_bSubDomainAccess < info.m_bSubDomainAccess;
413 return m_strIRI < info.m_strIRI;
417 bool ConfigParserData::Setting::operator==(const Setting& other) const
419 return m_name == other.m_name &&
420 m_value == other.m_value;
423 bool ConfigParserData::Setting::operator!=(const Setting& other) const
425 return m_name != other.m_name ||
426 m_value != other.m_value;
429 bool ConfigParserData::Setting::operator >(const Setting& other) const
431 return m_name > other.m_name;
434 bool ConfigParserData::Setting::operator>=(const Setting& other) const
436 return m_name >= other.m_name;
439 bool ConfigParserData::Setting::operator <(const Setting& other) const
441 return m_name < other.m_name;
444 bool ConfigParserData::Setting::operator<=(const Setting& other) const
446 return m_name <= other.m_name;
449 bool ConfigParserData::ServiceInfo::operator== (const ServiceInfo& info) const
451 return m_src == info.m_src &&
452 m_operation == info.m_operation &&
453 m_scheme == info.m_scheme &&
454 m_mime == info.m_mime &&
455 m_disposition == info.m_disposition;
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 &&
464 m_disposition != info.m_disposition;
467 bool ConfigParserData::LiveboxInfo::operator==(const LiveboxInfo& other) const
469 return m_liveboxId == other.m_liveboxId &&
470 m_autoLaunch == other.m_autoLaunch &&
471 m_updatePeriod == other.m_updatePeriod &&
472 m_primary == other.m_primary &&
473 m_label == other.m_label &&
474 m_icon == other.m_icon;
477 bool ConfigParserData::LiveboxInfo::operator!=(const LiveboxInfo& other) const
479 return m_liveboxId != other.m_liveboxId &&
480 m_autoLaunch != other.m_autoLaunch &&
481 m_updatePeriod != other.m_updatePeriod &&
482 m_primary != other.m_primary &&
483 m_label != other.m_label &&
484 m_icon != other.m_icon;