IP2CParser Class Reference

#include <ip2cparser.h>

+ Inheritance diagram for IP2CParser:

Classes

class  ConstructorDestructorParserStateSetter
 Sets states for IP2C when being constructed and destructed. More...
 
class  ParsingThread
 

Signals

void parsingFinished (bool bSuccess)
 A signal emitted when parser finishes its job. More...
 

Public Member Functions

 IP2CParser (IP2C *pTargetDatabase)
 
IP2Cip2c () const
 Retrieves the IP2C database this parser operates on. More...
 
bool isParsing () const
 For multi-threading purposes. If this is true it is not recommended to delete this object nor the underlying IP2C database. More...
 
bool readDatabase (const QString &filePath)
 
void readDatabaseThreaded (const QString &filePath)
 

Protected Types

typedef QHash< QString, QList
< IP2C::IP2CData > > 
Countries
 
typedef QHash< QString, QList
< IP2C::IP2CData >
>::const_iterator 
CountriesConstIt
 
typedef QHash< QString, QList
< IP2C::IP2CData > >::iterator 
CountriesIt
 

Protected Slots

void parsingThreadFinished ()
 

Protected Member Functions

bool convertAndSaveDatabase (QByteArray &downloadedData, const QString &outFilePath)
 
void convertCountriesIntoBinaryData (const Countries &countries, QByteArray &output)
 
bool doReadDatabase (const QString &filePath)
 
bool readDatabaseVersion1 (const QByteArray &dataArray)
 
bool readDatabaseVersion2 (const QByteArray &dataArray)
 
void readTextDatabase (QByteArray &textDatabase, Countries &countries)
 

Protected Attributes

bool bIsParsing
 
ParsingThreadcurrentParsingThread
 
IP2CpTargetDatabase
 Database to which the IP2C parser will save the data it retrieves from IP2C file. More...
 
QMutex thisLock
 

Detailed Description

Class accepts text database from: http://software77.net/geo-ip The first time the text database is read it is compacted into a smaller format and stored on the drive.

See Also
convertAndSaveDatabase()
Compacted database file format, version 1:
(all strings are null terminated)
Header:
TYPE LENGTH DESCRIPTION
-----------------------------------------------------
unsigned long 4 'I' 'P' '2' 'C' bytes
unsigned short 2 Version (equal to 1)

Block repeated until EOF:

TYPE LENGTH DESCRIPTION
-----------------------------------------------------
unsigned long 4 Beginning of an IP range
unsigned long 4 End of an IP range
string N/A Country name abbreviation

Compacted database file format, version 2: (all strings are null terminated) Header:

TYPE LENGTH DESCRIPTION
-----------------------------------------------------
unsigned long 4 'I' 'P' '2' 'C' bytes
unsigned short 2 Version (equal to 2)

Block repeated until EOF:

TYPE LENGTH DESCRIPTION
-----------------------------------------------------
string N/A Country full name
string N/A Country abbreviation
unsigned long 4 Number of IP Blocks (N_IP_BLOCKS)
-- BLOCK: repeated N_IP_BLOCKS times.
unsigned long 4 Beginning of an IP range
unsigned long 4 End of an IP range
-- END OF BLOCK

Definition at line 81 of file ip2cparser.h.

Member Typedef Documentation

typedef QHash<QString, QList<IP2C::IP2CData> > IP2CParser::Countries
protected

Key value is the abbreviation of the country name.

Definition at line 148 of file ip2cparser.h.

Member Function Documentation

bool IP2CParser::convertAndSaveDatabase ( QByteArray &  downloadedData,
const QString &  outFilePath 
)
protected

Converts downloaded text database to a compacted binary file. The name of the new file is IP2C::file.

Definition at line 40 of file ip2cparser.cpp.

void IP2CParser::convertCountriesIntoBinaryData ( const Countries countries,
QByteArray &  output 
)
protected

Converts previously created by readTextDatabase() countries hash table into an output data that can be saved into a file.

Definition at line 64 of file ip2cparser.cpp.

IP2C* IP2CParser::ip2c ( ) const
inline

Retrieves the IP2C database this parser operates on.

Definition at line 91 of file ip2cparser.h.

bool IP2CParser::isParsing ( ) const
inline

For multi-threading purposes. If this is true it is not recommended to delete this object nor the underlying IP2C database.

Definition at line 97 of file ip2cparser.h.

void IP2CParser::parsingFinished ( bool  bSuccess)
signal

A signal emitted when parser finishes its job.

It is not safe to delete IP2CParser object after readDatabase() call and before this signal is emitted.

void IP2CParser::readTextDatabase ( QByteArray &  textDatabase,
Countries countries 
)
protected

Called by convertAndSaveDatabase().

Parameters
textDatabase- contents of the file, this will be modified by this function.
[out]countries- returned hash table of countries.

Definition at line 300 of file ip2cparser.cpp.

Member Data Documentation

IP2C* IP2CParser::pTargetDatabase
protected

Database to which the IP2C parser will save the data it retrieves from IP2C file.

Since IP2CParser is prepared to work in a separate thread it is not advised to delete the IP2C object before parsing is complete.

Definition at line 162 of file ip2cparser.h.


The documentation for this class was generated from the following files: