Re: Popełniłem....

Autor: Adam Płaszczyca (trzypion_at_waw.pdi.net)
Data: Wed 24 Oct 2001 - 21:25:38 MET DST


Tomasz Szcześniak napisał(a):
>
> > > A czy potrafi pobrać pliki rozbite na kilka wiadomości?
> > Nie. Pole do popisu dla Was. W sumie nie powinno być to trudne :-)
>
> Zobaczę, rexxa nigdy w życiu do niczego nie użyłem, wszystko robię w
> C...
> Kiedyś musi być ten pierwszy raz :)

Oto on:

/* news binaries downloader */
'@echo off'
parse arg server newsgroup
CALL RxFuncAdd SysLoadFuncs, rexxutil, sysloadfuncs
CALL SysLoadFuncs
CALL RxFuncAdd "SockLoadFuncs","rxSock","SockLoadFuncs"
CALL SockLoadFuncs nul
SAY 'Otwieram socketa'
OurSocket = SockSocket("AF_INET", "SOCK_STREAM", "IPPROTO_TCP")
say 'OurSocket: 'OurSocket
RB=""
IF DATATYPE(LEFT(server,1))='NUM' THEN host.addr = server
ELSE
   DO
    say 'Szukam adresu IP servera'
    IF \SockGetHostByName(server,'host.') THEN
      DO
        say "Unknown host"
        DROP host.
        RETURN 0
      END
   END
say 'Adres servera: 'host.addr
target.!family = 'AF_INET'
target.!port = 119
target.!addr = host.addr
IF SockConnect(OurSocket,"target.!") = -1 THEN
   DO
     say "Failed to connect"
     RETURN 0
   END
say 'connected'

l=getto(oursocket,'0D0A'X, 1)
if left(l,4)<>"200 " then errexit("server response: "||l)

rc=putline(oursocket, "mode reader")
l=getto(oursocket,'0D0A'X, 1)
if left(l,4)<>"200 " then errexit("server response: "||l)

rc=putline(oursocket, "group "||newsgroup)
l=getto(oursocket,'0D0A'X, 1)
if left(l,4)<>"211 " then errexit("server response: "||l)

rc=putline(oursocket, "listgroup "||newsgroup)
l=getto(oursocket,'0D0A'X, 1)
if left(l,4)<>"211 " then errexit("server response: "||l)
l=''
n=1
articles.0=0
do while l<>'.'||'0D0A'X
        l=getto(oursocket,'0D0A'X, 0)
        if l='.'||'0D0A'X then iterate
        articles.n=left(l, length(l)-2)
        n=n+1
end
articles.0=n
rc=lineout(,n||' articles found')
tmsg='msg.tmp'
do n=1 to articles.0
        rc=putline(oursocket, "article "||articles.n)
        l=getto(oursocket,'0D0A'X, 1,0,0)
        if left(l,4)="220 " then
        do
        /* tmsg=articles.n||'.art' */
                say "writing article to "||tmsg
                call SysFileDelete(tmsg)
                rc=stream(tmsg,'C','OPEN WRITE')
                l=""
                do while l<>'.'||'0D0A'X
                        l=getto(oursocket,'0D0A'X,0, 32768,5)
                        rc=charout(tmsg,l)
                end
                rc=stream(tmsg,'C','CLOSE')
                'uudecode -d 'tmsg
        end
end
call SysFileDelete(tmsg)
rc=putline(oursocket, "quit")
CALL SockSoClose(OurSocket)
RETURN 0

putline: procedure
        parse arg socket, linia
        rc=SockSend(Socket, linia||'0D0A'X)
        if rc=-1 then errexit("write to host failed: "||linia)
        rc=lineout(,'> '||linia)
RETURN 0

getto: procedure
/*parametry:
  socket, delimiter, wizualizacja, maksymalna liczba znaków, czas
czekania
*/
        parse arg socket, delim, vis, bytecount, wait
        if bytecount='' then bytecount=0
        if wait='' then wait=0.1
        dl=length(delim)-1
        dane=""
        rc=0
        otoread=0
        /* czekamy na pojawienie się delimitera */
        do until rc<0 | pos(delim, dane)>0 | (bytecount>0 & toread>bytecount)
                /*ile znaków do czytania - w zmiennej toread*/
                rc=SockIoctl(socket,'FIONREAD','toread')
                if rc=0 & toread>0 then
                        rc = SockRecv(Socket, 'dane', toread, 'MSG_PEEK')
                /*aby niepotrzebnei nie obciążać maszyny */
                if otoread=toread then call SysSleep(wait)
        end
        /* czytamy do delimitera */
        if pos(delim,dane)<>0 then toread=pos(delim,dane)+dl
        rc=SockRecv(Socket, 'dane', toread )
        if vis=1 then rc=charout(,'< '||dane)
return dane

errexit: procedure
        parse arg msg
        say "ERROR!"
        say msg
        signal error
return 0

error:
exit
return

-- 
     ___________ (R)  
    /_  _______      Adam Płaszczyca (+48 502) 122 688
  ___/ /_  ___      ul. Ludwiki 1 m. 74, 01-226 Warszawa
 _______/ /_     IRC: _555, http://mike.oldfield.org.pl/
___________/	 mail: _555_at_irc.pl UIN: 4098313


To archiwum zostało wygenerowane przez hypermail 2.1.7 : Tue 18 May 2004 - 15:33:54 MET DST