JSONRPC/Http.pm

filter: Statementstmt 48.7% 20 / 41 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 6 / 10 Podpod 100% 4 / 4 totaltotal 44.7% 30 / 67 CC 7 SCAR 28.4
CC
7
Cov
38%
poe_init_server
42.0
poe_http_authentication_input_handler
6.0
new
2.0
CRAP 17.1
« JSONRPC.pm ↑ Summary
1 ##############################
2 # This code is part of FusionDirectory (http://www.fusiondirectory.org/)
3 # Copyright (C) 2011 FusionDirectory
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ##############################
19  
20 package POE::Component::Server::JSONRPC::Http;
21 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use POE::Component::Server::JSONRPC; # for old Perl 5.005
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use base qw(POE::Component::Server::JSONRPC);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 2 our $VERSION = '0.06';
27  
28 2 ▶use POE qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
29 Component::Server::SimpleHTTP
30 Filter::Line
31 2 /;
32  
33 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 =head1 NAME
36  
37 POE::Component::Server::JSONRPC::Http - POE http based JSON-RPC server
38  
39 =head2 new
40  
41 constructor
42 =cut
43  
44 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
45 0 my $class = shift;
46 0 return $class->SUPER::new(@_);
47 }
48  
49 =head2 poe_init_server
50  
51 Init HTTP Server.
52 =cut
53  
54 0 ▶sub poe_init_server {
Subroutine poe_init_server: not called CC=6 SCAR=37.4
Pod documented
55 0 my ($self, $kernel, $session, $heap) = @_[OBJECT, KERNEL, SESSION, HEAP];
56  
57 0 $kernel->alias_set( 'JSONRPCHTTP' );
58  
59 0 ▶ if (defined($self->{Authenticate})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'Authenticate'}) { } 0 0 0
60 0 $kernel->state('http_input_handler' , $self, 'poe_http_authentication_input_handler');
61 } else {
62 0 $kernel->state('http_input_handler' , $self, 'poe_input_handler');
63 }
64  
65 $self->{http} = POE::Component::Server::SimpleHTTP->new(
66 'ALIAS' => 'HTTPD',
67 'PORT' => $self->{Port},
68 $self->{Address} ? ('ADDRESS' => $self->{Address} ) : (),
69 $self->{Hostname} ? ('HOSTNAME' => $self->{Hostname} ) : (),
70 $self->{SslKey} ? ('SSLKEYCERT' => [$self->{SslKey}, $self->{SslCert}]) : (),
71 0 ▶ $self->{SslCacert} ? ('SSLINTERMEDIATECACERT' => $self->{SslCacert} ) : (),
Branch: 4 branches
BranchTrueFalseTotal
$self->{'Address'} ? : 0 0 0
$self->{'Hostname'} ? : 0 0 0
$self->{'SslKey'} ? : 0 0 0
$self->{'SslCacert'} ? : 0 0 0
72 'HANDLERS' => [
73 {
74 'DIR' => '.*',
75 'SESSION' => 'JSONRPCHTTP',
76 'EVENT' => 'http_input_handler',
77 },
78 ],
79 );
80 }
81  
82 =head2 poe_http_authentication_input_handler
83  
84 This function is used to treat HTTP authentication if needed
85 =cut
86  
87 0 ▶sub poe_http_authentication_input_handler {
Subroutine poe_http_authentication_input_handler: not called CC=2 SCAR=17.9
Pod documented
88 0 my ($self, $kernel, $session, $heap, $request, $response, $dirmatch) = @_[OBJECT, KERNEL, SESSION, HEAP, ARG0..$#_ ];
89  
90 0 my ( $login, $password ) = $request->authorization_basic();
91 0 ▶ if (&{$self->{Authenticate}}($login,$password)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&{$self->{'Authenticate'};}($login, $password)) { } 0 0 0
92 # Authentication worked
93 0 $kernel->post( 'JSONRPCHTTP', 'input_handler', $request, $response, $dirmatch);
94 } else {
95 # Set the authorization
96 0 $response->header( 'WWW-Authenticate' => 'Basic realm="JSONRPCRealm"' );
97 0 $response->code( 401 );
98 0 $response->content( 'FORBIDDEN.' );
99  
100 # Send it off!
101 0 $kernel->post( 'HTTPD', 'DONE', $response );
102 }
103 }
104  
105 =head2 poe_send
106  
107 Send HTTP response
108 =cut
109  
110 0 ▶sub poe_send {
Subroutine poe_send: not called CC=1 SCAR=6.9
Pod documented
111 0 my ($kernel,$response, $content) = @_[KERNEL,ARG0..$#_];
112  
113 #HTTP
114 0 $response->code( 200 );
115 0 $response->content( $content );
116  
117 0 $kernel->post( 'HTTPD', 'DONE', $response );
118 }
119  
120 2 1;
« JSONRPC.pm ↑ Summary