lftp/lftp-3.3.5-bz173276.patch

164 lines
5.0 KiB
Diff
Raw Normal View History

--- lftp-3.3.5/doc/lftp.1.bz173276 2005-12-02 02:23:31.000000000 -0500
+++ lftp-3.3.5/doc/lftp.1 2005-12-16 20:07:19.000000000 -0500
@@ -919,6 +919,27 @@
.BR dns:use-fork \ (boolean)
if true, lftp will fork before resolving host address. Default is true.
.TP
+.BR dns:use-first-address \ (boolean)
+If true (the default), lftp will use the first address returned by a host name lookup;
+if false, lftp will continue trying to find addresses of each address family
+in dns:order until an address of each family is found, is authoritatively
+known not to exist (as opposed to servers not being contactable), or the
+dns:fatal-timeout (if any) expires.
+Setting this to true will make lftp use the first available address for a name.
+.TP
+.BR dns:try-again \ (boolean)
+If true (the default), lftp will continue to try to lookup a dns name while
+no servers are contactable, until the dns-fatal-timeout expires or an address
+is found (of each family in dns:order if dns:use-first-address is false).
+If false, lftp will not retry dns name lookups .
+.TP
+.BR dns:n-attempts \ (number)
+If zero, (the default), there is no limit on the number of times lftp will try
+to lookup an address if dns:try-again is true.
+If > 0, lftp will try only this number of times to look up an address of each
+address family in dns:order .
+If dns:try-again is not true, this variable has no effect.
+.TP
.BR file:charset \ (string)
local character set. It is set from current locale initially.
.TP
--- lftp-3.3.5/src/resource.cc.bz173276 2005-11-08 02:21:19.000000000 -0500
+++ lftp-3.3.5/src/resource.cc 2005-12-16 20:02:48.000000000 -0500
@@ -341,7 +341,10 @@
res_timeout ("dns:fatal-timeout","0", ResMgr::UNumberValidate,0),
res_order ("dns:order", DEFAULT_ORDER, OrderValidate,0),
res_query_srv ("dns:SRV-query", "no", ResMgr::BoolValidate,0),
- res_use_fork ("dns:use-fork", "yes", ResMgr::BoolValidate,ResMgr::NoClosure);
+ res_use_fork ("dns:use-fork", "yes", ResMgr::BoolValidate,ResMgr::NoClosure),
+ res_use_first ("dns:use-first-address", "yes", ResMgr::BoolValidate,ResMgr::NoClosure),
+ res_try_again ("dns:try-again", "yes", ResMgr::BoolValidate,ResMgr::NoClosure),
+ res_n_attempts ("dns:n-attempts", "0", ResMgr::UNumberValidate,ResMgr::NoClosure);
static ResDecl
fish_shell ("fish:shell", "/bin/sh", 0,0),
--- lftp-3.3.5/src/Resolver.cc.bz173276 2005-11-08 01:17:11.000000000 -0500
+++ lftp-3.3.5/src/Resolver.cc 2005-12-16 20:20:09.000000000 -0500
@@ -682,6 +682,11 @@
time_t try_time;
int af_index=0;
int af_order[16];
+ int af_tries[16];
+ int af_try=0, af_tried=-1, try_afs_again=0;
+ int dns_use_first =ResMgr::QueryBool("dns:use-first-address",0),
+ dns_n_attempts=ResMgr::Query("dns:n-attempts",0),
+ dns_try_again =ResMgr::QueryBool("dns:try-again",0);
const char *order=ResMgr::Query("dns:order",name);
@@ -698,6 +703,8 @@
}
ParseOrder(order,af_order);
+
+ memset(af_tries, 0, sizeof(af_tries));
for(;;)
{
@@ -778,8 +785,32 @@
#else // !HAVE_GETADDRINFO
int af=af_order[af_index];
+
if(af==-1)
- break;
+ {
+ if( (timeout == 0)
+ && (dns_try_again == 0)
+ && ((dns_n_attempts == 0) || (af_tried == 0))
+ )
+ break;
+ else
+ { /* tried all afs at least once */
+ if( ( dns_try_again == 0 ) || (try_afs_again == 0))
+ break;
+
+ af_index = 0;
+ af = af_order[af_index];
+ af_tried = 0;
+ try_afs_again = 0;
+ }
+ }
+
+ if ( af_tries [ af_index ] != -1 )
+ {
+ af_tries[ af_index ]++;
+
+ if( (dns_n_attempts > 0) && ( af_tries [ af_index ] > dns_n_attempts) )
+ break;
struct hostent *ha;
# if defined(HAVE_GETIPNODEBYNAME)
@@ -801,12 +832,19 @@
}
# endif
- if(ha)
+ af_tried = 1;
+
+ if ( ha )
{
const char * const *a;
for(a=ha->h_addr_list; *a; a++)
- AddAddress(ha->h_addrtype, *a, ha->h_length);
- af_index++;
+ {
+ AddAddress(ha->h_addrtype, *a, ha->h_length);
+ af_tries[ af_index ] = -1;
+ if ( dns_use_first )
+ return;
+ }
+ af_index++;
# if defined(HAVE_GETIPNODEBYNAME)
freehostent(ha);
# endif
@@ -825,14 +863,33 @@
error=_("Host name lookup failure");
# endif
}
- af_index++;
- continue; // try other address families
+ af_tries[ af_index ] = -1;
}
+ } /* af_tries[ af_index ] != -1 */
+
+ if( af_tries[ af_index ] != -1 )
+ try_afs_again = 1;
+
#endif /* HAVE_GETADDRINFO */
- time_t t;
- if((t=time(0))-try_time<5)
- sleep(5-(t-try_time));
+ time_t t = time(0);
+ if( timeout && (( t - start_time ) >= (timeout - 1)) )
+ {
+ return;
+ }else
+ {
+ af_try = (af_order[af_index+1] == -1) ? 0 : ((af_index + 1) & 0xf);
+ if( (af_tries[ af_try ] != 0) || (af_tried == 0))
+ {
+ if( timeout == 0 )
+ {
+ if((t-try_time)<5)
+ sleep(5-(t-try_time));
+ }else
+ sleep(1);
+ }
+ af_index++;
+ }
}
}