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

📄 nntp.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 2 页
字号:
  }  $arg;}sub _timestr {  my $time = shift;  my @g    = reverse((gmtime($time))[0 .. 5]);  $g[1] += 1;  $g[0] %= 100;  sprintf "%02d%02d%02d %02d%02d%02d GMT", @g;}sub _grouplist {  my $nntp = shift;  my $arr  = $nntp->read_until_dot    or return undef;  my $hash = {};  my $ln;  foreach $ln (@$arr) {    my @a = split(/[\s\n]+/, $ln);    $hash->{$a[0]} = [@a[1, 2, 3]];  }  $hash;}sub _fieldlist {  my $nntp = shift;  my $arr  = $nntp->read_until_dot    or return undef;  my $hash = {};  my $ln;  foreach $ln (@$arr) {    my @a = split(/[\t\n]/, $ln);    my $m = shift @a;    $hash->{$m} = [@a];  }  $hash;}sub _articlelist {  my $nntp = shift;  my $arr  = $nntp->read_until_dot;  chomp(@$arr)    if $arr;  $arr;}sub _description {  my $nntp = shift;  my $arr  = $nntp->read_until_dot    or return undef;  my $hash = {};  my $ln;  foreach $ln (@$arr) {    chomp($ln);    $hash->{$1} = $ln      if $ln =~ s/^\s*(\S+)\s*//o;  }  $hash;}#### The commands##sub _ARTICLE  { shift->command('ARTICLE',  @_)->response == CMD_OK }sub _AUTHINFO { shift->command('AUTHINFO', @_)->response }sub _BODY     { shift->command('BODY',     @_)->response == CMD_OK }sub _DATE      { shift->command('DATE')->response == CMD_INFO }sub _GROUP     { shift->command('GROUP', @_)->response == CMD_OK }sub _HEAD      { shift->command('HEAD', @_)->response == CMD_OK }sub _HELP      { shift->command('HELP', @_)->response == CMD_INFO }sub _IHAVE     { shift->command('IHAVE', @_)->response == CMD_MORE }sub _LAST      { shift->command('LAST')->response == CMD_OK }sub _LIST      { shift->command('LIST', @_)->response == CMD_OK }sub _LISTGROUP { shift->command('LISTGROUP', @_)->response == CMD_OK }sub _NEWGROUPS { shift->command('NEWGROUPS', @_)->response == CMD_OK }sub _NEWNEWS   { shift->command('NEWNEWS', @_)->response == CMD_OK }sub _NEXT      { shift->command('NEXT')->response == CMD_OK }sub _POST      { shift->command('POST', @_)->response == CMD_MORE }sub _QUIT      { shift->command('QUIT', @_)->response == CMD_OK }sub _SLAVE     { shift->command('SLAVE', @_)->response == CMD_OK }sub _STAT      { shift->command('STAT', @_)->response == CMD_OK }sub _MODE      { shift->command('MODE', @_)->response == CMD_OK }sub _XGTITLE   { shift->command('XGTITLE', @_)->response == CMD_OK }sub _XHDR      { shift->command('XHDR', @_)->response == CMD_OK }sub _XPAT      { shift->command('XPAT', @_)->response == CMD_OK }sub _XPATH     { shift->command('XPATH', @_)->response == CMD_OK }sub _XOVER     { shift->command('XOVER', @_)->response == CMD_OK }sub _XROVER    { shift->command('XROVER', @_)->response == CMD_OK }sub _XTHREAD   { shift->unsupported }sub _XSEARCH   { shift->unsupported }sub _XINDEX    { shift->unsupported }#### IO/perl methods##sub DESTROY {  my $nntp = shift;  defined(fileno($nntp)) && $nntp->quit;}1;__END__=head1 NAMENet::NNTP - NNTP Client class=head1 SYNOPSIS    use Net::NNTP;    $nntp = Net::NNTP->new("some.host.name");    $nntp->quit;=head1 DESCRIPTIONC<Net::NNTP> is a class implementing a simple NNTP client in Perl as describedin RFC977. C<Net::NNTP> inherits its communication methods from C<Net::Cmd>=head1 CONSTRUCTOR=over 4=item new ( [ HOST ] [, OPTIONS ])This is the constructor for a new Net::NNTP object. C<HOST> is thename of the remote host to which a NNTP connection is required. If notgiven then it may be passed as the C<Host> option described below. If no host is passedthen two environment variables are checked, first C<NNTPSERVER> thenC<NEWSHOST>, then C<Net::Config> is checked, and if a host is not foundthen C<news> is used.C<OPTIONS> are passed in a hash like fashion, using key and value pairs.Possible options are:B<Host> - NNTP host to connect to. It may be a single scalar, as defined forthe C<PeerAddr> option in L<IO::Socket::INET>, or a reference toan array with hosts to try in turn. The L</host> method will return the valuewhich was used to connect to the host.B<Timeout> - Maximum time, in seconds, to wait for a response from theNNTP server, a value of zero will cause all IO operations to block.(default: 120)B<Debug> - Enable the printing of debugging information to STDERRB<Reader> - If the remote server is INN then initially the connectionwill be to nnrpd, by default C<Net::NNTP> will issue a C<MODE READER> commandso that the remote server becomes innd. If the C<Reader> option is givenwith a value of zero, then this command will not be sent and theconnection will be left talking to nnrpd.=back=head1 METHODSUnless otherwise stated all methods return either a I<true> or I<false>value, with I<true> meaning that the operation was a success. When a methodstates that it returns a value, failure will be returned as I<undef> or anempty list.=over 4=item article ( [ MSGID|MSGNUM ], [FH] )Retrieve the header, a blank line, then the body (text) of thespecified article. If C<FH> is specified then it is expected to be a valid filehandleand the result will be printed to it, on success a true value will bereturned. If C<FH> is not specified then the return value, on success,will be a reference to an array containing the article requested, eachentry in the array will contain one line of the article.If no arguments are passed then the current article in the currentlyselected newsgroup is fetched.C<MSGNUM> is a numeric id of an article in the current newsgroup, andwill change the current article pointer.  C<MSGID> is the message id ofan article as shown in that article's header.  It is anticipated that theclient will obtain the C<MSGID> from a list provided by the C<newnews>command, from references contained within another article, or from themessage-id provided in the response to some other commands.If there is an error then C<undef> will be returned.=item body ( [ MSGID|MSGNUM ], [FH] )Like C<article> but only fetches the body of the article.=item head ( [ MSGID|MSGNUM ], [FH] )Like C<article> but only fetches the headers for the article.=item articlefh ( [ MSGID|MSGNUM ] )=item bodyfh ( [ MSGID|MSGNUM ] )=item headfh ( [ MSGID|MSGNUM ] )These are similar to article(), body() and head(), but rather thanreturning the requested data directly, they return a tied filehandlefrom which to read the article.=item nntpstat ( [ MSGID|MSGNUM ] )The C<nntpstat> command is similar to the C<article> command except that notext is returned.  When selecting by message number within a group,the C<nntpstat> command serves to set the "current article pointer" withoutsending text.Using the C<nntpstat> command toselect by message-id is valid but of questionable value, since aselection by message-id does B<not> alter the "current article pointer".Returns the message-id of the "current article".=item group ( [ GROUP ] )Set and/or get the current group. If C<GROUP> is not given then informationis returned on the current group.In a scalar context it returns the group name.In an array context the return value is a list containing, the numberof articles in the group, the number of the first article, the numberof the last article and the group name.=item ihave ( MSGID [, MESSAGE ])The C<ihave> command informs the server that the client has an articlewhose id is C<MSGID>.  If the server desires a copy of thatarticle, and C<MESSAGE> has been given the it will be sent.Returns I<true> if the server desires the article and C<MESSAGE> wassuccessfully sent,if specified.If C<MESSAGE> is not specified then the message must be sent using theC<datasend> and C<dataend> methods from L<Net::Cmd>C<MESSAGE> can be either an array of lines or a reference to an array.=item last ()Set the "current article pointer" to the previous article in the currentnewsgroup.Returns the message-id of the article.=item date ()Returns the date on the remote server. This date will be in a UNIX timeformat (seconds since 1970)=item postok ()C<postok> will return I<true> if the servers initial response indicatedthat it will allow posting.=item authinfo ( USER, PASS )Authenticates to the server (using AUTHINFO USER / AUTHINFO PASS)using the supplied username and password.  Please note that thepassword is sent in clear text to the server.  This command should notbe used with valuable passwords unless the connection to the server issomehow protected.=item list ()Obtain information about all the active newsgroups. The results is a referenceto a hash where the key is a group name and each value is a reference to anarray. The elements in this array are:- the last article number in the group,the first article number in the group and any information flags about the group.=item newgroups ( SINCE [, DISTRIBUTIONS ])C<SINCE> is a time value and C<DISTRIBUTIONS> is either a distributionpattern or a reference to a list of distribution patterns.The result is the same as C<list>, but thegroups return will be limited to those created after C<SINCE> and, ifspecified, in one of the distribution areas in C<DISTRIBUTIONS>. =item newnews ( SINCE [, GROUPS [, DISTRIBUTIONS ]])C<SINCE> is a time value. C<GROUPS> is either a group pattern or a referenceto a list of group patterns. C<DISTRIBUTIONS> is either a distributionpattern or a reference to a list of distribution patterns.Returns a reference to a list which contains the message-ids of all news postedafter C<SINCE>, that are in a groups which matched C<GROUPS> and adistribution which matches C<DISTRIBUTIONS>.=item next ()Set the "current article pointer" to the next article in the currentnewsgroup.Returns the message-id of the article.=item post ( [ MESSAGE ] )Post a new article to the news server. If C<MESSAGE> is specified and postingis allowed then the message will be sent.If C<MESSAGE> is not specified then the message must be sent using theC<datasend> and C<dataend> methods from L<Net::Cmd>C<MESSAGE> can be either an array of lines or a reference to an array.The message, either sent via C<datasend> or as the C<MESSAGE>parameter, must be in the format as described by RFC822 and mustcontain From:, Newsgroups: and Subject: headers.=item postfh ()Post a new article to the news server using a tied filehandle.  Ifposting is allowed, this method will return a tied filehandle that youcan print() the contents of the article to be posted.  You mustexplicitly close() the filehandle when you are finished posting thearticle, and the return value from the close() call will indicatewhether the message was successfully posted.=item slave ()Tell the remote server that I am not a user client, but probably anothernews server.=item quit ()Quit the remote server and close the socket connection.=back=head2 Extension methodsThese methods use commands that are not part of the RFC977 documentation. Someservers may not support all of them.=over 4=item newsgroups ( [ PATTERN ] )Returns a reference to a hash where the keys are all the group names whichmatch C<PATTERN>, or all of the groups if no pattern is specified, andeach value contains the description text for the group.=item distributions ()Returns a reference to a hash where the keys are all the possibledistribution names and the values are the distribution descriptions.=item subscriptions ()Returns a reference to a list which contains a list of groups whichare recommended for a new user to subscribe to.=item overview_fmt ()Returns a reference to an array which contain the names of the fields returnedby C<xover>.=item active_times ()Returns a reference to a hash where the keys are the group names and eachvalue is a reference to an array containing the time the groups was createdand an identifier, possibly an Email address, of the creator.=item active ( [ PATTERN ] )Similar to C<list> but only active groups that match the pattern are returned.C<PATTERN> can be a group pattern.=item xgtitle ( PATTERN )Returns a reference to a hash where the keys are all the group names whichmatch C<PATTERN> and each value is the description text for the group.=item xhdr ( HEADER, MESSAGE-SPEC )Obtain the header field C<HEADER> for all the messages specified. The return value will be a referenceto a hash where the keys are the message numbers and each value containsthe text of the requested header for that message.=item xover ( MESSAGE-SPEC )The return value will be a referenceto a hash where the keys are the message numbers and each value containsa reference to an array which contains the overview fields for thatmessage.The names of the fields can be obtained by calling C<overview_fmt>.=item xpath ( MESSAGE-ID )Returns the path name to the file on the server which contains the specifiedmessage.=item xpat ( HEADER, PATTERN, MESSAGE-SPEC)The result is the same as C<xhdr> except the is will be restricted toheaders where the text of the header matches C<PATTERN>=item xroverThe XROVER command returns reference information for the article(s)specified.Returns a reference to a HASH where the keys are the message numbers and thevalues are the References: lines from the articles=item listgroup ( [ GROUP ] )Returns a reference to a list of all the active messages in C<GROUP>, orthe current group if C<GROUP> is not specified.=item readerTell the server that you are a reader and not another server.This is required by some servers. For example if you are connecting toan INN server and you have transfer permission your connection willbe connected to the transfer daemon, not the NNTP daemon. Issuingthis command will cause the transfer daemon to hand over controlto the NNTP daemon.Some servers do not understand this command, but issuing it and ignoringthe response is harmless.=back=head1 UNSUPPORTEDThe following NNTP command are unsupported by the package, and there areno plans to do so.    AUTHINFO GENERIC    XTHREAD    XSEARCH    XINDEX=head1 DEFINITIONS=over 4=item MESSAGE-SPECC<MESSAGE-SPEC> is either a single message-id, a single message number, ora reference to a list of two message numbers.If C<MESSAGE-SPEC> is a reference to a list of two message numbers and thesecond number in a range is less than or equal to the first then the rangerepresents all messages in the group after the first message number.B<NOTE> For compatibility reasons only with earlier versions of Net::NNTPa message spec can be passed as a list of two numbers, this is deprecatedand a reference to the list should now be passed=item PATTERNThe C<NNTP> protocol uses the C<WILDMAT> format for patterns.The WILDMAT format was first developed by Rich Salz based onthe format used in the UNIX "find" command to articulatefile names. It was developed to provide a uniform mechanismfor matching patterns in the same manner that the UNIX shellmatches filenames.Patterns are implicitly anchored at thebeginning and end of each string when testing for a match.There are five pattern matching operations other than a strictone-to-one match between the pattern and the source to bechecked for a match.The first is an asterisk C<*> to match any sequence of zero or morecharacters.The second is a question mark C<?> to match any single character. Thethird specifies a specific set of characters.The set is specified as a list of characters, or as a range of characterswhere the beginning and end of the range are separated by a minus (or dash)character, or as any combination of lists and ranges. The dash canalso be included in the set as a character it if is the beginningor end of the set. This set is enclosed in square brackets. Theclose square bracket C<]> may be used in a set if it is the firstcharacter in the set.The fourth operation is the same as thelogical not of the third operation and is specified the sameway as the third with the addition of a caret character C<^> atthe beginning of the test string just inside the open squarebracket.The final operation uses the backslash character toinvalidate the special meaning of an open square bracket C<[>,the asterisk, backslash or the question mark. Two backslashes insequence will result in the evaluation of the backslash as acharacter with no special meaning.=over 4=item Examples=item C<[^]-]>matches any single character other than a close squarebracket or a minus sign/dash.=item C<*bdc>matches any string that ends with the string "bdc"including the string "bdc" (without quotes).=item C<[0-9a-zA-Z]>matches any single printable alphanumeric ASCII character.=item C<a??d>matches any four character string which beginswith a and ends with d.=back=back=head1 SEE ALSOL<Net::Cmd>=head1 AUTHORGraham Barr <gbarr@pobox.com>=head1 COPYRIGHTCopyright (c) 1995-1997 Graham Barr. All rights reserved.This program is free software; you can redistribute it and/or modifyit under the same terms as Perl itself.=cut

⌨️ 快捷键说明

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