1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

[svn] Added user-contributed patches.

This commit is contained in:
hniksic 2000-03-02 06:16:12 -08:00
parent 18959ba4ab
commit 2b2fd2924a
6 changed files with 78 additions and 11 deletions

View File

@ -1,3 +1,14 @@
1999-09-17 Dan Berger <dberger@ix.netcom.com>
* http.c (gethttp): Send it.
* url.c (parseurl): Detect query string in HTTP URL-s.
(str_url): Print it.
2000-03-02 HIROSE Masaaki <hirose31@t3.rim.or.jp>
* html.c (html_allow): Add <link href=...> and <script src=...>.
1999-05-02 andrew deryabin <djsf@softhome.net> 1999-05-02 andrew deryabin <djsf@softhome.net>
* http.c (gethttp): Specify port in `Host' header only if it's * http.c (gethttp): Specify port in `Host' header only if it's

View File

@ -77,6 +77,8 @@ htmlfindurl (const char *buf, int bufsize, int *size, int init)
follow -- feel free to edit to suit your needs: */ follow -- feel free to edit to suit your needs: */
static struct tag_attr html_allow[] = { static struct tag_attr html_allow[] = {
{ "a", "href" }, { "a", "href" },
{ "link", "href" },
{ "script", "src" },
{ "img", "src" }, { "img", "src" },
{ "img", "href" }, { "img", "href" },
{ "body", "background" }, { "body", "background" },

View File

@ -303,7 +303,7 @@ static time_t http_atotm PARAMS ((char *));
static uerr_t static uerr_t
gethttp (struct urlinfo *u, struct http_stat *hs, int *dt) gethttp (struct urlinfo *u, struct http_stat *hs, int *dt)
{ {
char *request, *type, *command, *path; char *request, *type, *command, *path, *qstring;
char *user, *passwd; char *user, *passwd;
char *pragma_h, *referer, *useragent, *range, *wwwauth, *remhost; char *pragma_h, *referer, *useragent, *range, *wwwauth, *remhost;
char *authenticate_h; char *authenticate_h;
@ -384,6 +384,9 @@ gethttp (struct urlinfo *u, struct http_stat *hs, int *dt)
path = u->proxy->url; path = u->proxy->url;
else else
path = u->path; path = u->path;
qstring = u->qstring;
command = (*dt & HEAD_ONLY) ? "HEAD" : "GET"; command = (*dt & HEAD_ONLY) ? "HEAD" : "GET";
referer = NULL; referer = NULL;
if (ou->referer) if (ou->referer)
@ -467,6 +470,7 @@ gethttp (struct urlinfo *u, struct http_stat *hs, int *dt)
/* Allocate the memory for the request. */ /* Allocate the memory for the request. */
request = (char *)alloca (strlen (command) + strlen (path) request = (char *)alloca (strlen (command) + strlen (path)
+ (qstring ? strlen (qstring) : 0)
+ strlen (useragent) + strlen (useragent)
+ strlen (remhost) + host_port_len + strlen (remhost) + host_port_len
+ strlen (HTTP_ACCEPT) + strlen (HTTP_ACCEPT)
@ -479,12 +483,12 @@ gethttp (struct urlinfo *u, struct http_stat *hs, int *dt)
+ 64); + 64);
/* Construct the request. */ /* Construct the request. */
sprintf (request, "\ sprintf (request, "\
%s %s HTTP/1.0\r\n\ %s %s%s HTTP/1.0\r\n\
User-Agent: %s\r\n\ User-Agent: %s\r\n\
Host: %s%s\r\n\ Host: %s%s\r\n\
Accept: %s\r\n\ Accept: %s\r\n\
%s%s%s%s%s%s\r\n", %s%s%s%s%s%s\r\n",
command, path, useragent, remhost, host_port ? host_port : "", command, path, qstring, useragent, remhost, host_port ? host_port : "",
HTTP_ACCEPT, referer ? referer : "", HTTP_ACCEPT, referer ? referer : "",
wwwauth ? wwwauth : "", wwwauth ? wwwauth : "",
proxyauth ? proxyauth : "", proxyauth ? proxyauth : "",

View File

@ -226,6 +226,16 @@ maybe_add_to_list (acc_t **newentry, acc_t **list)
return; return;
} }
/* Helper function for the parser, shifts contents of
null-terminated string once character to the left.
Used in processing \ and " constructs in the netrc file */
static void
shift_left(char *string){
char *p;
for (p=string; *p; ++p)
*p = *(p+1);
}
/* Parse a .netrc file (as described in the ftp(1) manual page). */ /* Parse a .netrc file (as described in the ftp(1) manual page). */
static acc_t * static acc_t *
@ -234,7 +244,7 @@ parse_netrc (const char *path)
FILE *fp; FILE *fp;
char *line, *p, *tok, *premature_token; char *line, *p, *tok, *premature_token;
acc_t *current, *retval; acc_t *current, *retval;
int ln; int ln, quote;
/* The latest token we've seen in the file. */ /* The latest token we've seen in the file. */
enum enum
@ -263,6 +273,7 @@ parse_netrc (const char *path)
/* Parse the line. */ /* Parse the line. */
p = line; p = line;
quote = 0;
/* If the line is empty, then end any macro definition. */ /* If the line is empty, then end any macro definition. */
if (last_token == tok_macdef && !*p) if (last_token == tok_macdef && !*p)
@ -280,11 +291,25 @@ parse_netrc (const char *path)
if (*p == '#') if (*p == '#')
break; break;
/* If the token starts with quotation mark, note this fact,
and squash the quotation character */
if (*p == '"'){
quote = 1;
shift_left (p);
}
tok = p; tok = p;
/* Find the end of the token. */ /* Find the end of the token, handling quotes and escapes. */
while (*p && !ISSPACE (*p)) while (*p && (quote ? *p != '"' : !ISSPACE (*p))){
if (*p == '\\')
shift_left (p);
p ++; p ++;
}
/* if field was quoted, squash the trailing quotation mark */
if (quote)
shift_left(p);
/* Null-terminate the token, if it isn't already. */ /* Null-terminate the token, if it isn't already. */
if (*p) if (*p)

View File

@ -458,8 +458,23 @@ parseurl (const char *url, struct urlinfo *u, int strict)
if (type == URLHTTP) if (type == URLHTTP)
while (url[i] && url[i] == '/') while (url[i] && url[i] == '/')
++i; ++i;
u->path = (char *)xmalloc (strlen (url + i) + 8);
strcpy (u->path, url + i); /* dfb: break "path" into "path" and "qstring" if the URL is HTTP
if it's not an HTTP url, set l to the last character, so the
xmalloc and strncpy work as desired */
if (type == URLHTTP) {
for (l = i; url[l] && url[l] != '?'; l++);
if (l != strlen(url)) {
/* copy the query string, including the '?' into u->qstring */
u->qstring = (char *)xmalloc (strlen (url + l) + 8);
strcpy (u->qstring, url + l);
}
} else {
l = strlen(url);
}
u->path = strdupdelim (url + i, url + l);
if (type == URLFTP) if (type == URLFTP)
{ {
u->ftp_type = process_ftp_type (u->path); u->ftp_type = process_ftp_type (u->path);
@ -480,6 +495,8 @@ parseurl (const char *url, struct urlinfo *u, int strict)
/* Parse the directory. */ /* Parse the directory. */
parse_dir (u->path, &u->dir, &u->file); parse_dir (u->path, &u->dir, &u->file);
DEBUGP (("dir %s -> file %s -> ", u->dir, u->file)); DEBUGP (("dir %s -> file %s -> ", u->dir, u->file));
if (type == URLHTTP && u->qstring)
DEBUGP (("query-string %s -> ", u->qstring));
/* Simplify the directory. */ /* Simplify the directory. */
path_simplify (u->dir); path_simplify (u->dir);
/* Remove the leading `/' in HTTP. */ /* Remove the leading `/' in HTTP. */
@ -626,7 +643,7 @@ char *
str_url (const struct urlinfo *u, int hide) str_url (const struct urlinfo *u, int hide)
{ {
char *res, *host, *user, *passwd, *proto_name, *dir, *file; char *res, *host, *user, *passwd, *proto_name, *dir, *file;
int i, l, ln, lu, lh, lp, lf, ld; int i, l, ln, lu, lh, lp, lf, ld, lq;
/* Look for the protocol name. */ /* Look for the protocol name. */
for (i = 0; i < ARRAY_SIZE (sup_protos); i++) for (i = 0; i < ARRAY_SIZE (sup_protos); i++)
@ -667,7 +684,8 @@ str_url (const struct urlinfo *u, int hide)
lh = strlen (host); lh = strlen (host);
ld = strlen (dir); ld = strlen (dir);
lf = strlen (file); lf = strlen (file);
res = (char *)xmalloc (ln + lu + lp + lh + ld + lf + 20); /* safe sex */ lq = (u->proto == URLHTTP && u->qstring) ? strlen (u->qstring) : 0;
res = (char *)xmalloc (ln + lu + lp + lh + ld + lf + lq + 20); /* safe sex */
/* sprintf (res, "%s%s%s%s%s%s:%d/%s%s%s", proto_name, /* sprintf (res, "%s%s%s%s%s%s:%d/%s%s%s", proto_name,
(user ? user : ""), (passwd ? ":" : ""), (user ? user : ""), (passwd ? ":" : ""),
(passwd ? passwd : ""), (user ? "@" : ""), (passwd ? passwd : ""), (user ? "@" : ""),
@ -698,9 +716,15 @@ str_url (const struct urlinfo *u, int hide)
if (*dir) if (*dir)
res[l++] = '/'; res[l++] = '/';
strcpy (res + l, file); strcpy (res + l, file);
l += lf;
free (host); free (host);
free (dir); free (dir);
free (file); free (file);
if (u->qstring)
{
/* copy in the raw query string to avoid munging arguments */
memcpy (res + l, u->qstring, lq);
}
FREE_MAYBE (user); FREE_MAYBE (user);
FREE_MAYBE (passwd); FREE_MAYBE (passwd);
return res; return res;

View File

@ -32,7 +32,8 @@ struct urlinfo
char *host; /* Extracted hostname */ char *host; /* Extracted hostname */
unsigned short port; unsigned short port;
char ftp_type; char ftp_type;
char *path, *dir, *file; /* Path, as well as dir and file char *path, *dir, *file, *qstring;
/* Path, dir, file, and query string
(properly decoded) */ (properly decoded) */
char *user, *passwd; /* Username and password */ char *user, *passwd; /* Username and password */
struct urlinfo *proxy; /* The exact string to pass to proxy struct urlinfo *proxy; /* The exact string to pass to proxy