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.
18 * @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
22 #include "WacOrigin.h"
28 #include <<dpl/log/log.h>>
31 #include "ValidatorCommon.h"
34 const std::string SCHEME_HTTP = "http";
35 const std::string SCHEME_HTTPS = "https";
36 const int PORT_HTTP = 80;
37 const int PORT_HTTPS = 443;
40 namespace ValidationCore {
41 VC_DECLARE_DELETER(iri_struct, iri_destroy)
43 WacOrigin::WacOrigin(const std::string &url) :
50 WacOrigin::WacOrigin(const char *url) :
57 bool WacOrigin::operator==(const WacOrigin &second) const
59 if (m_parseFailed || second.m_parseFailed) {
63 return (m_scheme == second.m_scheme) &&
64 (m_host == second.m_host) &&
65 (m_port == second.m_port);
68 void WacOrigin::parse(const char *url)
70 // Step are taken from algorihtm:
71 // http://www.w3.org/TR/html5/origin-0.html#origin-0
75 AutoPtr<iri_struct> iri(iri_parse(url));
82 m_scheme = iri->scheme;
88 // Step 3 - Skip this point.
89 // WAC 2.0 PRV - we are suport only "http" and "https" schemas.
94 std::transform(m_scheme.begin(), m_scheme.end(), m_scheme.begin(), tolower);
96 // Step 6 - we only support "http" and "https" schemas
97 if ((m_scheme != SCHEME_HTTP) && (m_scheme != SCHEME_HTTPS)) {
102 // Step 7 - Skip. We do not support "file" schema.
108 m_parseFailed = true;
115 idna_to_ascii_lz(m_host.c_str(), &output, IDNA_USE_STD3_ASCII_RULES)) {
116 LogError("libidn error");
117 m_parseFailed = true;
125 std::transform(m_host.begin(), m_host.end(), m_host.begin(), ::tolower);
134 // Step 12 - Skip it. We do not return anything.
135 // User should create geters if he need access to schema/host/port.
138 void WacOrigin::setPort()
140 if (SCHEME_HTTP == m_scheme) {
143 } else if (SCHEME_HTTPS == m_scheme) {
147 LogDebug("Scheme " << m_scheme << " is not support by WAC2.0");
148 m_parseFailed = true;
151 } // namespace ValidationCore