2 # Defines MIME module directives
4 sub mod_mime_directives
7 $rv = [ [ 'AddType', 1, 6, 'virtual directory htaccess', undef, 10 ],
8 [ 'AddHandler', 1, 6, 'virtual directory htaccess', undef, 6 ],
9 [ 'AddOutputFilter', 1, 18, 'virtual directory htaccess', 2.0 ],
10 [ 'AddInputFilter', 1, 18, 'virtual directory htaccess', 2.0 ],
11 [ 'DefaultLanguage', 0, 19, 'virtual directory htaccess', 1.304 ],
12 [ 'RemoveHandler', 1, 6, 'directory htaccess', 1.304, 5 ],
13 [ 'RemoveType', 1, 6, 'directory htaccess', 1.313, 5 ],
14 [ 'RemoveEncoding', 1, 6, 'directory htaccess', 1.313, 5 ],
15 [ 'AddLanguage', 1, 19, 'virtual directory htaccess', undef, 4 ],
16 [ 'AddEncoding', 1, 6, 'virtual directory htaccess', undef, 8 ],
17 [ 'AddCharset', 1, 19, 'virtual directory htaccess', 1.310, 2 ],
18 [ 'ForceType', 0, 6, 'directory htaccess', -2.0 ],
19 [ 'SetHandler', 0, 6, 'directory htaccess' ],
20 [ 'TypesConfig', 0, 6, 'global' ] ];
21 return &make_directives($rv, $_[0], "mod_mime");
24 # extmap_input(directive, title, size, desc, list)
27 local($rv, $i, $type, $exts);
28 $rv = "<table border>\n".
29 "<tr $tb> <td><b>$_[1]</b></td> <td><b>$text{'mod_mime_ext'}</b></td>\n".
30 "<td><b>$_[1]</b></td> <td><b>$text{'mod_mime_ext'}</b></td> </tr>\n";
31 $len = int(@{$_[4]}/2)*2 + 2;
32 for($i=0; $i<$len; $i++) {
33 if ($i%2 == 0) { $rv .= "<tr $cb>\n"; }
35 $_[4]->[$i]->{'value'} =~ /^(\S+)\s*(.*)$/;
36 $type = $1; $exts = $2;
38 else { $type = $exts = ""; }
40 if ($_[2] eq "h") { $rv .= &handler_input($type, "$_[0]_type_$i"); }
41 else { $rv .= "<input name=$_[0]_type_$i size=$_[2] value=$type>"; }
43 $rv .= "<td><input name=$_[0]_exts_$i size=10 value=\"$exts\"></td>\n";
44 if ($i%2 == 1) { $rv .= "</tr>\n"; }
47 return (2, $_[3], $rv);
50 # parse_extmap(directive, regexp, desc)
53 local($i, $type, $exts, @rv, $re); $re = $_[1];
54 for($i=0; defined($in{"$_[0]_type_$i"}); $i++) {
55 $type = $in{"$_[0]_type_$i"}; $exts = $in{"$_[0]_exts_$i"};
56 if ($type !~ /\S/ && $exts !~ /\S/) { next; }
57 if ($type !~ /$re/) { &error(&text('mod_mime_einvalid', $type, $_[2])); }
58 if ($exts !~ /\S/) { &error(&text('mod_mime_eext', $_[2], $type)); }
59 push(@rv, "$type $exts");
66 &extmap_input("AddType", $text{'mod_mime_type'}, 20, $text{'mod_mime_xtype'}, $_[0]);
70 return &parse_extmap("AddType", '^(\S+)\/(\S+)$',
71 $text{'mod_mime_mtype'});
76 &extmap_input("AddHandler", $text{'mod_mime_handler'}, "h", $text{'mod_mime_chandl'}, $_[0]);
80 return &parse_extmap("AddHandler");
85 &extmap_input("AddEncoding", $text{'mod_mime_cenc'}, 20, $text{'mod_mime_cencs'}, $_[0]);
89 return &parse_extmap("AddEncoding", '^(\S+)$',
90 $text{'mod_mime_cenc'});
95 &extmap_input("AddLanguage", $text{'mod_mime_lang'}, 5, $text{'mod_mime_clangs'}, $_[0]);
99 return &parse_extmap("AddLanguage", '^\S+$', $text{'mod_mime_clang'});
104 return (1, $text{'mod_mime_defmime'},
105 &opt_input($_[0]->{'value'}, "ForceType", $text{'mod_mime_real'}, 15));
109 return &parse_opt("ForceType", '^\S+\/\S+$', $text{'mod_mime_etype'});
114 return (1, $text{'mod_mime_pass'},
115 &handler_input($_[0]->{'value'}, "SetHandler"));
119 return &parse_handler("SetHandler");
125 $text{'mod_mime_file'},
126 &opt_input($_[0]->{'value'}, "TypesConfig", $text{'mod_mime_default'}, 40).
127 &file_chooser_button("TypesConfig", 0));
131 return &parse_opt("TypesConfig");
134 sub edit_RemoveHandler
137 foreach $v (@{$_[0]}) {
138 push(@list, @{$v->{'words'}});
140 return (2, "$text{'mod_mime_ignhand'}",
141 &opt_input(@list ? join(" ", @list) : undef,
142 "RemoveHandler", "$text{'mod_mime_none'}", 40));
144 sub save_RemoveHandler
146 return &parse_opt("RemoveHandler");
152 foreach $v (@{$_[0]}) {
153 push(@list, @{$v->{'words'}});
155 return (2, "$text{'mod_mime_igntype'}",
156 &opt_input(@list ? join(" ", @list) : undef,
157 "RemoveType", "$text{'mod_mime_none'}", 40));
161 return &parse_opt("RemoveType");
164 sub edit_RemoveEncoding
167 foreach $v (@{$_[0]}) {
168 push(@list, @{$v->{'words'}});
170 return (2, "$text{'mod_mime_ignenc'}",
171 &opt_input(@list ? join(" ", @list) : undef,
172 "RemoveEncoding", "$text{'mod_mime_none'}", 40));
174 sub save_RemoveEncoding
176 return &parse_opt("RemoveEncoding");
181 &extmap_input("AddCharset", "$text{'mod_mime_chars'}", 12, "$text{'mod_mime_xchars'}", $_[0]);
185 return &parse_extmap("AddCharset");
188 sub edit_DefaultLanguage
190 return (1, $text{'mod_mime_deflang'},
191 &opt_input($_[0]->{'value'}, "DefaultLanguage", $text{'mod_mime_none'},
194 sub save_DefaultLanguage
196 return &parse_opt("DefaultLanguage", '\S', $text{'mod_mime_edeflang'});
199 sub edit_AddOutputFilter
201 return (2, $text{'mod_mime_outfilter'},
202 &filtmap_input("AddOutputFilter", $_[0]));
204 sub save_AddOutputFilter
206 return &parse_filtmap("AddOutputFilter");
209 sub edit_AddInputFilter
211 return (2, $text{'mod_mime_infilter'},
212 &filtmap_input("AddInputFilter", $_[0]));
214 sub save_AddInputFilter
216 return &parse_filtmap("AddInputFilter");
219 # filtmap_input(name, &values)
222 local $rv = "<table border>\n".
223 "<tr $tb> <td><b>$text{'mod_mime_filters'}</b></td>\n".
224 "<td><b>$text{'mod_mime_ext'}</b></td> </tr>\n";
226 foreach $d (@{$_[1]}, { }) {
227 local @w = @{$d->{'words'}};
228 local @v = split(/;/, shift(@w));
230 $rv .= "<td>".&filters_input(\@v, $_[0]."_f_$i")."</td>\n";
231 $rv .= "<td><input name=$_[0]_e_$i size=30 value='".
232 join(" ", @w)."'></td>\n";
239 # parse_filtmap(name)
243 for($i=0; defined($in{"$_[0]_e_$i"}); $i++) {
244 local @f = split(/\0/, $in{"$_[0]_f_$i"});
246 local $exts = $in{"$_[0]_e_$i"};
247 $exts || &error(&text('mod_mime_efext', join(" ", @f)));
248 push(@rv, join(";", @f)." ".$exts);