aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Draxinger <Wolfgang.Draxinger@physik.uni-muenchen.de>2013-06-20 16:55:28 +0200
committerWolfgang Draxinger <Wolfgang.Draxinger@physik.uni-muenchen.de>2013-06-20 16:55:28 +0200
commitef400acf33b32092c6c4c76f91a44d0a38061d0f (patch)
tree1763738d6c2710e809fc0f84769131d275eb3b4a
parentc50c12e6206772273f62752c1c0091ac78698665 (diff)
downloadlitheweb-ef400acf33b32092c6c4c76f91a44d0a38061d0f.tar.gz
litheweb-ef400acf33b32092c6c4c76f91a44d0a38061d0f.tar.bz2
...
-rw-r--r--picohttp.c16
-rw-r--r--picohttp.h51
-rw-r--r--test/bsdsocket.c9
3 files changed, 46 insertions, 30 deletions
diff --git a/picohttp.c b/picohttp.c
index f7b6948..957bfa6 100644
--- a/picohttp.c
+++ b/picohttp.c
@@ -1,5 +1,11 @@
#include "picohttp.h"
+#define picohttpIoWrite(ioops,size,buf) (ioops->write(size, buf, ioops->data))
+#define picohttpIoRead(ioops,size,buf) (ioops->read(size, buf, ioops->data))
+#define picohttpIoGetch(ioops) (ioops->getch(ioops->data))
+#define picohttpIoPutch(ioops,c) (ioops->putch(c, ioops->data))
+#define picohttpIoFlush(ioops) (ioops->flush(ioops->data))
+
#ifdef HOST_DEBUG
#include <stdio.h>
#define debug_printf(...) do{fprintf(stderr, __VA_ARGS__);}while(0)
@@ -446,6 +452,7 @@ static int16_t picohttpProcessQuery (
ch = picohttpIoGetch(req->ioops);
}
if( '=' == ch ) {
+ debug_printf("set variable '%s'\n", var);
} else {
}
}
@@ -522,15 +529,18 @@ static void picohttpProcessContentType(
if(!strncmp(contenttype, PICOHTTP_STR_MULTIPART_,
sizeof(PICOHTTP_STR_MULTIPART_)-1)) {
- req->query.contenttype.type = PICOHTTP_CONTENTTYPE_MULTIPART;
contenttype += sizeof(PICOHTTP_STR_MULTIPART_)-1;
+ req->query.contenttype =
+ PICOHTTP_CONTENTTYPE_MULTIPART;
if(!strncmp(contenttype,PICOHTTP_STR_FORMDATA,
sizeof(PICOHTTP_STR_FORMDATA)-1)) {
- req->query.contenttype.subtype =
- PICOHTTP_CONTENTTYPE_MULTIPART_SUBTYPE_FORM_DATA;
contenttype += sizeof(PICOHTTP_STR_FORMDATA)-1;
+
+ req->query.contenttype =
+ PICOHTTP_CONTENTTYPE_MULTIPART_FORMDATA;
}
+
char *boundary = strstr(contenttype, PICOHTTP_STR_BOUNDARY);
if(boundary) {
/* see RFC1521 regarding maximum length of boundary */
diff --git a/picohttp.h b/picohttp.h
index 34fc59b..76253b0 100644
--- a/picohttp.h
+++ b/picohttp.h
@@ -6,6 +6,7 @@
#include <stdint.h>
#define PICOHTTP_MULTIPARTBOUNDARY_MAX_LEN 70
+#define PICOHTTP_DISPOSITION_NAME_MAX 16
#define PICOHTTP_MAJORVERSION(x) ( (x & 0x7f00) >> 8 )
#define PICOHTTP_MINORVERSION(x) ( (x & 0x007f) )
@@ -14,20 +15,21 @@
#define PICOHTTP_METHOD_HEAD 2
#define PICOHTTP_METHOD_POST 3
-#define PICOHTTP_CONTENTTYPE_APPLICATION 0
-#define PICOHTTP_CONTENTTYPE_AUDIO 1
-#define PICOHTTP_CONTENTTYPE_IMAGE 2
-#define PICOHTTP_CONTENTTYPE_MESSAGE 3
-#define PICOHTTP_CONTENTTYPE_MODEL 4
-#define PICOHTTP_CONTENTTYPE_MULTIPART 5
-#define PICOHTTP_CONTENTTYPE_TEXT 6
-#define PICOHTTP_CONTENTTYPE_VIDEO 7
+#define PICOHTTP_CONTENTTYPE_APPLICATION 0x0000
+#define PICOHTTP_CONTENTTYPE_AUDIO 0x1000
+#define PICOHTTP_CONTENTTYPE_IMAGE 0x2000
+#define PICOHTTP_CONTENTTYPE_MESSAGE 0x3000
+#define PICOHTTP_CONTENTTYPE_MODEL 0x4000
-#define PICOHTTP_CONTENTTYPE_TEXT_SUBTYPE_CSV 3
-#define PICOHTTP_CONTENTTYPE_TEXT_SUBTYPE_HTML 4
-#define PICOHTTP_CONTENTTYPE_TEXT_SUBTYPE_PLAIN 6
+#define PICOHTTP_CONTENTTYPE_MULTIPART 0x5000
+#define PICOHTTP_CONTENTTYPE_MULTIPART_FORMDATA 0x5004
-#define PICOHTTP_CONTENTTYPE_MULTIPART_SUBTYPE_FORM_DATA 4
+#define PICOHTTP_CONTENTTYPE_TEXT 0x6000
+#define PICOHTTP_CONTENTTYPE_TEXT_CSV 0x6003
+#define PICOHTTP_CONTENTTYPE_TEXT_HTML 0x6004
+#define PICOHTTP_CONTENTTYPE_TEXT_PLAIN 0x6006
+
+#define PICOHTTP_CONTENTTYPE_VIDEO 0x7000
#define PICOHTTP_CODING_IDENTITY 0
#define PICOHTTP_CODING_COMPRESS 1
@@ -53,12 +55,6 @@ struct picohttpIoOps {
void *data;
};
-#define picohttpIoWrite(ioops,size,buf) (ioops->write(size, buf, ioops->data))
-#define picohttpIoRead(ioops,size,buf) (ioops->read(size, buf, ioops->data))
-#define picohttpIoGetch(ioops) (ioops->getch(ioops->data))
-#define picohttpIoPutch(ioops,c) (ioops->putch(c, ioops->data))
-#define picohttpIoFlush(ioops) (ioops->flush(ioops->data))
-
enum picohttpVarType {
PICOHTTP_TYPE_UNDEFINED = 0,
PICOHTTP_TYPE_INTEGER = 1,
@@ -120,10 +116,7 @@ struct picohttpRequest {
uint8_t minor;
} httpversion;
struct {
- struct {
- uint16_t type:4;
- uint16_t subtype:12;
- } contenttype;
+ uint16_t contenttype;
size_t contentlength;
uint8_t contentencoding;
uint8_t transferencoding;
@@ -141,12 +134,22 @@ struct picohttpRequest {
struct {
size_t length;
} currentchunk;
+ size_t received_octets;
struct {
size_t octets;
uint8_t header;
} sent;
};
+struct picohttpMultipart {
+ struct picohttpRequest *req;
+ uint16_t contenttype;
+ struct {
+ char name[PICOHTTP_DISPOSITION_NAME_MAX+1];
+ } disposition;
+ uint8_t boundarymatch_counter;
+};
+
void picohttpProcessRequest(
struct picohttpIoOps const * const ioops,
struct picohttpURLRoute const * const routes );
@@ -168,9 +171,9 @@ uint16_t picohttpGetch(
int picohttpMultipartNext(
struct picohttpRequest * const req,
- struct picohttpMultiPart * const mp);
+ struct picohttpMultipart * const mp);
uint16_t picohttpMultipartGetch(
- struct picohttpMultiPart * const mp);
+ struct picohttpMultipart * const mp);
#endif/*PICOHTTP_H_HEADERGUARD*/
diff --git a/test/bsdsocket.c b/test/bsdsocket.c
index cb6cde2..bddb5be 100644
--- a/test/bsdsocket.c
+++ b/test/bsdsocket.c
@@ -122,11 +122,11 @@ void rhTest(struct picohttpRequest *req)
char http_header[] = "HTTP/x.x 200 OK\r\nServer: picoweb\r\nContent-Type: text/text\r\n\r\n";
http_header[5] = '0'+req->httpversion.major;
http_header[7] = '0'+req->httpversion.minor;
- picohttpIoWrite(req->ioops, sizeof(http_header)-1, http_header);
+ picohttpResponseWrite(req, sizeof(http_header)-1, http_header);
char http_test[] = "handling request /test";
- picohttpIoWrite(req->ioops, sizeof(http_test)-1, http_test);
+ picohttpResponseWrite(req, sizeof(http_test)-1, http_test);
if(req->urltail) {
- picohttpIoWrite(req->ioops, strlen(req->urltail), req->urltail);
+ picohttpResponseWrite(req, strlen(req->urltail), req->urltail);
}
}
@@ -134,6 +134,9 @@ void rhUpload(struct picohttpRequest *req)
{
fprintf(stderr, "handling request /upload%s\n", req->urltail);
+ if( PICOHTTP_CONTENTTYPE_MULTIPART_FORMDATA != req->query.contenttype )
+ return;
+
char http_test[] = "handling request /upload";
picohttpResponseWrite(req, sizeof(http_test)-1, http_test);
if(req->urltail) {