summaryrefslogtreecommitdiff
path: root/httpd/httpd.c
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeffrey.armstrong@approximatrix.com>2016-12-14 09:14:39 -0500
committerJeffrey Armstrong <jeffrey.armstrong@approximatrix.com>2016-12-14 09:14:39 -0500
commitdc65ef038279df55d5e49052eabac4eae2617ee1 (patch)
tree84c7ffc081482c18c2bc0a6ddb1a4d6dd260f925 /httpd/httpd.c
parent84de937689bcb35ea3ddae55d9c74dc23463f79c (diff)
downloaduIP-FOSSIL-dc65ef038279df55d5e49052eabac4eae2617ee1.tar.gz
uIP-FOSSIL-dc65ef038279df55d5e49052eabac4eae2617ee1.zip
Now compiles with Turbo C 2.0 using included makefile. Added better logging (to screen). Added supprot for opening and sending gzip'ed files if available on disk.
Diffstat (limited to 'httpd/httpd.c')
-rw-r--r--httpd/httpd.c50
1 files changed, 41 insertions, 9 deletions
diff --git a/httpd/httpd.c b/httpd/httpd.c
index c7cc49c..459bfa2 100644
--- a/httpd/httpd.c
+++ b/httpd/httpd.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009 Jeffrey Armstrong
+ * Copyright (c) 2009, 2016 Jeffrey Armstrong
* Copyright (c) 2001-2005, Adam Dunkels.
* All rights reserved.
*
@@ -37,6 +37,7 @@
#include "http-str.h"
#include <string.h>
+#include <time.h>
#define STATE_WAITING 0
#define STATE_OUTPUT 1
@@ -62,7 +63,7 @@ static unsigned short generate_part_of_file(void *state)
fread(uip_appdata,sizeof(char),s->len,s->file.fp);
- if(s->len == s->file.len)
+ if(s->len >= s->file.len)
fclose(s->file.fp);
return s->len;
@@ -95,17 +96,22 @@ static PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr))
char *ptr;
PSOCK_BEGIN(&s->sout);
-
+
PSOCK_SEND_STR(&s->sout, statushdr);
+ if(s->compressed)
+ PSOCK_SEND_STR(&s->sout, http_content_encode);
+
ptr = strrchr(s->filename, ISO_period);
if(ptr == NULL) {
PSOCK_SEND_STR(&s->sout, http_content_type_binary);
} else if(strncmp(http_html, ptr, 5) == 0 ||
strncmp(http_shtml, ptr, 6) == 0 ||
- strncmp(http_htm, ptr, 4) == 0) {
+ strncmp(http_htm, ptr, 4) == 0 ||
+ strncmp(http_hgz, ptr, 4) == 0) {
PSOCK_SEND_STR(&s->sout, http_content_type_html);
- } else if(strncmp(http_css, ptr, 4) == 0) {
+ } else if(strncmp(http_css, ptr, 4) == 0 ||
+ strncmp(http_cgz, ptr, 4) == 0) {
PSOCK_SEND_STR(&s->sout, http_content_type_css);
} else if(strncmp(http_png, ptr, 4) == 0) {
PSOCK_SEND_STR(&s->sout, http_content_type_png);
@@ -116,6 +122,7 @@ static PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr))
} else {
PSOCK_SEND_STR(&s->sout, http_content_type_plain);
}
+
PSOCK_END(&s->sout);
}
@@ -123,8 +130,19 @@ static PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr))
static PT_THREAD(handle_output(struct httpd_state *s))
{
char *ptr;
+ time_t ltime;
PT_BEGIN(&s->outputpt);
+
+ printf("%s requested - ", s->filename);
+
+ if(s->compressed == 1 && compressed_available(s->filename) == 1)
+ compressed_name(s->filename);
+ else
+ s->compressed = 0;
+
+ ltime = time(NULL);
+ printf("using %s - %s", s->filename, ctime(&ltime));
if(httpd_fs_open(s->filename, &s->file) < 0) {
@@ -141,15 +159,18 @@ static PT_THREAD(handle_output(struct httpd_state *s))
PT_WAIT_THREAD(&s->outputpt,
send_headers(s,
http_header_200));
- ptr = strchr(s->filename, ISO_period);
+ /* ptr = strchr(s->filename, ISO_period); */
PT_WAIT_THREAD(&s->outputpt, send_file(s));
}
+
PSOCK_CLOSE(&s->sout);
PT_END(&s->outputpt);
}
static PT_THREAD(handle_input(struct httpd_state *s))
{
+ int i;
+
PSOCK_BEGIN(&s->sin);
PSOCK_READTO(&s->sin, ISO_space);
@@ -172,18 +193,29 @@ static PT_THREAD(handle_input(struct httpd_state *s))
}
/* httpd_log_file(uip_conn->ripaddr, s->filename);*/
-
- s->state = STATE_OUTPUT;
-
+ s->compressed = 0;
while(1) {
PSOCK_READTO(&s->sin, ISO_nl);
if(strncmp(s->inputbuf, http_referer, 8) == 0) {
s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
/* httpd_log(&s->inputbuf[9]);*/
+ } else if(strncmp(s->inputbuf, http_accept_encode, 17) == 0) {
+ i = 17;
+ while(s->inputbuf[i] != ISO_nl) {
+ if(strncmp(&s->inputbuf[i], http_gzip, 4) == 0) {
+ s->compressed = 1;
+ break;
+ }
+ i++;
+ }
+ } else if(PSOCK_DATALEN(&s->sin) < 3) {
+ break;
}
+
}
+ s->state = STATE_OUTPUT;
PSOCK_END(&s->sin);
}