aIRC — File Browser
aIRCv0.8.69 / aIRCv0.8.69 / addons / http.mrc
http.mrc — 5.4 KB — Download this file
;/**********************************************************************
; *
; * aIRC
; * HTTP Client
; *
; **********************************************************************/
;
alias _http.addonver { return 1.0 }
alias http {
var %resume,%parms,%server,%dirfile,%port,%localfile
if ($left($1,1) == -) {
if (r isin $1) { %resume = 1 }
%parms = $_parameter($2-,1,HTTP Client [/http],normal,$null,www.serv.com[:port][/dir]</file.ext>)
}
else { %parms = $_parameter($1-,1,HTTP Client [/http],normal,$null,www.serv.com[:port][/dir]</file.ext>) }
%parms = $remove(%parms,http://)
%server = $gettok(%parms,1,47)
%dirfile = / $+ $gettok(%parms,2-,47)
if ($gettok(%server,2,58)) { %port = $ifmatch }
elseif ($gettok(%dirfile,2,58)) { %port = $ifmatch }
else { %port = 80 }
%dirfile = $gettok(%dirfile,1,58)
%server = $gettok(%server,1,58)
%localfile = $getdir($gettok(%dirfile,-1,47)) $+ $gettok(%dirfile,$numtok(%dirfile,47),47)
if (%dirfile == /) { %localfile = $getdir(*.htm) $+ index.htm }
if ($isfile(%localfile) == $true) && (%resume == $null) && ($$?!="You already have the file $+ $crlf $+ $crlf $+ $nopath(%localfile) $+ $crlf $+ $crlf $+ SIZE: $+ $crlf $+ $crlf $+ $file(%localfile).size bytes $chr(91) $+ $_size($file(%localfile).size) $+ $chr(93) $+ $crlf $+ $crlf $+ Replace it?:" == $false) { return }
return $_airchttp(%server,%port,%dirfile,%localfile,$iif(%resume,1,0),_http)
}
alias _http.unload {
var %i = $window(0),%win,%num
while (%i) {
var %win = $window(%i),%num = $right(%win,-5)
if (@HTTP* iswm %win) && (%num isnum) {
sockclose HTTP $+ %num
close -@ %win
}
dec %i
}
}
alias _http.resume {
if ($_yesno(0,HTTP Client [/http],0,Download failed:<CRLF>http:// [ $+ [ $1- ] ] <CRLF>Do you want to try a resume?)) { http -r $1- }
}
menu @HTTP {
&close:{
sockclose $remove($active,@)
info.a Closing session HTTP $remove($active,@HTTP)
close -@ $active
}
}
alias _onclosewin.HTTP {
sockclose $remove($2,@)
info.a Closing HTTP session $remove($2,@HTTP)
}
;
;
; The handlers:
;
;
alias _http.init {
var %sock = $1,%win = @ $+ %sock
tokenize 9 $sock(%sock).mark
var %server = $1,%dirfile = $2,%localfile = $3,%port = $11,%mm
if (%port == 80) { %mm = %server $+ %dirfile }
else { %mm = %server $+ : $+ %port $+ %dirfile }
_recent.add http 10 %mm
window -ak +nt %win $_window.conf(@HTTP)
_window.font.reset %win @HTTP
titlebar %win %mm
aline $colour(info) %win $_color(info2) $+ Downloading: $nopath(%localfile)
aline $colour(info) %win $_color(info2) $+ Bytes: 0 $_color(info2) $+ Perc:
aline $colour(info) %win Connecting with %server $+ ...
}
alias _http.errsockopen {
var %sock = $1,%win = @ $+ %sock
close -@ %win
error.a HTTP connection with $_sockmark(%sock,1) $+ : $_sockerr
}
alias _http.errsockwrite {
var %sock = $1,%win = @ $+ %sock
close -@ %win
error.a HTTP connection with $_sockmark(%sock,1) $+ : $_sockerr
}
alias _http.errsockread {
var %sock = $1,%win = @ $+ %sock
close -@ %win
error.a HTTP connection with $_sockmark(%sock,1) $+ : $_sockerr
}
alias _http.errhttp {
var %sock = $1,%errstring = $2-,%win = @ $+ %sock,%file = $_sockmark(%sock,3)
close -@ %win
error.a %errstring
if ($isfile(%file)) { info.a You already have the file $nopath(%file) }
}
alias _http.startget {
var %sock = $1,%win = @ $+ %sock
rline $colour(info) %win 3 Connected! Requesting $_sockmark(%sock,2)
}
alias _http.nohttp11 {
var %sock = $1,%win = @ $+ %sock
close -@ %win
error.a Server $_sockmark(%sock,1) doesn't support HTTP 1.1
}
alias _http.noresumesupported {
var %sock = $1,%win = @ $+ %sock
error.a Server $_sockmark(%sock,1) doesn't support resumes. Downloading the entire file.
}
alias _http.startresuming {
var %sock = $1,%win = @ $+ %sock
rline $colour(info) %win 1 $_color(info2) $+ Resuming: $nopath($_sockmark(%sock,3))
}
alias _http.downloading {
var %sock = $1,%win = @ $+ %sock,%rcvd = $sock(%sock).rcvd
tokenize 9 $sock(%sock).mark
var %tmp1 = %rcvd - $9,%tmp2 = $calc(%tmp1 / (($ticks - $4) / 1000))
rline $colour(info) %win 2 $_color(info2) $+ Bytes: %tmp1 $_color(info2) $+ Perc: $_percent(%tmp1,$8)
rline $colour(info) %win 3 $_color(info2) $+ Remaining: $_duratio($calc(($8 - %tmp1) / %tmp2),2) $_sckbpsw(%tmp2)
; rline $colour(info) %win 3 $_color(info2) $+ Remaining: $_duratio($calc(($8 - %rcvd - $9) / $calc((%rcvd - $9) / (($ticks - $4) / 1000))),2) $_sckbpsw($calc((%rcvd - $9) / (($ticks - $4) / 1000)))
}
alias _http.sockclose {
var %sock = $1,%win = @ $+ %sock,%rcvd = $sock($1).rcvd
tokenize 9 $sock(%sock).mark
var %tmp1 = %rcvd - $9,%tmp2
if (%tmp1 == $8) {
%tmp2 = $calc(%tmp1 / (($ticks - $4) / 1000))
rline $colour(info) %win 2 $_color(info2) $+ Bytes: %tmp1 $_color(info2) $+ Perc: $_percent(%tmp1,$8)
rline $colour(info) %win 3 $_color(info2) $+ Completed in: $_duratio($calc(($ticks - $4) / 1000),2) $_sckbpsw(%tmp2)
_recent.add files 10 $_fixfilename($3,m)
}
elseif ($_getsetup(_autoresume)) {
rline $colour(ctcp) %win 3 ERROR - Attemping to resume...
http -r $window(%win).title
}
else {
rline $colour(ctcp) %win 3 ERROR - You can try to resume
.timer -mo 1 1 _http.resume $window(%win).title
}
close -@ %win
}
alias _windowsize.HTTP { return X Y 324 68 }
alias _windowopts.HTTP { return 0 1 1 }