Added libraries
This commit is contained in:
686
dlls/geoip/geolib/libGeoIP/GeoIP.c
Executable file
686
dlls/geoip/geolib/libGeoIP/GeoIP.c
Executable file
@ -0,0 +1,686 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/* GeoIP.c
|
||||
*
|
||||
* Copyright (C) 2003 MaxMind LLC All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "GeoIP.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifndef _WIN32
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h> /* For ntohl */
|
||||
#else
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#include <sys/types.h> /* for fstat */
|
||||
#include <sys/stat.h> /* for fstat */
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h> /* For uint32_t */
|
||||
#endif
|
||||
|
||||
#define COUNTRY_BEGIN 16776960
|
||||
#define STATE_BEGIN_REV0 16700000
|
||||
#define STATE_BEGIN_REV1 16000000
|
||||
#define STRUCTURE_INFO_MAX_SIZE 20
|
||||
#define DATABASE_INFO_MAX_SIZE 100
|
||||
#define MAX_ORG_RECORD_LENGTH 300
|
||||
#define US_OFFSET 1
|
||||
#define CANADA_OFFSET 677
|
||||
#define WORLD_OFFSET 1353
|
||||
#define FIPS_RANGE 360
|
||||
|
||||
#define CHECK_ERR(err, msg) { \
|
||||
if (err != Z_OK) { \
|
||||
fprintf(stderr, "%s error: %d\n", msg, err); \
|
||||
exit(1); \
|
||||
} \
|
||||
}
|
||||
|
||||
const char GeoIP_country_code[247][3] = { "--","AP","EU","AD","AE","AF","AG","AI","AL","AM","AN","AO","AQ","AR","AS","AT","AU","AW","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ","BM","BN","BO","BR","BS","BT","BV","BW","BY","BZ","CA","CC","CD","CF","CG","CH","CI","CK","CL","CM","CN","CO","CR","CU","CV","CX","CY","CZ","DE","DJ","DK","DM","DO","DZ","EC","EE","EG","EH","ER","ES","ET","FI","FJ","FK","FM","FO","FR","FX","GA","GB","GD","GE","GF","GH","GI","GL","GM","GN","GP","GQ","GR","GS","GT","GU","GW","GY","HK","HM","HN","HR","HT","HU","ID","IE","IL","IN","IO","IQ","IR","IS","IT","JM","JO","JP","KE","KG","KH","KI","KM","KN","KP","KR","KW","KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT","LU","LV","LY","MA","MC","MD","MG","MH","MK","ML","MM","MN","MO","MP","MQ","MR","MS","MT","MU","MV","MW","MX","MY","MZ","NA","NC","NE","NF","NG","NI","NL","NO","NP","NR","NU","NZ","OM","PA","PE","PF","PG","PH","PK","PL","PM","PN","PR","PS","PT","PW","PY","QA","RE","RO","RU","RW","SA","SB","SC","SD","SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO","SR","ST","SV","SY","SZ","TC","TD","TF","TG","TH","TJ","TK","TM","TN","TO","TP","TR","TT","TV","TW","TZ","UA","UG","UM","US","UY","UZ","VA","VC","VE","VG","VI","VN","VU","WF","WS","YE","YT","YU","ZA","ZM","ZR","ZW","A1","A2","O1"};
|
||||
|
||||
const char GeoIP_country_code3[247][4] = { "--","AP","EU","AND","ARE","AFG","ATG","AIA","ALB","ARM","ANT","AGO","AQ","ARG","ASM","AUT","AUS","ABW","AZE","BIH","BRB","BGD","BEL","BFA","BGR","BHR","BDI","BEN","BMU","BRN","BOL","BRA","BHS","BTN","BV","BWA","BLR","BLZ","CAN","CC","COD","CAF","COG","CHE","CIV","COK","CHL","CMR","CHN","COL","CRI","CUB","CPV","CX","CYP","CZE","DEU","DJI","DNK","DMA","DOM","DZA","ECU","EST","EGY","ESH","ERI","ESP","ETH","FIN","FJI","FLK","FSM","FRO","FRA","FX","GAB","GBR","GRD","GEO","GUF","GHA","GIB","GRL","GMB","GIN","GLP","GNQ","GRC","GS","GTM","GUM","GNB","GUY","HKG","HM","HND","HRV","HTI","HUN","IDN","IRL","ISR","IND","IO","IRQ","IRN","ISL","ITA","JAM","JOR","JPN","KEN","KGZ","KHM","KIR","COM","KNA","PRK","KOR","KWT","CYM","KAZ","LAO","LBN","LCA","LIE","LKA","LBR","LSO","LTU","LUX","LVA","LBY","MAR","MCO","MDA","MDG","MHL","MKD","MLI","MMR","MNG","MAC","MNP","MTQ","MRT","MSR","MLT","MUS","MDV","MWI","MEX","MYS","MOZ","NAM","NCL","NER","NFK","NGA","NIC","NLD","NOR","NPL","NRU","NIU","NZL","OMN","PAN","PER","PYF","PNG","PHL","PAK","POL","SPM","PCN","PRI","PSE","PRT","PLW","PRY","QAT","REU","ROU","RUS","RWA","SAU","SLB","SYC","SDN","SWE","SGP","SHN","SVN","SJM","SVK","SLE","SMR","SEN","SOM","SUR","STP","SLV","SYR","SWZ","TCA","TCD","TF","TGO","THA","TJK","TKL","TLS","TKM","TUN","TON","TUR","TTO","TUV","TWN","TZA","UKR","UGA","UM","USA","URY","UZB","VAT","VCT","VEN","VGB","VIR","VNM","VUT","WLF","WSM","YEM","YT","YUG","ZAF","ZMB","ZR","ZWE","A1","A2","O1"};
|
||||
|
||||
const char * GeoIP_country_name[247] = {"N/A","Asia/Pacific Region","Europe","Andorra","United Arab Emirates","Afghanistan","Antigua and Barbuda","Anguilla","Albania","Armenia","Netherlands Antilles","Angola","Antarctica","Argentina","American Samoa","Austria","Australia","Aruba","Azerbaijan","Bosnia and Herzegovina","Barbados","Bangladesh","Belgium","Burkina Faso","Bulgaria","Bahrain","Burundi","Benin","Bermuda","Brunei Darussalam","Bolivia","Brazil","Bahamas","Bhutan","Bouvet Island","Botswana","Belarus","Belize","Canada","Cocos (Keeling) Islands","Congo, The Democratic Republic of the","Central African Republic","Congo","Switzerland","Cote D'Ivoire","Cook Islands","Chile","Cameroon","China","Colombia","Costa Rica","Cuba","Cape Verde","Christmas Island","Cyprus","Czech Republic","Germany","Djibouti","Denmark","Dominica","Dominican Republic","Algeria","Ecuador","Estonia","Egypt","Western Sahara","Eritrea","Spain","Ethiopia","Finland","Fiji","Falkland Islands (Malvinas)","Micronesia, Federated States of","Faroe Islands","France","France, Metropolitan","Gabon","United Kingdom","Grenada","Georgia","French Guiana","Ghana","Gibraltar","Greenland","Gambia","Guinea","Guadeloupe","Equatorial Guinea","Greece","South Georgia and the South Sandwich Islands","Guatemala","Guam","Guinea-Bissau","Guyana","Hong Kong","Heard Island and McDonald Islands","Honduras","Croatia","Haiti","Hungary","Indonesia","Ireland","Israel","India","British Indian Ocean Territory","Iraq","Iran, Islamic Republic of","Iceland","Italy","Jamaica","Jordan","Japan","Kenya","Kyrgyzstan","Cambodia","Kiribati","Comoros","Saint Kitts and Nevis",
|
||||
"Korea, Democratic People's Republic of","Korea, Republic of","Kuwait","Cayman Islands","Kazakhstan","Lao People's Democratic Republic","Lebanon","Saint Lucia","Liechtenstein","Sri Lanka","Liberia","Lesotho","Lithuania","Luxembourg","Latvia","Libyan Arab Jamahiriya","Morocco","Monaco","Moldova, Republic of","Madagascar","Marshall Islands","Macedonia","Mali","Myanmar","Mongolia","Macau","Northern Mariana Islands","Martinique","Mauritania","Montserrat","Malta","Mauritius","Maldives","Malawi","Mexico","Malaysia","Mozambique","Namibia","New Caledonia","Niger","Norfolk Island","Nigeria","Nicaragua","Netherlands","Norway","Nepal","Nauru","Niue","New Zealand","Oman","Panama","Peru","French Polynesia","Papua New Guinea","Philippines","Pakistan","Poland","Saint Pierre and Miquelon","Pitcairn Islands","Puerto Rico","Palestinian Territory, Occupied","Portugal","Palau","Paraguay","Qatar","Reunion","Romania","Russian Federation","Rwanda","Saudi Arabia","Solomon Islands","Seychelles","Sudan","Sweden","Singapore","Saint Helena","Slovenia","Svalbard and Jan Mayen","Slovakia","Sierra Leone","San Marino","Senegal","Somalia","Suriname","Sao Tome and Principe","El Salvador","Syrian Arab Republic","Swaziland","Turks and Caicos Islands","Chad","French Southern Territories","Togo","Thailand","Tajikistan","Tokelau","Turkmenistan","Tunisia","Tonga","East Timor","Turkey","Trinidad and Tobago","Tuvalu","Taiwan","Tanzania, United Republic of","Ukraine","Uganda","United States Minor Outlying Islands","United States","Uruguay","Uzbekistan","Holy See (Vatican City State)","Saint Vincent and the Grenadines","Venezuela","Virgin Islands, British","Virgin Islands, U.S.","Vietnam","Vanuatu","Wallis and Futuna","Samoa","Yemen","Mayotte","Yugoslavia","South Africa","Zambia","Zaire","Zimbabwe",
|
||||
"Anonymous Proxy","Satellite Provider","Other"};
|
||||
|
||||
const char GeoIP_country_continent[247][3] = {"--","AS","EU","EU","AS","AS","SA","SA","EU","AS","SA","AF","AN","SA","OC","EU","OC","SA","AS","EU","SA","AS","EU","AF","EU","AS","AF","AF","SA","AS","SA","SA","SA","AS","AF","AF","EU","SA","NA","AS","AF","AF","AF","EU","AF","OC","SA","AF","AS","SA","SA","SA","AF","AS","AS","EU","EU","AF","EU","SA","SA","AF","SA","EU","AF","AF","AF","EU","AF","EU","OC","SA","OC","EU","EU","EU","AF","EU","SA","AS","SA","AF","EU","SA","AF","AF","SA","AF","EU","SA","SA","OC","AF","SA","AS","AF","SA","EU","SA","EU","AS","EU","AS","AS","AS","AS","AS","EU","EU","SA","AS","AS","AF","AS","AS","OC","AF","SA","AS","AS","AS","SA","AS","AS","AS","SA","EU","AS","AF","AF","EU","EU","EU","AF","AF","EU","EU","AF","OC","EU","AF","AS","AS","AS","OC","SA","AF","SA","EU","AF","AS","AF","NA","AS","AF","AF","OC","AF","OC","AF","SA","EU","EU","AS","OC","OC","OC","AS","SA","SA","OC","OC","AS","AS","EU","SA","OC","SA","AS","EU","OC","SA","AS","AF","EU","AS","AF","AS","OC","AF","AF","EU","AS","AF","EU","EU","EU","AF","EU","AF","AF","SA","AF","SA","AS","AF","SA","AF","AF","AF","AS","AS","OC","AS","AF","OC","AS","AS","SA","OC","AS","AF","EU","AF","OC","NA","SA","AS","EU","SA","SA","SA","SA","AS","OC","OC","OC","AS","AF","EU","AF","AF","AF","AF"};
|
||||
|
||||
const char * GeoIPDBDescription[NUM_DB_TYPES] = {NULL, "GeoIP Country Edition", "GeoIP City Edition, Rev 1", "GeoIP Region Edition, Rev 1", "GeoIP ISP Edition", "GeoIP Organization Edition", "GeoIP City Edition, Rev 0", "GeoIP Region Edition, Rev 0","GeoIP Proxy Edition","GeoIP Netspeed Edition"};
|
||||
|
||||
char *_full_path_to(const char *file_name) {
|
||||
char *path = malloc(sizeof(char) * 1024);
|
||||
|
||||
#ifndef _WIN32
|
||||
memset(path, 0, sizeof(char) * 1024);
|
||||
snprintf(path, sizeof(char) * 1024 - 1, "%s/%s", GEOIPDATADIR, file_name);
|
||||
#else
|
||||
char buf[MAX_PATH], *p, *q = NULL;
|
||||
int len;
|
||||
memset(buf, 0, sizeof(buf));
|
||||
len = GetModuleFileName(GetModuleHandle(NULL), buf, sizeof(buf) - 1);
|
||||
for (p = buf + len; p > buf; p--)
|
||||
if (*p == '\\')
|
||||
{
|
||||
if (!q)
|
||||
q = p;
|
||||
else
|
||||
*p = '/';
|
||||
}
|
||||
*q = 0;
|
||||
memset(path, 0, sizeof(char) * 1024);
|
||||
sprintf(path, "%s/%s", buf, file_name);
|
||||
#endif
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
char ** GeoIPDBFileName = NULL;
|
||||
|
||||
void _setup_dbfilename() {
|
||||
if (NULL == GeoIPDBFileName) {
|
||||
GeoIPDBFileName = malloc(sizeof(char *) * NUM_DB_TYPES);
|
||||
memset(GeoIPDBFileName, 0, sizeof(char *) * NUM_DB_TYPES);
|
||||
|
||||
GeoIPDBFileName[GEOIP_COUNTRY_EDITION] = _full_path_to("GeoIP.dat");
|
||||
GeoIPDBFileName[GEOIP_REGION_EDITION_REV0] = _full_path_to("GeoIPRegion.dat");
|
||||
GeoIPDBFileName[GEOIP_REGION_EDITION_REV1] = _full_path_to("GeoIPRegion.dat");
|
||||
GeoIPDBFileName[GEOIP_CITY_EDITION_REV0] = _full_path_to("GeoIPCity.dat");
|
||||
GeoIPDBFileName[GEOIP_CITY_EDITION_REV1] = _full_path_to("GeoIPCity.dat");
|
||||
GeoIPDBFileName[GEOIP_ISP_EDITION] = _full_path_to("GeoIPISP.dat");
|
||||
GeoIPDBFileName[GEOIP_ORG_EDITION] = _full_path_to("GeoIPOrg.dat");
|
||||
GeoIPDBFileName[GEOIP_PROXY_EDITION] = _full_path_to("GeoIPProxy.dat");
|
||||
GeoIPDBFileName[GEOIP_ASNUM_EDITION] = _full_path_to("GeoIPASNum.dat");
|
||||
GeoIPDBFileName[GEOIP_NETSPEED_EDITION] = _full_path_to("GeoIPNetSpeed.dat");
|
||||
}
|
||||
}
|
||||
|
||||
int _check_mtime(GeoIP *gi) {
|
||||
struct stat buf;
|
||||
|
||||
if (gi->flags & GEOIP_CHECK_CACHE) {
|
||||
if (fstat(fileno(gi->GeoIPDatabase), &buf) != -1) {
|
||||
if (buf.st_mtime > gi->mtime) {
|
||||
/* GeoIP Database file updated, reload database into memory cache */
|
||||
if (realloc(gi->cache, buf.st_size) != NULL) {
|
||||
if (fread(gi->cache, sizeof(unsigned char), buf.st_size, gi->GeoIPDatabase) != (size_t) buf.st_size) {
|
||||
fprintf(stderr,"Error reading file %s\n",gi->file_path);
|
||||
return -1;
|
||||
}
|
||||
gi->mtime = buf.st_mtime;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _file_exists(const char *file_name) {
|
||||
struct stat file_stat;
|
||||
return( (stat(file_name, &file_stat) == 0) ? 1:0);
|
||||
}
|
||||
|
||||
int GeoIP_db_avail(int type) {
|
||||
const char * filePath;
|
||||
if (type < 0 || type >= NUM_DB_TYPES) {
|
||||
return 0;
|
||||
}
|
||||
filePath = GeoIPDBFileName[type];
|
||||
if (NULL == filePath) {
|
||||
return 0;
|
||||
}
|
||||
return _file_exists(filePath);
|
||||
}
|
||||
|
||||
void _setup_segments(GeoIP * gi) {
|
||||
int i, j;
|
||||
unsigned char delim[3];
|
||||
unsigned char buf[SEGMENT_RECORD_LENGTH];
|
||||
|
||||
/* default to GeoIP Country Edition */
|
||||
gi->databaseType = GEOIP_COUNTRY_EDITION;
|
||||
gi->record_length = STANDARD_RECORD_LENGTH;
|
||||
fseek(gi->GeoIPDatabase, -3l, SEEK_END);
|
||||
for (i = 0; i < STRUCTURE_INFO_MAX_SIZE; i++) {
|
||||
fread(delim, 1, 3, gi->GeoIPDatabase);
|
||||
if (delim[0] == 255 && delim[1] == 255 && delim[2] == 255) {
|
||||
fread(&gi->databaseType, 1, 1, gi->GeoIPDatabase);
|
||||
if (gi->databaseType >= 106) {
|
||||
/* backwards compatibility with databases from April 2003 and earlier */
|
||||
gi->databaseType -= 105;
|
||||
}
|
||||
|
||||
if (gi->databaseType == GEOIP_REGION_EDITION_REV0) {
|
||||
/* Region Edition, pre June 2003 */
|
||||
gi->databaseSegments = malloc(sizeof(int));
|
||||
gi->databaseSegments[0] = STATE_BEGIN_REV0;
|
||||
} else if (gi->databaseType == GEOIP_REGION_EDITION_REV1) {
|
||||
/* Region Edition, post June 2003 */
|
||||
gi->databaseSegments = malloc(sizeof(int));
|
||||
gi->databaseSegments[0] = STATE_BEGIN_REV1;
|
||||
} else if (gi->databaseType == GEOIP_CITY_EDITION_REV0 ||
|
||||
gi->databaseType == GEOIP_CITY_EDITION_REV1 ||
|
||||
gi->databaseType == GEOIP_ORG_EDITION ||
|
||||
gi->databaseType == GEOIP_ISP_EDITION ||
|
||||
gi->databaseType == GEOIP_ASNUM_EDITION) {
|
||||
/* City/Org Editions have two segments, read offset of second segment */
|
||||
gi->databaseSegments = malloc(sizeof(int));
|
||||
gi->databaseSegments[0] = 0;
|
||||
fread(buf, SEGMENT_RECORD_LENGTH, 1, gi->GeoIPDatabase);
|
||||
for (j = 0; j < SEGMENT_RECORD_LENGTH; j++) {
|
||||
gi->databaseSegments[0] += (buf[j] << (j * 8));
|
||||
}
|
||||
if (gi->databaseType == GEOIP_ORG_EDITION ||
|
||||
gi->databaseType == GEOIP_ISP_EDITION)
|
||||
gi->record_length = ORG_RECORD_LENGTH;
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
fseek(gi->GeoIPDatabase, -4l, SEEK_CUR);
|
||||
}
|
||||
}
|
||||
if (gi->databaseType == GEOIP_COUNTRY_EDITION ||
|
||||
gi->databaseType == GEOIP_PROXY_EDITION ||
|
||||
gi->databaseType == GEOIP_NETSPEED_EDITION) {
|
||||
gi->databaseSegments = malloc(sizeof(int));
|
||||
gi->databaseSegments[0] = COUNTRY_BEGIN;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int _seek_record (GeoIP *gi, unsigned long ipnum) {
|
||||
int depth;
|
||||
unsigned int x;
|
||||
unsigned char stack_buffer[2 * MAX_RECORD_LENGTH];
|
||||
const unsigned char *buf = (gi->cache == NULL) ? stack_buffer : NULL;
|
||||
unsigned int offset = 0;
|
||||
|
||||
const unsigned char * p;
|
||||
int j;
|
||||
|
||||
_check_mtime(gi);
|
||||
for (depth = 31; depth >= 0; depth--) {
|
||||
if (gi->cache == NULL) {
|
||||
/* read from disk */
|
||||
fseek(gi->GeoIPDatabase, (long)gi->record_length * 2 * offset, SEEK_SET);
|
||||
fread(stack_buffer,gi->record_length,2,gi->GeoIPDatabase);
|
||||
} else {
|
||||
/* simply point to record in memory */
|
||||
buf = gi->cache + (long)gi->record_length * 2 *offset;
|
||||
}
|
||||
|
||||
if (ipnum & (1 << depth)) {
|
||||
/* Take the right-hand branch */
|
||||
if ( gi->record_length == 3 ) {
|
||||
/* Most common case is completely unrolled and uses constants. */
|
||||
x = (buf[3*1 + 0] << (0*8))
|
||||
+ (buf[3*1 + 1] << (1*8))
|
||||
+ (buf[3*1 + 2] << (2*8));
|
||||
|
||||
} else {
|
||||
/* General case */
|
||||
j = gi->record_length;
|
||||
p = &buf[2*j];
|
||||
x = 0;
|
||||
do {
|
||||
x <<= 8;
|
||||
x += *(--p);
|
||||
} while ( --j );
|
||||
}
|
||||
|
||||
} else {
|
||||
/* Take the left-hand branch */
|
||||
if ( gi->record_length == 3 ) {
|
||||
/* Most common case is completely unrolled and uses constants. */
|
||||
x = (buf[3*0 + 0] << (0*8))
|
||||
+ (buf[3*0 + 1] << (1*8))
|
||||
+ (buf[3*0 + 2] << (2*8));
|
||||
} else {
|
||||
/* General case */
|
||||
j = gi->record_length;
|
||||
p = &buf[1*j];
|
||||
x = 0;
|
||||
do {
|
||||
x <<= 8;
|
||||
x += *(--p);
|
||||
} while ( --j );
|
||||
}
|
||||
}
|
||||
|
||||
if (x >= gi->databaseSegments[0]) {
|
||||
return x;
|
||||
}
|
||||
offset = x;
|
||||
}
|
||||
|
||||
/* shouldn't reach here */
|
||||
fprintf(stderr,"Error Traversing Database for ipnum = %lu - Perhaps database is corrupt?\n",ipnum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long _addr_to_num (const char *addr) {
|
||||
int i;
|
||||
char tok[4];
|
||||
int octet;
|
||||
int j = 0, k = 0;
|
||||
unsigned long ipnum = 0;
|
||||
char c = 0;
|
||||
|
||||
for (i=0; i<4; i++) {
|
||||
for (;;) {
|
||||
c = addr[k++];
|
||||
if (c == '.' || c == '\0') {
|
||||
tok[j] = '\0';
|
||||
octet = atoi(tok);
|
||||
if (octet > 255)
|
||||
return 0;
|
||||
ipnum += (octet << ((3-i)*8));
|
||||
j = 0;
|
||||
break;
|
||||
} else if (c >= '0' && c<= '9') {
|
||||
if (j > 2) {
|
||||
return 0;
|
||||
}
|
||||
tok[j++] = c;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(c == '\0' && i<3) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return ipnum;
|
||||
}
|
||||
|
||||
GeoIP* GeoIP_open_type (int type, int flags) {
|
||||
GeoIP * gi;
|
||||
const char * filePath;
|
||||
if (type < 0 || type >= NUM_DB_TYPES) {
|
||||
printf("Invalid database type %d\n", type);
|
||||
return NULL;
|
||||
}
|
||||
_setup_dbfilename();
|
||||
filePath = GeoIPDBFileName[type];
|
||||
if (filePath == NULL) {
|
||||
printf("Invalid database type %d\n", type);
|
||||
return NULL;
|
||||
}
|
||||
gi = GeoIP_open (filePath, flags);
|
||||
return gi;
|
||||
}
|
||||
|
||||
GeoIP* GeoIP_new (int flags) {
|
||||
GeoIP * gi;
|
||||
_setup_dbfilename();
|
||||
gi = GeoIP_open (GeoIPDBFileName[GEOIP_COUNTRY_EDITION], flags);
|
||||
return gi;
|
||||
}
|
||||
|
||||
GeoIP* GeoIP_open (const char * filename, int flags) {
|
||||
struct stat buf;
|
||||
GeoIP *gi = (GeoIP *)malloc(sizeof(GeoIP));
|
||||
|
||||
#ifdef _WIN32
|
||||
WSADATA wsa;
|
||||
if (WSAStartup(MAKEWORD(1, 1), &wsa) != 0)
|
||||
return NULL;
|
||||
#endif
|
||||
|
||||
if (gi == NULL)
|
||||
return NULL;
|
||||
gi->file_path = malloc(sizeof(char) * (strlen(filename)+1));
|
||||
if (gi->file_path == NULL)
|
||||
return NULL;
|
||||
strcpy(gi->file_path, filename);
|
||||
gi->GeoIPDatabase = fopen(filename,"rb");
|
||||
if (gi->GeoIPDatabase == NULL) {
|
||||
fprintf(stderr,"Error Opening file %s\n",filename);
|
||||
free(gi->file_path);
|
||||
free(gi);
|
||||
return NULL;
|
||||
} else {
|
||||
if (flags & GEOIP_MEMORY_CACHE) {
|
||||
if (fstat(fileno(gi->GeoIPDatabase), &buf) == -1) {
|
||||
fprintf(stderr,"Error stating file %s\n",filename);
|
||||
free(gi);
|
||||
return NULL;
|
||||
}
|
||||
gi->mtime = buf.st_mtime;
|
||||
gi->cache = (unsigned char *) malloc(sizeof(unsigned char) * buf.st_size);
|
||||
if (gi->cache != NULL) {
|
||||
if (fread(gi->cache, sizeof(unsigned char), buf.st_size, gi->GeoIPDatabase) != (size_t) buf.st_size) {
|
||||
fprintf(stderr,"Error reading file %s\n",filename);
|
||||
free(gi->cache);
|
||||
free(gi);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
gi->cache = NULL;
|
||||
}
|
||||
gi->flags = flags;
|
||||
_setup_segments(gi);
|
||||
return gi;
|
||||
}
|
||||
}
|
||||
|
||||
void GeoIP_delete (GeoIP *gi) {
|
||||
if (gi->GeoIPDatabase != NULL)
|
||||
fclose(gi->GeoIPDatabase);
|
||||
if (gi->cache != NULL)
|
||||
free(gi->cache);
|
||||
if (gi->file_path != NULL)
|
||||
free(gi->file_path);
|
||||
if (gi->databaseSegments != NULL)
|
||||
free(gi->databaseSegments);
|
||||
free(gi);
|
||||
}
|
||||
|
||||
const char *GeoIP_country_code_by_name (GeoIP* gi, const char *name) {
|
||||
int country_id;
|
||||
country_id = GeoIP_id_by_name(gi, name);
|
||||
return (country_id > 0) ? GeoIP_country_code[country_id] : NULL;
|
||||
}
|
||||
|
||||
const char *GeoIP_country_code3_by_name (GeoIP* gi, const char *name) {
|
||||
int country_id;
|
||||
country_id = GeoIP_id_by_name(gi, name);
|
||||
return (country_id > 0) ? GeoIP_country_code3[country_id] : NULL;
|
||||
}
|
||||
|
||||
const char *GeoIP_country_name_by_name (GeoIP* gi, const char *name) {
|
||||
int country_id;
|
||||
country_id = GeoIP_id_by_name(gi, name);
|
||||
return (country_id > 0) ? GeoIP_country_name[country_id] : NULL;
|
||||
}
|
||||
|
||||
unsigned long lookupaddress (const char *host) {
|
||||
unsigned long addr = inet_addr(host);
|
||||
struct hostent * phe;
|
||||
if (addr == INADDR_NONE)
|
||||
{
|
||||
phe = gethostbyname(host);
|
||||
if (!phe)
|
||||
return 0;
|
||||
addr = *((unsigned long *) phe->h_addr_list[0]);
|
||||
}
|
||||
return ntohl(addr);
|
||||
}
|
||||
|
||||
int GeoIP_id_by_name (GeoIP* gi, const char *name) {
|
||||
unsigned long ipnum;
|
||||
int ret;
|
||||
if (name == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (gi->databaseType != GEOIP_COUNTRY_EDITION && gi->databaseType != GEOIP_PROXY_EDITION && gi->databaseType != GEOIP_NETSPEED_EDITION) {
|
||||
printf("Invalid database type %s, expected %s\n", GeoIPDBDescription[(int)gi->databaseType], GeoIPDBDescription[GEOIP_COUNTRY_EDITION]);
|
||||
return 0;
|
||||
}
|
||||
if (!(ipnum = lookupaddress(name)))
|
||||
return 0;
|
||||
ret = _seek_record(gi, ipnum) - COUNTRY_BEGIN;
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
const char *GeoIP_country_code_by_addr (GeoIP* gi, const char *addr) {
|
||||
int country_id;
|
||||
country_id = GeoIP_id_by_addr(gi, addr);
|
||||
return (country_id > 0) ? GeoIP_country_code[country_id] : NULL;
|
||||
}
|
||||
|
||||
const char *GeoIP_country_code3_by_addr (GeoIP* gi, const char *addr) {
|
||||
int country_id;
|
||||
country_id = GeoIP_id_by_addr(gi, addr);
|
||||
return (country_id > 0) ? GeoIP_country_code3[country_id] : NULL;
|
||||
return GeoIP_country_code3[country_id];
|
||||
}
|
||||
|
||||
const char *GeoIP_country_name_by_addr (GeoIP* gi, const char *addr) {
|
||||
int country_id;
|
||||
country_id = GeoIP_id_by_addr(gi, addr);
|
||||
return (country_id > 0) ? GeoIP_country_name[country_id] : NULL;
|
||||
return GeoIP_country_name[country_id];
|
||||
}
|
||||
|
||||
int GeoIP_country_id_by_addr (GeoIP* gi, const char *addr) {
|
||||
return GeoIP_id_by_addr(gi, addr);
|
||||
}
|
||||
|
||||
int GeoIP_country_id_by_name (GeoIP* gi, const char *host) {
|
||||
return GeoIP_id_by_name(gi, host);
|
||||
}
|
||||
|
||||
int GeoIP_id_by_addr (GeoIP* gi, const char *addr) {
|
||||
unsigned long ipnum;
|
||||
int ret;
|
||||
|
||||
if (addr == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (gi->databaseType != GEOIP_COUNTRY_EDITION && gi->databaseType != GEOIP_PROXY_EDITION && gi->databaseType != GEOIP_NETSPEED_EDITION) {
|
||||
printf("Invalid database type %s, expected %s\n", GeoIPDBDescription[(int)gi->databaseType], GeoIPDBDescription[GEOIP_COUNTRY_EDITION]);
|
||||
return 0;
|
||||
}
|
||||
ipnum = _addr_to_num(addr);
|
||||
ret = _seek_record(gi, ipnum) - COUNTRY_BEGIN;
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *GeoIP_database_info (GeoIP* gi) {
|
||||
int i;
|
||||
unsigned char buf[3];
|
||||
char *retval;
|
||||
int hasStructureInfo = 0;
|
||||
|
||||
if(gi == NULL)
|
||||
return NULL;
|
||||
|
||||
_check_mtime(gi);
|
||||
fseek(gi->GeoIPDatabase, -3l, SEEK_END);
|
||||
|
||||
/* first get past the database structure information */
|
||||
for (i = 0; i < STRUCTURE_INFO_MAX_SIZE; i++) {
|
||||
fread(buf, 1, 3, gi->GeoIPDatabase);
|
||||
if (buf[0] == 255 && buf[1] == 255 && buf[2] == 255) {
|
||||
hasStructureInfo = 1;
|
||||
break;
|
||||
}
|
||||
fseek(gi->GeoIPDatabase, -4l, SEEK_CUR);
|
||||
}
|
||||
if (hasStructureInfo == 1) {
|
||||
fseek(gi->GeoIPDatabase, -3l, SEEK_CUR);
|
||||
} else {
|
||||
/* no structure info, must be pre Sep 2002 database, go back to end */
|
||||
fseek(gi->GeoIPDatabase, -3l, SEEK_END);
|
||||
}
|
||||
|
||||
for (i = 0; i < DATABASE_INFO_MAX_SIZE; i++) {
|
||||
fread(buf, 1, 3, gi->GeoIPDatabase);
|
||||
if (buf[0] == 0 && buf[1] == 0 && buf[2] == 0) {
|
||||
retval = malloc(sizeof(char) * (i+1));
|
||||
if (retval == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
fread(retval, 1, i, gi->GeoIPDatabase);
|
||||
retval[i] = '\0';
|
||||
return retval;
|
||||
}
|
||||
fseek(gi->GeoIPDatabase, -4l, SEEK_CUR);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* GeoIP Region Edition functions */
|
||||
|
||||
void GeoIP_assign_region_by_inetaddr(GeoIP* gi, unsigned long inetaddr, GeoIPRegion *region) {
|
||||
unsigned int seek_region;
|
||||
|
||||
/* This also writes in the terminating NULs (if you decide to
|
||||
* keep them) and clear any fields that are not set. */
|
||||
memset(region, 0, sizeof(GeoIPRegion));
|
||||
|
||||
seek_region = _seek_record(gi, ntohl(inetaddr));
|
||||
|
||||
if (gi->databaseType == GEOIP_REGION_EDITION_REV0) {
|
||||
/* Region Edition, pre June 2003 */
|
||||
seek_region -= STATE_BEGIN_REV0;
|
||||
if (seek_region >= 1000) {
|
||||
region->country_code[0] = 'U';
|
||||
region->country_code[1] = 'S';
|
||||
region->region[0] = (char) ((seek_region - 1000)/26 + 65);
|
||||
region->region[1] = (char) ((seek_region - 1000)%26 + 65);
|
||||
} else {
|
||||
memcpy(region->country_code, GeoIP_country_code[seek_region], 2);
|
||||
}
|
||||
} else if (gi->databaseType == GEOIP_REGION_EDITION_REV1) {
|
||||
/* Region Edition, post June 2003 */
|
||||
seek_region -= STATE_BEGIN_REV1;
|
||||
if (seek_region < US_OFFSET) {
|
||||
/* Unknown */
|
||||
/* we don't need to do anything here b/c we memset region to 0 */
|
||||
} else if (seek_region < CANADA_OFFSET) {
|
||||
/* USA State */
|
||||
region->country_code[0] = 'U';
|
||||
region->country_code[1] = 'S';
|
||||
region->region[0] = (char) ((seek_region - US_OFFSET)/26 + 65);
|
||||
region->region[1] = (char) ((seek_region - US_OFFSET)%26 + 65);
|
||||
} else if (seek_region < WORLD_OFFSET) {
|
||||
/* Canada Province */
|
||||
region->country_code[0] = 'C';
|
||||
region->country_code[1] = 'A';
|
||||
region->region[0] = (char) ((seek_region - CANADA_OFFSET)/26 + 65);
|
||||
region->region[1] = (char) ((seek_region - CANADA_OFFSET)%26 + 65);
|
||||
} else {
|
||||
/* Not US or Canada */
|
||||
memcpy(region->country_code, GeoIP_country_code[(seek_region - WORLD_OFFSET) / FIPS_RANGE], 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GeoIPRegion * _get_region(GeoIP* gi, unsigned long ipnum) {
|
||||
GeoIPRegion * region;
|
||||
|
||||
region = malloc(sizeof(GeoIPRegion));
|
||||
if (region) {
|
||||
GeoIP_assign_region_by_inetaddr(gi, htonl(ipnum), region);
|
||||
}
|
||||
return region;
|
||||
}
|
||||
|
||||
GeoIPRegion * GeoIP_region_by_addr (GeoIP* gi, const char *addr) {
|
||||
unsigned long ipnum;
|
||||
if (addr == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (gi->databaseType != GEOIP_REGION_EDITION_REV0 &&
|
||||
gi->databaseType != GEOIP_REGION_EDITION_REV1) {
|
||||
printf("Invalid database type %s, expected %s\n", GeoIPDBDescription[(int)gi->databaseType], GeoIPDBDescription[GEOIP_REGION_EDITION_REV1]);
|
||||
return 0;
|
||||
}
|
||||
ipnum = _addr_to_num(addr);
|
||||
return _get_region(gi, ipnum);
|
||||
}
|
||||
|
||||
GeoIPRegion * GeoIP_region_by_name (GeoIP* gi, const char *name) {
|
||||
unsigned long ipnum;
|
||||
if (name == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (gi->databaseType != GEOIP_REGION_EDITION_REV0 &&
|
||||
gi->databaseType != GEOIP_REGION_EDITION_REV1) {
|
||||
printf("Invalid database type %s, expected %s\n", GeoIPDBDescription[(int)gi->databaseType], GeoIPDBDescription[GEOIP_REGION_EDITION_REV1]);
|
||||
return 0;
|
||||
}
|
||||
if (!(ipnum = lookupaddress(name)))
|
||||
return 0;
|
||||
return _get_region(gi, ipnum);
|
||||
}
|
||||
|
||||
void GeoIPRegion_delete (GeoIPRegion *gir) {
|
||||
free(gir);
|
||||
}
|
||||
|
||||
/* GeoIP Organization, ISP and AS Number Edition private method */
|
||||
char *_get_name (GeoIP* gi, unsigned long ipnum) {
|
||||
int seek_org;
|
||||
char buf[MAX_ORG_RECORD_LENGTH];
|
||||
char * org_buf, * buf_pointer;
|
||||
int record_pointer;
|
||||
|
||||
if (gi->databaseType != GEOIP_ORG_EDITION &&
|
||||
gi->databaseType != GEOIP_ISP_EDITION &&
|
||||
gi->databaseType != GEOIP_ASNUM_EDITION) {
|
||||
printf("Invalid database type %s, expected %s\n", GeoIPDBDescription[(int)gi->databaseType], GeoIPDBDescription[GEOIP_ORG_EDITION]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
seek_org = _seek_record(gi, ipnum);
|
||||
if (seek_org == gi->databaseSegments[0])
|
||||
return NULL;
|
||||
|
||||
record_pointer = seek_org + (2 * gi->record_length - 1) * gi->databaseSegments[0];
|
||||
|
||||
if (gi->cache == NULL) {
|
||||
fseek(gi->GeoIPDatabase, record_pointer, SEEK_SET);
|
||||
fread(buf, sizeof(char), MAX_ORG_RECORD_LENGTH, gi->GeoIPDatabase);
|
||||
org_buf = malloc(sizeof(char) * (strlen(buf)+1));
|
||||
strcpy(org_buf, buf);
|
||||
} else {
|
||||
buf_pointer = gi->cache + (long)record_pointer;
|
||||
org_buf = malloc(sizeof(char) * (strlen(buf_pointer)+1));
|
||||
strcpy(org_buf, buf_pointer);
|
||||
}
|
||||
return org_buf;
|
||||
}
|
||||
|
||||
char *GeoIP_name_by_addr (GeoIP* gi, const char *addr) {
|
||||
unsigned long ipnum;
|
||||
if (addr == NULL) {
|
||||
return 0;
|
||||
}
|
||||
ipnum = _addr_to_num(addr);
|
||||
return _get_name(gi, ipnum);
|
||||
}
|
||||
|
||||
char *GeoIP_name_by_name (GeoIP* gi, const char *name) {
|
||||
unsigned long ipnum;
|
||||
if (name == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (!(ipnum = lookupaddress(name)))
|
||||
return 0;
|
||||
return _get_name(gi, ipnum);
|
||||
}
|
||||
|
||||
char *GeoIP_org_by_addr (GeoIP* gi, const char *addr) {
|
||||
return GeoIP_name_by_addr(gi, addr);
|
||||
}
|
||||
|
||||
char *GeoIP_org_by_name (GeoIP* gi, const char *name) {
|
||||
return GeoIP_name_by_name(gi, name);
|
||||
}
|
||||
|
||||
unsigned char GeoIP_database_edition (GeoIP* gi) {
|
||||
return gi->databaseType;
|
||||
}
|
158
dlls/geoip/geolib/libGeoIP/GeoIP.h
Executable file
158
dlls/geoip/geolib/libGeoIP/GeoIP.h
Executable file
@ -0,0 +1,158 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/* GeoIP.h
|
||||
*
|
||||
* Copyright (C) 2003 MaxMind LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef GEOIP_H
|
||||
#define GEOIP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<string.h>
|
||||
#include <sys/types.h> /* for fstat */
|
||||
#include <sys/stat.h> /* for fstat */
|
||||
|
||||
//typedef int uint32_t;
|
||||
|
||||
#define SEGMENT_RECORD_LENGTH 3
|
||||
#define STANDARD_RECORD_LENGTH 3
|
||||
#define ORG_RECORD_LENGTH 4
|
||||
#define MAX_RECORD_LENGTH 4
|
||||
#define NUM_DB_TYPES 16
|
||||
|
||||
typedef struct GeoIPTag {
|
||||
FILE *GeoIPDatabase;
|
||||
char *file_path;
|
||||
unsigned char *cache;
|
||||
unsigned int *databaseSegments;
|
||||
char databaseType;
|
||||
time_t mtime;
|
||||
int flags;
|
||||
char record_length;
|
||||
int record_iter; /* used in GeoIP_next_record */
|
||||
} GeoIP;
|
||||
|
||||
typedef struct GeoIPRegionTag {
|
||||
char country_code[3];
|
||||
char region[3];
|
||||
} GeoIPRegion;
|
||||
|
||||
typedef enum {
|
||||
GEOIP_STANDARD = 0,
|
||||
GEOIP_MEMORY_CACHE = 1,
|
||||
GEOIP_CHECK_CACHE = 2,
|
||||
} GeoIPOptions;
|
||||
|
||||
typedef enum {
|
||||
GEOIP_COUNTRY_EDITION = 1,
|
||||
GEOIP_REGION_EDITION_REV0 = 7,
|
||||
GEOIP_CITY_EDITION_REV0 = 6,
|
||||
GEOIP_ORG_EDITION = 5,
|
||||
GEOIP_ISP_EDITION = 4,
|
||||
GEOIP_CITY_EDITION_REV1 = 2,
|
||||
GEOIP_REGION_EDITION_REV1 = 3,
|
||||
GEOIP_PROXY_EDITION = 8,
|
||||
GEOIP_ASNUM_EDITION = 9,
|
||||
GEOIP_NETSPEED_EDITION = 10,
|
||||
} GeoIPDBTypes;
|
||||
|
||||
typedef enum {
|
||||
GEOIP_ANON_PROXY = 1,
|
||||
GEOIP_HTTP_X_FORWARDED_FOR_PROXY = 2,
|
||||
GEOIP_HTTP_CLIENT_IP_PROXY = 3,
|
||||
} GeoIPProxyTypes;
|
||||
|
||||
typedef enum {
|
||||
GEOIP_UNKNOWN_SPEED = 0,
|
||||
GEOIP_DIALUP_SPEED = 1,
|
||||
GEOIP_CABLEDSL_SPEED = 2,
|
||||
GEOIP_CORPORATE_SPEED = 3,
|
||||
} GeoIPNetspeedValues;
|
||||
|
||||
extern char **GeoIPDBFileName;
|
||||
extern const char * GeoIPDBDescription[NUM_DB_TYPES];
|
||||
extern const char *GeoIPCountryDBFileName;
|
||||
extern const char *GeoIPRegionDBFileName;
|
||||
extern const char *GeoIPCityDBFileName;
|
||||
extern const char *GeoIPOrgDBFileName;
|
||||
extern const char *GeoIPISPDBFileName;
|
||||
|
||||
extern const char GeoIP_country_code[247][3];
|
||||
extern const char GeoIP_country_code3[247][4];
|
||||
extern const char * GeoIP_country_name[247];
|
||||
extern const char GeoIP_country_continent[247][3];
|
||||
|
||||
#ifdef DLL
|
||||
#define GEOIP_API __declspec(dllexport)
|
||||
#else
|
||||
#define GEOIP_API
|
||||
#endif /* DLL */
|
||||
|
||||
GEOIP_API GeoIP* GeoIP_open_type (int type, int flags);
|
||||
GEOIP_API GeoIP* GeoIP_new(int flags);
|
||||
GEOIP_API GeoIP* GeoIP_open(const char * filename, int flags);
|
||||
GEOIP_API int GeoIP_db_avail(int type);
|
||||
GEOIP_API void GeoIP_delete(GeoIP* gi);
|
||||
GEOIP_API const char *GeoIP_country_code_by_addr (GeoIP* gi, const char *addr);
|
||||
GEOIP_API const char *GeoIP_country_code_by_name (GeoIP* gi, const char *host);
|
||||
GEOIP_API const char *GeoIP_country_code3_by_addr (GeoIP* gi, const char *addr);
|
||||
GEOIP_API const char *GeoIP_country_code3_by_name (GeoIP* gi, const char *host);
|
||||
GEOIP_API const char *GeoIP_country_name_by_addr (GeoIP* gi, const char *addr);
|
||||
GEOIP_API const char *GeoIP_country_name_by_name (GeoIP* gi, const char *host);
|
||||
|
||||
/* Deprecated - for backwards compatibility only */
|
||||
GEOIP_API int GeoIP_country_id_by_addr (GeoIP* gi, const char *addr);
|
||||
GEOIP_API int GeoIP_country_id_by_name (GeoIP* gi, const char *host);
|
||||
GEOIP_API char *GeoIP_org_by_addr (GeoIP* gi, const char *addr);
|
||||
GEOIP_API char *GeoIP_org_by_name (GeoIP* gi, const char *host);
|
||||
/* End deprecated */
|
||||
|
||||
GEOIP_API int GeoIP_id_by_addr (GeoIP* gi, const char *addr);
|
||||
GEOIP_API int GeoIP_id_by_name (GeoIP* gi, const char *host);
|
||||
|
||||
GEOIP_API GeoIPRegion * GeoIP_region_by_addr (GeoIP* gi, const char *addr);
|
||||
GEOIP_API GeoIPRegion * GeoIP_region_by_name (GeoIP* gi, const char *host);
|
||||
|
||||
/* Warning - don't call this after GeoIP_assign_region_by_inetaddr calls */
|
||||
GEOIP_API void GeoIPRegion_delete (GeoIPRegion *gir);
|
||||
|
||||
GEOIP_API void GeoIP_assign_region_by_inetaddr(GeoIP* gi, unsigned long inetaddr, GeoIPRegion *gir);
|
||||
|
||||
/* Used to query GeoIP Organization, ISP and AS Number databases */
|
||||
GEOIP_API char *GeoIP_name_by_addr (GeoIP* gi, const char *addr);
|
||||
GEOIP_API char *GeoIP_name_by_name (GeoIP* gi, const char *host);
|
||||
|
||||
GEOIP_API char *GeoIP_database_info (GeoIP* gi);
|
||||
GEOIP_API unsigned char GeoIP_database_edition (GeoIP* gi);
|
||||
|
||||
GEOIP_API unsigned int _seek_record (GeoIP *gi, unsigned long ipnum);
|
||||
GEOIP_API unsigned long _addr_to_num (const char *addr);
|
||||
|
||||
#ifdef BSD
|
||||
#define memcpy(dest, src, n) bcopy(src, dest, n)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GEOIP_H */
|
55
dlls/geoip/geolib/libGeoIP/GeoIPBitReader.c
Executable file
55
dlls/geoip/geolib/libGeoIP/GeoIPBitReader.c
Executable file
@ -0,0 +1,55 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/* GeoIPBitReader.c
|
||||
*
|
||||
* Copyright (C) 2002 MaxMind.com. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "GeoIPBitReader.h"
|
||||
|
||||
GeoIPBitReader * GeoIPBitReader_new(const char * filename) {
|
||||
GeoIPBitReader *gibr = (GeoIPBitReader *)malloc(sizeof(GeoIPBitReader));
|
||||
gibr->GeoIPBitFH = fopen(filename,"rb");
|
||||
if (gibr->GeoIPBitFH == NULL) {
|
||||
fprintf(stderr, "Error Opening file %s\n",filename);
|
||||
return NULL;
|
||||
}
|
||||
gibr->position = 8;
|
||||
return gibr;
|
||||
}
|
||||
|
||||
unsigned long GeoIPBitReader_read(GeoIPBitReader * gibr, short int numBits) {
|
||||
unsigned long num = 0;
|
||||
int i, bit;
|
||||
int bytes_read;
|
||||
|
||||
for (i = 0; i < numBits; ++i) {
|
||||
if (BITS_IN_BYTE == gibr->position) {
|
||||
/* read in next byte */
|
||||
bytes_read = fread(&gibr->bits, 1, 1, gibr->GeoIPBitFH);
|
||||
if (bytes_read == 0) {
|
||||
fprintf(stderr, "Warning: EOF reached\n");
|
||||
gibr->bits = 0;
|
||||
}
|
||||
gibr->position = 0;
|
||||
}
|
||||
bit = ((gibr->bits & (1 << (BITS_IN_BYTE - gibr->position - 1))) > 0) ? 1 : 0;
|
||||
bit <<= i;
|
||||
num += bit;
|
||||
++(gibr->position);
|
||||
}
|
||||
return num;
|
||||
}
|
52
dlls/geoip/geolib/libGeoIP/GeoIPBitReader.h
Executable file
52
dlls/geoip/geolib/libGeoIP/GeoIPBitReader.h
Executable file
@ -0,0 +1,52 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/* GeoIPBitReader.h
|
||||
*
|
||||
* Copyright (C) 2002 MaxMind.com. All Rights Reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef GEOIPBITREADER_H
|
||||
#define GEOIPBITREADER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
#define BITS_IN_BYTE 8
|
||||
|
||||
typedef struct GeoIPBitReaderTag {
|
||||
FILE *GeoIPBitFH;
|
||||
char bits;
|
||||
short int position;
|
||||
} GeoIPBitReader;
|
||||
|
||||
typedef enum {
|
||||
EOF_FLAG = 0,
|
||||
NOOP_FLAG = 1,
|
||||
VALUE_FLAG = 2
|
||||
} GeoIPBitReaderRecordCode;
|
||||
|
||||
GeoIPBitReader * GeoIPBitReader_new(const char * filename);
|
||||
unsigned long GeoIPBitReader_read(GeoIPBitReader * gibr, short int numBits);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // GEOIPBITREADER_H
|
202
dlls/geoip/geolib/libGeoIP/GeoIPCity.c
Executable file
202
dlls/geoip/geolib/libGeoIP/GeoIPCity.c
Executable file
@ -0,0 +1,202 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/* GeoIPCity.c
|
||||
*
|
||||
* Copyright (C) 2003 MaxMind LLC
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <GeoIP.h>
|
||||
#include <GeoIPCity.h>
|
||||
#ifndef _WIN32
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h> /* For ntohl */
|
||||
#else
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#include <sys/types.h> /* For uint32_t */
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h> /* For uint32_t */
|
||||
#endif
|
||||
|
||||
const int FULL_RECORD_LENGTH = 50;
|
||||
|
||||
GeoIPRecord * _extract_record(GeoIP* gi, unsigned int seek_record, int *next_record_ptr) {
|
||||
int record_pointer;
|
||||
unsigned char *record_buf = NULL;
|
||||
unsigned char *begin_record_buf = NULL;
|
||||
GeoIPRecord * record;
|
||||
int str_length = 0;
|
||||
int j;
|
||||
double latitude = 0, longitude = 0;
|
||||
int dmaarea_combo = 0;
|
||||
int bytes_read = 0;
|
||||
if (seek_record == gi->databaseSegments[0])
|
||||
return NULL;
|
||||
|
||||
record = malloc(sizeof(GeoIPRecord));
|
||||
memset(record, 0, sizeof(GeoIPRecord));
|
||||
|
||||
record_pointer = seek_record + (2 * gi->record_length - 1) * gi->databaseSegments[0];
|
||||
|
||||
if (gi->cache == NULL) {
|
||||
fseek(gi->GeoIPDatabase, record_pointer, SEEK_SET);
|
||||
begin_record_buf = record_buf = malloc(sizeof(char) * FULL_RECORD_LENGTH);
|
||||
bytes_read = fread(record_buf, sizeof(char), FULL_RECORD_LENGTH, gi->GeoIPDatabase);
|
||||
if (bytes_read == 0) {
|
||||
/* eof or other error */
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
record_buf = gi->cache + (long)record_pointer;
|
||||
}
|
||||
|
||||
/* get country */
|
||||
record->country_code = (char *) GeoIP_country_code [record_buf[0]];
|
||||
record->country_code3 = (char *) GeoIP_country_code3[record_buf[0]];
|
||||
record->country_name = (char *) GeoIP_country_name [record_buf[0]];
|
||||
record_buf++;
|
||||
|
||||
/* get region */
|
||||
while (record_buf[str_length] != '\0')
|
||||
str_length++;
|
||||
if (str_length > 0) {
|
||||
record->region = malloc(str_length+1);
|
||||
strncpy(record->region, record_buf, str_length+1);
|
||||
}
|
||||
record_buf += str_length + 1;
|
||||
str_length = 0;
|
||||
|
||||
/* get city */
|
||||
while (record_buf[str_length] != '\0')
|
||||
str_length++;
|
||||
if (str_length > 0) {
|
||||
record->city = malloc(str_length+1);
|
||||
strncpy(record->city, record_buf, str_length+1);
|
||||
}
|
||||
record_buf += (str_length + 1);
|
||||
str_length = 0;
|
||||
|
||||
/* get postal code */
|
||||
while (record_buf[str_length] != '\0')
|
||||
str_length++;
|
||||
if (str_length > 0) {
|
||||
record->postal_code = malloc(str_length+1);
|
||||
strncpy(record->postal_code, record_buf, str_length+1);
|
||||
}
|
||||
record_buf += (str_length + 1);
|
||||
|
||||
/* get latitude */
|
||||
for (j = 0; j < 3; ++j)
|
||||
latitude += (record_buf[j] << (j * 8));
|
||||
record->latitude = latitude/10000 - 180;
|
||||
record_buf += 3;
|
||||
|
||||
/* get longitude */
|
||||
for (j = 0; j < 3; ++j)
|
||||
longitude += (record_buf[j] << (j * 8));
|
||||
record->longitude = longitude/10000 - 180;
|
||||
|
||||
/* get area code and dma code for post April 2002 databases and for US locations */
|
||||
if (GEOIP_CITY_EDITION_REV1 == gi->databaseType) {
|
||||
if (!strcmp(record->country_code, "US")) {
|
||||
record_buf += 3;
|
||||
for (j = 0; j < 3; ++j)
|
||||
dmaarea_combo += (record_buf[j] << (j * 8));
|
||||
record->dma_code = dmaarea_combo/1000;
|
||||
record->area_code = dmaarea_combo % 1000;
|
||||
}
|
||||
}
|
||||
|
||||
if (gi->cache == NULL)
|
||||
free(begin_record_buf);
|
||||
|
||||
/* Used for GeoIP_next_record */
|
||||
if (next_record_ptr != NULL)
|
||||
*next_record_ptr = seek_record + record_buf - begin_record_buf + 3;
|
||||
|
||||
return record;
|
||||
}
|
||||
|
||||
GeoIPRecord * _get_record(GeoIP* gi, unsigned long ipnum) {
|
||||
unsigned int seek_record;
|
||||
|
||||
if (gi->databaseType != GEOIP_CITY_EDITION_REV0 &&
|
||||
gi->databaseType != GEOIP_CITY_EDITION_REV1) {
|
||||
printf("Invalid database type %s, expected %s\n", GeoIPDBDescription[(int)gi->databaseType], GeoIPDBDescription[GEOIP_CITY_EDITION_REV1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
seek_record = _seek_record(gi, ipnum);
|
||||
return _extract_record(gi, seek_record, NULL);
|
||||
}
|
||||
|
||||
GeoIPRecord * GeoIP_record_by_addr (GeoIP* gi, const char *addr) {
|
||||
unsigned long ipnum;
|
||||
if (addr == NULL) {
|
||||
return 0;
|
||||
}
|
||||
ipnum = _addr_to_num(addr);
|
||||
return _get_record(gi, ipnum);
|
||||
}
|
||||
|
||||
GeoIPRecord * GeoIP_record_by_name (GeoIP* gi, const char *name) {
|
||||
unsigned long ipnum;
|
||||
struct hostent * host;
|
||||
if (name == NULL) {
|
||||
return 0;
|
||||
}
|
||||
host = gethostbyname(name);
|
||||
if (host == NULL) {
|
||||
return 0;
|
||||
}
|
||||
ipnum = ntohl(*((unsigned int*)host->h_addr_list[0]));
|
||||
return _get_record(gi, ipnum);
|
||||
}
|
||||
|
||||
int GeoIP_record_id_by_addr (GeoIP* gi, const char *addr) {
|
||||
unsigned long ipnum;
|
||||
if (gi->databaseType != GEOIP_CITY_EDITION_REV0 &&
|
||||
gi->databaseType != GEOIP_CITY_EDITION_REV1) {
|
||||
printf("Invalid database type %s, expected %s\n", GeoIPDBDescription[(int)gi->databaseType], GeoIPDBDescription[GEOIP_CITY_EDITION_REV1]);
|
||||
return 0;
|
||||
}
|
||||
if (addr == NULL) {
|
||||
return 0;
|
||||
}
|
||||
ipnum = _addr_to_num(addr);
|
||||
return _seek_record(gi, ipnum);
|
||||
}
|
||||
|
||||
int GeoIP_init_record_iter (GeoIP* gi) {
|
||||
return gi->databaseSegments[0] + 1;
|
||||
}
|
||||
|
||||
int GeoIP_next_record (GeoIP* gi, GeoIPRecord **gir, int *record_iter) {
|
||||
if (gi->cache != NULL) {
|
||||
printf("GeoIP_next_record not supported in memory cache mode\n");
|
||||
return 1;
|
||||
}
|
||||
*gir = _extract_record(gi, *record_iter, record_iter);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GeoIPRecord_delete (GeoIPRecord *gir) {
|
||||
free(gir->region);
|
||||
free(gir->city);
|
||||
free(gir->postal_code);
|
||||
free(gir);
|
||||
}
|
57
dlls/geoip/geolib/libGeoIP/GeoIPCity.h
Executable file
57
dlls/geoip/geolib/libGeoIP/GeoIPCity.h
Executable file
@ -0,0 +1,57 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/* GeoIPCity.h
|
||||
*
|
||||
* Copyright (C) 2003 MaxMind LLC All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef GEOIPCITY_H
|
||||
#define GEOIPCITY_H
|
||||
|
||||
#include "GeoIP.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct GeoIPRecordTag {
|
||||
char *country_code;
|
||||
char *country_code3;
|
||||
char *country_name;
|
||||
char *region;
|
||||
char *city;
|
||||
char *postal_code;
|
||||
float latitude;
|
||||
float longitude;
|
||||
int dma_code;
|
||||
int area_code;
|
||||
} GeoIPRecord;
|
||||
|
||||
GeoIPRecord * GeoIP_record_by_addr (GeoIP* gi, const char *addr);
|
||||
GeoIPRecord * GeoIP_record_by_name (GeoIP* gi, const char *host);
|
||||
|
||||
int GeoIP_record_id_by_addr (GeoIP* gi, const char *addr);
|
||||
int GeoIP_init_record_iter (GeoIP* gi);
|
||||
/* returns 0 on success, 1 on failure */
|
||||
int GeoIP_next_record (GeoIP* gi, GeoIPRecord **gir, int *record_iter);
|
||||
|
||||
void GeoIPRecord_delete (GeoIPRecord *gir);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GEOIPCITY_H */
|
305
dlls/geoip/geolib/libGeoIP/GeoIPUpdate.c
Executable file
305
dlls/geoip/geolib/libGeoIP/GeoIPUpdate.c
Executable file
@ -0,0 +1,305 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/* GeoIPUpdate.c
|
||||
*
|
||||
* Copyright (C) 2002 MaxMind.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "GeoIP.h"
|
||||
#include "GeoIPUpdate.h"
|
||||
|
||||
#include "global.h"
|
||||
#include "md5.h"
|
||||
#include <sys/types.h>
|
||||
#ifndef _WIN32
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#else
|
||||
#include <windows.h>
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#include <zlib.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
//#include <unistd.h>
|
||||
|
||||
extern void _setup_dbfilename();
|
||||
|
||||
const char *GeoIPUpdateHost = "updates.maxmind.com";
|
||||
const char *GeoIPHTTPRequest = "GET /app/update?license_key=%s&md5=%s HTTP/1.0\nHost: updates.maxmind.com\n\n";
|
||||
|
||||
/* messages */
|
||||
const char *NoCurrentDB = "%s can't be opened, proceeding to download database\n";
|
||||
const char *MD5Info = "MD5 Digest of installed database is %s\n";
|
||||
const char *SavingGzip = "Saving gzip file to %s ... ";
|
||||
const char *WritingFile = "Writing uncompressed data to %s ...";
|
||||
|
||||
void GeoIP_printf(void (*f)(char *), const char *str) {
|
||||
char * f_str;
|
||||
f_str = malloc(strlen(str)+1);
|
||||
strcpy(f_str,str);
|
||||
if (f != NULL)
|
||||
(*f)(f_str);
|
||||
}
|
||||
|
||||
short int GeoIP_update_database (char * license_key, int verbose, void (*f)( char *)) {
|
||||
struct hostent *hostlist;
|
||||
int sock, len;
|
||||
char * buf;
|
||||
struct sockaddr_in sa;
|
||||
int offset = 0, err;
|
||||
int block_size = 1024;
|
||||
char * request_uri;
|
||||
char *uncompr = NULL, *compr;
|
||||
unsigned long comprLen;
|
||||
FILE *comp_fh, *cur_db_fh, *gi_fh;
|
||||
gzFile gz_fh;
|
||||
char * file_path_gz, * file_path_test;
|
||||
MD5_CTX context;
|
||||
unsigned char buffer[1024], digest[16];
|
||||
char hex_digest[32] = "00000000000000000000000000000000";
|
||||
unsigned int i;
|
||||
char *f_str;
|
||||
GeoIP * gi;
|
||||
char * db_info;
|
||||
|
||||
_setup_dbfilename();
|
||||
|
||||
/* get MD5 of current GeoIP database file */
|
||||
if ((cur_db_fh = fopen (GeoIPDBFileName[GEOIP_COUNTRY_EDITION], "rb")) == NULL) {
|
||||
f_str = malloc(strlen(NoCurrentDB) + strlen(GeoIPDBFileName[GEOIP_COUNTRY_EDITION]) - 1);
|
||||
sprintf(f_str,NoCurrentDB, GeoIPDBFileName[GEOIP_COUNTRY_EDITION]);
|
||||
if (f != NULL)
|
||||
(*f)(f_str);
|
||||
} else {
|
||||
MD5Init(&context);
|
||||
while ((len = fread (buffer, 1, 1024, cur_db_fh)) > 0)
|
||||
MD5Update (&context, buffer, len);
|
||||
MD5Final (digest, &context);
|
||||
fclose (cur_db_fh);
|
||||
for (i = 0; i < 16; i++)
|
||||
sprintf (&hex_digest[2*i], "%02x", digest[i]);
|
||||
f_str = malloc(strlen(MD5Info) + strlen(hex_digest) - 1);
|
||||
sprintf(f_str, MD5Info, hex_digest);
|
||||
if (f != NULL)
|
||||
(*f)(f_str);
|
||||
}
|
||||
|
||||
hostlist = gethostbyname(GeoIPUpdateHost);
|
||||
|
||||
if (hostlist == NULL)
|
||||
return GEOIP_DNS_ERR;
|
||||
|
||||
if (hostlist->h_addrtype != AF_INET)
|
||||
return GEOIP_NON_IPV4_ERR;
|
||||
|
||||
if((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
return GEOIP_SOCKET_OPEN_ERR;
|
||||
}
|
||||
|
||||
memset(&sa, 0, sizeof(struct sockaddr_in));
|
||||
sa.sin_port = htons(80);
|
||||
memcpy(&sa.sin_addr, hostlist->h_addr_list[0], hostlist->h_length);
|
||||
sa.sin_family = AF_INET;
|
||||
|
||||
if (verbose == 1)
|
||||
GeoIP_printf(f,"Connecting to MaxMind GeoIP Update server\n");
|
||||
|
||||
/* Download gzip file */
|
||||
if (connect(sock, (struct sockaddr *)&sa, sizeof(struct sockaddr))< 0)
|
||||
return GEOIP_CONNECTION_ERR;
|
||||
|
||||
request_uri = malloc(sizeof(char) * (strlen(license_key) + strlen(GeoIPHTTPRequest)+36));
|
||||
if (request_uri == NULL)
|
||||
return GEOIP_OUT_OF_MEMORY_ERR;
|
||||
sprintf(request_uri,GeoIPHTTPRequest,license_key, hex_digest);
|
||||
send(sock, request_uri, strlen(request_uri),0);
|
||||
free(request_uri);
|
||||
|
||||
buf = malloc(sizeof(char) * block_size);
|
||||
if (buf == NULL)
|
||||
return GEOIP_OUT_OF_MEMORY_ERR;
|
||||
|
||||
if (verbose == 1)
|
||||
GeoIP_printf(f,"Downloading gzipped GeoIP Database...\n");
|
||||
|
||||
for (;;) {
|
||||
int amt;
|
||||
amt = recv(sock, &buf[offset], block_size,0);
|
||||
if (amt == 0) {
|
||||
break;
|
||||
} else if (amt == -1) {
|
||||
free(buf);
|
||||
return GEOIP_SOCKET_READ_ERR;
|
||||
}
|
||||
offset += amt;
|
||||
buf = realloc(buf, offset+block_size);
|
||||
if (buf == NULL)
|
||||
return GEOIP_OUT_OF_MEMORY_ERR;
|
||||
}
|
||||
|
||||
compr = strstr(buf, "\r\n\r\n") + 4;
|
||||
comprLen = offset + buf - compr;
|
||||
|
||||
if (strstr(compr, "License Key Invalid") != NULL) {
|
||||
if (verbose == 1)
|
||||
GeoIP_printf(f,"Failed\n");
|
||||
free(buf);
|
||||
return GEOIP_LICENSE_KEY_INVALID_ERR;
|
||||
} else if (strstr(compr, "No new updates available") != NULL) {
|
||||
free(buf);
|
||||
return GEOIP_NO_NEW_UPDATES;
|
||||
}
|
||||
|
||||
if (verbose == 1)
|
||||
GeoIP_printf(f,"Done\n");
|
||||
|
||||
/* save gzip file */
|
||||
file_path_gz = malloc(sizeof(char) * (strlen(GeoIPDBFileName[GEOIP_COUNTRY_EDITION]) + 4));
|
||||
if (file_path_gz == NULL)
|
||||
return GEOIP_OUT_OF_MEMORY_ERR;
|
||||
strcpy(file_path_gz,GeoIPDBFileName[GEOIP_COUNTRY_EDITION]);
|
||||
strcat(file_path_gz,".gz");
|
||||
if (verbose == 1) {
|
||||
f_str = malloc(strlen(SavingGzip) + strlen(file_path_gz) - 1);
|
||||
sprintf(f_str,SavingGzip,file_path_gz);
|
||||
if (f != NULL)
|
||||
(*f)(f_str);
|
||||
}
|
||||
comp_fh = fopen(file_path_gz, "wb");
|
||||
|
||||
if(comp_fh == NULL) {
|
||||
free(buf);
|
||||
return GEOIP_GZIP_IO_ERR;
|
||||
}
|
||||
|
||||
fwrite(compr, 1, comprLen, comp_fh);
|
||||
fclose(comp_fh);
|
||||
free(buf);
|
||||
|
||||
if (verbose == 1)
|
||||
GeoIP_printf(f,"Done\n");
|
||||
|
||||
if (verbose == 1)
|
||||
GeoIP_printf(f,"Uncompressing gzip file ... ");
|
||||
|
||||
/* uncompress gzip file */
|
||||
offset = 0;
|
||||
gz_fh = gzopen(file_path_gz, "rb");
|
||||
free(file_path_gz);
|
||||
for (;;) {
|
||||
int amt;
|
||||
uncompr = realloc(uncompr, offset+block_size);
|
||||
if (uncompr == NULL)
|
||||
return GEOIP_OUT_OF_MEMORY_ERR;
|
||||
amt = gzread(gz_fh, &uncompr[offset], block_size);
|
||||
if (amt == -1) {
|
||||
gzclose(gz_fh);
|
||||
return GEOIP_GZIP_READ_ERR;
|
||||
}
|
||||
if (amt == 0) {
|
||||
break;
|
||||
}
|
||||
offset += amt;
|
||||
}
|
||||
gzclose(gz_fh);
|
||||
unlink(file_path_gz);
|
||||
|
||||
if (verbose == 1)
|
||||
GeoIP_printf(f,"Done\n");
|
||||
|
||||
if (verbose == 1) {
|
||||
f_str = malloc(strlen(WritingFile) + strlen(GeoIPDBFileName[GEOIP_COUNTRY_EDITION]) - 1);
|
||||
sprintf(f_str,WritingFile,GeoIPDBFileName[GEOIP_COUNTRY_EDITION]);
|
||||
}
|
||||
|
||||
/* write uncompressed GeoIP.dat.test file */
|
||||
file_path_test = malloc(sizeof(char) * (strlen(GeoIPDBFileName[GEOIP_COUNTRY_EDITION]) + 6));
|
||||
if (file_path_test == NULL)
|
||||
return GEOIP_OUT_OF_MEMORY_ERR;
|
||||
strcpy(file_path_test,GeoIPDBFileName[GEOIP_COUNTRY_EDITION]);
|
||||
strcat(file_path_test,".test");
|
||||
gi_fh = fopen(file_path_test, "wb");
|
||||
|
||||
if(gi_fh == NULL) {
|
||||
free(uncompr);
|
||||
return GEOIP_TEST_IO_ERR;
|
||||
}
|
||||
|
||||
fwrite(uncompr, 1, offset, gi_fh);
|
||||
fclose(gi_fh);
|
||||
free(uncompr);
|
||||
|
||||
/* sanity check */
|
||||
gi = GeoIP_open(file_path_test, GEOIP_STANDARD);
|
||||
|
||||
if (verbose == 1)
|
||||
GeoIP_printf(f,"Performing santity checks ... ");
|
||||
|
||||
if (gi == NULL) {
|
||||
GeoIP_printf(f,"Error opening sanity check database\n");
|
||||
return GEOIP_SANITY_OPEN_ERR;
|
||||
}
|
||||
|
||||
/* this checks to make sure the files is complete, since info is at the end */
|
||||
/* dependent on future databases having MaxMind in info */
|
||||
if (verbose == 1)
|
||||
GeoIP_printf(f,"database_info ");
|
||||
db_info = GeoIP_database_info(gi);
|
||||
if (db_info == NULL) {
|
||||
GeoIP_delete(gi);
|
||||
if (verbose == 1)
|
||||
GeoIP_printf(f,"FAIL\n");
|
||||
return GEOIP_SANITY_INFO_FAIL;
|
||||
}
|
||||
if (strstr(db_info, "MaxMind") == NULL) {
|
||||
free(db_info);
|
||||
GeoIP_delete(gi);
|
||||
if (verbose == 1)
|
||||
GeoIP_printf(f,"FAIL\n");
|
||||
return GEOIP_SANITY_INFO_FAIL;
|
||||
}
|
||||
free(db_info);
|
||||
if (verbose == 1)
|
||||
GeoIP_printf(f,"PASS ");
|
||||
|
||||
/* this performs an IP lookup test of a US IP address */
|
||||
if (verbose == 1)
|
||||
GeoIP_printf(f,"lookup ");
|
||||
if (strcmp(GeoIP_country_code_by_addr(gi,"24.24.24.24"), "US") != 0) {
|
||||
GeoIP_delete(gi);
|
||||
if (verbose == 1)
|
||||
GeoIP_printf(f,"FAIL\n");
|
||||
return GEOIP_SANITY_LOOKUP_FAIL;
|
||||
}
|
||||
GeoIP_delete(gi);
|
||||
if (verbose == 1)
|
||||
GeoIP_printf(f,"PASS\n");
|
||||
|
||||
/* install GeoIP.dat.test -> GeoIP.dat */
|
||||
err = rename(file_path_test, GeoIPDBFileName[GEOIP_COUNTRY_EDITION]);
|
||||
if (err != 0) {
|
||||
GeoIP_printf(f,"GeoIP Install error while renaming file\n");
|
||||
return GEOIP_RENAME_ERR;
|
||||
}
|
||||
|
||||
if (verbose == 1)
|
||||
GeoIP_printf(f,"Done\n");
|
||||
|
||||
return 0;
|
||||
}
|
53
dlls/geoip/geolib/libGeoIP/GeoIPUpdate.h
Executable file
53
dlls/geoip/geolib/libGeoIP/GeoIPUpdate.h
Executable file
@ -0,0 +1,53 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/* GeoIP.h
|
||||
*
|
||||
* Copyright (C) 2002 MaxMind.com
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef GEOIPUPDATE_H
|
||||
#define GEOIPUPDATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
GEOIP_NO_NEW_UPDATES = 1, /* Database up-to-date, no action taken */
|
||||
GEOIP_SUCCESS = 0, /* Success */
|
||||
GEOIP_LICENSE_KEY_INVALID_ERR = -1, /* License Key Invalid */
|
||||
GEOIP_DNS_ERR = -11, /* Unable to resolve hostname */
|
||||
GEOIP_NON_IPV4_ERR = -12, /* Non - IPv4 address */
|
||||
GEOIP_SOCKET_OPEN_ERR = -13, /* Error opening socket */
|
||||
GEOIP_CONNECTION_ERR = -14, /* Unable to connect */
|
||||
GEOIP_GZIP_IO_ERR = -15, /* Unable to write GeoIP.dat.gz file */
|
||||
GEOIP_TEST_IO_ERR = -16, /* Unable to write GeoIP.dat.test file */
|
||||
GEOIP_GZIP_READ_ERR = -17, /* Unable to read gzip data */
|
||||
GEOIP_OUT_OF_MEMORY_ERR = -18, /* Out of memory error */
|
||||
GEOIP_SOCKET_READ_ERR = -19, /* Error reading from socket, see errno */
|
||||
GEOIP_SANITY_OPEN_ERR = -20, /* Sanity check GeoIP_open error */
|
||||
GEOIP_SANITY_INFO_FAIL = -21, /* Sanity check database_info string failed */
|
||||
GEOIP_SANITY_LOOKUP_FAIL = -22, /* Sanity check ip address lookup failed */
|
||||
GEOIP_RENAME_ERR = -23, /* Rename error while installing db, check errno */
|
||||
} GeoIPUpdateCode;
|
||||
|
||||
short int GeoIP_update_database (char * license_key, int verbose, void (*f)( char *));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GEOIPUPDATE_H */
|
157
dlls/geoip/geolib/libGeoIP/Geolib.dev
Executable file
157
dlls/geoip/geolib/libGeoIP/Geolib.dev
Executable file
@ -0,0 +1,157 @@
|
||||
[Project]
|
||||
FileName=Geolib.dev
|
||||
Name=Geolib
|
||||
UnitCount=11
|
||||
Type=2
|
||||
Ver=1
|
||||
ObjFiles=
|
||||
Includes="C:\Documents and Settings\dvander.ACADEMIC\Desktop\amxx\dlls\geoip\geolib\libGeoIP";"C:\Documents and Settings\dvander.ACADEMIC\Desktop\amxx\dlls\geoip\geolib\zlib"
|
||||
Libs=
|
||||
PrivateResource=
|
||||
ResourceIncludes=
|
||||
MakeIncludes=
|
||||
Compiler=-DBUILDING_DLL=1_@@_
|
||||
CppCompiler=
|
||||
Linker=--no-export-all-symbols --add-stdcall-alias_@@_../../../../../../../../Dev-Cpp/lib/libws2_32.a_@@_../../../../mysql/extra/lib_win32/zlib.lib_@@_../../../../../../../../libmyntdll.a_@@_
|
||||
IsCpp=0
|
||||
Icon=
|
||||
ExeOutput=
|
||||
ObjectOutput=
|
||||
OverrideOutput=0
|
||||
OverrideOutputName=Geolib.dll
|
||||
HostApplication=
|
||||
Folders=
|
||||
CommandLine=
|
||||
IncludeVersionInfo=0
|
||||
SupportXPThemes=0
|
||||
CompilerSet=0
|
||||
CompilerSettings=000000000000000000
|
||||
|
||||
[Unit1]
|
||||
FileName=GeoIP.c
|
||||
CompileCpp=0
|
||||
Folder=Geolib
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit2]
|
||||
FileName=GeoIP.h
|
||||
CompileCpp=0
|
||||
Folder=Geolib
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit3]
|
||||
FileName=GeoIPBitReader.c
|
||||
CompileCpp=0
|
||||
Folder=Geolib
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit4]
|
||||
FileName=GeoIPBitReader.h
|
||||
CompileCpp=0
|
||||
Folder=Geolib
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit5]
|
||||
FileName=GeoIPCity.c
|
||||
CompileCpp=0
|
||||
Folder=Geolib
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit6]
|
||||
FileName=GeoIPCity.h
|
||||
CompileCpp=0
|
||||
Folder=Geolib
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit7]
|
||||
FileName=GeoIPUpdate.c
|
||||
CompileCpp=0
|
||||
Folder=Geolib
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit8]
|
||||
FileName=GeoIPUpdate.h
|
||||
CompileCpp=0
|
||||
Folder=Geolib
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit9]
|
||||
FileName=global.h
|
||||
CompileCpp=0
|
||||
Folder=Geolib
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit10]
|
||||
FileName=md5.c
|
||||
CompileCpp=0
|
||||
Folder=Geolib
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[Unit11]
|
||||
FileName=md5.h
|
||||
CompileCpp=0
|
||||
Folder=Geolib
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
[VersionInfo]
|
||||
Major=0
|
||||
Minor=1
|
||||
Release=1
|
||||
Build=1
|
||||
LanguageID=1033
|
||||
CharsetID=1252
|
||||
CompanyName=
|
||||
FileVersion=
|
||||
FileDescription=Developed using the Dev-C++ IDE
|
||||
InternalName=
|
||||
LegalCopyright=
|
||||
LegalTrademarks=
|
||||
OriginalFilename=
|
||||
ProductName=
|
||||
ProductVersion=
|
||||
AutoIncBuildNr=0
|
||||
|
BIN
dlls/geoip/geolib/libGeoIP/Geolib.dll
Executable file
BIN
dlls/geoip/geolib/libGeoIP/Geolib.dll
Executable file
Binary file not shown.
52
dlls/geoip/geolib/libGeoIP/Geolib.layout
Executable file
52
dlls/geoip/geolib/libGeoIP/Geolib.layout
Executable file
@ -0,0 +1,52 @@
|
||||
[Editors]
|
||||
Focused=0
|
||||
Order=0,4,9,6
|
||||
[Editor_0]
|
||||
Open=1
|
||||
Top=1
|
||||
CursorCol=15
|
||||
CursorRow=26
|
||||
TopLine=1
|
||||
LeftChar=1
|
||||
[Editor_1]
|
||||
Open=0
|
||||
Top=0
|
||||
[Editor_2]
|
||||
Open=0
|
||||
Top=0
|
||||
[Editor_3]
|
||||
Open=0
|
||||
Top=0
|
||||
[Editor_4]
|
||||
Open=1
|
||||
Top=0
|
||||
CursorCol=13
|
||||
CursorRow=25
|
||||
TopLine=4
|
||||
LeftChar=1
|
||||
[Editor_5]
|
||||
Open=0
|
||||
Top=0
|
||||
[Editor_6]
|
||||
Open=1
|
||||
Top=0
|
||||
CursorCol=15
|
||||
CursorRow=27
|
||||
TopLine=1
|
||||
LeftChar=1
|
||||
[Editor_7]
|
||||
Open=0
|
||||
Top=0
|
||||
[Editor_8]
|
||||
Open=0
|
||||
Top=0
|
||||
[Editor_9]
|
||||
Open=1
|
||||
Top=0
|
||||
CursorCol=1
|
||||
CursorRow=1
|
||||
TopLine=1
|
||||
LeftChar=1
|
||||
[Editor_10]
|
||||
Open=0
|
||||
Top=0
|
20
dlls/geoip/geolib/libGeoIP/Makefile.am
Executable file
20
dlls/geoip/geolib/libGeoIP/Makefile.am
Executable file
@ -0,0 +1,20 @@
|
||||
lib_LTLIBRARIES = libGeoIP.la libGeoIPUpdate.la libGeoIPBitReader.la
|
||||
|
||||
EXTRA_DIST = md5.h global.h
|
||||
|
||||
AM_CPPFLAGS = -DGEOIPDATADIR=\"$(pkgdatadir)\" -Wall
|
||||
|
||||
if WITH_CITY
|
||||
libGeoIP_la_SOURCES = GeoIP.c GeoIPCity.c
|
||||
include_HEADERS = GeoIP.h GeoIPCity.h GeoIPBitReader.h GeoIPUpdate.h
|
||||
else
|
||||
libGeoIP_la_SOURCES = GeoIP.c
|
||||
include_HEADERS = GeoIP.h GeoIPBitReader.h GeoIPUpdate.h
|
||||
endif
|
||||
|
||||
libGeoIPUpdate_la_SOURCES = GeoIPUpdate.c md5.c
|
||||
libGeoIPBitReader_la_SOURCES = GeoIPBitReader.c
|
||||
|
||||
libGeoIP_la_LDFLAGS = -version-info @GEOIP_VERSION_INFO@
|
||||
|
||||
libGeoIPUpdate_la_LIBADD = -lz
|
365
dlls/geoip/geolib/libGeoIP/Makefile.in
Executable file
365
dlls/geoip/geolib/libGeoIP/Makefile.in
Executable file
@ -0,0 +1,365 @@
|
||||
# Makefile.in generated automatically by automake 1.4-p6 from Makefile.am
|
||||
|
||||
# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
|
||||
SHELL = @SHELL@
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
||||
bindir = @bindir@
|
||||
sbindir = @sbindir@
|
||||
libexecdir = @libexecdir@
|
||||
datadir = @datadir@
|
||||
sysconfdir = @sysconfdir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
localstatedir = @localstatedir@
|
||||
libdir = @libdir@
|
||||
infodir = @infodir@
|
||||
mandir = @mandir@
|
||||
includedir = @includedir@
|
||||
oldincludedir = /usr/include
|
||||
|
||||
DESTDIR =
|
||||
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
|
||||
top_builddir = ..
|
||||
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
transform = @program_transform_name@
|
||||
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
host_alias = @host_alias@
|
||||
host_triplet = @host@
|
||||
AS = @AS@
|
||||
CC = @CC@
|
||||
DLLTOOL = @DLLTOOL@
|
||||
ECHO = @ECHO@
|
||||
EXEEXT = @EXEEXT@
|
||||
GEOIP_VERSION_INFO = @GEOIP_VERSION_INFO@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LN_S = @LN_S@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
OBJDUMP = @OBJDUMP@
|
||||
OBJEXT = @OBJEXT@
|
||||
PACKAGE = @PACKAGE@
|
||||
RANLIB = @RANLIB@
|
||||
STRIP = @STRIP@
|
||||
VERSION = @VERSION@
|
||||
WITH_CITY = @WITH_CITY@
|
||||
|
||||
lib_LTLIBRARIES = libGeoIP.la libGeoIPUpdate.la libGeoIPBitReader.la
|
||||
|
||||
EXTRA_DIST = md5.h global.h
|
||||
|
||||
AM_CPPFLAGS = -DGEOIPDATADIR=\"$(pkgdatadir)\" -Wall
|
||||
@WITH_CITY_TRUE@libGeoIP_la_SOURCES = GeoIP.c GeoIPCity.c
|
||||
@WITH_CITY_FALSE@libGeoIP_la_SOURCES = GeoIP.c
|
||||
@WITH_CITY_TRUE@include_HEADERS = GeoIP.h GeoIPCity.h GeoIPBitReader.h GeoIPUpdate.h
|
||||
@WITH_CITY_FALSE@include_HEADERS = GeoIP.h GeoIPBitReader.h GeoIPUpdate.h
|
||||
|
||||
libGeoIPUpdate_la_SOURCES = GeoIPUpdate.c md5.c
|
||||
libGeoIPBitReader_la_SOURCES = GeoIPBitReader.c
|
||||
|
||||
libGeoIP_la_LDFLAGS = -version-info @GEOIP_VERSION_INFO@
|
||||
|
||||
libGeoIPUpdate_la_LIBADD = -lz
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_CLEAN_FILES =
|
||||
LTLIBRARIES = $(lib_LTLIBRARIES)
|
||||
|
||||
|
||||
DEFS = @DEFS@ -I. -I$(srcdir)
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBS = @LIBS@
|
||||
libGeoIP_la_LIBADD =
|
||||
@WITH_CITY_FALSE@libGeoIP_la_OBJECTS = GeoIP.lo
|
||||
@WITH_CITY_TRUE@libGeoIP_la_OBJECTS = GeoIP.lo GeoIPCity.lo
|
||||
libGeoIPUpdate_la_LDFLAGS =
|
||||
libGeoIPUpdate_la_DEPENDENCIES =
|
||||
libGeoIPUpdate_la_OBJECTS = GeoIPUpdate.lo md5.lo
|
||||
libGeoIPBitReader_la_LDFLAGS =
|
||||
libGeoIPBitReader_la_LIBADD =
|
||||
libGeoIPBitReader_la_OBJECTS = GeoIPBitReader.lo
|
||||
CFLAGS = @CFLAGS@
|
||||
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
CCLD = $(CC)
|
||||
LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
|
||||
HEADERS = $(include_HEADERS)
|
||||
|
||||
DIST_COMMON = Makefile.am Makefile.in
|
||||
|
||||
|
||||
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
|
||||
|
||||
TAR = gtar
|
||||
GZIP_ENV = --best
|
||||
SOURCES = $(libGeoIP_la_SOURCES) $(libGeoIPUpdate_la_SOURCES) $(libGeoIPBitReader_la_SOURCES)
|
||||
OBJECTS = $(libGeoIP_la_OBJECTS) $(libGeoIPUpdate_la_OBJECTS) $(libGeoIPBitReader_la_OBJECTS)
|
||||
|
||||
all: all-redirect
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .S .c .lo .o .obj .s
|
||||
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
|
||||
cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps libGeoIP/Makefile
|
||||
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
cd $(top_builddir) \
|
||||
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
|
||||
|
||||
|
||||
mostlyclean-libLTLIBRARIES:
|
||||
|
||||
clean-libLTLIBRARIES:
|
||||
-test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
|
||||
|
||||
distclean-libLTLIBRARIES:
|
||||
|
||||
maintainer-clean-libLTLIBRARIES:
|
||||
|
||||
install-libLTLIBRARIES: $(lib_LTLIBRARIES)
|
||||
@$(NORMAL_INSTALL)
|
||||
$(mkinstalldirs) $(DESTDIR)$(libdir)
|
||||
@list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||
if test -f $$p; then \
|
||||
echo "$(LIBTOOL) --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p"; \
|
||||
$(LIBTOOL) --mode=install $(INSTALL) $$p $(DESTDIR)$(libdir)/$$p; \
|
||||
else :; fi; \
|
||||
done
|
||||
|
||||
uninstall-libLTLIBRARIES:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
list='$(lib_LTLIBRARIES)'; for p in $$list; do \
|
||||
$(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libdir)/$$p; \
|
||||
done
|
||||
|
||||
.c.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
# FIXME: We should only use cygpath when building on Windows,
|
||||
# and only if it is available.
|
||||
.c.obj:
|
||||
$(COMPILE) -c `cygpath -w $<`
|
||||
|
||||
.s.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
.S.o:
|
||||
$(COMPILE) -c $<
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.o core *.core
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
clean-compile:
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
maintainer-clean-compile:
|
||||
|
||||
.c.lo:
|
||||
$(LIBTOOL) --mode=compile $(COMPILE) -c $<
|
||||
|
||||
.s.lo:
|
||||
$(LIBTOOL) --mode=compile $(COMPILE) -c $<
|
||||
|
||||
.S.lo:
|
||||
$(LIBTOOL) --mode=compile $(COMPILE) -c $<
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
||||
clean-libtool:
|
||||
-rm -rf .libs _libs
|
||||
|
||||
distclean-libtool:
|
||||
|
||||
maintainer-clean-libtool:
|
||||
|
||||
libGeoIP.la: $(libGeoIP_la_OBJECTS) $(libGeoIP_la_DEPENDENCIES)
|
||||
$(LINK) -rpath $(libdir) $(libGeoIP_la_LDFLAGS) $(libGeoIP_la_OBJECTS) $(libGeoIP_la_LIBADD) $(LIBS)
|
||||
|
||||
libGeoIPUpdate.la: $(libGeoIPUpdate_la_OBJECTS) $(libGeoIPUpdate_la_DEPENDENCIES)
|
||||
$(LINK) -rpath $(libdir) $(libGeoIPUpdate_la_LDFLAGS) $(libGeoIPUpdate_la_OBJECTS) $(libGeoIPUpdate_la_LIBADD) $(LIBS)
|
||||
|
||||
libGeoIPBitReader.la: $(libGeoIPBitReader_la_OBJECTS) $(libGeoIPBitReader_la_DEPENDENCIES)
|
||||
$(LINK) -rpath $(libdir) $(libGeoIPBitReader_la_LDFLAGS) $(libGeoIPBitReader_la_OBJECTS) $(libGeoIPBitReader_la_LIBADD) $(LIBS)
|
||||
|
||||
install-includeHEADERS: $(include_HEADERS)
|
||||
@$(NORMAL_INSTALL)
|
||||
$(mkinstalldirs) $(DESTDIR)$(includedir)
|
||||
@list='$(include_HEADERS)'; for p in $$list; do \
|
||||
if test -f "$$p"; then d= ; else d="$(srcdir)/"; fi; \
|
||||
echo " $(INSTALL_DATA) $$d$$p $(DESTDIR)$(includedir)/$$p"; \
|
||||
$(INSTALL_DATA) $$d$$p $(DESTDIR)$(includedir)/$$p; \
|
||||
done
|
||||
|
||||
uninstall-includeHEADERS:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
list='$(include_HEADERS)'; for p in $$list; do \
|
||||
rm -f $(DESTDIR)$(includedir)/$$p; \
|
||||
done
|
||||
|
||||
tags: TAGS
|
||||
|
||||
ID: $(HEADERS) $(SOURCES) $(LISP)
|
||||
list='$(SOURCES) $(HEADERS)'; \
|
||||
unique=`for i in $$list; do echo $$i; done | \
|
||||
awk ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
here=`pwd` && cd $(srcdir) \
|
||||
&& mkid -f$$here/ID $$unique $(LISP)
|
||||
|
||||
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
|
||||
tags=; \
|
||||
here=`pwd`; \
|
||||
list='$(SOURCES) $(HEADERS)'; \
|
||||
unique=`for i in $$list; do echo $$i; done | \
|
||||
awk ' { files[$$0] = 1; } \
|
||||
END { for (i in files) print i; }'`; \
|
||||
test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
|
||||
|| (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
|
||||
|
||||
mostlyclean-tags:
|
||||
|
||||
clean-tags:
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID
|
||||
|
||||
maintainer-clean-tags:
|
||||
|
||||
distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
|
||||
|
||||
subdir = libGeoIP
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@for file in $(DISTFILES); do \
|
||||
d=$(srcdir); \
|
||||
if test -d $$d/$$file; then \
|
||||
cp -pr $$d/$$file $(distdir)/$$file; \
|
||||
else \
|
||||
test -f $(distdir)/$$file \
|
||||
|| ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|
||||
|| cp -p $$d/$$file $(distdir)/$$file || :; \
|
||||
fi; \
|
||||
done
|
||||
GeoIP.lo GeoIP.o : GeoIP.c GeoIP.h
|
||||
GeoIPBitReader.lo GeoIPBitReader.o : GeoIPBitReader.c GeoIPBitReader.h
|
||||
GeoIPCity.lo GeoIPCity.o : GeoIPCity.c GeoIP.h GeoIPCity.h
|
||||
GeoIPUpdate.lo GeoIPUpdate.o : GeoIPUpdate.c GeoIP.h GeoIPUpdate.h \
|
||||
global.h md5.h
|
||||
md5.lo md5.o : md5.c global.h md5.h
|
||||
|
||||
info-am:
|
||||
info: info-am
|
||||
dvi-am:
|
||||
dvi: dvi-am
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
installcheck-am:
|
||||
installcheck: installcheck-am
|
||||
install-exec-am: install-libLTLIBRARIES
|
||||
install-exec: install-exec-am
|
||||
|
||||
install-data-am: install-includeHEADERS
|
||||
install-data: install-data-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
install: install-am
|
||||
uninstall-am: uninstall-libLTLIBRARIES uninstall-includeHEADERS
|
||||
uninstall: uninstall-am
|
||||
all-am: Makefile $(LTLIBRARIES) $(HEADERS)
|
||||
all-redirect: all-am
|
||||
install-strip:
|
||||
$(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
|
||||
installdirs:
|
||||
$(mkinstalldirs) $(DESTDIR)$(libdir) $(DESTDIR)$(includedir)
|
||||
|
||||
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-rm -f Makefile $(CONFIG_CLEAN_FILES)
|
||||
-rm -f config.cache config.log stamp-h stamp-h[0-9]*
|
||||
|
||||
maintainer-clean-generic:
|
||||
mostlyclean-am: mostlyclean-libLTLIBRARIES mostlyclean-compile \
|
||||
mostlyclean-libtool mostlyclean-tags \
|
||||
mostlyclean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
clean-am: clean-libLTLIBRARIES clean-compile clean-libtool clean-tags \
|
||||
clean-generic mostlyclean-am
|
||||
|
||||
clean: clean-am
|
||||
|
||||
distclean-am: distclean-libLTLIBRARIES distclean-compile \
|
||||
distclean-libtool distclean-tags distclean-generic \
|
||||
clean-am
|
||||
-rm -f libtool
|
||||
|
||||
distclean: distclean-am
|
||||
|
||||
maintainer-clean-am: maintainer-clean-libLTLIBRARIES \
|
||||
maintainer-clean-compile maintainer-clean-libtool \
|
||||
maintainer-clean-tags maintainer-clean-generic \
|
||||
distclean-am
|
||||
@echo "This command is intended for maintainers to use;"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
|
||||
.PHONY: mostlyclean-libLTLIBRARIES distclean-libLTLIBRARIES \
|
||||
clean-libLTLIBRARIES maintainer-clean-libLTLIBRARIES \
|
||||
uninstall-libLTLIBRARIES install-libLTLIBRARIES mostlyclean-compile \
|
||||
distclean-compile clean-compile maintainer-clean-compile \
|
||||
mostlyclean-libtool distclean-libtool clean-libtool \
|
||||
maintainer-clean-libtool uninstall-includeHEADERS \
|
||||
install-includeHEADERS tags mostlyclean-tags distclean-tags clean-tags \
|
||||
maintainer-clean-tags distdir info-am info dvi-am dvi check check-am \
|
||||
installcheck-am installcheck install-exec-am install-exec \
|
||||
install-data-am install-data install-am install uninstall-am uninstall \
|
||||
all-redirect all-am all installdirs mostlyclean-generic \
|
||||
distclean-generic clean-generic maintainer-clean-generic clean \
|
||||
mostlyclean distclean maintainer-clean
|
||||
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
42
dlls/geoip/geolib/libGeoIP/Makefile.win
Executable file
42
dlls/geoip/geolib/libGeoIP/Makefile.win
Executable file
@ -0,0 +1,42 @@
|
||||
# Project: Geolib
|
||||
# Makefile created by Dev-C++ 4.9.8.0
|
||||
|
||||
CPP = g++.exe
|
||||
CC = gcc.exe
|
||||
WINDRES = windres.exe
|
||||
RES =
|
||||
OBJ = GeoIP.o GeoIPBitReader.o GeoIPCity.o GeoIPUpdate.o md5.o $(RES)
|
||||
LINKOBJ = GeoIP.o GeoIPBitReader.o GeoIPCity.o GeoIPUpdate.o md5.o $(RES)
|
||||
LIBS = -L"C:/Dev-Cpp/lib" --no-export-all-symbols --add-stdcall-alias ../../../../../../../../Dev-Cpp/lib/libws2_32.a ../../../../mysql/extra/lib_win32/zlib.lib ../../../../../../../../libmyntdll.a
|
||||
INCS = -I"C:/Dev-Cpp/include" -I"C:/Documents and Settings/dvander.ACADEMIC/Desktop/amxx/dlls/geoip/geolib/libGeoIP" -I"C:/Documents and Settings/dvander.ACADEMIC/Desktop/amxx/dlls/geoip/geolib/zlib"
|
||||
CXXINCS = -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include/c++/mingw32" -I"C:/Dev-Cpp/include/c++/backward" -I"C:/Dev-Cpp/include" -I"C:/Documents and Settings/dvander.ACADEMIC/Desktop/amxx/dlls/geoip/geolib/libGeoIP" -I"C:/Documents and Settings/dvander.ACADEMIC/Desktop/amxx/dlls/geoip/geolib/zlib"
|
||||
BIN = Geolib.a
|
||||
CXXFLAGS = $(CXXINCS)
|
||||
CFLAGS = $(INCS)-DBUILDING_DLL=1
|
||||
|
||||
.PHONY: all all-before all-after clean clean-custom
|
||||
|
||||
all: all-before Geolib.a all-after
|
||||
|
||||
|
||||
clean: clean-custom
|
||||
rm -f $(OBJ) $(BIN)
|
||||
|
||||
$(BIN): $(LINKOBJ)
|
||||
ar r $(BIN) $(LINKOBJ)
|
||||
ranlib $(BIN)
|
||||
|
||||
GeoIP.o: GeoIP.c
|
||||
$(CC) -c GeoIP.c -o GeoIP.o $(CFLAGS)
|
||||
|
||||
GeoIPBitReader.o: GeoIPBitReader.c
|
||||
$(CC) -c GeoIPBitReader.c -o GeoIPBitReader.o $(CFLAGS)
|
||||
|
||||
GeoIPCity.o: GeoIPCity.c
|
||||
$(CC) -c GeoIPCity.c -o GeoIPCity.o $(CFLAGS)
|
||||
|
||||
GeoIPUpdate.o: GeoIPUpdate.c
|
||||
$(CC) -c GeoIPUpdate.c -o GeoIPUpdate.o $(CFLAGS)
|
||||
|
||||
md5.o: md5.c
|
||||
$(CC) -c md5.c -o md5.o $(CFLAGS)
|
32
dlls/geoip/geolib/libGeoIP/global.h
Executable file
32
dlls/geoip/geolib/libGeoIP/global.h
Executable file
@ -0,0 +1,32 @@
|
||||
/* GLOBAL.H - RSAREF types and constants
|
||||
*/
|
||||
|
||||
/* PROTOTYPES should be set to one if and only if the compiler supports
|
||||
function argument prototyping.
|
||||
The following makes PROTOTYPES default to 0 if it has not already
|
||||
|
||||
been defined with C compiler flags.
|
||||
*/
|
||||
#ifndef PROTOTYPES
|
||||
#define PROTOTYPES 0
|
||||
#endif
|
||||
|
||||
/* POINTER defines a generic pointer type */
|
||||
typedef unsigned char *POINTER;
|
||||
|
||||
/* UINT2 defines a two byte word */
|
||||
typedef unsigned short int UINT2;
|
||||
|
||||
/* UINT4 defines a four byte word */
|
||||
typedef unsigned long int UINT4;
|
||||
|
||||
/* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
|
||||
If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
|
||||
returns an empty list.
|
||||
*/
|
||||
#if PROTOTYPES
|
||||
#define PROTO_LIST(list) list
|
||||
#else
|
||||
#define PROTO_LIST(list) ()
|
||||
#endif
|
||||
|
2
dlls/geoip/geolib/libGeoIP/libGeolib.def
Executable file
2
dlls/geoip/geolib/libGeoIP/libGeolib.def
Executable file
@ -0,0 +1,2 @@
|
||||
; dlltool --base-file C:\DOCUME~1\DVANDE~1.ACA\LOCALS~1\Temp/cca04056.base --output-exp Geolib.exp --dllname Geolib.dll --output-def libGeolib.def --no-export-all-symbols --add-stdcall-alias --exclude-symbol=DllMainCRTStartup@12 --def C:\DOCUME~1\DVANDE~1.ACA\LOCALS~1\Temp/cca04056.def --output-lib libGeolib.a
|
||||
EXPORTS
|
339
dlls/geoip/geolib/libGeoIP/md5.c
Executable file
339
dlls/geoip/geolib/libGeoIP/md5.c
Executable file
@ -0,0 +1,339 @@
|
||||
/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
|
||||
*/
|
||||
|
||||
/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
|
||||
rights reserved.
|
||||
|
||||
License to copy and use this software is granted provided that it
|
||||
is identified as the "RSA Data Security, Inc. MD5 Message-Digest
|
||||
Algorithm" in all material mentioning or referencing this software
|
||||
or this function.
|
||||
|
||||
License is also granted to make and use derivative works provided
|
||||
that such works are identified as "derived from the RSA Data
|
||||
Security, Inc. MD5 Message-Digest Algorithm" in all material
|
||||
mentioning or referencing the derived work.
|
||||
|
||||
RSA Data Security, Inc. makes no representations concerning either
|
||||
the merchantability of this software or the suitability of this
|
||||
software for any particular purpose. It is provided "as is"
|
||||
without express or implied warranty of any kind.
|
||||
|
||||
These notices must be retained in any copies of any part of this
|
||||
documentation and/or software.
|
||||
*/
|
||||
|
||||
#include "global.h"
|
||||
#include "md5.h"
|
||||
|
||||
/* Constants for MD5Transform routine.
|
||||
*/
|
||||
|
||||
#define S11 7
|
||||
#define S12 12
|
||||
#define S13 17
|
||||
#define S14 22
|
||||
#define S21 5
|
||||
#define S22 9
|
||||
#define S23 14
|
||||
#define S24 20
|
||||
#define S31 4
|
||||
#define S32 11
|
||||
#define S33 16
|
||||
#define S34 23
|
||||
#define S41 6
|
||||
#define S42 10
|
||||
#define S43 15
|
||||
#define S44 21
|
||||
|
||||
static void MD5Transform PROTO_LIST ((UINT4 [4], unsigned char [64]));
|
||||
static void Encode PROTO_LIST
|
||||
((unsigned char *, UINT4 *, unsigned int));
|
||||
static void Decode PROTO_LIST
|
||||
((UINT4 *, unsigned char *, unsigned int));
|
||||
static void MD5_memcpy PROTO_LIST ((POINTER, POINTER, unsigned int));
|
||||
static void MD5_memset PROTO_LIST ((POINTER, int, unsigned int));
|
||||
|
||||
static unsigned char PADDING[64] = {
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/* F, G, H and I are basic MD5 functions.
|
||||
*/
|
||||
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
||||
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define I(x, y, z) ((y) ^ ((x) | (~z)))
|
||||
|
||||
/* ROTATE_LEFT rotates x left n bits.
|
||||
*/
|
||||
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
|
||||
|
||||
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
|
||||
Rotation is separate from addition to prevent recomputation.
|
||||
*/
|
||||
#define FF(a, b, c, d, x, s, ac) { \
|
||||
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define GG(a, b, c, d, x, s, ac) { \
|
||||
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define HH(a, b, c, d, x, s, ac) { \
|
||||
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define II(a, b, c, d, x, s, ac) { \
|
||||
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
/* MD5 initialization. Begins an MD5 operation, writing a new context.
|
||||
*/
|
||||
void MD5Init (context)
|
||||
MD5_CTX *context; /* context */
|
||||
{
|
||||
context->count[0] = context->count[1] = 0;
|
||||
/* Load magic initialization constants.
|
||||
*/
|
||||
context->state[0] = 0x67452301;
|
||||
context->state[1] = 0xefcdab89;
|
||||
context->state[2] = 0x98badcfe;
|
||||
context->state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
/* MD5 block update operation. Continues an MD5 message-digest
|
||||
operation, processing another message block, and updating the
|
||||
context.
|
||||
*/
|
||||
void MD5Update (context, input, inputLen)
|
||||
MD5_CTX *context; /* context */
|
||||
unsigned char *input; /* input block */
|
||||
unsigned int inputLen; /* length of input block */
|
||||
{
|
||||
unsigned int i, index, partLen;
|
||||
|
||||
/* Compute number of bytes mod 64 */
|
||||
index = (unsigned int)((context->count[0] >> 3) & 0x3F);
|
||||
|
||||
/* Update number of bits */
|
||||
if ((context->count[0] += ((UINT4)inputLen << 3))
|
||||
|
||||
< ((UINT4)inputLen << 3))
|
||||
context->count[1]++;
|
||||
context->count[1] += ((UINT4)inputLen >> 29);
|
||||
|
||||
partLen = 64 - index;
|
||||
|
||||
/* Transform as many times as possible.
|
||||
*/
|
||||
if (inputLen >= partLen) {
|
||||
MD5_memcpy
|
||||
((POINTER)&context->buffer[index], (POINTER)input, partLen);
|
||||
MD5Transform (context->state, context->buffer);
|
||||
|
||||
for (i = partLen; i + 63 < inputLen; i += 64)
|
||||
MD5Transform (context->state, &input[i]);
|
||||
|
||||
index = 0;
|
||||
}
|
||||
else
|
||||
i = 0;
|
||||
|
||||
/* Buffer remaining input */
|
||||
MD5_memcpy
|
||||
((POINTER)&context->buffer[index], (POINTER)&input[i],
|
||||
inputLen-i);
|
||||
}
|
||||
|
||||
/* MD5 finalization. Ends an MD5 message-digest operation, writing the
|
||||
the message digest and zeroizing the context.
|
||||
*/
|
||||
void MD5Final (digest, context)
|
||||
unsigned char digest[16]; /* message digest */
|
||||
MD5_CTX *context; /* context */
|
||||
{
|
||||
unsigned char bits[8];
|
||||
unsigned int index, padLen;
|
||||
|
||||
/* Save number of bits */
|
||||
Encode (bits, context->count, 8);
|
||||
|
||||
/* Pad out to 56 mod 64.
|
||||
*/
|
||||
index = (unsigned int)((context->count[0] >> 3) & 0x3f);
|
||||
padLen = (index < 56) ? (56 - index) : (120 - index);
|
||||
MD5Update (context, PADDING, padLen);
|
||||
|
||||
/* Append length (before padding) */
|
||||
MD5Update (context, bits, 8);
|
||||
|
||||
/* Store state in digest */
|
||||
Encode (digest, context->state, 16);
|
||||
|
||||
/* Zeroize sensitive information.
|
||||
*/
|
||||
MD5_memset ((POINTER)context, 0, sizeof (*context));
|
||||
}
|
||||
|
||||
/* MD5 basic transformation. Transforms state based on block.
|
||||
*/
|
||||
static void MD5Transform (state, block)
|
||||
UINT4 state[4];
|
||||
unsigned char block[64];
|
||||
{
|
||||
UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
|
||||
|
||||
Decode (x, block, 64);
|
||||
|
||||
/* Round 1 */
|
||||
FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
|
||||
FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
|
||||
FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
|
||||
FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
|
||||
FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
|
||||
FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
|
||||
FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
|
||||
FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
|
||||
FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
|
||||
FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
|
||||
FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
|
||||
FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
|
||||
FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
|
||||
FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
|
||||
FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
|
||||
FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
|
||||
|
||||
/* Round 2 */
|
||||
GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
|
||||
GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
|
||||
GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
|
||||
GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
|
||||
GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
|
||||
GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
|
||||
GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
|
||||
GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
|
||||
GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
|
||||
GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
|
||||
GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
|
||||
|
||||
GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
|
||||
GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
|
||||
GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
|
||||
GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
|
||||
GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
|
||||
|
||||
/* Round 3 */
|
||||
HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
|
||||
HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
|
||||
HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
|
||||
HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
|
||||
HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
|
||||
HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
|
||||
HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
|
||||
HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
|
||||
HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
|
||||
HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
|
||||
HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
|
||||
HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
|
||||
HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
|
||||
HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
|
||||
HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
|
||||
HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
|
||||
|
||||
/* Round 4 */
|
||||
II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
|
||||
II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
|
||||
II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
|
||||
II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
|
||||
II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
|
||||
II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
|
||||
II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
|
||||
II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
|
||||
II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
|
||||
II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
|
||||
II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
|
||||
II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
|
||||
II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
|
||||
II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
|
||||
II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
|
||||
II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
|
||||
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
|
||||
/* Zeroize sensitive information.
|
||||
|
||||
*/
|
||||
MD5_memset ((POINTER)x, 0, sizeof (x));
|
||||
}
|
||||
|
||||
/* Encodes input (UINT4) into output (unsigned char). Assumes len is
|
||||
a multiple of 4.
|
||||
*/
|
||||
static void Encode (output, input, len)
|
||||
unsigned char *output;
|
||||
UINT4 *input;
|
||||
unsigned int len;
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
for (i = 0, j = 0; j < len; i++, j += 4) {
|
||||
output[j] = (unsigned char)(input[i] & 0xff);
|
||||
output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
|
||||
output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
|
||||
output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
/* Decodes input (unsigned char) into output (UINT4). Assumes len is
|
||||
a multiple of 4.
|
||||
*/
|
||||
static void Decode (output, input, len)
|
||||
UINT4 *output;
|
||||
unsigned char *input;
|
||||
unsigned int len;
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
||||
for (i = 0, j = 0; j < len; i++, j += 4)
|
||||
output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
|
||||
(((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
|
||||
}
|
||||
|
||||
/* Note: Replace "for loop" with standard memcpy if possible.
|
||||
*/
|
||||
|
||||
static void MD5_memcpy (output, input, len)
|
||||
POINTER output;
|
||||
POINTER input;
|
||||
unsigned int len;
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
|
||||
output[i] = input[i];
|
||||
}
|
||||
|
||||
/* Note: Replace "for loop" with standard memset if possible.
|
||||
*/
|
||||
static void MD5_memset (output, value, len)
|
||||
POINTER output;
|
||||
int value;
|
||||
unsigned int len;
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
((char *)output)[i] = (char)value;
|
||||
}
|
36
dlls/geoip/geolib/libGeoIP/md5.h
Executable file
36
dlls/geoip/geolib/libGeoIP/md5.h
Executable file
@ -0,0 +1,36 @@
|
||||
/* MD5.H - header file for MD5C.C
|
||||
*/
|
||||
|
||||
/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
|
||||
rights reserved.
|
||||
|
||||
License to copy and use this software is granted provided that it
|
||||
is identified as the "RSA Data Security, Inc. MD5 Message-Digest
|
||||
Algorithm" in all material mentioning or referencing this software
|
||||
or this function.
|
||||
|
||||
License is also granted to make and use derivative works provided
|
||||
that such works are identified as "derived from the RSA Data
|
||||
Security, Inc. MD5 Message-Digest Algorithm" in all material
|
||||
mentioning or referencing the derived work.
|
||||
|
||||
RSA Data Security, Inc. makes no representations concerning either
|
||||
the merchantability of this software or the suitability of this
|
||||
software for any particular purpose. It is provided "as is"
|
||||
without express or implied warranty of any kind.
|
||||
|
||||
These notices must be retained in any copies of any part of this
|
||||
documentation and/or software.
|
||||
*/
|
||||
|
||||
/* MD5 context. */
|
||||
typedef struct {
|
||||
UINT4 state[4]; /* state (ABCD) */
|
||||
UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
|
||||
unsigned char buffer[64]; /* input buffer */
|
||||
} MD5_CTX;
|
||||
|
||||
void MD5Init PROTO_LIST ((MD5_CTX *));
|
||||
void MD5Update PROTO_LIST
|
||||
((MD5_CTX *, unsigned char *, unsigned int));
|
||||
void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *));
|
Reference in New Issue
Block a user