extensions/geoip/GeoIP.h
author David Anderson <dvander@alliedmods.net>
Fri Jun 08 03:50:23 2007 +0000 (2007-06-08)
changeset 925 2cd3d817b5ab
parent 316 1b691b2ff277
permissions -rw-r--r--
added sm_unban
faluco@316
     1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
faluco@316
     2
/* GeoIP.h
faluco@316
     3
 *
faluco@316
     4
 * Copyright (C) 2006 MaxMind LLC
faluco@316
     5
 *
faluco@316
     6
 * This library is free software; you can redistribute it and/or
faluco@316
     7
 * modify it under the terms of the GNU Lesser General Public
faluco@316
     8
 * License as published by the Free Software Foundation; either
faluco@316
     9
 * version 2.1 of the License, or (at your option) any later version.
faluco@316
    10
 *
faluco@316
    11
 * This library is distributed in the hope that it will be useful,
faluco@316
    12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
faluco@316
    13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
faluco@316
    14
 * Lesser General Public License for more details.
faluco@316
    15
 *
faluco@316
    16
 * You should have received a copy of the GNU Lesser General Public
faluco@316
    17
 * License along with this library; if not, write to the Free Software
faluco@316
    18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
faluco@316
    19
 */
faluco@316
    20
faluco@316
    21
#ifndef GEOIP_H
faluco@316
    22
#define GEOIP_H
faluco@316
    23
faluco@316
    24
#ifdef __cplusplus
faluco@316
    25
extern "C" {
faluco@316
    26
#endif
faluco@316
    27
faluco@316
    28
#include<stdio.h>
faluco@316
    29
#include<stdlib.h>
faluco@316
    30
#include<string.h>
faluco@316
    31
#include <sys/types.h> /* for fstat */
faluco@316
    32
#include <sys/stat.h>	/* for fstat */
faluco@316
    33
faluco@316
    34
#define SEGMENT_RECORD_LENGTH 3
faluco@316
    35
#define STANDARD_RECORD_LENGTH 3
faluco@316
    36
#define ORG_RECORD_LENGTH 4
faluco@316
    37
#define MAX_RECORD_LENGTH 4
faluco@316
    38
#define NUM_DB_TYPES 20
faluco@316
    39
faluco@316
    40
typedef struct GeoIPTag {
faluco@316
    41
  FILE *GeoIPDatabase;
faluco@316
    42
  char *file_path;
faluco@316
    43
	unsigned char *cache;
faluco@316
    44
	unsigned char *index_cache;
faluco@316
    45
	unsigned int *databaseSegments;
faluco@316
    46
	char databaseType;
faluco@316
    47
	time_t mtime;
faluco@316
    48
	int flags;
faluco@316
    49
	char record_length;
faluco@316
    50
	int record_iter; /* used in GeoIP_next_record */
faluco@316
    51
} GeoIP;
faluco@316
    52
faluco@316
    53
typedef struct GeoIPRegionTag {
faluco@316
    54
	char country_code[3];
faluco@316
    55
	char region[3];
faluco@316
    56
} GeoIPRegion;
faluco@316
    57
faluco@316
    58
typedef enum {
faluco@316
    59
	GEOIP_STANDARD = 0,
faluco@316
    60
	GEOIP_MEMORY_CACHE = 1,
faluco@316
    61
	GEOIP_CHECK_CACHE = 2,
faluco@316
    62
	GEOIP_INDEX_CACHE = 4,
faluco@316
    63
} GeoIPOptions;
faluco@316
    64
faluco@316
    65
typedef enum {
faluco@316
    66
	GEOIP_COUNTRY_EDITION     = 1,
faluco@316
    67
	GEOIP_REGION_EDITION_REV0 = 7,
faluco@316
    68
	GEOIP_CITY_EDITION_REV0   = 6,
faluco@316
    69
	GEOIP_ORG_EDITION         = 5,
faluco@316
    70
	GEOIP_ISP_EDITION         = 4,
faluco@316
    71
	GEOIP_CITY_EDITION_REV1   = 2,
faluco@316
    72
	GEOIP_REGION_EDITION_REV1 = 3,
faluco@316
    73
	GEOIP_PROXY_EDITION       = 8,
faluco@316
    74
	GEOIP_ASNUM_EDITION       = 9,
faluco@316
    75
	GEOIP_NETSPEED_EDITION    = 10,
faluco@316
    76
	GEOIP_DOMAIN_EDITION      = 11
faluco@316
    77
} GeoIPDBTypes;
faluco@316
    78
faluco@316
    79
typedef enum {
faluco@316
    80
	GEOIP_ANON_PROXY = 1,
faluco@316
    81
	GEOIP_HTTP_X_FORWARDED_FOR_PROXY = 2,
faluco@316
    82
	GEOIP_HTTP_CLIENT_IP_PROXY = 3,
faluco@316
    83
} GeoIPProxyTypes;
faluco@316
    84
faluco@316
    85
typedef enum {
faluco@316
    86
	GEOIP_UNKNOWN_SPEED = 0,
faluco@316
    87
	GEOIP_DIALUP_SPEED = 1,
faluco@316
    88
	GEOIP_CABLEDSL_SPEED = 2,
faluco@316
    89
	GEOIP_CORPORATE_SPEED = 3,
faluco@316
    90
} GeoIPNetspeedValues;
faluco@316
    91
faluco@316
    92
extern char **GeoIPDBFileName;
faluco@316
    93
extern const char * GeoIPDBDescription[NUM_DB_TYPES];
faluco@316
    94
extern const char *GeoIPCountryDBFileName;
faluco@316
    95
extern const char *GeoIPRegionDBFileName;
faluco@316
    96
extern const char *GeoIPCityDBFileName;
faluco@316
    97
extern const char *GeoIPOrgDBFileName;
faluco@316
    98
extern const char *GeoIPISPDBFileName;
faluco@316
    99
faluco@316
   100
extern const char GeoIP_country_code[251][3];
faluco@316
   101
extern const char GeoIP_country_code3[251][4];
faluco@316
   102
extern const char * GeoIP_country_name[251];
faluco@316
   103
extern const char GeoIP_country_continent[251][3];
faluco@316
   104
faluco@316
   105
#ifdef DLL
faluco@316
   106
#define GEOIP_API __declspec(dllexport)
faluco@316
   107
#else
faluco@316
   108
#define GEOIP_API
faluco@316
   109
#endif  /* DLL */
faluco@316
   110
faluco@316
   111
GEOIP_API void GeoIP_setup_custom_directory(char *dir);
faluco@316
   112
GEOIP_API GeoIP* GeoIP_open_type (int type, int flags);
faluco@316
   113
GEOIP_API GeoIP* GeoIP_new(int flags);
faluco@316
   114
GEOIP_API GeoIP* GeoIP_open(const char * filename, int flags);
faluco@316
   115
GEOIP_API int GeoIP_db_avail(int type);
faluco@316
   116
GEOIP_API void GeoIP_delete(GeoIP* gi);
faluco@316
   117
GEOIP_API const char *GeoIP_country_code_by_addr (GeoIP* gi, const char *addr);
faluco@316
   118
GEOIP_API const char *GeoIP_country_code_by_name (GeoIP* gi, const char *host);
faluco@316
   119
GEOIP_API const char *GeoIP_country_code3_by_addr (GeoIP* gi, const char *addr);
faluco@316
   120
GEOIP_API const char *GeoIP_country_code3_by_name (GeoIP* gi, const char *host);
faluco@316
   121
GEOIP_API const char *GeoIP_country_name_by_addr (GeoIP* gi, const char *addr);
faluco@316
   122
GEOIP_API const char *GeoIP_country_name_by_name (GeoIP* gi, const char *host);
faluco@316
   123
GEOIP_API const char *GeoIP_country_name_by_ipnum (GeoIP* gi, unsigned long ipnum);
faluco@316
   124
GEOIP_API const char *GeoIP_country_code_by_ipnum (GeoIP* gi, unsigned long ipnum);
faluco@316
   125
GEOIP_API const char *GeoIP_country_code3_by_ipnum (GeoIP* gi, unsigned long ipnum);
faluco@316
   126
faluco@316
   127
/* Deprecated - for backwards compatibility only */
faluco@316
   128
GEOIP_API int GeoIP_country_id_by_addr (GeoIP* gi, const char *addr);
faluco@316
   129
GEOIP_API int GeoIP_country_id_by_name (GeoIP* gi, const char *host);
faluco@316
   130
GEOIP_API char *GeoIP_org_by_addr (GeoIP* gi, const char *addr);
faluco@316
   131
GEOIP_API char *GeoIP_org_by_name (GeoIP* gi, const char *host);
faluco@316
   132
/* End deprecated */
faluco@316
   133
faluco@316
   134
GEOIP_API int GeoIP_id_by_addr (GeoIP* gi, const char *addr);
faluco@316
   135
GEOIP_API int GeoIP_id_by_name (GeoIP* gi, const char *host);
faluco@316
   136
GEOIP_API int GeoIP_id_by_ipnum (GeoIP* gi, unsigned long ipnum);
faluco@316
   137
faluco@316
   138
GEOIP_API GeoIPRegion * GeoIP_region_by_addr (GeoIP* gi, const char *addr);
faluco@316
   139
GEOIP_API GeoIPRegion * GeoIP_region_by_name (GeoIP* gi, const char *host);
faluco@316
   140
GEOIP_API GeoIPRegion * GeoIP_region_by_ipnum (GeoIP *gi, unsigned long ipnum);
faluco@316
   141
faluco@316
   142
/* Warning - don't call this after GeoIP_assign_region_by_inetaddr calls */
faluco@316
   143
GEOIP_API void GeoIPRegion_delete (GeoIPRegion *gir);
faluco@316
   144
faluco@316
   145
GEOIP_API void GeoIP_assign_region_by_inetaddr(GeoIP* gi, unsigned long inetaddr, GeoIPRegion *gir);
faluco@316
   146
faluco@316
   147
/* Used to query GeoIP Organization, ISP and AS Number databases */
faluco@316
   148
GEOIP_API char *GeoIP_name_by_ipnum (GeoIP* gi, unsigned long ipnum);
faluco@316
   149
GEOIP_API char *GeoIP_name_by_addr (GeoIP* gi, const char *addr);
faluco@316
   150
GEOIP_API char *GeoIP_name_by_name (GeoIP* gi, const char *host);
faluco@316
   151
faluco@316
   152
GEOIP_API char *GeoIP_database_info (GeoIP* gi);
faluco@316
   153
GEOIP_API unsigned char GeoIP_database_edition (GeoIP* gi);
faluco@316
   154
faluco@316
   155
/* Convert region code to region name */
faluco@316
   156
GEOIP_API const char * GeoIP_region_name_by_code(const char *country_code, const char *region_code);
faluco@316
   157
faluco@316
   158
/* Get timezone from country and region code */
faluco@316
   159
GEOIP_API const char * GeoIP_time_zone_by_country_and_region(const char *country_code, const char *region_code);
faluco@316
   160
faluco@316
   161
#ifdef BSD
faluco@316
   162
#define memcpy(dest, src, n) bcopy(src, dest, n)
faluco@316
   163
#endif
faluco@316
   164
faluco@316
   165
#ifdef __cplusplus
faluco@316
   166
}
faluco@316
   167
#endif
faluco@316
   168
faluco@316
   169
#endif /* GEOIP_H */