~britco/nginx/master

« back to all changes in this revision

Viewing changes to src/http/modules/ngx_http_geoip_module.c

  • Committer: Bazaar Package Importer
  • Author(s): Kartik Mistry, Kartik Mistry, Michael Lustfield
  • Date: 2010-11-27 21:04:02 UTC
  • mfrom: (1.3.8 upstream)
  • mto: This revision was merged to the branch mainline in revision 36.
  • Revision ID: james.westby@ubuntu.com-20101127210402-14sgjpe6r3jup8a9
Tags: 0.8.53-1
[Kartik Mistry]
* debian/control:
  + Added Michael Lustfield as co-maintainer
* nginx.conf:
  + No need to use regex in gzip_disable for msie6, Thanks to António P. P.
    Almeida <appa@perusio.net> (Closes: #592147)
* conf/sites-available/default:
  + Fixed typo for "include fastcgi", Thanks to Mostafa Ghadamyari
    <nginx@gigfa.com> (Closes: #593142, #593143)
* debian/patches/fix_reloading_ipv6.diff:
  + Removed, merged upstream
* debian/init.d:
  + Added fix to control nginx by user in a simple way by setting DAEMON
    variable to an invalid name in /etc/default/nginx. Patch by Toni Mueller
    <support@oeko.net> (Closes: #594598)
* debian/NEWS.Debian:
  + Updated news for 0.8.x as stable branch

[Michael Lustfield]
* New upstream release (Closes: #602970)
  + 0.8.x branch is declared stable by upstream now
* Add a UFW profile set:
  + debian/nginx.ufw.profile: Added.
  + debian/control: nginx: Suggests ufw.
  + debian/dirs: Add 'etc/ufw/applications.d'
  + debian/rules: Add install rule for the nginx UFW profile.
* Moved debian/dirs to debian/nginx.dirs
* Added types_hash_max_size to nginx.conf
* Install simple default index.html file (Closes: #581416)
  + debian/dirs: Add 'usr/share/nginx/www'.
  + debian/nginx.install: Add 'html/* usr/share/nginx/www'.
* debian/patches/nginx-echo.diff:
  + Added Echo module
* Added files for nginx.docs
  - /usr/share/doc/nginx/
    + debian/help/docs/fcgiwrap
    + debian/help/docs/php
    + debian/help/docs/support-irc
    + debian/help/docs/upstream
* Added files for nginx.examples
  - /usr/share/doc/nginx/examples/
    + debian/help/docs/drupal
    + debian/help/docs/http
    + debian/help/docs/mail
    + debian/help/docs/mailman
    + debian/help/docs/nginx.conf
    + debian/help/docs/virtual_hosts
    + debian/help/docs/wordpress
* debian/conf/:
  + Removed excess spaces
  + Added tabs where appropriate
  + Added SCRIPT_FILENAME to fastcgi_params

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    ngx_http_variable_value_t *v, uintptr_t data);
31
31
static ngx_int_t ngx_http_geoip_city_variable(ngx_http_request_t *r,
32
32
    ngx_http_variable_value_t *v, uintptr_t data);
 
33
static ngx_int_t ngx_http_geoip_region_name_variable(ngx_http_request_t *r,
 
34
    ngx_http_variable_value_t *v, uintptr_t data);
33
35
static ngx_int_t ngx_http_geoip_city_float_variable(ngx_http_request_t *r,
34
36
    ngx_http_variable_value_t *v, uintptr_t data);
 
37
static ngx_int_t ngx_http_geoip_city_int_variable(ngx_http_request_t *r,
 
38
    ngx_http_variable_value_t *v, uintptr_t data);
35
39
static GeoIPRecord *ngx_http_geoip_get_city_record(ngx_http_request_t *r);
36
40
 
37
41
static ngx_int_t ngx_http_geoip_add_variables(ngx_conf_t *cf);
128
132
      ngx_http_geoip_city_variable,
129
133
      offsetof(GeoIPRecord, region), 0, 0 },
130
134
 
 
135
    { ngx_string("geoip_region_name"), NULL,
 
136
      ngx_http_geoip_region_name_variable,
 
137
      0, 0, 0 },
 
138
 
131
139
    { ngx_string("geoip_city"), NULL,
132
140
      ngx_http_geoip_city_variable,
133
141
      offsetof(GeoIPRecord, city), 0, 0 },
144
152
      ngx_http_geoip_city_float_variable,
145
153
      offsetof(GeoIPRecord, longitude), 0, 0 },
146
154
 
 
155
    { ngx_string("geoip_dma_code"), NULL,
 
156
      ngx_http_geoip_city_int_variable,
 
157
      offsetof(GeoIPRecord, dma_code), 0, 0 },
 
158
 
 
159
    { ngx_string("geoip_area_code"), NULL,
 
160
      ngx_http_geoip_city_int_variable,
 
161
      offsetof(GeoIPRecord, area_code), 0, 0 },
 
162
 
147
163
    { ngx_null_string, NULL, NULL, 0, 0, 0 }
148
164
};
149
165
 
215
231
 
216
232
    len = ngx_strlen(val);
217
233
    v->data = ngx_pnalloc(r->pool, len);
218
 
 
219
234
    if (v->data == NULL) {
220
235
        GeoIPRecord_delete(gr);
221
236
        return NGX_ERROR;
245
260
 
246
261
 
247
262
static ngx_int_t
 
263
ngx_http_geoip_region_name_variable(ngx_http_request_t *r,
 
264
    ngx_http_variable_value_t *v, uintptr_t data)
 
265
{
 
266
    size_t        len;
 
267
    const char   *val;
 
268
    GeoIPRecord  *gr;
 
269
 
 
270
    gr = ngx_http_geoip_get_city_record(r);
 
271
    if (gr == NULL) {
 
272
        goto not_found;
 
273
    }
 
274
 
 
275
    val = GeoIP_region_name_by_code(gr->country_code, gr->region);
 
276
 
 
277
    GeoIPRecord_delete(gr);
 
278
 
 
279
    if (val == NULL) {
 
280
        goto not_found;
 
281
    }
 
282
 
 
283
    len = ngx_strlen(val);
 
284
    v->data = ngx_pnalloc(r->pool, len);
 
285
    if (v->data == NULL) {
 
286
        return NGX_ERROR;
 
287
    }
 
288
 
 
289
    ngx_memcpy(v->data, val, len);
 
290
 
 
291
    v->len = len;
 
292
    v->valid = 1;
 
293
    v->no_cacheable = 0;
 
294
    v->not_found = 0;
 
295
 
 
296
    return NGX_OK;
 
297
 
 
298
not_found:
 
299
 
 
300
    v->not_found = 1;
 
301
 
 
302
    return NGX_OK;
 
303
}
 
304
 
 
305
 
 
306
static ngx_int_t
248
307
ngx_http_geoip_city_float_variable(ngx_http_request_t *r,
249
308
    ngx_http_variable_value_t *v, uintptr_t data)
250
309
{
273
332
}
274
333
 
275
334
 
 
335
static ngx_int_t
 
336
ngx_http_geoip_city_int_variable(ngx_http_request_t *r,
 
337
    ngx_http_variable_value_t *v, uintptr_t data)
 
338
{
 
339
    int           val;
 
340
    GeoIPRecord  *gr;
 
341
 
 
342
    gr = ngx_http_geoip_get_city_record(r);
 
343
    if (gr == NULL) {
 
344
        v->not_found = 1;
 
345
        return NGX_OK;
 
346
    }
 
347
 
 
348
    v->data = ngx_pnalloc(r->pool, NGX_INT64_LEN);
 
349
    if (v->data == NULL) {
 
350
        GeoIPRecord_delete(gr);
 
351
        return NGX_ERROR;
 
352
    }
 
353
 
 
354
    val = *(int *) ((char *) gr + data);
 
355
 
 
356
    v->len = ngx_sprintf(v->data, "%d", val) - v->data;
 
357
 
 
358
    GeoIPRecord_delete(gr);
 
359
 
 
360
    return NGX_OK;
 
361
}
 
362
 
 
363
 
276
364
static GeoIPRecord *
277
365
ngx_http_geoip_get_city_record(ngx_http_request_t *r)
278
366
{