Author: bapt
Date: Sun Jul 20 00:30:28 2014
New Revision: 268901
URL: http://svnweb.freebsd.org/changeset/base/268901

Log:
  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

Modified:
  stable/9/lib/libfetch/common.c
  stable/9/lib/libfetch/common.h
  stable/9/lib/libfetch/fetch.h
  stable/9/lib/libfetch/http.c
Directory Properties:
  stable/9/lib/libfetch/   (props changed)

Modified: stable/9/lib/libfetch/common.c
==============================================================================
--- stable/9/lib/libfetch/common.c      Sun Jul 20 00:29:41 2014        
(r268900)
+++ stable/9/lib/libfetch/common.c      Sun Jul 20 00:30:28 2014        
(r268901)
@@ -1110,6 +1110,9 @@ fetch_writev(conn_t *conn, struct iovec 
                        errno = 0;
                        pfd.revents = 0;
                        if (poll(&pfd, 1, deltams) < 0) {
+                               /* POSIX compliance */
+                               if (errno == EAGAIN)
+                                       continue;
                                if (errno == EINTR && fetchRestartCalls)
                                        continue;
                                return (-1);

Modified: stable/9/lib/libfetch/common.h
==============================================================================
--- stable/9/lib/libfetch/common.h      Sun Jul 20 00:29:41 2014        
(r268900)
+++ stable/9/lib/libfetch/common.h      Sun Jul 20 00:30:28 2014        
(r268901)
@@ -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 *);
 

Modified: stable/9/lib/libfetch/fetch.h
==============================================================================
--- stable/9/lib/libfetch/fetch.h       Sun Jul 20 00:29:41 2014        
(r268900)
+++ stable/9/lib/libfetch/fetch.h       Sun Jul 20 00:30:28 2014        
(r268901)
@@ -102,6 +102,8 @@ FILE                *fetchGetHTTP(struct url *, const 
 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 *);

Modified: stable/9/lib/libfetch/http.c
==============================================================================
--- stable/9/lib/libfetch/http.c        Sun Jul 20 00:29:41 2014        
(r268900)
+++ stable/9/lib/libfetch/http.c        Sun Jul 20 00:30:28 2014        
(r268901)
@@ -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 cha
        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
        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
                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, 
        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));
+}
_______________________________________________
svn-src-stable-9@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-stable-9
To unsubscribe, send any mail to "svn-src-stable-9-unsubscr...@freebsd.org"

Reply via email to