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

📄 filter.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 2 页
字号:
# # /*#  * *********** WARNING **************#  * This file generated by ModPerl::WrapXS/0.01#  * Any changes made here will be lost#  * ***********************************#  * 01: lib/ModPerl/Code.pm:708#  * 02: lib/ModPerl/WrapXS.pm:624#  * 03: lib/ModPerl/WrapXS.pm:1173#  * 04: Makefile.PL:423#  * 05: Makefile.PL:325#  * 06: Makefile.PL:56#  */# package Apache2::Filter;use strict;use warnings FATAL => 'all';use Apache2::XSLoader ();our $VERSION = '2.000002';Apache2::XSLoader::load __PACKAGE__;1;__END__=head1 NAMEApache2::Filter - Perl API for Apache 2.0 Filtering=head1 Synopsis  use Apache2::Filter ();    # filter attributes  my $c = $f->c;  my $r = $f->r;  my $frec = $f->frec();  my $next_f = $f->next;    my $ctx = $f->ctx;  $f->ctx($ctx);    # bucket brigade filtering API  $rc = $f->next->get_brigade($bb, $mode, $block, $readbytes);  $rc = $f->next->pass_brigade($bb);  $rc = $f->fflush($bb);    # streaming filtering API  while ($filter->read(my $buffer, $wanted)) {      # transform $buffer here      $filter->print($buffer);  }  if ($f->seen_eos) {      $filter->print("filter signature");  }    # filter manipulations  $r->add_input_filter(\&callback);  $c->add_input_filter(\&callback);  $r->add_output_filter(\&callback);  $c->add_output_filter(\&callback);  $f->remove;=head1 DescriptionC<Apache2::Filter> provides Perl API for Apache 2.0 filteringframework.Make sure to read C<the Filteringtutorial|docs::2.0::user::handlers::filters>.=head1 Common Filter APIThe following methods can be called from any filter handler:=head2 C<c>Get the current connection object from a connection or a requestfilter:  $c = $f->c;=over 4=item obj: C<$f>( C<L<Apache2::Filter object|docs::2.0::api::Apache2::Filter>> )=item ret: C<$c>( C<L<Apache2::Connection object|docs::2.0::api::Apache2::Connection>> )=item since: 2.0.00=back=head2 C<ctx>Get/set the filter context data.  $ctx = $f->ctx;         $f->ctx($ctx);=over 4=item obj: C<$f>( C<L<Apache2::Filter object|docs::2.0::api::Apache2::Filter>> )=item opt arg2: C<$ctx> ( SCALAR )next context=item ret: C<$ctx> ( SCALAR )current context=item since: 2.0.00=backA filter context is created before the filter is called for the firsttime and it's destroyed at the end of the request. The context ispreserved between filter invocations of the same request. So if afilter needs to store some data between invocations it should use thefilter context for that.  The filter context is initialized with theC<undef> value.The C<ctx> method accepts a single SCALAR argument. Therefore if youwant to store any other perl datastructure you should use a referenceto it.For example you can store a hash reference:  $f->ctx({ foo => 'bar' });and then access it:  $foo = $f->ctx->{foo};if you access the context more than once it's more efficient to copyit's value before using it:  my $ctx = $f->ctx;  $foo = $ctx->{foo};to avoid redundant method calls. As of this writing C<$ctx> is not atied variable, so if you modify it need to store it at the end:  $f->ctx($ctx);META: later we might make it a TIEd-variable interface, so it'll bestored automatically.Besides its primary purpose of storing context data across multiplefilter invocations, this method is also useful when used as aflag. For example here is how to ensure that something happens onlyonce during the filter's life:  unless ($f->ctx) {      do_something_once();      $f->ctx(1);  }=head2 C<frec>Get/set the C<L<Apache2::FilterRec|docs::2.0::api::Apache2::FilterRec>>(filter record) object.  $frec = $f->frec();=over 4=item obj: C<$f>( C<L<Apache2::Filter object|docs::2.0::api::Apache2::Filter>> )=item ret: C<$frec>( C<L<Apache2::FilterRec object|docs::2.0::api::Apache2::FilterRec>> )=item since: 2.0.00=backFor example you can callC<L<$frec-E<gt>name|docs::2.0::api::Apache2::FilterRec/C_name_>> to getfilter's name.=head2 C<next>Return the C<Apache2::Filter> object of the next filter in chain.  $next_f = $f->next;=over 4=item obj: C<$f>( C<L<Apache2::Filter object|docs::2.0::api::Apache2::Filter>> )The current filter object=item ret: C<$next_f>( C<L<Apache2::Filter object|docs::2.0::api::Apache2::Filter>> )The next filter object in chain=item since: 2.0.00=backSince Apache inserts several core filters at the end of each chain,normally this method always returns an object. However if it's not amod_perl filter handler, you can call only the following methods onit: C<L<get_brigade|/C_get_brigade_>>,C<L<pass_brigade|/C_pass_brigade_>>, C<L<c|/C_c_>>, C<L<r|/C_r_>>,C<L<frec|/C_frec_>> and C<L<next|/C_next_>>. If you call other methodsthe behavior is undefined.The next filter can be a mod_perl one or not, it's easy to tell whichone is that by callingC<L<$f-E<gt>frec-E<gt>name|docs::2.0::api::Apache2::FilterRec/C_name_>>.=head2 C<r>Inside an HTTP request filter retrieve the current request object:  $r = $f->r;=over 4=item obj: C<$f>( C<L<Apache2::Filter object|docs::2.0::api::Apache2::Filter>> )=item ret: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item since: 2.0.00=backIf a sub-request adds filters, then that sub-request object isassociated with the filter.=head2 C<remove>Remove the current filter from the filter chain (for the currentrequest or connection).  $f->remove;=over 4=item obj: C<$f>( C<L<Apache2::Filter object|docs::2.0::api::Apache2::Filter>> )=item ret: no return value=item since: 2.0.00=backNotice that you should either complete the current filter invocationnormally (by calling C<L<get_brigade|/C_get_brigade_>> orC<L<pass_brigade|/C_pass_brigade_>> depending on the filter kind) orif nothing was done, return C<Apache2::Const::DECLINED> and mod_perl will takecare of passing the current bucket brigade through unmodified to thenext filter in chain.Note: calling remove() on the very top connection filter doesn'taffect the filter chain due to a bug in Apache 2.0 (which may be fixedin 2.1). So don't use it with connection filters, till it gets fixedin Apache and then make sure to require the minimum Apache version ifyou rely on.Remember that if the connection isC<L<$c-E<gt>keepalive|docs::2.0::api::Apache2::Connection/C_keepalive_>>) and the connection filter is removed, it won't be added until theconnection is closed. Which may happen after many HTTP requests. Youmay want to keep the filter in place and pass the data throughunmodified, by returning C<Apache2::Const::DECLINED>. If you need to reset thewhole or parts of the filter context between requests, use theL<technique based on C<$c-E<gt>keepalives>counting|docs::2.0::user::handler::filters>.This method works for native Apache (non-mod_perl) filters too.=head1 Bucket Brigade Filter APIThe following methods can be called from any filter, directlymanipulating bucket brigades:=head2 C<fflush>Flush a bucket brigade down the filter stack.  $rc = $f->fflush($bb);=over 4=item obj: C<$f>( C<L<Apache2::Filter object|docs::2.0::api::Apache2::Filter>> )The current filter=item arg1: C<$bb>( C<L<Apache2::Brigade object|docs::2.0::api::APR::Brigade>> )The brigade to flush=item ret:  C<$rc> ( C<L<APR::Const statusconstant|docs::2.0::api::APR::Const>> )Refer to the C<L<pass_brigade()|/C_pass_brigade_>> entry.=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=backC<fflush> is a shortcut method. So instead of doing:  my $b = APR::Bucket::flush_create($f->c->bucket_alloc);  $bb->insert_tail($b);  $f->pass_brigade($bb);one can just write:  $f->fflush($bb);=head2 C<get_brigade>This is a method to use in bucket brigade input filters. It acquires abucket brigade from the upstream input filter.  $rc = $next_f->get_brigade($bb, $mode, $block, $readbytes);  $rc = $next_f->get_brigade($bb, $mode, $block);  $rc = $next_f->get_brigade($bb, $mode)  $rc = $next_f->get_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<filter handlers|docs::2.0::user::handlers::filters> it'susually C<L<$f-E<gt>next|/C_next_>>. Inside L<protocolhandlers|docs::2.0::user::handlers::protocols>:C<L<$c-E<gt>input_filters|docs::2.0::api::Apache2::Connection/C_input_filters_>>.=item arg1: C<$bb>( C<L<APR::Brigade object|docs::2.0::api::APR::Brigade>> )The original bucket brigade passed to C<get_brigade()>, which must beempty.Inside L<input filterhandlers|docs::2.0::user::handlers::filters> it's usually the secondargument to the filter handler.Otherwise it should be created:  my $bb = APR::Brigade->new($c->pool, $c->bucket_alloc);On return it gets populated with the next bucket brigade. That brigademay contain nothing if there was no more data to read. The returnstatus tells the outcome.=item opt arg2: C<$mode> ( C<L<Apache2::Const :input_modeconstant|docs::2.0::api::Apache2::Const/C__input_mode_>> )The filter mode in which the data should be read.If inside the filter handler, you should normally pass the same modethat was passed to the filter handler (the third argument).At the end of this section the available modes are presented.If the argument C<$mode> is not passed,C<L<Apache2::Const::MODE_READBYTES|docs::2.0::api::Apache2::Const/C_Apache2__Const__MODE_READBYTES_>>is used as a default value.=item opt arg3: C<$block> ( C<L<APR::Const :read_typeconstant|docs::2.0::api::APR::Const/C__input_mode_>> )You may ask the reading operation to be blocking:C<L<APR::Const::BLOCK_READ|docs::2.0::api::APR::Const/C_APR__Const__BLOCK_READ_>>,or nonblocking:C<L<APR::Const::NONBLOCK_READ|docs::2.0::api::APR::Const/C_APR__Const__NONBLOCK_READ_>>.If inside the filter handler, you should normally pass the sameblocking mode argument that was passed to the filter handler (theforth argument).If the argument C<$block> is not passed,C<L<APR::Const::BLOCK_READ|docs::2.0::api::APR::Const/C_APR__Const__BLOCK_READ_>> isused as a default value.=item opt arg4: C<$readbytes> ( integer )How many bytes to read from the next filter.If inside the filter handler, you may want the same number of bytes,as the upstream filter, i.e. the argument that was passed to thefilter handler (the fifth argument).If the argument C<$block> is not passed, 8192 is used as a defaultvalue.=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 and C<$bb> is populated (see the C<$bb> entry).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 read from the network, thenC<Apache2::NOBODY_READ> is returned (META: need to add this constant).Inside L<protocol handlers|docs::2.0::user::handlers::protocols> thereturn code can also be C<APR::Const::EOF>, which is success as well.=item excpt: C<L<APR::Error|docs::2.0::api::APR::Error>>You don't have to ask for the return value. If this function is calledin the VOID context, e.g.:  $f->next->get_brigade($bb, $mode, $block, $readbytes);mod_perl will do the error checking on your behalf, and if the returncode is notC<L<APR::Const::SUCCESS|docs::2.0::api::APR::Const/C_APR__Const__SUCCESS_>>, anC<L<APR::Error exception|docs::2.0::api::APR::Error>> will be thrown.The only time you want to do the error checking yourself, is whenreturn codes besidesC<L<APR::Const::SUCCESS|docs::2.0::api::APR::Const/C_APR__Const__SUCCESS_>> areconsidered as successful and you want to manage them by yourself.=item since: 2.0.00=backAvailable input filter modes (the optional second argument C<$mode>)are:=over=item * C<L<Apache2::Const::MODE_READBYTES|docs::2.0::api::Apache2::Const/C_Apache2__Const__MODE_READBYTES_>>The filter should return at most readbytes data=item * C<L<Apache2::Const::MODE_GETLINE|docs::2.0::api::Apache2::Const/C_Apache2__Const__MODE_GETLINE_>>The filter should return at most one line of CRLF data.  (If apotential line is too long or no CRLF is found, the filter may returnpartial data).=item * C<L<Apache2::Const::MODE_EATCRLF|docs::2.0::api::Apache2::Const/C_Apache2__Const__MODE_EATCRLF_>>The filter should implicitly eat any CRLF pairs that it sees.=item * C<L<Apache2::Const::MODE_SPECULATIVE|docs::2.0::api::Apache2::Const/C_Apache2__Const__MODE_SPECULATIVE_>>The filter read should be treated as speculative and any returned datashould be stored for later retrieval in another mode.=item * C<L<Apache2::Const::MODE_EXHAUSTIVE|docs::2.0::api::Apache2::Const/C_Apache2__Const__MODE_EXHAUSTIVE_>>The filter read should be exhaustive and read until it can not readany more. Use this mode with extreme caution.=item * C<L<Apache2::Const::MODE_INIT|docs::2.0::api::Apache2::Const/C_Apache2__Const__MODE_INIT_>>The filter should initialize the connection if needed, NNTP or FTPover SSL for example.=backEither compile all these constants with:  use Apache2::Const -compile => qw(:input_mode);But it's a bit more efficient to compile only those constants that youneed.Example:Here is a fragment of a filter handler, that receives a bucket brigadefrom the upstream filter:  use Apache2::Filter ();  use APR::Const    -compile => qw(SUCCESS);  use Apache2::Const -compile => qw(OK);  sub filter {      my ($f, $bb, $mode, $block, $readbytes) = @_;            my $rc = $f->next->get_brigade($bb, $mode, $block, $readbytes);      return $rc unless $rc == APR::Const::SUCCESS;            # ... process $bb      

⌨️ 快捷键说明

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