projects
/
project
/
uclient.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
http: fix processing server http data separated by \n instead of \r\n
[project/uclient.git]
/
uclient-http.c
diff --git
a/uclient-http.c
b/uclient-http.c
index fa66f78a0562ffe5a867154a2572422f412a70cb..e58cf274b3a6cef5b06929462c7638f3d648afa1 100644
(file)
--- a/
uclient-http.c
+++ b/
uclient-http.c
@@
-108,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;
@@
-575,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;
@@
-661,28
+663,33
@@
static void __uclient_notify_read(struct uclient_http *uh)
return;
if (uh->state < HTTP_STATE_RECV_DATA) {
return;
if (uh->state < HTTP_STATE_RECV_DATA) {
- char *sep;
+ char *sep
, *next
;
int cur_len;
do {
int cur_len;
do {
- sep = str
str(data, "\r\n"
);
+ sep = str
chr(data, '\n'
);
if (!sep)
break;
if (!sep)
break;
+ next = sep + 1;
+ if (sep > data && sep[-1] == '\r')
+ sep--;
+
/* Check for multi-line HTTP headers */
if (sep > data) {
/* Check for multi-line HTTP headers */
if (sep > data) {
- if (!
sep[2]
)
+ if (!
*next
)
return;
return;
- if (isspace(
sep[2]) && sep[2] != '\r
') {
+ if (isspace(
*next) && *next != '\r' && *next != '\n
') {
sep[0] = ' ';
sep[0] = ' ';
- sep[1] = ' ';
+ if (sep + 1 < next)
+ sep[1] = ' ';
continue;
}
}
*sep = 0;
continue;
}
}
*sep = 0;
- cur_len =
sep + 2
- data;
+ cur_len =
next
- data;
uclient_parse_http_line(uh, data);
if (seq != uh->seq)
return;
uclient_parse_http_line(uh, data);
if (seq != uh->seq)
return;
@@
-848,7
+855,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);
@@
-1061,7
+1068,7
@@
uclient_http_read(struct uclient *cl, char *buf, unsigned int len)
return len;
}
return len;
}
-
bool
uclient_http_redirect(struct uclient *cl)
+
int
uclient_http_redirect(struct uclient *cl)
{
struct uclient_http *uh = container_of(cl, struct uclient_http, uc);
struct blobmsg_policy location = {
{
struct uclient_http *uh = container_of(cl, struct uclient_http, uc);
struct blobmsg_policy location = {
@@
-1093,7
+1100,9
@@
bool uclient_http_redirect(struct uclient *cl)
free(cl->url);
cl->url = url;
free(cl->url);
cl->url = url;
- uclient_http_connect(cl);
+ if (uclient_http_connect(cl))
+ return -1;
+
uclient_http_request_done(cl);
return true;
uclient_http_request_done(cl);
return true;