about summary refs log tree commit homepage
path: root/http_put.c
diff options
context:
space:
mode:
Diffstat (limited to 'http_put.c')
-rw-r--r--http_put.c126
1 files changed, 63 insertions, 63 deletions
diff --git a/http_put.c b/http_put.c
index 15ff9f7..740ce08 100644
--- a/http_put.c
+++ b/http_put.c
@@ -173,7 +173,7 @@ static enum mog_next http_put_commit(struct mog_http *http)
 
         if (http->wbuf && http->wbuf != MOG_WR_ERROR)
                 return MOG_NEXT_WAIT_WR;
-        if (!http->persistent || http->wbuf == MOG_WR_ERROR)
+        if (!http->_p.persistent || http->wbuf == MOG_WR_ERROR)
                 return MOG_NEXT_CLOSE;
         mog_http_reset(http);
         return MOG_NEXT_ACTIVE;
@@ -182,65 +182,65 @@ static enum mog_next http_put_commit(struct mog_http *http)
 static void stash_advance_rbuf(struct mog_http *http, char *buf, size_t buf_len)
 {
         struct mog_rbuf *rbuf = http->rbuf;
-        size_t end = http->line_end + 1;
+        size_t end = http->_p.line_end + 1;
 
-        if (http->line_end == 0 || buf_len <= end) {
-                http->offset = 0;
+        if (http->_p.line_end == 0 || buf_len <= end) {
+                http->_p.offset = 0;
                 mog_rbuf_free_and_null(&http->rbuf);
                 return;
         }
 
-        assert(buf[http->line_end] == '\n' && "line_end is not LF");
+        assert(buf[http->_p.line_end] == '\n' && "line_end is not LF");
         assert(buf_len <= MOG_RBUF_MAX_SIZE && "bad rbuf size");
-        assert(end <= http->offset && "invalid line end");
+        assert(end <= http->_p.offset && "invalid line end");
         if (rbuf == NULL)
                 http->rbuf = rbuf = mog_rbuf_new(MOG_RBUF_BASE_SIZE);
 
         memmove(rbuf->rptr, buf + end, buf_len - end);
         rbuf->rsize = buf_len - end;
-        http->offset -= end;
-        if (http->tmp_tip >= end)
-                http->tmp_tip -= end;
-        http->line_end = 0;
+        http->_p.offset -= end;
+        if (http->_p.tmp_tip >= end)
+                http->_p.tmp_tip -= end;
+        http->_p.line_end = 0;
 }
 
 static void
 chunked_body_after_header(struct mog_http *http, char *buf, size_t buf_len)
 {
-        size_t tmpoff = http->offset;
+        size_t tmpoff = http->_p.offset;
 
         mog_chunk_init(http);
-        http->offset = tmpoff;
+        http->_p.offset = tmpoff;
 
         switch (mog_chunk_parse(http, buf, buf_len)) {
         case MOG_PARSER_ERROR:
                 (void)write_err(http, "400 Bad Request");
                 return;
         case MOG_PARSER_CONTINUE:
-                assert(http->chunk_state != MOG_CHUNK_STATE_DONE);
+                assert(http->_p.chunk_state != MOG_CHUNK_STATE_DONE);
                 /* fall through */
         case MOG_PARSER_DONE:
-                switch (http->chunk_state) {
+                switch (http->_p.chunk_state) {
                 case MOG_CHUNK_STATE_SIZE:
-                        assert(http->offset == buf_len
+                        assert(http->_p.offset == buf_len
                                && "HTTP chunk parser didn't finish size");
                         return;
                 case MOG_CHUNK_STATE_DATA:
-                        assert(http->offset == buf_len
+                        assert(http->_p.offset == buf_len
                                && "HTTP chunk parser didn't finish data");
                         return;
                 case MOG_CHUNK_STATE_TRAILER:
-                        assert(http->offset > 0 &&
-                               "http->offset unset while in trailer");
+                        assert(http->_p.offset > 0 &&
+                               "http->_p.offset unset while in trailer");
                         stash_advance_rbuf(http, buf, buf_len);
-                        http->skip_rbuf_defer = 1;
+                        http->_p.skip_rbuf_defer = 1;
                         return;
                 case MOG_CHUNK_STATE_DONE:
                         put_commit_resp(http);
-                        assert(http->offset > 0 &&
-                               "http->offset unset after chunk body done");
+                        assert(http->_p.offset > 0 &&
+                               "http->_p.offset unset after chunk body done");
                         stash_advance_rbuf(http, buf, buf_len);
-                        http->skip_rbuf_defer = 1;
+                        http->_p.skip_rbuf_defer = 1;
                 }
         }
 }
@@ -248,45 +248,45 @@ chunked_body_after_header(struct mog_http *http, char *buf, size_t buf_len)
 static void
 identity_body_after_header(struct mog_http *http, char *buf, size_t buf_len)
 {
-        size_t body_len = buf_len - http->offset;
-        char *body_ptr = buf + http->offset;
+        size_t body_len = buf_len - http->_p.offset;
+        char *body_ptr = buf + http->_p.offset;
 
-        if (http->content_len < body_len)
-                body_len = http->content_len;
+        if (http->_p.content_len < body_len)
+                body_len = http->_p.content_len;
         if (body_len == 0)
                 return;
-        http->offset += body_len;
+        http->_p.offset += body_len;
         if (!mog_http_write_full(http->forward, body_ptr, body_len))
                 (void)write_err(http, NULL);
 }
 
 static bool lengths_ok(struct mog_http *http)
 {
-        if (http->content_len < 0)
+        if (http->_p.content_len < 0)
                 return false;        /* ERANGE */
 
-        if (http->has_content_range) {
-                if (http->chunked)
+        if (http->_p.has_content_range) {
+                if (http->_p.chunked)
                         return false;
 
-                if (http->range_end < 0 || http->range_beg < 0)
+                if (http->_p.range_end < 0 || http->_p.range_beg < 0)
                         return false;        /* ERANGE */
 
-                assert(http->range_end >= 0 && http->range_beg >= 0 &&
+                assert(http->_p.range_end >= 0 && http->_p.range_beg >= 0 &&
                        "bad range, http_parser.rl broken");
 
                 /* can't end after we start */
-                if (http->range_end < http->range_beg)
+                if (http->_p.range_end < http->_p.range_beg)
                         return false;
 
                 /*
                  * Content-Length should match Content-Range boundaries
                  * WARNING: Eric Wong sucks at arithmetic, check this:
                  */
-                if (http->content_len >= 0) {
-                        off_t expect = http->range_end - http->range_beg + 1;
+                if (http->_p.content_len >= 0) {
+                        off_t expect = http->_p.range_end - http->_p.range_beg + 1;
 
-                        if (http->content_len != expect)
+                        if (http->_p.content_len != expect)
                                 return false;
                 }
         }
@@ -324,7 +324,7 @@ static struct mog_file * open_put(struct mog_http *http, char *path)
          * we can't do an atomic rename(2) on successful PUT
          * if we have a partial upload
          */
-        if (http->has_content_range) {
+        if (http->_p.has_content_range) {
                 http->forward = mog_file_open_put(http->svc, path, O_CREAT);
                 if (http->forward == NULL)
                         return NULL;
@@ -354,9 +354,9 @@ static struct mog_file * open_put(struct mog_http *http, char *path)
 
         file->path = xstrdup(path);
         assert(file->foff == 0 && "file->foff should be zero");
-        if (http->has_content_range)
-                file->foff = http->range_beg;
-        if (http->has_trailer_md5 || http->has_expect_md5)
+        if (http->_p.has_content_range)
+                file->foff = http->_p.range_beg;
+        if (http->_p.has_trailer_md5 || http->_p.has_expect_md5)
                 mog_digest_init(&file->digest, GC_MD5);
 
         return file;
@@ -387,12 +387,12 @@ void mog_http_put(struct mog_http *http, char *buf, size_t buf_len)
         if (file == NULL)
                 goto err;
 
-        if (buf_len == http->offset) {
+        if (buf_len == http->_p.offset) {
                 /* we got the HTTP header in one read() */
-                if (http->chunked) {
+                if (http->_p.chunked) {
                         mog_rbuf_free_and_null(&http->rbuf);
                         mog_chunk_init(http);
-                        http->offset = buf_len;
+                        http->_p.offset = buf_len;
                 }
                 return;
         }
@@ -400,10 +400,10 @@ void mog_http_put(struct mog_http *http, char *buf, size_t buf_len)
          * otherwise we got part of the request body with the header,
          * write partially read body
          */
-        assert(buf_len > http->offset && http->offset > 0
-               && "http->offset is wrong");
+        assert(buf_len > http->_p.offset && http->_p.offset > 0
+               && "http->_p.offset is wrong");
 
-        if (http->chunked)
+        if (http->_p.chunked)
                 chunked_body_after_header(http, buf, buf_len);
         else
                 identity_body_after_header(http, buf, buf_len);
@@ -502,9 +502,9 @@ static enum mog_next identity_put_in_progress(struct mog_fd *mfd)
         assert(http->wbuf == NULL && "can't receive file with http->wbuf");
         assert(http->forward && http->forward != MOG_IOSTAT && "bad forward");
 
-        need = http->content_len - http->forward->as.file.foff;
-        if (http->has_content_range)
-                need += http->range_beg;
+        need = http->_p.content_len - http->forward->as.file.foff;
+        if (http->_p.has_content_range)
+                need += http->_p.range_beg;
         if (need == 0)
                 return http_put_commit(http);
 
@@ -549,19 +549,19 @@ again:
         assert(http->wbuf == NULL && "can't receive file with http->wbuf");
         assert(http->forward && http->forward != MOG_IOSTAT && "bad forward");
 
-        switch (http->chunk_state) {
+        switch (http->_p.chunk_state) {
         case MOG_CHUNK_STATE_DATA:
                 assert(http->rbuf == NULL && "unexpected http->rbuf");
-                if (http->content_len == 0) { /* final chunk */
-                        http->chunk_state = MOG_CHUNK_STATE_TRAILER;
-                        http->offset = 0;
+                if (http->_p.content_len == 0) { /* final chunk */
+                        http->_p.chunk_state = MOG_CHUNK_STATE_TRAILER;
+                        http->_p.offset = 0;
                         goto chunk_state_trailer;
                 }
-                assert(http->content_len > 0 && "bad chunk length");
+                assert(http->_p.content_len > 0 && "bad chunk length");
                 /* read the chunk into memory */
                 buf = mog_fsbuf_get(&buf_len);
-                if (buf_len > http->content_len)
-                        buf_len = http->content_len;
+                if (buf_len > http->_p.content_len)
+                        buf_len = http->_p.content_len;
                 do {
                         r = read(mfd->fd, buf, buf_len);
                 } while (r < 0 && errno == EINTR);
@@ -571,10 +571,10 @@ again:
                 if (!mog_http_write_full(http->forward, buf, r))
                         return write_err(http, NULL);
 
-                http->content_len -= r;
+                http->_p.content_len -= r;
 
                 /* chunk is complete */
-                if (http->content_len == 0)
+                if (http->_p.content_len == 0)
                         mog_chunk_init(http);
                 goto again;
         case MOG_CHUNK_STATE_TRAILER:
@@ -610,15 +610,15 @@ chunk_state_trailer:
                 case MOG_PARSER_ERROR:
                         return write_err(http, "400 Bad Request");
                 case MOG_PARSER_CONTINUE:
-                        assert(http->chunk_state != MOG_CHUNK_STATE_DONE);
+                        assert(http->_p.chunk_state != MOG_CHUNK_STATE_DONE);
                 case MOG_PARSER_DONE:
-                        switch (http->chunk_state) {
+                        switch (http->_p.chunk_state) {
                         case MOG_CHUNK_STATE_SIZE:
                                 if (in_trailer)
                                         assert(0 && "bad chunk state: size");
                                 /* client is trickling chunk size :< */
                                 mog_rbuf_free_and_null(&http->rbuf);
-                                http->offset = 0;
+                                http->_p.offset = 0;
                                 goto again;
                         case MOG_CHUNK_STATE_DATA:
                                 if (in_trailer)
@@ -635,7 +635,7 @@ chunk_state_trailer:
                                 /* pipelined HTTP request after trailers! */
                                 if (http->rbuf)
                                         assert(http->rbuf->rsize > 0
-                                               && http->offset == 0
+                                               && http->_p.offset == 0
                                                && "bad rbuf");
                                 return http_put_commit(http);
                         }
@@ -657,7 +657,7 @@ read_err:
 
 enum mog_next mog_http_put_in_progress(struct mog_fd *mfd)
 {
-        if (mfd->as.http.chunked)
+        if (mfd->as.http._p.chunked)
                 return chunked_put_in_progress(mfd);
 
         return identity_put_in_progress(mfd);