~ubuntu-branches/ubuntu/lucid/wget/lucid-security

« back to all changes in this revision

Viewing changes to src/res.c

  • Committer: Bazaar Package Importer
  • Author(s): Marc Deslauriers
  • Date: 2009-12-12 08:15:59 UTC
  • mfrom: (2.1.5 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091212081559-mvccl4kzdqb138y3
Tags: 1.12-1.1ubuntu1
* Merge from debian testing, remaining changes:
  - Add wget-udeb to ship wget.gnu as alternative to busybox wget
    implementation.
* Keep build dependencies in main:
  - debian/control: remove info2man build-dep
  - debian/patches/00list: disable wget-infopod_generated_manpage.dpatch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Support for Robot Exclusion Standard (RES).
2
 
   Copyright (C) 2001, 2006, 2007, 2008 Free Software Foundation, Inc.
 
2
   Copyright (C) 2001, 2006, 2007, 2008, 2009 Free Software Foundation,
 
3
   Inc.
3
4
 
4
5
This file is part of Wget.
5
6
 
67
68
   res_match_path, res_register_specs, res_get_specs, and
68
69
   res_retrieve_file.  */
69
70
 
70
 
#ifdef HAVE_CONFIG_H
71
 
# include <config.h>
72
 
#endif
 
71
#include "wget.h"
73
72
 
74
73
#include <stdio.h>
75
74
#include <stdlib.h>
77
76
#include <errno.h>
78
77
#include <assert.h>
79
78
 
80
 
#include "wget.h"
81
79
#include "utils.h"
82
80
#include "hash.h"
83
81
#include "url.h"
181
179
#define EOL(p) ((p) >= lineend)
182
180
 
183
181
#define SKIP_SPACE(p) do {              \
184
 
  while (!EOL (p) && ISSPACE (*p))      \
 
182
  while (!EOL (p) && c_isspace (*p))      \
185
183
    ++p;                                \
186
184
} while (0)
187
185
 
267
265
         lineend to a location preceding the first comment.  Real line
268
266
         ending remains in lineend_real.  */
269
267
      for (lineend = p; lineend < lineend_real; lineend++)
270
 
        if ((lineend == p || ISSPACE (*(lineend - 1)))
 
268
        if ((lineend == p || c_isspace (*(lineend - 1)))
271
269
            && *lineend == '#')
272
270
          break;
273
271
 
274
272
      /* Ignore trailing whitespace in the same way. */
275
 
      while (lineend > p && ISSPACE (*(lineend - 1)))
 
273
      while (lineend > p && c_isspace (*(lineend - 1)))
276
274
        --lineend;
277
275
 
278
276
      assert (!EOL (p));
279
277
 
280
278
      field_b = p;
281
 
      while (!EOL (p) && (ISALNUM (*p) || *p == '-'))
 
279
      while (!EOL (p) && (c_isalnum (*p) || *p == '-'))
282
280
        ++p;
283
281
      field_e = p;
284
282
 
416
414
   advance the pointer.  */
417
415
 
418
416
#define DECODE_MAYBE(c, ptr) do {                               \
419
 
  if (c == '%' && ISXDIGIT (ptr[1]) && ISXDIGIT (ptr[2]))       \
 
417
  if (c == '%' && c_isxdigit (ptr[1]) && c_isxdigit (ptr[2]))       \
420
418
    {                                                           \
421
419
      char decoded = X2DIGITS_TO_NUM (ptr[1], ptr[2]);          \
422
420
      if (decoded != '/')                                       \
466
464
    if (matches (specs->paths[i].path, path))
467
465
      {
468
466
        bool allowedp = specs->paths[i].allowedp;
469
 
        DEBUGP (("%s path %s because of rule `%s'.\n",
 
467
        DEBUGP (("%s path %s because of rule %s.\n",
470
468
                 allowedp ? "Allowing" : "Rejecting",
471
 
                 path, specs->paths[i].path));
 
469
                 path, quote (specs->paths[i].path)));
472
470
        return allowedp;
473
471
      }
474
472
  return true;
535
533
   Return true if robots were retrieved OK, false otherwise.  */
536
534
 
537
535
bool
538
 
res_retrieve_file (const char *url, char **file)
 
536
res_retrieve_file (const char *url, char **file, struct iri *iri)
539
537
{
 
538
  struct iri *i = iri_new ();
540
539
  uerr_t err;
541
540
  char *robots_url = uri_merge (url, RES_SPECS_LOCATION);
542
541
  int saved_ts_val = opt.timestamping;
543
 
  int saved_sp_val = opt.spider;
 
542
  int saved_sp_val = opt.spider, url_err;
 
543
  struct url * url_parsed;
 
544
 
 
545
  /* Copy server URI encoding for a possible IDNA transformation, no need to
 
546
     encode the full URI in UTF-8 because "robots.txt" is plain ASCII */
 
547
  set_uri_encoding (i, iri->uri_encoding, false);
 
548
  i->utf8_encode = false;
544
549
 
545
550
  logputs (LOG_VERBOSE, _("Loading robots.txt; please ignore errors.\n"));
546
551
  *file = NULL;
547
552
  opt.timestamping = false;
548
553
  opt.spider       = false;
549
 
  err = retrieve_url (robots_url, file, NULL, NULL, NULL, false);
 
554
 
 
555
  url_parsed = url_parse (robots_url, &url_err, iri, true);
 
556
  if (!url_parsed)
 
557
    {
 
558
      char *error = url_error (robots_url, url_err);
 
559
      logprintf (LOG_NOTQUIET, "%s: %s.\n", robots_url, error);
 
560
      xfree (error);
 
561
      err = URLERROR;
 
562
    }
 
563
  else
 
564
    {
 
565
      err = retrieve_url (url_parsed, robots_url, file, NULL, NULL, NULL,
 
566
                          false, i, false);
 
567
      url_free(url_parsed);
 
568
    }
 
569
 
550
570
  opt.timestamping = saved_ts_val;
551
 
  opt.spider       = saved_sp_val;  
 
571
  opt.spider       = saved_sp_val;
552
572
  xfree (robots_url);
 
573
  iri_free (i);
553
574
 
554
575
  if (err != RETROK && *file != NULL)
555
576
    {
569
590
  bool ret = are_urls_equal (url, robots_url);
570
591
 
571
592
  xfree (robots_url);
572
 
  
 
593
 
573
594
  return ret;
574
595
}
575
596
 
605
626
    { "http://www.yoyodyne.com/somepath/", false },
606
627
    { "http://www.yoyodyne.com/somepath/robots.txt", false },
607
628
  };
608
 
  
609
 
  for (i = 0; i < sizeof(test_array)/sizeof(test_array[0]); ++i) 
 
629
 
 
630
  for (i = 0; i < sizeof(test_array)/sizeof(test_array[0]); ++i)
610
631
    {
611
 
      mu_assert ("test_is_robots_txt_url: wrong result", 
 
632
      mu_assert ("test_is_robots_txt_url: wrong result",
612
633
                 is_robots_txt_url (test_array[i].url) == test_array[i].expected_result);
613
634
    }
614
635