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

GeoIPWrapper.cpp

Go to the documentation of this file.
00001 /* GeoIPWrapper.h
00002  *
00003  * Copyright (C) 2005 Guwashi <guwashi[AT]fooos[DOT]com>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #include "GeoIPWrapper.h"
00021 
00022 GeoIPWrapper::GeoIPWrapper(char* filename, int flags)
00023 {
00024   m_gi = GeoIP_open(filename, flags);
00025 }
00026 
00027 GeoIPWrapper::GeoIPWrapper(int flags)
00028 {
00029   m_gi = GeoIP_new(flags);
00030 }
00031 
00032 GeoIPWrapper::~GeoIPWrapper()
00033 {
00034   if (m_gi) GeoIP_delete(m_gi);
00035 }
00036 
00037 const char* GeoIPWrapper::getCountryCodeByName(const char* host) const
00038 {
00039   if (!m_gi) return "--";
00040   const char* result = GeoIP_country_code_by_name(m_gi, host);
00041   return (NULL == result) ? "--" : result;
00042 }
00043 
00044 const char* GeoIPWrapper::getCountryCodeByAddr(const char* addr) const
00045 {
00046   if (!m_gi) return "--";
00047   const char* result = GeoIP_country_code_by_addr(m_gi, addr);
00048   return (NULL == result) ? "--" : result;
00049 }
00050 
00051 const char* GeoIPWrapper::getCountryCode3ByName(const char* host) const
00052 {
00053   if (!m_gi) return "--";
00054   const char* result = GeoIP_country_code3_by_name(m_gi, host);
00055   return (NULL == result) ? "--" : result;
00056 }
00057 
00058 const char* GeoIPWrapper::getCountryCode3ByAddr(const char* addr) const
00059 {
00060   if (!m_gi) return "--";
00061   const char* result = GeoIP_country_code3_by_addr(m_gi, addr);
00062   return (NULL == result) ? "--" : result;
00063 }
00064 
00065 const char* GeoIPWrapper::getCountryNameByName(const char* host) const
00066 {
00067   if (!m_gi) return "--";
00068   const char* result = GeoIP_country_name_by_name(m_gi, host);
00069   return (NULL == result) ? "--" : result;
00070 }
00071 
00072 const char* GeoIPWrapper::getCountryNameByAddr(const char* addr) const
00073 {
00074   if (!m_gi) return "--";
00075   const char* result = GeoIP_country_name_by_addr(m_gi, addr);
00076   return (NULL == result) ? "--" : result;
00077 }
00078 
00079 int GeoIPWrapper::getIdByName(const char* host) const
00080 {
00081   if (!m_gi) return 0;
00082   return GeoIP_id_by_name(m_gi, host);
00083 }
00084 
00085 int GeoIPWrapper::getIdByAddr(const char* addr) const
00086 {
00087   if (!m_gi) return 0;
00088   return GeoIP_id_by_addr(m_gi, addr);
00089 }
00090 
00091 const char* GeoIPWrapper::idToCountryCode(int countryId)
00092 {
00093   // sizeof(GeoIP_country_code) == 741
00094   return (countryId > 0 && countryId < sizeof(GeoIP_country_code) / 3)  ? GeoIP_country_code[countryId] : "--";
00095 }
00096 
00097 const char* GeoIPWrapper::idToCountryCode3(int countryId)
00098 {
00099   // sizeof(GeoIP_country_code3) == 988
00100   return (countryId > 0 && countryId < sizeof(GeoIP_country_code3) / 4) ? GeoIP_country_code3[countryId] : "--";
00101 }
00102 
00103 const char* GeoIPWrapper::idToCountryName(int countryId)
00104 {
00105   // sizeof(GeoIP_country_name) == 988
00106   return (countryId > 0 && countryId < sizeof(GeoIP_country_name) / 4) ? GeoIP_country_name[countryId] : "--";
00107 }

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