⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filter.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 2 页
字号:
      return Apache2::Const::OK;  }Usually arguments C<$mode>, C<$block>, C<$readbytes> are the same aspassed to the filter itself.You can see that in case of a failure, the handler returns immediatelywith that failure code, which gets propagated to the downstreamfilter.If you decide not check the return code, you can write it as:  sub filter {      my ($f, $bb, $mode, $block, $readbytes) = @_;            $f->next->get_brigade($bb, $mode, $block, $readbytes);            # ... process $bb            return Apache2::Const::OK;  }and the error checking will be done on your behalf.You will find many more examples in C<the filterhandlers|docs::2.0::user::handlers::filters> andC<the protocolhandlers|docs::2.0::user::handlers::protocols> tutorials.=head2 C<pass_brigade>This is a method to use in bucket brigade output filters.  It passesthe current bucket brigade to the downstream output filter.  $rc = $next_f->pass_brigade($bb);=over 4=item obj: C<$next_f>( C<L<Apache2::Filter object|docs::2.0::api::Apache2::Filter>> )The next filter in the filter chain.Inside L<output filter handlers|docs::2.0::user::handlers::filters>it's usually C<L<$f-E<gt>next|/C_next_>>. Inside L<protocolhandlers|docs::2.0::user::handlers::protocols>:C<L<$c-E<gt>output_filters|docs::2.0::api::Apache2::Connection/C_output_filters_>>.=item arg1: C<$bb>( C<L<APR::Brigade object|docs::2.0::api::APR::Brigade>> )The bucket brigade to pass.Inside L<output filterhandlers|docs::2.0::user::handlers::filters> it's usually the second argument to the filter handler (after potential manipulations).=item ret: C<$rc> ( C<L<APR::Const statusconstant|docs::2.0::api::APR::Const>> )On success,C<L<APR::Const::SUCCESS|docs::2.0::api::APR::Const/C_APR__Const__SUCCESS_>> isreturned.In case of a failure -- a failure code is returned, in which casenormally it should be returned to the caller.If the bottom-most filter doesn't write to the network, thenC<Apache2::NOBODY_WROTE> is returned (META: need to add this constant).Also refer to the C<L<get_brigade()|/C_get_brigade_>> entry to see howto avoid checking the errors explicitly.=item excpt: C<L<APR::Error|docs::2.0::api::APR::Error>>Exceptions are thrown only when this function is called in the VOIDcontext. Refer to the C<L<get_brigade()|/C_get_brigade_>> entry fordetails.=item since: 2.0.00=backThe caller relinquishes ownership of the brigade (i.e. it may getdestroyed/overwritten/etc. by the callee).Example:Here is a fragment of a filter handler, that passes a bucket brigadeto the downstream filter (after some potential processing of thebuckets in the bucket brigade):  use Apache2::Filter ();  use APR::Const    -compile => qw(SUCCESS);  use Apache2::Const -compile => qw(OK);  sub filter {      my ($f, $bb) = @_;        # ... process $bb        my $rc = $f->next->pass_brigade($bb);      return $rc unless $rc == APR::Const::SUCCESS;        return Apache2::Const::OK;  }=head1 Streaming Filter APIThe following methods can be called from any filter, which uses thesimplified streaming functionality:=head2 C<print>Send the contents of C<$buffer> to the next filter in chain (viainternal buffer).  $sent = $f->print($buffer);=over 4=item obj: C<$f>( C<L<Apache2::Filter object|docs::2.0::api::Apache2::Filter>> )=item arg1: C<$buffer> ( string )The data to send.=item ret: C<$sent> ( integer )How many characters were sent. There is no need to check, since allshould go through and if something goes work an exception will bethrown.=item excpt: C<L<APR::Error|docs::2.0::api::APR::Error>>=item since: 2.0.00=backThis method should be used only in L<streamingfilters|docs::2.0::user::handlers::filters>.=head2 C<read>Read data from the filter  $read = $f->read($buffer, $wanted);=over 4=item obj: C<$f>( C<L<Apache2::Filter object|docs::2.0::api::Apache2::Filter>> )=item arg1: C<$buffer> ( SCALAR )The buffer to fill. All previous data will be lost.=item opt arg2: C<$wanted> ( integer )How many bytes to attempt to read.If this optional argument is not specified -- the default 8192 will beused.=item ret: C<$read> ( integer )How many bytes were actually read.C<$buffer> gets populated with the string that is read. It willcontain an empty string if there was nothing to read.=item excpt: C<L<APR::Error|docs::2.0::api::APR::Error>>=item since: 2.0.00=backReads at most C<$wanted> characters into C<$buffer>. The returnedvalue C<$read> tells exactly how many were read, making it easy to useit in a while loop:  while ($filter->read(my $buffer, $wanted)) {      # transform $buffer here      $filter->print($buffer);  }This is a streaming filter method, which acquires a single bucketbrigade behind the scenes and reads data from all itsbuckets. Therefore it can only read from one bucket brigade per filterinvocation.If the EOS bucket is read, the C<L<seen_eos|/C_seen_eos_>> method willreturn a true value.=head2 C<seen_eos>This methods returns a true value when the EOS bucket is seen by theC<L<read|/C_read_>> method.  $ok = $f->seen_eos;=over 4=item obj: C<$f>( C<L<Apache2::Filter object|docs::2.0::api::Apache2::Filter>> )The filter to remove=item ret: C<$ok> ( boolean )a true value if EOS has been seen, otherwise a false value=item since: 2.0.00=backThis method only works in streaming filters which exhaustivelyC<L<$f-E<gt>read|/C_read_>> all the incoming data in a while loop,like so:      while ($f->read(my $buffer, $wanted)) {          # do something with $buffer      }      if ($f->seen_eos) {          # do something      }The technique in this example is useful when a streaming filter wantsto append something to the very end of data, or do something at theend of the last filter invocation. After the EOS bucket is read, thefilter should expect not to be invoked again.If an input streaming filter doesn't consume all data in the bucketbrigade (or even in several bucket brigades), it has to generate theEOS event by itself. So when the filter is done it has to set the EOSflag:  $f->seen_eos(1);when the filter handler returns, internally mod_perl will take care ofcreating and sending the EOS bucket to the upstream input filter.A similar logic may apply for output filters.In most other cases you shouldn't set this flag.  When this flag isprematurely set (before the real EOS bucket has arrived) in thecurrent filter invocation, instead of invoking the filter again,mod_perl will create and send the EOS bucket to the next filter,ignoring any other bucket brigades that may have left to consume. Asmentioned earlier this special behavior is useful in writing specialtests that test abnormal situations.=head1 Other Filter-related APIOther methods which affect filters, but called onnon-C<Apache2::Filter> objects:=head2 C<add_input_filter>Add C<&callback> filter handler to input request filter chain.  $r->add_input_filter(\&callback);Add C<&callback> filter handler to input connection filter chain.  $c->add_input_filter(\&callback);=over 4=item obj: C<$c>( C<L<Apache2::Connection object|docs::2.0::api::Apache2::Connection>> ) or C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item arg1: C<&callback> (CODE ref)=item ret: no return value=item since: 2.0.00=back[META: It seems that you can't add a filter when another filter iscalled. I've tried to add an output connection filter from the inputconnection filter when it was called for the first time. It didn'thave any affect for the first request (over keepalive connection). Theonly way I succeeded to do that is from that input connection filter'sfilter_init handler.In fact it does work if there is any filter additional filter of thesame kind configured from httpd.conf or via filter_init. It looks likethere is a bug in httpd, where it doesn't prepare the chain of 3rdparty filter if none were inserted before the first filter was called.]=head2 C<add_output_filter>Add C<&callback> filter handler to output request filter chain.  $r->add_output_filter(\&callback);Add C<&callback> filter handler to output connection filter chain.  $c->add_output_filter(\&callback);=over 4=item obj: C<$c>( C<L<Apache2::Connection object|docs::2.0::api::Apache2::Connection>> ) or C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item arg1: C<&callback> (CODE ref)=item ret: no return value=item since: 2.0.00=back=head1 Filter Handler AttributesPackages using filter attributes have to subclass C<Apache2::Filter>:  package MyApache2::FilterCool;  use base qw(Apache2::Filter);Attributes are parsed during the code compilation, by the functionC<MODIFY_CODE_ATTRIBUTES>, inherited from the C<Apache2::Filter>package.=head2 C<FilterRequestHandler>The C<FilterRequestHandler> attribute tells mod_perl to insert thefilter into an HTTP request filter chain. For example, to configure an output request filter handler, use theC<FilterRequestHandler> attribute in the handler subroutine'sdeclaration:  package MyApache2::FilterOutputReq;  sub handler : FilterRequestHandler { ... }and add the configuration entry:  PerlOutputFilterHandler MyApache2::FilterOutputReqThis is the default mode. So if you are writing an HTTP requestfilter, you don't have to specify this attribute.The section L<HTTP Request vs. ConnectionFilters|docs::2.0::user::handlers::filters/HTTP_Request_vs__Connection_Filters>delves into more details.=head2 C<FilterConnectionHandler>The C<FilterConnectionHandler> attribute tells mod_perl to insert thisfilter into a connection filter chain.For example, to configure an output connection filter handler, use theC<FilterConnectionHandler> attribute in the handler subroutine'sdeclaration:  package MyApache2::FilterOutputCon;  sub handler : FilterConnectionHandler { ... }and add the configuration entry:  PerlOutputFilterHandler MyApache2::FilterOutputConThe section L<HTTP Request vs. ConnectionFilters|docs::2.0::user::handlers::filters/HTTP_Request_vs__Connection_Filters>delves into more details.=head2 C<FilterInitHandler>The attribute C<FilterInitHandler> marks the function suitable to beused as a filter initialization callback, which is called immediatelyafter a filter is inserted to the filter chain and before it'sactually called.  sub init : FilterInitHandler {      my $f = shift;      #...      return Apache2::Const::OK;  }In order to hook this filter callback, the real filter has to assignthis callback using theC<L<FilterHasInitHandler|/C_FilterHasInitHandler_>> which accepts areference to the callback function.For further discussion and examples refer to the L<FilterInitializationPhase|docs::2.0::user::handlers::filters/Filter_Initialization_Phase>tutorial section.=head2 C<FilterHasInitHandler>If a filter wants to run an initialization callback it can registersuch using the C<FilterHasInitHandler> attribute. Similar toC<push_handlers> the callback reference is expected, rather than acallback name. The used callback function has to have theC<L<FilterInitHandler|/C_FilterInitHandler_>> attribute. For example:  package MyApache2::FilterBar;  use base qw(Apache2::Filter);  sub init   : FilterInitHandler { ... }  sub filter : FilterRequestHandler FilterHasInitHandler(\&init) {      my ($f, $bb) = @_;      # ...      return Apache2::Const::OK;  }For further discussion and examples refer to the L<FilterInitializationPhase|docs::2.0::user::handlers::filters/Filter_Initialization_Phase>tutorial section.=head1 Configurationmod_perl 2.0 filters configuration is explained in the L<filterhandlerstutorial|docs::2.0::user::handlers::filters/mod_perl_Filters_Declaration_and_Configuration>.=head2 C<PerlInputFilterHandler>SeeC<L<PerlInputFilterHandler|docs::2.0::user::handlers::filters/C_PerlInputFilterHandler_>>.=head2 C<PerlOutputFilterHandler>SeeC<L<PerlOutputFilterHandler|docs::2.0::user::handlers::filters/C_PerlOutputFilterHandler_>>.=head2 C<PerlSetInputFilter>SeeC<L<PerlSetInputFilter|docs::2.0::user::handlers::filters/C_PerlSetInputFilter_>>.=head2 C<PerlSetOutputFilter>SeeC<L<PerlSetInputFilter|docs::2.0::user::handlers::filters/C_PerlSetInputFilter_>>.=head1 TIE InterfaceC<Apache2::Filter> also implements a tied interface, so you can workwith the C<$f> object as a hash reference.The TIE interface is mostly unimplemented and might be implementedpost 2.0 release.=head2 C<TIEHANDLE>  $ret = TIEHANDLE($stashsv, $sv);=over 4=item obj: C<$stashsv> ( SCALAR )=item arg1: C<$sv> ( SCALAR )=item ret: C<$ret> ( SCALAR )=item since: subject to change=back=head2 C<PRINT>  $ret = PRINT(...);=over 4=item obj: C<...> (XXX)=item ret: C<$ret> ( integer )=item since: subject to change=back=head1 See AlsoL<mod_perl 2.0 documentation|docs::2.0::index>.=head1 Copyrightmod_perl 2.0 and its core modules are copyrighted underThe Apache Software License, Version 2.0.=head1 AuthorsL<The mod_perl development team and numerouscontributors|about::contributors::people>.=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -