projects
/
project
/
uclient.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
uclient-fetch: load CA certificates
[project/uclient.git]
/
uclient-http.c
diff --git
a/uclient-http.c
b/uclient-http.c
index
c25e52f
..
676ce1b
100644
(file)
--- a/
uclient-http.c
+++ b/
uclient-http.c
@@
-41,6
+41,7
@@
enum request_type {
REQ_HEAD,
REQ_POST,
REQ_PUT,
REQ_HEAD,
REQ_POST,
REQ_PUT,
+ REQ_DELETE,
__REQ_MAX
};
__REQ_MAX
};
@@
-58,6
+59,7
@@
static const char * const request_types[__REQ_MAX] = {
[REQ_HEAD] = "HEAD",
[REQ_POST] = "POST",
[REQ_PUT] = "PUT",
[REQ_HEAD] = "HEAD",
[REQ_POST] = "POST",
[REQ_PUT] = "PUT",
+ [REQ_DELETE] = "DELETE",
};
struct uclient_http {
};
struct uclient_http {
@@
-71,6
+73,7
@@
struct uclient_http {
struct ustream_ssl ussl;
struct uloop_timeout disconnect_t;
struct ustream_ssl ussl;
struct uloop_timeout disconnect_t;
+ unsigned int seq;
bool ssl_require_validation;
bool ssl;
bool ssl_require_validation;
bool ssl;
@@
-112,18
+115,17
@@
static int uclient_do_connect(struct uclient_http *uh, const char *port)
if (uh->uc.url->port)
port = uh->uc.url->port;
if (uh->uc.url->port)
port = uh->uc.url->port;
- fd = usock(USOCK_TCP | USOCK_NONBLOCK, uh->uc.url->host, port);
+ memset(&uh->uc.remote_addr, 0, sizeof(uh->uc.remote_addr));
+
+ fd = usock_inet(USOCK_TCP | USOCK_NONBLOCK, uh->uc.url->host, port, &uh->uc.remote_addr);
if (fd < 0)
return -1;
ustream_fd_init(&uh->ufd, fd);
if (fd < 0)
return -1;
ustream_fd_init(&uh->ufd, fd);
- memset(&uh->uc.local_addr, 0, sizeof(uh->uc.local_addr));
- memset(&uh->uc.remote_addr, 0, sizeof(uh->uc.remote_addr));
-
sl = sizeof(uh->uc.local_addr);
sl = sizeof(uh->uc.local_addr);
+ memset(&uh->uc.local_addr, 0, sl);
getsockname(fd, &uh->uc.local_addr.sa, &sl);
getsockname(fd, &uh->uc.local_addr.sa, &sl);
- getpeername(fd, &uh->uc.remote_addr.sa, &sl);
return 0;
}
return 0;
}
@@
-194,6
+196,7
@@
static void uclient_notify_eof(struct uclient_http *uh)
static void uclient_http_reset_state(struct uclient_http *uh)
{
static void uclient_http_reset_state(struct uclient_http *uh)
{
+ uh->seq++;
uclient_backend_reset_state(&uh->uc);
uh->read_chunked = -1;
uh->content_length = -1;
uclient_backend_reset_state(&uh->uc);
uh->read_chunked = -1;
uh->content_length = -1;
@@
-543,7
+546,7
@@
uclient_http_send_headers(struct uclient_http *uh)
url->location, url->host);
blobmsg_for_each_attr(cur, uh->headers.head, rem)
url->location, url->host);
blobmsg_for_each_attr(cur, uh->headers.head, rem)
- ustream_printf(uh->us, "%s: %s\n", blobmsg_name(cur), (char *) blobmsg_data(cur));
+ ustream_printf(uh->us, "%s: %s\
r\
n", blobmsg_name(cur), (char *) blobmsg_data(cur));
if (uh->req_type == REQ_POST || uh->req_type == REQ_PUT)
ustream_printf(uh->us, "Transfer-Encoding: chunked\r\n");
if (uh->req_type == REQ_POST || uh->req_type == REQ_PUT)
ustream_printf(uh->us, "Transfer-Encoding: chunked\r\n");
@@
-639,6
+642,7
@@
error:
static void __uclient_notify_read(struct uclient_http *uh)
{
struct uclient *uc = &uh->uc;
static void __uclient_notify_read(struct uclient_http *uh)
{
struct uclient *uc = &uh->uc;
+ unsigned int seq = uh->seq;
char *data;
int len;
char *data;
int len;
@@
-673,6
+677,9
@@
static void __uclient_notify_read(struct uclient_http *uh)
*sep = 0;
cur_len = sep + 2 - data;
uclient_parse_http_line(uh, data);
*sep = 0;
cur_len = sep + 2 - data;
uclient_parse_http_line(uh, data);
+ if (seq != uh->seq)
+ return;
+
ustream_consume(uh->us, cur_len);
len -= cur_len;
ustream_consume(uh->us, cur_len);
len -= cur_len;
@@
-689,8
+696,13
@@
static void __uclient_notify_read(struct uclient_http *uh)
if (uh->eof)
return;
if (uh->eof)
return;
- if (uh->state == HTTP_STATE_RECV_DATA && uc->cb->data_read)
- uc->cb->data_read(uc);
+ if (uh->state == HTTP_STATE_RECV_DATA) {
+ /* Now it's uclient user turn to read some data */
+ uloop_timeout_cancel(&uc->connection_timeout);
+
+ if (uc->cb->data_read)
+ uc->cb->data_read(uc);
+ }
}
static void __uclient_notify_write(struct uclient_http *uh)
}
static void __uclient_notify_write(struct uclient_http *uh)
@@
-813,6
+825,7
@@
static int uclient_setup_https(struct uclient_http *uh)
uh->ussl.notify_error = uclient_ssl_notify_error;
uh->ussl.notify_verify_error = uclient_ssl_notify_verify_error;
uh->ussl.notify_connected = uclient_ssl_notify_connected;
uh->ussl.notify_error = uclient_ssl_notify_error;
uh->ussl.notify_verify_error = uclient_ssl_notify_verify_error;
uh->ussl.notify_connected = uclient_ssl_notify_connected;
+ uh->ussl.server_name = uh->uc.url->host;
uh->ssl_ops->init(&uh->ussl, &uh->ufd.stream, uh->ssl_ctx, false);
uh->ssl_ops->set_peer_cn(&uh->ussl, uh->uc.url->host);
uh->ssl_ops->init(&uh->ussl, &uh->ufd.stream, uh->ssl_ctx, false);
uh->ssl_ops->set_peer_cn(&uh->ussl, uh->uc.url->host);
@@
-926,7
+939,7
@@
uclient_http_set_header(struct uclient *cl, const char *name, const char *value)
}
static int
}
static int
-uclient_http_send_data(struct uclient *cl, char *buf, unsigned int len)
+uclient_http_send_data(struct uclient *cl, c
onst c
har *buf, unsigned int len)
{
struct uclient_http *uh = container_of(cl, struct uclient_http, uc);
{
struct uclient_http *uh = container_of(cl, struct uclient_http, uc);
@@
-1030,6
+1043,10
@@
uclient_http_read(struct uclient *cl, char *buf, unsigned int len)
uclient_notify_eof(uh);
uclient_notify_eof(uh);
+ /* Now that we consumed something and if this isn't EOF, start timer again */
+ if (!uh->uc.eof && !cl->connection_timeout.pending)
+ uloop_timeout_set(&cl->connection_timeout, cl->timeout_msecs);
+
return len;
}
return len;
}