6d8de2a92d0017fc4c5dd96670767d839dab202d
[framework/web/wrt-installer.git] / src_mobile / 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 Wrapper::~Wrapper()
32 {
33     iri_destroy(m_Iri);
34 }
35 //! \brief Returns true if iri is valid
36 bool Wrapper::Validate()
37 {
38     return
39         m_Iri != NULL &&
40         m_Iri->scheme != NULL && (
41             m_Iri->display != NULL ||
42             m_Iri->user != NULL ||
43             m_Iri->auth != NULL ||
44             m_Iri->password != NULL ||
45             m_Iri->host != NULL ||
46             m_Iri->path != NULL ||
47             m_Iri->query != NULL ||
48             m_Iri->anchor != NULL ||
49             m_Iri->qparams != NULL ||
50             m_Iri->schemelist != NULL);
51 }
52
53 std::ostream & operator<<(std::ostream& a_stream,
54                           const Wrapper& a_wrapper)
55 {
56     iri_t& iri = *a_wrapper.m_Iri;
57 #define PRINT_FIELD(field) "] " #field " [" << (iri.field ? iri.field : "null")
58     a_stream <<
59     " display [" << (iri.display ? iri.display : "null") <<
60     PRINT_FIELD(scheme) <<
61     PRINT_FIELD(user) <<
62     PRINT_FIELD(auth) <<
63     PRINT_FIELD(password) <<
64     PRINT_FIELD(host) <<
65     "] port [" << (iri.port ? iri.port : -1) <<
66     PRINT_FIELD(path) <<
67     PRINT_FIELD(query) <<
68     PRINT_FIELD(anchor) <<
69     "]";
70     return a_stream;
71 #undef PRINT_FIELD
72 }
73 } //namespace LibIri