summaryrefslogtreecommitdiff
path: root/include/modules/geolocation.h
blob: f6363ba401e85a966c55ac9f5986691f043c9231 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * InspIRCd -- Internet Relay Chat Daemon
 *
 *   Copyright (C) 2019 Sadie Powell <sadie@witchery.services>
 *
 * This file is part of InspIRCd.  InspIRCd is free software: you can
 * redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, version 2.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


#pragma once

namespace Geolocation
{
	class APIBase;
	class API;
	class Location;
}

class Geolocation::APIBase : public DataProvider
{
 public:
	APIBase(Module* parent)
		: DataProvider(parent, "geolocationapi")
	{
	}

	/** Looks up the location of the specified user.
	 * @param user The user to look up the location of.
	 * @return Either an instance of the Location class or NULL if no location could be found.
	 */
	virtual Location* GetLocation(User* user) = 0;

	/** Looks up the location of the specified IP address.
	 * @param sa The IP address to look up the location of.
	 * @return Either an instance of the Location class or NULL if no location could be found.
	 */
	virtual Location* GetLocation(irc::sockets::sockaddrs& sa) = 0;
};

class Geolocation::API : public dynamic_reference<Geolocation::APIBase>
{
 public:
	API(Module* parent)
		: dynamic_reference<Geolocation::APIBase>(parent, "geolocationapi")
	{
	}
};

class Geolocation::Location : public usecountbase
{
private:
	/** The two character country code for this location. */
	std::string code;

	/** The country name for this location. */
	std::string name;

 public:
	Location(const std::string& Code, const std::string& Name)
		: code(Code)
		, name(Name)
	{
	}

	/** Retrieves the two character country code for this location. */
	std::string GetCode() const { return code; }

	/** Retrieves the country name for this location. */
	std::string GetName() const { return name; }
};