aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Message.pm169
-rw-r--r--src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Packet.pm127
-rw-r--r--src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Session.pm12
-rw-r--r--src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Transport.pm8
4 files changed, 127 insertions, 189 deletions
diff --git a/src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Message.pm b/src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Message.pm
index 228431c90..b0a942c04 100644
--- a/src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Message.pm
+++ b/src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Message.pm
@@ -1,17 +1,8 @@
package Vici::Message;
-require Exporter;
-use AutoLoader qw(AUTOLOAD);
-
-our @ISA = qw(Exporter);
-our @EXPORT = qw(
- new, from_data, hash, encode, raw, result
-);
our $VERSION = '0.9';
use strict;
-use warnings;
-use Switch;
use Vici::Transport;
use constant {
@@ -85,52 +76,46 @@ sub parse {
(my $key, $data) = unpack('C/a*a*', $data);
- switch ($type)
- {
- case KEY_VALUE
- {
- (my $value, $data) = unpack('n/a*a*', $data);
- $hash->{$key} = $value;
- }
- case SECTION_START
- {
- my %section = ();
- $data = parse($data, \%section);
- $hash->{$key} = \%section;
- }
- case LIST_START
- {
- my @list = ();
- my $more = 1;
+ if ( $type == KEY_VALUE )
+ {
+ (my $value, $data) = unpack('n/a*a*', $data);
+ $hash->{$key} = $value;
+ }
+ elsif ( $type == SECTION_START )
+ {
+ my %section = ();
+ $data = parse($data, \%section);
+ $hash->{$key} = \%section;
+ }
+ elsif ( $type == LIST_START )
+ {
+ my @list = ();
+ my $more = 1;
- while (length($data) > 0 and $more)
+ while (length($data) > 0 and $more)
+ {
+ (my $type, $data) = unpack('Ca*', $data);
+ if ( $type == LIST_ITEM )
{
- (my $type, $data) = unpack('Ca*', $data);
- switch ($type)
- {
- case LIST_ITEM
- {
- (my $value, $data) = unpack('n/a*a*', $data);
- push(@list, $value);
- }
- case LIST_END
- {
- $more = 0;
- $hash->{$key} = \@list;
- }
- else
- {
- die "message parsing error: ", $type, "\n"
- }
- }
+ (my $value, $data) = unpack('n/a*a*', $data);
+ push(@list, $value);
+ }
+ elsif ( $type == LIST_END )
+ {
+ $more = 0;
+ $hash->{$key} = \@list;
+ }
+ else
+ {
+ die "message parsing error: ", $type, "\n"
}
}
- else
- {
- die "message parsing error: ", $type, "\n"
- }
- }
- }
+ }
+ else
+ {
+ die "message parsing error: ", $type, "\n"
+ }
+ }
return $data;
}
@@ -141,31 +126,28 @@ sub encode_hash {
while ( (my $key, my $value) = each %$hash )
{
- switch (ref($value))
+ if ( ref($value) eq 'HASH' )
{
- case 'HASH'
- {
- $enc .= pack('CC/a*', SECTION_START, $key);
- $enc .= encode_hash($value);
- $enc .= pack('C', SECTION_END);
- }
- case 'ARRAY'
- {
- $enc .= pack('CC/a*', LIST_START, $key);
+ $enc .= pack('CC/a*', SECTION_START, $key);
+ $enc .= encode_hash($value);
+ $enc .= pack('C', SECTION_END);
+ }
+ elsif ( ref($value) eq 'ARRAY' )
+ {
+ $enc .= pack('CC/a*', LIST_START, $key);
- foreach my $item (@$value)
- {
- $enc .= pack('Cn/a*', LIST_ITEM, $item);
- }
- $enc .= pack('C', LIST_END);
- }
- else
+ foreach my $item (@$value)
{
- $enc .= pack('CC/a*n/a*', KEY_VALUE, $key, $value);
+ $enc .= pack('Cn/a*', LIST_ITEM, $item);
}
+ $enc .= pack('C', LIST_END);
+ }
+ else
+ {
+ $enc .= pack('CC/a*n/a*', KEY_VALUE, $key, $value);
}
}
- return $enc;
+ return $enc;
}
sub raw_hash {
@@ -185,38 +167,35 @@ sub raw_hash {
}
$raw .= $key;
- switch (ref($value))
+ if ( ref($value) eq 'HASH' )
{
- case 'HASH'
- {
- $raw .= '{' . raw_hash($value) . '}';
- }
- case 'ARRAY'
- {
- my $first_item = 1;
- $raw .= '[';
+ $raw .= '{' . raw_hash($value) . '}';
+ }
+ elsif ( ref($value) eq 'ARRAY' )
+ {
+ my $first_item = 1;
+ $raw .= '[';
- foreach my $item (@$value)
+ foreach my $item (@$value)
+ {
+ if ($first_item)
{
- if ($first_item)
- {
- $first_item = 0;
- }
- else
- {
- $raw .= ' ';
- }
- $raw .= $item;
+ $first_item = 0;
}
- $raw .= ']';
- }
- else
- {
- $raw .= '=' . $value;
+ else
+ {
+ $raw .= ' ';
+ }
+ $raw .= $item;
}
+ $raw .= ']';
+ }
+ else
+ {
+ $raw .= '=' . $value;
}
}
- return $raw;
+ return $raw;
}
1;
diff --git a/src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Packet.pm b/src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Packet.pm
index 62dac0a37..9e2b77fa5 100644
--- a/src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Packet.pm
+++ b/src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Packet.pm
@@ -1,17 +1,8 @@
package Vici::Packet;
-require Exporter;
-use AutoLoader qw(AUTOLOAD);
-
-our @ISA = qw(Exporter);
-our @EXPORT = qw(
- new, request, register, unregister, streamed_request
-);
our $VERSION = '0.9';
use strict;
-use warnings;
-use Switch;
use Vici::Message;
use Vici::Transport;
@@ -45,21 +36,18 @@ sub request {
my $response = $self->{'Transport'}->receive();
my ($type, $data) = unpack('Ca*', $response);
- switch ($type)
+ if ( $type == CMD_RESPONSE )
{
- case CMD_RESPONSE
- {
- return Vici::Message->from_data($data);
- }
- case CMD_UNKNOWN
- {
- die "unknown command '", $command, "'\n"
- }
- else
- {
- die "invalid response type\n"
- }
- };
+ return Vici::Message->from_data($data);
+ }
+ elsif ( $type == CMD_UNKNOWN )
+ {
+ die "unknown command '", $command, "'\n"
+ }
+ else
+ {
+ die "invalid response type\n"
+ }
}
sub register {
@@ -70,21 +58,18 @@ sub register {
my $response = $self->{'Transport'}->receive();
my ($type, $data) = unpack('Ca*', $response);
- switch ($type)
+ if ( $type == EVENT_CONFIRM )
{
- case EVENT_CONFIRM
- {
- return
- }
- case EVENT_UNKNOWN
- {
- die "unknown event '", $event, "'\n"
- }
- else
- {
- die "invalid response type\n"
- }
- };
+ return
+ }
+ elsif ( $type == EVENT_UNKNOWN )
+ {
+ die "unknown event '", $event, "'\n"
+ }
+ else
+ {
+ die "invalid response type\n"
+ }
}
sub unregister {
@@ -95,21 +80,18 @@ sub unregister {
my $response = $self->{'Transport'}->receive();
my ($type, $data) = unpack('Ca*', $response);
- switch ($type)
+ if ( $type == EVENT_CONFIRM )
{
- case EVENT_CONFIRM
- {
- return
- }
- case EVENT_UNKNOWN
- {
- die "unknown event '", $event, "'\n"
- }
- else
- {
- die "invalid response type\n"
- }
- };
+ return
+ }
+ elsif ( $type == EVENT_UNKNOWN )
+ {
+ die "unknown event '", $event, "'\n"
+ }
+ else
+ {
+ die "invalid response type\n"
+ }
}
sub streamed_request {
@@ -123,33 +105,30 @@ sub streamed_request {
my $more = 1;
my @list = ();
- while ($more)
- {
+ while ($more)
+ {
my $response = $self->{'Transport'}->receive();
my ($type, $data) = unpack('Ca*', $response);
- switch ($type)
+ if ( $type == EVENT )
+ {
+ (my $event_name, $data) = unpack('C/a*a*', $data);
+
+ if ($event_name eq $event)
+ {
+ my $msg = Vici::Message->from_data($data);
+ push(@list, $msg);
+ }
+ }
+ elsif ( $type == CMD_RESPONSE )
+ {
+ $self->unregister($event);
+ $more = 0;
+ }
+ else
{
- case EVENT
- {
- (my $event_name, $data) = unpack('C/a*a*', $data);
-
- if ($event_name eq $event)
- {
- my $msg = Vici::Message->from_data($data);
- push(@list, $msg);
- }
- }
- case CMD_RESPONSE
- {
- $self->unregister($event);
- $more = 0;
- }
- else
- {
- $self->unregister($event);
- die "invalid response type\n";
- }
+ $self->unregister($event);
+ die "invalid response type\n";
}
}
return \@list;
diff --git a/src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Session.pm b/src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Session.pm
index 02ed269f8..5252296cf 100644
--- a/src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Session.pm
+++ b/src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Session.pm
@@ -1,20 +1,8 @@
package Vici::Session;
-require Exporter;
-use AutoLoader qw(AUTOLOAD);
-
-our @ISA = qw(Exporter);
-our @EXPORT = qw(
- new, version, stats, reload_settings, initiate, terminate, install,
- uninstall, list_sas, list_policies, list_conns, get_conns, list_certs,
- list_authorities, get_authorities, load_conn, unload_conn, load_cert,
- load_key, load_shared, clear_creds, load_authority, unload_authority,
- load_pool, unload_pool, get_pools, get_algorithms
-);
our $VERSION = '0.9';
use strict;
-use warnings;
use Vici::Packet;
use Vici::Message;
diff --git a/src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Transport.pm b/src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Transport.pm
index 88a09fb0c..6524bf76d 100644
--- a/src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Transport.pm
+++ b/src/libcharon/plugins/vici/perl/Vici-Session/lib/Vici/Transport.pm
@@ -1,16 +1,8 @@
package Vici::Transport;
-require Exporter;
-use AutoLoader qw(AUTOLOAD);
-
-our @ISA = qw(Exporter);
-our @EXPORT = qw(
- new, send, receive
-);
our $VERSION = '0.9';
use strict;
-use warnings;
sub new {
my $class = shift;