# # -*- Perl -*- # $Id: zip.pl,v 1.10.4.6 2005/06/06 06:13:35 opengl2772 Exp $ # zip filter for namazu # Copyright (C) 2004 MATSUMURA Namihiko # 2004 Yukio USUDA # 2004-2005 Namazu Project All rights reserved. # # This is free software with ABSOLUTELY NO WARRANTY. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either versions 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA # package lit; use strict; require 'util.pl'; sub mediatype() { return ('application/lit'); } my $clitpath="clit"; sub status() { return 'yes' if (util::checkcmd($clitpath)); return 'no'; } sub recursive() { return 0; } sub pre_codeconv() { return 0; } sub post_codeconv () { return 0; } sub add_magic ($) { my ($magic) = @_; $magic->addFileExts('\\.lit', 'application/lit'); $magic->addFileExts('\\.LIT', 'application/lit'); return; } sub filter ($$$$$) { my ($orig_cfile, $contref, $weighted_str, $headings, $fields) = @_; my $tmpfile; my $uniqnumber = int(rand(10000)); do { $tmpfile = util::tmpnam('NMZ.lit' . substr("000$uniqnumber", -4)); $uniqnumber++; } while (-f $tmpfile); { my $fh = util::efopen("> $tmpfile"); print $fh $$contref; util::fclose($fh); } $$contref =""; my $err = undef; $err = unlit_filter($tmpfile, $contref, $weighted_str, $headings, $fields); unlink($tmpfile); return $err; } sub unlit_filter ($$$$$) { my ($status,@cmd); my ($tmpfile, $contref, $weighted_str, $headings, $fields) = @_; util::vprint("Processing lit file ... (using '$clitpath')\n"); my $tmpfile2 = util::tmpnam('NMZ.lit_dir'); my $tmpfile3 = util::tmpnam('NMZ.lit_ls'); mkdir($tmpfile2); @cmd = ("$clitpath", "$tmpfile","$tmpfile2"); $status = util::syscmd( command => \@cmd, option => { "stdout" => $tmpfile3, "stderr" => "/dev/null", }, ); if ($status == 0) { my $summary = util::readfile("$tmpfile3"); # codeconv::toeuc(\$summary); codeconv::codeconv_document(\$summary); #$$contref .= $summary . " "; } else { unlink($tmpfile); unlink($tmpfile3); system("rm","-rf","$tmpfile2"); return 'Unable to convert lit file (maybe copying protection)'; } my %files; my $filenames = undef; if ($status == 0) { my $filelist = util::readfile("$tmpfile3"); codeconv::normalize_document(\$filelist); while ($filelist =~/\n\.\.\.\.\.\s+ # five dots?! ([^"]+)\s+ # filename "(\S+)"--\s+ # mime-type (.*) # description /gx){ # my $filename = "$tmpfile2/$1"; my $desc=$3; $files{$filename} = [stat($filename)]->[7]; # codeconv::toeuc(\$filename); codeconv::codeconv_document(\$filename); $filename = gfilter::filename_to_title($desc, $weighted_str); $filenames .= $desc . " "; } } $$contref .= $filenames . " " if (defined $filenames); unlink($tmpfile3); my $fname; foreach $fname (keys %files){ my $size = $files{$fname}; if ($size == 0) { util::dprint("$fname: filesize is 0"); } elsif ($size > $conf::FILE_SIZE_MAX) { util::dprint("$fname: Too large lit file"); } elsif ($fname =~ m!^($conf::DENY_FILE)$!i ) { # codeconv::toeuc(\$fname); codeconv::codeconv_document(\$fname); util::vprint(sprintf(_("Denied: %s"), $fname)); } elsif ($fname !~ m!^($conf::ALLOW_FILE)$!i) { # codeconv::toeuc(\$fname); codeconv::codeconv_document(\$fname); util::vprint(sprintf(_("Not allowed: %s"), $fname)); } else { my $con = ""; util::vprint("processing $fname"); my $err = lit::nesting_filter($fname, \$con, $weighted_str); if (defined $err) { util::dprint("filter/lit.pl gets error message \"$err\""); } $$contref .= $con . " "; } }; system("rm","-rf","$tmpfile2"); return undef; } sub nesting_filter ($$$){ my ($filename, $contref, $weighted_str) = @_; my $err = undef; my $dummy_shelterfname = ""; my $headings = ""; my %fields; my $mmtype = undef; my ($kanji, $mtype) = mknmz::apply_filter(\$filename, $contref, $weighted_str, \$headings, \%fields, $dummy_shelterfname, $mmtype); if ($mtype =~ /; x-system=unsupported$/){ $$contref = ""; $err = $mtype; }elsif ($mtype =~ /; x-error=(.*)$/){ $$contref = ""; $err = $1; }else{ gfilter::show_filter_debug_info($contref, $weighted_str, \%fields, \$headings); for my $field (keys %fields) { $$contref .= " ". $fields{$field}; } $$contref .= util::readfile("$filename"); } return $err; } 1;