libisdn
|
00001 /* 00002 * ISO 3166-1 Numeric-, Two-Letter Codes and Names 00003 * Taken from: http://en.wikipedia.org/wiki/ISO_3166-1 00004 */ 00005 #ifdef HAVE_CONFIG_H 00006 #include "config.h" 00007 #endif 00008 00009 #include <stdio.h> 00010 #include <strings.h> 00011 00012 #include "ISO3166.h" 00013 00014 #include "utils/common.h" 00015 00016 static const struct { 00017 const unsigned short id; 00018 const char *code; 00019 const char *name; 00020 } iso_3166[] = { 00021 { 4, "AF", "Afghanistan" }, 00022 { 248, "AX", "Aland Islands" }, 00023 { 8, "AL", "Albania" }, 00024 { 12, "DZ", "Algeria" }, 00025 { 16, "AS", "American Samoa" }, 00026 { 20, "AD", "Andorra" }, 00027 { 24, "AO", "Angola" }, 00028 { 660, "AI", "Anguilla" }, 00029 { 10, "AQ", "Antarctica" }, 00030 { 28, "AG", "Antigua and Barbuda" }, 00031 { 32, "AR", "Argentina" }, 00032 { 51, "AM", "Armenia" }, 00033 { 533, "AW", "Aruba" }, 00034 { 36, "AU", "Australia" }, 00035 { 40, "AT", "Austria" }, 00036 { 31, "AZ", "Azerbaijan" }, 00037 { 44, "BS", "Bahamas" }, 00038 { 48, "BH", "Bahrain" }, 00039 { 50, "BD", "Bangladesh" }, 00040 { 52, "BB", "Barbados" }, 00041 { 112, "BY", "Belarus" }, 00042 { 56, "BE", "Belgium" }, 00043 { 84, "BZ", "Belize" }, 00044 { 204, "BJ", "Benin" }, 00045 { 60, "BM", "Bermuda" }, 00046 { 64, "BT", "Bhutan" }, 00047 { 68, "BO", "Bolivia, Plurinational State of" }, 00048 { 70, "BA", "Bosnia and Herzegovina" }, 00049 { 72, "BW", "Botswana" }, 00050 { 74, "BV", "Bouvet Island" }, 00051 { 76, "BR", "Brazil" }, 00052 { 86, "IO", "British Indian Ocean Territory" }, 00053 { 96, "BN", "Brunei Darussalam" }, 00054 { 100, "BG", "Bulgaria" }, 00055 { 854, "BF", "Burkina Faso" }, 00056 { 108, "BI", "Burundi" }, 00057 { 116, "KH", "Cambodia" }, 00058 { 120, "CM", "Cameroon" }, 00059 { 124, "CA", "Canada" }, 00060 { 132, "CV", "Cape Verde" }, 00061 { 136, "KY", "Cayman Islands" }, 00062 { 140, "CF", "Central African Republic" }, 00063 { 148, "TD", "Chad" }, 00064 { 152, "CL", "Chile" }, 00065 { 156, "CN", "China" }, 00066 { 162, "CX", "Christmas Island" }, 00067 { 166, "CC", "Cocos (Keeling) Islands" }, 00068 { 170, "CO", "Colombia" }, 00069 { 174, "KM", "Comoros" }, 00070 { 178, "CG", "Congo" }, 00071 { 180, "CD", "Congo, the Democratic Republic of the" }, 00072 { 184, "CK", "Cook Islands" }, 00073 { 188, "CR", "Costa Rica" }, 00074 { 384, "CI", "Cote d'Ivoire" }, 00075 { 191, "HR", "Croatia" }, 00076 { 192, "CU", "Cuba" }, 00077 { 196, "CY", "Cyprus" }, 00078 { 203, "CZ", "Czech Republic" }, 00079 { 208, "DK", "Denmark" }, 00080 { 262, "DJ", "Djibouti" }, 00081 { 212, "DM", "Dominica" }, 00082 { 214, "DO", "Dominican Republic" }, 00083 { 218, "EC", "Ecuador" }, 00084 { 818, "EG", "Egypt" }, 00085 { 222, "SV", "El Salvador" }, 00086 { 226, "GQ", "Equatorial Guinea" }, 00087 { 232, "ER", "Eritrea" }, 00088 { 233, "EE", "Estonia" }, 00089 { 231, "ET", "Ethiopia" }, 00090 { 238, "FK", "Falkland Islands (Malvinas)" }, 00091 { 234, "FO", "Faroe Islands" }, 00092 { 242, "FJ", "Fiji" }, 00093 { 246, "FI", "Finland" }, 00094 { 250, "FR", "France" }, 00095 { 254, "GF", "French Guiana" }, 00096 { 258, "PF", "French Polynesia" }, 00097 { 260, "TF", "French Southern Territories" }, 00098 { 266, "GA", "Gabon" }, 00099 { 270, "GM", "Gambia" }, 00100 { 268, "GE", "Georgia" }, 00101 { 276, "DE", "Germany" }, 00102 { 288, "GH", "Ghana" }, 00103 { 292, "GI", "Gibraltar" }, 00104 { 300, "GR", "Greece" }, 00105 { 304, "GL", "Greenland" }, 00106 { 308, "GD", "Grenada" }, 00107 { 312, "GP", "Guadeloupe" }, 00108 { 316, "GU", "Guam" }, 00109 { 320, "GT", "Guatemala" }, 00110 { 831, "GG", "Guernsey" }, 00111 { 324, "GN", "Guinea" }, 00112 { 624, "GW", "Guinea-Bissau" }, 00113 { 328, "GY", "Guyana" }, 00114 { 332, "HT", "Haiti" }, 00115 { 334, "HM", "Heard Island and McDonald Islands" }, 00116 { 336, "VA", "Holy See (Vatican City State)" }, 00117 { 340, "HN", "Honduras" }, 00118 { 344, "HK", "Hong Kong" }, 00119 { 348, "HU", "Hungary" }, 00120 { 352, "IS", "Iceland" }, 00121 { 356, "IN", "India" }, 00122 { 360, "ID", "Indonesia" }, 00123 { 364, "IR", "Iran, Islamic Republic of" }, 00124 { 368, "IQ", "Iraq" }, 00125 { 372, "IE", "Ireland" }, 00126 { 833, "IM", "Isle of Man" }, 00127 { 376, "IL", "Israel" }, 00128 { 380, "IT", "Italy" }, 00129 { 388, "JM", "Jamaica" }, 00130 { 392, "JP", "Japan" }, 00131 { 832, "JE", "Jersey" }, 00132 { 400, "JO", "Jordan" }, 00133 { 398, "KZ", "Kazakhstan" }, 00134 { 404, "KE", "Kenya" }, 00135 { 296, "KI", "Kiribati" }, 00136 { 408, "KP", "Korea, Democratic People's Republic of" }, 00137 { 410, "KR", "Korea, Republic of" }, 00138 { 414, "KW", "Kuwait" }, 00139 { 417, "KG", "Kyrgyzstan" }, 00140 { 418, "LA", "Lao People's Democratic Republic" }, 00141 { 428, "LV", "Latvia" }, 00142 { 422, "LB", "Lebanon" }, 00143 { 426, "LS", "Lesotho" }, 00144 { 430, "LR", "Liberia" }, 00145 { 434, "LY", "Libyan Arab Jamahiriya" }, 00146 { 438, "LI", "Liechtenstein" }, 00147 { 440, "LT", "Lithuania" }, 00148 { 442, "LU", "Luxembourg" }, 00149 { 446, "MO", "Macao" }, 00150 { 807, "MK", "Macedonia, the former Yugoslav Republic of" }, 00151 { 450, "MG", "Madagascar" }, 00152 { 454, "MW", "Malawi" }, 00153 { 458, "MY", "Malaysia" }, 00154 { 462, "MV", "Maldives" }, 00155 { 466, "ML", "Mali" }, 00156 { 470, "MT", "Malta" }, 00157 { 584, "MH", "Marshall Islands" }, 00158 { 474, "MQ", "Martinique" }, 00159 { 478, "MR", "Mauritania" }, 00160 { 480, "MU", "Mauritius" }, 00161 { 175, "YT", "Mayotte" }, 00162 { 484, "MX", "Mexico" }, 00163 { 583, "FM", "Micronesia, Federated States of" }, 00164 { 498, "MD", "Moldova, Republic of" }, 00165 { 492, "MC", "Monaco" }, 00166 { 496, "MN", "Mongolia" }, 00167 { 499, "ME", "Montenegro" }, 00168 { 500, "MS", "Montserrat" }, 00169 { 504, "MA", "Morocco" }, 00170 { 508, "MZ", "Mozambique" }, 00171 { 104, "MM", "Myanmar" }, 00172 { 516, "NA", "Namibia" }, 00173 { 520, "NR", "Nauru" }, 00174 { 524, "NP", "Nepal" }, 00175 { 528, "NL", "Netherlands" }, 00176 { 530, "AN", "Netherlands Antilles" }, 00177 { 540, "NC", "New Caledonia" }, 00178 { 554, "NZ", "New Zealand" }, 00179 { 558, "NI", "Nicaragua" }, 00180 { 562, "NE", "Niger" }, 00181 { 566, "NG", "Nigeria" }, 00182 { 570, "NU", "Niue" }, 00183 { 574, "NF", "Norfolk Island" }, 00184 { 580, "MP", "Northern Mariana Islands" }, 00185 { 578, "NO", "Norway" }, 00186 { 512, "OM", "Oman" }, 00187 { 586, "PK", "Pakistan" }, 00188 { 585, "PW", "Palau" }, 00189 { 275, "PS", "Palestinian Territory, Occupied" }, 00190 { 591, "PA", "Panama" }, 00191 { 598, "PG", "Papua New Guinea" }, 00192 { 600, "PY", "Paraguay" }, 00193 { 604, "PE", "Peru" }, 00194 { 608, "PH", "Philippines" }, 00195 { 612, "PN", "Pitcairn" }, 00196 { 616, "PL", "Poland" }, 00197 { 620, "PT", "Portugal" }, 00198 { 630, "PR", "Puerto Rico" }, 00199 { 634, "QA", "Qatar" }, 00200 { 638, "RE", "Reunion" }, 00201 { 642, "RO", "Romania" }, 00202 { 643, "RU", "Russian Federation" }, 00203 { 646, "RW", "Rwanda" }, 00204 { 652, "BL", "Saint Barthelemy" }, 00205 { 654, "SH", "Saint Helena, Ascension and Tristan da Cunha" }, 00206 { 659, "KN", "Saint Kitts and Nevis" }, 00207 { 662, "LC", "Saint Lucia" }, 00208 { 663, "MF", "Saint Martin (French part)" }, 00209 { 666, "PM", "Saint Pierre and Miquelon" }, 00210 { 670, "VC", "Saint Vincent and the Grenadines" }, 00211 { 882, "WS", "Samoa" }, 00212 { 674, "SM", "San Marino" }, 00213 { 678, "ST", "Sao Tome and Principe" }, 00214 { 682, "SA", "Saudi Arabia" }, 00215 { 686, "SN", "Senegal" }, 00216 { 688, "RS", "Serbia" }, 00217 { 690, "SC", "Seychelles" }, 00218 { 694, "SL", "Sierra Leone" }, 00219 { 702, "SG", "Singapore" }, 00220 { 703, "SK", "Slovakia" }, 00221 { 705, "SI", "Slovenia" }, 00222 { 90, "SB", "Solomon Islands" }, 00223 { 706, "SO", "Somalia" }, 00224 { 710, "ZA", "South Africa" }, 00225 { 239, "GS", "South Georgia and the South Sandwich Islands" }, 00226 { 724, "ES", "Spain" }, 00227 { 144, "LK", "Sri Lanka" }, 00228 { 736, "SD", "Sudan" }, 00229 { 740, "SR", "Suriname" }, 00230 { 744, "SJ", "Svalbard and Jan Mayen" }, 00231 { 748, "SZ", "Swaziland" }, 00232 { 752, "SE", "Sweden" }, 00233 { 756, "CH", "Switzerland" }, 00234 { 760, "SY", "Syrian Arab Republic" }, 00235 { 158, "TW", "Taiwan, Province of China" }, 00236 { 762, "TJ", "Tajikistan" }, 00237 { 834, "TZ", "Tanzania, United Republic of" }, 00238 { 764, "TH", "Thailand" }, 00239 { 626, "TL", "Timor-Leste" }, 00240 { 768, "TG", "Togo" }, 00241 { 772, "TK", "Tokelau" }, 00242 { 776, "TO", "Tonga" }, 00243 { 780, "TT", "Trinidad and Tobago" }, 00244 { 788, "TN", "Tunisia" }, 00245 { 792, "TR", "Turkey" }, 00246 { 795, "TM", "Turkmenistan" }, 00247 { 796, "TC", "Turks and Caicos Islands" }, 00248 { 798, "TV", "Tuvalu" }, 00249 { 800, "UG", "Uganda" }, 00250 { 804, "UA", "Ukraine" }, 00251 { 784, "AE", "United Arab Emirates" }, 00252 { 826, "GB", "United Kingdom" }, 00253 { 840, "US", "United States" }, 00254 { 581, "UM", "United States Minor Outlying Islands" }, 00255 { 858, "UY", "Uruguay" }, 00256 { 860, "UZ", "Uzbekistan" }, 00257 { 548, "VU", "Vanuatu" }, 00258 { 862, "VE", "Venezuela, Bolivarian Republic of" }, 00259 { 704, "VN", "Vietnam" }, 00260 { 92, "VG", "Virgin Islands, British" }, 00261 { 850, "VI", "Virgin Islands, U.S." }, 00262 { 876, "WF", "Wallis and Futuna" }, 00263 { 732, "EH", "Western Sahara" }, 00264 { 887, "YE", "Yemen" }, 00265 { 894, "ZM", "Zambia" }, 00266 { 716, "ZW", "Zimbabwe" }, 00267 }; 00268 00269 int iso3166_by_id(unsigned short id, const char **code, const char **name) 00270 { 00271 for (int i = 0; i < ARRAY_SIZE(iso_3166); i++) { 00272 if (iso_3166[i].id == id) { 00273 if (name) *name = iso_3166[i].name; 00274 if (code) *code = iso_3166[i].code; 00275 return 0; 00276 } 00277 } 00278 return -1; 00279 } 00280 00281 int iso3166_by_code(const char *code, unsigned short *id, const char **name) 00282 { 00283 for (int i = 0; i < ARRAY_SIZE(iso_3166); i++) { 00284 if (!strcasecmp(iso_3166[i].code, code)) { 00285 if (name) *name = iso_3166[i].name; 00286 if (id) *id = iso_3166[i].id; 00287 return 0; 00288 } 00289 } 00290 return -1; 00291 }