annotate contrib/unicode2nginx/unicode-to-nginx.pl @ 7690:8253424d1aff

Added size check to ngx_http_alloc_large_header_buffer(). This ensures that copying won't write more than the buffer size even if the buffer comes from hc->free and it is smaller than the large client header buffer size in the virtual host configuration. This might happen if size of large client header buffers is different in name-based virtual hosts, similarly to the problem with number of buffers fixed in 6926:e662cbf1b932.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 06 Aug 2020 05:02:22 +0300
parents 8752257e883f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1 #!/usr/bin/perl -w
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3 # Convert unicode mappings to nginx configuration file format.
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5 # You may find useful mappings in various places, including
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6 # unicode.org official site:
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7 #
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 # http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1251.TXT
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 # http://www.unicode.org/Public/MAPPINGS/VENDORS/MISC/KOI8-R.TXT
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11 # Needs perl 5.6 or later.
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12
6665
8752257e883f Contrib: unicode2nginx compatibility with recent Perl versions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 667
diff changeset
13 # Written by Maxim Dounin, mdounin@mdounin.ru
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
15 ###############################################################################
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
16
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17 require 5.006;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
19 while (<>) {
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
20 # Skip comments and empty lines
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
21
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22 next if /^#/;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
23 next if /^\s*$/;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
24 chomp;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
25
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
26 # Convert mappings
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
27
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
28 if (/^\s*0x(..)\s*0x(....)\s*(#.*)/) {
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29 # Mapping <from-code> <unicode-code> "#" <unicode-name>
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
30 my $cs_code = $1;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 my $un_code = $2;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32 my $un_name = $3;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
34 # Produce UTF-8 sequence from character code;
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35
6665
8752257e883f Contrib: unicode2nginx compatibility with recent Perl versions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 667
diff changeset
36 my $un_utf8 = join('',
8752257e883f Contrib: unicode2nginx compatibility with recent Perl versions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 667
diff changeset
37 map { sprintf("%02X", $_) }
8752257e883f Contrib: unicode2nginx compatibility with recent Perl versions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 667
diff changeset
38 unpack("U0C*", pack("U", hex($un_code)))
8752257e883f Contrib: unicode2nginx compatibility with recent Perl versions.
Maxim Dounin <mdounin@mdounin.ru>
parents: 667
diff changeset
39 );
667
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
40
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
41 print " $cs_code $un_utf8 ; $un_name\n";
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
43 } else {
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44 warn "Unrecognized line: '$_'";
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
45 }
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
46 }
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
47
63a820b0bc6c nginx-0.3.55-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
48 ###############################################################################