home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.madoka.org
/
2014.12.ftp.madoka.org.tar
/
ftp.madoka.org
/
pub
/
plum
/
1.x
/
plum10b8.lzh
/
plum10b8
/
dccgate.plm
< prev
next >
Wrap
Text File
|
1997-06-25
|
3KB
|
116 lines
package dccgate;
$DCCREADSIZE = 4096;
$DCCREPLYSIZE = 4;
$_ = 'dccgate';
sub main_loop {
foreach $dccclientno (&'array($dccclientlist || $;)) {
&dcc_client($dccclientno) if vec($'rout, $dccclientno, 1);
}
foreach $dccserverno (&'array($dccserverlist || $;)) {
&dcc_server($dccserverno) if vec($'rout, $dccserverno, 1);
}
foreach $dcclistenno (&'array($dcclistenlist || $;)) {
&dcc_accept($dcclistenno) if vec($'rout, $dcclistenno, 1);
}
}
sub xss_dcc {
local($serverno, $prefix, $cmd, @params) = @_;
@params = &gateway(@params);
if (scalar(@params) > 0) {
return ($prefix, $cmd, @params);
} else {
return ();
}
}
sub xsp_dcc {
local($serverno, $prefix, $cmd, @params) = @_;
@params = &gateway(@params);
if (scalar(@params) > 0) {
return ($prefix, $cmd, @params);
} else {
return ();
}
}
sub dcc_client {
local($dccclientno) = @_;
local($input, $output, $tmp);
$input = "'$'socket[$dccclientno]";
$tmp = '';
if (sysread($input, $tmp, $DCCREPLYSIZE)) {
$output = "'$'socket[$dccpeer[$dccclientno]]";
print $output $tmp if fileno($output);
} else {
&'close($dccclientno);
vec($'rin, $dccclientno, 1) = 0;
$dccclientlist = &'remove($dccclientlist, $dccclientno);
}
}
sub dcc_server {
local($dccserverno) = @_;
local($input, $output, $tmp);
$input = "'$'socket[$dccserverno]";
$tmp = '';
if (sysread($input, $tmp, $DCCREADSIZE)) {
$output = "'$'socket[$dccpeer[$dccserverno]]";
print $output $tmp if fileno($output);
} else {
&'close($dccserverno);
vec($'rin, $dccserverno, 1) = 0;
$dccserverlist = &'remove($dccserverlist, $dccserverno);
}
}
sub dcc_accept {
local($dcclistenno) = @_;
local($dccclientno, $dccserverno);
if ($dccclientno = &'accept($dcclistenno)) {
$dccserverno = $dccpeer[$dcclistenno];
$dccpeer[$dccclientno] = $dccserverno;
$dccpeer[$dccserverno] = $dccclientno;
vec($'rin, $dcclistenno, 1) = 0;
vec($'rin, $dccclientno, 1) = 1;
vec($'rin, $dccserverno, 1) = 1;
$dcclistenlist = &'remove($dcclistenlist, $dcclistenno);
$dccclientlist = &'add($dccclientlist || $;, $dccclientno);
$dccserverlist = &'add($dccserverlist || $;, $dccserverno);
}
&'close($dcclistenno);
}
sub gateway {
local(@params) = @_;
local($dccserverno, $dcclistenno);
if ($params[0] eq 'SEND') {
if ($dcclistenno = &'listen(0, 1)) {
if ($dccserverno = &'connect($params[2], $params[3])) {
$dcclistenlist = &'add($dcclistenlist || $;, $dcclistenno);
vec($'rin, $dcclistenno, 1) = 1;
$dccpeer[$dcclistenno] = $dccserverno;
$params[2] = unpack('N', $'THISADDR);
$params[3] = $'port[$dcclistenno];
}
}
} elsif ($params[0] eq 'CANCEL') {
if ($params[2] == unpack('N', $'THISADDR)) {
foreach $dcclistenno (&'array($dcclistenlist)) {
next unless $params[3] == $'port[$dcclistenno];
&'close($dcclistenno);
$dccserverno = $dccpeer[$dcclistenno];
&'close($dccserverno);
vec($'rin, $dccserverno, 1) = 0;
$dccserverlist = &'remove($dccserverlist, $dccserverno);
return ();
}
}
}
return @params;
}