Yenta/Server.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 8 Conditioncond n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 71 CC 5 SCAR 21.0
CC
5
Cov
0%
read
20.0
new
6.0
timeout
2.0
CRAP 8.2
1 # -*- perl -*-
2  
3 # Copyright (c) 2009 AdCopy
4 # Author: Jeff Weisberg
5 # Created: 2009-Mar-30 10:34 (EDT)
6 # Function: server side
7 #
8 # $Id: Server.pm,v 1.14 2010/12/22 15:24:41 jaw Exp $
9  
10 package AC::Yenta::Server;
11 use AC::Yenta::Debug 'server';
12 use AC::Yenta::Protocol;
13 use AC::Yenta::Config;
14 use AC::Yenta::Kibitz::Status::Server;
15 use AC::Yenta::Kibitz::Store::Server;
16 use strict;
17  
18 our @ISA = 'AC::DC::IO::TCP';
19  
20 my $HDRSIZE = AC::Yenta::Protocol->header_size();
21 my $TIMEOUT = 2;
22  
23 my %HANDLER = (
24 yenta_status => 'AC::Yenta::Kibitz::Status::Server',
25 yenta_get => \&AC::Yenta::Kibitz::Store::Server::api_get,
26 yenta_distrib => \&AC::Yenta::Kibitz::Store::Server::api_distrib,
27 yenta_check => \&AC::Yenta::Kibitz::Store::Server::api_check,
28 http => 'AC::Yenta::Stats',
29 );
30  
31 sub new {
32 my $class = shift;
33 my $fd = shift;
34 my $ip = shift;
35  
36 unless( $AC::Yenta::CONF->check_acl( $ip ) ){
37 verbose("rejecting connection from $ip");
38 return;
39 }
40  
41 my $me = $class->SUPER::new( peerip => $ip, info => "tcp yenta server (from: $ip)" );
42  
43 $me->init($fd);
44 $me->wantread(1);
45 $me->timeout_rel($TIMEOUT);
46 $me->set_callback('read', \&read);
47 $me->set_callback('timeout', \&timeout);
48 }
49  
50 sub timeout {
51 my $me = shift;
52  
53 debug("connection timed out");
54 $me->shut();
55 }
56  
57 sub read {
58 my $me = shift;
59 my $evt = shift;
60  
61 my $yp = AC::Yenta::Protocol->new( secret => conf_value('secret') );
62 my($proto, $data, $content) = $yp->read_protocol( $me, $evt );
63 return unless $proto;
64  
65 # dispatch request
66 my $h = $HANDLER{ $proto->{type} };
67  
68 unless( $h ){
69 verbose("unknown message type: $proto->{type}");
70 $me->shut();
71 return;
72 }
73  
74 debug("handling request - $proto->{type}");
75  
76 if( ref $h ){
77 $h->( $me, $proto, $data, $content );
78 }else{
79 $h->handler( $me, $proto, $data, $content );
80 }
81 }
82  
83  
84 1;