| 1 | package Net::IPMessenger; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use IO::Socket::INET; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Net::IPMessenger::ClientData; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Net::IPMessenger::Encrypt; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Net::IPMessenger::MessageCommand; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Net::IPMessenger::RecvEventHandler; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use base qw( Class::Accessor::Fast ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | __PACKAGE__->mk_accessors( | |||||||||||||||||||||||||||||||||||||||||
| 15 | qw( | ||||||||||||||||||||||||||||||||||||||||||
| 16 | packet_count sending_packet user message | ||||||||||||||||||||||||||||||||||||||||||
| 17 | nickname groupname username hostname | ||||||||||||||||||||||||||||||||||||||||||
| 18 | socket serveraddr sendretry broadcast | ||||||||||||||||||||||||||||||||||||||||||
| 19 | event_handler encrypt debug | ||||||||||||||||||||||||||||||||||||||||||
| 20 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | our $VERSION = '0.14'; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | my $PROTO = 'udp'; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | my $PORT = 2425; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | my $BROADCAST = '255.255.255.255'; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | my $MAX_SOCKBUF = 65535; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | my $SEND_RETRY = 3; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=26.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 3 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | $self->packet_count(0); | |||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | $self->user( {} ); | |||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | $self->message( [] ); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | $self->event_handler( [] ); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | $self->sending_packet( {} ); | |||||||||||||||||||||||||||||||||||||||||
| 42 | 3 | $self->broadcast( [] ); | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 3 | ▶ | $self->nickname( $args{NickName} ) if $args{NickName}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | ▶ | $self->groupname( $args{GroupName} ) if $args{GroupName}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | ▶ | $self->username( $args{UserName} ) if $args{UserName}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | ▶ | $self->hostname( $args{HostName} ) if $args{HostName}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 3 | ▶ | $self->serveraddr( $args{ServerAddr} ) if $args{ServerAddr}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | ▶ | $self->debug( $args{Debug} ) if $args{Debug}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 3 | ▶ | $self->add_broadcast( $args{BroadCast} ) if $args{BroadCast}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | ▶ | $self->sendretry( $args{SendRetry} || $SEND_RETRY ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args{'SendRetry'} || $SEND_RETRY
MC/DC0%0/2
$args{'SendRetry'} || $SEND_RETRY
$args{'SendRetry'}
$SEND_RETRY
Truth table33%1/3
A || B
A= $args{'SendRetry'}B= $SEND_RETRY
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | # encryption support | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | my $encrypt = Net::IPMessenger::Encrypt->new; | |||||||||||||||||||||||||||||||||||||||||
| 55 | # enable only encrypt modules are available | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | ▶ | $self->encrypt($encrypt) if $encrypt; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | my $sock = IO::Socket::INET->new( | ||||||||||||||||||||||||||||||||||||||||||
| 59 | Proto => $PROTO, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | ▶ | LocalPort => $args{Port} || $PORT, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args{'Port'} || $PORT
MC/DC0%0/2
$args{'Port'} || $PORT
$args{'Port'}
$PORT
Truth table33%1/3
A || B
A= $args{'Port'}B= $PORT
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | ) or return; | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | $self->socket($sock); | |||||||||||||||||||||||||||||||||||||||||
| 64 | 2 | $self->add_event_handler( Net::IPMessenger::RecvEventHandler->new ); | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub get_connection { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_connection: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | shift->socket; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | ▶ | sub add_event_handler { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_event_handler: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | push @{ $self->event_handler }, shift; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | sub add_broadcast { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_broadcast: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | push @{ $self->broadcast }, shift; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 4 | ▶ | sub recv { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
recv: called CC=10 SCAR=25.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 4 | my $sock = $self->socket; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 4 | my $msg; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 4 | ▶ | $sock->recv( $msg, $MAX_SOCKBUF ) or croak "recv: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 4 | my $peeraddr = inet_ntoa( $sock->peeraddr ); | |||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | my $peerport = $sock->peerport; | |||||||||||||||||||||||||||||||||||||||||
| 91 | # ignore yourself | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 4 | ▶ | if ( $self->serveraddr ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | return if ( $peeraddr eq $self->serveraddr ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 4 | my $user = Net::IPMessenger::ClientData->new( | |||||||||||||||||||||||||||||||||||||||||
| 97 | Message => $msg, | ||||||||||||||||||||||||||||||||||||||||||
| 98 | PeerAddr => $peeraddr, | ||||||||||||||||||||||||||||||||||||||||||
| 99 | PeerPort => $peerport, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | $self->update_userlist( $user, $msg ); | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 4 | my $command = $self->messagecommand( $user->command ); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 4 | my $modename = $command->modename; | |||||||||||||||||||||||||||||||||||||||||
| 105 | # invoke event handler | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 4 | my $ev_handler = $self->event_handler; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 4 | ▶ | if ( ref $ev_handler and ref $ev_handler eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $ev_handler and ref $ev_handler eq "ARRAY"
MC/DC0%0/2
ref $ev_handler and ref $ev_handler eq "ARRAY"
ref $ev_handler
ref $ev_handler eq "ARRAY"
Truth table33%1/3
A and B
A= ref $ev_handlerB= ref $ev_handler eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 4 | for my $handler ( @{$ev_handler} ) { | |||||||||||||||||||||||||||||||||||||||||
| 109 | 4 | ▶ | if ( $self->debug and $handler->can('debug') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->debug and $handler->can("debug")
MC/DC0%0/2
$self->debug and $handler->can("debug")
$self->debug
$handler->can("debug")
Truth table33%1/3
A and B
A= $self->debugB= $handler->can("debug")
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $handler->debug( $self, $user ); | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 4 | ▶ | $handler->$modename( $self, $user ) if $handler->can($modename); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 4 | return $user; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 4 | ▶ | sub update_userlist { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_userlist: called CC=4 SCAR=14.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 4 | my $user = shift; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 4 | my $msg = shift; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 4 | my $key = $user->key; | |||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | # exists in user list | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 4 | ▶ | if ( exists $self->user->{$key} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $self->user->{$key}->parse($msg); | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | # new user | ||||||||||||||||||||||||||||||||||||||||||
| 129 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 4 | my $command = $self->messagecommand( $user->command ); | |||||||||||||||||||||||||||||||||||||||||
| 131 | 4 | my $modename = $command->modename; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 4 | ▶ | unless ( $modename eq 'SENDMSG' and $command->get_noaddlist ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$modename eq "SENDMSG" and $command->get_noaddlist
MC/DC0%0/2
$modename eq "SENDMSG" and $command->get_noaddlist
$modename eq "SENDMSG"
$command->get_noaddlist
Truth table66%2/3
A and B
A= $modename eq "SENDMSG"B= $command->get_noaddlist
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 4 | $self->user->{$key} = $user; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | sub parse_anslist { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_anslist: not called CC=15 SCAR=54.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $user = shift; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my $listaddr = shift; | |||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my @list = split( /\a/, $user->option ); | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my $title = shift(@list); | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $count = shift(@list); | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my %present; | |||||||||||||||||||||||||||||||||||||||||
| 148 | my %new; | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | for my $key ( keys %{ $self->user } ) { | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if ( defined $self->user->{$key}->listaddr | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->user->{$key}->listaddr and $listaddr eq $self->user->{$key}->listaddr
MC/DC0%0/2
defined $self->user->{$key}->listaddr and $listaddr eq $self->user->{$key}->listaddr
defined $self->user->{$key}->listaddr
$listaddr eq $self->user->{$key}->listaddr
Truth table0%0/3
A and B
A= defined $self->user->{$key}->listaddrB= $listaddr eq $self->user->{$key}->listaddr
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | and $listaddr eq $self->user->{$key}->listaddr ) | ||||||||||||||||||||||||||||||||||||||||||
| 152 | { | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $present{$key} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | my $uname = shift @list or last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | my $host = shift @list or last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | my $pnum = shift @list or last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | my $addr = shift @list or last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | my $com = shift @list or last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | my $nick = shift @list or last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | my $group = shift @list or last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if ( $self->serveraddr ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | next if ( $addr eq $self->serveraddr ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | my $newuser = Net::IPMessenger::ClientData->new( | |||||||||||||||||||||||||||||||||||||||||
| 171 | Ver => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 172 | PacketNum => $pnum, | ||||||||||||||||||||||||||||||||||||||||||
| 173 | User => $uname, | ||||||||||||||||||||||||||||||||||||||||||
| 174 | Host => $host, | ||||||||||||||||||||||||||||||||||||||||||
| 175 | Command => $com, | ||||||||||||||||||||||||||||||||||||||||||
| 176 | Nick => $nick, | ||||||||||||||||||||||||||||||||||||||||||
| 177 | Group => $group, | ||||||||||||||||||||||||||||||||||||||||||
| 178 | PeerAddr => $addr, | ||||||||||||||||||||||||||||||||||||||||||
| 179 | PeerPort => $PORT, | ||||||||||||||||||||||||||||||||||||||||||
| 180 | ListAddr => $listaddr, | ||||||||||||||||||||||||||||||||||||||||||
| 181 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my $newkey = $newuser->key; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $self->user->{$newkey} = $newuser; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | $new{$newkey} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my @deleted; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | foreach my $pkey ( keys %present ) { | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | unless ( exists $new{$pkey} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | push @deleted, $self->user->{$pkey}->nickname; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | delete $self->user->{$pkey}; | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | return (@deleted); | |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 4 | ▶ | sub generate_packet { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_packet: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 4 | my( $self, $args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 4 | my $command = $args->{command}; | |||||||||||||||||||||||||||||||||||||||||
| 200 | 4 | ▶ | my $option = $args->{option} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'option'} || ''
MC/DC0%0/1
$args->{'option'} || ''
$args->{'option'}
Truth table50%1/2
A
A= $args->{'option'}
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 4 | ▶ | my $packet_num = $args->{packet_num} || $self->get_new_packet_num; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args->{'packet_num'} || $self->get_new_packet_num
MC/DC0%0/2
$args->{'packet_num'} || $self->get_new_packet_num
$args->{'packet_num'}
$self->get_new_packet_num
Truth table33%1/3
A || B
A= $args->{'packet_num'}B= $self->get_new_packet_num
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 4 | $args->{option} = $option; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 4 | $args->{packet_num} = $packet_num; | |||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 4 | my $msg = sprintf "1:%s:%s:%s:%s:%s", $packet_num, $self->username, | |||||||||||||||||||||||||||||||||||||||||
| 206 | $self->hostname, $command, $option; | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 4 | return $msg; | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 4 | ▶ | sub send { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send: called CC=14 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 4 | my( $self, $args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 212 | 4 | my $sock = $self->socket; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 4 | my $command = $args->{command}; | |||||||||||||||||||||||||||||||||||||||||
| 214 | 4 | my $msg = $self->generate_packet($args); | |||||||||||||||||||||||||||||||||||||||||
| 215 | 4 | my $packet_num = $args->{packet_num}; | |||||||||||||||||||||||||||||||||||||||||
| 216 | # TODO check max msg length check by MAX_SOCKBUF | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | # stack sendmsg packet number | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 4 | ▶ | if ( $command->modename eq 'SENDMSG' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$command->modename eq "SENDMSG" and $command->get_sendcheck and not exists $self->sending_packet->{$packet_num}
$command->modename eq "SENDMSG" and $command->get_sendcheck
MC/DC33%1/3
$command->modename eq "SENDMSG" and $command->get_sendcheck and not exists $self->sending_packet->{$packet_num}
$command->modename eq "SENDMSG"
$command->get_sendcheck
not exists $self->sending_packet->{$packet_num}
Truth table50%2/4
A and B and not(C)
A= $command->modename eq "SENDMSG"B= $command->get_sendcheckC= not exists $self->sending_packet->{$packet_num}
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | and $command->get_sendcheck | ||||||||||||||||||||||||||||||||||||||||||
| 221 | and not exists $self->sending_packet->{$packet_num} ) | ||||||||||||||||||||||||||||||||||||||||||
| 222 | { | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | $args->{sendretry} = $self->sendretry; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | $self->sending_packet->{$packet_num} = $args; | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 4 | my $peerport = $args->{peerport}; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 4 | ▶ | if ( not defined $peerport ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 2 | ▶ | $peerport = $sock->peerport || $PORT; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$sock->peerport || $PORT
MC/DC0%0/2
$sock->peerport || $PORT
$sock->peerport
$PORT
Truth table33%1/3
A || B
A= $sock->peerportB= $PORT
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | # send broadcast packet | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 4 | ▶ | if ( $command->get_broadcast ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 1 | ▶ | $sock->sockopt( SO_BROADCAST() => 1 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | or croak "failed sockopt : $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 1 | ▶ | unless ( @{ $self->broadcast } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 1 | $self->add_broadcast($BROADCAST); | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 1 | for my $broadcast_addr ( @{ $self->broadcast } ) { | |||||||||||||||||||||||||||||||||||||||||
| 241 | 1 | my $dest = sockaddr_in( $peerport, inet_aton($broadcast_addr) ); | |||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | ▶ | $sock->send( $msg, 0, $dest ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | or croak "send() failed : $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 1 | ▶ | $sock->sockopt( SO_BROADCAST() => 0 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | or croak "failed sockopt : $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | # send packet | ||||||||||||||||||||||||||||||||||||||||||
| 250 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 3 | my $peeraddr = $args->{peeraddr}; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 3 | ▶ | if ( not defined $peeraddr ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 2 | $peeraddr = inet_ntoa( $sock->peeraddr ); | |||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 3 | my $dest = sockaddr_in( $peerport, inet_aton($peeraddr) ); | |||||||||||||||||||||||||||||||||||||||||
| 257 | 3 | ▶ | $sock->send( $msg, 0, $dest ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | or croak "send() failed : $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | sub flush_sendings { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flush_sendings: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | for my $packet_num ( keys %{ $self->sending_packet } ) { | |||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | my $args = $self->sending_packet->{$packet_num}; | |||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | if ( 0 > --$args->{sendretry} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | delete $self->sending_packet->{$packet_num}; | |||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | $args->{packet_num} = $packet_num; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | $self->send($args); | |||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 16 | ▶ | sub messagecommand { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
messagecommand: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 16 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 278 | 16 | return Net::IPMessenger::MessageCommand->new(shift); | |||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 4 | ▶ | sub get_new_packet_num { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_new_packet_num: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 4 | my $count = $self->packet_count; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 4 | $self->packet_count( ++$count ); | |||||||||||||||||||||||||||||||||||||||||
| 285 | 4 | return ( time + $count ); | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 2 | ▶ | sub my_info { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
my_info: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 2 | ▶ | return sprintf "%s\0%s\0", $self->nickname || '', $self->groupname || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$self->nickname || ''
$self->groupname || ''
MC/DC0%0/1
$self->nickname || ''
$self->nickname
MC/DC0%0/1
$self->groupname || ''
$self->groupname
Truth table50%1/2
A
A= $self->nickname
Truth table50%1/2
A
A= $self->groupname
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 294 | __END__ | ||||||||||||||||||||||||||||||||||||||||||