| 1 | package Yote::Server; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | no warnings 'numeric'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Lock::Server; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Yote; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use bytes; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use IO::Socket::SSL; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Time::HiRes qw(time); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use UUID::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | $VERSION = '1.26'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | our $DEBUG = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | my( $pkg, $args ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=23.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | my $class = ref( $pkg ) || $pkg; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $pkg || $pkg
MC/DC0%0/2
ref $pkg || $pkg
ref $pkg
$pkg
Truth table33%1/3
A || B
A= ref $pkgB= $pkg
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | my $server = bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | args => $args || {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # the following are the args currently used | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | yote_root_dir => $args->{yote_root_dir}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | yote_host => $args->{yote_host} || '127.0.0.1', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | yote_port => $args->{yote_port} || 8881, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | pids => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | _locker => new Lock::Server( { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | port => $args->{lock_port}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | host => $args->{lock_host} || '127.0.0.1', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | lock_attempt_timeout => $args->{lock_attempt_timeout}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | lock_timeout => $args->{lock_timeout}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | STORE => Yote::ServerStore->_new( { root => $args->{yote_root_dir} } ), | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%4/8
$args || {}
$args->{'yote_host'} || '127.0.0.1'
$args->{'yote_port'} || 8881
$args->{'lock_host'} || '127.0.0.1'
MC/DC0%0/1
$args || {}
$args
MC/DC0%0/1
$args->{'yote_host'} || '127.0.0.1'
$args->{'yote_host'}
MC/DC0%0/1
$args->{'yote_port'} || 8881
$args->{'yote_port'}
MC/DC0%0/1
$args->{'lock_host'} || '127.0.0.1'
$args->{'lock_host'}
Truth table50%1/2
A
A= $args
Truth table50%1/2
A
A= $args->{'yote_host'}
Truth table50%1/2
A
A= $args->{'yote_port'}
Truth table50%1/2
A
A= $args->{'lock_host'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $server->{STORE}{_locker} = $server->{_locker}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $server; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } #new | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | sub store { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | shift->{STORE}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
store: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | sub load_options { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | my( $yote_root_dir ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_options: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $confile = "$yote_root_dir/yote.conf"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # set up default options | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $options = { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | yote_root_dir => $yote_root_dir, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | yote_host => '127.0.0.1', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | yote_port => 8881, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | lock_port => 8004, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | lock_host => '127.0.0.1', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | lock_attempt_timeout => 12, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | lock_timeout => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | use_ssl => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | SSL_cert_file => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | SSL_key_file => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # override base defaults with those from conf file | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if( -f $confile && -r $confile ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $confile and -r $confile
MC/DC0%0/2
-f $confile and -r $confile
-f $confile
-r $confile
Truth table0%0/3
A and B
A= -f $confileB= -r $confile
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # TODO - create conf with defaults and make it part of the install | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | open( IN, "<$confile" ) or die "Unable to open config file $@ $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | while( <IN> ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | chomp; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | s/\#.*//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if( /^\s*([^=\s]+)\s*=\s*([^\s].*)\s*$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if( defined $options->{$1} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $options->{$1} = $2 if defined $options->{$1}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | print STDERR "Warning: encountered '$1' in file. Ignoring"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | close IN; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } #if config file is there | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | return $options; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } #load_options | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | sub ensure_locker { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ensure_locker: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # if running as the server, this will not be called. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # if something else is managing forking ( like the CGI ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # this should be run to make sure the locker socket | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # opens and closes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | $SIG{INT} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | _log( "$0 got INT signal. Shutting down." ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | $self->{_locker}->stop if $self->{_locker}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | exit; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if( ! $self->{_locker}->ping(1) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $self->{_locker}->start; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } #ensure_locker | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | sub start { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $self->{_locker}->start; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my $listener_socket = $self->_create_listener_socket; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | die "Unable to open socket " unless $listener_socket; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if( my $pid = fork ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # parent | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $self->{server_pid} = $pid; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | return $pid; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # in child | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | $0 = "YoteServer process"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $self->_run_loop( $listener_socket ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } #start | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | sub stop { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stop: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if( my $pid = $self->{server_pid} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $self->{error} = "Sending INT signal to lock server of pid '$pid'"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | kill 'INT', $pid; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $self->{error} = "No Yote server running"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | =head2 run | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | Runs the lock server. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | my $listener_socket = $self->_create_listener_socket; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | die "Unable to open socket " unless $listener_socket; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $self->_run_loop( $listener_socket ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | sub _create_listener_socket { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_listener_socket: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | my $listener_socket; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if( $self->{use_ssl} && ( ! $self->{SSL_cert_file} || ! $self->{SSL_key_file} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->{"use_ssl"} and not $self->{"SSL_cert_file"} && $self->{"SSL_key_file"}
$self->{'SSL_cert_file'} && $self->{'SSL_key_file'}
MC/DC0%0/3
$self->{"use_ssl"} and not $self->{"SSL_cert_file"} && $self->{"SSL_key_file"}
$self->{"use_ssl"}
$self->{'SSL_cert_file'}
$self->{'SSL_key_file'}
Truth table0%0/4
A and not(B && C)
A= $self->{"use_ssl"}B= $self->{'SSL_cert_file'}C= $self->{'SSL_key_file'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | die "Cannot start server. SSL selected but is missing filename for SSL_cert_file and/or SSL_key_file"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | while( ! $listener_socket && ++$count < 10 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $listener_socket and ++$count < 10
MC/DC0%0/2
not $listener_socket and ++$count < 10
not $listener_socket
++$count < 10
Truth table0%0/3
not(A) and B
A= not $listener_socketB= ++$count < 10
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | if( $self->{args}{use_ssl} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | my $cert_file = $self->{args}{SSL_cert_file}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my $key_file = $self->{args}{SSL_key_file}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | if( index( $cert_file, '/' ) != 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | $cert_file = "$self->{yote_root_dir}/$cert_file"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | if( index( $key_file, '/' ) != 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | $key_file = "$self->{yote_root_dir}/$key_file"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $listener_socket = new IO::Socket::SSL( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | Listen => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | LocalAddr => "$self->{yote_host}:$self->{yote_port}", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | SSL_cert_file => $cert_file, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | SSL_key_file => $key_file, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | $listener_socket = new IO::Socket::INET( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | Listen => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | LocalAddr => "$self->{yote_host}:$self->{yote_port}", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | last if $listener_socket; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | print STDERR "Unable to open the yote socket [$self->{yote_host}:$self->{yote_port}] ($!). Retry $count of 10\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | sleep 5 * $count; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | ▶ | unless( $listener_socket ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | $self->{error} = "Unable to open yote socket on port '$self->{yote_port}' : $! $@\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | $self->{_locker}->stop; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | _log( "unable to start yote server : $@ $!." ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | print STDERR "Starting yote server\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | unless( $self->{yote_root_dir} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | eval('use Yote::ConfigData'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | $self->{yote_root_dir} = $@ ? '/opt/yote' : Yote::ConfigData->config( 'yote_root' ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | undef $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # if this is cancelled, make sure all child procs are killed too | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | $SIG{INT} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | _log( "got INT signal. Shutting down." ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | $listener_socket && $listener_socket->close; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | for my $pid ( @{ $self->{_pids} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | kill 'HUP', $pid; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | $self->{_locker}->stop; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | exit; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $SIG{CHLD} = 'IGNORE'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | return $listener_socket; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } #_create_listener_socket | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | sub _run_loop { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | my( $self, $listener_socket ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run_loop: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | while( my $connection = $listener_socket->accept ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $self->_process_request( $connection ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | sub _log { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | my( $msg, $sev ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_log: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | $sev //= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$sev //= 1
MC/DC0%0/1
$sev //= 1
$sev
Truth table0%0/2
A
A= $sev
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | ▶ | if( $sev <= $DEBUG ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | print STDERR "Yote::Server : $msg\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | open my $out, ">>/opt/yote/log/yote.log" or return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | print $out "$msg\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | close $out; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | sub _find_ids_in_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | my $data = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_find_ids_in_data: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | my $r = ref( $data ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if( $r eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | return grep { $_ && index($_,'v')!=0 } map { ref( $_ ) ? _find_ids_in_data($_) : $_ } @$data; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | elsif( $r eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | return grep { $_ && index($_,'v')!=0} map { ref( $_ ) ? _find_ids_in_data($_) : $_ } values %$data; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | elsif( $r ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | die "_find_ids_in_data encountered a non ARRAY or HASH reference"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } #_find_ids_in_data | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | # EXPERIMETNAL - this will return the entire public tree. The idea is to program | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # without having to explicitly shove data across. This errs on the side of much | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # more data, so relies on private data and method calls (encapsulation) to | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # mitigate this | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | sub _unroll_ids { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | my( $store, $ids, $seen ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unroll_ids: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | $seen //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$seen //= {}
MC/DC0%0/1
$seen //= {}
$seen
Truth table0%0/2
A
A= $seen
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my( @items ) = ( map { $store->fetch($_) } @$ids ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | my @outids; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | for my $item( @items ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | my $iid = $store->_get_id($item); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my $r = ref( $item ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $seen->{$iid}++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | if( $r eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | push @outids, grep { ! $seen->{$_}++ } map { $store->_get_id($_) } grep { ref($_) } @$item; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | elsif( $r eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | push @outids, grep { ! $seen->{$_}++ } map { $store->_get_id($_) } grep { ref($_) } values %$item; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | my $data = $item->{DATA}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | push @outids, map { $data->{$_} } grep { /^[^_]/ && $data->{$_} != /^v/ && ! $seen->{$data->{$_}}++ } keys %$data; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
/^[^_]/ and $data->{$_} != /^v/
MC/DC0%0/2
/^[^_]/ and $data->{$_} != /^v/
/^[^_]/
$data->{$_} != /^v/
Truth table0%0/3
A and B
A= /^[^_]/B= $data->{$_} != /^v/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | _unroll_ids( $store, \@outids, $seen ) if @outids; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | [ keys %$seen ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } #_unroll_ids | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | sub _process_request { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # Reads incomming request from the socket, parses it, performs it and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # prints the result back to the socket. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | my( $self, $sock ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_request: not called CC=14 SCAR=53.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | if ( my $pid = fork ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | # parent | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | push @{$self->{_pids}},$pid; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # use Devel::SimpleProfiler;Devel::SimpleProfiler::start; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | my( $self, $sock ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | #child | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $0 = "YoteServer processing request"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | $SIG{INT} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | _log( " process $$ got INT signal. Shutting down." ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | $sock->close; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | exit; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my $req = <$sock>; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | $ENV{REMOTE_HOST} = $sock->peerhost; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | my( %headers, %cookies ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | while( my $hdr = <$sock> ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | $hdr =~ s/\s*$//s; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | last if $hdr !~ /[a-zA-Z]/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | my( $key, $val ) = ( $hdr =~ /^([^:]+):(.*)/ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | $headers{$key} = $val; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | for my $cookie ( split( /\s*;\s*/, $headers{Cookie} ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | $cookie =~ s/^\s*|^\s*$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my( $key, $val ) = split( /\s*=\s*/, $cookie, 2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | $cookies{ $key } = $val; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | # read certain length from socket ( as many bytes as content length ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | my $content_length = $headers{'Content-Length'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | my $data; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | if ( $content_length > 0 && ! eof $sock) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$content_length > 0 and not eof $sock
MC/DC0%0/2
$content_length > 0 and not eof $sock
$content_length > 0
not eof $sock
Truth table0%0/3
A and not(B)
A= $content_length > 0B= not eof $sock
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | read $sock, $data, $content_length; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | my( $verb, $path ) = split( /\s+/, $req ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | # escape for serving up web pages | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # the thought is that this should be able to be a stand alone webserver | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | # for testing and to provide the javascript | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | if ( $path =~ m!/__/! ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | # TODO - make sure install script makes the directories properly | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | my $filename = "$self->{yote_root_dir}/html/" . substr( $path, 4 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | if ( -e $filename ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my @stat = stat $filename; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | my $content_type = $filename =~ /css$/ ? 'text/css' : 'text/html'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | my @headers = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | "Content-Type: $content_type; charset=utf-8", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 'Server: Yote', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | "Content-Length: $stat[7]", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | open( IN, "<$filename" ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | $sock->print( "HTTP/1.1 200 OK\n" . join ("\n", @headers). "\n\n" ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | while ( $data = <IN> ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | $sock->print( $data ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | close IN; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | $sock->print( "HTTP/1.1 404 FILE NOT FOUND\n\n" ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $sock->close; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | exit; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | # data has the input parmas in JSON format. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | # POST / | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | if ( $verb ne 'POST' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | $sock->print( "HTTP/1.1 400 BAD REQUEST\n\n" ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | $sock->close; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | $data =~ s/^p=//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | my $out_json; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | $out_json = $self->invoke_payload( $data ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | if( ref $@ eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | $out_json = encode_json( $@ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | elsif( $@ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $out_json = encode_json( { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | err => $@, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | my @headers = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 'Content-Type: text/json; charset=utf-8', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 'Server: Yote', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 'Access-Control-Allow-Headers: accept, content-type, cookie, origin, connection, cache-control', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 'Access-Control-Allow-Origin: *', #TODO - have this configurable | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 'Content-Length: ' . bytes::length( $out_json ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | $sock->print( "HTTP/1.1 200 OK\n" . join ("\n", @headers). "\n\n$out_json\n" ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | $sock->close; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | exit; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | } #child | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } #_process_request | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | sub invoke_payload { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | ▶ | my( $self, $raw_req_data, $file_uploads ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
invoke_payload: not called CC=26 SCAR=65.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | my $req_data = decode_json( $raw_req_data ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | my( $obj_id, $token, $action, $params ) = @$req_data{ 'i', 't', 'a', 'pl' }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | my $server_root = $self->{STORE}->fetch_server_root; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | my $server_root_id = $server_root->{ID}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | my $id_to_last_update_time; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | ▶ | my $session = $token && $token ne '_' ? $server_root->_fetch_session( $token ) : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$token and $token ne "_"
MC/DC0%0/2
$token and $token ne "_"
$token
$token ne "_"
Truth table0%0/3
A and B
A= $tokenB= $token ne "_"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | if( $session ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | $id_to_last_update_time = $session->get__has_ids2times; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | unless( $obj_id eq '_' || # either the object id that is acted upon is | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$obj_id eq "_" or $obj_id eq $server_root_id or $id_to_last_update_time->{$obj_id}
$obj_id eq "_" or $obj_id eq $server_root_id
MC/DC0%0/3
$obj_id eq "_" or $obj_id eq $server_root_id or $id_to_last_update_time->{$obj_id}
$obj_id eq "_"
$obj_id eq $server_root_id
$id_to_last_update_time->{$obj_id}
Truth table0%0/4
A or B or C
A= $obj_id eq "_"B= $obj_id eq $server_root_idC= $id_to_last_update_time->{$obj_id}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | $obj_id eq $server_root_id || # the server root or is known to the session | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | ( $id_to_last_update_time->{$obj_id} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | # tried to do an action on an object it wasn't handed. do a 404 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | die( "client with token [$token] and session ($session) tried to invoke on obj id '$obj_id' which it does not have" ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | ▶ | if( substr( $action, 0, 1 ) eq '_' || $action =~ /^[gs]et$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
substr($action, 0, 1) eq "_" or $action =~ /^[gs]et$/
MC/DC0%0/2
substr($action, 0, 1) eq "_" or $action =~ /^[gs]et$/
substr($action, 0, 1) eq "_"
$action =~ /^[gs]et$/
Truth table0%0/3
A or B
A= substr($action, 0, 1) eq "_"B= $action =~ /^[gs]et$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | die( "Private method called" ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | ▶ | if ( $params && ref( $params ) ne 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$params and ref $params ne "ARRAY"
MC/DC0%0/2
$params and ref $params ne "ARRAY"
$params
ref $params ne "ARRAY"
Truth table0%0/3
A and B
A= $paramsB= ref $params ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | die( "Bad Req Param Not Array : $params" ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my $store = $self->{STORE}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | # now things are getting a bit more complicated. The params passed in | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | # are always a list, but they may contain other containers that are not | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | # yote objects. So, transform the incomming parameter list and check all | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | # yote objects inside for may. Use a recursive helper function for this. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | my $in_params = $store->__transform_params( $params, $session, $file_uploads ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | # This obj is the object that the method call is on | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | my $obj = $obj_id eq '_' ? $server_root : | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | $store->fetch( $obj_id ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | unless( $obj->can( $action ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | die( "Bad Req : invalid method :'$action'" ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # if there is a session, attach it to the object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | ▶ | if( $session ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | $obj->{SESSION} = $session; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | $obj->{SESSION}{SERVER_ROOT} = $server_root; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | # <<------------- the actual method call --------------->> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | my(@res) = ($obj->$action( @$in_params )); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | # this is included in what is returned to the client | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | my $out_res = $store->_xform_in( \@res, 'allow datastructures' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | # in case the method generated a new session, (re)set that now | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | $session = $obj->{SESSION}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | ▶ | if( $session ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | $id_to_last_update_time = $session->get__has_ids2times; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | # the ids that were referenced explicitly in the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | # method call. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | my @out_ids = _find_ids_in_data( $out_res ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | # Based on the return value of the method call, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # these ids are ones that the client should have. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | # We will check to see if these need updates | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | my @should_have = ( @{ _unroll_ids( $store, [@out_ids, keys %$id_to_last_update_time] ) } ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | my( @updates, %methods ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | # check if existing are in the session | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | for my $should_have_id ( @should_have, keys %$id_to_last_update_time ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | my $needs_update = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | ▶ | if( $session) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | # check if the client of this session needs an update, otherwise assume that it does | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | ▶ | my( $client_s, $client_ms ) = @{ $id_to_last_update_time->{$should_have_id} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | my( $server_s, $server_ms ) = $store->_last_updated( $should_have_id ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | $needs_update = $client_s == 0 || $server_s > $client_s || ($server_s == $client_s && $server_ms > $client_ms ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
$client_s == 0 || $server_s > $client_s || $server_s == $client_s && $server_ms > $client_ms
$client_s == 0 or $server_s > $client_s
$server_s == $client_s and $server_ms > $client_ms
MC/DC0%0/4
$client_s == 0 || $server_s > $client_s || $server_s == $client_s && $server_ms > $client_ms
$client_s == 0
$server_s > $client_s
$server_s == $client_s
$server_ms > $client_ms
Truth table0%0/5
A or B || C and D
A= $client_s == 0B= $server_s > $client_sC= $server_s == $client_sD= $server_ms > $client_ms
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | ▶ | if( $needs_update ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | my $should_have_obj = $store->fetch( $should_have_id ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | my $ref = ref( $should_have_obj ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | my $data; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | ▶ | if( $ref eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | $data = [ map { $store->_xform_in( $_ ) } @$should_have_obj ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } elsif( $ref eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | $data = { map { $_ => $store->_xform_in( $should_have_obj->{$_} ) } keys %$should_have_obj }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | my $d = $should_have_obj->{DATA}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | ▶ | $data = { map { $_ => $d->{$_} } grep { index($_,"_") != 0 } keys %$d }, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$methods{$ref} ||= $should_have_obj->_callable_methods
MC/DC0%0/2
$methods{$ref} ||= $should_have_obj->_callable_methods
$methods{$ref}
$should_have_obj->_callable_methods
Truth table0%0/3
A ||= B
A= $methods{$ref}B= $should_have_obj->_callable_methods
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | $methods{$ref} ||= $should_have_obj->_callable_methods; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | my $update = { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | id => $should_have_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | cls => $ref, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | data => $data, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | push @updates, $update; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | ▶ | if( $session ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | $id_to_last_update_time->{$should_have_id} = [Time::HiRes::gettimeofday]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | } # if this needs an update | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | } #each object the client should have | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | my $out_json = to_json( { result => $out_res, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | updates => \@updates, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | methods => \%methods, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | delete $obj->{SESSION}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | $self->{STORE}->stow_all; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | return $out_json; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | } #invoke_payload | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | # ------- END Yote::Server | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | package Yote::ServerStore; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 1 | ▶ | use Data::RecordStore; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 1 | ▶ | use base 'Yote::ObjStore'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | sub _new { #Yote::ServerStore | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 1 | ▶ | my( $pkg, $args ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new: called CC=1 SCAR=1.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 1 | $args->{store} = "$args->{root}/DATA_STORE"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 1 | my $self = $pkg->SUPER::_new( $args ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | # keeps track of when any object had been last updated. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | # use like $self->{OBJ_UPDATE_DB}->put_record( $obj_id, [ time ] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | # or my( $time ) = @{ $self->{OBJ_UPDATE_DB}->get_record( $obj_id ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | $self->{OBJ_UPDATE_DB} = Data::RecordStore::FixedStore->open( "LL", "$args->{root}/OBJ_META" ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | my( $m, $ms ) = ( Time::HiRes::gettimeofday ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | $self->{OBJ_UPDATE_DB}->put_record( $self->{ID}, [ $m, $ms ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | } #_new | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | sub _dirty { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | ▶ | my( $self, $ref, $id ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dirty: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | $self->SUPER::_dirty( $ref, $id ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | $self->{OBJ_UPDATE_DB}->ensure_entry_count( $id ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | my( $m, $ms ) = ( Time::HiRes::gettimeofday ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | $self->{OBJ_UPDATE_DB}->put_record( $id, [ $m, $ms ] ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | sub stow_all { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | ▶ | my $self = $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stow_all: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | for my $obj (values %{$self->{_DIRTY}} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | my $obj_id = $self->_get_id( $obj ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | $self->{OBJ_UPDATE_DB}->ensure_entry_count( $obj_id ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | $self->SUPER::stow_all; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | } #stow_all | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | sub _last_updated { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | ▶ | my( $self, $obj_id ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_last_updated: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | my( $s, $ms ) = @{ $self->{OBJ_UPDATE_DB}->get_record( $obj_id ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | $s, $ms; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | sub _log { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | ▶ | Yote::Server::_log(shift); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_log: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | sub __transform_params { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | # Recursively transforms incoming parameters into values, yote objects, or non yote containers. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | # This checks to make sure that the parameters are allowed by the given token. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | # Throws execptions if the parametsr are not allowed, or if a reference that is not a hash or array | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | # is encountered. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | ▶ | my( $self, $param, $session, $files ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__transform_params: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | ▶ | if( ref( $param ) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | return { map { $_ => $self->__transform_params($param->{$_}, $session, $files) } keys %$param }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | elsif( ref( $param ) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | return [ map { $self->__transform_params($_, $session, $files) } @$param ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | } elsif( ref( $param ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | die "Transforming Params: got weird ref '" . ref( $param ) . "'"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | if( ( index( $param, 'v' ) != 0 && index($param, 'f' ) != 0 ) && !$session->get__has_ids2times({})->{$param} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
index($param, "v") != 0 and index($param, "f") != 0 and not $session->get__has_ids2times({})->{$param}
index($param, "v") != 0 and index($param, "f") != 0
MC/DC0%0/3
index($param, "v") != 0 and index($param, "f") != 0 and not $session->get__has_ids2times({})->{$param}
index($param, "v") != 0
index($param, "f") != 0
not $session->get__has_ids2times({})->{$param}
Truth table0%0/4
A and B and not(C)
A= index($param, "v") != 0B= index($param, "f") != 0C= not $session->get__has_ids2times({})->{$param}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | # obj id given, but the client should not have that id | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | ▶ | if( $param ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | die { err => 'Sync Error', needs_resync => 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | return $self->_xform_out( $param, $files ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | } #__transform_params | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | sub _xform_out { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | ▶ | my( $self, $val, $files ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_xform_out: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | ▶ | return undef unless defined( $val ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | if( index($val,'f') == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | # convert to file object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | ▶ | if( $val =~ /^f(\d+)_(\d+)$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | my( $offset_start, $offset_end ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | ▶ | for( my $i=$offset_start; $i < $offset_end; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | my $file = $files->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 0 | ▶ | if( $file ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | my( $orig_filename ) = ( $file =~ /([^\/]*)$/ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | my( $extension ) = ( $orig_filename =~ /\.([^.\/]+)$/ ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | # TODO - cleanup, maybe use File::Temp or something | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | my $newname = "/tmp/".UUID::Tiny::create_uuid_as_string(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | open (FILE, ">$newname"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | my $fh = $file->fh; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | ▶ | while (read ($fh, my $Buffer, 1024)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | print FILE $Buffer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | close FILE; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | # create yote object here that wraps the file name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | return $self->newobj( { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | file_path => $newname, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | file_extension => $extension, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | file_name => $orig_filename, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | } #finding the file | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | return $self->SUPER::_xform_out( $val ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | } #_xform_out | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | # Unlike the superclass version of this, this provides an arguemnt to | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | # allow non-yote datastructures to be returned. The contents of those | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | # data structures will all recursively be xformed in. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | sub _xform_in { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | ▶ | my( $self, $val, $allow_datastructures ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_xform_in: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | my $r = ref $val; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | ▶ | if( $r ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | ▶ | if( $allow_datastructures) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | # check if this is a yote object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | ▶ | if( ref( $val ) eq 'ARRAY' && ! tied( @$val ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
ref $val eq "ARRAY" and not tied @$val
MC/DC0%0/2
ref $val eq "ARRAY" and not tied @$val
ref $val eq "ARRAY"
not tied @$val
Truth table0%0/3
A and not(B)
A= ref $val eq "ARRAY"B= not tied @$val
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | ▶ | return [ map { ref $_ ? $self->_xform_in( $_, $allow_datastructures ) : "v$_" } @$val ]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | ▶ | elsif( ref( $val ) eq 'HASH' && ! tied %$val ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $val eq "HASH" and not tied %$val
MC/DC0%0/2
ref $val eq "HASH" and not tied %$val
ref $val eq "HASH"
not tied %$val
Truth table0%0/3
A and not(B)
A= ref $val eq "HASH"B= not tied %$val
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | ▶ | return { map { $_ => ( ref( $val->{$_} ) ? $self->_xform_in( $val->{$_}, $allow_datastructures ) : "v$val->{$_}" ) } keys %$val }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | return $self->_get_id( $val ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | ▶ | return defined $val ? "v$val" : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | } #_xform_in | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | sub newobj { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | ▶ | my( $self, $data, $class ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
newobj: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | ▶ | $class ||= 'Yote::ServerObj'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$class ||= "Yote::ServerObj"
MC/DC0%0/1
$class ||= "Yote::ServerObj"
$class
Truth table0%0/2
A
A= $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 0 | $class->_new( $self, $data ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | } #newobj | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | sub fetch_server_root { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_server_root: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 0 | ▶ | return $self->{SERVER_ROOT} if $self->{SERVER_ROOT}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 0 | my $system_root = $self->fetch_root; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | my $server_root = $system_root->get_server_root; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | ▶ | unless( $server_root ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 0 | $server_root = Yote::ServerRoot->_new( $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 0 | $system_root->set_server_root( $server_root ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | $self->stow_all; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | # some setup here? accounts/webapps/etc? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | # or make it simple. if the webapp has an account, then pass that account | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | # with the rest of the arguments | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | # then verify if the command can run on the app object with those args | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | # or even : $myapp->run( 'command', @args ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | ▶ | $self->{SERVER_ROOT} ||= $server_root; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"SERVER_ROOT"} ||= $server_root
MC/DC0%0/2
$self->{"SERVER_ROOT"} ||= $server_root
$self->{"SERVER_ROOT"}
$server_root
Truth table0%0/3
A ||= B
A= $self->{"SERVER_ROOT"}B= $server_root
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | $server_root; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | } #fetch_server_root | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | sub lock { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | ▶ | my( $self, $key ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lock: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | ▶ | $self->{_lockerClient} ||= $self->{_locker}->client( $$ ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"_lockerClient"} ||= $self->{"_locker"}->client($$)
MC/DC0%0/2
$self->{"_lockerClient"} ||= $self->{"_locker"}->client($$)
$self->{"_lockerClient"}
$self->{"_locker"}->client($$)
Truth table0%0/3
A ||= B
A= $self->{"_lockerClient"}B= $self->{"_locker"}->client($$)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | $self->{_lockerClient}->lock( $key ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | sub unlock { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | ▶ | my( $self, $key ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unlock: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | $self->{_lockerClient}->unlock( $key ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | # ------- END Yote::ServerStore | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | package Yote::ServerObj; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 1 | ▶ | use base 'Yote::Obj'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | sub _log { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 0 | ▶ | Yote::Server::_log(shift); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_log: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | sub _err { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 0 | ▶ | shift; #self | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_err: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 0 | die { err => shift }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 1 | $Yote::ServerObj::PKG2METHS = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | sub __discover_methods { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | ▶ | my $pkg = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__discover_methods: not called CC=7 SCAR=38.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | my $meths = $Yote::ServerObj::PKG2METHS->{$pkg}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | ▶ | if( $meths ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 0 | return $meths; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | my @m = grep { $_ !~ /::/ } keys %{"${pkg}\::"}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | ▶ | if( $pkg eq 'Yote::ServerObj' ) { #the base, presumably | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 0 | return [ sort grep { $_ !~ /^(_|[gs]et_|(can|[sg]et|VERSION|AUTOLOAD|DESTROY|CARP_TRACE|BEGIN|isa|import|PKG2METHS|ISA|add_to_|remove_from)$)/ } @m ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | my %hasm = map { $_ => 1 } @m; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | for my $class ( @{"${pkg}\::ISA" } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | ▶ | next if $class eq 'Yote::ServerObj' || $class eq 'Yote::Obj'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$class eq "Yote::ServerObj" or $class eq "Yote::Obj"
MC/DC0%0/2
$class eq "Yote::ServerObj" or $class eq "Yote::Obj"
$class eq "Yote::ServerObj"
$class eq "Yote::Obj"
Truth table0%0/3
A or B
A= $class eq "Yote::ServerObj"B= $class eq "Yote::Obj"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | my $pm = __discover_methods( $class ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 0 | push @m, @$pm; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 0 | my $base_meths = __discover_methods( 'Yote::ServerObj' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | my( %base ) = map { $_ => 1 } 'AUTOLOAD', @$base_meths; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 0 | ▶ | $meths = [ sort grep { $_ !~ /^(_|[gs]et_|(can|[sg]et|VERSION|AUTOLOAD|DESTROY|BEGIN|isa|import|PKG2METHS|ISA|add_to_|remove_from)$)/ && ! $base{$_} } @m ]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_ =~ /^(_|[gs]et_|(can|[sg]et|VERSION|AUTOLOAD|DESTROY|BEGIN|isa|import|PKG2METHS|ISA|add_to_|remove_from)$)/ || $base{$_}
MC/DC0%0/2
$_ =~ /^(_|[gs]et_|(can|[sg]et|VERSION|AUTOLOAD|DESTROY|BEGIN|isa|import|PKG2METHS|ISA|add_to_|remove_from)$)/ || $base{$_}
$_ =~ /^(_|[gs]et_|(can|[sg]et|VERSION|AUTOLOAD|DESTROY|BEGIN|isa|import|PKG2METHS|ISA|add_to_|remove_from)$)/
$base{$_}
Truth table0%0/3
A || B
A= $_ =~ /^(_|[gs]et_|(can|[sg]et|VERSION|AUTOLOAD|DESTROY|BEGIN|isa|import|PKG2METHS|ISA|add_to_|remove_from)$)/B= $base{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 0 | $Yote::ServerObj::PKG2METHS->{$pkg} = $meths; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | $meths; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | } #__discover_methods | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | # when sending objects across, the format is like | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | # id : { data : { }, methods : [] } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | # the methods exclude all the methods of Yote::Obj | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | sub _callable_methods { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_callable_methods: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 0 | my $pkg = ref( $self ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | __discover_methods( $pkg ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | } # _callable_methods | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | sub _get { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | ▶ | my( $self, $fld, $default ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 0 | ▶ | if( ! defined( $self->{DATA}{$fld} ) && defined($default) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $self->{"DATA"}{$fld} and defined $default
MC/DC0%0/2
not defined $self->{"DATA"}{$fld} and defined $default
not defined $self->{"DATA"}{$fld}
defined $default
Truth table0%0/3
not(A) and B
A= not defined $self->{"DATA"}{$fld}B= defined $default
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | ▶ | if( ref( $default ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 0 | $self->{STORE}->_dirty( $default, $self->{STORE}->_get_id( $default ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | $self->{STORE}->_dirty( $self, $self->{ID} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | $self->{DATA}{$fld} = $self->{STORE}->_xform_in( $default ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | $self->{STORE}->_xform_out( $self->{DATA}{$fld} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | } #_get | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | # ------- END Yote::ServerObj | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | package Yote::ServerRoot; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 1 | ▶ | use base 'Yote::ServerObj'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | sub _init { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 0 | $self->set__doesHave_Token2objs({}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 0 | $self->set__apps({}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | $self->set__token_timeslots([]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | $self->set__token_timeslots_metadata([]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 0 | $self->set__token_mutex([]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | sub _log { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 0 | ▶ | Yote::Server::_log(shift); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_log: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | # fetches or creates session which has a _token field | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | sub fetch_session { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 0 | ▶ | my( $self, $token ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_session: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 0 | ▶ | my $session = $self->_fetch_session( $token ) || $self->_create_session; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->_fetch_session($token) || $self->_create_session
MC/DC0%0/2
$self->_fetch_session($token) || $self->_create_session
$self->_fetch_session($token)
$self->_create_session
Truth table0%0/3
A || B
A= $self->_fetch_session($token)B= $self->_create_session
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 0 | $self->{SESSION} = $session; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 0 | $session; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | sub _fetch_session { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 0 | ▶ | my( $self, $token ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fetch_session: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 0 | $self->{STORE}->lock( 'token_mutex' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 0 | my $slots = $self->get__token_timeslots(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 0 | ▶ | for( my $i=0; $i<@$slots; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 0 | ▶ | if( my $session = $slots->[$i]{$token} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 0 | ▶ | if( $i > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | # make sure this is in the most current 'boat' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 0 | $slots->[0]{ $token } = $session; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 0 | $self->{STORE}->unlock( 'token_mutex' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 0 | return $session; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 0 | $self->{STORE}->unlock( 'token_mutex' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 0 | 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | } #_fetch_sesion | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | sub _create_session { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_session: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 0 | my $tries = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 0 | ▶ | if( $tries > 3 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 0 | die "Error creating token. Got the same random number 4 times in a row"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 0 | my $token = int( rand( 1_000_000_000 ) ); #TODO - find max this can be for long int | |||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | # make the token boat. tokens last at least 10 mins, so quantize | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | # 10 minutes via time 10 min = 600 seconds = 600 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | # or easy, so that 1000 seconds ( ~ 16 mins ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | # todo - make some sort of quantize function here | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 0 | my $current_time_chunk = int( time / 100 ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 0 | my $earliest_valid_time_chunk = $current_time_chunk - 7; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 0 | $self->{STORE}->lock( 'token_mutex' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | # A list of slot 'boats' which store token -> ip | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 0 | my $slots = $self->get__token_timeslots(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | # a list of times. the list index of these times corresponds | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | # to the slot 'boats' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 0 | my $slot_data = $self->get__token_timeslots_metadata(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | # Check if the token is already used ( very unlikely ). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | # If already used, try this again :/ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 0 | ▶ | for( my $i=0; $i<@$slot_data; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 0 | ▶ | return $self->_create_session( $tries++ ) if $slots->[ $i ]{ $token }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | # See if the most recent time slot is current. If it is behind, create a new current slot | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | # create a new most recent boat. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | my $session = $self->{STORE}->newobj( { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 0 | _has_ids2times => {}, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | _token => $token }, 'Yote::ServerSession' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 0 | ▶ | if( $slot_data->[ 0 ] == $current_time_chunk ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 0 | $slots->[ 0 ]{ $token } = $session; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 0 | unshift @$slot_data, $current_time_chunk; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 0 | unshift @$slots, { $token => $session }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | # remove this token from old boats so it doesn't get purged | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | # when in a valid boat. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 0 | ▶ | for( my $i=1; $i<@$slot_data; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 0 | delete $slots->[$i]{ $token }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 0 | $self->{STORE}->_stow( $slots ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 0 | $self->{STORE}->_stow( $slot_data ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 0 | $self->{STORE}->unlock( 'token_mutex' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 0 | $session; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | } #_create_session | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | sub _destroy_session { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 0 | ▶ | my( $self, $token ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_destroy_session: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 0 | $self->{STORE}->lock( 'token_mutex' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 0 | my $slots = $self->get__token_timeslots(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 0 | ▶ | for( my $i=0; $i<@$slots; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 0 | delete $slots->[$i]{ $token }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | 0 | $self->{STORE}->_stow( $slots ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 0 | $self->{STORE}->unlock( 'token_mutex' ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | } #_destroy_session | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | # Needed for when no logins are going to happen | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | sub create_token { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 0 | ▶ | shift->_create_session->get__token; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_token: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | # Returns the app and possibly a logged in account | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | sub fetch_app { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 0 | ▶ | my( $self, $app_name ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_app: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 0 | my $apps = $self->get__apps; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 0 | my $app = $apps->{$app_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 0 | ▶ | unless( $app ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 0 | eval("require $app_name"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 0 | ▶ | if( $@ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | # TODO - have/use a good logging system with clarity and stuff | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | # warnings, errors, etc | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 0 | $app = $app_name->_new( $self->{STORE} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 0 | $apps->{$app_name} = $app; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | 0 | ▶ | my $acct = $self->{SESSION} ? $self->{SESSION}->get_acct : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | 0 | return $app, $acct, $self->{SESSION}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | } #fetch_app | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | sub fetch_root { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 0 | ▶ | return shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_root: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | sub init_root { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_root: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | 0 | ▶ | my $session = $self->{SESSION} || $self->_create_session; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'SESSION'} || $self->_create_session
MC/DC0%0/2
$self->{'SESSION'} || $self->_create_session
$self->{'SESSION'}
$self->_create_session
Truth table0%0/3
A || B
A= $self->{'SESSION'}B= $self->_create_session
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | 0 | $self->{SESSION} = $session; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | 0 | $session->set__has_ids2times({}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 0 | my $token = $session->get__token; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 0 | return $self, $token; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | # while this is a non-op, it will cause any updated contents to be | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | # transfered to the caller automatically | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | ▶ | sub update { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | # ------- END Yote::ServerRoot | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | package Yote::ServerSession; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 1 | ▶ | use base 'Yote::ServerObj'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | sub fetch { # fetch scrambled id | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 0 | ▶ | my( $self, $in_sess_id ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | 0 | $self->get__ids([])->[$in_sess_id-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | sub getid { #scramble id for object | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | 0 | ▶ | my( $self, $obj ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getid: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | 0 | my $o2i = $self->get__obj2id({}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | 0 | ▶ | if( $o2i->{$obj} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | 0 | return $o2i->{$obj}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | 0 | my $ids = $self->get__ids([]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | 0 | push @$ids, $obj; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | 0 | my $id = scalar @$ids; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | 0 | $o2i->{$obj} = $id; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | 0 | $id; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | } #id | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | # ------- END Yote::ServerSession | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||