Net/NNTP/Proxy.pm

filter: Statementstmt 6.5% 23 / 354 Branchbran 0.0% 0 / 202 Conditioncond 0.0% 0 / 119 MC/DCmcdc 0.0% 0 / 66 Subroutinesub 9.4% 5 / 53 Podpod 81.0% 30 / 37 totaltotal 6.9% 58 / 831 CC 168 SCAR 52.3
CC
168
Cov
3%
process
702.0
_stat
420.0
article
306.0
CRAP 187.1
« News/Article/Cancel.pm ↑ Summary News/Article/Response.pm »
1 1 $VERSION = '0.54';
2 package Net::NNTP::Proxy;
3 1 our $VERSION = '0.54';
4  
5 # -*- Perl -*-
6 ###############################################################################
7 # Written by Tim Skirvin <tskirvin@killfile.org>
8 # Relies extensively on code from Net::NNTP, which was written and maintained
9 # by Graham Barr <gbarr@pobox.com>. Thanks.
10 #
11 # Copyright 2000-2002, Tim Skirvin. Redistribution terms are below.
12 ###############################################################################
13  
14  
15 =head1 NAME
16  
17 Net::NNTP::Proxy - a news server in perl
18  
19 =head1 SYNOPSIS
20  
21 use Net::NNTP::Proxy;
22 my $server = new Net::NNTP::Proxy || die "Couldn't start the server: $!\n";
23 $server->push(new Net::NNTP::Client);
24 $server->listen(9119);
25 my $client = $server->connect;
26  
27 See below for more functions.
28  
29 =head1 DESCRIPTION
30  
31 This package is a basic news server written in perl. It contains a list
32 of Net::NNTP::Client connections, and talks to all of these to get its
33 data; it then serves it back out to a port just like a regular news server.
34 It's also clean enough to run multiple-processes (and maybe even
35 multi-threaded, if I'm lucky.)
36  
37 newsproxy.pl is used to actually run this thing.
38  
39 =head1 METHODS
40  
41 =over 4
42  
43 =cut
44  
45 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 1 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 1 ▶use Errno qw(EAGAIN);
Subroutine BEGIN: called CC=1 SCAR=0.0
48 1 ▶use News::Article;
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50 1 ▶use vars qw($DEBUG $MAXCONN $CONNMESSAGE $PORT $NEWLINE);
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 ### Variables #################################################################
53 1 $DEBUG = 1; # Should debugging be on? 1 = yes, 0 = no.
54 1 $MAXCONN = 5; # Maximum number of connections in the queue.
55 1 $CONNMESSAGE = ""; # Message to send when connected.
56 ###############################################################################
57  
58 1 $PORT = 119; # Default news port
59 1 $NEWLINE = "\r\n"; # Newline string
60  
61 =head2 NETWORK AND FUNCTIONALITY
62  
63 These functions create the object and connect it to the network.
64  
65 =item new ( )
66  
67 Create a new server object. Doesn't actually bind to the port; you still
68 need to use C<listen()> for that.
69  
70 =cut
71  
72 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
73 0 my $class = shift;
74 0 my $object = {};
75 0 bless $object, $class;
76 0 $object->_init('port', shift);
77 }
78  
79 ### _init ( KEY, VALUE [...] )
80 # Do the work for new(). And clone(), if I decide to make one.
81 0 ▶sub _init {
Subroutine _init: not called CC=7 SCAR=40.3
82 0 my ($self, %hash) = @_;
83  
84 # User-modified variables
85 0 ▶ $$self{'NEWSSERVERS'} = $hash{'newsservers'} || [];
Condition0%0/2
$hash{'newsservers'} || []
l!l
00
MC/DC0%0/1
$hash{'newsservers'} || []
$hash{'newsservers'}
Truth table0%0/2
A
A= $hash{'newsservers'}
Aresult
11
00
86  
87 # Cached variables
88 0 ▶ $$self{'SERVER'} = $hash{'server'} || "";
Condition0%0/2
$hash{'server'} || ''
l!l
00
MC/DC0%0/1
$hash{'server'} || ''
$hash{'server'}
Truth table0%0/2
A
A= $hash{'server'}
Aresult
11
00
89 0 ▶ $$self{'GROUP'} = $hash{'group'} || "";
Condition0%0/2
$hash{'group'} || ''
l!l
00
MC/DC0%0/1
$hash{'group'} || ''
$hash{'group'}
Truth table0%0/2
A
A= $hash{'group'}
Aresult
11
00
90 0 ▶ $$self{'POINTER'} = $hash{'pointer'} || 0;
Condition0%0/2
$hash{'pointer'} || 0
l!l
00
MC/DC0%0/1
$hash{'pointer'} || 0
$hash{'pointer'}
Truth table0%0/2
A
A= $hash{'pointer'}
Aresult
11
00
91 0 ▶ $$self{'ARTICLES'} = $hash{'articles'} || [];
Condition0%0/2
$hash{'articles'} || []
l!l
00
MC/DC0%0/1
$hash{'articles'} || []
$hash{'articles'}
Truth table0%0/2
A
A= $hash{'articles'}
Aresult
11
00
92  
93 # Internal variables
94 0 ▶ $$self{'SOCKET'} = $hash{'socket'} || {};
Condition0%0/2
$hash{'socket'} || {}
l!l
00
MC/DC0%0/1
$hash{'socket'} || {}
$hash{'socket'}
Truth table0%0/2
A
A= $hash{'socket'}
Aresult
11
00
95  
96 0 $self;
97 }
98  
99 =item openport ( [PORT] )
100  
101 Listens on C<PORT> for a TCP connection.
102  
103 =cut
104  
105 0 ▶sub openport {
Subroutine openport: not called CC=4 SCAR=30.0
Pod documented
106 0 my ($self, $port) = @_;
107 0 ▶ my $server = $self->_open_socket($port || 119);
Condition0%0/2
$port || 119
l!l
00
MC/DC0%0/1
$port || 119
$port
Truth table0%0/2
A
A= $port
Aresult
11
00
108 0 ▶ $$self{'SOCKET'} = $server if $server;;
Branch: 1 branch
BranchTrueFalseTotal
if $server 0 0 0
109 0 ▶ return $server ? $self : undef;
Branch: 1 branch
BranchTrueFalseTotal
$server ? : 0 0 0
110 }
111  
112 =item closeport ()
113  
114 Stops listening for a TCP connection.
115  
116 =cut
117  
118 0 ▶sub closeport {
Subroutine closeport: not called CC=2 SCAR=17.9
Pod documented
119 0 my ($self, @rest) = @_;
120 0 ▶ $$self{'SOCKET'} ? close $$self{'SOCKET'}
Branch: 1 branch
BranchTrueFalseTotal
$self->{'SOCKET'} ? : 0 0 0
121 : 0;
122 }
123  
124 =item connect ( FILEHANDLE )
125  
126 Connects to the given C<FILEHANDLE>. Returns the filehandle again.
127  
128 =cut
129  
130 0 ▶sub connect {
Subroutine connect: not called CC=3 SCAR=24.8
Pod documented
131 0 my ($self, $fh) = @_;
132 0 ▶ my $server = $$self{'SOCKET'} || return undef;
Condition0%0/2
$self->{'SOCKET'} || (return undef)
l!l
00
MC/DC0%0/1
$self->{'SOCKET'} || (return undef)
$self->{'SOCKET'}
Truth table0%0/2
A
A= $self->{'SOCKET'}
Aresult
11
00
133 0 ▶ $fh ||= \*CLIENT;
Condition0%0/2
$fh ||= \*CLIENT
l!l
00
MC/DC0%0/1
$fh ||= \*CLIENT
$fh
Truth table0%0/2
A
A= $fh
Aresult
11
00
134 0 accept($fh, $server);
135 0 $fh;
136 }
137  
138 =item disconnect ( FILEHANDLE )
139  
140 Disconnects from C<FILEHANDLE>, closing it in the process.
141  
142 =cut
143  
144 0 ▶sub disconnect {
Subroutine disconnect: not called CC=3 SCAR=24.8
Pod documented
145 0 ▶ my ($self, $fh) = @_; return undef unless $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 0 0 0
146 0 ▶ return undef unless defined fileno($fh);
Branch: 1 branch
BranchTrueFalseTotal
unless defined fileno $fh 0 0 0
147 0 close $fh;
148 }
149  
150 =item process ( FILEHANDLE, LINE )
151  
152 Process C<LINE>, which was received from C<FILEHANDLE>, and call the
153 appropriate news function (which are all documented below). Returns
154  
155 =cut
156  
157 0 ▶sub process {
Subroutine process: not called CC=26 SCAR=65.5
Pod documented
158 0 ▶ my ($self, $fh, $line) = @_; $line ||= $_;
Condition0%0/3
$line ||= $_
l!l&&r!l&&!r
000
MC/DC0%0/2
$line ||= $_
$line $_
Truth table0%0/3
A ||= B
A= $lineB= $_
ABresult
1X1
011
000
159 0 $line =~ s/^\s+|\s+$//g; # Trim leading/trailing whitespace
160 0 my ($command, @rest) = split('\s+', $line);
161 0 my @return;
162 0 ▶ if (lc $command eq 'authinfo') {
Branch: 24 branches
BranchTrueFalseTotal
if (lc $command eq 'authinfo') { } 0 0 0
elsif (lc $command eq 'article') { } 0 0 0
elsif (lc $command eq 'body') { } 0 0 0
elsif (lc $command eq 'date') { } 0 0 0
elsif (lc $command eq 'group') { } 0 0 0
elsif (lc $command eq 'head') { } 0 0 0
elsif (lc $command eq 'help') { } 0 0 0
elsif (lc $command eq 'ihave') { } 0 0 0
elsif (lc $command eq 'last') { } 0 0 0
elsif (lc $command eq 'list') { } 0 0 0
elsif (lc $command eq 'listgroup') { } 0 0 0
elsif (lc $command eq 'mode') { } 0 0 0
elsif (lc $command eq 'newgroups') { } 0 0 0
elsif (lc $command eq 'newnews') { } 0 0 0
elsif (lc $command eq 'next') { } 0 0 0
elsif (lc $command eq 'post') { } 0 0 0
elsif (lc $command eq 'slave') { } 0 0 0
elsif (lc $command eq 'stat') { } 0 0 0
elsif (lc $command eq 'xgtitle') { } 0 0 0
elsif (lc $command eq 'xhdr') { } 0 0 0
elsif (lc $command eq 'xover') { } 0 0 0
elsif (lc $command eq 'xpat') { } 0 0 0
elsif (lc $command eq 'xpath') { } 0 0 0
elsif (lc $command eq 'quit') { } 0 0 0
163 0 @return = "400 Not yet implemented";
164 # @return = $self->authinfo(@rest);
165 } elsif (lc $command eq 'article') { # Works
166 # @return = $self->article($rest[0]);
167 0 @return = $self->article($rest[0], 1, 1);
168 } elsif (lc $command eq 'body') { # Works - sortof
169 0 @return = $self->article($rest[0], 0, 1);
170 # @return = $self->body(@rest);
171 } elsif (lc $command eq 'date') { # Works
172 0 @return = $self->date;
173 } elsif (lc $command eq 'group') { # Works
174 0 @return = $self->group($rest[0]);
175 } elsif (lc $command eq 'head') { # Works - sortof
176 0 @return = $self->article($rest[0], 1, 0);
177 # @return = $self->head(@rest);
178 } elsif (lc $command eq 'help') {
179 0 @return = "400 Not yet implemented";
180 # @return = $self->help(@rest);
181 } elsif (lc $command eq 'ihave') {
182 0 @return = "400 Not yet implemented";
183 # @return = $self->ihave(@rest);
184 } elsif (lc $command eq 'last') { # Works
185 0 @return = $self->last();
186 } elsif (lc $command eq 'list') {
187 0 @return = $self->list(@rest);
188 } elsif (lc $command eq 'listgroup') { # Works
189 0 @return = $self->listgroup($rest[0]);
190 } elsif (lc $command eq 'mode') { # Works
191 0 @return = $self->mode(@rest);
192 } elsif (lc $command eq 'newgroups') {
193 0 @return = "400 Not yet implemented";
194 # @return = $self->newgroups(@rest);
195 } elsif (lc $command eq 'newnews') {
196 0 @return = "400 Not yet implemented";
197 # @return = $self->newnews(@rest);
198 } elsif (lc $command eq 'next') { # Works
199 0 @return = $self->next();
200 } elsif (lc $command eq 'post') { # Works mostly
201 0 @return = $self->post($fh);
202 } elsif (lc $command eq 'slave') {
203 0 @return = "400 Not yet implemented";
204 # @return = $self->slave(@rest);
205 } elsif (lc $command eq 'stat') { # Works
206 0 @return = $self->stat($rest[0]);
207 } elsif (lc $command eq 'xgtitle') {
208 0 @return = "400 Not yet implemented";
209 # @return = $self->xgtitle(@rest);
210 } elsif (lc $command eq 'xhdr') {
211 # @return = $self->xhdr(@rest);
212 } elsif (lc $command eq 'xover') { # Works, I think
213 0 @return = $self->xover(@rest);
214 } elsif (lc $command eq 'xpat') {
215 0 @return = "400 Not yet implemented";
216 # @return = $self->xpat(@rest);
217 } elsif (lc $command eq 'xpath') {
218 0 @return = "400 Not yet implemented";
219 # @return = $self->xpath(@rest);
220 } elsif (lc $command eq 'quit') { # Works
221 0 $self->quit($fh);
222 0 return undef;
223 } else { # Works
224 0 @return = $self->badcommand;
225 }
226 0 print $fh join ($NEWLINE, @return, '');
227 0 1;
228 }
229  
230 =head2 NEWS SERVERS
231  
232 These functions return and manipulate the list of news servers that the
233 object connects to and works with.
234  
235 =item newsservers ( )
236  
237 Returns a reference to an array containing the list of news servers that
238 can be accessed.
239  
240 =item push ( SERVER [, SERVER [, SERVER [...]]] )
241  
242 Adds C<SERVER> item onto the end of the list of news servers.
243  
244 =item pop ( )
245  
246 Removes the first item from the list of the news servers.
247  
248 =cut
249  
250 0 ▶sub newsservers { shift->{'NEWSSERVERS'} }
Subroutine newsservers: not called CC=1 SCAR=6.9
Pod documented
251 0 ▶sub push { CORE::push ( @{shift->{'NEWSSERVERS'}}, @_ ) }
Subroutine push: not called CC=1 SCAR=6.9
Pod documented
252 0 ▶sub pop { unshift @{shift->{'NEWSSERVERS'}} }
Subroutine pop: not called CC=1 SCAR=6.9
Pod documented
253  
254  
255 =head2 NEWS FUNCTIONS
256  
257 These functions implement news functionality. Return values are designed
258 to be written to a socket, which is taken care of by C<process()>. None
259 of this stuff is overly well documented; it follows the NNTP standards
260 well where possible, however.
261  
262 =item authinfo ( USER, PASS )
263  
264 Not yet implemented.
265  
266 =cut
267  
268 0 ▶sub authinfo { }
Subroutine authinfo: not called CC=1 SCAR=0.0
Pod documented
269  
270 =item article ( ID [, HEAD, BODY] )
271  
272 Retrieve and return the article indicated by C<ID>. Looks through the
273 list of news servers in order; the first server to have the article
274 returns it.
275  
276 =cut
277  
278 0 ▶sub article {
Subroutine article: not called CC=17 SCAR=57.2
Pod documented
279 0 ▶ my ($self, $id, $head, $body) = @_; $id ||= "";
Condition0%0/2
$id ||= ""
l!l
00
MC/DC0%0/1
$id ||= ""
$id
Truth table0%0/2
A
A= $id
Aresult
11
00
280 0 ▶ return undef unless ($head || $body);
Branch: 1 branch
BranchTrueFalseTotal
unless $head or $body 0 0 0
Condition0%0/3
$head or $body
l!l&&r!l&&!r
000
MC/DC0%0/2
$head or $body
$head $body
Truth table0%0/3
A or B
A= $headB= $body
ABresult
1X1
011
000
281 0 my $article = $self->_article($id); # Helper function
282 0 ▶ if ($article && ref $article) { # We got the article.
Branch: 2 branches
BranchTrueFalseTotal
if ($article and ref $article) { } 0 0 0
elsif ($article) { } 0 0 0
Condition0%0/3
$article and ref $article
!ll&&!rl&&r
000
MC/DC0%0/2
$article and ref $article
$article ref $article
Truth table0%0/3
A and B
A= $articleB= ref $article
ABresult
0X0
100
111
283 0 ▶ my $ID = ($id =~ /^\d+$/) ? $id : 0;
Branch: 1 branch
BranchTrueFalseTotal
$id =~ /^\d+$/ ? : 0 0 0
284 0 my $messageid = $article->header('message-id');
285 0 my $code;
286 my @return;
287 0 ▶ if ($head) {
Branch: 1 branch
BranchTrueFalseTotal
if ($head) { } 0 0 0
288 0 ▶ CORE::push @return, $body ? "220 $ID $messageid article"
Branch: 1 branch
BranchTrueFalseTotal
$body ? : 0 0 0
289 : "221 $ID $messageid head"
290 } else {
291 0 ▶ CORE::push @return, "222 $ID $messageid body" if $body;
Branch: 1 branch
BranchTrueFalseTotal
if $body 0 0 0
292 }
293  
294 # We need to reformat the lines from rawheaders, which may include
295 # newlines, for later reformatting
296 0 ▶ if ($head) {
Branch: 1 branch
BranchTrueFalseTotal
if ($head) 0 0 0
297 0 my @headers = $article->rawheaders;
298 0 foreach (@headers) { CORE::push @return, split("\n", $_); }
299 0 ▶ CORE::push @return, "" if $body;
Branch: 1 branch
BranchTrueFalseTotal
if $body 0 0 0
300 }
301  
302 # Fix a bug in Net::NNTP
303 0 ▶ if ($body) { map { s/^\./../o } @{$article->body} }
Branch: 1 branch
BranchTrueFalseTotal
if ($body) 0 0 0
304 0 ▶ CORE::push @return, $article->body if $body;
Branch: 1 branch
BranchTrueFalseTotal
if $body 0 0 0
305 0 CORE::push @return, ".";
306 0 ▶ wantarray ? @return : join($NEWLINE, @return);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
307 } elsif ($article) { # Error message - return it
308 0 $article;
309 } else {
310 0 "420 No such article\n";
311 }
312 }
313  
314 =item body ( ID )
315  
316 As C<article()>, but just returns the body.
317  
318 =cut
319  
320 0 ▶sub body { shift->article($_[0], 0, 1) }
Subroutine body: not called CC=1 SCAR=6.9
Pod documented
321  
322 =item date ()
323  
324 Returns the current date from the server.
325  
326 =cut
327  
328 0 ▶sub date {
Subroutine date: not called CC=1 SCAR=6.9
Pod documented
329 0 my @localtime = gmtime;
330 0 sprintf("111 %04d%02d%02d%02d%02d%02d\n",
331 $localtime[5] + 1900, $localtime[4] + 1, $localtime[3] + 1,
332 $localtime[2], $localtime[1], $localtime[0]);
333 }
334  
335 =item group ( GROUP )
336  
337 Changes to the given C<GROUP>.
338  
339 =cut
340  
341 0 ▶sub group {
Subroutine group: not called CC=7 SCAR=40.3
Pod documented
342 0 ▶ my ($self, $group) = @_; return undef unless $group;
Branch: 1 branch
BranchTrueFalseTotal
unless $group 0 0 0
343 0 my ($newsgroup, $server) = $self->_group($group);
344 0 ▶ return $self->nosuchgroup($newsgroup) unless ($newsgroup && $server);
Branch: 1 branch
BranchTrueFalseTotal
unless $newsgroup and $server 0 0 0
Condition0%0/3
$newsgroup and $server
!ll&&!rl&&r
000
MC/DC0%0/2
$newsgroup and $server
$newsgroup $server
Truth table0%0/3
A and B
A= $newsgroupB= $server
ABresult
0X0
100
111
345 0 $$self{GROUP} = $newsgroup; $$self{SERVER} = $server;
346 0 my @list = $self->_listgroup($newsgroup, $server); my $count = scalar @list;
347 0 ▶ sprintf('211 %d %d %d %s', $count || 0, $list[0] || 0,
Branch: 1 branch
BranchTrueFalseTotal
$count ? : 0 0 0
Condition0%0/4
$count || 0
l!l
00
$list[0] || 0
l!l
00
MC/DC0%0/1
$count || 0
$count
MC/DC0%0/1
$list[0] || 0
$list[0]
Truth table0%0/2
A
A= $count
Aresult
11
00
Truth table0%0/2
A
A= $list[0]
Aresult
11
00
348 $count ? $list[$count - 1] : 0, $group);
349 }
350  
351 =item head ( ID )
352  
353 As C<article()>, but just returns the headers.
354  
355 =cut
356  
357 0 ▶sub head { shift->article($_[0], 1, 0) }
Subroutine head: not called CC=1 SCAR=6.9
Pod documented
358  
359 =item help ()
360  
361 Not yet implemented.
362  
363 =cut
364  
365 0 ▶sub help () { }
Subroutine help: not called CC=1 SCAR=0.0
Pod documented
366  
367 =item ihave ()
368  
369 Not yet implemented
370  
371 =cut
372  
373 0 ▶sub ihave { }
Subroutine ihave: not called CC=1 SCAR=0.0
Pod documented
374  
375 =item last ()
376  
377 Stats the previous message, if there is one. See C<stat()>.
378  
379 =cut
380  
381 0 ▶sub last {
Subroutine last: not called CC=3 SCAR=24.8
Pod documented
382 0 my $self = shift;
383 0 ▶ if ($$self{POINTER} < 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'POINTER'} < 0) { } 0 0 0
elsif ($self->{'POINTER'} == 0) { } 0 0 0
384 0 "422 No Previous Article";
385 } elsif ($$self{POINTER} == 0) {
386 0 $$self{POINTER}--; "422 No Previous Article";
387 } else {
388 0 $$self{POINTER}--; $self->stat();
389 }
390 }
391  
392 =item list ( TYPE ARGS )
393  
394 Lists off a certain value. Valid values are:
395  
396 active ( PATTERN )
397 active.times
398 newsgroups ( PATTERN )
399 overview.fmt (NOT YET IMPLEMENTED)
400  
401 =cut
402  
403 0 ▶sub list {
Subroutine list: not called CC=7 SCAR=40.3
Pod documented
404 0 my ($self, $type, @args) = @_;
405 0 ▶ if (lc $type eq 'active' || lc $type eq '') {
Branch: 4 branches
BranchTrueFalseTotal
if (lc $type eq 'active' or lc $type eq '') { } 0 0 0
elsif (lc $type eq 'active.times' or $type eq 'active_times') { } 0 0 0
elsif (lc $type eq 'overview.fmt') { } 0 0 0
elsif (lc $type eq 'newsgroups') { } 0 0 0
Condition0%0/3
lc $type eq "active" or lc $type eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
lc $type eq "active" or lc $type eq ""
lc $type eq "active" lc $type eq ""
Truth table0%0/3
A or B
A= lc $type eq "active"B= lc $type eq ""
ABresult
1X1
011
000
406 0 $self->_list_active(@args);
407 ▶ } elsif (lc $type eq 'active.times' || $type eq 'active_times') {
Condition0%0/3
lc $type eq "active.times" or $type eq "active_times"
l!l&&r!l&&!r
000
MC/DC0%0/2
lc $type eq "active.times" or $type eq "active_times"
lc $type eq "active.times" $type eq "active_times"
Truth table0%0/3
A or B
A= lc $type eq "active.times"B= $type eq "active_times"
ABresult
1X1
011
000
408 0 $self->_list_active_times(@args);
409 } elsif (lc $type eq 'overview.fmt') { # Tricky
410 } elsif (lc $type eq 'newsgroups') {
411 0 $self->_list_newsgroups(@args);
412 } else { # None of the supported lists -> bad command
413 0 $self->badcommand;
414 }
415 }
416  
417 =item listgroup ( GROUP )
418  
419 Loads up a given group, and gets a list of articles in it.
420  
421 =cut
422  
423 0 ▶sub listgroup { # Works!
Subroutine listgroup: not called CC=3 SCAR=24.8
Pod documented
424 0 my ($self, $group) = @_;
425 0 my ($newsgroup, $server) = $self->_group($group);
426 0 ▶ return $self->nosuchgroup($group) unless ($newsgroup && $server);
Branch: 1 branch
BranchTrueFalseTotal
unless $newsgroup and $server 0 0 0
Condition0%0/3
$newsgroup and $server
!ll&&!rl&&r
000
MC/DC0%0/2
$newsgroup and $server
$newsgroup $server
Truth table0%0/3
A and B
A= $newsgroupB= $server
ABresult
0X0
100
111
427 0 $$self{GROUP} = $newsgroup; $$self{SERVER} = $server;
428 0 my @list = $self->_listgroup($group, $server); my $count = scalar @list;
429 0 return join("\n", "211 Article list follows", @list, ".");
430 }
431  
432 =item mode ( STRING )
433  
434 Sets the reader mode. At present, only 'reader' works.
435  
436 =cut
437  
438 0 ▶sub mode { # Works!
Subroutine mode: not called CC=3 SCAR=24.8
Pod documented
439 0 my ($self, $mode) = @_;
440 0 ▶ return $self->badcommand unless lc $mode eq 'reader';
Branch: 1 branch
BranchTrueFalseTotal
unless lc $mode eq "reader" 0 0 0
441 0 ▶ return "200 " . ($CONNMESSAGE || "Welcome to $0");
Condition0%0/2
$Net::NNTP::Proxy::CONNMESSAGE || "Welcome to $0"
l!l
00
MC/DC0%0/1
$Net::NNTP::Proxy::CONNMESSAGE || "Welcome to $0"
$Net::NNTP::Proxy::CONNMESSAGE
Truth table0%0/2
A
A= $Net::NNTP::Proxy::CONNMESSAGE
Aresult
11
00
442 }
443  
444 =item newgroups ( GROUPS, DATE, TIME, [TZ] )
445  
446 Not yet implemented
447  
448 =cut
449  
450 0 ▶sub newgroups { }
Subroutine newgroups: not called CC=1 SCAR=0.0
Pod documented
451  
452 # newnews newsgroups yyyymmdd hhmmss [GMT]
453  
454 =item newnews ( GROUPS, DATE, TIME, [TZ] )
455  
456 Not yet implemented
457  
458 =cut
459  
460 0 ▶sub newnews { }
Subroutine newnews: not called CC=1 SCAR=0.0
Pod documented
461 # next
462 0 ▶sub next {
Subroutine next: not called CC=3 SCAR=24.8
Pod undocumented
463 0 my $self = shift;
464 0 ▶ return $self->nogroupselect() unless (defined $$self{GROUP});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"GROUP"} 0 0 0
465 0 ▶ if ($$self{POINTER} >= scalar@{$$self{ARTICLES}} - 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'POINTER'} >= scalar @{$self->{'ARTICLES'};} - 1) { } 0 0 0
466 0 "421 No Next Article";
467 0 } else { $$self{POINTER}++; $self->stat; }
468 }
469 # post
470 0 ▶sub post {
Subroutine post: not called CC=11 SCAR=48.8
Pod undocumented
471 0 ▶ my ($self, $fh) = @_; return undef unless $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 0 0 0
472 0 print $fh "340 Send article to be posted\n";
473 0 my @lines;
474 0 ▶ while (defined (my $line = <$fh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
475 0 $line =~ s/(\r?\n|\n?\r)$//g; # chomp wasn't working
476 0 ▶ last if $line =~ /^\.$/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\.$/ 0 0 0
477 0 CORE::push @lines, $line;
478 }
479 0 ▶ my $article = News::Article->new(\@lines)
Condition0%0/2
'News::Article'->new(\@lines) || (return '441 Posting Failed (Article was Empty)')
l!l
00
MC/DC0%0/1
'News::Article'->new(\@lines) || (return '441 Posting Failed (Article was Empty)')
'News::Article'->new(\@lines)
Truth table0%0/2
A
A= 'News::Article'->new(\@lines)
Aresult
11
00
480 || return "441 Posting Failed (Article was Empty)";
481 0 ▶ $article->write(\*STDOUT) if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Net::NNTP::Proxy::DEBUG 0 0 0
482 0 $article->set_headers('newsgroups',
483 $self->_fix_groups($article->header('newsgroups')) );
484 0 $article->add_message_id; $article->add_date;
485 0 my $success = 0; my @problems;
486 0 foreach my $server (@{$self->newsservers}) {
487 0 ▶ my $nntp = $server->nntp || next;
Condition0%0/2
$server->nntp || (next)
l!l
00
MC/DC0%0/1
$server->nntp || (next)
$server->nntp
Truth table0%0/2
A
A= $server->nntp
Aresult
11
00
488 0 my $name = $server->name;
489 0 ▶ next unless $server->postok;
Branch: 1 branch
BranchTrueFalseTotal
unless $server->postok 0 0 0
490 0 local $@;
491 0 warn "Posting to $name\n";
492 0 eval { $article->post($nntp) } ;
493 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
494 0 chomp $@;
495 0 warn "Error in posting to $name: $@\n";
496 0 CORE::push @problems, "$name: $@";
497 } else {
498 0 $success++;
499 }
500 }
501 0 ▶ $success ? "240 Article Posted to $success servers"
Branch: 1 branch
BranchTrueFalseTotal
$success ? : 0 0 0
502 : "441 Was unable to post to any news servers - " . join(', ', @problems);
503 }
504  
505 =item slave ()
506  
507 Not yet implemented
508  
509 =cut
510  
511 0 ▶sub slave () { }
Subroutine slave: not called CC=1 SCAR=0.0
Pod documented
512  
513 # stat [MessageID|Number]
514 0 ▶sub stat {
Subroutine stat: not called CC=5 SCAR=34.0
Pod undocumented
515 0 my ($self, $id) = @_;
516 0 ▶ return $self->nogroupselect() unless (defined $$self{GROUP});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"GROUP"} 0 0 0
517 0 my ($number, $messageid) = $self->_stat($id);
518 0 ▶ $number ||= 0;
Condition0%0/2
$number ||= 0
l!l
00
MC/DC0%0/1
$number ||= 0
$number
Truth table0%0/2
A
A= $number
Aresult
11
00
519  
520 0 ▶ if ($messageid) { return "223 $number $messageid"; }
Branch: 2 branches
BranchTrueFalseTotal
if ($messageid) { } 0 0 0
elsif ($number) { } 0 0 0
521 0 elsif ($number) { return "423 No Such Article In Group"; }
522 0 else { return "430 No Such Article"; }
523 }
524  
525 =item xgtitle ( GROUP_PATTERN )
526  
527 Not yet implemented
528  
529 =cut
530  
531 0 ▶sub xgtitle { }
Subroutine xgtitle: not called CC=1 SCAR=0.0
Pod documented
532  
533 =item xhdr ( RANGE | ID )
534  
535 Not yet implemented
536  
537 =cut
538  
539 0 ▶sub xhdr { }
Subroutine xhdr: not called CC=1 SCAR=0.0
Pod documented
540  
541 =item xover ( RANGE )
542  
543 Returns the overview information from the given C<RANGE>.
544  
545 =cut
546  
547 0 ▶sub xover {
Subroutine xover: not called CC=5 SCAR=34.0
Pod documented
548 0 my ($self, $range) = @_;
549 0 ▶ return $self->nogroupselect() unless (defined $$self{GROUP});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"GROUP"} 0 0 0
550
551 0 ▶ my $server = $$self{SERVER} || return undef;
Condition0%0/2
$self->{'SERVER'} || (return undef)
l!l
00
MC/DC0%0/1
$self->{'SERVER'} || (return undef)
$self->{'SERVER'}
Truth table0%0/2
A
A= $self->{'SERVER'}
Aresult
11
00
552 0 ▶ my $hash = $server->xover($range) || return undef;
Condition0%0/2
$server->xover($range) || (return undef)
l!l
00
MC/DC0%0/1
$server->xover($range) || (return undef)
$server->xover($range)
Truth table0%0/2
A
A= $server->xover($range)
Aresult
11
00
553 0 my @return = "224 overview data follows";
554 0 foreach (sort { $a <=> $b } keys %{$hash}) {
555 0 CORE::push @return, join("\t", $_, @{$$hash{$_}});
556 }
557 0 CORE::push @return, ".";
558
559 0 join("\n", @return);
560 }
561  
562 =item xpat ( HEADER, RANGE | ID, PATTERN [, PATTERN [, PATTERN ]] )
563  
564 Not yet implemented
565  
566 =cut
567  
568 0 ▶sub xpat { }
Subroutine xpat: not called CC=1 SCAR=0.0
Pod documented
569  
570 =item xpath ( ID )
571  
572 Not yet implemented
573  
574 =cut
575  
576 0 ▶sub xpath { }
Subroutine xpath: not called CC=1 SCAR=0.0
Pod documented
577  
578 =item quit ( FILEHANDLE )
579  
580 Close C<FILEHANDLE> and quit.
581  
582 =cut
583  
584 0 ▶sub quit {
Subroutine quit: not called CC=2 SCAR=17.9
Pod documented
585 0 my ($self, $fh) = @_;
586 0 ▶ return undef unless defined fileno($fh);
Branch: 1 branch
BranchTrueFalseTotal
unless defined fileno $fh 0 0 0
587 0 print $fh "205 Goodbye\n";
588 0 close $fh;
589 }
590  
591 # Error messages
592 0 ▶sub nosuchgroup { my $group = shift || ""; return "411 No such group $group" }
Subroutine nosuchgroup: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
593 0 ▶sub badcommand { "500 Syntax Error or Unknown Command" }
Subroutine badcommand: not called CC=1 SCAR=6.9
Pod undocumented
594 0 ▶sub nogroupselect { "512 No Group Selected" }
Subroutine nogroupselect: not called CC=1 SCAR=6.9
Pod undocumented
595 0 ▶sub badarticlenumber { "423 Bad article number"; }
Subroutine badarticlenumber: not called CC=1 SCAR=6.9
Pod undocumented
596  
597 ###############################################################################
598 ##### INTERNAL AND HELPER FUNCTIONS ###########################################
599 ###############################################################################
600  
601 ### DESTROY
602 # When the object goes away, make sure that disconnect() is called.
603 0 ▶sub DESTROY { shift->disconnect() }
Subroutine DESTROY: not called CC=1 SCAR=6.9
604  
605 ### _fix_groups ( LINE )
606 # Takes a Newsgroups: line, and takes out everything after the '@' in each
607 # group. This is important for translating back to the real world's groups.
608 # Hopefully this won't break PGPMoose and such too badly; I don't think they
609 # follow Newsgroups:...
610 0 ▶sub _fix_groups {
Subroutine _fix_groups: not called CC=2 SCAR=17.9
611 0 my ($self, $line) = @_;
612 0 ▶ my @groups = split(',', $line || "");
Condition0%0/2
$line || ''
l!l
00
MC/DC0%0/1
$line || ''
$line
Truth table0%0/2
A
A= $line
Aresult
11
00
613 0 map { s/^\s*(\S+)(@\S*)\s*$/$1/ } @groups;
614 0 join(',', @groups);
615 }
616  
617 ### _group ( GROUP )
618 # Loads GROUP from the appropriate server
619 0 ▶sub _group {
Subroutine _group: not called CC=10 SCAR=47.0
620 0 ▶ my ($self, $group) = @_; return undef unless $group;
Branch: 1 branch
BranchTrueFalseTotal
unless $group 0 0 0
621 0 ▶ if ($group =~ /^(.*)@(.*)$/) { # Group we created
Branch: 1 branch
BranchTrueFalseTotal
if ($group =~ /^(.*)@(.*)$/) { } 0 0 0
622 0 my $newsgroup = $1; my $servername = $2;
623 0 foreach my $server (@{$$self{NEWSSERVERS}}) {
624 0 ▶ next unless $server;
Branch: 1 branch
BranchTrueFalseTotal
unless $server 0 0 0
625 0 my $newsserver = $server->name;
626 0 ▶ return ($newsgroup, $server) if ($servername eq $newsserver);
Branch: 1 branch
BranchTrueFalseTotal
if $servername eq $newsserver 0 0 0
627 }
628 0 return undef;
629 } else { # Group we're proxying
630 0 my $newsgroup = $group;
631 # Figure out which server has the first feed of this group.
632 0 foreach my $server (@{$$self{NEWSSERVERS}}) {
633 0 ▶ next unless ($server && $server->connected);
Branch: 1 branch
BranchTrueFalseTotal
unless $server and $server->connected 0 0 0
Condition0%0/3
$server and $server->connected
!ll&&!rl&&r
000
MC/DC0%0/2
$server and $server->connected
$server $server->connected
Truth table0%0/3
A and B
A= $serverB= $server->connected
ABresult
0X0
100
111
634 0 ▶ $server->group($newsgroup) ? return ($newsgroup, $server) : next;
Branch: 1 branch
BranchTrueFalseTotal
$server->group($newsgroup) ? : 0 0 0
635 }
636 }
637 0 return undef;
638 }
639  
640 ### _list_newsgroups ( [PATTERN] )
641 # Creates the newsgroups list out of the newsgroups values.
642 0 ▶sub _list_newsgroups {
Subroutine _list_newsgroups: not called CC=7 SCAR=40.3
643 0 my ($self, $pattern) = @_;
644 0 ▶ $pattern ||= '*';
Condition0%0/2
$pattern ||= "*"
l!l
00
MC/DC0%0/1
$pattern ||= "*"
$pattern
Truth table0%0/2
A
A= $pattern
Aresult
11
00
645 0 my @return = "215 Newsgroups Follow";
646 0 my %fullhash;
647 0 foreach (@{$$self{'NEWSSERVERS'}}) {
648 0 my $server = $_->server;
649 0 my $hash = $_->newsgroups($pattern);
650 0 foreach (keys %{$hash}) {
651 0 ▶ $fullhash{$_} ||= $$hash{$_};
Condition0%0/3
$fullhash{$_} ||= $hash->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$fullhash{$_} ||= $hash->{$_}
$fullhash{$_} $hash->{$_}
Truth table0%0/3
A ||= B
A= $fullhash{$_}B= $hash->{$_}
ABresult
1X1
011
000
652 0 CORE::push @return, "$_\@$server $$hash{$_}";
653 }
654 }
655 0 foreach (keys %fullhash) { CORE::push @return, "$_ $fullhash{$_}"; }
656 0 CORE::push @return, ".";
657 0 ▶ wantarray ? @return : join($NEWLINE, @return);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
658 }
659  
660 ### _list_active ( [PATTERN] )
661 # Creates the active list out of the active values.
662 0 ▶sub _list_active {
Subroutine _list_active: not called CC=10 SCAR=47.0
663 0 my ($self, $pattern) = @_;
664 0 ▶ $pattern ||= '*';
Condition0%0/2
$pattern ||= "*"
l!l
00
MC/DC0%0/1
$pattern ||= "*"
$pattern
Truth table0%0/2
A
A= $pattern
Aresult
11
00
665 0 my @return = "215 Newsgroups Follow .";
666 0 my %fullhash;
667 0 foreach (@{$$self{'NEWSSERVERS'}}) {
668 0 ▶ my $name = $_->name || "";
Condition0%0/2
$_->name || ''
l!l
00
MC/DC0%0/1
$_->name || ''
$_->name
Truth table0%0/2
A
A= $_->name
Aresult
11
00
669 0 ▶ my $hash = $_->active($pattern) || {};
Condition0%0/2
$_->active($pattern) || {}
l!l
00
MC/DC0%0/1
$_->active($pattern) || {}
$_->active($pattern)
Truth table0%0/2
A
A= $_->active($pattern)
Aresult
11
00
670 0 foreach (sort keys %{$hash}) {
671 0 ▶ next unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 0 0
672 0 CORE::push @return, "$_\@$name @{$$hash{$_}}";
673 0 ▶ $fullhash{$_} ||= "@{$$hash{$_}}";
Condition0%0/3
$fullhash{$_} ||= join($", @{$hash->{$_};})
l!l&&r!l&&!r
000
MC/DC0%0/2
$fullhash{$_} ||= join($", @{$hash->{$_};})
$fullhash{$_} join($", @{$hash->{$_};})
Truth table0%0/3
A ||= B
A= $fullhash{$_}B= join($", @{$hash->{$_};})
ABresult
1X1
011
000
674 }
675 }
676 0 foreach (sort keys %fullhash) { CORE::push @return, "$_ $fullhash{$_}"; }
677 0 CORE::push @return, ".";
678 0 ▶ wantarray ? @return : join($NEWLINE, @return);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
679 }
680  
681 ### _list_active_times ( [PATTERN] )
682 # Creates the active.times list out of the active.times values.
683 0 ▶sub _list_active_times {
Subroutine _list_active_times: not called CC=8 SCAR=42.8
684 0 my ($self, $pattern) = @_;
685 0 ▶ $pattern ||= '*';
Condition0%0/2
$pattern ||= "*"
l!l
00
MC/DC0%0/1
$pattern ||= "*"
$pattern
Truth table0%0/2
A
A= $pattern
Aresult
11
00
686 0 my @return = "215 Group Creations";
687 0 my %fullhash;
688 0 foreach (@{$$self{'NEWSSERVERS'}}) {
689 0 my $server = $_->name;
690 0 my $hash = $_->active_times();
691 0 foreach (sort keys %{$hash}) {
692 0 ▶ next unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 0 0
693 0 CORE::push @return, "$_\@$server @{$$hash{$_}}[0]";
694 0 ▶ $fullhash{$_} ||= "@{$$hash{$_}}[0]";
Condition0%0/3
$fullhash{$_} ||= join($", @{$$hash{$_};}[0])
l!l&&r!l&&!r
000
MC/DC0%0/2
$fullhash{$_} ||= join($", @{$$hash{$_};}[0])
$fullhash{$_} join($", @{$$hash{$_};}[0])
Truth table0%0/3
A ||= B
A= $fullhash{$_}B= join($", @{$$hash{$_};}[0])
ABresult
1X1
011
000
695 }
696 }
697 0 foreach (sort keys %fullhash) { CORE::push @return, "$_ $fullhash{$_}"; }
698 0 CORE::push @return, ".";
699 0 ▶ wantarray ? @return : join($NEWLINE, @return);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
700 }
701  
702 ### _listgroup ( [GROUP] , SERVER )
703 # Returns the listgroup information. GROUP can be 'undef' if you'd like.
704 0 ▶sub _listgroup {
Subroutine _listgroup: not called CC=4 SCAR=30.0
705 0 ▶ my ($self, $group, $server) = @_; return undef unless $server;
Branch: 1 branch
BranchTrueFalseTotal
unless $server 0 0 0
706 0 ▶ $$self{ARTICLES} = $server->listgroup($group) || [];
Condition0%0/2
$server->listgroup($group) || []
l!l
00
MC/DC0%0/1
$server->listgroup($group) || []
$server->listgroup($group)
Truth table0%0/2
A
A= $server->listgroup($group)
Aresult
11
00
707 0 $$self{POINTER} = 0;
708 0 ▶ wantarray ? @{$$self{ARTICLES}} : $$self{ARTICLES};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
709 }
710  
711 ### _stat ( [ID] )
712 # Get the stat information on C<ID>, and set $POINTER if necessary.
713 0 ▶sub _stat {
Subroutine _stat: not called CC=20 SCAR=60.4
714 0 my ($self, $id) = @_;
715  
716 # Get the various important values for later use
717 0 my $pointer = $$self{POINTER}; my @articles = @{$$self{ARTICLES}};
718 0 my $server = $$self{SERVER}; my $group = $$self{GROUP};
719 0 my @servers = @{$$self{NEWSSERVERS}};
720
721 0 ▶ if (!(defined $id)) { # No ID given at all -> last result
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $id) { } 0 0 0
elsif ($id =~ /^\d+$/) { } 0 0 0
722 0 ▶ return (-1, undef) unless ($pointer >= 0);
Branch: 1 branch
BranchTrueFalseTotal
unless $pointer >= 0 0 0 0
723 0 ▶ if (defined $pointer && scalar @articles && defined $server) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $pointer and scalar @articles and defined $server) { } 0 0 0
elsif (scalar @articles and defined $server) { } 0 0 0
Condition0%0/5
defined $pointer and scalar @articles and defined $server
!ll&&!rl&&r
000
defined $pointer and scalar @articles
!ll
00
MC/DC0%0/2
defined $pointer and scalar @articles and defined $server
defined $pointer defined $server
Truth table0%0/3
A and B
A= defined $pointerB= defined $server
ABresult
0X0
100
111
724 # my $nntp = $server->nntp || return (undef, undef);
725 0 my $messageid = $server->nntpstat($articles[$pointer]);
726 0 ▶ return ($articles[$pointer], $messageid) if $messageid;
Branch: 1 branch
BranchTrueFalseTotal
if $messageid 0 0 0
727 ▶ } elsif (scalar @articles && defined $server) {
Condition0%0/3
scalar @articles and defined $server
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @articles and defined $server
scalar @articles defined $server
Truth table0%0/3
A and B
A= scalar @articlesB= defined $server
ABresult
0X0
100
111
728 0 return (1, undef)
729 } else {
730 0 return (undef, undef);
731 }
732 } elsif ($id =~ /^\d+$/) { # Numeric ID -> in a group
733 # If we're not in a group, then just stop now.
734 0 ▶ return (undef, undef) unless ( scalar @articles && defined $server );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @articles and defined $server 0 0 0
Condition0%0/3
scalar @articles and defined $server
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @articles and defined $server
scalar @articles defined $server
Truth table0%0/3
A and B
A= scalar @articlesB= defined $server
ABresult
0X0
100
111
735 # There's two choices here - do it locally, or do it by the 'net. The
736 # latter is more computationally efficient but requires network accesses.
737 0 ▶ for (my $i = 0; $i < scalar @articles; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @articles) 0 0 0
738 0 ▶ if ($articles[$i] eq $id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($articles[$i] eq $id) 0 0 0
739 0 ▶ my $messageid = $server->nntpstat($articles[$i]) || next;
Condition0%0/2
$server->nntpstat($articles[$i]) || (next)
l!l
00
MC/DC0%0/1
$server->nntpstat($articles[$i]) || (next)
$server->nntpstat($articles[$i])
Truth table0%0/2
A
A= $server->nntpstat($articles[$i])
Aresult
11
00
740 0 ▶ $$self{POINTER} = $i if $messageid;
Branch: 1 branch
BranchTrueFalseTotal
if $messageid 0 0 0
741 0 ▶ return ($id, $messageid) if $messageid;
Branch: 1 branch
BranchTrueFalseTotal
if $messageid 0 0 0
742 }
743 }
744 0 $$self{POINTER} = undef;
745 0 return ($id, undef);
746 } else { # It's a full message ID
747 0 foreach ($server, @servers) {
748 0 ▶ next unless $_;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 0 0
749 0 my $messageid = $_->nntpstat($id);
750 0 ▶ return (0, $messageid) if $messageid;
Branch: 1 branch
BranchTrueFalseTotal
if $messageid 0 0 0
751 }
752 0 return (undef, undef);
753 }
754 }
755  
756 ### _article ( ID [, NID] )
757 # Downloads the given ID from all of the object's news servers.
758 0 ▶sub _article {
Subroutine _article: not called CC=13 SCAR=52.0
759 0 ▶ my ($self, $id, $nid) = @_; $id ||= "";
Condition0%0/2
$id ||= ""
l!l
00
MC/DC0%0/1
$id ||= ""
$id
Truth table0%0/2
A
A= $id
Aresult
11
00
760  
761 # If the given ID is numeric or not given, then try to find and
762 # load the appropriate message-ID. If that doesn't work, then it
763 # was a bad number.
764 0 ▶ if (!$id || $id =~ /^\d+$/) { # Non-existant or numeric
Branch: 1 branch
BranchTrueFalseTotal
if (not $id or $id =~ /^\d+$/) 0 0 0
Condition0%0/3
not $id or $id =~ /^\d+$/
l!l&&r!l&&!r
000
MC/DC0%0/2
not $id or $id =~ /^\d+$/
not $id $id =~ /^\d+$/
Truth table0%0/3
not(A) or B
A= not $idB= $id =~ /^\d+$/
ABresult
1X1
011
000
765 0 my ($number, $mid) = $self->_stat($id);
766 0 ▶ return "" if ($id && $mid && ($id eq $mid)); # TESTING
Branch: 1 branch
BranchTrueFalseTotal
if $id and $mid and $id eq $mid 0 0 0
Condition0%0/6
$id and $mid and $id eq $mid
!ll&&!rl&&r
000
$id and $mid
!ll&&!rl&&r
000
MC/DC0%0/3
$id and $mid and $id eq $mid
$id $mid $id eq $mid
Truth table0%0/4
A and B and C
A= $idB= $midC= $id eq $mid
ABCresult
0XX0
10X0
1100
1111
767 0 $self->_group($$self{GROUP});
768 0 ▶ return $self->_article( $mid, $id ) || $self->badarticlenumber;
Condition0%0/3
$self->_article($mid, $id) || $self->badarticlenumber
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_article($mid, $id) || $self->badarticlenumber
$self->_article($mid, $id) $self->badarticlenumber
Truth table0%0/3
A || B
A= $self->_article($mid, $id)B= $self->badarticlenumber
ABresult
1X1
011
000
769 }
770  
771 0 ▶ warn "Looking for article $id\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Net::NNTP::Proxy::DEBUG 0 0 0
772
773 # Search through all of the news servers in order for the full
774 # message-ID.
775 0 foreach my $server (@{$$self{NEWSSERVERS}}) {
776 0 my $article = News::Article->new($server->article($id));
777 0 ▶ return $article if $article;
Branch: 1 branch
BranchTrueFalseTotal
if $article 0 0 0
778 }
779 # If all else fails, go with the numeric ID (if possible)
780 0 ▶ my $server = $$self{SERVER} || return undef;
Condition0%0/2
$self->{'SERVER'} || (return undef)
l!l
00
MC/DC0%0/1
$self->{'SERVER'} || (return undef)
$self->{'SERVER'}
Truth table0%0/2
A
A= $self->{'SERVER'}
Aresult
11
00
781 0 my $article = News::Article->new($server->article($nid));
782 0 ▶ $article ? $article : undef;
Branch: 1 branch
BranchTrueFalseTotal
$article ? : 0 0 0
783 }
784  
785 ### _open_socket ( PORT [, MAXCONN] )
786 # Build a socket. Code taken from Programming Perl, 3rd Edition.
787 0 ▶sub _open_socket {
Subroutine _open_socket: not called CC=7 SCAR=40.3
788 0 my ($self, $port, $maxconn) = @_;
789 0 ▶ return undef unless $port;
Branch: 1 branch
BranchTrueFalseTotal
unless $port 0 0 0
790
791 # make the socket
792 0 socket(SERVER, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
793
794 # so we can restart our server quickly
795 0 setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1);
796
797 # build up my socket address
798 0 ▶ unless (bind (SERVER, sockaddr_in($port, INADDR_ANY) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (bind SERVER, sockaddr_in($port, "\0\0\0\0")) 0 0 0
799 0 warn "Couldn't bind to port $port: $!\n";
800 0 return undef;
801 }
802
803 # establish a queue for incoming connections
804 0 ▶ unless (listen(SERVER, $maxconn || $MAXCONN || SOMAXCONN) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (listen SERVER, $maxconn || $Net::NNTP::Proxy::MAXCONN || 4096) 0 0 0
Condition0%0/5
$maxconn || $Net::NNTP::Proxy::MAXCONN || 4096
l!l
00
$maxconn or $Net::NNTP::Proxy::MAXCONN
l!l&&r!l&&!r
000
MC/DC0%0/2
$maxconn || $Net::NNTP::Proxy::MAXCONN || 4096
$maxconn $Net::NNTP::Proxy::MAXCONN
Truth table0%0/3
A or B
A= $maxconnB= $Net::NNTP::Proxy::MAXCONN
ABresult
1X1
011
000
805 0 warn "Couldn't listen on port $port: $!\n";
806 0 return undef;
807 }
808 0 ▶ warn "Listening on port $port\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Net::NNTP::Proxy::DEBUG 0 0 0
809
810 0 \*SERVER;
811 }
812  
813 =back
814  
815 =head1 REQUIREMENTS
816  
817 C<News::Article>, C<Net::NNTP>
818  
819 =head1 NOTES
820  
821 This documentation is basically functional, but not much more.
822  
823 =head1 SEE ALSO
824  
825 L<Net::NNTP>, L<Net::NNTP::Client>, L<newsproxy.pl>
826  
827 =head1 TODO
828  
829 Write better documentation. Write other news server types that aren't
830 Net::NNTP::Client. Implement the rest of the functions that I haven't
831 gotten around to yet. Speed it up.
832  
833 =head1 AUTHOR
834  
835 Written by Tim Skirvin <tskirvin@killfile.org>.
836  
837 =head1 COPYRIGHT
838  
839 Copyright 2000-2002 by Tim Skirvin <tskirvin@killfile.org>. This code may be
840 redistributed under the same terms as Perl itself.
841  
842 =cut
843  
844 1 1;
845  
846 # Version History
847 # v0.5a - Thu Nov 9 18:03:58 CST 2000
848 # Commenting in progress. This thing still needs some serious work to
849 # make it pretty, though.
850 # v0.51a - Tue Apr 24 15:56:49 CDT 2001
851 # Worked around a bug from Net::NNTP where '^..' is turned into '^.'.
852 # v0.52a - Mon Jan 28 11:30:32 CST 2002
853 # Replaced push() with CORE::push(). Started sorting the active and
854 # active_times() outputs. Changed to variable EOL string. Fixed some
855 # bugs in _list_active and the line with returning arrays.
856 # v0.53a - Wed Jan 30 09:32:27 CST 2002
857 # Fixed article() to have uniform newlines.
858 # v0.54 Thu Apr 22 11:44:01 CDT 2004
859 ### No real changes, just internal layout changes.
« News/Article/Cancel.pm ↑ Summary News/Article/Response.pm »