~ubuntu-branches/ubuntu/maverick/curl/maverick

« back to all changes in this revision

Viewing changes to lib/hostip.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2008-06-18 15:21:57 UTC
  • mto: (3.1.1 lenny) (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20080618152157-j8b12047aqcl6kii
Tags: upstream-7.18.2
ImportĀ upstreamĀ versionĀ 7.18.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
 * KIND, either express or implied.
20
20
 *
21
 
 * $Id: hostip.c,v 1.190 2008-01-15 22:44:12 bagder Exp $
 
21
 * $Id: hostip.c,v 1.191 2008-03-11 22:55:24 bagder Exp $
22
22
 ***************************************************************************/
23
23
 
24
24
#include "setup.h"
268
268
    Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
269
269
}
270
270
 
 
271
/*
 
272
 * Check if the entry should be pruned. Assumes a locked cache.
 
273
 */
271
274
static int
272
275
remove_entry_if_stale(struct SessionHandle *data, struct Curl_dns_entry *dns)
273
276
{
284
287
  if( !hostcache_timestamp_remove(&user,dns) )
285
288
    return 0;
286
289
 
287
 
  /* ok, we do need to clear the cache. although we need to remove just a
288
 
     single entry we clean the entire hash, as no explicit delete function
289
 
     is provided */
290
 
  if(data->share)
291
 
    Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
292
 
 
293
290
  Curl_hash_clean_with_criterium(data->dns.hostcache,
294
291
                                 (void *) &user,
295
292
                                 hostcache_timestamp_remove);
296
293
 
297
 
  if(data->share)
298
 
    Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
299
 
 
300
294
  return 1;
301
295
}
302
296
 
397
391
  size_t entry_len;
398
392
  struct SessionHandle *data = conn->data;
399
393
  CURLcode result;
400
 
  int rc;
 
394
  int rc = CURLRESOLV_ERROR; /* default to failure */
401
395
  *entry = NULL;
402
396
 
403
397
#ifdef HAVE_SIGSETJMP
407
401
    if(sigsetjmp(curl_jmpenv, 1)) {
408
402
      /* this is coming from a siglongjmp() */
409
403
      failf(data, "name lookup timed out");
410
 
      return CURLRESOLV_ERROR;
 
404
      return rc;
411
405
    }
412
406
  }
413
407
#endif
416
410
  entry_id = create_hostcache_id(hostname, port);
417
411
  /* If we can't create the entry id, fail */
418
412
  if(!entry_id)
419
 
    return CURLRESOLV_ERROR;
 
413
    return rc;
420
414
 
421
415
  entry_len = strlen(entry_id);
422
416
 
426
420
  /* See if its already in our dns cache */
427
421
  dns = Curl_hash_pick(data->dns.hostcache, entry_id, entry_len+1);
428
422
 
429
 
  if(data->share)
430
 
    Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
431
 
 
432
 
  /* free the allocated entry_id again */
433
 
  free(entry_id);
434
 
 
435
 
  /* See whether the returned entry is stale. Deliberately done after the
436
 
     locked block */
437
 
  if( remove_entry_if_stale(data,dns) )
 
423
  /* See whether the returned entry is stale. Done before we release lock */
 
424
  if( remove_entry_if_stale(data, dns) )
438
425
    dns = NULL; /* the memory deallocation is being handled by the hash */
439
426
 
440
 
  rc = CURLRESOLV_ERROR; /* default to failure */
 
427
  if(dns) {
 
428
    dns->inuse++; /* we use it! */
 
429
    rc = CURLRESOLV_RESOLVED;
 
430
  }
 
431
 
 
432
  if(data->share)
 
433
    Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
 
434
 
 
435
  /* free the allocated entry_id again */
 
436
  free(entry_id);
441
437
 
442
438
  if(!dns) {
443
439
    /* The entry was not in the cache. Resolve it to IP address */
486
482
        rc = CURLRESOLV_RESOLVED;
487
483
    }
488
484
  }
489
 
  else {
490
 
    if(data->share)
491
 
      Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
492
 
    dns->inuse++; /* we use it! */
493
 
    if(data->share)
494
 
      Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
495
 
    rc = CURLRESOLV_RESOLVED;
496
 
  }
497
485
 
498
486
  *entry = dns;
499
487