On 01/08/05(17:20) you Poul <p6yfabdyi-mykgh44qo6tw.ml@delegate.org> wrote in <_A2808@delegate-en.ML_> |> I'm not sure if chunked encoding has something to do with this error, |> but at least it fails because FTP/HTTP-DeleGate does not support |> retrievals with "Range:" header. |> I added a tentative code to support it and uploaded it as: |> ftp://ftp.delegate.org/pub/DeleGate/beta/delegate8.10.4-pre7.tar.gz | |I try it... |Downloading file is cached.... |With prev version when I stop transfer in Opera - file deleted in cache.. |With this version when I stop transfer - file download continue in cache, |but |I can't resume transfer in Opera... only when all file downloaded in cache |- transfer |complete in Opera.... with prev version resume work, but start from 0... I modified DeleGate to support partial getting for FTP/HTTP without downloading an entire file, as enclosed patch. The modified version is uploaded as 8.10.4-pre8 too. |I am runing on my homeserver DeleGate as Ftp,Socks,POP,SMTP proxy, |WWW-server and Squid as HTTP proxy....only because I can't continiue |terminated(stoped) download with DeleGate - this feature is ne嚆ssary for |my ADSL connection... I've got why partial getting is necessary in your environment. Cheers, Yutaka -- D G Yutaka Sato <pfqcabdyi-mykgh44qo6tw.ml@delegate.org> http://delegate.org/y.sato/ ( - ) National Institute of Advanced Industrial Science and Technology _< >_ 1-1-4 Umezono, Tsukuba, Ibaraki, 305-8568 Japan Do the more with the less -- B. Fuller diff -cr dist/delegate8.10.4-pre7/src/delegate.h ./src/delegate.h *** dist/delegate8.10.4-pre7/src/delegate.h Sat Jan 8 06:21:07 2005 --- ./src/delegate.h Sat Jan 8 20:10:04 2005 *************** *** 661,666 **** --- 661,670 ---- /**/ #define RespWithBody Conn->resp_with_body + #define reqPARTIAL (0 < Conn->cl.p_range[0] || 0 < Conn->cl.p_range[1]) + #define reqPART_FROM (0 < Conn->cl.p_range[0] ? Conn->cl.p_range[0] : 0) + #define gotPART_FROM Conn->sv.p_range[0] + #define CO_REJECTED 1 #define CO_CANTRESOLV 2 #define CO_CANTCONN 4 diff -cr dist/delegate8.10.4-pre7/src/ftp.c ./src/ftp.c *** dist/delegate8.10.4-pre7/src/ftp.c Fri Jan 7 16:10:12 2005 --- ./src/ftp.c Sat Jan 8 20:46:38 2005 *************** *** 2557,2563 **** --- 2557,2566 ---- get_resp(fs,NULL,AVStr(resp),sizeof(resp)); return dsock; } + /* static int listretr(FILE *ts,FILE *fs,PCStr(path),int *isdirp,PVStr(resp),int rsize) + */ + static int listretr(Connection *Conn,FILE *ts,FILE *fs,PCStr(path),int *isdirp,PVStr(resp),int rsize) { const char *dp; CStr(xpath,1024); CStr(apath,1024); *************** *** 2592,2597 **** --- 2595,2610 ---- isdir = 1; } + if( 0 < reqPART_FROM ){ + CStr(rest,128); + sprintf(rest,"REST %d",reqPART_FROM); + if( put_get(ts,fs,AVStr(resp),rsize,"%s\r\n",rest) == EOF ){ + gotPART_FROM = reqPART_FROM; + }else{ + gotPART_FROM = -1; + } + } + if( put_get(ts,fs,AVStr(resp),rsize,"%s\r\n",comm) == EOF ) return -1; *************** *** 2664,2670 **** --- 2677,2686 ---- FILE *tc; put_serv(0,ts,"PORT 0,0,0,0,0,0\r\n"); if( get_resp(fs,NULL,AVStr(resp),rsize) != EOF ) + /* if( listretr(ts,fs,path,isdirp,AVStr(resp),rsize) == 0 ) + */ + if( listretr(Conn,ts,fs,path,isdirp,AVStr(resp),rsize) == 0 ) if( get_resp(fs,NULL,AVStr(resp),rsize) != EOF ){ tc = TMPFILE("XDC"); getMessageFX(fs,NULL,FTP_FROMSERV_TIMEOUT,relay1,tc,"",""); *************** *** 2689,2695 **** --- 2705,2714 ---- goto EXIT; } }else{ + /* if( listretr(ts,fs,path,isdirp,AVStr(resp),rsize) < 0 ){ + */ + if( listretr(Conn,ts,fs,path,isdirp,AVStr(resp),rsize) < 0 ){ if( 0 <= psock ){ close(psock); psock = -1; *************** *** 5485,5491 **** --- 5504,5516 ---- goto EXIT; if( dfp = cache_verify(Conn,ts,fs,path,AVStr(resp),rsize,isdirp) ) + { + if( 0 < reqPART_FROM ){ + fseek(dfp,reqPART_FROM,0); + gotPART_FROM = reqPART_FROM; + } goto EXIT; + } setConnTimeout(Conn); if( FCF.fc_nopasvSV ) usePASV = 0; diff -cr dist/delegate8.10.4-pre7/src/ftpgw.c ./src/ftpgw.c *** dist/delegate8.10.4-pre7/src/ftpgw.c Fri Jan 7 08:04:20 2005 --- ./src/ftpgw.c Sat Jan 8 20:41:19 2005 *************** *** 255,260 **** --- 255,275 ---- int CCV_relay_texts(Connection *Conn,FILE *ins[],FILE *out,FILE *dup); int file_copy(FILE *src,FILE *dst,FILE *cache,int bytes,int *binary); + + static void write_bytes(Connection *Conn,FILE *in,FILE *out,PCStr(range)){ + int len,rcc,ch; + len = atoi(range); + + for( rcc = 0; rcc < len; rcc++ ){ + ch = getc(in); + if( ch == EOF ) + break; + if( putc(ch,out) == EOF ) + break; + } + sv1log("write_bytes %d/%d\n",rcc,len); + } + static int ident_copy(Connection *Conn,FILE *fsd,FILE *tc,FILE *cachefp,PCStr(server),PCStr(path),int size,int expire) { int binary; const char *encoding; *************** *** 265,272 **** const char *base; FILE *ins[3]; /**/ FILE *tcx = 0; - FILE *tcs; - int len; tmp = reusableTMPFILE("ident_copy",(iFUNCP)ident_copy); file_copy(fsd,tmp,NULL,CHECK_LENG,&binary); --- 280,285 ---- *************** *** 278,283 **** --- 291,298 ---- base = path; if( !Conn->body_only && 0<Conn->cl.p_range[0] || 0<Conn->cl.p_range[1] ){ + int len; + CStr(range,32); /* *stcodep = 206; */ *************** *** 289,298 **** len = Conn->sv.p_range[1] - Conn->sv.p_range[0] + 1; putHEAD(Conn,tc,206,"Partial",server,ctype,encoding,len,-1,expire); fputs("\r\n",tc); ! tcx = TMPFILE("Range"); ! tcs = tc; ! tc = tcx; }else if( !Conn->body_only ) putHttpHeader1(Conn,tc,server,ctype,encoding,size,expire); --- 304,316 ---- len = Conn->sv.p_range[1] - Conn->sv.p_range[0] + 1; putHEAD(Conn,tc,206,"Partial",server,ctype,encoding,len,-1,expire); fputs("\r\n",tc); + fflush(tc); ! sprintf(range,"%d",len); ! tcx = openFilter(Conn,"RANGE",(iFUNCP)write_bytes,tc,range); ! if( tcx != NULL ){ ! tc = tcx; ! } }else if( !Conn->body_only ) putHttpHeader1(Conn,tc,server,ctype,encoding,size,expire); *************** *** 316,327 **** fclose(tmp); if( tcx != NULL ){ - fflush(tcx); - fseek(tcx,0,0); - fseek(tcx,Conn->cl.p_range[0],0); - len = Conn->sv.p_range[1] - Conn->sv.p_range[0] + 1; - file_copy(tcx,tcs,NULL,len,NULL); fclose(tcx); } return totalc; } --- 334,341 ---- fclose(tmp); if( tcx != NULL ){ fclose(tcx); + NoHangWait(); } return totalc; } *************** *** 607,612 **** --- 621,630 ---- if( cachefp == NULL ) return 0; + if( reqPARTIAL ){ + /* should use ident_copy() */ + } + tc0 = tc; if( !HTTP_relayThru(Conn) && fileMaybeText(path) ) tc = openHttpResponseFilter(Conn,tc0); *************** *** 808,813 **** --- 826,836 ---- sv1log("FTP/HTTP: server opened [%d]\n",server); fsc = fdopen(server,"r"); + + if( reqPARTIAL ){ + docache = 0; + gotPART_FROM = -1; + } svdata = ftp_fopen(Conn,put,server,host,ruser,rpass,path,AVStr(resp),sizeof(resp),&isdir); if( svdata != NULL && file_isreg(fileno(svdata)) ){