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 "wac_widget_id.h"
27 #include <dpl/log/log.h>
28 #include <dpl/string.h>
33 const char *SCHEME_HTTP = "http";
34 const char *SCHEME_HTTPS = "https";
37 WacWidgetId::WacWidgetId(const DPL::OptionalString &widgetId) :
40 if (!widgetId.IsNull()) {
41 std::string wid = DPL::ToUTF8String(*widgetId);
46 bool WacWidgetId::matchHost(const DPL::String &second) const
48 LogDebug("m_schemaMatch is: " << m_schemaMatch);
53 LogDebug("Matching DNS identity: " << m_host <<
54 " " << DPL::ToUTF8String(second));
56 return m_host == DPL::ToUTF8String(second);
59 void WacWidgetId::parse(const char *url)
61 LogDebug("Widget id to parse: " << url);
63 std::unique_ptr<iri_struct, std::function<void(iri_struct*)> >
64 iri(iri_parse(url), iri_destroy);
67 LogError("Error in parsing widget id.");
68 return; // m_schemaMatch == false;
73 if (iri.get()->scheme) {
74 scheme = iri.get()->scheme;
76 LogWarning("Error. No scheme in widget id.");
77 return; // m_schemaMatch == false;
80 // should we support HTTP and HTTPS? wac says nothing
81 // std::transform(m_scheme.begin(), m_scheme.end(), m_scheme.begin(),
84 // We only match "http" and "https" schemas
85 if ((scheme != SCHEME_HTTP) && (scheme != SCHEME_HTTPS)) {
86 LogWarning("Unknown scheme in widget id." << scheme);
87 return; // m_schemaMatch == false;
92 if (iri.get()->host) {
93 m_host = iri.get()->host;
94 LogDebug("Host has been set to: " << m_host);
97 // What to do when host is empty? No info in wac documentation.
99 // Any post processing algorithm? No info in wac documentation.