diff -P -c httpdown313/Makefile httpdown313-hacked/Makefile *** httpdown313/Makefile Thu May 15 12:09:42 1997 --- httpdown313-hacked/Makefile Mon Nov 1 15:03:06 1999 *************** *** 7,13 **** # linker library options # # default(SunOS 4.1.1-JL 1 sun4c) ! LIBS= -lresolv # SunOS 5.5 Generic sun4c sparc # LIBS= -lnsl -lsocket -lresolv --- 7,13 ---- # linker library options # # default(SunOS 4.1.1-JL 1 sun4c) ! # LIBS= -lresolv # SunOS 5.5 Generic sun4c sparc # LIBS= -lnsl -lsocket -lresolv diff -P -c httpdown313/http.cc httpdown313-hacked/http.cc *** httpdown313/http.cc Thu May 15 12:09:04 1997 --- httpdown313-hacked/http.cc Mon Nov 1 15:02:26 1999 *************** *** 121,129 **** char *p; if(size==0) return 0; p=strstr(buff,cl); ! char *b=BodyOf(buff); if(p==NULL) return 0; p+=strlen(cl); --- 121,130 ---- char *p; if(size==0) return 0; p=strstr(buff,cl); ! // char *b=BodyOf(buff); if(p==NULL) return 0; + char *b=BodyOf(p); p+=strlen(cl); *************** *** 135,146 **** // Body の頭をさがす if(b==NULL) return 0; ! c= *b; *b='\0'; int hh=strlen(buff); *b=c; ! ! // printf("(Content-Length: %d at %d) ",ll,hh); return ll+hh; } --- 136,148 ---- // Body の頭をさがす if(b==NULL) return 0; ! c= *b; //退避してますな *b='\0'; int hh=strlen(buff); *b=c; ! #ifdef DEBUG ! printf("(Content-Length: %d at %d) ",ll,hh); ! #endif return ll+hh; } diff -P -c httpdown313/httpdown.cc httpdown313-hacked/httpdown.cc *** httpdown313/httpdown.cc Wed Jan 15 14:04:13 1997 --- httpdown313-hacked/httpdown.cc Sat Nov 13 16:06:21 1999 *************** *** 10,15 **** --- 10,17 ---- // 必要なら加えて下さい // #include + #define DEFAULT_SLEEP_TIME 10 + #ifdef __SUNPRO_CC #include #endif *************** *** 20,25 **** --- 22,33 ---- Matching SaveMatch; Matching URLMatch; + // 991031 + u_int SleepTime=0; + #define MinSleepTime 0 + size_t DefaultLimit=524288; // 必要に応じて変更してください(管理者向け) + size_t TransferLimit=0; + size_t Transferd=0; inline char *nowtime(void) { *************** *** 78,84 **** char buff[1024],combuff[30]; char url[1024]; ! int l; while(!feof(fp)) { --- 86,92 ---- char buff[1024],combuff[30]; char url[1024]; ! long l; while(!feof(fp)) { *************** *** 166,171 **** --- 174,203 ---- continue; } + // 991031 追加 by fkz + if(strcmp(combuff,"sleep")==0) // sleep time + { + if(sscanf(buff,"%s %d",combuff,&l)==2){ + if(l >= MinSleepTime) + SleepTime=(u_int)l; + } + continue; + } + + if(strcmp(combuff,"defaultlimit")==0) // 転送量上限のデフォルト + { + if(sscanf(buff,"%s %ld",combuff,&l)==2) + DefaultLimit=l; + continue; + } + if(strcmp(combuff,"transferlimit")==0) // 転送量上限 + { + if(sscanf(buff,"%s %ld",combuff,&l)==2) + TransferLimit=l; + continue; + } + + // ここまで 991031 // 旧式の設定様式 switch(buff[0]) { *************** *** 276,282 **** void Help(void) { ! puts("\nhttpdown ver 3.12"); puts(" file recursive down loader via http or ftp"); puts("\nHttpdown usage:"); puts(" httpdown definition-file\n"); --- 308,314 ---- void Help(void) { ! puts("\nhttpdown ver 3.12 + fkz-patch 0.004"); puts(" file recursive down loader via http or ftp"); puts("\nHttpdown usage:"); puts(" httpdown definition-file\n"); *************** *** 291,296 **** --- 323,332 ---- puts("httpproxy proxy : proxy server for http"); puts("ftpproxy proxy : proxy server for ftp"); + puts("sleep TIME : transfer interval"); + puts("defaultlimit SIZE : transfer limit for .httpdownrc"); + puts("transferlimit SIZE: transfer limit"); + puts("r URL : rejection URL(not transfered)"); puts("other type of lines are ignored.\n"); puts("try also 'man httpdown'\n"); *************** *** 447,454 **** { // 末端として処理済 AddSData(url,URLTerminated); } free(content); ! // sleep(1); // あまりに早い転送を抑制 } if(Termination) break; --- 483,508 ---- { // 末端として処理済 AddSData(url,URLTerminated); } + // 991031 + #ifdef DEBUG + printf("size= %d \n",size); + #endif + Transferd += size; + // 991031 転送量の上限に達したか? + if((TransferLimit==0) && (DefaultLimit==0)){ + // なんもしない + }else{ + if((TransferLimit != 0) && (Transferd >= TransferLimit)){ + // transferlimitが指定されている場合 + Termination=1; + }else if((Transferd >= DefaultLimit) && (TransferLimit==0)){ + // defaultlimitのみ指定されている場合 + Termination=1; + } + } + // ここまで 991031 free(content); ! sleep(SleepTime); // あまりに早い転送を抑制 } if(Termination) break; *************** *** 583,588 **** --- 637,643 ---- } int level=5; + SleepTime = DEFAULT_SLEEP_TIME; // 初期化ファイルの読み込み LoadDefaultDefinition(level); diff -P -c httpdown313/readme.hack.euc httpdown313-hacked/readme.hack.euc *** httpdown313/readme.hack.euc Thu Jan 1 09:00:00 1970 --- httpdown313-hacked/readme.hack.euc Mon Nov 1 23:30:40 1999 *************** *** 0 **** --- 1,29 ---- + ・反省を込めて追加した機能 + httpdownは便利ですが、うっかり使うと目的のサイトやネットワークに + 多大な負荷をかけ、いろいろな方に迷惑をかけてしまいます。私も + うっかりな設定のまま使って迷惑をかけてしまった経験があるので、 + 反省の意味を込めてささやかながらフェイルセーフ機能を追加してみました。 + + ただし、.httpdownrcと定義ファイルにのみ有効で、コマンドラインからの + 入力には対応させていないのでご注意下さい。 + + sleep SECOND ファイルを取得したあと、SECOND秒待ちます + defaultlimit LIMITSIZE 転送量がLIMITSIZEに達したら止めます。 + transferlimit LIMITSIZE defaultlimitと同じく、LIMITSIZEに達したら転送を + 終了します。ただし、defaultlimitより優先されます。.httpdownrcに + defaultlimitを書いて、個別の定義ファイルにtransferlimitを書く、 + という使用法を想定しています。 + + ・その他、手をいれたところ +  proxyサーバとhttpdの相性が悪いことがあるのか、HTTPヘッダの + 改行コードが1行目とそれ以降で違うことがありました。httpdownでは + 一行目の改行コードを読んでそれに合わせているのですが、そのときは + 一行目だけLFであとはCR+LFなんていうことになっていました。そこで + Content-length:行を優先して確認するように変更させてもらいました。 + + ・使い方 + patch -p1 < patch-aa + 必要に応じてMinSleepTimeとDefaultLimitを変更して下さい。 + + fkz@pluto.dti.ne.jp + 19991101