summaryrefslogtreecommitdiffstats
path: root/8.patch
blob: 94126f748bd3f13359c809381b335e275ffcf960 (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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
From 570306a94ee8caa1af9c817c5f991cbfee9003d3 Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@remirepo.net>
Date: Thu, 24 Sep 2020 09:34:59 +0200
Subject: [PATCH] adapt for library version 8.1.0

---
 config.m4     |  17 ++++--
 ip2location.c | 146 +++++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 128 insertions(+), 35 deletions(-)

diff --git a/config.m4 b/config.m4
index 7c3ae1d..5abb4fa 100644
--- a/config.m4
+++ b/config.m4
@@ -38,16 +38,25 @@ if test "$PHP_IP2LOCATION" != "no"; then
 
   # --with-ip2location -> check for lib and symbol presence
   LIBNAME=IP2Location # you may want to change this
-  LIBSYMBOL=IP2Location_open_mem # you most likely want to change this
+  LIBSYMBOLOLD=IP2Location_open_mem
+  LIBSYMBOLNEW=IP2Location_set_lookup_mode
 
-  PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
+  PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOLNEW,
   [
     PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $IP2LOCATION_DIR/lib, IP2LOCATION_SHARED_LIBADD)
     AC_DEFINE(HAVE_IPLOCATIONLIB,1,[ ])
   ],[
-    AC_MSG_ERROR([wrong ip2location, lib version >= 6.x.x is required or library not found])
+    PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOLOLD,
+    [
+      PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $IP2LOCATION_DIR/lib, IP2LOCATION_SHARED_LIBADD)
+      AC_DEFINE(HAVE_IPLOCATIONLIB,1,[ ])
+    ],[
+      AC_MSG_ERROR([wrong ip2location, lib version >= 6.x.x is required or library not found])
+    ],[
+      -L$IP2LOCATION_DIR/$PHP_LIBDIR
+    ])
   ],[
-    -L$IP2LOCATION_DIR/$PHP_LIBDIR 
+    -L$IP2LOCATION_DIR/$PHP_LIBDIR
   ])
 
   PHP_SUBST(IP2LOCATION_SHARED_LIBADD)
diff --git a/ip2location.c b/ip2location.c
index e415e68..7996b57 100644
--- a/ip2location.c
+++ b/ip2location.c
@@ -158,7 +158,11 @@ PHP_FUNCTION(ip2location_open_mem)
 	}
 	/*Shared memory method is not supported*/
 	if( method == IP2LOCATION_FILE_IO || method == IP2LOCATION_CACHE_MEMORY || method == IP2LOCATION_SHARED_MEMORY ){
+#if API_VERSION_NUMERIC >= 80100
+		if(IP2Location_set_lookup_mode(IP2LOCATION_G(ip2location_ptr), method) == -1){
+#else
 		if(IP2Location_open_mem(IP2LOCATION_G(ip2location_ptr), method) == -1){
+#endif
 			RETURN_FALSE;
 		}
 		else{
@@ -351,7 +355,7 @@ PHP_FUNCTION(ip2location_get_domain)
  * Returns ip address's zipcode information */
 PHP_FUNCTION(ip2location_get_zipcode)
 {
-	char *ip_address;
+	char *ip_address, *ret;
 	size_t ip_len;
 	IP2LocationRecord *record = NULL;
 
@@ -361,10 +365,15 @@ PHP_FUNCTION(ip2location_get_zipcode)
 		return;
 	}
 	record = IP2Location_get_zipcode(IP2LOCATION_G(ip2location_ptr), ip_address);
+#if API_VERSION_NUMERIC >= 80100
+	ret = record->zip_code;
+#else
+	ret = record->zipcode;
+#endif
 #if PHP_MAJOR_VERSION >= 7
-	RETVAL_STRING(record->zipcode);
+	RETVAL_STRING(ret);
 #else
-	RETVAL_STRING(record->zipcode, 1);
+	RETVAL_STRING(ret, 1);
 #endif
 	IP2Location_free_record(record);
 }
@@ -374,7 +383,7 @@ PHP_FUNCTION(ip2location_get_zipcode)
  * Returns ip address's timezone information */
 PHP_FUNCTION(ip2location_get_timezone)
 {
-	char *ip_address;
+	char *ip_address, *ret;
 	size_t ip_len;
 	IP2LocationRecord *record = NULL;
 
@@ -384,20 +393,31 @@ PHP_FUNCTION(ip2location_get_timezone)
 		return;
 	}
 	record = IP2Location_get_timezone(IP2LOCATION_G(ip2location_ptr), ip_address);
+#if API_VERSION_NUMERIC >= 80100
+	ret = record->time_zone;
+#else
+	ret = record->timezone;
+#endif
 #if PHP_MAJOR_VERSION >= 7
-	RETVAL_STRING(record->timezone);
+	RETVAL_STRING(ret);
 #else
-	RETVAL_STRING(record->timezone, 1);
+	RETVAL_STRING(ret, 1);
 #endif
 	IP2Location_free_record(record);
 }
 /* }}} */
 
+
+#if API_VERSION_NUMERIC >= 80100
+/* see https://github.com/chrislim2888/IP2Location-C-Library/issues/37 */
+IP2LocationRecord *IP2Location_get_netspeed(IP2Location *handler, char *ip);
+#endif
+
 /* {{{ ip2location_get_netspeed("ip_address") 
  * Returns ip address's netspeed information */
 PHP_FUNCTION(ip2location_get_netspeed)
 {
-	char *ip_address;
+	char *ip_address, *ret;
 	size_t ip_len;
 	IP2LocationRecord *record = NULL;
 
@@ -406,11 +426,17 @@ PHP_FUNCTION(ip2location_get_netspeed)
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ip_address, &ip_len) == FAILURE) {
 		return;
 	}
+
 	record = IP2Location_get_netspeed(IP2LOCATION_G(ip2location_ptr), ip_address);
+#if API_VERSION_NUMERIC >= 80100
+	ret = record->net_speed;
+#else
+	ret = record->netspeed;
+#endif
 #if PHP_MAJOR_VERSION >= 7
-	RETVAL_STRING(record->netspeed);
+	RETVAL_STRING(ret);
 #else
-	RETVAL_STRING(record->netspeed, 1);
+	RETVAL_STRING(ret, 1);
 #endif
 	IP2Location_free_record(record);
 }
@@ -420,7 +446,7 @@ PHP_FUNCTION(ip2location_get_netspeed)
  * Returns ip address's iddcode information */
 PHP_FUNCTION(ip2location_get_iddcode)
 {
-	char *ip_address;
+	char *ip_address, *ret;
 	size_t ip_len;
 	IP2LocationRecord *record = NULL;
 
@@ -430,10 +456,15 @@ PHP_FUNCTION(ip2location_get_iddcode)
 		return;
 	}
 	record = IP2Location_get_iddcode(IP2LOCATION_G(ip2location_ptr), ip_address);
+#if API_VERSION_NUMERIC >= 80100
+	ret = record->idd_code;
+#else
+	ret = record->iddcode;
+#endif
 #if PHP_MAJOR_VERSION >= 7
-	RETVAL_STRING(record->iddcode);
+	RETVAL_STRING(ret);
 #else
-	RETVAL_STRING(record->iddcode, 1);
+	RETVAL_STRING(ret, 1);
 #endif
 	IP2Location_free_record(record);
 }
@@ -443,7 +474,7 @@ PHP_FUNCTION(ip2location_get_iddcode)
  * Returns ip address's areacode  information */
 PHP_FUNCTION(ip2location_get_areacode)
 {
-	char *ip_address;
+	char *ip_address, *ret;
 	size_t ip_len;
 	IP2LocationRecord *record = NULL;
 
@@ -453,10 +484,15 @@ PHP_FUNCTION(ip2location_get_areacode)
 		return;
 	}
 	record = IP2Location_get_areacode(IP2LOCATION_G(ip2location_ptr), ip_address);
+#if API_VERSION_NUMERIC >= 80100
+	ret = record->area_code;
+#else
+	ret = record->areacode;
+#endif
 #if PHP_MAJOR_VERSION >= 7
-	RETVAL_STRING(record->areacode);
+	RETVAL_STRING(ret);
 #else
-	RETVAL_STRING(record->areacode, 1);
+	RETVAL_STRING(ret, 1);
 #endif
 	IP2Location_free_record(record);
 }
@@ -466,7 +502,7 @@ PHP_FUNCTION(ip2location_get_areacode)
  * Returns ip address's weatherstationcode information */
 PHP_FUNCTION(ip2location_get_weatherstationcode)
 {
-	char *ip_address;
+	char *ip_address, *ret;
 	size_t ip_len;
 	IP2LocationRecord *record = NULL;
 
@@ -476,10 +512,15 @@ PHP_FUNCTION(ip2location_get_weatherstationcode)
 		return;
 	}
 	record = IP2Location_get_weatherstationcode(IP2LOCATION_G(ip2location_ptr), ip_address);
+#if API_VERSION_NUMERIC >= 80100
+	ret = record->weather_station_code;
+#else
+	ret = record->weatherstationcode;
+#endif
 #if PHP_MAJOR_VERSION >= 7
-	RETVAL_STRING(record->weatherstationcode);
+	RETVAL_STRING(ret);
 #else
-	RETVAL_STRING(record->weatherstationcode, 1);
+	RETVAL_STRING(ret, 1);
 #endif
 	IP2Location_free_record(record);
 }
@@ -489,7 +530,7 @@ PHP_FUNCTION(ip2location_get_weatherstationcode)
  * Returns ip address's weatherstationname information */
 PHP_FUNCTION(ip2location_get_weatherstationname)
 {
-	char *ip_address;
+	char *ip_address, *ret;
 	size_t ip_len;
 	IP2LocationRecord *record = NULL;
 
@@ -499,10 +540,15 @@ PHP_FUNCTION(ip2location_get_weatherstationname)
 		return;
 	}
 	record = IP2Location_get_weatherstationname(IP2LOCATION_G(ip2location_ptr), ip_address);
+#if API_VERSION_NUMERIC >= 80100
+	ret = record->weather_station_name;
+#else
+	ret = record->weatherstationname;
+#endif
 #if PHP_MAJOR_VERSION >= 7
-	RETVAL_STRING(record->weatherstationname);
+	RETVAL_STRING(ret);
 #else
-	RETVAL_STRING(record->weatherstationname, 1);
+	RETVAL_STRING(ret, 1);
 #endif
 	IP2Location_free_record(record);
 }
@@ -558,7 +604,7 @@ PHP_FUNCTION(ip2location_get_mnc)
  * Returns ip address's mobilebrand information */
 PHP_FUNCTION(ip2location_get_mobilebrand)
 {
-	char *ip_address;
+	char *ip_address, *ret;
 	size_t ip_len;
 	IP2LocationRecord *record = NULL;
 
@@ -568,10 +614,15 @@ PHP_FUNCTION(ip2location_get_mobilebrand)
 		return;
 	}
 	record = IP2Location_get_mobilebrand(IP2LOCATION_G(ip2location_ptr), ip_address);
+#if API_VERSION_NUMERIC >= 80100
+	ret = record->mobile_brand;
+#else
+	ret = record->mobilebrand;
+#endif
 #if PHP_MAJOR_VERSION >= 7
-	RETVAL_STRING(record->mobilebrand);
+	RETVAL_STRING(ret);
 #else
-	RETVAL_STRING(record->mobilebrand, 1);
+	RETVAL_STRING(ret, 1);
 #endif
 	IP2Location_free_record(record);
 }
@@ -600,7 +651,7 @@ PHP_FUNCTION(ip2location_get_elevation)
  * Returns ip address's internet connection usagetype information */
 PHP_FUNCTION(ip2location_get_usagetype)
 {
-	char *ip_address;
+	char *ip_address, *ret;
 	size_t ip_len;
 	IP2LocationRecord *record = NULL;
 
@@ -610,10 +661,15 @@ PHP_FUNCTION(ip2location_get_usagetype)
 		return;
 	}
 	record = IP2Location_get_usagetype(IP2LOCATION_G(ip2location_ptr), ip_address);
+#if API_VERSION_NUMERIC >= 80100
+	ret = record->usage_type;
+#else
+	ret = record->usagetype;
+#endif
 #if PHP_MAJOR_VERSION >= 7
-	RETVAL_STRING(record->usagetype);
+	RETVAL_STRING(ret);
 #else
-	RETVAL_STRING(record->usagetype, 1);
+	RETVAL_STRING(ret, 1);
 #endif
 	IP2Location_free_record(record);
 }
@@ -641,6 +697,17 @@ PHP_FUNCTION(ip2location_get_all)
 	add_assoc_string(return_value, "city",record->city);
 	add_assoc_string(return_value, "isp",record->isp);
 	add_assoc_string(return_value, "domain",record->domain);
+#if API_VERSION_NUMERIC >= 80100
+	add_assoc_string(return_value, "zipcode",record->zip_code);
+	add_assoc_string(return_value, "timezone",record->time_zone);
+	add_assoc_string(return_value, "netspeed",record->net_speed);
+	add_assoc_string(return_value, "iddcode",record->idd_code);
+	add_assoc_string(return_value, "areacode",record->area_code);
+	add_assoc_string(return_value, "weatherstationcode",record->weather_station_code);
+	add_assoc_string(return_value, "weatherstationname",record->weather_station_name);
+	add_assoc_string(return_value, "mobilebrand",record->mobile_brand);
+	add_assoc_string(return_value, "usagetype",record->usage_type);
+#else
 	add_assoc_string(return_value, "zipcode",record->zipcode);
 	add_assoc_string(return_value, "timezone",record->timezone);
 	add_assoc_string(return_value, "netspeed",record->netspeed);
@@ -648,10 +715,11 @@ PHP_FUNCTION(ip2location_get_all)
 	add_assoc_string(return_value, "areacode",record->areacode);
 	add_assoc_string(return_value, "weatherstationcode",record->weatherstationcode);
 	add_assoc_string(return_value, "weatherstationname",record->weatherstationname);
-	add_assoc_string(return_value, "mcc",record->mcc);
-	add_assoc_string(return_value, "mnc",record->mnc);
 	add_assoc_string(return_value, "mobilebrand",record->mobilebrand);
 	add_assoc_string(return_value, "usagetype",record->usagetype);
+#endif
+	add_assoc_string(return_value, "mcc",record->mcc);
+	add_assoc_string(return_value, "mnc",record->mnc);
 #else
 	add_assoc_string(return_value, "country_short", record->country_short, 1);
 	add_assoc_string(return_value, "country_long", record->country_long, 1);
@@ -659,6 +727,17 @@ PHP_FUNCTION(ip2location_get_all)
 	add_assoc_string(return_value, "city",record->city, 1);
 	add_assoc_string(return_value, "isp",record->isp, 1);
 	add_assoc_string(return_value, "domain",record->domain, 1);
+#if API_VERSION_NUMERIC >= 80100
+	add_assoc_string(return_value, "zipcode",record->zip_code, 1);
+	add_assoc_string(return_value, "timezone",record->time_zone, 1);
+	add_assoc_string(return_value, "netspeed",record->net_speed, 1);
+	add_assoc_string(return_value, "iddcode",record->idd_code, 1);
+	add_assoc_string(return_value, "areacode",record->area_code, 1);
+	add_assoc_string(return_value, "weatherstationcode",record->weather_station_code, 1);
+	add_assoc_string(return_value, "weatherstationname",record->weather_station_name, 1);
+	add_assoc_string(return_value, "mobilebrand",record->mobile_brand, 1);
+	add_assoc_string(return_value, "usagetype",record->usage_type, 1);
+#else
 	add_assoc_string(return_value, "zipcode",record->zipcode, 1);
 	add_assoc_string(return_value, "timezone",record->timezone, 1);
 	add_assoc_string(return_value, "netspeed",record->netspeed, 1);
@@ -666,11 +745,12 @@ PHP_FUNCTION(ip2location_get_all)
 	add_assoc_string(return_value, "areacode",record->areacode, 1);
 	add_assoc_string(return_value, "weatherstationcode",record->weatherstationcode, 1);
 	add_assoc_string(return_value, "weatherstationname",record->weatherstationname, 1);
-	add_assoc_string(return_value, "mcc",record->mcc, 1);
-	add_assoc_string(return_value, "mnc",record->mnc, 1);
 	add_assoc_string(return_value, "mobilebrand",record->mobilebrand, 1);
 	add_assoc_string(return_value, "usagetype",record->usagetype, 1);
 #endif
+	add_assoc_string(return_value, "mcc",record->mcc, 1);
+	add_assoc_string(return_value, "mnc",record->mnc, 1);
+#endif
 
 	add_assoc_double(return_value, "latitude",record->latitude );
 	add_assoc_double(return_value, "longitude",record->longitude );
@@ -701,7 +781,11 @@ PHP_FUNCTION(ip2location_delete_shm)
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") != SUCCESS) {
 		return;
 	}
+#if API_VERSION_NUMERIC >= 80100
+	IP2Location_clear_memory();
+#else
 	IP2Location_delete_shm();
+#endif
 }
 /* }}} */