diff options
author | George Hazan <ghazan@miranda.im> | 2021-12-26 20:31:39 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-12-26 20:31:39 +0300 |
commit | cddcd7483a7c472598af098e759e5d309024f606 (patch) | |
tree | b0a227d6e087c41958cc84d27bc323353248aae5 /plugins/CountryFlags/src/ip2country.cpp | |
parent | 1039b2829a264280493ba0fa979214fe024dc70c (diff) |
DWORD -> uint32_t
Diffstat (limited to 'plugins/CountryFlags/src/ip2country.cpp')
-rw-r--r-- | plugins/CountryFlags/src/ip2country.cpp | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/plugins/CountryFlags/src/ip2country.cpp b/plugins/CountryFlags/src/ip2country.cpp index 6f3b2c6901..de8cc0e439 100644 --- a/plugins/CountryFlags/src/ip2country.cpp +++ b/plugins/CountryFlags/src/ip2country.cpp @@ -24,34 +24,34 @@ extern struct CountryListEntry *countries; /************************* Bin Records ****************************/
-#define DATARECORD_SIZE (sizeof(DWORD)+sizeof(DWORD)+sizeof(uint16_t))
+#define DATARECORD_SIZE (sizeof(uint32_t)+sizeof(uint32_t)+sizeof(uint16_t))
// mir_free() the return value
-static uint8_t* GetDataHeader(uint8_t *data, DWORD cbDataSize, DWORD *pnDataRecordCount)
+static uint8_t* GetDataHeader(uint8_t *data, uint32_t cbDataSize, uint32_t *pnDataRecordCount)
{
uint8_t *recordData;
- /* uncompressed size stored in first DWORD */
- *pnDataRecordCount = (*(DWORD*)data) / DATARECORD_SIZE;
- recordData = (uint8_t*)mir_alloc(*(DWORD*)data);
+ /* uncompressed size stored in first uint32_t */
+ *pnDataRecordCount = (*(uint32_t*)data) / DATARECORD_SIZE;
+ recordData = (uint8_t*)mir_alloc(*(uint32_t*)data);
if (recordData != nullptr)
- Huffman_Uncompress(data + sizeof(DWORD), recordData, cbDataSize - sizeof(DWORD), *(DWORD*)data);
+ Huffman_Uncompress(data + sizeof(uint32_t), recordData, cbDataSize - sizeof(uint32_t), *(uint32_t*)data);
return recordData;
}
-static int GetDataRecord(uint8_t *data, DWORD index, DWORD *pdwFrom, DWORD *pdwTo)
+static int GetDataRecord(uint8_t *data, uint32_t index, uint32_t *pdwFrom, uint32_t *pdwTo)
{
data += index * DATARECORD_SIZE;
- *pdwFrom = *(DWORD*)data;
- data += sizeof(DWORD);
- if (pdwTo != nullptr) *pdwTo = *(DWORD*)data;
- data += sizeof(DWORD);
+ *pdwFrom = *(uint32_t*)data;
+ data += sizeof(uint32_t);
+ if (pdwTo != nullptr) *pdwTo = *(uint32_t*)data;
+ data += sizeof(uint32_t);
return (int)*(uint16_t*)data;
}
/************************* Record Cache ***************************/
static mir_cs csRecordCache;
-static DWORD nDataRecordsCount; /* protected by csRecordCache */
+static uint32_t nDataRecordsCount; /* protected by csRecordCache */
static uint8_t *dataRecords; /* protected by csRecordCache */
#define UNLOADDELAY 30*1000 /* time after which the data records are being unloaded */
@@ -64,17 +64,17 @@ static void CALLBACK UnloadRecordCache(LPARAM) }
// function assumes it has got the csRecordCache mutex
-static BOOL EnsureRecordCacheLoaded(uint8_t **pdata, DWORD *pcount)
+static BOOL EnsureRecordCacheLoaded(uint8_t **pdata, uint32_t *pcount)
{
HRSRC hrsrc;
- DWORD cb;
+ uint32_t cb;
mir_cslock lck(csRecordCache);
if (dataRecords == nullptr) {
/* load record data list from resources */
hrsrc = FindResource(g_plugin.getInst(), MAKEINTRESOURCE(IDR_IPTOCOUNTRY), L"BIN");
cb = SizeofResource(g_plugin.getInst(), hrsrc);
dataRecords = (uint8_t*)LockResource(LoadResource(g_plugin.getInst(), hrsrc));
- if (cb <= sizeof(DWORD) || dataRecords == nullptr)
+ if (cb <= sizeof(uint32_t) || dataRecords == nullptr)
return FALSE;
/* uncompress record data */
dataRecords = GetDataHeader(dataRecords, cb, &nDataRecordsCount);
@@ -98,8 +98,8 @@ static void LeaveRecordCache(void) INT_PTR ServiceIpToCountry(WPARAM wParam, LPARAM)
{
uint8_t *data;
- DWORD dwFrom, dwTo;
- DWORD low = 0, i, high;
+ uint32_t dwFrom, dwTo;
+ uint32_t low = 0, i, high;
int id;
if (EnsureRecordCacheLoaded(&data, &high)) {
/* binary search in record data */
@@ -163,10 +163,10 @@ struct { struct ResizableByteBuffer {
uint8_t *buf;
- DWORD cbLength, cbAlloced;
+ uint32_t cbLength, cbAlloced;
};
-static void AppendToByteBuffer(struct ResizableByteBuffer *buffer, const void *append, DWORD cbAppendSize)
+static void AppendToByteBuffer(struct ResizableByteBuffer *buffer, const void *append, uint32_t cbAppendSize)
{
if (buffer->cbAlloced <= buffer->cbLength + cbAppendSize) {
uint8_t* buf = (uint8_t*)mir_realloc(buffer->buf, buffer->cbAlloced + ALLOC_STEP + cbAppendSize);
@@ -184,7 +184,7 @@ static int EnumIpDataLines(const char *pszFileCSV, const char *pszFileOut) FILE *fp;
char line[1024], out[512], *pszFrom, *pszTo, *pszTwo, *pszCountry, *buf;
int i, j;
- DWORD dwOut;
+ uint32_t dwOut;
uint16_t wOut;
struct ResizableByteBuffer buffer;
@@ -233,10 +233,10 @@ static int EnumIpDataLines(const char *pszFileCSV, const char *pszFileOut) buf = (char*)countries[i].szName;
/* check country */
if (!mir_strcmpi(pszCountry, buf)) {
- dwOut = (DWORD)atoi(pszFrom);
- AppendToByteBuffer(&buffer, (void*)&dwOut, sizeof(DWORD));
- dwOut = (DWORD)atoi(pszTo);
- AppendToByteBuffer(&buffer, (void*)&dwOut, sizeof(DWORD));
+ dwOut = (uint32_t)atoi(pszFrom);
+ AppendToByteBuffer(&buffer, (void*)&dwOut, sizeof(uint32_t));
+ dwOut = (uint32_t)atoi(pszTo);
+ AppendToByteBuffer(&buffer, (void*)&dwOut, sizeof(uint32_t));
wOut = (uint16_t)countries[i].id;
AppendToByteBuffer(&buffer, (void*)&wOut, sizeof(uint16_t));
break;
@@ -252,9 +252,9 @@ static int EnumIpDataLines(const char *pszFileCSV, const char *pszFileOut) OutputDebugStringA("Done!\n"); /* all ascii */
if (buffer.buf != NULL) {
HANDLE hFileOut;
- DWORD cbWritten = 0;
+ uint32_t cbWritten = 0;
uint8_t *compressed;
- DWORD cbCompressed;
+ uint32_t cbCompressed;
/* compress whole data */
OutputDebugStringA("Compressing...\n"); /* all ascii */
compressed = (uint8_t*)mir_alloc(buffer.cbAlloced + 384);
@@ -266,7 +266,7 @@ static int EnumIpDataLines(const char *pszFileCSV, const char *pszFileOut) if (hFileOut != INVALID_HANDLE_VALUE) {
/* store data length count at beginning */
dwOut = buffer.cbLength;
- WriteFile(hFileOut, &dwOut, sizeof(DWORD), &cbWritten, NULL);
+ WriteFile(hFileOut, &dwOut, sizeof(uint32_t), &cbWritten, NULL);
/* store compressed data records */
WriteFile(hFileOut, compressed, cbCompressed, &cbWritten, NULL);
CloseHandle(hFileOut);
|