Changeset 45

Show
Ignore:
Timestamp:
21.11.2006 00:51:34 (2 years ago)
Author:
jorge
Message:

If using image hashing, check that required perl modules are available, or disable hashing and send a message to the logger why hashing was disabled and which modules are missing.
This should make the plugin work even though we do not have the required parameters for the optional hashing database.

Files:

Legend:

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

    r42 r45  
    1919use Mail::SpamAssassin::Logger; 
    2020use Fcntl ':flock'; 
    21 use DBI; 
     21 
     22use constant HAS_DBI => eval { require DBI; }; 
     23use constant HAS_DBD_MYSQL => eval { require DBD::mysql; }; 
     24use constant HAS_MLDBM => eval { require MLDBM; }; 
     25use constant HAS_DB_FILE => eval { require DB_File; }; 
     26use constant HAS_STORABLE => eval { require Storable; }; 
    2227 
    2328#Defines the defaults and reads the configuration and wordlists 
     
    8186 
    8287sub get_ddb { 
     88    return undef unless (HAS_DBI and HAS_DBD_MYSQL); 
    8389    my $conf = get_config(); 
    8490    my %dopts = ( AutoCommit => 1 ); 
     
    366372    } 
    367373 
     374    if ($conf->{focr_enable_image_hashing} == 3) { 
     375        unless (HAS_DBI and HAS_DBD_MYSQL) { 
     376            $conf->{focr_enable_image_hashing} = 0; 
     377            debuglog("Disable Image Hashing"); 
     378            debuglog("Missing DBI") unless HAS_DBI; 
     379            debuglog("Missing DBD::mysql") unless HAS_DBD_MYSQL; 
     380        } 
     381    } 
     382    if ($conf->{focr_enable_image_hashing} == 2) { 
     383        unless (HAS_MLDBM and HAS_DB_FILE and HAS_STORABLE) { 
     384            $conf->{focr_enable_image_hashing} = 0; 
     385            debuglog("Disable Image Hashing"); 
     386            debuglog("Missing MLDBM") unless HAS_MLDBM; 
     387            debuglog("Missing DB_File") unless HAS_DB_FILE; 
     388            debuglog("Missing Storable") unless HAS_STORABLE; 
     389        } 
     390    } 
    368391    if ($conf->{focr_enable_image_hashing} == 2 and -r $conf->{focr_digest_db}) { 
    369392        my %DB; my $dbm; my $err = 0; 
     
    429452    if ($conf->{focr_enable_image_hashing} == 3) { 
    430453        my $ddb = $conf->{focr_ddb} = get_ddb(); 
    431         if (defined $conf->{focr_ddb}) { 
     454        if (defined $ddb) { 
    432455            my $db   = $conf->{focr_mysql_db}; 
    433456            my $tab  = $conf->{focr_mysql_hash}; 
  • trunk/devel/FuzzyOcr/Hashing.pm

    r44 r45  
    99use lib "../"; 
    1010use FuzzyOcr::Config qw(get_thresholds get_config set_config debuglog logfile); 
    11 use DBI; 
    12 use MLDBM qw(DB_File Storable); 
    1311use Fcntl; 
    1412use Fcntl ':flock'; 
     
    6058    return (0,'') if ( 
    6159        ($conf->{focr_enable_image_hashing} == 0) or 
    62         (not defined $conf->{focr_ddb}) 
     60        ($conf->{focr_enable_image_hashing} == 3 and not defined $conf->{focr_ddb}) 
    6361    ); 
    6462    my $digest = $_[0]; 
     
    134132    } 
    135133    elsif ($conf->{focr_enable_image_hashing} == 2) { 
     134        use MLDBM qw(DB_File Storable); 
    136135        my %DB = (); my $dbm; 
    137136        tie %DB, 'MLDBM', $dbfile, O_RDWR or $ret++; 
     
    242241    } 
    243242    elsif ($conf->{focr_enable_image_hashing} == 2) { 
     243        use MLDBM qw(DB_File Storable); 
    244244        my $dbfile = $_[2] || $conf->{focr_db_hash}; 
    245245        my %DB = (); 
     
    341341    my $ret; 
    342342 
    343     debuglog("fmt_time: When =  $when"); 
    344343    if ($when>86400) { 
    345344        my $d = int($when/86400);