http: get rid of the global state Move the header parsing state into the transport, making use of the existing bitfield. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
diff --git a/src/transport-http.c b/src/transport-http.c
index 3feee00..d111d5c 100644
--- a/src/transport-http.c
+++ b/src/transport-http.c
@@ -33,6 +33,12 @@
#include "buffer.h"
#include "pkt.h"
+typedef enum {
+ NONE,
+ FIELD,
+ VALUE
+} last_cb_type;
+
typedef struct {
git_transport parent;
git_vector refs;
@@ -40,7 +46,10 @@ typedef struct {
git_buf buf;
git_remote_head **heads;
int error;
- int transfer_finished :1;
+ int transfer_finished :1,
+ ct_found :1,
+ ct_finished :1,
+ last_cb :3;
char *content_type;
char *service;
} transport_http;
@@ -115,13 +124,7 @@ cleanup:
* Content-Type. on_header_{field,value} should be kept generic enough
* to work for any request.
*/
-static enum {
- FIELD,
- VALUE,
- NONE
-} last_cb = NONE;
-static int ct_found, ct_finished;
static const char *typestr = "Content-Type";
static int on_header_field(http_parser *parser, const char *str, size_t len)
@@ -129,25 +132,25 @@ static int on_header_field(http_parser *parser, const char *str, size_t len)
transport_http *t = (transport_http *) parser->data;
git_buf *buf = &t->buf;
- if (last_cb == VALUE && ct_found) {
- ct_finished = 1;
- ct_found = 0;
+ if (t->last_cb == VALUE && t->ct_found) {
+ t->ct_finished = 1;
+ t->ct_found = 0;
t->content_type = git__strdup(git_buf_cstr(buf));
if (t->content_type == NULL)
return t->error = GIT_ENOMEM;
git_buf_clear(buf);
}
- if (ct_found) {
- last_cb = FIELD;
+ if (t->ct_found) {
+ t->last_cb = FIELD;
return 0;
}
- if (last_cb != FIELD)
+ if (t->last_cb != FIELD)
git_buf_clear(buf);
git_buf_put(buf, str, len);
- last_cb = FIELD;
+ t->last_cb = FIELD;
return git_buf_oom(buf);
}
@@ -157,21 +160,21 @@ static int on_header_value(http_parser *parser, const char *str, size_t len)
transport_http *t = (transport_http *) parser->data;
git_buf *buf = &t->buf;
- if (ct_finished) {
- last_cb = VALUE;
+ if (t->ct_finished) {
+ t->last_cb = VALUE;
return 0;
}
- if (last_cb == VALUE)
+ if (t->last_cb == VALUE)
git_buf_put(buf, str, len);
- if (last_cb == FIELD && !strcmp(git_buf_cstr(buf), typestr)) {
- ct_found = 1;
+ if (t->last_cb == FIELD && !strcmp(git_buf_cstr(buf), typestr)) {
+ t->ct_found = 1;
git_buf_clear(buf);
git_buf_put(buf, str, len);
}
- last_cb = VALUE;
+ t->last_cb = VALUE;
return git_buf_oom(buf);
}