Main Page | Class List | File List | Class Members | File Members

GeoIP.h

Go to the documentation of this file.
00001 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
00002 /* GeoIP.h
00003  *
00004  * Copyright (C) 2003 MaxMind LLC
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 #ifndef GEOIP_H
00022 #define GEOIP_H
00023 
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif
00027 
00028 #include<stdio.h>
00029 #include<stdlib.h>
00030 #include<string.h>
00031 #include <sys/types.h> /* for fstat */
00032 #include <sys/stat.h>   /* for fstat */
00033 
00034 #define SEGMENT_RECORD_LENGTH 3
00035 #define STANDARD_RECORD_LENGTH 3
00036 #define ORG_RECORD_LENGTH 4
00037 #define MAX_RECORD_LENGTH 4
00038 #define NUM_DB_TYPES 16
00039 
00040 typedef struct GeoIPTag {
00041   FILE *GeoIPDatabase;
00042   char *file_path;
00043         unsigned char *cache;
00044         unsigned char *index_cache;
00045         unsigned int *databaseSegments;
00046         char databaseType;
00047         time_t mtime;
00048         int flags;
00049         char record_length;
00050         int record_iter; /* used in GeoIP_next_record */
00051 } GeoIP;
00052 
00053 typedef struct GeoIPRegionTag {
00054         char country_code[3];
00055         char region[3];
00056 } GeoIPRegion;
00057 
00058 typedef enum {
00059         GEOIP_STANDARD = 0,
00060         GEOIP_MEMORY_CACHE = 1,
00061         GEOIP_CHECK_CACHE = 2,
00062         GEOIP_INDEX_CACHE = 4,
00063 } GeoIPOptions;
00064 
00065 typedef enum {
00066         GEOIP_COUNTRY_EDITION     = 1,
00067         GEOIP_REGION_EDITION_REV0 = 7,
00068         GEOIP_CITY_EDITION_REV0   = 6,
00069         GEOIP_ORG_EDITION         = 5,
00070         GEOIP_ISP_EDITION         = 4,
00071         GEOIP_CITY_EDITION_REV1   = 2,
00072         GEOIP_REGION_EDITION_REV1 = 3,
00073         GEOIP_PROXY_EDITION       = 8,
00074         GEOIP_ASNUM_EDITION       = 9,
00075         GEOIP_NETSPEED_EDITION   = 10,
00076 } GeoIPDBTypes;
00077 
00078 typedef enum {
00079         GEOIP_ANON_PROXY = 1,
00080         GEOIP_HTTP_X_FORWARDED_FOR_PROXY = 2,
00081         GEOIP_HTTP_CLIENT_IP_PROXY = 3,
00082 } GeoIPProxyTypes;
00083 
00084 typedef enum {
00085         GEOIP_UNKNOWN_SPEED = 0,
00086         GEOIP_DIALUP_SPEED = 1,
00087         GEOIP_CABLEDSL_SPEED = 2,
00088         GEOIP_CORPORATE_SPEED = 3,
00089 } GeoIPNetspeedValues;
00090 
00091 extern char **GeoIPDBFileName;
00092 extern const char * GeoIPDBDescription[NUM_DB_TYPES];
00093 extern const char *GeoIPCountryDBFileName;
00094 extern const char *GeoIPRegionDBFileName;
00095 extern const char *GeoIPCityDBFileName;
00096 extern const char *GeoIPOrgDBFileName;
00097 extern const char *GeoIPISPDBFileName;
00098 
00099 extern const char GeoIP_country_code[247][3];
00100 extern const char GeoIP_country_code3[247][4];
00101 extern const char * GeoIP_country_name[247];
00102 extern const char GeoIP_country_continent[247][3];
00103 
00104 #ifdef DLL
00105 #define GEOIP_API __declspec(dllexport)
00106 #else
00107 #define GEOIP_API
00108 #endif  /* DLL */
00109 
00110 GEOIP_API GeoIP* GeoIP_open_type (int type, int flags);
00111 GEOIP_API GeoIP* GeoIP_new(int flags);
00112 GEOIP_API GeoIP* GeoIP_open(const char * filename, int flags);
00113 GEOIP_API int GeoIP_db_avail(int type);
00114 GEOIP_API void GeoIP_delete(GeoIP* gi);
00115 GEOIP_API const char *GeoIP_country_code_by_addr (GeoIP* gi, const char *addr);
00116 GEOIP_API const char *GeoIP_country_code_by_name (GeoIP* gi, const char *host);
00117 GEOIP_API const char *GeoIP_country_code3_by_addr (GeoIP* gi, const char *addr);
00118 GEOIP_API const char *GeoIP_country_code3_by_name (GeoIP* gi, const char *host);
00119 GEOIP_API const char *GeoIP_country_name_by_addr (GeoIP* gi, const char *addr);
00120 GEOIP_API const char *GeoIP_country_name_by_name (GeoIP* gi, const char *host);
00121 GEOIP_API const char *GeoIP_country_code_by_ipnum (GeoIP* gi, unsigned long ipnum);
00122 
00123 /* Deprecated - for backwards compatibility only */
00124 GEOIP_API int GeoIP_country_id_by_addr (GeoIP* gi, const char *addr);
00125 GEOIP_API int GeoIP_country_id_by_name (GeoIP* gi, const char *host);
00126 GEOIP_API char *GeoIP_org_by_addr (GeoIP* gi, const char *addr);
00127 GEOIP_API char *GeoIP_org_by_name (GeoIP* gi, const char *host);
00128 /* End deprecated */
00129 
00130 GEOIP_API int GeoIP_id_by_addr (GeoIP* gi, const char *addr);
00131 GEOIP_API int GeoIP_id_by_name (GeoIP* gi, const char *host);
00132 GEOIP_API int GeoIP_id_by_ipnum (GeoIP* gi, unsigned long ipnum);
00133 
00134 GEOIP_API GeoIPRegion * GeoIP_region_by_addr (GeoIP* gi, const char *addr);
00135 GEOIP_API GeoIPRegion * GeoIP_region_by_name (GeoIP* gi, const char *host);
00136 
00137 /* Warning - don't call this after GeoIP_assign_region_by_inetaddr calls */
00138 GEOIP_API void GeoIPRegion_delete (GeoIPRegion *gir);
00139 
00140 GEOIP_API void GeoIP_assign_region_by_inetaddr(GeoIP* gi, unsigned long inetaddr, GeoIPRegion *gir);
00141 
00142 /* Used to query GeoIP Organization, ISP and AS Number databases */
00143 GEOIP_API char *GeoIP_name_by_addr (GeoIP* gi, const char *addr);
00144 GEOIP_API char *GeoIP_name_by_name (GeoIP* gi, const char *host);
00145 
00146 GEOIP_API char *GeoIP_database_info (GeoIP* gi);
00147 GEOIP_API unsigned char GeoIP_database_edition (GeoIP* gi);
00148 
00149 GEOIP_API unsigned int _seek_record (GeoIP *gi, unsigned long ipnum);
00150 GEOIP_API unsigned long _addr_to_num (const char *addr);
00151 
00152 #ifdef BSD
00153 #define memcpy(dest, src, n) bcopy(src, dest, n)
00154 #endif
00155 
00156 #ifdef __cplusplus
00157 }
00158 #endif
00159 
00160 #endif /* GEOIP_H */

Generated on Tue Jun 28 01:09:07 2005 for CountryFilter by  doxygen 1.4.3-20050623