mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-11-27 13:32:45 +00:00
MFC: r267131, r267132, r267133, r268493, r268671
Use NULL instead of 0 (Patch by Sascha Wildner <saw at online.de> for Dragonfly) Remove unnecessary semicolons (Patch by Sascha Wildner <saw at online.de> for Dragonfly) Add support for arbitrary http requests [1] Support EAGAIN in fetch_writev Submitted by: Alex Hornung <alex at alexhornung.com> [1] Reviewed by: des
This commit is contained in:
parent
bc8365adf2
commit
525e7e22a1
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/stable/10/; revision=268900
@ -1110,6 +1110,9 @@ fetch_writev(conn_t *conn, struct iovec *iov, int iovcnt)
|
||||
errno = 0;
|
||||
pfd.revents = 0;
|
||||
if (poll(&pfd, 1, deltams) < 0) {
|
||||
/* POSIX compliance */
|
||||
if (errno == EAGAIN)
|
||||
continue;
|
||||
if (errno == EINTR && fetchRestartCalls)
|
||||
continue;
|
||||
return (-1);
|
||||
|
@ -117,6 +117,9 @@ int fetch_no_proxy_match(const char *);
|
||||
*/
|
||||
FILE *http_request(struct url *, const char *,
|
||||
struct url_stat *, struct url *, const char *);
|
||||
FILE *http_request_body(struct url *, const char *,
|
||||
struct url_stat *, struct url *, const char *,
|
||||
const char *, const char *);
|
||||
FILE *ftp_request(struct url *, const char *,
|
||||
struct url_stat *, struct url *, const char *);
|
||||
|
||||
|
@ -102,6 +102,8 @@ FILE *fetchGetHTTP(struct url *, const char *);
|
||||
FILE *fetchPutHTTP(struct url *, const char *);
|
||||
int fetchStatHTTP(struct url *, struct url_stat *, const char *);
|
||||
struct url_ent *fetchListHTTP(struct url *, const char *);
|
||||
FILE *fetchReqHTTP(struct url *, const char *, const char *,
|
||||
const char *, const char *);
|
||||
|
||||
/* FTP-specific functions */
|
||||
FILE *fetchXGetFTP(struct url *, struct url_stat *, const char *);
|
||||
|
@ -1030,7 +1030,7 @@ typedef struct {
|
||||
static void
|
||||
init_http_auth_params(http_auth_params_t *s)
|
||||
{
|
||||
s->scheme = s->realm = s->user = s->password = 0;
|
||||
s->scheme = s->realm = s->user = s->password = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1129,7 +1129,7 @@ CvtHex(IN HASH Bin, OUT HASHHEX Hex)
|
||||
Hex[i*2] = hexchars[j];
|
||||
j = Bin[i] & 0xf;
|
||||
Hex[i*2+1] = hexchars[j];
|
||||
};
|
||||
}
|
||||
Hex[HASHHEXLEN] = '\0';
|
||||
};
|
||||
|
||||
@ -1164,7 +1164,7 @@ DigestCalcHA1(
|
||||
MD5Update(&Md5Ctx, ":", 1);
|
||||
MD5Update(&Md5Ctx, pszCNonce, strlen(pszCNonce));
|
||||
MD5Final(HA1, &Md5Ctx);
|
||||
};
|
||||
}
|
||||
CvtHex(HA1, SessionKey);
|
||||
}
|
||||
|
||||
@ -1198,7 +1198,7 @@ DigestCalcResponse(
|
||||
if (strcasecmp(pszQop, "auth-int") == 0) {
|
||||
MD5Update(&Md5Ctx, ":", 1);
|
||||
MD5Update(&Md5Ctx, HEntity, HASHHEXLEN);
|
||||
};
|
||||
}
|
||||
MD5Final(HA2, &Md5Ctx);
|
||||
CvtHex(HA2, HA2Hex);
|
||||
|
||||
@ -1215,7 +1215,7 @@ DigestCalcResponse(
|
||||
MD5Update(&Md5Ctx, ":", 1);
|
||||
MD5Update(&Md5Ctx, pszQop, strlen(pszQop));
|
||||
MD5Update(&Md5Ctx, ":", 1);
|
||||
};
|
||||
}
|
||||
MD5Update(&Md5Ctx, HA2Hex, HASHHEXLEN);
|
||||
MD5Final(RespHash, &Md5Ctx);
|
||||
CvtHex(RespHash, Response);
|
||||
@ -1249,7 +1249,7 @@ http_digest_auth(conn_t *conn, const char *hdr, http_auth_challenge_t *c,
|
||||
int r;
|
||||
char noncecount[10];
|
||||
char cnonce[40];
|
||||
char *options = 0;
|
||||
char *options = NULL;
|
||||
|
||||
if (!c->realm || !c->nonce) {
|
||||
DEBUG(fprintf(stderr, "realm/nonce not set in challenge\n"));
|
||||
@ -1494,6 +1494,14 @@ http_print_html(FILE *out, FILE *in)
|
||||
* Core
|
||||
*/
|
||||
|
||||
FILE *
|
||||
http_request(struct url *URL, const char *op, struct url_stat *us,
|
||||
struct url *purl, const char *flags)
|
||||
{
|
||||
|
||||
return (http_request_body(URL, op, us, purl, flags, NULL, NULL));
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a request and process the reply
|
||||
*
|
||||
@ -1501,8 +1509,9 @@ http_print_html(FILE *out, FILE *in)
|
||||
* XXX off into a separate function.
|
||||
*/
|
||||
FILE *
|
||||
http_request(struct url *URL, const char *op, struct url_stat *us,
|
||||
struct url *purl, const char *flags)
|
||||
http_request_body(struct url *URL, const char *op, struct url_stat *us,
|
||||
struct url *purl, const char *flags, const char *content_type,
|
||||
const char *body)
|
||||
{
|
||||
char timebuf[80];
|
||||
char hbuf[MAXHOSTNAMELEN + 7], *host;
|
||||
@ -1519,6 +1528,7 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
|
||||
http_headerbuf_t headerbuf;
|
||||
http_auth_challenges_t server_challenges;
|
||||
http_auth_challenges_t proxy_challenges;
|
||||
size_t body_len;
|
||||
|
||||
/* The following calls don't allocate anything */
|
||||
init_http_headerbuf(&headerbuf);
|
||||
@ -1690,8 +1700,19 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
|
||||
if (url->offset > 0)
|
||||
http_cmd(conn, "Range: bytes=%lld-", (long long)url->offset);
|
||||
http_cmd(conn, "Connection: close");
|
||||
|
||||
if (body) {
|
||||
body_len = strlen(body);
|
||||
http_cmd(conn, "Content-Length: %zu", body_len);
|
||||
if (content_type != NULL)
|
||||
http_cmd(conn, "Content-Type: %s", content_type);
|
||||
}
|
||||
|
||||
http_cmd(conn, "");
|
||||
|
||||
if (body)
|
||||
fetch_write(conn, body, body_len);
|
||||
|
||||
/*
|
||||
* Force the queued request to be dispatched. Normally, one
|
||||
* would do this with shutdown(2) but squid proxies can be
|
||||
@ -2042,3 +2063,12 @@ fetchListHTTP(struct url *url __unused, const char *flags __unused)
|
||||
warnx("fetchListHTTP(): not implemented");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
FILE *
|
||||
fetchReqHTTP(struct url *URL, const char *method, const char *flags,
|
||||
const char *content_type, const char *body)
|
||||
{
|
||||
|
||||
return (http_request_body(URL, method, NULL, http_get_proxy(URL, flags),
|
||||
flags, content_type, body));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user