~ubuntu-branches/ubuntu/precise/wget/precise-proposed

« back to all changes in this revision

Viewing changes to src/convert.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-10-19 00:00:09 UTC
  • mfrom: (2.1.13 sid)
  • Revision ID: james.westby@ubuntu.com-20111019000009-8p33w3wz4b1rdri0
Tags: 1.13-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add wget-udeb to ship wget.gnu as alternative to busybox wget
    implementation.
  - Depend on libssl-dev 0.9.8k-7ubuntu4 (LP: #503339)
* Dropped changes, superseded in Debian:
  - Keep build dependencies in main:
    + debian/control: remove info2man build-dep
    + debian/patches/series: disable wget-infopod_generated_manpage
  - Mark wget Multi-Arch: foreign, so packages that aren't of the same arch
    can depend on it.
* Pass --with-ssl=openssl; we don't want to use gnutls, there's no udeb for
  it.
* Add a second build pass for the udeb, so we can build without libidn.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Conversion of links to local files.
2
 
   Copyright (C) 2003, 2004, 2005, 2006, 2007,
3
 
   2008, 2009 Free Software Foundation, Inc.
 
2
   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
 
3
   Free Software Foundation, Inc.
4
4
 
5
5
This file is part of GNU Wget.
6
6
 
33
33
#include <stdio.h>
34
34
#include <stdlib.h>
35
35
#include <string.h>
36
 
#ifdef HAVE_UNISTD_H
37
 
# include <unistd.h>
38
 
#endif /* HAVE_UNISTD_H */
 
36
#include <unistd.h>
39
37
#include <errno.h>
40
38
#include <assert.h>
41
39
#include "convert.h"
47
45
#include "res.h"
48
46
#include "html-url.h"
49
47
#include "css-url.h"
 
48
#include "iri.h"
50
49
 
51
50
static struct hash_table *dl_file_url_map;
52
51
struct hash_table *dl_url_file_map;
105
104
      for (cur_url = urls; cur_url; cur_url = cur_url->next)
106
105
        {
107
106
          char *local_name;
108
 
          struct url *u = cur_url->url;
 
107
          struct url *u;
 
108
          struct iri *pi;
109
109
 
110
110
          if (cur_url->link_base_p)
111
111
            {
119
119
          /* We decide the direction of conversion according to whether
120
120
             a URL was downloaded.  Downloaded URLs will be converted
121
121
             ABS2REL, whereas non-downloaded will be converted REL2ABS.  */
 
122
 
 
123
          pi = iri_new ();
 
124
          set_uri_encoding (pi, opt.locale, true);
 
125
 
 
126
          u = url_parse (cur_url->url->url, NULL, pi, true);
122
127
          local_name = hash_table_get (dl_url_file_map, u->url);
123
128
 
124
129
          /* Decide on the conversion type.  */
144
149
              cur_url->local_name = NULL;
145
150
              DEBUGP (("will convert url %s to complete\n", u->url));
146
151
            }
 
152
 
 
153
          url_free (u);
 
154
          iri_free (pi);
147
155
        }
148
156
 
149
157
      /* Convert the links in the file.  */
193
201
static const char *replace_attr (const char *, int, FILE *, const char *);
194
202
static const char *replace_attr_refresh_hack (const char *, int, FILE *,
195
203
                                              const char *, int);
196
 
static char *local_quote_string (const char *);
 
204
static char *local_quote_string (const char *, bool);
197
205
static char *construct_relative (const char *, const char *);
198
206
 
199
207
/* Change the links in one file.  LINKS is a list of links in the
228
236
      }
229
237
  }
230
238
 
231
 
  fm = read_file (file);
 
239
  fm = wget_read_file (file);
232
240
  if (!fm)
233
241
    {
234
242
      logprintf (LOG_NOTQUIET, _("Cannot convert links in %s: %s\n"),
248
256
    {
249
257
      logprintf (LOG_NOTQUIET, _("Unable to delete %s: %s\n"),
250
258
                 quote (file), strerror (errno));
251
 
      read_file_free (fm);
 
259
      wget_read_file_free (fm);
252
260
      return;
253
261
    }
254
262
  /* Now open the file for writing.  */
257
265
    {
258
266
      logprintf (LOG_NOTQUIET, _("Cannot convert links in %s: %s\n"),
259
267
                 file, strerror (errno));
260
 
      read_file_free (fm);
 
268
      wget_read_file_free (fm);
261
269
      return;
262
270
    }
263
271
 
291
299
          /* Convert absolute URL to relative. */
292
300
          {
293
301
            char *newname = construct_relative (file, link->local_name);
294
 
            char *quoted_newname = local_quote_string (newname);
 
302
            char *quoted_newname = local_quote_string (newname,
 
303
                                                       link->link_css_p);
295
304
 
296
305
            if (link->link_css_p)
297
306
              p = replace_plain (p, link->size, fp, quoted_newname);
315
324
            char *quoted_newlink = html_quote_string (newlink);
316
325
 
317
326
            if (link->link_css_p)
318
 
              p = replace_plain (p, link->size, fp, quoted_newlink);
 
327
              p = replace_plain (p, link->size, fp, newlink);
319
328
            else if (!link->link_refresh_p)
320
329
              p = replace_attr (p, link->size, fp, quoted_newlink);
321
330
            else
342
351
  if (p - fm->content < fm->length)
343
352
    fwrite (p, 1, fm->length - (p - fm->content), fp);
344
353
  fclose (fp);
345
 
  read_file_free (fm);
 
354
  wget_read_file_free (fm);
346
355
 
347
356
  logprintf (LOG_VERBOSE, "%d-%d\n", to_file_count, to_url_count);
348
357
}
602
611
   because those characters have special meanings in URLs.  */
603
612
 
604
613
static char *
605
 
local_quote_string (const char *file)
 
614
local_quote_string (const char *file, bool no_html_quote)
606
615
{
607
616
  const char *from;
608
617
  char *newname, *to;
609
618
 
610
619
  char *any = strpbrk (file, "?#%;");
611
620
  if (!any)
612
 
    return html_quote_string (file);
 
621
    return no_html_quote ? strdup (file) : html_quote_string (file);
613
622
 
614
623
  /* Allocate space assuming the worst-case scenario, each character
615
624
     having to be quoted.  */
646
655
      }
647
656
  *to = '\0';
648
657
 
649
 
  return html_quote_string (newname);
 
658
  return no_html_quote ? strdup (newname) : html_quote_string (newname);
650
659
}
651
660
 
652
661
/* Book-keeping code for dl_file_url_map, dl_url_file_map,