From e4206e9cfb067ea33280c022d702c7f5f19a6372 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Wed, 18 Nov 2009 10:32:06 +0000 Subject: [PATCH] MDL-20887 latest geoip lib imported --- lib/geoip/ChangeLog.htm | 7 +++++- lib/geoip/geoip.inc | 45 +++++++++++++++++++++++++++++++++-- lib/geoip/geoipcity.inc | 11 ++++++++- lib/geoip/geoipregionvars.php | 14 ++++++++++- 4 files changed, 72 insertions(+), 5 deletions(-) diff --git a/lib/geoip/ChangeLog.htm b/lib/geoip/ChangeLog.htm index 72940f95ae..632a2b37da 100644 --- a/lib/geoip/ChangeLog.htm +++ b/lib/geoip/ChangeLog.htm @@ -1,4 +1,9 @@ + * Workaround php's broken usage of mb_substr instead of substr with + mbstring.func_overload and mbstring.internal_encoding ( Boris Zentner ) + * Change Turkey's continent code from AS to EU ( Boris Zentner ) + * Update FIPS codes 20090723 ( Boris Zentner ) 1.8 2009-04-02 + * Add continent_code to the city record. See: sample_city.php ( Boris Zentner ) * Update FIPS codes 20090401 ( Boris Zentner ) * Fixed spelling of Kazakhstan, was Kazakstan * Fix TN FIPS codes and add two new TH79 and TH80 ( Boris Zentner ) @@ -58,4 +63,4 @@ * Added support for GeoIP Region and GeoIP City 1.0 2002-11-21 - * Initial checkin to CVS + * Initial checkin to CVS \ No newline at end of file diff --git a/lib/geoip/geoip.inc b/lib/geoip/geoip.inc index 776b14c471..70948dcdc3 100644 --- a/lib/geoip/geoip.inc +++ b/lib/geoip/geoip.inc @@ -203,6 +203,35 @@ class GeoIP { "Anonymous Proxy","Satellite Provider","Other", "Aland Islands","Guernsey","Isle of Man","Jersey","Saint Barthelemy","Saint Martin" ); + + var $GEOIP_CONTINENT_CODES = array( +"--", "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", "EU", "SA", "OC", +"AS", "AF", "EU", "AF", "OC", "NA", "SA", "AS", "EU", "SA", +"SA", "SA", "SA", "AS", "OC", "OC", "OC", "AS", "AF", "EU", +"AF", "AF", "EU", "AF", "--", "--", "--", "EU", "EU", "EU", +"EU", "SA", "SA" ); + } function geoip_load_shared_mem ($file) { @@ -391,10 +420,17 @@ function _geoip_seek_country($gi, $ipnum) { $offset = 0; for ($depth = 31; $depth >= 0; --$depth) { if ($gi->flags & GEOIP_MEMORY_CACHE) { + // workaround php's broken substr, strpos, etc handling with + // mbstring.func_overload and mbstring.internal_encoding + $enc = mb_internal_encoding(); + mb_internal_encoding('ISO-8859-1'); + $buf = substr($gi->memory_buffer, 2 * $gi->record_length * $offset, 2 * $gi->record_length); - } elseif ($gi->flags & GEOIP_SHARED_MEMORY) { + + mb_internal_encoding($enc); + } elseif ($gi->flags & GEOIP_SHARED_MEMORY) { $buf = @shmop_read ($gi->shmid, 2 * $gi->record_length * $offset, 2 * $gi->record_length ); @@ -437,7 +473,12 @@ function _get_org($gi,$ipnum){ fseek($gi->filehandle, $record_pointer, SEEK_SET); $org_buf = fread($gi->filehandle,MAX_ORG_RECORD_LENGTH); } + // workaround php's broken substr, strpos, etc handling with + // mbstring.func_overload and mbstring.internal_encoding + $enc = mb_internal_encoding(); + mb_internal_encoding('ISO-8859-1'); $org_buf = substr($org_buf, 0, strpos($org_buf, 0)); + mb_internal_encoding($enc); return $org_buf; } @@ -498,4 +539,4 @@ function getdnsattributes ($l,$ip){ return $str; } -?> +?> \ No newline at end of file diff --git a/lib/geoip/geoipcity.inc b/lib/geoip/geoipcity.inc index 3c21c694ca..2297745e3f 100644 --- a/lib/geoip/geoipcity.inc +++ b/lib/geoip/geoipcity.inc @@ -45,6 +45,7 @@ class geoiprecord { var $area_code; var $dma_code; # metro and dma code are the same. use metro_code var $metro_code; + var $continent_code; } class geoipdnsrecord { @@ -119,6 +120,12 @@ function _get_record($gi,$ipnum){ if ($seek_country == $gi->databaseSegments) { return NULL; } + + // workaround php's broken substr, strpos, etc handling with + // mbstring.func_overload and mbstring.internal_encoding + $enc = mb_internal_encoding(); + mb_internal_encoding('ISO-8859-1'); + $record_pointer = $seek_country + (2 * $gi->record_length - 1) * $gi->databaseSegments; if ($gi->flags & GEOIP_MEMORY_CACHE) { @@ -135,6 +142,7 @@ function _get_record($gi,$ipnum){ $record->country_code = $gi->GEOIP_COUNTRY_CODES[$char]; $record->country_code3 = $gi->GEOIP_COUNTRY_CODES3[$char]; $record->country_name = $gi->GEOIP_COUNTRY_NAMES[$char]; + $record->continent_code = $gi->GEOIP_CONTINENT_CODES[$char]; $record_buf_pos++; $str_length = 0; // Get region @@ -194,6 +202,7 @@ function _get_record($gi,$ipnum){ $record->area_code = $metroarea_combo%1000; } } + mb_internal_encoding($enc); return $record; } @@ -205,4 +214,4 @@ function GeoIP_record_by_addr ($gi,$addr){ return _get_record($gi, $ipnum); } -?> +?> \ No newline at end of file diff --git a/lib/geoip/geoipregionvars.php b/lib/geoip/geoipregionvars.php index 90816e2a5f..9ae67dbf79 100644 --- a/lib/geoip/geoipregionvars.php +++ b/lib/geoip/geoipregionvars.php @@ -1938,6 +1938,7 @@ $GEOIP_REGION_NAME = array( "23" => "Rangarvallasysla", "28" => "Skagafjardarsysla", "29" => "Snafellsnes- og Hnappadalssysla", + "30" => "Strandasysla", "31" => "Sudur-Mulasysla", "32" => "Sudur-Tingeyjarsysla", "34" => "Vestur-Bardastrandarsysla", @@ -2190,6 +2191,7 @@ $GEOIP_REGION_NAME = array( "17" => "Louangphrabang"), "LB" => array( "01" => "Beqaa", + "02" => "Al Janub", "03" => "Liban-Nord", "04" => "Beyrouth", "05" => "Mont-Liban", @@ -2261,6 +2263,7 @@ $GEOIP_REGION_NAME = array( "LR" => array( "01" => "Bong", "04" => "Grand Cape Mount", + "05" => "Lofa", "06" => "Maryland", "07" => "Monrovia", "09" => "Nimba", @@ -2844,8 +2847,10 @@ $GEOIP_REGION_NAME = array( "05" => "Lagos", "10" => "Rivers", "11" => "Federal Capital Territory", + "12" => "Gongola", "16" => "Ogun", "17" => "Ondo", + "18" => "Oyo", "21" => "Akwa Ibom", "22" => "Cross River", "23" => "Kaduna", @@ -2968,6 +2973,7 @@ $GEOIP_REGION_NAME = array( "14" => "Yaren"), "NZ" => array( "10" => "Chatham Islands", + "85" => "Waikato", "E7" => "Auckland", "E8" => "Bay of Plenty", "E9" => "Canterbury", @@ -3095,6 +3101,7 @@ $GEOIP_REGION_NAME = array( "42" => "Misamis Occidental", "43" => "Misamis Oriental", "44" => "Mountain", + "45" => "Negros Occidental", "46" => "Negros Oriental", "47" => "Nueva Ecija", "48" => "Nueva Vizcaya", @@ -3458,6 +3465,7 @@ $GEOIP_REGION_NAME = array( "RW" => array( "01" => "Butare", "06" => "Gitarama", + "07" => "Kibungo", "09" => "Kigali", "11" => "Est", "12" => "Kigali", @@ -3728,6 +3736,7 @@ $GEOIP_REGION_NAME = array( "04" => "Saint-Louis", "05" => "Tambacounda", "07" => "Thies", + "08" => "Louga", "09" => "Fatick", "10" => "Kaolack", "11" => "Kolda", @@ -4283,12 +4292,14 @@ $GEOIP_REGION_NAME = array( "03" => "Ben Tre", "04" => "Binh Tri Thien", "05" => "Cao Bang", + "06" => "Cuu Long", "07" => "Dac Lac", "09" => "Dong Thap", "11" => "Ha Bac", "12" => "Hai Hung", "13" => "Hai Phong", "14" => "Ha Nam Ninh", + "15" => "Ha Noi", "16" => "Ha Son Binh", "17" => "Ha Tuyen", "19" => "Hoang Lien Son", @@ -4396,6 +4407,7 @@ $GEOIP_REGION_NAME = array( "03" => "Al Mahrah", "04" => "Hadramawt", "05" => "Shabwah", + "06" => "Al Ghaydah", "08" => "Al Hudaydah", "10" => "Al Mahwit", "11" => "Dhamar", @@ -4441,4 +4453,4 @@ $GEOIP_REGION_NAME = array( "09" => "Bulawayo", "10" => "Harare") ); -?> +?> \ No newline at end of file -- 2.39.5