GeoIPDatabase *GeoIPDatabase::load(const QString &filename, QString &error) { GeoIPDatabase *db = nullptr; QFile file(filename); if (file.size() > MAX_FILE_SIZE) { error = tr("Unsupported database file size."); return 0; } if (!file.open(QFile::ReadOnly)) { error = file.errorString(); return 0; } db = new GeoIPDatabase(file.size()); if (file.read(reinterpret_cast<char *>(db->m_data), db->m_size) != db->m_size) { error = file.errorString(); delete db; return 0; } if (!db->parseMetadata(db->readMetadata(), error) || !db->loadDB(error)) { delete db; return 0; } return db; }
GeoIPDatabase *GeoIPDatabase::load(const QByteArray &data, QString &error) { GeoIPDatabase *db = nullptr; if (data.size() > MAX_FILE_SIZE) { error = tr("Unsupported database file size."); return 0; } db = new GeoIPDatabase(data.size()); memcpy(reinterpret_cast<char *>(db->m_data), data.constData(), db->m_size); if (!db->parseMetadata(db->readMetadata(), error) || !db->loadDB(error)) { delete db; return 0; } return db; }