Update the uhttpd version

This commit is contained in:
jbnadal
2018-04-13 17:59:07 +02:00
parent 4baa7f38fb
commit 38ba93805b
10 changed files with 135 additions and 13 deletions

View File

@@ -19,6 +19,10 @@
#include <libubox/blobmsg.h>
#include <ctype.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "uhttpd.h"
#include "tls.h"
@@ -37,6 +41,8 @@ const char * const http_versions[] = {
const char * const http_methods[] = {
[UH_HTTP_MSG_GET] = "GET",
[UH_HTTP_MSG_PUT] = "PUT",
[UH_HTTP_MSG_DELETE] = "DELETE",
[UH_HTTP_MSG_POST] = "POST",
[UH_HTTP_MSG_HEAD] = "HEAD",
[UH_HTTP_MSG_OPTIONS] = "OPTIONS",
@@ -45,8 +51,10 @@ const char * const http_methods[] = {
void uh_http_header(struct client *cl, int code, const char *summary)
{
struct http_request *r = &cl->request;
struct blob_attr *cur;
const char *enc = "Transfer-Encoding: chunked\r\n";
const char *conn;
int rem;
cl->http_code = code;
@@ -64,12 +72,17 @@ void uh_http_header(struct client *cl, int code, const char *summary)
if (!r->connection_close)
ustream_printf(cl->us, "Keep-Alive: timeout=%d\r\n", conf.http_keepalive);
blobmsg_for_each_attr(cur, cl->hdr_response.head, rem)
ustream_printf(cl->us, "%s: %s\r\n", blobmsg_name(cur),
blobmsg_get_string(cur));
}
static void uh_connection_close(struct client *cl)
{
cl->state = CLIENT_STATE_CLOSE;
cl->us->eof = true;
cl->refcount = 0;
ustream_state_change(cl->us);
}
@@ -86,6 +99,7 @@ static void client_timeout(struct uloop_timeout *timeout)
struct client *cl = container_of(timeout, struct client, timeout);
cl->state = CLIENT_STATE_CLOSE;
uh_client_unref (cl);
uh_connection_close(cl);
}
@@ -114,6 +128,7 @@ void uh_request_done(struct client *cl)
{
uh_chunk_eof(cl);
uh_dispatch_done(cl);
blob_buf_init(&cl->hdr_response, 0);
memset(&cl->dispatch, 0, sizeof(cl->dispatch));
if (!conf.http_keepalive || cl->request.connection_close)
@@ -519,7 +534,7 @@ static void client_close(struct client *cl)
cl->state = CLIENT_STATE_CLEANUP;
return;
}
// printf ("client_close (%d)\n", n_clients);
client_done = true;
n_clients--;
uh_dispatch_done(cl);
@@ -530,6 +545,7 @@ static void client_close(struct client *cl)
close(cl->sfd.fd.fd);
list_del(&cl->list);
blob_buf_free(&cl->hdr);
blob_buf_free(&cl->hdr_response);
free(cl);
uh_unblock_listeners();
@@ -580,6 +596,7 @@ static void set_addr(struct uh_addr *addr, void *src)
addr->family = sin->sin_family;
if (addr->family == AF_INET) {
addr->port = ntohs(sin->sin_port);
printf("client id: %d - ip addr: %s\n", n_clients, inet_ntoa(sin->sin_addr));
memcpy(&addr->in, &sin->sin_addr, sizeof(addr->in));
} else {
addr->port = ntohs(sin6->sin6_port);