summaryrefslogtreecommitdiffstats
path: root/win32utils/GeoIP.diff
blob: bc9b6bcb5c3ffc8d52c81458a9f60544616de47e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
diff -ruN dists/GeoIP-1.5.1/libGeoIP/GeoIP.c dev/GeoIP-1.5.1/libGeoIP/GeoIP.c
--- dists/GeoIP-1.5.1/libGeoIP/GeoIP.c	2013-03-23 03:26:09.000000000 +0100
+++ dev/GeoIP-1.5.1/libGeoIP/GeoIP.c	2013-07-19 16:56:58.000000000 +0200
@@ -19,6 +19,7 @@
  */
 
 #include "GeoIP.h"
+#include "GeoIP_internal.h"
 
 static geoipv6_t IPV6_NULL;
 
@@ -44,6 +45,10 @@
 #include <stdint.h>     /* For uint32_t */
 #endif
 
+#if defined(_WIN32)
+#include "pread.h"
+#endif
+
 #ifdef _UNUSED
 #elif defined(__GNUC__)
 #define _UNUSED __attribute__ ((unused))
diff -ruN dists/GeoIP-1.5.1/libGeoIP/GeoIP.h dev/GeoIP-1.5.1/libGeoIP/GeoIP.h
--- dists/GeoIP-1.5.1/libGeoIP/GeoIP.h	2013-03-23 03:26:09.000000000 +0100
+++ dev/GeoIP-1.5.1/libGeoIP/GeoIP.h	2013-07-19 16:53:33.000000000 +0200
@@ -154,31 +154,33 @@
 	GEOIP_CORPORATE_SPEED = 3,
 } GeoIPNetspeedValues;
 
+#ifdef GEOIP_EXPORTS
+#define GEOIP_API __declspec(dllexport)
+#define GEOIP_DATA __declspec(dllexport)
+#else
+#define GEOIP_DATA __declspec(dllimport)
+#define GEOIP_API
+#endif  /* GEOIP_EXPORTS */
+
 extern char **GeoIPDBFileName;
-extern const char * GeoIPDBDescription[NUM_DB_TYPES];
-extern const char *GeoIPCountryDBFileName;
-extern const char *GeoIPRegionDBFileName;
-extern const char *GeoIPCityDBFileName;
-extern const char *GeoIPOrgDBFileName;
-extern const char *GeoIPISPDBFileName;
-extern const char *GeoIPLocationADBFileName;
-extern const char *GeoIPAccuracyRadiusFileName;
-extern const char *GeoIPCityConfidenceFileName;
+extern GEOIP_DATA const char * GeoIPDBDescription[NUM_DB_TYPES];
+extern GEOIP_DATA const char *GeoIPCountryDBFileName;
+extern GEOIP_DATA const char *GeoIPRegionDBFileName;
+extern GEOIP_DATA const char *GeoIPCityDBFileName;
+extern GEOIP_DATA const char *GeoIPOrgDBFileName;
+extern GEOIP_DATA const char *GeoIPISPDBFileName;
+extern GEOIP_DATA const char *GeoIPLocationADBFileName;
+extern GEOIP_DATA const char *GeoIPAccuracyRadiusFileName;
+extern GEOIP_DATA const char *GeoIPCityConfidenceFileName;
 extern char * GeoIP_custom_directory;
 
 /* Warning: do not use those arrays as doing so may break your
  * program with newer GeoIP versions */
-extern const char GeoIP_country_code[255][3];
-extern const char GeoIP_country_code3[255][4];
-extern const char * GeoIP_country_name[255];
-extern const char * GeoIP_utf8_country_name[255];
-extern const char GeoIP_country_continent[255][3];
-
-#ifdef DLL
-#define GEOIP_API __declspec(dllexport)
-#else
-#define GEOIP_API
-#endif  /* DLL */
+extern GEOIP_DATA const char GeoIP_country_code[255][3];
+extern GEOIP_DATA const char GeoIP_country_code3[255][4];
+extern GEOIP_DATA const char * GeoIP_country_name[255];
+extern GEOIP_DATA const char * GeoIP_utf8_country_name[255];
+extern GEOIP_DATA const char GeoIP_country_continent[255][3];
 
 GEOIP_API void GeoIP_setup_custom_directory(char *dir);
 GEOIP_API GeoIP* GeoIP_open_type (int type, int flags);
diff -ruN dists/GeoIP-1.5.1/libGeoIP/GeoIPCity.c dev/GeoIP-1.5.1/libGeoIP/GeoIPCity.c
--- dists/GeoIP-1.5.1/libGeoIP/GeoIPCity.c	2013-03-23 03:26:09.000000000 +0100
+++ dev/GeoIP-1.5.1/libGeoIP/GeoIPCity.c	2013-07-19 15:41:05.000000000 +0200
@@ -35,6 +35,10 @@
 #include <stdint.h>	/* For uint32_t */
 #endif
 
+#if defined(_WIN32)
+#include "pread.h"
+#endif
+
 #ifndef HAVE_PREAD
 #define pread(fd, buf, count, offset) \
         ( \
diff -ruN dists/GeoIP-1.5.1/libGeoIP/GeoIPCity.h dev/GeoIP-1.5.1/libGeoIP/GeoIPCity.h
--- dists/GeoIP-1.5.1/libGeoIP/GeoIPCity.h	2013-03-23 03:26:09.000000000 +0100
+++ dev/GeoIP-1.5.1/libGeoIP/GeoIPCity.h	2013-07-19 16:23:58.000000000 +0200
@@ -48,22 +48,22 @@
         int netmask;	
 } GeoIPRecord;
 
-GeoIPRecord * GeoIP_record_by_ipnum (GeoIP* gi, unsigned long ipnum);
-GeoIPRecord * GeoIP_record_by_addr (GeoIP* gi, const char *addr);
-GeoIPRecord * GeoIP_record_by_name (GeoIP* gi, const char *host);
-
-GeoIPRecord * GeoIP_record_by_ipnum_v6 (GeoIP* gi, geoipv6_t ipnum);
-GeoIPRecord * GeoIP_record_by_addr_v6 (GeoIP* gi, const char *addr);
-GeoIPRecord * GeoIP_record_by_name_v6 (GeoIP* gi, const char *host);
+GEOIP_API GeoIPRecord * GeoIP_record_by_ipnum (GeoIP* gi, unsigned long ipnum);
+GEOIP_API GeoIPRecord * GeoIP_record_by_addr (GeoIP* gi, const char *addr);
+GEOIP_API GeoIPRecord * GeoIP_record_by_name (GeoIP* gi, const char *host);
+
+GEOIP_API GeoIPRecord * GeoIP_record_by_ipnum_v6 (GeoIP* gi, geoipv6_t ipnum);
+GEOIP_API GeoIPRecord * GeoIP_record_by_addr_v6 (GeoIP* gi, const char *addr);
+GEOIP_API GeoIPRecord * GeoIP_record_by_name_v6 (GeoIP* gi, const char *host);
 
-int GeoIP_record_id_by_addr (GeoIP* gi, const char *addr);
-int GeoIP_record_id_by_addr_v6 (GeoIP* gi, const char *addr);
+GEOIP_API int GeoIP_record_id_by_addr (GeoIP* gi, const char *addr);
+GEOIP_API int GeoIP_record_id_by_addr_v6 (GeoIP* gi, const char *addr);
 
-int GeoIP_init_record_iter (GeoIP* gi);
+GEOIP_API int GeoIP_init_record_iter (GeoIP* gi);
 /* returns 0 on success, 1 on failure */
-int GeoIP_next_record (GeoIP* gi, GeoIPRecord **gir, int *record_iter);
+GEOIP_API int GeoIP_next_record (GeoIP* gi, GeoIPRecord **gir, int *record_iter);
 
-void GeoIPRecord_delete (GeoIPRecord *gir);
+GEOIP_API void GeoIPRecord_delete (GeoIPRecord *gir);
 
 /* NULL on failure otherwise a malloced string in utf8 */
 /* char * GeoIP_iso_8859_1__utf8(const char *); */
diff -ruN dists/GeoIP-1.5.1/libGeoIP/Makefile.vc dev/GeoIP-1.5.1/libGeoIP/Makefile.vc
--- dists/GeoIP-1.5.1/libGeoIP/Makefile.vc	2013-03-23 03:26:09.000000000 +0100
+++ dev/GeoIP-1.5.1/libGeoIP/Makefile.vc	2013-07-19 16:47:45.000000000 +0200
@@ -1,29 +1,42 @@
 #NMAKE makefile for Windows developers. 
-#Produces a static library (GeoIP.lib). 
+##Produces a static library (GeoIP.lib). 
+#Produces a DLL (GeoIP.dll) and library (GeoIP.lib).
  
 COMPILER=cl 
  
-CFLAGS=-DWIN32 -MD -nologo 
+CFLAGS=-DWIN32 -DGEOIP_EXPORTS -MD -nologo 
  
 GEOIPINC = -I..\libGeoIP 
  
-CC1 = $(COMPILER) $(CFLAGS) $(GEOIPINC) -DGEOIPDATADIR=\"$(GEOIPDATADIR)\" 
+CC1 = $(COMPILER) $(CFLAGS) $(GEOIPINC) -DGEOIPDATADIR=\"$(GEOIPDATADIR)\" -DPACKAGE_VERSION=\"1.5.1\"
  
-OBJS=GeoIP.obj GeoIPCity.obj regionName.obj md5.obj timeZone.obj
+LINKER=link
+
+LDFLAGS=/DLL /nologo /subsystem:console
+
+LD1 = $(LINKER) $(LDFLAGS)
+
+OBJS=GeoIP.obj GeoIPCity.obj GeoIP_depreciated.obj regionName.obj md5.obj timeZone.obj pread.obj
  
-EXTRA_LIBS= advapi32.lib wsock32.lib 
+EXTRA_LIBS= ws2_32.lib
  
 AR=lib 
  
-GeoIP.lib:  GeoIP.obj GeoIPCity.obj regionName.obj md5.obj timeZone.obj
-   $(AR) -nologo $(OBJS) $(EXTRA_LIBS) /OUT:GeoIP.lib 
+#GeoIP.lib:  GeoIP.obj GeoIPCity.obj regionName.obj md5.obj timeZone.obj pread.obj
+#   $(AR) -nologo $(OBJS) $(EXTRA_LIBS) /OUT:GeoIP.lib 
  
+GeoIP.dll GeoIP.lib: $(OBJS)
+   $(LD1) $(OBJS) $(EXTRA_LIBS) /out:GeoIP.dll /implib:GeoIP.lib
+
 GeoIP.obj: GeoIP.c 
    $(CC1) -c GeoIP.c $(GEOIPINC) 
  
 GeoIPCity.obj: GeoIPCity.c 
    $(CC1) -c GeoIPCity.c $(GEOIPINC)
 
+GeoIP_depreciated.obj: GeoIP_depreciated.c 
+   $(CC1) -c GeoIP_depreciated.c $(GEOIPINC)
+
 regionName.obj: regionName.c 
    $(CC1) -c regionName.c $(GEOIPINC)
 
@@ -32,3 +45,6 @@
 
 timeZone.obj: timeZone.c 
    $(CC1) -c timeZone.c $(GEOIPINC)
+
+pread.obj: pread.c 
+   $(CC1) -c pread.c $(GEOIPINC)
diff -ruN dists/GeoIP-1.5.1/libGeoIP/pread.c dev/GeoIP-1.5.1/libGeoIP/pread.c
--- dists/GeoIP-1.5.1/libGeoIP/pread.c	1970-01-01 01:00:00.000000000 +0100
+++ dev/GeoIP-1.5.1/libGeoIP/pread.c	2013-07-19 15:37:44.000000000 +0200
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2013  Internet Systems Consortium, Inc. ("ISC")
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <windows.h>
+#include <io.h>
+
+#include "pread.h"
+
+CRITICAL_SECTION preadsc;
+
+#ifdef _WIN64
+int pread(int fd, void *buf, unsigned int nbyte, __int64 offset)
+{
+	int cc = -1;
+	__int64 prev = (__int64)-1L;
+
+	EnterCriticalSection(&preadsc);
+	prev = _lseeki64(fd, 0L, SEEK_CUR);
+	if (prev == (__int64)-1L)
+		goto done;
+	if (_lseeki64(fd, offset, SEEK_SET) != offset)
+		goto done;
+	cc = _read(fd, buf, nbyte);
+
+done:
+	if (prev != (__int64)-1L)
+		(void)_lseeki64(fd, prev, SEEK_SET);
+	LeaveCriticalSection(&preadsc);
+
+	return cc;
+}
+#else
+int pread(int fd, void *buf, unsigned int nbyte, long offset)
+{
+	int cc = -1;
+	long prev = -1L;
+
+	EnterCriticalSection(&preadsc);
+	prev = _lseek(fd, 0L, SEEK_CUR);
+	if (prev == -1L)
+		goto done;
+	if (_lseek(fd, offset, SEEK_SET) != offset)
+		goto done;
+	cc = _read(fd, buf, nbyte);
+
+done:
+	if (prev != -1L)
+		(void)_lseek(fd, prev, SEEK_SET);
+	LeaveCriticalSection(&preadsc);
+
+	return cc;
+}
+#endif
+
+BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved )
+{
+	if (fdwReason == DLL_PROCESS_ATTACH)
+		InitializeCriticalSection(&preadsc);
+	return TRUE;
+}
diff -ruN dists/GeoIP-1.5.1/libGeoIP/pread.h dev/GeoIP-1.5.1/libGeoIP/pread.h
--- dists/GeoIP-1.5.1/libGeoIP/pread.h	1970-01-01 01:00:00.000000000 +0100
+++ dev/GeoIP-1.5.1/libGeoIP/pread.h	2013-07-19 15:39:01.000000000 +0200
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2013  Internet Systems Consortium, Inc. ("ISC")
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifdef _WIN64
+typedef __int64 ssize_t;
+
+int pread(int fd, void *buf, unsigned int nbyte, __int64 offset);
+#else
+typedef int ssize_t;
+
+int pread(int fd, void *buf, unsigned int nbyte, long offset);
+#endif
+
+#define HAVE_PREAD
+
+extern CRITICAL_SECTION preadsc;
diff -ruN dists/GeoIP-1.5.1/libGeoIP/regionName.c dev/GeoIP-1.5.1/libGeoIP/regionName.c
--- dists/GeoIP-1.5.1/libGeoIP/regionName.c	2013-03-23 03:26:09.000000000 +0100
+++ dev/GeoIP-1.5.1/libGeoIP/regionName.c	2013-07-19 16:37:56.000000000 +0200
@@ -1,3 +1,5 @@
+#include "GeoIP.h"
+
 #include <string.h>
 #include <stdio.h>
 
diff -ruN dists/GeoIP-1.5.1/libGeoIP/timeZone.c dev/GeoIP-1.5.1/libGeoIP/timeZone.c
--- dists/GeoIP-1.5.1/libGeoIP/timeZone.c	2013-03-23 03:26:09.000000000 +0100
+++ dev/GeoIP-1.5.1/libGeoIP/timeZone.c	2013-07-19 17:22:44.000000000 +0200
@@ -1,4 +1,7 @@
+#include "GeoIP.h"
+
 #include <string.h> 
+
 const char* GeoIP_time_zone_by_country_and_region(const char * country,const char * region) {
   const char* timezone = NULL;
   if (country == NULL) {
diff -ruN dists/GeoIP-1.5.1/test/Makefile.vc dev/GeoIP-1.5.1/test/Makefile.vc
--- dists/GeoIP-1.5.1/test/Makefile.vc	2013-03-23 03:26:09.000000000 +0100
+++ dev/GeoIP-1.5.1/test/Makefile.vc	2013-07-19 16:48:55.000000000 +0200
@@ -9,7 +9,7 @@
  
 GEOIPINC = -I..\libGeoIP 
  
-CC1 = $(COMPILER) $(CFLAGS) $(GEOIPINC) 
+CC1 = $(COMPILER) $(CFLAGS) $(GEOIPINC) -DSRCDIR=\"../\"
  
 GEOIPLIB = ..\libGeoIP\GeoIP.lib 
  
diff -ruN dists/GeoIP-1.5.1/test/benchmark.c dev/GeoIP-1.5.1/test/benchmark.c
--- dists/GeoIP-1.5.1/test/benchmark.c	2013-03-23 03:26:09.000000000 +0100
+++ dev/GeoIP-1.5.1/test/benchmark.c	2013-07-19 16:26:23.000000000 +0200
@@ -81,7 +81,7 @@
 void testgeoiporg(int flags, const char *msg, int numlookups)
 {
     GeoIP *i = NULL;
-    GeoIPRegion *i3 = NULL;
+    char *i3 = NULL;
     int i4 = 0;
     int i2 = 0;
     double t = 0;