Closed Mecanik closed 3 years ago
Leaving this here for all those people that would like to use this "library" but unfortunately the documentation is poor and you must google around to find stuff.
/* Get country name */
status = MMDB_get_value(&result.entry, &entry_data, "country ", "names", "en", NULL);
if (MMDB_SUCCESS != status) { }
if (entry_data.has_data && entry_data.type == MMDB_DATA_TYPE_UTF8_STRING)
{
// c++
std::string sz(entry_data.utf8_string, entry_data.data_size);
// c
char* cdata;
if ((cdata = (char*)malloc(entry_data.data_size + 1)))
{
snprintf(cdata, entry_data.data_size + 1, "%s", entry_data.utf8_string);
}
free(cdata);
}
/* Get country 2 letter iso code */
status = MMDB_get_value(&result.entry, &entry_data, "country", "iso_code", NULL);
if (MMDB_SUCCESS != status) { }
if (entry_data.has_data && entry_data.type == MMDB_DATA_TYPE_UTF8_STRING)
{
// c++
std::string sz(entry_data.utf8_string, entry_data.data_size);
// c
char* cdata;
if ((cdata = (char*)malloc(entry_data.data_size + 1)))
{
snprintf(cdata, entry_data.data_size + 1, "%s", entry_data.utf8_string);
}
free(cdata);
}
/* Get city name */
status = MMDB_get_value(&result.entry, &entry_data, "city", "names", "en", NULL);
if (MMDB_SUCCESS != status) {}
if (entry_data.has_data && entry_data.type == MMDB_DATA_TYPE_UTF8_STRING)
{
// c++
std::string sz(entry_data.utf8_string, entry_data.data_size);
// c
char* cdata;
if ((cdata = (char*)malloc(entry_data.data_size + 1)))
{
snprintf(cdata, entry_data.data_size + 1, "%s", entry_data.utf8_string);
}
free(cdata);
}
As my last comment here, I must say that I am very disappointed. So many people contributed to this "library", but frankly it's just below my expectations. If you take IP2Location library which is far more simple, you can get it running in just under 5 minutes.
Regarding performance, DOH... even with maximum optimizations this "library" performs under IP2Location for example. I ended up creating my own cache system because I cannot even risk using this under high load.
All the best.
I am glad you figured out how to use the library.
Hi,
At my first attempt of using this "library" I'm a bit disappointed. Maybe I`m just being really dumb, but I doubt it since I have followed your "docs", yet the only thing that actually works is opening the database.
My test pseudocode:
There is no error returned by _gaierror, or _mmdberror; _result.foundentry returns true.
So what is the problem? See this screenshot: https://prnt.sc/1rscmqx
But everything else is NULL. So where's the data?
Please explain to me how am I supposed to get the data, because I have tried several ways before posting here.
Thank you