]> jfr.im git - irc/quakenet/newserv.git/blame - geoip/libGeoIP/GeoIP.h
CHANSERV: authtracker now keeps 240 days history
[irc/quakenet/newserv.git] / geoip / libGeoIP / GeoIP.h
CommitLineData
3193eda0
CP
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
2/* GeoIP.h
3 *
69793602 4 * Copyright (C) 2006 MaxMind LLC
3193eda0
CP
5 *
6 * This library is free software; you can redistribute it and/or
69793602 7 * modify it under the terms of the GNU Lesser General Public
3193eda0
CP
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
69793602 14 * Lesser General Public License for more details.
3193eda0 15 *
69793602 16 * You should have received a copy of the GNU Lesser General Public
3193eda0 17 * License along with this library; if not, write to the Free Software
69793602 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3193eda0
CP
19 */
20
21#ifndef GEOIP_H
22#define GEOIP_H
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
69793602
CP
28#include <sys/types.h>
29#include <sys/socket.h>
30#include <netinet/in.h>
31#include <arpa/inet.h>
32
3193eda0
CP
33#include<stdio.h>
34#include<stdlib.h>
35#include<string.h>
36#include <sys/types.h> /* for fstat */
37#include <sys/stat.h> /* for fstat */
38
39#define SEGMENT_RECORD_LENGTH 3
40#define STANDARD_RECORD_LENGTH 3
41#define ORG_RECORD_LENGTH 4
42#define MAX_RECORD_LENGTH 4
69793602
CP
43#define NUM_DB_TYPES 20
44
45/* 128 bit address in network order */
46typedef struct in6_addr geoipv6_t;
47
48#define GEOIP_CHKBIT_V6(bit,ptr) (ptr[((127UL - bit) >> 3)] & (1UL << (~(127 - bit) & 7)))
3193eda0
CP
49
50typedef struct GeoIPTag {
51 FILE *GeoIPDatabase;
52 char *file_path;
53 unsigned char *cache;
54 unsigned char *index_cache;
55 unsigned int *databaseSegments;
56 char databaseType;
57 time_t mtime;
58 int flags;
69793602 59 off_t size;
3193eda0 60 char record_length;
69793602 61 int charset; /* 0 iso-8859-1 1 utf8 */
3193eda0 62 int record_iter; /* used in GeoIP_next_record */
69793602
CP
63 int netmask; /* netmask of last lookup - set using depth in _GeoIP_seek_record */
64 time_t last_mtime_check;
3193eda0
CP
65} GeoIP;
66
69793602
CP
67
68typedef enum {
69 GEOIP_CHARSET_ISO_8859_1 = 0,
70 GEOIP_CHARSET_UTF8 = 1
71} GeoIPCharset;
72
3193eda0
CP
73typedef struct GeoIPRegionTag {
74 char country_code[3];
75 char region[3];
76} GeoIPRegion;
77
78typedef enum {
79 GEOIP_STANDARD = 0,
80 GEOIP_MEMORY_CACHE = 1,
81 GEOIP_CHECK_CACHE = 2,
69793602
CP
82 GEOIP_INDEX_CACHE = 4,
83 GEOIP_MMAP_CACHE = 8,
3193eda0
CP
84} GeoIPOptions;
85
86typedef enum {
87 GEOIP_COUNTRY_EDITION = 1,
88 GEOIP_REGION_EDITION_REV0 = 7,
89 GEOIP_CITY_EDITION_REV0 = 6,
90 GEOIP_ORG_EDITION = 5,
91 GEOIP_ISP_EDITION = 4,
92 GEOIP_CITY_EDITION_REV1 = 2,
93 GEOIP_REGION_EDITION_REV1 = 3,
94 GEOIP_PROXY_EDITION = 8,
95 GEOIP_ASNUM_EDITION = 9,
69793602
CP
96 GEOIP_NETSPEED_EDITION = 10,
97 GEOIP_DOMAIN_EDITION = 11,
98 GEOIP_COUNTRY_EDITION_V6 = 12,
3193eda0
CP
99} GeoIPDBTypes;
100
101typedef enum {
102 GEOIP_ANON_PROXY = 1,
103 GEOIP_HTTP_X_FORWARDED_FOR_PROXY = 2,
69793602 104 GEOIP_HTTP_CLIENT_IP_PROXY = 3,
3193eda0
CP
105} GeoIPProxyTypes;
106
107typedef enum {
108 GEOIP_UNKNOWN_SPEED = 0,
109 GEOIP_DIALUP_SPEED = 1,
110 GEOIP_CABLEDSL_SPEED = 2,
69793602 111 GEOIP_CORPORATE_SPEED = 3,
3193eda0
CP
112} GeoIPNetspeedValues;
113
114extern char **GeoIPDBFileName;
115extern const char * GeoIPDBDescription[NUM_DB_TYPES];
116extern const char *GeoIPCountryDBFileName;
117extern const char *GeoIPRegionDBFileName;
118extern const char *GeoIPCityDBFileName;
119extern const char *GeoIPOrgDBFileName;
120extern const char *GeoIPISPDBFileName;
121
69793602
CP
122/* Warning: do not use those arrays as doing so may break your
123 * program with newer GeoIP versions */
124extern const char GeoIP_country_code[253][3];
125extern const char GeoIP_country_code3[253][4];
126extern const char * GeoIP_country_name[253];
127extern const char GeoIP_country_continent[253][3];
3193eda0
CP
128
129#ifdef DLL
130#define GEOIP_API __declspec(dllexport)
131#else
132#define GEOIP_API
133#endif /* DLL */
134
69793602 135GEOIP_API void GeoIP_setup_custom_directory(char *dir);
3193eda0 136GEOIP_API GeoIP* GeoIP_open_type (int type, int flags);
69793602 137GEOIP_API GeoIP* GeoIP_new(int flags);
3193eda0
CP
138GEOIP_API GeoIP* GeoIP_open(const char * filename, int flags);
139GEOIP_API int GeoIP_db_avail(int type);
140GEOIP_API void GeoIP_delete(GeoIP* gi);
141GEOIP_API const char *GeoIP_country_code_by_addr (GeoIP* gi, const char *addr);
142GEOIP_API const char *GeoIP_country_code_by_name (GeoIP* gi, const char *host);
143GEOIP_API const char *GeoIP_country_code3_by_addr (GeoIP* gi, const char *addr);
144GEOIP_API const char *GeoIP_country_code3_by_name (GeoIP* gi, const char *host);
145GEOIP_API const char *GeoIP_country_name_by_addr (GeoIP* gi, const char *addr);
146GEOIP_API const char *GeoIP_country_name_by_name (GeoIP* gi, const char *host);
69793602 147GEOIP_API const char *GeoIP_country_name_by_ipnum (GeoIP* gi, unsigned long ipnum);
3193eda0 148GEOIP_API const char *GeoIP_country_code_by_ipnum (GeoIP* gi, unsigned long ipnum);
69793602
CP
149GEOIP_API const char *GeoIP_country_code3_by_ipnum (GeoIP* gi, unsigned long ipnum);
150
151/* */
152GEOIP_API const char *GeoIP_country_name_by_ipnum_v6 (GeoIP* gi, geoipv6_t ipnum);
153GEOIP_API const char *GeoIP_country_code_by_ipnum_v6 (GeoIP* gi, geoipv6_t ipnum);
154GEOIP_API const char *GeoIP_country_code3_by_ipnum_v6 (GeoIP* gi, geoipv6_t ipnum);
3193eda0
CP
155
156/* Deprecated - for backwards compatibility only */
157GEOIP_API int GeoIP_country_id_by_addr (GeoIP* gi, const char *addr);
158GEOIP_API int GeoIP_country_id_by_name (GeoIP* gi, const char *host);
159GEOIP_API char *GeoIP_org_by_addr (GeoIP* gi, const char *addr);
160GEOIP_API char *GeoIP_org_by_name (GeoIP* gi, const char *host);
69793602
CP
161GEOIP_API char *GeoIP_org_by_ipnum (GeoIP* gi, unsigned long ipnum);
162
163GEOIP_API char *GeoIP_org_by_ipnum_v6 (GeoIP* gi, geoipv6_t ipnum);
164GEOIP_API char *GeoIP_org_by_addr_v6 (GeoIP* gi, const char *addr);
165GEOIP_API char *GeoIP_org_by_name_v6 (GeoIP* gi, const char *name);
166
3193eda0
CP
167/* End deprecated */
168
169GEOIP_API int GeoIP_id_by_addr (GeoIP* gi, const char *addr);
170GEOIP_API int GeoIP_id_by_name (GeoIP* gi, const char *host);
171GEOIP_API int GeoIP_id_by_ipnum (GeoIP* gi, unsigned long ipnum);
172
69793602
CP
173GEOIP_API int GeoIP_id_by_addr_v6 (GeoIP* gi, const char *addr);
174GEOIP_API int GeoIP_id_by_name_v6 (GeoIP* gi, const char *host);
175GEOIP_API int GeoIP_id_by_ipnum_v6 (GeoIP* gi, geoipv6_t ipnum);
176
3193eda0
CP
177GEOIP_API GeoIPRegion * GeoIP_region_by_addr (GeoIP* gi, const char *addr);
178GEOIP_API GeoIPRegion * GeoIP_region_by_name (GeoIP* gi, const char *host);
69793602
CP
179GEOIP_API GeoIPRegion * GeoIP_region_by_ipnum (GeoIP *gi, unsigned long ipnum);
180
181GEOIP_API GeoIPRegion * GeoIP_region_by_addr_v6 (GeoIP* gi, const char *addr);
182GEOIP_API GeoIPRegion * GeoIP_region_by_name_v6 (GeoIP* gi, const char *host);
183GEOIP_API GeoIPRegion * GeoIP_region_by_ipnum_v6 (GeoIP *gi, geoipv6_t ipnum);
3193eda0
CP
184
185/* Warning - don't call this after GeoIP_assign_region_by_inetaddr calls */
186GEOIP_API void GeoIPRegion_delete (GeoIPRegion *gir);
187
188GEOIP_API void GeoIP_assign_region_by_inetaddr(GeoIP* gi, unsigned long inetaddr, GeoIPRegion *gir);
189
69793602
CP
190GEOIP_API void GeoIP_assign_region_by_inetaddr_v6(GeoIP* gi, geoipv6_t inetaddr, GeoIPRegion *gir);
191
3193eda0 192/* Used to query GeoIP Organization, ISP and AS Number databases */
69793602 193GEOIP_API char *GeoIP_name_by_ipnum (GeoIP* gi, unsigned long ipnum);
3193eda0
CP
194GEOIP_API char *GeoIP_name_by_addr (GeoIP* gi, const char *addr);
195GEOIP_API char *GeoIP_name_by_name (GeoIP* gi, const char *host);
196
69793602
CP
197GEOIP_API char *GeoIP_name_by_ipnum_v6 (GeoIP* gi, geoipv6_t ipnum);
198GEOIP_API char *GeoIP_name_by_addr_v6 (GeoIP* gi, const char *addr);
199GEOIP_API char *GeoIP_name_by_name_v6 (GeoIP* gi, const char *name);
200
201/** return two letter country code */
202GEOIP_API const char* GeoIP_code_by_id(int id);
203
204/** return three letter country code */
205GEOIP_API const char* GeoIP_code3_by_id(int id);
206
207/** return full name of country */
208GEOIP_API const char* GeoIP_name_by_id(int id);
209
210/** return continent of country */
211GEOIP_API const char* GeoIP_continent_by_id(int id);
212
213/** return id by country code **/
214GEOIP_API int GeoIP_id_by_code(const char *country);
215
216/** return return number of known countries */
217GEOIP_API unsigned GeoIP_num_countries(void);
218
3193eda0
CP
219GEOIP_API char *GeoIP_database_info (GeoIP* gi);
220GEOIP_API unsigned char GeoIP_database_edition (GeoIP* gi);
221
69793602
CP
222GEOIP_API int GeoIP_charset (GeoIP* gi);
223GEOIP_API int GeoIP_set_charset (GeoIP* gi, int charset);
224
225GEOIP_API int GeoIP_last_netmask (GeoIP* gi);
226GEOIP_API char **GeoIP_range_by_ip (GeoIP* gi, const char *addr);
227GEOIP_API void GeoIP_range_by_ip_delete(char **ptr);
228
229/* Convert region code to region name */
230GEOIP_API const char * GeoIP_region_name_by_code(const char *country_code, const char *region_code);
231
232/* Get timezone from country and region code */
233GEOIP_API const char * GeoIP_time_zone_by_country_and_region(const char *country_code, const char *region_code);
3193eda0
CP
234
235#ifdef BSD
236#define memcpy(dest, src, n) bcopy(src, dest, n)
237#endif
238
239#ifdef __cplusplus
240}
241#endif
242
243#endif /* GEOIP_H */