home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.madoka.org
/
2014.12.ftp.madoka.org.tar
/
ftp.madoka.org
/
pub
/
plum
/
2.x
/
plum2_28_2.lzh
/
module
/
ctcp
/
dcc
/
http.plm
< prev
next >
Wrap
Text File
|
1998-10-15
|
12KB
|
372 lines
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><!-- $_ if 0; # -*- perl -*-
# $Id: http.plm,v 2.9 1998/09/26 14:21:40 hasegawa Exp $
# copyright (c)1998 pupu_j <hasegawa@agusa.nuie.nagoya-u.ac.jp>
package ctcp_dcc_http;
$READSIZE = 4096;
$CLIENTINFO = 'DCC';
$SOCKADDR = 'S n N x8';
$TIMEOUT = 3600;
$_ = 'ctcp_dcc_http';
sub main_loop {
local($userno) = @_;
foreach $cno (&'array($dccclientlist)) {
if (vec($'rout, $cno, 1)) {
&dcc_client($cno);
vec($'rout, $cno, 1) = 0;
} elsif (time() - $'access[$cno] > $TIMEOUT) {
&'close($cno);
$dccclientlist = &'remove($dccclientlist, $cno);
&'close($peer[$cno]);
$httpserverlist = &'remove($httpserverlist, $peer[$cno]);
$peer[$peer[$cno]] = 0;
$peer[$cno] = 0;
}
}
foreach $sno (&'array($dccserverlist)) {
if (vec($'rout, $sno, 1)) {
&dcc_server($sno);
vec($'rout, $sno, 1) = 0;
} elsif (time() - $'access[$sno] > $TIMEOUT) {
&'close($sno);
$dccserverlist = &'remove($dccserverlist, $sno);
&'close($peer[$sno]);
$httpserverlist = &'remove($httpserverlist, $peer[$sno]);
$peer[$peer[$sno]] = 0;
$peer[$sno] = 0;
}
}
foreach $sno (&'array($httpserverlist)) {
if (vec($'rout, $sno, 1)) {
&http_server($sno);
vec($'rout, $sno, 1) = 0;
} elsif (time() - $'access[$sno] > $TIMEOUT) {
&http_close($sno);
}
}
foreach $lno (&'array($dcclistenlist)) {
if (vec($'rout, $lno, 1)) {
&dcc_listen($lno);
vec($'rout, $lno, 1) = 0;
} elsif (time() - $'access[$lno] > $TIMEOUT) {
&'close($lno);
$dcclistenlist = &'remove($dcclistenlist, $lno);
&'close($peer[$lno]);
$httpserverlist = &'remove($httpserverlist, $peer[$lno]);
$peer[$peer[$lno]] = 0;
$peer[$lno] = 0;
}
}
}
sub cpss_dcc {
local($serverno, $prefix, $cmd, @params) = @_;
local($userno, @msg);
$userno = $'userno[$serverno];
if (&checkmask($userno, $prefix, $params[0])) {
@msg = &server_gate($serverno, $prefix, $params[0], split(/\s+/, $params[1]));
if (@msg) {
return ($prefix, $cmd, $params[0], join(' ', @msg));
} else {
return ();
}
}
return ($prefix, $cmd, @params);
}
sub cpcs_dcc {
local($clientno, $prefix, $cmd, @params) = @_;
local($userno, @msg);
$userno = $'userno[$clientno];
if (&checkmask($userno, '*!*@*', $params[0])) {
@msg = &client_gate($clientno, $prefix, $params[0], split(/\s+/, $params[1]));
if (@params) {
return ($prefix, $cmd, $params[0], join(' ', @msg));
} else {
return ();
}
}
return ($prefix, $cmd, @params);
}
sub server_gate {
local($serverno, $prefix, $chan, @params) = @_;
local($lno);
return @params if scalar(@params) < 4;
if ("\L$params[0]\E" eq 'send' || "\L$params[0]\E" eq 'chat') {
$lno = &'listen(0, 1) || return @params;
$param[$lno] = &'list(@params);
$server[$lno] = $serverno;
$userno[$lno] = $'userno[$serverno];
$dcclistenlist = &'add($dcclistenlist, $lno);
$params[3] = (unpack($SOCKADDR, getsockname($'socket[$lno])))[1];
foreach $cno (&'array($'clientlist)) {
next unless $'avail[$cno];
next unless $'server[$cno] == $serverno;
$params[2] = (unpack($SOCKADDR, getsockname($'socket[$cno])))[2];
&'c_print($cno, $prefix, 'PRIVMSG', $'nick[$cno], "\cA" . join(' ', 'DCC', @params) . "\cA");
}
return ();
}
return @params;
}
sub client_gate {
local($clientno, $prefix, $chan, @params) = @_;
local($userno, $proxy, $gate, $host, $port, $sno, $socket);
return @params if scalar(@params) < 4;
$userno = $'userno[$clientno];
$proxy = &'property($userno, 'proxy');
($host, $port) = split(/\:/, $proxy);
$gate = &'property($userno, 'gateway');
if ($host && $port && $gate && ($sno = &'connect($host, $port))) {
$socket = $'socket[$sno];
print $socket 'HEAD http://', $gate, '/ HTTP/1.0', "\r\n";
print $socket "\r\n";
$param[$sno] = &'list(@params);
$server[$sno] = $'server[$clientno];
$http[$sno] = 1;
$userno[$sno] = $userno;
$rbuf[$sno] = '';
$reply[$sno] = '';
$chan[$sno] = $chan;
$httpserverlist = &'add($httpserverlist, $sno);
return ();
}
return @params;
}
sub dcc_client {
local($clientno) = @_;
local($tmp, $socket);
$tmp = '';
if (sysread($'socket[$clientno], $tmp, $READSIZE)) {
$socket = $'socket[$peer[$clientno]];
print $socket $tmp if fileno($socket);
} else {
&'close($clientno);
$dccclientlist = &'remove($dccclientlist, $clientno);
&'close($peer[$clientno]);
$httpserverlist = &'remove($httpserverlist, $peer[$clientno]);
$peer[$peer[$clientno]] = 0;
$peer[$clientno] = 0;
}
}
sub dcc_server {
local($serverno) = @_;
local($tmp, $socket);
$tmp = '';
if (sysread($'socket[$serverno], $tmp, $READSIZE)) {
$socket = $'socket[$peer[$serverno]];
print $socket $tmp if fileno($socket);
} else {
&'close($serverno);
$dccserverlist = &'remove($dccserverlist, $serverno);
&'close($peer[$serverno]);
$httpserverlist = &'remove($httpserverlist, $peer[$serverno]);
$peer[$peer[$serverno]] = 0;
$peer[$serverno] = 0;
}
}
sub http_server {
local($serverno) = @_;
local($tmp, $next, $rest, $socket, $stat, $cno, $sno, $var, $val, $host, $port, $gate, @params);
$tmp = '';
if (sysread($'socket[$serverno], $tmp, $READSIZE)) {
if ($http[$serverno]) {
$socket = $'socket[$serverno];
$rbuf[$serverno] .= $tmp;
while ((($next, $rest) = split(/\r\n/, $rbuf[$serverno], 2)) == 2) {
$rbuf[$serverno] = $rest;
if ($next) {
$reply[$serverno] = &'add($reply[$serverno], $next);
} else {
$stat = (split(/\s+/, (&'array($reply[$serverno]))[0]))[1];
if ($stat eq '201') {
foreach $reply (&'array($reply[$serverno])) {
($var, $val) = split(/\s*\:\s*/, $reply, 2);
if ("\L$var\E" eq 'listen') {
($host, $port) = split(/\//, $val);
last;
}
}
@params = &'array($param[$serverno]);
$params[2] = $host;
$params[3] = $port;
&'s_print($server[$serverno], '', 'PRIVMSG', $chan[$serverno], "\cA" . join(' ', 'DCC', @params) . "\cA");
$gate = &'property($'userno[$server[$serverno]], 'gateway');
print $socket 'POST http://', $gate, '/ HTTP/1.0', "\r\n";
print $socket "\r\n";
$reply[$serverno] = '';
} elsif ($stat eq '202') {
@params = &'array($param[$serverno]);
if ($sno = &'connect($params[2], $params[3])) {
$http[$serverno] = 0;
$userno[$sno] = $userno[$serverno];
$dccserverlist = &'add($dccserverlist, $sno);
$peer[$serverno] = $sno;
$peer[$sno] = $serverno;
$socket = $'socket[$sno];
print $socket $rbuf[$serverno] if fileno($socket);
} else {
&http_close($serverno);
}
last;
} elsif ($stat eq '204') {
if ($cno = &'accept($peer[$serverno])) {
&'close($peer[$serverno]);
$http[$serverno] = 0;
$userno[$cno] = $userno[$serverno];
$dccclientlist = &'add($dccclientlist, $cno);
$peer[$serverno] = $cno;
$peer[$cno] = $serverno;
$socket = $'socket[$cno];
print $socket $rbuf[$serverno] if fileno($socket);
} else {
&http_close($serverno);
}
last;
} else {
&http_close($serverno);
last;
}
}
}
$rbuf[$serverno] = $next || '';
} else {
$socket = $'socket[$peer[$serverno]];
print $socket $tmp if fileno($socket);
}
} else {
&http_close($serverno);
}
}
sub http_close {
local($serverno) = @_;
&'close($serverno);
$httpserverlist = &'remove($httpserverlist, $serverno);
if ($peer[$serverno]) {
&'close($peer[$serverno]);
$dcclistenlist = &'remove($dcclistenlist, $peer[$serverno]);
$dccclientlist = &'remove($dccclientlist, $peer[$serverno]);
$dccserverlist = &'remove($dccserverlist, $peer[$serverno]);
$peer[$peer[$serverno]] = 0;
$peer[$serverno] = 0;
}
}
sub dcc_listen {
local($listenno) = @_;
local($cno, $sno, $userno, $proxy, $gate, $host, $port, $socket, @params);
$userno = $'userno[$server[$listenno]];
$proxy = &'property($userno, 'proxy');
($host, $port) = split(/\:/, $proxy);
$gate = &'property($userno, 'gateway');
if ($host && $port && $gate && ($sno = &'connect($host, $port))) {
$socket = $'socket[$sno];
@params = &'array($param[$listenno]);
print $socket 'POST http://', $gate, '/', join('/', @params[2, 3]), ' HTTP/1.0', "\r\n";
print $socket "\r\n";
$http[$sno] = 1;
$userno[$sno] = $userno[$listenno];
$rbuf[$sno] = '';
$reply[$sno] = '';
$peer[$sno] = $listenno;
$peer[$listenno] = $sno;
$httpserverlist = &'add($httpserverlist, $sno);
} else {
&'close($listenno);
}
$dcclistenlist = &'remove($dcclistenlist, $lno);
}
sub checkmask {
local($userno, $prefix, $chan) = @_;
local($user, $chlist, $list);
foreach $mask (&'property($userno, 'mask')) {
($user, $chlist) = split(/\s+/, $mask);
$list = '';
foreach $vchan (split(/\,/, $chlist || '')) {
$list = &'add($list, &'real($vchan));
}
if ($chan =~ /^[\#\&\+]/) {
next unless (!$list || &'exist($list, $chan));
} else {
next unless (!$list || &'exist($list, '*'));
}
if ($user =~ /^\-/) {
$regex = &'regex(substr($user, 1));
return 0 if $prefix =~ /$regex/i;
}
if ($user =~ /^\+/) {
$regex = &'regex(substr($user, 1));
} else {
$regex = &'regex($user);
}
return 1 if $prefix =~ /$regex/i;
}
return 0;
}
__END__
--><HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-2022-JP">
<LINK REV="made" HREF="mailto:hasegawa@agusa.nuie.nagoya-u.ac.jp">
<TITLE>ctcp/dcc/http.plm</TITLE></HEAD><BODY>
$B%*%s%i%$%s%I%-%e%a%s%H(B
<HR><H3>$BL>A0(B</H3>
ctcp/dcc/http.plm - DCC SEND$B$H(BDCC CHAT$B$r(BHTTP$B$r;H$C$FCf7Q$9$k(B
<HR><H3>$B@bL@(B</H3>
DCC SEND$B$H(BDCC CHAT$B$N%j%/%(%9%H$,Aw$i$l$F$-$?$H$-$K!"(B
HTTP$B$N(BProxy$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