Changeset 117

Show
Ignore:
Timestamp:
17.12.2006 00:48:10 (2 years ago)
Author:
decoder
Message:

Config.pm code modified to make parsing and start up of configuration only possible once
This is an experimental approach to fix issues with amavisd and other third party tools,
that are using the SA API directly.

Added multi-image sample file.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/devel/FuzzyOcr.pm

    r113 r117  
    310310 
    311311    # Try to load personal wordlist 
    312     if ($conf->{focr_personal_wordlist} =~ m/^\//) { 
    313         read_words( $conf->{focr_personal_wordlist} ); 
    314     } else { 
    315         my $peruserlist = $main->sed_path($conf->{focr_personal_wordlist}); 
    316         if ( -r $peruserlist ) { 
    317             read_words( $peruserlist ); 
     312    unless ($conf->{focr_no_homedirs}) { 
     313        if ($conf->{focr_personal_wordlist} =~ m/^\//) { 
     314            read_words( $conf->{focr_personal_wordlist} ); 
    318315        } else { 
    319             # Only complain if the file exists 
    320             if ( -e $peruserlist ) { 
    321                 errorlog("Cannot read personal_wordlist: $peruserlist, skipping..."); 
    322             } 
    323         } 
    324     } 
    325  
     316            my $peruserlist = $main->sed_path($conf->{focr_personal_wordlist}); 
     317            if ( -r $peruserlist ) { 
     318                read_words( $peruserlist ); 
     319            } else { 
     320                # Only complain if the file exists 
     321                if ( -e $peruserlist ) { 
     322                    errorlog("Cannot read personal_wordlist: $peruserlist, skipping..."); 
     323                } 
     324            } 
     325        } 
     326    } 
    326327    my $haserr; 
    327328    foreach my $filename (keys %imgfiles) { 
  • trunk/devel/FuzzyOcr/Config.pm

    r116 r117  
    5555our $dbref; 
    5656 
     57# State of the plugin, already initialized? 
     58our $initialized = 0; 
     59 
    5760our @bin_utils = qw/gifsicle 
    5861    giffix 
     
    304307        type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING 
    305308    }); 
    306  
     309    push (@cmds, { 
     310        setting => 'focr_no_homedirs', 
     311        default => 0, 
     312        type => $Mail::SpamAssassin::Conf::CONF_TYPE_BOOL 
     313    }); 
    307314    push (@cmds, { 
    308315        setting => 'focr_db_hash', 
     
    508515sub parse_config { 
    509516    my ($self, $opts) = @_; 
     517 
     518    # Don't parse a config twice 
     519    if ($initialized) { return 1; } 
     520 
    510521    if ($opts->{key} eq 'focr_end_config') { 
    511522        $conf = $opts->{conf}; 
     
    514525 
    515526        # Parse preprocessor file 
    516         my $pfile = $main->sed_path($conf->{'focr_preprocessor_file'})
     527        my $pfile = $conf->{'focr_preprocessor_file'}
    517528        infolog("Starting preprocessor parser for file \"$pfile\"..."); 
    518529        ($retcode, @preprocessors) = parse_preprocessors($pfile); 
     
    523534 
    524535        # Parse scanset file 
    525         my $sfile = $main->sed_path($conf->{'focr_scanset_file'})
     536        my $sfile = $conf->{'focr_scanset_file'}
    526537        infolog("Starting scanset parser for file \"$sfile\"..."); 
    527538        ($retcode, @scansets) = parse_scansets($sfile); 
     
    530541            return 0; 
    531542        } 
     543 
    532544        return 1; 
    533545    } elsif ($opts->{key} eq 'focr_bin_helper') { 
     
    557569sub finish_parsing_end { 
    558570    my ($self, $opts) = @_; 
     571 
     572    # Don't call this function twice 
     573    if ($initialized) { return 1; } 
     574 
    559575    my $main = $self->{main}; 
    560576    $conf = $opts->{conf}; 
     
    638654            errorlog("Missing DBI") unless HAS_DBI; 
    639655            errorlog("Missing DBD::mysql") unless HAS_DBD_MYSQL; 
     656        } 
     657 
     658        # Warn if MLDBM databases are present, but can't be imported 
     659        unless (HAS_MLDBM and HAS_DB_FILE and HAS_STORABLE and (-r $conf->{focr_db_hash} or -r $conf->{focr_db_safe})) { 
     660            infolog("Importing for MLDBM databases not available (dependencies missing)"); 
    640661        } 
    641662    } 
     
    717738            } 
    718739        } 
    719         if ($conf->{focr_enable_image_hashing} == 3 and defined (my $ddb = get_mysql_ddb())) { 
     740        if ($conf->{focr_enable_image_hashing} == 3 and defined (my $ddb = get_mysql_ddb()) 
     741            and (-r $conf->{focr_db_hash} or -r $conf->{focr_db_safe}) 
     742            and HAS_MLDBM and HAS_DB_FILE and HAS_STORABLE) { 
     743 
    720744            import MLDBM qw(DB_File Storable); 
    721745            my $db   = $conf->{focr_mysql_db}; 
     
    802826    read_words( $conf->{focr_global_wordlist} , 'Global'); 
    803827    1; 
     828 
     829    # Important: We parsed the config now and did all post config parsing stuff 
     830    # don't do it again (for amavisd and other 3rd party applications using the SA API directly) 
     831    $initialized = 1; 
    804832} 
    805833