Logoj0ke.net Open Build Service > Projects > internetx:php5:5.6.24:extensions > php5-geoip > geoip-1.0.8-ipv6-fix.patch
Sign Up | Log In

File geoip-1.0.8-ipv6-fix.patch of Package php5-geoip

x
 
1
diff -ruN geoip-1.0.8.orig/geoip.c geoip-1.0.8/geoip.c
2
--- geoip-1.0.8.orig/geoip.c    1970-01-01 10:13:08.000000000 +0100
3
+++ geoip-1.0.8/geoip.c 2012-11-13 11:58:08.000000000 +0100
4
@@ -42,8 +42,11 @@
5
    PHP_FE(geoip_database_info,   NULL)   
6
 #define GEOIPDEF(php_func, c_func, db_type) \
7
    PHP_FE(php_func,    NULL)
8
+#define GEOIPMULTIDEF(php_func, c_func, db_type, c_func_v6, db_type_v6) \
9
+        PHP_FE(php_func,        NULL)
10
 #include "geoip.def"
11
 #undef GEOIPDEF
12
+#undef GEOIPMULTIDEF
13
    PHP_FE(geoip_continent_code_by_name,   NULL)
14
    PHP_FE(geoip_org_by_name,   NULL)
15
    PHP_FE(geoip_record_by_name,   NULL)
16
@@ -119,11 +122,23 @@
17
    
18
    /* For database type constants */
19
    REGISTER_LONG_CONSTANT("GEOIP_COUNTRY_EDITION",     GEOIP_COUNTRY_EDITION,     CONST_CS | CONST_PERSISTENT);
20
+   REGISTER_LONG_CONSTANT("GEOIP_COUNTRY_EDITION_V4",  GEOIP_COUNTRY_EDITION,     CONST_CS | CONST_PERSISTENT);
21
+#if LIBGEOIP_VERSION >= 1004005
22
+   REGISTER_LONG_CONSTANT("GEOIP_COUNTRY_EDITION_V6",  GEOIP_COUNTRY_EDITION_V6,  CONST_CS | CONST_PERSISTENT);
23
+#endif
24
    REGISTER_LONG_CONSTANT("GEOIP_REGION_EDITION_REV0", GEOIP_REGION_EDITION_REV0, CONST_CS | CONST_PERSISTENT);
25
    REGISTER_LONG_CONSTANT("GEOIP_CITY_EDITION_REV0",   GEOIP_CITY_EDITION_REV0,   CONST_CS | CONST_PERSISTENT);
26
+   REGISTER_LONG_CONSTANT("GEOIP_CITY_EDITION_REV0_V4",   GEOIP_CITY_EDITION_REV0,   CONST_CS | CONST_PERSISTENT);
27
+#if LIBGEOIP_VERSION >= 1004005
28
+   REGISTER_LONG_CONSTANT("GEOIP_CITY_EDITION_REV0_V6",   GEOIP_CITY_EDITION_REV0_V6,   CONST_CS | CONST_PERSISTENT);
29
+#endif
30
    REGISTER_LONG_CONSTANT("GEOIP_ORG_EDITION",         GEOIP_ORG_EDITION,         CONST_CS | CONST_PERSISTENT);
31
    REGISTER_LONG_CONSTANT("GEOIP_ISP_EDITION",         GEOIP_ISP_EDITION,         CONST_CS | CONST_PERSISTENT);
32
    REGISTER_LONG_CONSTANT("GEOIP_CITY_EDITION_REV1",   GEOIP_CITY_EDITION_REV1,   CONST_CS | CONST_PERSISTENT);
33
+   REGISTER_LONG_CONSTANT("GEOIP_CITY_EDITION_REV1_V4", GEOIP_CITY_EDITION_REV1, CONST_CS | CONST_PERSISTENT);
34
+#if LIBGEOIP_VERSION >= 1004005
35
+   REGISTER_LONG_CONSTANT("GEOIP_CITY_EDITION_REV1_V6", GEOIP_CITY_EDITION_REV1_V6, CONST_CS | CONST_PERSISTENT);
36
+#endif
37
    REGISTER_LONG_CONSTANT("GEOIP_REGION_EDITION_REV1", GEOIP_REGION_EDITION_REV1, CONST_CS | CONST_PERSISTENT);
38
    REGISTER_LONG_CONSTANT("GEOIP_PROXY_EDITION",       GEOIP_PROXY_EDITION,       CONST_CS | CONST_PERSISTENT);
39
    REGISTER_LONG_CONSTANT("GEOIP_ASNUM_EDITION",       GEOIP_ASNUM_EDITION,       CONST_CS | CONST_PERSISTENT);
40
@@ -313,10 +328,50 @@
41
        RETURN_STRING((char*)return_code, 1); \
42
        \
43
    }
44
+
45
+#define GEOIPMULTIDEF(php_func, c_func, db_type, c_func_v6, db_type_v6) \
46
+        PHP_FUNCTION(php_func) \
47
+        { \
48
+                GeoIP * gi; \
49
+                char * hostname = NULL; \
50
+                const char * return_code; \
51
+                int arglen; \
52
+                \
53
+                if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) { \
54
+                        return; \
55
+                } \
56
+                \
57
+                if (GeoIP_db_avail(db_type)) { \
58
+                        gi = GeoIP_open_type(db_type, GEOIP_STANDARD); \
59
+                } else { \
60
+                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[db_type]); \
61
+                        return; \
62
+                } \
63
+                \
64
+                return_code = c_func(gi, hostname); \
65
+                GeoIP_delete(gi); \
66
+                if (return_code != NULL) { \
67
+                        RETURN_STRING((char*)return_code, 1); \
68
+                } \
69
+                if (GeoIP_db_avail(db_type_v6)) { \
70
+                        gi = GeoIP_open_type(db_type_v6, GEOIP_STANDARD); \
71
+                        return_code = c_func_v6(gi, hostname); \
72
+                        GeoIP_delete(gi); \
73
+                        if (return_code != NULL) { \
74
+                                RETURN_STRING((char*)return_code, 1); \
75
+                        } \
76
+                } \
77
+                php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Host %s not found", hostname); \
78
+                RETURN_FALSE; \
79
+                \
80
+        }
81
+
82
 #include "geoip.def"
83
 #undef GEOIPDEF
84
+#undef GEOIPMULTIDEF
85
 /* }}} */
86
 
87
+
88
 /* {{{ proto string geoip_continent_code_by_name( string hostname )
89
    Returns the Continent name found in the GeoIP Database */
90
 PHP_FUNCTION(geoip_continent_code_by_name)
91
@@ -339,6 +394,13 @@
92
 
93
    id = GeoIP_id_by_name(gi, hostname);
94
    GeoIP_delete(gi);
95
+#if LIBGEOIP_VERSION >= 1004005
96
+   if (id == 0 && GeoIP_db_avail(GEOIP_COUNTRY_EDITION_V6)) {
97
+       gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION_V6, GEOIP_STANDARD);
98
+       id = GeoIP_id_by_name_v6(gi, hostname);
99
+       GeoIP_delete(gi);
100
+   }
101
+#endif
102
    if (id == 0) {
103
        php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Host %s not found", hostname);
104
        RETURN_FALSE;
105
@@ -385,28 +447,66 @@
106
    GeoIP * gi;
107
    char * hostname = NULL;
108
    int arglen;
109
-   GeoIPRecord * gir;
110
+   GeoIPRecord * gir = NULL;
111
 
112
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &hostname, &arglen) == FAILURE) {
113
        return;
114
    }
115
 
116
-   if (GeoIP_db_avail(GEOIP_CITY_EDITION_REV1) || GeoIP_db_avail(GEOIP_CITY_EDITION_REV0)) {
117
-       if (GeoIP_db_avail(GEOIP_CITY_EDITION_REV1)) {
118
-           gi = GeoIP_open_type(GEOIP_CITY_EDITION_REV1, GEOIP_STANDARD);
119
+   int ipv4_db_available = 1;
120
+#if LIBGEOIP_VERSION >= 1004005
121
+   int ipv6_db_available = 1;
122
+#endif
123
+
124
+   if (GeoIP_db_avail(GEOIP_CITY_EDITION_REV1)) {
125
+       gi = GeoIP_open_type(GEOIP_CITY_EDITION_REV1, GEOIP_STANDARD);
126
+   } else if (GeoIP_db_avail(GEOIP_CITY_EDITION_REV0)) {
127
+       gi = GeoIP_open_type(GEOIP_CITY_EDITION_REV0, GEOIP_STANDARD);
128
+   } else {
129
+       ipv4_db_available = 9;
130
+   }
131
+
132
+   if (ipv4_db_available) {
133
+       gir = GeoIP_record_by_name(gi, hostname);
134
+   }
135
+
136
+   if (NULL != gi) {
137
+       GeoIP_delete(gi);
138
+   }
139
+
140
+#if LIBGEOIP_VERSION >= 1004005
141
+   if (NULL == gir) {
142
+       if (GeoIP_db_avail(GEOIP_CITY_EDITION_REV1_V6)) {
143
+           gi = GeoIP_open_type(GEOIP_CITY_EDITION_REV1_V6, GEOIP_STANDARD);
144
+       } else if (GeoIP_db_avail(GEOIP_CITY_EDITION_REV0_V6)) {
145
+           gi = GeoIP_open_type(GEOIP_CITY_EDITION_REV0_V6, GEOIP_STANDARD);
146
        } else {
147
-           gi = GeoIP_open_type(GEOIP_CITY_EDITION_REV0, GEOIP_STANDARD);
148
+           ipv6_db_available = 0;
149
+       }
150
+
151
+       if (ipv6_db_available) {
152
+           gir = GeoIP_record_by_name_v6(gi, hostname);
153
+       }
154
+
155
+       if (NULL != gi) {
156
+           GeoIP_delete(gi);
157
        }
158
-   }   else {
159
-       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required database not available at %s.", GeoIPDBFileName[GEOIP_CITY_EDITION_REV0]);
160
-       return;
161
    }
162
-   gir = GeoIP_record_by_name(gi, hostname);
163
+#endif
164
 
165
-   GeoIP_delete(gi);
166
-   
167
    if (NULL == gir) {
168
+       if (!ipv4_db_available) {
169
+           php_error_docref(NULL TSRMLS_CC, E_WARNING, "Required IPv4 database not available at %s.", GeoIPDBFileName[GEOIP_CITY_EDITION_REV0]);
170
+       }
171
+
172
+#if LIBGEOIP_VERSION >= 1004005
173
+       if (!ipv6_db_available) {
174
+           php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Required IPv6 database not available at %s.", GeoIPDBFileName[GEOIP_CITY_EDITION_REV0_V6]);
175
+       }
176
+#endif
177
+
178
        php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Host %s not found", hostname);
179
+
180
        RETURN_FALSE;
181
    }
182
    
183
diff -ruN geoip-1.0.8.orig/geoip.def geoip-1.0.8/geoip.def
184
--- geoip-1.0.8.orig/geoip.def  1970-01-01 10:13:08.000000000 +0100
185
+++ geoip-1.0.8/geoip.def   2012-11-13 12:19:51.000000000 +0100
186
@@ -17,12 +17,20 @@
187
 */
188
 
189
 /* GEOIPDEF(php_func, c_func, db_type) */
190
-GEOIPDEF(geoip_country_code_by_name,   GeoIP_country_code_by_name, GEOIP_COUNTRY_EDITION)
191
-GEOIPDEF(geoip_country_code3_by_name,  GeoIP_country_code3_by_name,    GEOIP_COUNTRY_EDITION)
192
-GEOIPDEF(geoip_country_name_by_name,   GeoIP_country_name_by_name, GEOIP_COUNTRY_EDITION)
193
+GEOIPDEF(geoip_country_code_by_name_v4,    GeoIP_country_code_by_name, GEOIP_COUNTRY_EDITION)
194
+GEOIPDEF(geoip_country_code3_by_name_v4,   GeoIP_country_code3_by_name,    GEOIP_COUNTRY_EDITION)
195
+GEOIPDEF(geoip_country_name_by_name_v4,    GeoIP_country_name_by_name, GEOIP_COUNTRY_EDITION)
196
 
197
-#if LIBGEOIP_VERSION >= 1004005 && FALSE
198
+#if LIBGEOIP_VERSION >= 1004005
199
 GEOIPDEF(geoip_country_code_by_name_v6,    GeoIP_country_code_by_name_v6,  GEOIP_COUNTRY_EDITION_V6)
200
 GEOIPDEF(geoip_country_code3_by_name_v6,   GeoIP_country_code3_by_name_v6, GEOIP_COUNTRY_EDITION_V6)
201
 GEOIPDEF(geoip_country_name_by_name_v6,    GeoIP_country_name_by_name_v6,  GEOIP_COUNTRY_EDITION_V6)
202
-#endif
203
\ No newline at end of file
204
+
205
+GEOIPMULTIDEF(geoip_country_code_by_name, GeoIP_country_code_by_name,     GEOIP_COUNTRY_EDITION, GeoIP_country_code_by_name_v6, GEOIP_COUNTRY_EDITION_V6)
206
+GEOIPMULTIDEF(geoip_country_code3_by_name,        GeoIP_country_code3_by_name,    GEOIP_COUNTRY_EDITION, GeoIP_country_code3_by_name_v6, GEOIP_COUNTRY_EDITION_V6)
207
+GEOIPMULTIDEF(geoip_country_name_by_name, GeoIP_country_name_by_name,     GEOIP_COUNTRY_EDITION, GeoIP_country_name_by_name_v6,  GEOIP_COUNTRY_EDITION_V6)
208
+#else
209
+GEOIPDEF(geoip_country_code_by_name, GeoIP_country_code_by_name,     GEOIP_COUNTRY_EDITION)
210
+GEOIPDEF(geoip_country_code3_by_name,        GeoIP_country_code3_by_name,    GEOIP_COUNTRY_EDITION)
211
+GEOIPDEF(geoip_country_name_by_name, GeoIP_country_name_by_name,     GEOIP_COUNTRY_EDITION)
212
+#endif
213
diff -ruN geoip-1.0.8.orig/php_geoip.h geoip-1.0.8/php_geoip.h
214
--- geoip-1.0.8.orig/php_geoip.h    1970-01-01 10:13:08.000000000 +0100
215
+++ geoip-1.0.8/php_geoip.h 2012-11-13 11:21:40.000000000 +0100
216
@@ -49,8 +49,11 @@
217
 PHP_FUNCTION(geoip_database_info);
218
 #define GEOIPDEF(php_func, c_func, db_type) \
219
 PHP_FUNCTION(php_func);
220
+#define GEOIPMULTIDEF(php_func, c_func, db_type, c_func_v6, db_type_v6) \
221
+PHP_FUNCTION(php_func);
222
 #include "geoip.def"
223
 #undef GEOIPDEF
224
+#undef GEOIPMULTIDEF
225
 PHP_FUNCTION(geoip_continent_code_by_name);
226
 PHP_FUNCTION(geoip_org_by_name);
227
 PHP_FUNCTION(geoip_record_by_name);
228