ts-ip2region2 1.4.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/checksums.json +1 -1
- package/data/ip2region.7z +0 -0
- package/ip2region/xdb_api.h +10 -4
- package/ip2region/xdb_searcher.c +8 -1
- package/ip2region/xdb_util.c +32 -10
- package/package.json +1 -1
package/data/checksums.json
CHANGED
package/data/ip2region.7z
CHANGED
|
Binary file
|
package/ip2region/xdb_api.h
CHANGED
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
#ifndef C_IP2REGION_XDB_H
|
|
10
10
|
#define C_IP2REGION_XDB_H
|
|
11
11
|
|
|
12
|
+
// @Note:
|
|
13
|
+
// this define must be put before any header include
|
|
14
|
+
// force the LFS for ftell
|
|
15
|
+
#define _FILE_OFFSET_BITS 64
|
|
12
16
|
#include <stdio.h>
|
|
13
17
|
#include <stdlib.h>
|
|
14
18
|
#include <string.h>
|
|
@@ -17,9 +21,6 @@
|
|
|
17
21
|
# define XDB_PUBLIC(type) extern __declspec(dllexport) type
|
|
18
22
|
# define XDB_PRIVATE(type) static type
|
|
19
23
|
# define XDB_WINDOWS
|
|
20
|
-
#ifndef WIN32_LEAN_AND_MEAN
|
|
21
|
-
#define WIN32_LEAN_AND_MEAN
|
|
22
|
-
#endif
|
|
23
24
|
#include <winsock2.h>
|
|
24
25
|
#include <ws2tcpip.h>
|
|
25
26
|
#include <windows.h>
|
|
@@ -204,6 +205,11 @@ XDB_PUBLIC(int) xdb_v6_ip_to_string(const bytes_ip_t *, char *, size_t);
|
|
|
204
205
|
// returns: -1 if ip1 < ip2, 1 if ip1 > ip2 or 0
|
|
205
206
|
XDB_PUBLIC(int) xdb_ip_sub_compare(const bytes_ip_t *, int, const char *, int);
|
|
206
207
|
|
|
208
|
+
// large file seek and tell
|
|
209
|
+
XDB_PUBLIC(int) xdb_fseek(FILE *, long long, int);
|
|
210
|
+
|
|
211
|
+
XDB_PUBLIC(long long) xdb_ftell(FILE *);
|
|
212
|
+
|
|
207
213
|
// --- END xdb utils
|
|
208
214
|
|
|
209
215
|
|
|
@@ -276,4 +282,4 @@ XDB_PUBLIC(int) xdb_get_io_count(xdb_searcher_t *);
|
|
|
276
282
|
|
|
277
283
|
// --- END xdb searcher api
|
|
278
284
|
|
|
279
|
-
#endif // C_IP2REGION_XDB_H
|
|
285
|
+
#endif // C_IP2REGION_XDB_H
|
package/ip2region/xdb_searcher.c
CHANGED
|
@@ -196,6 +196,13 @@ XDB_PUBLIC(int) xdb_search(xdb_searcher_t *xdb, const bytes_ip_t *ip_bytes, int
|
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
// printf("s_ptr=%u, e_ptr=%u\n", s_ptr, e_ptr);
|
|
199
|
+
// @Note: ptr validate, zero ptr means source data missing
|
|
200
|
+
// so we could just stop here and return an empty string.
|
|
201
|
+
if (s_ptr == 0 || e_ptr == 0) {
|
|
202
|
+
xdb_region_buffer_empty(region);
|
|
203
|
+
return err;
|
|
204
|
+
}
|
|
205
|
+
|
|
199
206
|
// binary search to get the final region info
|
|
200
207
|
// segment_buffer = xdb_malloc(seg_index_size);
|
|
201
208
|
seg_index_size = xdb->version->segment_index_size;
|
|
@@ -270,4 +277,4 @@ XDB_PUBLIC(xdb_version_t *) xdb_get_version(xdb_searcher_t *xdb) {
|
|
|
270
277
|
|
|
271
278
|
XDB_PUBLIC(int) xdb_get_io_count(xdb_searcher_t *xdb) {
|
|
272
279
|
return xdb->io_count;
|
|
273
|
-
}
|
|
280
|
+
}
|
package/ip2region/xdb_util.c
CHANGED
|
@@ -228,7 +228,7 @@ XDB_PUBLIC(void) xdb_free_content(void *ptr) {
|
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
XDB_PUBLIC(int) xdb_verify_from_header(FILE *handle, xdb_header_t *header) {
|
|
231
|
-
int runtime_ptr_bytes = 0; // runtime ptr bytes
|
|
231
|
+
unsigned int runtime_ptr_bytes = 0; // runtime ptr bytes
|
|
232
232
|
if (header->version == xdb_structure_20) {
|
|
233
233
|
runtime_ptr_bytes = 4;
|
|
234
234
|
} else if (header->version == xdb_structure_30) {
|
|
@@ -244,15 +244,10 @@ XDB_PUBLIC(int) xdb_verify_from_header(FILE *handle, xdb_header_t *header) {
|
|
|
244
244
|
return 3;
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
long
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
// Use unsigned long long for maxFilePtr to avoid overflow
|
|
253
|
-
unsigned long long maxFilePtr = (1ULL << (runtime_ptr_bytes * 8)) - 1;
|
|
254
|
-
// printf("fileBytes: %ld, maxFilePtr: %llu\n", fileBytes, maxFilePtr);
|
|
255
|
-
if ((unsigned long long)fileBytes > maxFilePtr) {
|
|
247
|
+
long long fileBytes = xdb_ftell(handle);
|
|
248
|
+
long long maxFilePtr = (1LL << (runtime_ptr_bytes * 8)) - 1;
|
|
249
|
+
// printf("fileBytes: %lld, maxFilePtr: %lld\n", fileBytes, maxFilePtr);
|
|
250
|
+
if (fileBytes > maxFilePtr) {
|
|
256
251
|
return 4;
|
|
257
252
|
}
|
|
258
253
|
|
|
@@ -500,4 +495,31 @@ XDB_PUBLIC(int) xdb_ip_sub_compare(const bytes_ip_t *ip1, int bytes, const char
|
|
|
500
495
|
}
|
|
501
496
|
}
|
|
502
497
|
return 0;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
XDB_PUBLIC(int) xdb_fseek(FILE *handle, long long offset, int whence) {
|
|
501
|
+
// we may have to use the large file solution later
|
|
502
|
+
// #if defined(XDB_LINUX)
|
|
503
|
+
// return fseeko(handle, (off_t) offset, whence);
|
|
504
|
+
// #elif defined(XDB_WINDOWS)
|
|
505
|
+
// return _fseeki64(handle, (__int64) offset, whence)
|
|
506
|
+
// #else
|
|
507
|
+
// return fseek(handle, (long) offset, whence);
|
|
508
|
+
// #endif
|
|
509
|
+
|
|
510
|
+
return fseek(handle, (long) offset, whence);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
XDB_PUBLIC(long long) xdb_ftell(FILE *handle) {
|
|
514
|
+
// we may have to use the large file solution later
|
|
515
|
+
// #if defined(XDB_LINUX)
|
|
516
|
+
// return (long long) ftello(handle);
|
|
517
|
+
// #elif defined(XDB_WINDOWS)
|
|
518
|
+
// return (long long) _ftelli64(handle);
|
|
519
|
+
// #else
|
|
520
|
+
// // report error ?
|
|
521
|
+
// return (long long) ftell(handle);
|
|
522
|
+
// #endif
|
|
523
|
+
|
|
524
|
+
return (long long) ftell(handle);
|
|
503
525
|
}
|
package/package.json
CHANGED