Kodi Development 22.0
for Binary and Script based Add-Ons
 
Loading...
Searching...
No Matches
Network.h
1/*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9#pragma once
10
11#include "AddonBase.h"
12#include "c-api/network.h"
13
14#ifdef __cplusplus
15
16//==============================================================================
25//------------------------------------------------------------------------------
26
27namespace kodi
28{
29namespace network
30{
31
32//============================================================================
39inline bool ATTR_DLL_LOCAL WakeOnLan(const std::string& mac)
40{
41 using namespace ::kodi::addon;
42
43 return CPrivateBase::m_interface->toKodi->kodi_network->wake_on_lan(
44 CPrivateBase::m_interface->toKodi->kodiBase, mac.c_str());
45}
46//----------------------------------------------------------------------------
47
48//============================================================================
66inline std::string ATTR_DLL_LOCAL GetIPAddress()
67{
68 using namespace ::kodi::addon;
69
70 std::string ip;
71 char* string = CPrivateBase::m_interface->toKodi->kodi_network->get_ip_address(
72 CPrivateBase::m_interface->toKodi->kodiBase);
73 if (string != nullptr)
74 {
75 ip = string;
76 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
77 string);
78 }
79 return ip;
80}
81//----------------------------------------------------------------------------
82
83//============================================================================
101inline std::string ATTR_DLL_LOCAL GetHostname()
102{
103 using namespace ::kodi::addon;
104
105 std::string ip;
106 char* string = CPrivateBase::m_interface->toKodi->kodi_network->get_hostname(
107 CPrivateBase::m_interface->toKodi->kodiBase);
108 if (string != nullptr)
109 {
110 ip = string;
111 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
112 string);
113 }
114 return ip;
115}
116//----------------------------------------------------------------------------
117
118//============================================================================
137inline std::string ATTR_DLL_LOCAL GetUserAgent()
138{
139 using namespace ::kodi::addon;
140
141 std::string agent;
142 char* string = CPrivateBase::m_interface->toKodi->kodi_network->get_user_agent(
143 CPrivateBase::m_interface->toKodi->kodiBase);
144 if (string != nullptr)
145 {
146 agent = string;
147 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
148 string);
149 }
150 return agent;
151}
152//----------------------------------------------------------------------------
153
154//============================================================================
173inline bool ATTR_DLL_LOCAL IsLocalHost(const std::string& hostname)
174{
175 using namespace ::kodi::addon;
176
177 return CPrivateBase::m_interface->toKodi->kodi_network->is_local_host(
178 CPrivateBase::m_interface->toKodi->kodiBase, hostname.c_str());
179}
180//----------------------------------------------------------------------------
181
182//==============================================================================
190inline bool ATTR_DLL_LOCAL IsHostOnLAN(const std::string& hostname, bool offLineCheck = false)
191{
192 using namespace kodi::addon;
193
194 return CPrivateBase::m_interface->toKodi->kodi_network->is_host_on_lan(
195 CPrivateBase::m_interface->toKodi->kodiBase, hostname.c_str(), offLineCheck);
196}
197//------------------------------------------------------------------------------
198
199//============================================================================
224inline std::string ATTR_DLL_LOCAL URLEncode(const std::string& url)
225{
226 using namespace ::kodi::addon;
227
228 std::string retString;
229 char* string = CPrivateBase::m_interface->toKodi->kodi_network->url_encode(
230 CPrivateBase::m_interface->toKodi->kodiBase, url.c_str());
231 if (string != nullptr)
232 {
233 retString = string;
234 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
235 string);
236 }
237 return retString;
238}
239//----------------------------------------------------------------------------
240
241//============================================================================
267inline bool ATTR_DLL_LOCAL DNSLookup(const std::string& hostName, std::string& ipAddress)
268{
269 using namespace ::kodi::addon;
270
271 bool ret = false;
272 char* string = CPrivateBase::m_interface->toKodi->kodi_network->dns_lookup(
273 CPrivateBase::m_interface->toKodi->kodiBase, hostName.c_str(), &ret);
274 if (string != nullptr)
275 {
276 ipAddress = string;
277 CPrivateBase::m_interface->toKodi->free_string(CPrivateBase::m_interface->toKodi->kodiBase,
278 string);
279 }
280 return ret;
281}
282//----------------------------------------------------------------------------
283
284} /* namespace network */
285} /* namespace kodi */
286
287#endif /* __cplusplus */
std::string ATTR_DLL_LOCAL URLEncode(const std::string &url)
URL encodes the given string.
Definition Network.h:224
std::string ATTR_DLL_LOCAL GetIPAddress()
To the current own ip address as a string.
Definition Network.h:66
bool ATTR_DLL_LOCAL WakeOnLan(const std::string &mac)
Send WakeOnLan magic packet.
Definition Network.h:39
bool ATTR_DLL_LOCAL IsLocalHost(const std::string &hostname)
Check given name or ip address corresponds to localhost.
Definition Network.h:173
bool ATTR_DLL_LOCAL IsHostOnLAN(const std::string &hostname, bool offLineCheck=false)
Checks whether the specified path refers to a local network.
Definition Network.h:190
std::string ATTR_DLL_LOCAL GetHostname()
Return our hostname.
Definition Network.h:101
bool ATTR_DLL_LOCAL DNSLookup(const std::string &hostName, std::string &ipAddress)
Lookup URL in DNS cache.
Definition Network.h:267
std::string ATTR_DLL_LOCAL GetUserAgent()
Returns Kodi's HTTP UserAgent string.
Definition Network.h:137