-
Notifications
You must be signed in to change notification settings - Fork 8
/
ngx_http_set_lang_module.c
764 lines (512 loc) · 21.3 KB
/
ngx_http_set_lang_module.c
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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
/*
* Copyright (c) 2009 Marcus Clyne
*/
#include <ndk.h>
// TODO : add setting a variable that dictates the method - $set_lang_method
static ngx_int_t ngx_http_set_lang_cookie = 0;
static ngx_int_t ngx_set_lang_method_var_index;
typedef struct ngx_http_set_lang_loc_conf_s ngx_http_set_lang_loc_conf_t;
typedef ngx_int_t (*ngx_http_set_lang_func_pt) (ngx_http_request_t *r, ngx_http_set_lang_loc_conf_t *conf, ngx_str_t *v);
static ngx_int_t ngx_http_set_lang_from_accept_lang (ngx_http_request_t *r, ngx_http_set_lang_loc_conf_t *conf, ngx_str_t *v);
static ngx_int_t ngx_http_set_lang_from_get (ngx_http_request_t *r, ngx_http_set_lang_loc_conf_t *conf, ngx_str_t *v);
static ngx_int_t ngx_http_set_lang_from_post (ngx_http_request_t *r, ngx_http_set_lang_loc_conf_t *conf, ngx_str_t *v);
static ngx_int_t ngx_http_set_lang_from_cookie (ngx_http_request_t *r, ngx_http_set_lang_loc_conf_t *conf, ngx_str_t *v);
static ngx_int_t ngx_http_set_lang_from_geoip (ngx_http_request_t *r, ngx_http_set_lang_loc_conf_t *conf, ngx_str_t *v);
static ngx_int_t ngx_http_set_lang_from_host (ngx_http_request_t *r, ngx_http_set_lang_loc_conf_t *conf, ngx_str_t *v);
static ngx_int_t ngx_http_set_lang_from_referer (ngx_http_request_t *r, ngx_http_set_lang_loc_conf_t *conf, ngx_str_t *v);
static ngx_int_t ngx_http_set_lang_from_var (ngx_http_request_t *r, ngx_http_set_lang_loc_conf_t *conf, ngx_str_t *v);
static char * ngx_http_set_lang (ngx_conf_t *cf, ngx_command_t *cmd, void *cnf);
static ngx_int_t ngx_http_set_lang_from_methods (ngx_http_request_t *r, ngx_str_t *v);
static ngx_int_t ngx_http_set_lang_init (ngx_conf_t *cf);
static void * ngx_http_set_lang_create_loc_conf (ngx_conf_t *cf);
static char * ngx_http_set_lang_merge_loc_conf (ngx_conf_t *cf, void *parent, void *child);
static ndk_set_var_t ngx_http_var_set_lang_def = {
NDK_SET_VAR_BASIC,
ngx_http_set_lang_from_methods,
0,
NULL
};
typedef struct {
ngx_http_set_lang_func_pt func; // put func first because it's more efficient for calling
ngx_str_t name;
} ngx_http_set_lang_method_t;
struct ngx_http_set_lang_loc_conf_s {
ngx_int_t enable;
ngx_flag_t set_cookie;
ngx_flag_t set_method;
ngx_int_t var_index;
ngx_array_t *langs;
ngx_array_t *indexes;
ngx_array_t *hosts;
ngx_array_t *referers;
ngx_http_set_lang_method_t *methods;
ngx_str_t get_var;
ngx_str_t post_var;
ngx_str_t cookie;
};
static ngx_http_set_lang_method_t ngx_http_set_lang_methods [] = {
{ngx_http_set_lang_from_accept_lang, ngx_string ("accept_lang")},
{ngx_http_set_lang_from_get, ngx_string ("get")},
{ngx_http_set_lang_from_post, ngx_string ("post")},
{ngx_http_set_lang_from_cookie, ngx_string ("cookie")},
{ngx_http_set_lang_from_geoip, ngx_string ("geoip")},
{ngx_http_set_lang_from_host, ngx_string ("host")},
{ngx_http_set_lang_from_referer, ngx_string ("referer")},
{NULL, ngx_null_string}
};
static ngx_command_t ngx_http_set_lang_commands[] = {
{
ngx_string ("set_lang"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_1MORE,
ngx_http_set_lang,
0,
0,
&ngx_http_var_set_lang_def
},
{
ngx_string ("set_lang_method"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_FLAG,
ngx_conf_set_flag_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof (ngx_http_set_lang_loc_conf_t, set_method),
NULL
},
{
ngx_string ("lang_cookie"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof (ngx_http_set_lang_loc_conf_t, cookie),
NULL
},
{
ngx_string ("lang_get_var"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof (ngx_http_set_lang_loc_conf_t, get_var),
NULL
},
{
ngx_string ("lang_list"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_1MORE,
ndk_conf_set_str_array_multi_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof (ngx_http_set_lang_loc_conf_t, langs),
NULL
},
{
ngx_string ("lang_post_var"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof (ngx_http_set_lang_loc_conf_t, post_var),
NULL
},
{
ngx_string ("lang_host"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE2,
ngx_conf_set_keyval_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof (ngx_http_set_lang_loc_conf_t, hosts),
NULL
},
{
ngx_string ("lang_referer"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE2,
ngx_conf_set_keyval_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof (ngx_http_set_lang_loc_conf_t, referers),
NULL
},
ngx_null_command
};
ngx_http_module_t ngx_http_set_lang_module_ctx = {
ngx_http_set_lang_init, // preconfig
NULL, // postconfig
NULL, // create main config
NULL, // init main config
NULL, // create server config
NULL, // merge server config
ngx_http_set_lang_create_loc_conf, // create location config
ngx_http_set_lang_merge_loc_conf // merge location config
};
ngx_module_t ngx_http_set_lang_module = {
NGX_MODULE_V1,
&ngx_http_set_lang_module_ctx, // module context
ngx_http_set_lang_commands, // module directives
NGX_HTTP_MODULE, // module type
NULL, // init master
NULL, // init module
NULL, // init process
NULL, // init thread
NULL, // exit thread
NULL, // exit process
NULL, // exit master
NGX_MODULE_V1_PADDING
};
static ngx_int_t
ngx_http_set_lang_from_methods (ngx_http_request_t *r, ngx_str_t *v)
{
ngx_http_set_lang_loc_conf_t *llcf;
ngx_http_set_lang_method_t *method;
size_t len;
u_char *cookie, *p;
ngx_table_elt_t *cookie_hdr;
ngx_int_t rc;
ngx_http_variable_value_t *mv;
ngx_http_set_lang_func_pt func;
llcf = ngx_http_get_module_loc_conf (r, ngx_http_set_lang_module);
if (!llcf->enable)
return NGX_DECLINED;
// reset var index - NOTE : if a method that issues subrequests is added, then this won't always work;
llcf->var_index = 0;
// iterate over methods of getting lang value
for (method = llcf->methods ; (func = method->func) ; method++) {
rc = func (r, llcf, v);
switch (rc) {
case NGX_OK :
if (method->func != ngx_http_set_lang_from_cookie && llcf->set_cookie) {
// TODO : add parsing of path and exipires on cookie
// create lang cookie
len = llcf->cookie.len + v->len + sizeof ("; path=/");
cookie = ngx_pnalloc (r->pool, len + 1);
if (cookie == NULL) {
return NGX_ERROR;
}
p = ngx_copy (cookie, llcf->cookie.data, llcf->cookie.len);
*p++ = '=';
p = ngx_copy (p, v->data, v->len);
p = ngx_copy (p, "; path=/", sizeof ("; path=/"));
// add lang cookie to main response
cookie_hdr = ngx_list_push (&r->main->headers_out.headers);
if (cookie_hdr == NULL) {
return NGX_ERROR;
}
cookie_hdr->hash = 1;
cookie_hdr->key.len = sizeof ("Set-Cookie") - 1;
cookie_hdr->key.data = (u_char *) "Set-Cookie";
cookie_hdr->value.len = len;
cookie_hdr->value.data = cookie;
}
if (llcf->set_method) {
mv = ngx_http_get_indexed_variable (r, ngx_set_lang_method_var_index);
mv->data = method->name.data;
mv->len = method->name.len;
mv->valid = 1;
mv->no_cacheable = 0;
mv->not_found = 0;
}
return NGX_OK;
case NGX_DECLINED :
continue;
}
return NGX_ERROR;
}
return NGX_DECLINED;
}
static ngx_int_t
ngx_http_set_lang_from_accept_lang (ngx_http_request_t *r, ngx_http_set_lang_loc_conf_t *conf, ngx_str_t *v)
{
ngx_str_t accept_lang, *lang;
u_char *s, *m, *e;
size_t len;
ngx_uint_t i;
if (r->headers_in.accept_language == NULL)
return NGX_DECLINED;
accept_lang = r->headers_in.accept_language->value;
s = accept_lang.data;
e = accept_lang.data + accept_lang.len;
do {
// strip spaces
while (*s == ' ') {
s++;
if (s == e)
return NGX_DECLINED;
};
m = s;
// parse between ',' and ';'
while (m < e && *m != ',' && *m != ';') m++;
len = m-s;
// compare to lang list
lang = conf->langs->elts;
for (i=conf->langs->nelts; i; i--,lang++) {
if (len == lang->len && !ngx_strncasecmp (s, lang->data, len)) {
v->data = s;
v->len = len;
return NGX_OK;
}
}
// strip weighting, ',' and ';'
if (*m == ';') while (m < e && *m != ',') m++;
if (*m == ',') m++;
s = m;
} while (m < e);
return NGX_DECLINED;
}
static ngx_int_t
ngx_http_set_lang_from_get (ngx_http_request_t *r, ngx_http_set_lang_loc_conf_t *conf, ngx_str_t *v)
{
ngx_str_t value;
if (ngx_http_arg (r, conf->get_var.data, conf->get_var.len, &value) == NGX_DECLINED)
return NGX_DECLINED;
v->data = value.data;
v->len = value.len;
return NGX_OK;
}
static ngx_int_t
ngx_http_set_lang_from_post (ngx_http_request_t *r, ngx_http_set_lang_loc_conf_t *conf, ngx_str_t *v)
{
// TODO
return NGX_DECLINED;
}
static ngx_int_t
ngx_http_set_lang_from_cookie (ngx_http_request_t *r, ngx_http_set_lang_loc_conf_t *conf, ngx_str_t *v)
{
ngx_str_t cookie;
if (ngx_http_parse_multi_header_lines (&r->headers_in.cookies, &conf->cookie, &cookie) == NGX_DECLINED)
return NGX_DECLINED;
v->data = cookie.data;
v->len = cookie.len;
return NGX_OK;
}
static ngx_int_t
ngx_http_set_lang_from_geoip (ngx_http_request_t *r, ngx_http_set_lang_loc_conf_t *conf, ngx_str_t *v)
{
// TODO
return NGX_DECLINED;
}
static ngx_int_t
ngx_http_set_lang_from_host (ngx_http_request_t *r, ngx_http_set_lang_loc_conf_t *conf, ngx_str_t *v)
{
ngx_keyval_t *kv;
ngx_uint_t i;
ngx_str_t host;
// TODO : change to a hashed version
host = r->headers_in.host->value;
kv = conf->hosts->elts;
for (i=conf->hosts->nelts; i; i--, kv++) {
if (kv->key.data[0] == '.') {
// check wildcard domain suffixes (e.g. .example.fr ->fr)
if (host.len > kv->key.len &&
host.data [host.len - kv->key.len] == '.' &&
!ngx_strncasecmp (host.data + host.len - kv->key.len, kv->key.data, kv->key.len - 1)) {
v->data = kv->value.data;
v->len = kv->value.len;
return NGX_OK;
}
// check static domains
} else if (host.len == kv->key.len && !ngx_strncasecmp (host.data, kv->key.data, host.len)) {
v->data = kv->value.data;
v->len = kv->value.len;
return NGX_OK;
}
// TODO : regexes
}
return NGX_DECLINED;
}
static ngx_int_t
ngx_http_set_lang_from_referer (ngx_http_request_t *r, ngx_http_set_lang_loc_conf_t *conf, ngx_str_t *v)
{
ngx_keyval_t *kv;
ngx_uint_t i;
ngx_str_t referer;
// TODO : change to a hashed version
if (r->headers_in.referer == NULL)
return NGX_DECLINED;
referer = r->headers_in.referer->value;
kv = conf->referers->elts;
for (i=conf->referers->nelts; i; i--, kv++) {
if (kv->key.data[0] == '.') {
// check wildcard domain suffixes (e.g. .example.fr ->fr)
if (referer.len > kv->key.len &&
referer.data [referer.len - kv->key.len] == '.' &&
!ngx_strncasecmp (referer.data + referer.len - kv->key.len, kv->key.data, kv->key.len - 1)) {
v->data = kv->value.data;
v->len = kv->value.len;
return NGX_OK;
}
// check static domains
} else if (referer.len == kv->key.len && !ngx_strncasecmp (referer.data, kv->key.data, referer.len)) {
v->data = kv->value.data;
v->len = kv->value.len;
return NGX_OK;
}
// TODO : regexes
}
return NGX_DECLINED;
}
static ngx_int_t
ngx_http_set_lang_from_var (ngx_http_request_t *r, ngx_http_set_lang_loc_conf_t *conf, ngx_str_t *v)
{
ngx_http_variable_value_t *value;
ngx_int_t *indexes;
indexes = conf->indexes->elts;
value = ngx_http_get_indexed_variable (r, indexes [conf->var_index]);
if (value == NULL) {
conf->var_index++;
return NGX_DECLINED;
}
v->data = value->data;
v->len = value->len;
return NGX_OK;
}
static char *
ngx_http_set_lang (ngx_conf_t *cf, ngx_command_t *cmd, void *cnf)
{
ngx_http_variable_t *var;
ngx_str_t *value;
ngx_uint_t i;
ngx_int_t *index;
ngx_http_set_lang_loc_conf_t *conf;
ngx_http_set_lang_method_t *method, *next_method;
char *p;
conf = ngx_http_conf_get_module_loc_conf (cf, ngx_http_set_lang_module);
// check for duplicates
if (conf->enable != NGX_CONF_UNSET)
return "is duplicate";
value = cf->args->elts;
value++;
// check for validitiy
if (value->data[0] != '$') {
if (value->len == 2 && !ngx_strncasecmp (value->data, (u_char *) "on", 2)) {
conf->enable = 1;
return NGX_CONF_OK;
} else if (value->len == 3 && !ngx_strncasecmp (value->data, (u_char *) "off", 3)) {
conf->enable = 0;
return NGX_CONF_OK;
}
ngx_conf_log_error (NGX_LOG_EMERG, cf, 0, "\"%V\" variable name does not start with '$' and not on/off", value);
return NGX_CONF_ERROR;
}
if (cf->args->nelts < 3) {
ngx_conf_log_error (NGX_LOG_EMERG, cf, 0, "no set_lang methods defined");
return NGX_CONF_ERROR;
}
conf->enable = 1;
// add the variable to the rewrite processes
p = ndk_set_var (cf, cmd, cnf);
if (p != NGX_CONF_OK)
return p;
// parse set_from methods (adding blank one on end)
method = ngx_pcalloc (cf->pool, (cf->args->nelts - 1) * sizeof (ngx_http_set_lang_method_t));
if (method == NULL)
return NGX_CONF_ERROR;
conf->methods = method;
value++;
for (i=cf->args->nelts-2; i; i--, value++, method++) {
next_method = ngx_http_set_lang_methods;
do {
if (next_method->func == NULL) {
ngx_conf_log_error (NGX_LOG_EMERG, cf, 0, "set from \"%V\" is not a valid method", value);
return NGX_CONF_ERROR;
}
if (value->data[0] == '$') {
value->data++;
value->len--;
// add variable
var = ngx_http_add_variable (cf, value, NGX_HTTP_VAR_CHANGEABLE);
if (var == NULL)
return NGX_CONF_ERROR;
if (conf->indexes == NGX_CONF_UNSET_PTR) {
conf->indexes = ngx_array_create (cf->pool, 3, sizeof (ngx_int_t));
if (conf->indexes == NULL)
return NGX_CONF_ERROR;
}
// add var index to list
index = ngx_array_push (conf->indexes);
if (index == NULL)
return NGX_CONF_ERROR;
*index = ngx_http_get_variable_index (cf, value);
if (*index == NGX_ERROR)
return NGX_CONF_ERROR;
// add method to list
method->func = ngx_http_set_lang_from_var;
method->name.data = (u_char *) "variable";
method->name.len = sizeof ("variable") - 1; // TODO : include the variable name
break;
} else if (value->len == next_method->name.len && !ngx_strncasecmp (value->data, next_method->name.data, value->len)) {
*method = *next_method;
if (method->func == ngx_http_set_lang_from_cookie && conf->set_cookie == NGX_CONF_UNSET)
conf->set_cookie = 1;
break;
}
next_method++;
} while (1);
}
return NGX_CONF_OK;
}
static ngx_int_t
ngx_http_set_lang_init (ngx_conf_t *cf)
{
ngx_http_variable_t *v;
ngx_str_t var_name = ngx_string ("set_lang_method");
ngx_int_t index;
v = ngx_http_add_variable (cf, &var_name, 0);
if (v == NULL) {
return NGX_ERROR;
}
v->get_handler = ndk_http_rewrite_var;
index = ngx_http_get_variable_index (cf, &var_name);
if (index == NGX_ERROR) {
return NGX_ERROR;
}
ngx_set_lang_method_var_index = index;
return NGX_OK;
}
static void *
ngx_http_set_lang_create_loc_conf (ngx_conf_t *cf)
{
ngx_http_set_lang_loc_conf_t *conf;
ndk_pcallocp_rn (conf, cf->pool);
conf->enable = NGX_CONF_UNSET;
conf->set_cookie = NGX_CONF_UNSET;
conf->set_method = NGX_CONF_UNSET;
conf->langs = NGX_CONF_UNSET_PTR;
conf->methods = NGX_CONF_UNSET_PTR;
conf->indexes = NGX_CONF_UNSET_PTR;
return conf;
}
static char *
ngx_http_set_lang_merge_loc_conf (ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_set_lang_loc_conf_t *prev, *conf;
ngx_http_set_lang_method_t *method;
ngx_http_set_lang_func_pt func;
prev = parent;
conf = child;
ngx_conf_merge_value (conf->enable, prev->enable, 0);
ngx_conf_merge_value (conf->set_cookie, prev->set_cookie, 0);
ngx_conf_merge_value (conf->set_method, prev->set_method, 0);
ngx_conf_merge_ptr_value (conf->langs, prev->langs, NULL);
ngx_conf_merge_ptr_value (conf->methods, prev->methods, NULL);
ngx_conf_merge_ptr_value (conf->indexes, prev->indexes, NULL);
if (conf->hosts == NULL)
conf->hosts = prev->hosts;
if (conf->referers == NULL)
conf->referers = prev->referers;
ngx_conf_merge_str_value (conf->post_var, prev->get_var, "lang");
ngx_conf_merge_str_value (conf->get_var, prev->post_var, "lang");
ngx_conf_merge_str_value (conf->cookie, prev->cookie, "lang");
if (conf->enable) {
method = conf->methods;
for ( ; (func = method->func) ; method++) {
if (func == ngx_http_set_lang_from_host && conf->hosts == NULL) {
ngx_conf_log_error (NGX_LOG_EMERG, cf, 0, "no hosts have been specified for set_lang (e.g. lang_host example.de de;)");
return NGX_CONF_ERROR;
}
if (func == ngx_http_set_lang_from_referer && conf->referers == NULL) {
ngx_conf_log_error (NGX_LOG_EMERG, cf, 0, "no referers have been specified for set_lang (e.g. lang_referer example.de de;)");
return NGX_CONF_ERROR;
}
if (func == ngx_http_set_lang_from_accept_lang && conf->langs == NULL) {
ngx_conf_log_error (NGX_LOG_EMERG, cf, 0, "no languages have been specified for set_lang (e.g.: lang_list en fr de;)");
return NGX_CONF_ERROR;
}
if (func == ngx_http_set_lang_from_cookie) {
ngx_http_set_lang_cookie = 1;
}
}
}
return NGX_CONF_OK;
}