]>
Commit | Line | Data |
---|---|---|
3193eda0 CP |
1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */ |
2 | /* GeoIP.h | |
3 | * | |
4 | * Copyright (C) 2003 MaxMind LLC | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public | |
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 | |
14 | * General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public | |
17 | * License along with this library; if not, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 | */ | |
20 | ||
21 | #ifndef GEOIP_H | |
22 | #define GEOIP_H | |
23 | ||
24 | #ifdef __cplusplus | |
25 | extern "C" { | |
26 | #endif | |
27 | ||
28 | #include<stdio.h> | |
29 | #include<stdlib.h> | |
30 | #include<string.h> | |
31 | #include <sys/types.h> /* for fstat */ | |
32 | #include <sys/stat.h> /* for fstat */ | |
33 | ||
34 | #define SEGMENT_RECORD_LENGTH 3 | |
35 | #define STANDARD_RECORD_LENGTH 3 | |
36 | #define ORG_RECORD_LENGTH 4 | |
37 | #define MAX_RECORD_LENGTH 4 | |
38 | #define NUM_DB_TYPES 16 | |
39 | ||
40 | typedef struct GeoIPTag { | |
41 | FILE *GeoIPDatabase; | |
42 | char *file_path; | |
43 | unsigned char *cache; | |
44 | unsigned char *index_cache; | |
45 | unsigned int *databaseSegments; | |
46 | char databaseType; | |
47 | time_t mtime; | |
48 | int flags; | |
49 | char record_length; | |
50 | int record_iter; /* used in GeoIP_next_record */ | |
51 | } GeoIP; | |
52 | ||
53 | typedef struct GeoIPRegionTag { | |
54 | char country_code[3]; | |
55 | char region[3]; | |
56 | } GeoIPRegion; | |
57 | ||
58 | typedef enum { | |
59 | GEOIP_STANDARD = 0, | |
60 | GEOIP_MEMORY_CACHE = 1, | |
61 | GEOIP_CHECK_CACHE = 2, | |
62 | GEOIP_INDEX_CACHE = 4 | |
63 | } GeoIPOptions; | |
64 | ||
65 | typedef enum { | |
66 | GEOIP_COUNTRY_EDITION = 1, | |
67 | GEOIP_REGION_EDITION_REV0 = 7, | |
68 | GEOIP_CITY_EDITION_REV0 = 6, | |
69 | GEOIP_ORG_EDITION = 5, | |
70 | GEOIP_ISP_EDITION = 4, | |
71 | GEOIP_CITY_EDITION_REV1 = 2, | |
72 | GEOIP_REGION_EDITION_REV1 = 3, | |
73 | GEOIP_PROXY_EDITION = 8, | |
74 | GEOIP_ASNUM_EDITION = 9, | |
75 | GEOIP_NETSPEED_EDITION = 10 | |
76 | } GeoIPDBTypes; | |
77 | ||
78 | typedef enum { | |
79 | GEOIP_ANON_PROXY = 1, | |
80 | GEOIP_HTTP_X_FORWARDED_FOR_PROXY = 2, | |
81 | GEOIP_HTTP_CLIENT_IP_PROXY = 3 | |
82 | } GeoIPProxyTypes; | |
83 | ||
84 | typedef enum { | |
85 | GEOIP_UNKNOWN_SPEED = 0, | |
86 | GEOIP_DIALUP_SPEED = 1, | |
87 | GEOIP_CABLEDSL_SPEED = 2, | |
88 | GEOIP_CORPORATE_SPEED = 3 | |
89 | } GeoIPNetspeedValues; | |
90 | ||
91 | extern char **GeoIPDBFileName; | |
92 | extern const char * GeoIPDBDescription[NUM_DB_TYPES]; | |
93 | extern const char *GeoIPCountryDBFileName; | |
94 | extern const char *GeoIPRegionDBFileName; | |
95 | extern const char *GeoIPCityDBFileName; | |
96 | extern const char *GeoIPOrgDBFileName; | |
97 | extern const char *GeoIPISPDBFileName; | |
98 | ||
99 | extern const char GeoIP_country_code[247][3]; | |
100 | extern const char GeoIP_country_code3[247][4]; | |
101 | extern const char * GeoIP_country_name[247]; | |
102 | extern const char GeoIP_country_continent[247][3]; | |
103 | ||
104 | #ifdef DLL | |
105 | #define GEOIP_API __declspec(dllexport) | |
106 | #else | |
107 | #define GEOIP_API | |
108 | #endif /* DLL */ | |
109 | ||
110 | GEOIP_API GeoIP* GeoIP_open_type (int type, int flags); | |
111 | GEOIP_API GeoIP* GeoIP_new(int flags, char *filename); | |
112 | GEOIP_API GeoIP* GeoIP_open(const char * filename, int flags); | |
113 | GEOIP_API int GeoIP_db_avail(int type); | |
114 | GEOIP_API void GeoIP_delete(GeoIP* gi); | |
115 | GEOIP_API const char *GeoIP_country_code_by_addr (GeoIP* gi, const char *addr); | |
116 | GEOIP_API const char *GeoIP_country_code_by_name (GeoIP* gi, const char *host); | |
117 | GEOIP_API const char *GeoIP_country_code3_by_addr (GeoIP* gi, const char *addr); | |
118 | GEOIP_API const char *GeoIP_country_code3_by_name (GeoIP* gi, const char *host); | |
119 | GEOIP_API const char *GeoIP_country_name_by_addr (GeoIP* gi, const char *addr); | |
120 | GEOIP_API const char *GeoIP_country_name_by_name (GeoIP* gi, const char *host); | |
121 | GEOIP_API const char *GeoIP_country_code_by_ipnum (GeoIP* gi, unsigned long ipnum); | |
122 | GEOIP_API int GeoIP_country_info_by_id(int id, char **two, char **three, char **full); | |
123 | ||
124 | /* Deprecated - for backwards compatibility only */ | |
125 | GEOIP_API int GeoIP_country_id_by_addr (GeoIP* gi, const char *addr); | |
126 | GEOIP_API int GeoIP_country_id_by_name (GeoIP* gi, const char *host); | |
127 | GEOIP_API char *GeoIP_org_by_addr (GeoIP* gi, const char *addr); | |
128 | GEOIP_API char *GeoIP_org_by_name (GeoIP* gi, const char *host); | |
129 | /* End deprecated */ | |
130 | ||
131 | GEOIP_API int GeoIP_id_by_addr (GeoIP* gi, const char *addr); | |
132 | GEOIP_API int GeoIP_id_by_name (GeoIP* gi, const char *host); | |
133 | GEOIP_API int GeoIP_id_by_ipnum (GeoIP* gi, unsigned long ipnum); | |
134 | ||
135 | GEOIP_API GeoIPRegion * GeoIP_region_by_addr (GeoIP* gi, const char *addr); | |
136 | GEOIP_API GeoIPRegion * GeoIP_region_by_name (GeoIP* gi, const char *host); | |
137 | ||
138 | /* Warning - don't call this after GeoIP_assign_region_by_inetaddr calls */ | |
139 | GEOIP_API void GeoIPRegion_delete (GeoIPRegion *gir); | |
140 | ||
141 | GEOIP_API void GeoIP_assign_region_by_inetaddr(GeoIP* gi, unsigned long inetaddr, GeoIPRegion *gir); | |
142 | ||
143 | /* Used to query GeoIP Organization, ISP and AS Number databases */ | |
144 | GEOIP_API char *GeoIP_name_by_addr (GeoIP* gi, const char *addr); | |
145 | GEOIP_API char *GeoIP_name_by_name (GeoIP* gi, const char *host); | |
146 | ||
147 | GEOIP_API char *GeoIP_database_info (GeoIP* gi); | |
148 | GEOIP_API unsigned char GeoIP_database_edition (GeoIP* gi); | |
149 | ||
150 | GEOIP_API unsigned int _seek_record (GeoIP *gi, unsigned long ipnum); | |
151 | GEOIP_API unsigned long _addr_to_num (const char *addr); | |
152 | ||
153 | #ifdef BSD | |
154 | #define memcpy(dest, src, n) bcopy(src, dest, n) | |
155 | #endif | |
156 | ||
157 | #ifdef __cplusplus | |
158 | } | |
159 | #endif | |
160 | ||
161 | #endif /* GEOIP_H */ |