/usr/share/perl5/RPC/PlServer/Comm.pm is in libplrpc-perl 0.2020-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | # -*- perl -*-
#
#
# PlRPC - Perl RPC, package for writing simple, RPC like clients and
# servers
#
#
# Copyright (c) 1997,1998 Jochen Wiedmann
#
# You may distribute under the terms of either the GNU General Public
# License or the Artistic License, as specified in the Perl README file.
#
# Author: Jochen Wiedmann
# Email: jochen.wiedmann at freenet.de
#
require 5.004;
use strict;
require Storable;
package RPC::PlServer::Comm;
$RPC::PlServer::Comm::VERSION = '0.1003';
############################################################################
#
# Name: new (Class method)
#
# Purpose: Constructor
#
# Inputs: $class - This class
# $attr - Hash ref of attributes
#
# Result: Server object for success, error message otherwise
#
############################################################################
sub new ($) {
my($class, $attr) = @_;
my $self = {};
bless($self, (ref($class) || $class));
if (my $comp = $attr->{'compression'}) {
if ($comp eq 'off') {
$self->{'compression'} = undef;
} elsif ($comp eq 'gzip') {
require Compress::Zlib;
$self->{'compression'} = 'gzip';
} else {
die "Unknown compression type ($comp), use 'off' or 'gzip'";
}
}
if (my $cipher = $attr->{'cipher'}) {
$self->{'cipher'} = $cipher;
}
if (my $maxmessage = $attr->{'maxmessage'}) {
$self->{'maxmessage'} = $maxmessage;
}
$self;
}
############################################################################
#
# Name: Write
#
# Purpose: Writing to a PlRPC socket; used by both the client (when
# sending a method name and arguments) and the server (for
# sending the result list). Communication occurrs in packets.
# Each packet is preceeded by 4 bytes with the true packet
# size. If encryption happens, then the packet is padded with
# NUL bytes to a multiple of blocksize bytes. However, the
# stored size remains unchanged.
#
# Inputs: $self - Instance of RPC::PlServer or RPC::PlClient
# $socket - The socket to write to
# $args - Reference to array of arguments being sent
#
# Result: Nothing; dies in case of errors.
#
############################################################################
sub Write ($$$) {
my($self, $socket, $msg) = @_;
my $encodedMsg = Storable::nfreeze($msg);
$encodedMsg = Compress::Zlib::compress($encodedMsg)
if ($self->{'compression'});
my($encodedSize) = length($encodedMsg);
if (my $cipher = $self->{'cipher'}) {
my $size = $cipher->blocksize;
if (my $addSize = length($encodedMsg) % $size) {
$encodedMsg .= chr(0) x ($size - $addSize);
}
$msg = '';
for (my $i = 0; $i < length($encodedMsg); $i += $size) {
$msg .= $cipher->encrypt(substr($encodedMsg, $i, $size));
}
$encodedMsg = $msg;
}
local $\;
if (!$socket->print(pack("N", $encodedSize), $encodedMsg) ||
!$socket->flush()) {
die "Error while writing socket: $!";
}
}
############################################################################
#
# Name: Read
#
# Purpose: Reading from a PlRPC socket; used by both the client (when
# receiving a result list) and the server (for receiving the
# method name and arguments). Counterpart of Write, see
# above for specs.
#
# Inputs: $self - Instance of RPC::PlServer or RPC::PlClient
# $socket - The socket to read from
#
# Result: Array ref to result list; dies in case of errors.
#
############################################################################
sub Read($$) {
my($self, $socket) = @_;
my $result;
my($encodedSize, $readSize, $blockSize);
$readSize = 4;
$encodedSize = '';
while ($readSize > 0) {
my $result = $socket->read($encodedSize, $readSize,
length($encodedSize));
if (!$result) {
return undef if defined($result);
die "Error while reading socket: $!";
}
$readSize -= $result;
}
$encodedSize = unpack("N", $encodedSize);
my $max = $self->getMaxMessage();
die "Maximum message size of $max exceeded, use option 'maxmessage' to"
. " increase" if $max && $encodedSize > $max;
$readSize = $encodedSize;
if ($self->{'cipher'}) {
$blockSize = $self->{'cipher'}->blocksize;
if (my $addSize = ($encodedSize % $blockSize)) {
$readSize += ($blockSize - $addSize);
}
}
my $msg = '';
my $rs = $readSize;
while ($rs > 0) {
my $result = $socket->read($msg, $rs, length($msg));
if (!$result) {
die "Unexpected EOF" if defined $result;
die "Error while reading socket: $!";
}
$rs -= $result;
}
if ($self->{'cipher'}) {
my $cipher = $self->{'cipher'};
my $encodedMsg = $msg;
$msg = '';
for (my $i = 0; $i < $readSize; $i += $blockSize) {
$msg .= $cipher->decrypt(substr($encodedMsg, $i, $blockSize));
}
$msg = substr($msg, 0, $encodedSize);
}
$msg = Compress::Zlib::uncompress($msg) if ($self->{'compression'});
Storable::thaw($msg);
}
############################################################################
#
# Name: Init
#
# Purpose: Initialize an object for using RPC::PlServer::Comm methods
#
# Input: $self - Instance
#
# Returns: The instance in case of success, dies in case of trouble.
#
############################################################################
############################################################################
#
# Name: getMaxMessage
#
# Purpose: Returns the maximum size of a message
#
# Inputs: None
#
# Returns: Maximum message size or 65536, if none specified
#
############################################################################
sub getMaxMessage() {
my $self = shift;
return defined($self->{'maxmessage'}) ?
$self->{'maxmessage'} : 65536;
}
1;
|