extensions/geoip/GeoIP.h
changeset 316 1b691b2ff277
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/extensions/geoip/GeoIP.h	Fri Jan 19 01:50:42 2007 +0000
     1.3 @@ -0,0 +1,169 @@
     1.4 +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
     1.5 +/* GeoIP.h
     1.6 + *
     1.7 + * Copyright (C) 2006 MaxMind LLC
     1.8 + *
     1.9 + * This library is free software; you can redistribute it and/or
    1.10 + * modify it under the terms of the GNU Lesser General Public
    1.11 + * License as published by the Free Software Foundation; either
    1.12 + * version 2.1 of the License, or (at your option) any later version.
    1.13 + *
    1.14 + * This library is distributed in the hope that it will be useful,
    1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.17 + * Lesser General Public License for more details.
    1.18 + *
    1.19 + * You should have received a copy of the GNU Lesser General Public
    1.20 + * License along with this library; if not, write to the Free Software
    1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    1.22 + */
    1.23 +
    1.24 +#ifndef GEOIP_H
    1.25 +#define GEOIP_H
    1.26 +
    1.27 +#ifdef __cplusplus
    1.28 +extern "C" {
    1.29 +#endif
    1.30 +
    1.31 +#include<stdio.h>
    1.32 +#include<stdlib.h>
    1.33 +#include<string.h>
    1.34 +#include <sys/types.h> /* for fstat */
    1.35 +#include <sys/stat.h>	/* for fstat */
    1.36 +
    1.37 +#define SEGMENT_RECORD_LENGTH 3
    1.38 +#define STANDARD_RECORD_LENGTH 3
    1.39 +#define ORG_RECORD_LENGTH 4
    1.40 +#define MAX_RECORD_LENGTH 4
    1.41 +#define NUM_DB_TYPES 20
    1.42 +
    1.43 +typedef struct GeoIPTag {
    1.44 +  FILE *GeoIPDatabase;
    1.45 +  char *file_path;
    1.46 +	unsigned char *cache;
    1.47 +	unsigned char *index_cache;
    1.48 +	unsigned int *databaseSegments;
    1.49 +	char databaseType;
    1.50 +	time_t mtime;
    1.51 +	int flags;
    1.52 +	char record_length;
    1.53 +	int record_iter; /* used in GeoIP_next_record */
    1.54 +} GeoIP;
    1.55 +
    1.56 +typedef struct GeoIPRegionTag {
    1.57 +	char country_code[3];
    1.58 +	char region[3];
    1.59 +} GeoIPRegion;
    1.60 +
    1.61 +typedef enum {
    1.62 +	GEOIP_STANDARD = 0,
    1.63 +	GEOIP_MEMORY_CACHE = 1,
    1.64 +	GEOIP_CHECK_CACHE = 2,
    1.65 +	GEOIP_INDEX_CACHE = 4,
    1.66 +} GeoIPOptions;
    1.67 +
    1.68 +typedef enum {
    1.69 +	GEOIP_COUNTRY_EDITION     = 1,
    1.70 +	GEOIP_REGION_EDITION_REV0 = 7,
    1.71 +	GEOIP_CITY_EDITION_REV0   = 6,
    1.72 +	GEOIP_ORG_EDITION         = 5,
    1.73 +	GEOIP_ISP_EDITION         = 4,
    1.74 +	GEOIP_CITY_EDITION_REV1   = 2,
    1.75 +	GEOIP_REGION_EDITION_REV1 = 3,
    1.76 +	GEOIP_PROXY_EDITION       = 8,
    1.77 +	GEOIP_ASNUM_EDITION       = 9,
    1.78 +	GEOIP_NETSPEED_EDITION    = 10,
    1.79 +	GEOIP_DOMAIN_EDITION      = 11
    1.80 +} GeoIPDBTypes;
    1.81 +
    1.82 +typedef enum {
    1.83 +	GEOIP_ANON_PROXY = 1,
    1.84 +	GEOIP_HTTP_X_FORWARDED_FOR_PROXY = 2,
    1.85 +	GEOIP_HTTP_CLIENT_IP_PROXY = 3,
    1.86 +} GeoIPProxyTypes;
    1.87 +
    1.88 +typedef enum {
    1.89 +	GEOIP_UNKNOWN_SPEED = 0,
    1.90 +	GEOIP_DIALUP_SPEED = 1,
    1.91 +	GEOIP_CABLEDSL_SPEED = 2,
    1.92 +	GEOIP_CORPORATE_SPEED = 3,
    1.93 +} GeoIPNetspeedValues;
    1.94 +
    1.95 +extern char **GeoIPDBFileName;
    1.96 +extern const char * GeoIPDBDescription[NUM_DB_TYPES];
    1.97 +extern const char *GeoIPCountryDBFileName;
    1.98 +extern const char *GeoIPRegionDBFileName;
    1.99 +extern const char *GeoIPCityDBFileName;
   1.100 +extern const char *GeoIPOrgDBFileName;
   1.101 +extern const char *GeoIPISPDBFileName;
   1.102 +
   1.103 +extern const char GeoIP_country_code[251][3];
   1.104 +extern const char GeoIP_country_code3[251][4];
   1.105 +extern const char * GeoIP_country_name[251];
   1.106 +extern const char GeoIP_country_continent[251][3];
   1.107 +
   1.108 +#ifdef DLL
   1.109 +#define GEOIP_API __declspec(dllexport)
   1.110 +#else
   1.111 +#define GEOIP_API
   1.112 +#endif  /* DLL */
   1.113 +
   1.114 +GEOIP_API void GeoIP_setup_custom_directory(char *dir);
   1.115 +GEOIP_API GeoIP* GeoIP_open_type (int type, int flags);
   1.116 +GEOIP_API GeoIP* GeoIP_new(int flags);
   1.117 +GEOIP_API GeoIP* GeoIP_open(const char * filename, int flags);
   1.118 +GEOIP_API int GeoIP_db_avail(int type);
   1.119 +GEOIP_API void GeoIP_delete(GeoIP* gi);
   1.120 +GEOIP_API const char *GeoIP_country_code_by_addr (GeoIP* gi, const char *addr);
   1.121 +GEOIP_API const char *GeoIP_country_code_by_name (GeoIP* gi, const char *host);
   1.122 +GEOIP_API const char *GeoIP_country_code3_by_addr (GeoIP* gi, const char *addr);
   1.123 +GEOIP_API const char *GeoIP_country_code3_by_name (GeoIP* gi, const char *host);
   1.124 +GEOIP_API const char *GeoIP_country_name_by_addr (GeoIP* gi, const char *addr);
   1.125 +GEOIP_API const char *GeoIP_country_name_by_name (GeoIP* gi, const char *host);
   1.126 +GEOIP_API const char *GeoIP_country_name_by_ipnum (GeoIP* gi, unsigned long ipnum);
   1.127 +GEOIP_API const char *GeoIP_country_code_by_ipnum (GeoIP* gi, unsigned long ipnum);
   1.128 +GEOIP_API const char *GeoIP_country_code3_by_ipnum (GeoIP* gi, unsigned long ipnum);
   1.129 +
   1.130 +/* Deprecated - for backwards compatibility only */
   1.131 +GEOIP_API int GeoIP_country_id_by_addr (GeoIP* gi, const char *addr);
   1.132 +GEOIP_API int GeoIP_country_id_by_name (GeoIP* gi, const char *host);
   1.133 +GEOIP_API char *GeoIP_org_by_addr (GeoIP* gi, const char *addr);
   1.134 +GEOIP_API char *GeoIP_org_by_name (GeoIP* gi, const char *host);
   1.135 +/* End deprecated */
   1.136 +
   1.137 +GEOIP_API int GeoIP_id_by_addr (GeoIP* gi, const char *addr);
   1.138 +GEOIP_API int GeoIP_id_by_name (GeoIP* gi, const char *host);
   1.139 +GEOIP_API int GeoIP_id_by_ipnum (GeoIP* gi, unsigned long ipnum);
   1.140 +
   1.141 +GEOIP_API GeoIPRegion * GeoIP_region_by_addr (GeoIP* gi, const char *addr);
   1.142 +GEOIP_API GeoIPRegion * GeoIP_region_by_name (GeoIP* gi, const char *host);
   1.143 +GEOIP_API GeoIPRegion * GeoIP_region_by_ipnum (GeoIP *gi, unsigned long ipnum);
   1.144 +
   1.145 +/* Warning - don't call this after GeoIP_assign_region_by_inetaddr calls */
   1.146 +GEOIP_API void GeoIPRegion_delete (GeoIPRegion *gir);
   1.147 +
   1.148 +GEOIP_API void GeoIP_assign_region_by_inetaddr(GeoIP* gi, unsigned long inetaddr, GeoIPRegion *gir);
   1.149 +
   1.150 +/* Used to query GeoIP Organization, ISP and AS Number databases */
   1.151 +GEOIP_API char *GeoIP_name_by_ipnum (GeoIP* gi, unsigned long ipnum);
   1.152 +GEOIP_API char *GeoIP_name_by_addr (GeoIP* gi, const char *addr);
   1.153 +GEOIP_API char *GeoIP_name_by_name (GeoIP* gi, const char *host);
   1.154 +
   1.155 +GEOIP_API char *GeoIP_database_info (GeoIP* gi);
   1.156 +GEOIP_API unsigned char GeoIP_database_edition (GeoIP* gi);
   1.157 +
   1.158 +/* Convert region code to region name */
   1.159 +GEOIP_API const char * GeoIP_region_name_by_code(const char *country_code, const char *region_code);
   1.160 +
   1.161 +/* Get timezone from country and region code */
   1.162 +GEOIP_API const char * GeoIP_time_zone_by_country_and_region(const char *country_code, const char *region_code);
   1.163 +
   1.164 +#ifdef BSD
   1.165 +#define memcpy(dest, src, n) bcopy(src, dest, n)
   1.166 +#endif
   1.167 +
   1.168 +#ifdef __cplusplus
   1.169 +}
   1.170 +#endif
   1.171 +
   1.172 +#endif /* GEOIP_H */