Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
Remove the unused CITYCONFIDENCE* database types
Browse files Browse the repository at this point in the history
  • Loading branch information
borisz committed Feb 19, 2013
1 parent 9e9f099 commit 999d57a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 167 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
* Update time zones ( Boris Zentner )
* Update Region codes ( Boris Zentner )
* Remove the unused CITYCONFIDENCE* database types ( Boris Zentner )
* bootstrap rebuilds ltmain.sh ( Boris Zentner )
* Update README.OSX for Lion ( Boris Zentner )
* Change Macedonia to Macedonia, The Former Yugoslav Republic of
Expand Down
44 changes: 0 additions & 44 deletions apps/geoiplookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,50 +325,6 @@ geoiplookup(GeoIP * gi, char *hostname, int i)
GeoIPRecord_delete(gir);
}
}
else if (GEOIP_CITYCONFIDENCE_EDITION == i) {
gir = GeoIP_record_by_ipnum(gi, ipnum);
if (NULL == gir) {
printf("%s: IP Address not found\n", GeoIPDBDescription[i]);
}
else {
char country_str[5], region_str[5], city_str[5], postal_str[5];
_mk_conf_str(gir->country_conf, country_str, 5);
_mk_conf_str(gir->region_conf, region_str, 5);
_mk_conf_str(gir->city_conf, city_str, 5);
_mk_conf_str(gir->postal_conf, postal_str, 5);

printf("%s: %s, %s, %s, %s, %f, %f, %d, %d, %s, %s, %s, %s\n", GeoIPDBDescription[i], gir->country_code, _mk_NA(gir->region), _mk_NA(gir->city), _mk_NA(gir->postal_code),
gir->latitude, gir->longitude, gir->metro_code, gir->area_code,
country_str, region_str, city_str, postal_str
);
_say_range_by_ip(gi, ipnum);
GeoIPRecord_delete(gir);
}
}
else if (GEOIP_CITYCONFIDENCEDIST_EDITION == i) {
gir = GeoIP_record_by_ipnum(gi, ipnum);
if (NULL == gir) {
printf("%s: IP Address not found\n", GeoIPDBDescription[i]);
}
else {
char country_str[5], region_str[5], city_str[5], postal_str[5], accuracy_radius_str[5];
_mk_conf_str(gir->country_conf, country_str, 5);
_mk_conf_str(gir->region_conf, region_str, 5);
_mk_conf_str(gir->city_conf, city_str, 5);
_mk_conf_str(gir->postal_conf, postal_str, 5);
if (gir->accuracy_radius != 1023){
sprintf(accuracy_radius_str, "%d", gir->accuracy_radius );
} else {
strcpy(accuracy_radius_str,"N/A");}

printf("%s: %s, %s, %s, %s, %f, %f, %d, %d, %s, %s, %s, %s, %s\n", GeoIPDBDescription[i], gir->country_code, _mk_NA(gir->region), _mk_NA(gir->city), _mk_NA(gir->postal_code),
gir->latitude, gir->longitude, gir->metro_code, gir->area_code,
country_str, region_str, city_str, postal_str, accuracy_radius_str
);
_say_range_by_ip(gi, ipnum);
GeoIPRecord_delete(gir);
}
}
else if (GEOIP_ORG_EDITION == i || GEOIP_ISP_EDITION == i) {
org = GeoIP_org_by_ipnum(gi, ipnum);
if (org == NULL) {
Expand Down
25 changes: 4 additions & 21 deletions libGeoIP/GeoIP.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ const char * GeoIPDBDescription[NUM_DB_TYPES] = {
"GeoIP Country V6 Edition",
"GeoIP LocationID ASCII Edition",
"GeoIP Accuracy Radius Edition",
"GeoIP City with Confidence Edition",
"GeoIP City with Confidence and Accuracy Edition",
NULL,
NULL,
"GeoIP Large Country Edition",
"GeoIP Large Country V6 Edition",
NULL,
Expand Down Expand Up @@ -399,8 +399,6 @@ void _GeoIP_setup_dbfilename() {
GeoIPDBFileName[GEOIP_COUNTRY_EDITION_V6] = _GeoIP_full_path_to("GeoIPv6.dat");
GeoIPDBFileName[GEOIP_LOCATIONA_EDITION] = _GeoIP_full_path_to("GeoIPLocA.dat");
GeoIPDBFileName[GEOIP_ACCURACYRADIUS_EDITION] = _GeoIP_full_path_to("GeoIPDistance.dat");
GeoIPDBFileName[GEOIP_CITYCONFIDENCE_EDITION] = _GeoIP_full_path_to("GeoIPCityConfidence.dat");
GeoIPDBFileName[GEOIP_CITYCONFIDENCEDIST_EDITION] = _GeoIP_full_path_to("GeoIPCityConfidenceDist.dat");
GeoIPDBFileName[GEOIP_LARGE_COUNTRY_EDITION] = _GeoIP_full_path_to("GeoIP.dat");
GeoIPDBFileName[GEOIP_LARGE_COUNTRY_EDITION_V6] = _GeoIP_full_path_to("GeoIPv6.dat");
GeoIPDBFileName[GEOIP_ASNUM_EDITION_V6] = _GeoIP_full_path_to("GeoIPASNumv6.dat");
Expand Down Expand Up @@ -535,8 +533,6 @@ void _setup_segments(GeoIP * gi) {
gi->databaseType == GEOIP_LOCATIONA_EDITION ||
gi->databaseType == GEOIP_ACCURACYRADIUS_EDITION ||
gi->databaseType == GEOIP_ACCURACYRADIUS_EDITION_V6 ||
gi->databaseType == GEOIP_CITYCONFIDENCE_EDITION ||
gi->databaseType == GEOIP_CITYCONFIDENCEDIST_EDITION ||
gi->databaseType == GEOIP_CITY_EDITION_REV0_V6 ||
gi->databaseType == GEOIP_CITY_EDITION_REV1_V6 ||
gi->databaseType == GEOIP_CITYCONF_EDITION ||
Expand All @@ -548,7 +544,7 @@ void _setup_segments(GeoIP * gi) {
gi->databaseSegments = malloc(sizeof(int));
gi->databaseSegments[0] = 0;

segment_record_length = gi->databaseType == GEOIP_CITYCONFIDENCEDIST_EDITION ? LARGE_SEGMENT_RECORD_LENGTH : SEGMENT_RECORD_LENGTH;
segment_record_length = SEGMENT_RECORD_LENGTH;

silence = read(fno, buf, segment_record_length );
for (j = 0; j < segment_record_length; j++) {
Expand All @@ -561,21 +557,8 @@ void _setup_segments(GeoIP * gi) {
gi->databaseType == GEOIP_DOMAIN_EDITION ||
gi->databaseType == GEOIP_DOMAIN_EDITION_V6 ||
gi->databaseType == GEOIP_ISP_EDITION ||
gi->databaseType == GEOIP_ISP_EDITION_V6 ||
gi->databaseType == GEOIP_CITYCONFIDENCEDIST_EDITION
)
gi->databaseType == GEOIP_ISP_EDITION_V6 )
gi->record_length = ORG_RECORD_LENGTH;

if ( gi->databaseType == GEOIP_CITYCONFIDENCE_EDITION
|| gi->databaseType == GEOIP_CITYCONFIDENCEDIST_EDITION
) {
silence = pread(fileno(gi->GeoIPDatabase), buf, gi->record_length, gi->databaseSegments[0] * 2 * gi->record_length);
gi->dyn_seg_size = 0;
for (j = 0; j < gi->record_length; j++) {
gi->dyn_seg_size += (buf[j] << (j * 8));
}
}

}
break;
} else {
Expand Down
4 changes: 2 additions & 2 deletions libGeoIP/GeoIP.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ typedef enum {
GEOIP_COUNTRY_EDITION_V6 = 12,
GEOIP_LOCATIONA_EDITION = 13,
GEOIP_ACCURACYRADIUS_EDITION = 14,
GEOIP_CITYCONFIDENCE_EDITION = 15,
GEOIP_CITYCONFIDENCEDIST_EDITION = 16,
GEOIP_CITYCONFIDENCE_EDITION = 15, /* unsupported */
GEOIP_CITYCONFIDENCEDIST_EDITION = 16, /* unsupported */
GEOIP_LARGE_COUNTRY_EDITION = 17,
GEOIP_LARGE_COUNTRY_EDITION_V6 = 18,
GEOIP_CITYCONFIDENCEDIST_ISP_ORG_EDITION = 19, /* unsued, but gaps are not allowed */
Expand Down
98 changes: 2 additions & 96 deletions libGeoIP/GeoIPCity.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
static
const int FULL_RECORD_LENGTH = 50;

static const int CITYCONFIDENCE_FIXED_RECORD = 4;
static const int CITYCONFIDENCEDIST_FIXED_RECORD = 6;


static
GeoIPRecord *
Expand All @@ -62,93 +59,6 @@ _extract_record(GeoIP * gi, unsigned int seek_record, int *next_record_ptr)
memset(record, 0, sizeof(GeoIPRecord));
record->charset = gi->charset;

if (gi->databaseType == GEOIP_CITYCONFIDENCE_EDITION
|| gi->databaseType == GEOIP_CITYCONFIDENCEDIST_EDITION) {

int fixed_rec_size = gi->record_length +
((gi->databaseType == GEOIP_CITYCONFIDENCE_EDITION)
? CITYCONFIDENCE_FIXED_RECORD
: CITYCONFIDENCEDIST_FIXED_RECORD);

//allocate max rec size, even for CITYCONFIDENCE_FIXED_RECORD
//+4 is the max_record_length
unsigned char tmp_fixed_record[CITYCONFIDENCEDIST_FIXED_RECORD + 4];
int dseg = gi->databaseSegments[0] * gi->record_length * 2 + gi->record_length;
// int aligned_dseg = dseg ;

int offset = seek_record - gi->databaseSegments[0] - 1; /* -1 b/c zero is not
* found. but the array
* start with 0 */
record_pointer = offset * fixed_rec_size + dseg + gi->dyn_seg_size;
if (gi->cache == NULL) {

/* read from disk */
bytes_read = pread(fileno(gi->GeoIPDatabase), tmp_fixed_record, fixed_rec_size, record_pointer);

if (bytes_read != fixed_rec_size)
return NULL;

record->country_conf = tmp_fixed_record[0];
record->region_conf = tmp_fixed_record[1];
record->city_conf = tmp_fixed_record[2];
record->postal_conf = tmp_fixed_record[3];

record->accuracy_radius =
gi->databaseType == GEOIP_CITYCONFIDENCEDIST_EDITION
? ((tmp_fixed_record[4] + (tmp_fixed_record[5] << 8)) & 0x3ff) : 0x3ff;

int t = fixed_rec_size - gi->record_length;

record_pointer = dseg + tmp_fixed_record[t] +
(tmp_fixed_record[t + 1] << 8) + (tmp_fixed_record[t + 2] << 16) ;

if (gi->record_length == 4)
record_pointer += (tmp_fixed_record[t + 3] << 24);

begin_record_buf = record_buf = malloc(sizeof(char) * FULL_RECORD_LENGTH);

bytes_read = pread(fileno(gi->GeoIPDatabase), record_buf, FULL_RECORD_LENGTH, record_pointer);

if (bytes_read == 0) {
/* eof or other error */
free(begin_record_buf);
free(record);
return NULL;
}

}
else {
record_buf = gi->cache + (long) record_pointer;

record->country_conf = record_buf[0];
record->region_conf = record_buf[1];
record->city_conf = record_buf[2];
record->postal_conf = record_buf[3];

record->accuracy_radius =
gi->databaseType == GEOIP_CITYCONFIDENCEDIST_EDITION
? ((record_buf[4] + (record_buf[5] << 8)) & 0x3ff) : 0x3ff;

int t = fixed_rec_size - gi->record_length;

record_pointer = dseg + record_buf[t] +
(record_buf[t + 1] << 8) + (record_buf[t + 2] << 16) ;

if (gi->record_length == 4)
record_pointer += (record_buf[t + 3] << 24);

record_buf = gi->cache + (long) record_pointer;
}

} /* other city records */
else {

record->country_conf = GEOIP_UNKNOWN_CONF;
record->region_conf = GEOIP_UNKNOWN_CONF;
record->city_conf = GEOIP_UNKNOWN_CONF;
record->postal_conf = GEOIP_UNKNOWN_CONF;
record->accuracy_radius = GEOIP_UNKNOWN_ACCURACY_RADIUS;

record_pointer = seek_record + (2 * gi->record_length - 1) * gi->databaseSegments[0];

if (gi->cache == NULL) {
Expand All @@ -164,7 +74,6 @@ _extract_record(GeoIP * gi, unsigned int seek_record, int *next_record_ptr)
else {
record_buf = gi->cache + (long) record_pointer;
}
}

/* get country */
record->continent_code = (char *) GeoIP_country_continent[record_buf[0]];
Expand Down Expand Up @@ -222,8 +131,7 @@ _extract_record(GeoIP * gi, unsigned int seek_record, int *next_record_ptr)
* get area code and metro code for post April 2002 databases and for US
* locations
*/
if (GEOIP_CITY_EDITION_REV1 == gi->databaseType
|| GEOIP_CITYCONFIDENCE_EDITION == gi->databaseType) {
if (GEOIP_CITY_EDITION_REV1 == gi->databaseType) {
if (!strcmp(record->country_code, "US")) {
record_buf += 3;
for (j = 0; j < 3; ++j)
Expand All @@ -249,9 +157,7 @@ _get_record(GeoIP * gi, unsigned long ipnum)
{
unsigned int seek_record;
if (gi->databaseType != GEOIP_CITY_EDITION_REV0
&& gi->databaseType != GEOIP_CITY_EDITION_REV1
&& gi->databaseType != GEOIP_CITYCONFIDENCE_EDITION
&& gi->databaseType != GEOIP_CITYCONFIDENCEDIST_EDITION) {
&& 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;
}
Expand Down
4 changes: 0 additions & 4 deletions libGeoIP/GeoIPCity.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ extern "C" {
#endif

#define GEOIP_UNKNOWN_CONF ( 0x7f )
#define GEOIP_UNKNOWN_ACCURACY_RADIUS ( 0x3ff )

typedef struct GeoIPRecordTag {
char *country_code;
Expand All @@ -46,9 +45,6 @@ typedef struct GeoIPRecordTag {
int area_code;
int charset;
char *continent_code;
/* confidence factor for Country/Region/City/Postal */
unsigned char country_conf, region_conf, city_conf, postal_conf;
int accuracy_radius;
} GeoIPRecord;

GeoIPRecord * GeoIP_record_by_ipnum (GeoIP* gi, unsigned long ipnum);
Expand Down

0 comments on commit 999d57a

Please sign in to comment.