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: allow overwriting files if -O was used
[project/uclient.git]
/
uclient-http.c
diff --git
a/uclient-http.c
b/uclient-http.c
index 4300d0511e95d0dfa74d5044bd0e1ab8bd92018f..195fa1cfcdcbbc2ea008b1d1e17efc4553b79989 100644
(file)
--- a/
uclient-http.c
+++ b/
uclient-http.c
@@
-19,6
+19,7
@@
#include <ctype.h>
#include <unistd.h>
#include <stdint.h>
#include <ctype.h>
#include <unistd.h>
#include <stdint.h>
+#include <fcntl.h>
#include <libubox/ustream.h>
#include <libubox/ustream-ssl.h>
#include <libubox/ustream.h>
#include <libubox/ustream-ssl.h>
@@
-107,6
+108,8
@@
static const char * const uclient_http_prefix[] = {
[__PREFIX_MAX] = NULL
};
[__PREFIX_MAX] = NULL
};
+static int uclient_http_connect(struct uclient *cl);
+
static int uclient_do_connect(struct uclient_http *uh, const char *port)
{
socklen_t sl;
static int uclient_do_connect(struct uclient_http *uh, const char *port)
{
socklen_t sl;
@@
-115,18
+118,18
@@
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, uh->uc.url->host, port, &uh->uc.remote_addr);
if (fd < 0)
return -1;
if (fd < 0)
return -1;
+ fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
ustream_fd_init(&uh->ufd, fd);
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;
}
@@
-212,6
+215,7
@@
static void uclient_http_reset_state(struct uclient_http *uh)
static void uclient_http_init_request(struct uclient_http *uh)
{
static void uclient_http_init_request(struct uclient_http *uh)
{
+ uh->seq++;
uclient_http_reset_state(uh);
blob_buf_init(&uh->meta, 0);
}
uclient_http_reset_state(uh);
blob_buf_init(&uh->meta, 0);
}
@@
-540,6
+544,9
@@
uclient_http_send_headers(struct uclient_http *uh)
if (uh->state >= HTTP_STATE_HEADERS_SENT)
return;
if (uh->state >= HTTP_STATE_HEADERS_SENT)
return;
+ if (uh->uc.proxy_url)
+ url = uh->uc.proxy_url;
+
ustream_printf(uh->us,
"%s %s HTTP/1.1\r\n"
"Host: %s\r\n",
ustream_printf(uh->us,
"%s %s HTTP/1.1\r\n"
"Host: %s\r\n",
@@
-562,6
+569,7
@@
uclient_http_send_headers(struct uclient_http *uh)
static void uclient_http_headers_complete(struct uclient_http *uh)
{
enum auth_type auth_type = uh->auth_type;
static void uclient_http_headers_complete(struct uclient_http *uh)
{
enum auth_type auth_type = uh->auth_type;
+ int seq = uh->uc.seq;
uh->state = HTTP_STATE_RECV_DATA;
uh->uc.meta = uh->meta.head;
uh->state = HTTP_STATE_RECV_DATA;
uh->uc.meta = uh->meta.head;
@@
-569,7
+577,7
@@
static void uclient_http_headers_complete(struct uclient_http *uh)
if (auth_type == AUTH_TYPE_UNKNOWN && uh->uc.status_code == 401 &&
(uh->req_type == REQ_HEAD || uh->req_type == REQ_GET)) {
if (auth_type == AUTH_TYPE_UNKNOWN && uh->uc.status_code == 401 &&
(uh->req_type == REQ_HEAD || uh->req_type == REQ_GET)) {
- uclient_http_
init_request(uh
);
+ uclient_http_
connect(&uh->uc
);
uclient_http_send_headers(uh);
uh->state = HTTP_STATE_REQUEST_DONE;
return;
uclient_http_send_headers(uh);
uh->state = HTTP_STATE_REQUEST_DONE;
return;
@@
-578,7
+586,7
@@
static void uclient_http_headers_complete(struct uclient_http *uh)
if (uh->uc.cb->header_done)
uh->uc.cb->header_done(&uh->uc);
if (uh->uc.cb->header_done)
uh->uc.cb->header_done(&uh->uc);
- if (uh->eof)
+ if (uh->eof
|| seq != uh->uc.seq
)
return;
if (uh->req_type == REQ_HEAD || uh->uc.status_code == 204) {
return;
if (uh->req_type == REQ_HEAD || uh->uc.status_code == 204) {
@@
-732,6
+740,10
@@
static void uclient_notify_state(struct ustream *us)
{
struct uclient_http *uh = container_of(us, struct uclient_http, ufd.stream);
{
struct uclient_http *uh = container_of(us, struct uclient_http, ufd.stream);
+ if (uh->ufd.stream.write_error) {
+ uclient_http_error(uh, UCLIENT_ERROR_CONNECT);
+ return;
+ }
uclient_notify_eof(uh);
}
uclient_notify_eof(uh);
}
@@
-838,7
+850,7
@@
static int uclient_http_connect(struct uclient *cl)
struct uclient_http *uh = container_of(cl, struct uclient_http, uc);
int ret;
struct uclient_http *uh = container_of(cl, struct uclient_http, uc);
int ret;
- if (!cl->eof || uh->disconnect)
+ if (!cl->eof || uh->disconnect
|| uh->connection_close
)
uclient_http_disconnect(uh);
uclient_http_init_request(uh);
uclient_http_disconnect(uh);
uclient_http_init_request(uh);
@@
-1115,6
+1127,7
@@
const struct uclient_backend uclient_backend_http = {
.connect = uclient_http_connect,
.disconnect = uclient_http_request_disconnect,
.update_url = uclient_http_free_url_state,
.connect = uclient_http_connect,
.disconnect = uclient_http_request_disconnect,
.update_url = uclient_http_free_url_state,
+ .update_proxy_url = uclient_http_free_url_state,
.read = uclient_http_read,
.write = uclient_http_send_data,
.read = uclient_http_read,
.write = uclient_http_send_data,