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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
|
--- pecl/geoip/trunk/geoip.c 2015/02/15 15:08:09 335947
+++ pecl/geoip/trunk/geoip.c 2015/02/15 17:56:49 335948
@@ -129,11 +129,19 @@
{
if (stage == PHP_INI_STAGE_RUNTIME || stage == PHP_INI_STAGE_HTACCESS) {
GEOIP_G(set_runtime_custom_directory) = 1;
+#if PHP_MAJOR_VERSION >= 7
+ geoip_change_custom_directory(new_value->val);
+#else
geoip_change_custom_directory(new_value);
+#endif
return SUCCESS;
}
+#if PHP_MAJOR_VERSION >= 7
+ return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
+#else
return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
+#endif
}
/* }}} */
#endif
@@ -250,7 +258,7 @@
/* {{{ proto boolean geoip_db_avail( [ int database ] ) */
PHP_FUNCTION(geoip_db_avail)
{
- long edition;
+ zend_long edition;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &edition) == FAILURE) {
return;
@@ -269,7 +277,7 @@
/* {{{ proto string geoip_db_filename( [ int database ] ) */
PHP_FUNCTION(geoip_db_filename)
{
- long edition;
+ zend_long edition;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &edition) == FAILURE) {
return;
@@ -282,7 +290,11 @@
}
if (NULL != GeoIPDBFileName[edition])
+#if PHP_MAJOR_VERSION >= 7
+ RETURN_STRING(GeoIPDBFileName[edition]);
+#else
RETURN_STRING(GeoIPDBFileName[edition], 1);
+#endif
}
/* }}} */
@@ -297,16 +309,31 @@
{
if (NULL != GeoIPDBDescription[i])
{
+#if PHP_MAJOR_VERSION >= 7
+ zval real_row;
+ zval *row = &real_row;
+
+ array_init(row);
+#else
zval *row;
ALLOC_INIT_ZVAL(row);
array_init(row);
+#endif
add_assoc_bool(row, "available", GeoIP_db_avail(i));
if (GeoIPDBDescription[i]) {
+#if PHP_MAJOR_VERSION >= 7
+ add_assoc_string(row, "description", (char *)GeoIPDBDescription[i]);
+#else
add_assoc_string(row, "description", (char *)GeoIPDBDescription[i], 1);
+#endif
}
if (GeoIPDBFileName[i]) {
+#if PHP_MAJOR_VERSION >= 7
+ add_assoc_string(row, "filename", GeoIPDBFileName[i]);
+#else
add_assoc_string(row, "filename", GeoIPDBFileName[i], 1);
+#endif
}
add_index_zval(return_value, i, row);
@@ -321,7 +348,7 @@
{
GeoIP * gi;
char * db_info;
- long edition = GEOIP_COUNTRY_EDITION;
+ zend_long edition = GEOIP_COUNTRY_EDITION;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &edition) == FAILURE) {
return;
@@ -346,12 +373,45 @@
db_info = GeoIP_database_info(gi);
GeoIP_delete(gi);
+#if PHP_MAJOR_VERSION >= 7
+ RETVAL_STRING(db_info);
+#else
RETVAL_STRING(db_info, 1);
+#endif
free(db_info);
}
/* }}} */
/* {{{ */
+#if PHP_MAJOR_VERSION >= 7
+#define GEOIPDEF(php_func, c_func, db_type) \
+ PHP_FUNCTION(php_func) \
+ { \
+ GeoIP * gi; \
+ char * hostname = NULL; \
+ const char * return_code; \
+ size_t arglen; \
+ \
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) { \
+ return; \
+ } \
+ \
+ if (GeoIP_db_avail(db_type)) { \
+ gi = GeoIP_open_type(db_type, GEOIP_STANDARD); \
+ } else { \
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[db_type]); \
+ return; \
+ } \
+ \
+ return_code = c_func(gi, hostname); \
+ GeoIP_delete(gi); \
+ if (return_code == NULL) { \
+ RETURN_FALSE; \
+ } \
+ RETURN_STRING((char*)return_code); \
+ \
+ }
+#else
#define GEOIPDEF(php_func, c_func, db_type) \
PHP_FUNCTION(php_func) \
{ \
@@ -379,6 +439,7 @@
RETURN_STRING((char*)return_code, 1); \
\
}
+#endif
#include "geoip.def"
#undef GEOIPDEF
/* }}} */
@@ -390,7 +451,11 @@
GeoIP * gi;
char * hostname = NULL;
int id;
+#if PHP_MAJOR_VERSION >= 7
+ size_t arglen;
+#else
int arglen;
+#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
return;
@@ -408,7 +473,11 @@
if (id == 0) {
RETURN_FALSE;
}
+#if PHP_MAJOR_VERSION >= 7
+ RETURN_STRING((char *)GeoIP_country_continent[id]);
+#else
RETURN_STRING((char *)GeoIP_country_continent[id], 1);
+#endif
}
/* }}} */
@@ -419,7 +488,11 @@
GeoIP * gi;
char * hostname = NULL;
char * org;
+#if PHP_MAJOR_VERSION >= 7
+ size_t arglen;
+#else
int arglen;
+#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
return;
@@ -437,7 +510,11 @@
if (org == NULL) {
RETURN_FALSE;
}
+#if PHP_MAJOR_VERSION >= 7
+ RETVAL_STRING(org);
+#else
RETVAL_STRING(org, 1);
+#endif
free(org);
}
/* }}} */
@@ -449,7 +526,11 @@
GeoIP * gi;
char * hostname = NULL;
char * org;
+#if PHP_MAJOR_VERSION >= 7
+ size_t arglen;
+#else
int arglen;
+#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
return;
@@ -467,7 +548,11 @@
if (org == NULL) {
RETURN_FALSE;
}
+#if PHP_MAJOR_VERSION >= 7
+ RETVAL_STRING(org);
+#else
RETVAL_STRING(org, 1);
+#endif
free(org);
}
/* }}} */
@@ -479,7 +564,11 @@
GeoIP * gi;
char * hostname = NULL;
char * org;
+#if PHP_MAJOR_VERSION >= 7
+ size_t arglen;
+#else
int arglen;
+#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
return;
@@ -497,7 +586,11 @@
if (org == NULL) {
RETURN_FALSE;
}
+#if PHP_MAJOR_VERSION >= 7
+ RETVAL_STRING(org);
+#else
RETVAL_STRING(org, 1);
+#endif
free(org);
}
/* }}} */
@@ -510,7 +603,11 @@
GeoIP * gi;
char * hostname = NULL;
char * org;
+#if PHP_MAJOR_VERSION >= 7
+ size_t arglen;
+#else
int arglen;
+#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
return;
@@ -528,7 +625,11 @@
if (org == NULL) {
RETURN_FALSE;
}
+#if PHP_MAJOR_VERSION >= 7
+ RETVAL_STRING(org);
+#else
RETVAL_STRING(org, 1);
+#endif
free(org);
}
/* }}} */
@@ -540,7 +641,11 @@
{
GeoIP * gi;
char * hostname = NULL;
+#if PHP_MAJOR_VERSION >= 7
+ size_t arglen;
+#else
int arglen;
+#endif
GeoIPRecord * gir;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
@@ -566,15 +671,27 @@
}
array_init(return_value);
-#if LIBGEOIP_VERSION >= 1004003
+#if PHP_MAJOR_VERSION >= 7
+# if LIBGEOIP_VERSION >= 1004003
+ add_assoc_string(return_value, "continent_code", (gir->continent_code == NULL) ? "" : gir->continent_code);
+# endif
+ add_assoc_string(return_value, "country_code", (gir->country_code == NULL) ? "" : gir->country_code);
+ add_assoc_string(return_value, "country_code3", (gir->country_code3 == NULL) ? "" : gir->country_code3);
+ add_assoc_string(return_value, "country_name", (gir->country_name == NULL) ? "" : gir->country_name);
+ add_assoc_string(return_value, "region", (gir->region == NULL) ? "" : gir->region);
+ add_assoc_string(return_value, "city", (gir->city == NULL) ? "" : gir->city);
+ add_assoc_string(return_value, "postal_code", (gir->postal_code == NULL) ? "" : gir->postal_code);
+#else
+# if LIBGEOIP_VERSION >= 1004003
add_assoc_string(return_value, "continent_code", (gir->continent_code == NULL) ? "" : gir->continent_code, 1);
-#endif
+# endif
add_assoc_string(return_value, "country_code", (gir->country_code == NULL) ? "" : gir->country_code, 1);
add_assoc_string(return_value, "country_code3", (gir->country_code3 == NULL) ? "" : gir->country_code3, 1);
add_assoc_string(return_value, "country_name", (gir->country_name == NULL) ? "" : gir->country_name, 1);
add_assoc_string(return_value, "region", (gir->region == NULL) ? "" : gir->region, 1);
add_assoc_string(return_value, "city", (gir->city == NULL) ? "" : gir->city, 1);
add_assoc_string(return_value, "postal_code", (gir->postal_code == NULL) ? "" : gir->postal_code, 1);
+#endif
add_assoc_double(return_value, "latitude", gir->latitude);
add_assoc_double(return_value, "longitude", gir->longitude);
#if LIBGEOIP_VERSION >= 1004005
@@ -594,7 +711,11 @@
{
GeoIP * gi;
char * hostname = NULL;
+#if PHP_MAJOR_VERSION >= 7
+ size_t arglen;
+#else
int arglen;
+#endif
int netspeed;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
@@ -620,7 +741,11 @@
{
GeoIP * gi;
char * hostname = NULL;
+#if PHP_MAJOR_VERSION >= 7
+ size_t arglen;
+#else
int arglen;
+#endif
GeoIPRegion * region;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
@@ -646,9 +771,14 @@
}
array_init(return_value);
+#if PHP_MAJOR_VERSION >= 7
+ add_assoc_string(return_value, "country_code", region->country_code);
+ add_assoc_string(return_value, "region", region->region);
+#else
add_assoc_string(return_value, "country_code", region->country_code, 1);
add_assoc_string(return_value, "region", region->region, 1);
-
+#endif
+
GeoIPRegion_delete(region);
}
/* }}} */
@@ -660,7 +790,11 @@
GeoIP * gi;
char * hostname = NULL;
char * isp;
+#if PHP_MAJOR_VERSION >= 7
+ size_t arglen;
+#else
int arglen;
+#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
return;
@@ -678,7 +812,11 @@
if (isp == NULL) {
RETURN_FALSE;
}
+#if PHP_MAJOR_VERSION >= 7
+ RETVAL_STRING(isp);
+#else
RETVAL_STRING(isp, 1);
+#endif
free(isp);
}
@@ -690,7 +828,11 @@
char * country_code = NULL;
char * region_code = NULL;
const char * region_name;
+#if PHP_MAJOR_VERSION >= 7
+ size_t countrylen, regionlen;
+#else
int countrylen, regionlen;
+#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &country_code, &countrylen, ®ion_code, ®ionlen) == FAILURE) {
return;
@@ -705,7 +847,11 @@
if (region_name == NULL) {
RETURN_FALSE;
}
+#if PHP_MAJOR_VERSION >= 7
+ RETURN_STRING((char*)region_name);
+#else
RETURN_STRING((char*)region_name, 1);
+#endif
}
/* }}} */
#endif
@@ -718,7 +864,11 @@
char * country = NULL;
char * region = NULL;
const char * timezone;
+#if PHP_MAJOR_VERSION >= 7
+ size_t countrylen, arg2len;
+#else
int countrylen, arg2len;
+#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &country, &countrylen, ®ion, &arg2len) == FAILURE) {
return;
@@ -733,7 +883,11 @@
if (timezone == NULL) {
RETURN_FALSE;
}
+#if PHP_MAJOR_VERSION >= 7
+ RETURN_STRING((char*)timezone);
+#else
RETURN_STRING((char*)timezone, 1);
+#endif
}
/* }}} */
#endif
@@ -744,7 +898,11 @@
PHP_FUNCTION(geoip_setup_custom_directory)
{
char * dir = NULL;
+#if PHP_MAJOR_VERSION >= 7
+ size_t dirlen;
+#else
int dirlen;
+#endif
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &dir, &dirlen) == FAILURE) {
return;
--- pecl/geoip/trunk/php_geoip.h 2015/02/15 15:08:09 335947
+++ pecl/geoip/trunk/php_geoip.h 2015/02/15 17:56:49 335948
@@ -26,6 +26,10 @@
#define PHP_GEOIP_VERSION "1.1.0"
+#if PHP_MAJOR_VERSION < 7
+typedef long zend_long;
+#endif
+
#ifdef PHP_WIN32
#define PHP_GEOIP_API __declspec(dllexport)
#else
|