tizen beta release
[framework/web/wrt-installer.git] / src / configuration_parser / libiriwrapper.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file        libiriwrapper.cpp
18  * @author      Piotr Marcinkiewicz (p.marcinkiew@samsung.com
19  * @version     0.1
20  * @brief       Libiri parser wrapper
21  */
22 #include <stdlib.h>
23 #include <iri.h>
24 #include "libiriwrapper.h"
25
26 //TODO: Design and implement new IRI manager class
27
28 namespace LibIri {
29 Wrapper::Wrapper(const char* aIri) : m_Iri(iri_parse(aIri))
30 {
31 }
32 Wrapper::~Wrapper()
33 {
34     iri_destroy(m_Iri);
35 }
36 //! \brief Returns true if iri is valid
37 bool Wrapper::Validate()
38 {
39     return
40         m_Iri != NULL &&
41         m_Iri->scheme != NULL && (
42             m_Iri->display != NULL ||
43             m_Iri->user != NULL ||
44             m_Iri->auth != NULL ||
45             m_Iri->password != NULL ||
46             m_Iri->host != NULL ||
47             m_Iri->path != NULL ||
48             m_Iri->query != NULL ||
49             m_Iri->anchor != NULL ||
50             m_Iri->qparams != NULL ||
51             m_Iri->schemelist != NULL);
52 }
53
54 std::ostream & operator<<(std::ostream& a_stream,
55         const Wrapper& a_wrapper)
56 {
57     iri_t& iri = *a_wrapper.m_Iri;
58 #define PRINT_FIELD(field) "] " # field " [" << (iri.field ? iri.field : "null")
59     a_stream <<
60     " display [" << (iri.display ? iri.display : "null") <<
61     PRINT_FIELD(scheme) <<
62     PRINT_FIELD(user) <<
63     PRINT_FIELD(auth) <<
64     PRINT_FIELD(password) <<
65     PRINT_FIELD(host) <<
66     "] port [" << (iri.port ? iri.port : -1) <<
67     PRINT_FIELD(path) <<
68     PRINT_FIELD(query) <<
69     PRINT_FIELD(anchor) <<
70     "]";
71     return a_stream;
72 #undef PRINT_FIELD
73 }
74 } //namespace LibIri