From: naoki i. <am...@us...> - 2008-04-17 15:13:31
|
Update of /cvsroot/popfile/engine/Classifier In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6287/Classifier Modified Files: Bayes.pm Log Message: Change Log 1. The session keys are now released when they are expired 2. New global parameter 'GLOBAL_session_timeout' (default : 1800 seconds) 3. Replaced get_administrator_session_key with get_single_user_session_key Classifier/Bayes.pm UI/HTML.pm POPFile/History.pm POPFile/Configuration.pm tests/TestConfiguration.tst The session keys which does not used in GLOBAL_session_timeout seconds will be released. NOTE : The session key for the administrator which got from get_administrator_session_key won't be expired. For this reason, please use get_single_user_session_key instead of get_administrator_session_key in the single user mode. NOTE : The 'last used time' is updated when valid_session_key__ is called with the session key. 4. Added 'Single User Mode Parameters' section in the Advanced tab UI/HTML.pm skins/default/advanced-page.thtml languages/English.msg languages/Nihongo.msg All POPFile parameters now can be changed in the single user mode. 'Single User Mode Parameters' section has been added below the 'Global POPFile Parameters' section. 5. Updated translation file languages/Nihongo.msg 6. The session cache is purged when the session key is released 7. The query is stopped when the session key is released UI/HTML.pm 8. Added escape_html_() function in HTTP.pm UI/HTTP.pm UI/HTML.pm tests/TestHTML.script This function is used for escaping ", <, >, &, ' characters. They are converted to ", <, >, & and ' 9. The matched header is showed/emphasized if the magnets are used UI/HTML.pm POPFile/History.pm Classifier/Bayes.pm tests/TestHTML.script The magnet icon's "title" will be like 'From:te...@ex...' in the history tab. The header information will be showed/emphasized in the single message view. 10. Minor fixes of the skins skins/default/common-bottom.thtml skins/default/users-page.thtml skins/default/administration-page.thtml skins/default/pop3-chain-panel.thtml skins/default/pop3-configuration-panel.thtml skins/default/socks-widget.thtml skins/default/nntp-configuration.thtml skins/default/smtp-configuration.thtml skins/default/windows-configuration.thtml Proxy/POP3.pm Proxy/NNTP.pm Proxy/SMTP.pm Platform/MSWin32.pm tests/TestPOP3.tst tests/TestHTML.tst Current state of the test suite: TestBayesScript PASS TestBayes PASS TestConfiguration PASS * TestHistory PASS TestHTML PASS * TestHTTP PASS TestIMAP PASS TestInsertScript PASS * TestLogger PASS TestMailParse PASS TestModule PASS TestMQ PASS TestMutex PASS TestPipeScript PASS TestPOP3 PASS TestProxy PASS TestWordMangle PASS TestXMLRPC PASS * : TODO : needs to add tests for multi user support Index: Bayes.pm =================================================================== RCS file: /cvsroot/popfile/engine/Classifier/Bayes.pm,v retrieving revision 1.366 retrieving revision 1.367 diff -C2 -d -r1.366 -r1.367 *** Bayes.pm 16 Apr 2008 13:08:04 -0000 1.366 --- Bayes.pm 17 Apr 2008 15:13:04 -0000 1.367 *************** *** 271,275 **** if ( $type eq 'CREAT' ) { my ( $session, $user ) = ( $message[0], $message[1] ); ! $self->{api_sessions__}{$session} = $user; $self->db_update_cache__( $session ); $self->log_( 1, "CREAT message on $session for $user" ); --- 271,276 ---- if ( $type eq 'CREAT' ) { my ( $session, $user ) = ( $message[0], $message[1] ); ! $self->{api_sessions__}{$session}{userid} = $user; ! $self->{api_sessions__}{$session}{lastused} = time; $self->db_update_cache__( $session ); $self->log_( 1, "CREAT message on $session for $user" ); *************** *** 314,318 **** $self->upgrade_predatabase_data__(); ! $self->upgrade_v1_data__(); # Since Text::Kakasi is not thread-safe, we use it under the --- 315,319 ---- $self->upgrade_predatabase_data__(); ! $self->upgrade_v1_parameters__(); # Since Text::Kakasi is not thread-safe, we use it under the *************** *** 372,375 **** --- 373,394 ---- #---------------------------------------------------------------------------- # + # service + # + # service() is a called periodically to give the module a chance to do + # housekeeping work. + # + # + #---------------------------------------------------------------------------- + sub service + { + my ( $self ) = @_; + + $self->release_expired_sessions__(); + + return 1; + } + + #---------------------------------------------------------------------------- + # # forked # *************** *** 473,479 **** --- 492,501 ---- #---------------------------------------------------------------------------- + # # cleanup_orphan_words__ + # # Removes Words from (words) no longer associated with a bucket # Called when the TICKD message is received each hour. + # #---------------------------------------------------------------------------- sub cleanup_orphan_words__ *************** *** 736,750 **** where bucket_template.id = ?;' ); # PROFILE BLOCK STOP ! $self->{db_get_user_parameter__} = $self->db_()->prepare( # PROFILE BLOCK START 'select user_params.val from user_params where user_params.userid = ? and ! user_params.utid = ?;' ); # PROFILE BLOCK STOP ! $self->{db_set_user_parameter__} = $self->db_()->prepare( # PROFILE BLOCK START ! 'replace into user_params ( userid, utid, val ) values ( ?, ?, ? );' ); # PROFILE BLOCK STOP ! $self->{db_get_user_parameter_default__} = $self->db_()->prepare( # PROFILE BLOCK START 'select user_template.def from user_template ! where user_template.id = ?;' ); # PROFILE BLOCK STOP $self->{db_get_buckets_with_magnets__} = $self->db_()->prepare( # PROFILE BLOCK START --- 758,772 ---- where bucket_template.id = ?;' ); # PROFILE BLOCK STOP ! $self->{db_get_user_parameter__} = $self->db_()->prepare( # PROFILE BLOCK START 'select user_params.val from user_params where user_params.userid = ? and ! user_params.utid = ?;' ); # PROFILE BLOCK STOP ! $self->{db_set_user_parameter__} = $self->db_()->prepare( # PROFILE BLOCK START ! 'replace into user_params ( userid, utid, val ) values ( ?, ?, ? );' ); # PROFILE BLOCK STOP ! $self->{db_get_user_parameter_default__} = $self->db_()->prepare( # PROFILE BLOCK START 'select user_template.def from user_template ! where user_template.id = ?;' ); # PROFILE BLOCK STOP $self->{db_get_buckets_with_magnets__} = $self->db_()->prepare( # PROFILE BLOCK START *************** *** 957,963 **** # There's an assumption here that this is the single user version # of POPFile and hence what we do is cheat and get a session key ! # assuming that the user name is admin with password '' ! my $session = $self->get_administrator_session_key(); if ( !defined( $session ) ) { --- 979,985 ---- # There's an assumption here that this is the single user version # of POPFile and hence what we do is cheat and get a session key ! # for the single user mode ! my $session = $self->get_single_user_session_key(); if ( !defined( $session ) ) { *************** *** 1196,1205 **** #---------------------------------------------------------------------------- # ! # upgrade_v1_data__ # # If the deprecated parameters found, upgrades them to the SQL database. # #---------------------------------------------------------------------------- ! sub upgrade_v1_data__ { my ( $self ) = @_; --- 1218,1227 ---- #---------------------------------------------------------------------------- # ! # upgrade_v1_parameters__ # # If the deprecated parameters found, upgrades them to the SQL database. # #---------------------------------------------------------------------------- ! sub upgrade_v1_parameters__ { my ( $self ) = @_; *************** *** 1576,1580 **** if ( defined( $self->{api_sessions__}{$session} ) ) { ! $self->log_( 1, "release_session_key releasing key $session for user $self->{api_sessions__}{$session}" ); delete $self->{api_sessions__}{$session}; } --- 1598,1602 ---- if ( defined( $self->{api_sessions__}{$session} ) ) { ! $self->log_( 1, "release_session_key releasing key $session for user $self->{api_sessions__}{$session}{userid}" ); delete $self->{api_sessions__}{$session}; } *************** *** 1608,1614 **** $self->log_( 0, "Invalid session key $session provided in $package @ $line" ); select( undef, undef, undef, 1 ); } ! return $self->{api_sessions__}{$session}; } --- 1630,1666 ---- $self->log_( 0, "Invalid session key $session provided in $package @ $line" ); select( undef, undef, undef, 1 ); + + return undef; } ! # Update the last access time ! ! $self->{api_sessions__}{$session}{lastused} = time; ! ! return $self->{api_sessions__}{$session}{userid}; ! } ! ! #---------------------------------------------------------------------------- ! # ! # release_expired_sessions__ ! # ! # Releases the expired session keys ! # Called when the TICKD message is received each hour. ! # ! #---------------------------------------------------------------------------- ! sub release_expired_sessions__ ! { ! my ( $self ) = @_; ! ! my $timeout = time - $self->global_config_( 'session_timeout' ); ! ! foreach my $session ( keys %{$self->{api_sessions__}} ) { ! next if ( defined( $self->{api_sessions__}{$session}{notexpired} ) ); ! ! if ( $self->{api_sessions__}{$session}{lastused} < $timeout ) { ! $self->log_( 1, "Session key $session will be expired due to a timeout" ); ! $self->release_session_key( $session ); ! } ! } } *************** *** 1668,1676 **** my $session = $self->generate_unique_session_key__(); ! $self->{api_sessions__}{$session} = $result->[0]; $self->db_update_cache__( $session ); ! $self->log_( 1, "get_session_key returning key $session for user $self->{api_sessions__}{$session}" ); return $session; --- 1720,1729 ---- my $session = $self->generate_unique_session_key__(); ! $self->{api_sessions__}{$session}{userid} = $result->[0]; ! $self->{api_sessions__}{$session}{lastused} = time; $self->db_update_cache__( $session ); ! $self->log_( 1, "get_session_key returning key $session for user $self->{api_sessions__}{$session}{userid}" ); return $session; *************** *** 1747,1751 **** my $session = $self->generate_unique_session_key__(); ! $self->{api_sessions__}{$session} = 1; $self->db_update_cache__( $session ); $self->log_( 1, "get_administrator_session_key returning key $session" ); --- 1800,1806 ---- my $session = $self->generate_unique_session_key__(); ! $self->{api_sessions__}{$session}{userid} = 1; ! $self->{api_sessions__}{$session}{lastused} = time; ! $self->{api_sessions__}{$session}{notexpired} = 1; # does not be expired $self->db_update_cache__( $session ); $self->log_( 1, "get_administrator_session_key returning key $session" ); *************** *** 1768,1772 **** my $single_user_session = $self->generate_unique_session_key__(); ! $self->{api_sessions__}{$single_user_session} = 1; $self->db_update_cache__( $single_user_session ); $self->log_( 1, "get_single_user_session_key returning key $single_user_session for the single user mode" ); --- 1823,1828 ---- my $single_user_session = $self->generate_unique_session_key__(); ! $self->{api_sessions__}{$single_user_session}{userid} = 1; ! $self->{api_sessions__}{$single_user_session}{lastused} = time; $self->db_update_cache__( $single_user_session ); $self->log_( 1, "get_single_user_session_key returning key $single_user_session for the single user mode" ); *************** *** 1868,1872 **** my $user_session = $self->generate_unique_session_key__(); ! $self->{api_sessions__}{$user_session} = $user; $self->db_update_cache__( $user_session ); $self->log_( 1, "get_session_key_from_token returning key $user_session for user $user" ); --- 1924,1929 ---- my $user_session = $self->generate_unique_session_key__(); ! $self->{api_sessions__}{$user_session}{userid} = $user; ! $self->{api_sessions__}{$user_session}{lastused} = time; $self->db_update_cache__( $user_session ); $self->log_( 1, "get_session_key_from_token returning key $user_session for user $user" ); *************** *** 4758,4761 **** --- 4815,4853 ---- #---------------------------------------------------------------------------- # + # get_magnet_header_and_value + # + # Get the header and value of the magnet + # + # $session A valid session key returned by a call to get_session_key + # $magnetid The ID for the magnet + # + #---------------------------------------------------------------------------- + sub get_magnet_header_and_value + { + my ( $self, $session, $magnetid ) = @_; + + my $userid = $self->valid_session_key__( $session ); + return undef if ( !defined( $userid ) ); + + my $m = $self->db_()->prepare( + "select magnet_types.header, magnets.val from magnet_types, magnets + where magnet_types.id = magnets.mtid and magnets.id = ?;" ); + + $m->execute( $magnetid ); + my $result = $m->fetchrow_arrayref; + $m->finish; + + if ( defined( $result ) ) { + my $header = $result->[0]; + my $value = $result->[1]; + + return ( $header, $value ); + } + + return undef; + } + + #---------------------------------------------------------------------------- + # # get_stopword_list # |