[pLog-svn] r6088 - plog/branches/lifetype-1.2/class/security

Mark Wu markplace at gmail.com
Thu Nov 29 03:09:44 EST 2007


Hi Oscar:

Yep, I think paul add the 2nd for-loop to make sure the "rest of filters"
can have change to executed.

But, we have to remove those "executed" fiters when we re-run all pipeline
filters, or the same pipeline filter will execute twice.

** About the code re-format, mm.... I just trim the white space in the
end-of-line...

Mark

> -----Original Message-----
> From: plog-svn-bounces at devel.lifetype.net 
> [mailto:plog-svn-bounces at devel.lifetype.net] On Behalf Of 
> Oscar Renalias
> Sent: Thursday, November 29, 2007 3:49 PM
> To: LifeType Developer List
> Subject: Re: [pLog-svn] r6088 - 
> plog/branches/lifetype-1.2/class/security
> 
> Can you check if the second run of the pipeline has been 
> there since the very beginning of its implementation? I seem 
> to remember that it was added later on by Paul (but I could be wrong)
> 
> And another unrelated comment: are you doing some sort of 
> reformatting to the code or is your editor reformatting the 
> code? I find it difficult to follow your checkins sometimes 
> because 95% of the changes are due to reformatting...
> 
> On Nov 29, 2007 7:52 AM,  <mark at devel.lifetype.net> wrote:
> > Author: mark
> > Date: 2007-11-29 00:52:47 -0500 (Thu, 29 Nov 2007) New 
> Revision: 6088
> >
> > Modified:
> >    plog/branches/lifetype-1.2/class/security/pipeline.class.php
> > Log:
> > Fixed a the famous "pipeline run twice" bug 
> http://bugs.lifetype.net/view.php?id=616 .
> >
> > I change the strategy of filters process. I only run the 
> un-executed filters in 2nd for-loop.
> >
> > Modified: 
> plog/branches/lifetype-1.2/class/security/pipeline.class.php
> > ===================================================================
> > --- 
> plog/branches/lifetype-1.2/class/security/pipeline.class.php  
>       2007-11-28 20:30:55 UTC (rev 6087)
> > +++ 
> plog/branches/lifetype-1.2/class/security/pipeline.class.php  
>       2007-11-29 05:52:47 UTC (rev 6088)
> > @@ -3,19 +3,19 @@
> >      /**
> >       * \defgroup Security
> >       *
> > -     * The Security module provides a basic implementation 
> of a generic Pipeline to which we can
> > +     * The Security module provides a basic implementation of a 
> > + generic Pipeline to which we can
> >       * register "filters", which wil carry out specific 
> actions. Any of the filters can interrupt the
> >       * processing, depending on the logic of the filter. 
> Please see the Pipeline class for more information.
> >       */
> >
> >
> > -
> > +
> >      lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
> > -
> > +
> >      /**
> >       * global array used to hold the list of filters that 
> we're going to use in the pipeline.
> >       * Now again, more than ever, wish that PHP4 had 
> support for static attributes at the class
> > -     * level...
> > +     * level...
> >       */
> >      $_pLogPipelineRegisteredFilters = array();
> >
> > @@ -35,7 +35,7 @@
> >       * The out of the box implementation of the Pipeline 
> comes with a null filter (a filter that does nothing -- go figure :))
> >       * and a filter that implements a Bayesian filter for 
> advanced spam protection. See the BayesianFilter class for 
> more information.
> >       */
> > -    class Pipeline
> > +    class Pipeline
> >      {
> >
> >          /**
> > @@ -49,7 +49,7 @@
> >           * that is currently processing the incoming request
> >           */
> >          var $_blogInfo;
> > -
> > +
> >          /**
> >           * variable to hold the final result of executing 
> the pipeline
> >           */
> > @@ -64,14 +64,14 @@
> >           */
> >          function Pipeline( $httpRequest, $blogInfo = null )
> >          {
> > -
> >
> > +
> >              $this->_httpRequest = $httpRequest;
> >              $this->_blogInfo    = $blogInfo;
> > -
> > +
> >              $this->_registerDefaultFilters();;
> >          }
> > -
> > +
> >          /**
> >           * Method that takes care of registering the 
> default filters used in the pipeline.
> >           *
> > @@ -88,10 +88,10 @@
> >              $this->registerFilter( "NullPipelineFilter" );
> >              $this->registerFilter( "CommentFilter" );
> >              $this->registerFilter( "BayesianFilter" );
> > -
> > +
> >              return true;
> >          }
> > -
> > +
> >          /**
> >           * Static method that registers a filter externally
> >           *
> > @@ -102,11 +102,11 @@
> >          function registerFilter( $filterClass )
> >          {
> >              global $_pLogPipelineRegisteredFilters;
> > -
> > +
> >              if( 
> !is_array($_pLogPipelineRegisteredFilters))     // make sure 
> that we have an array...
> >                  $_pLogPipelineRegisteredFilters = Array();
> > -
> > -            
> $_pLogPipelineRegisteredFilters["$filterClass"] =  $filterClass;
> > +
> > +            
> $_pLogPipelineRegisteredFilters["$filterClass"] = false;
> >          }
> >
> >          /**
> > @@ -117,8 +117,8 @@
> >          {
> >              lt_include( PLOG_CLASS_PATH . 
> 'class/security/pipelinerequest.class.php' );
> >              lt_include( PLOG_CLASS_PATH . 
> 'class/security/pipelineresult.class.php' );
> > -            global $_pLogPipelineRegisteredFilters;
> > -
> > +            global $_pLogPipelineRegisteredFilters;
> > +
> >              // check if the pipeline is enabled
> >              $config =& Config::getConfig();
> >              if( $config->getValue( 
> "security_pipeline_enabled" ) == 
> > false ) { @@ -130,41 +130,48 @@
> >              $this->_result = new PipelineResult( true );
> >
> >              // if enabled, then check all the filters
> > -            foreach( $_pLogPipelineRegisteredFilters as 
> $filterClass ) {
> > +            foreach( $_pLogPipelineRegisteredFilters as 
> $filterClass 
> > + => $executed ) {
> >                  // create an instance of the filter
> >                  $pipelineRequest = new PipelineRequest( 
> $this->_httpRequest, $this->_blogInfo );
> >                  $filter = new $filterClass( $pipelineRequest );
> > -                // and execute it...
> > +                // and execute it...
> >                  $result = $filter->filter();
> > +                               // and cahge the executed 
> flag to ture
> > +                               
> > + $_pLogPipelineRegisteredFilters["$filterClass"] = true;
> >                  // if there was an error, we better say so now
> >                  // and quite, making sure that we're keeping the
> >                  // error code
> > -
> > +
> >                  // Save off the result
> >                                 $this->_result = $result;
> > -
> > -                if( !$result->isValid()) {
> > +
> > +                if( !$result->isValid()) {
> >                      // break out of this loop
> >                      break;
> >                  }
> >              }
> > -
> > +
> >              // If one of the filters returns that this was 
> not a valid result
> >              if ( !$this->_result->isValid() ) {
> > -                // Now rerun through all of the filters so 
> they can clean up
> > +                // Now rerun through all of the filters so 
> they can 
> > + clean up
> >                  // if they have saved anything persistantly
> > -                // This also gives filters a chance to do 
> anything else they
> > +                // This also gives filters a chance to do anything 
> > + else they
> >                  // want to do (i.e. report ip address to dns 
> > blacklist)
> > -
> > -                foreach( $_pLogPipelineRegisteredFilters 
> as $filterClass ) {
> > -                    // create an instance of the filter
> > -                    $pipelineRequest = new 
> PipelineRequest( $this->_httpRequest,
> > -                                                           
>  $this->_blogInfo,
> > -                                                            true );
> > -                    $filter = new $filterClass( $pipelineRequest );
> > -                    // and execute it...
> > -                    $result = $filter->filter();
> > -                    // if there was an error, we want to keep going
> > +
> > +                foreach( $_pLogPipelineRegisteredFilters 
> as $filterClass => $executed ) {
> > +                    // We just need to run the unexecuted filters
> > +                    if( !$executed ) {
> > +                        // create an instance of the filter
> > +                        $pipelineRequest = new 
> PipelineRequest( $this->_httpRequest,
> > +                                                           
>      $this->_blogInfo,
> > +                                                           
>      true );
> > +                        $filter = new $filterClass( 
> $pipelineRequest );
> > +                        // and execute it...
> > +                        $result = $filter->filter();
> > +                                       // and cahge the 
> executed flag to ture
> > +                                       
> $_pLogPipelineRegisteredFilters["$filterClass"] = true;
> > +                        // if there was an error, we want 
> to keep going
> > +                    }
> >                  }
> >              }
> >
> >
> > _______________________________________________
> > pLog-svn mailing list
> > pLog-svn at devel.lifetype.net
> > http://limedaley.com/mailman/listinfo/plog-svn
> >
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.lifetype.net
> http://limedaley.com/mailman/listinfo/plog-svn



More information about the pLog-svn mailing list