get_mime_boundary tests
FossilOrigin-Name: 60c5397f0ca912546c789cb17ce2b5adf1196675417dc06f91b49ddcd1bfceb3
This commit is contained in:
parent
0b70dba7b8
commit
ea616acdb7
6 changed files with 40 additions and 28 deletions
5
Makefile
5
Makefile
|
@ -96,6 +96,9 @@ install: $(TARGET)
|
|||
install -d $(PREFIX)/share/treebird/
|
||||
cp -r dist/ $(PREFIX)/share/treebird/
|
||||
|
||||
test:
|
||||
make -C test
|
||||
|
||||
apache_start:
|
||||
./scripts/fcgistarter.sh
|
||||
|
||||
|
@ -119,4 +122,4 @@ clean_deps:
|
|||
|
||||
clean_all: clean clean_deps
|
||||
|
||||
.PHONY: all filec clean update clean clean_deps clean_all
|
||||
.PHONY: all filec clean update clean clean_deps clean_all test
|
||||
|
|
13
src/mime.c
13
src/mime.c
|
@ -22,17 +22,18 @@
|
|||
#include <stdlib.h>
|
||||
#include "mime.h"
|
||||
|
||||
char* get_mime_boundary()
|
||||
char* get_mime_boundary(char* content_type_str, char** bound)
|
||||
{
|
||||
if (!getenv("CONTENT_TYPE")) return 1;
|
||||
char* content = content_type_str ? content_type_str : getenv("CONTENT_TYPE");
|
||||
|
||||
// Data gets changed in place
|
||||
char* content_type = malloc(strlen(getenv("CONTENT_TYPE"))+1);
|
||||
char* content_type = malloc(strlen(content)+1);
|
||||
if (!content_type)
|
||||
{
|
||||
perror("malloc");
|
||||
exit(1);
|
||||
}
|
||||
strcpy(content_type, content);
|
||||
|
||||
char* bound_str;
|
||||
char* boundary;
|
||||
|
@ -55,10 +56,12 @@ char* get_mime_boundary()
|
|||
if ((tmp = strchr(boundary, '\"')))
|
||||
*tmp = '\0';
|
||||
|
||||
return 0;
|
||||
*bound = boundary;
|
||||
|
||||
return content_type;
|
||||
error:
|
||||
free(content_type);
|
||||
return 1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* strnws(char* str)
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#ifndef MIME_H
|
||||
#define MIME_H
|
||||
|
||||
char* get_mime_boundary();
|
||||
char* get_mime_boundary(char* content_type, char** res);
|
||||
char* read_mime_data(char* boundary, char* begin, struct http_form_info* info);
|
||||
|
||||
#endif /* MIME_H */
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
CC ?= cc
|
||||
MASTODONT_DIR = mastodont-c/
|
||||
MASTODONT = $(MASTODONT_DIR)libmastodont.a
|
||||
CFLAGS += -Wall -I ../$(MASTODONT_DIR)include/ -Wno-unused-variable -Wno-discarded-qualifiers -I/usr/include/ $(shell pkg-config --cflags libcurl libcjson libpcre)
|
||||
CFLAGS += -g -Wall -I ../$(MASTODONT_DIR)include/ -Wno-unused-variable -Wno-discarded-qualifiers -I/usr/include/ $(shell pkg-config --cflags libcurl libcjson libpcre)
|
||||
LDFLAGS = -L./../$(MASTODONT_DIR) -lmastodont $(shell pkg-config --libs libcjson libcurl libpcre) -lfcgi
|
||||
TARGET = tests
|
||||
SRC = unit/main.c
|
||||
SRC = unit/main.c ../src/mime.c
|
||||
OBJ = $(patsubst %.c,%.o,$(SRC))
|
||||
|
||||
all: $(TARGET)
|
||||
|
|
BIN
test/tests
BIN
test/tests
Binary file not shown.
|
@ -1,29 +1,35 @@
|
|||
#include "../mine.h"
|
||||
#define BOUNDARY_CONTENT_T1 "Content-Type: multipart/form-data; boundary=---------------------------9051914041544843365972754266"
|
||||
#define BOUNDARY_CONTENT_T2 "Content-Type: multipart/form-data; boundary=\"---------------------------9051914041544843365972754266\""
|
||||
#include "../../src/mime.h"
|
||||
#define BOUNDARY_CONTENT_T1 "multipart/form-data; boundary=---------------------------9051914041544843365972754266"
|
||||
#define BOUNDARY_CONTENT_T2 "multipart/form-data; boundary=\"---------------------------9051914041544843365972754266\""
|
||||
#define BOUNDARY_RES_T "---------------------------9051914041544843365972754266"
|
||||
|
||||
#define MULTIPART_TEST "-----------------------------9051914041544843365972754266\r\n"
|
||||
"Content-Disposition: form-data; name=\"text\"\r\n\r\n"
|
||||
|
||||
"text default\r\n"
|
||||
"-----------------------------9051914041544843365972754266\r\n"
|
||||
"Content-Disposition: form-data; name=\"file1\"; filename=\"a.txt\"\r\n"
|
||||
"Content-Type: text/plain\r\n\r\n"
|
||||
|
||||
"Content of a.txt.\r\n\r\n"
|
||||
|
||||
"-----------------------------9051914041544843365972754266\r\n"
|
||||
"Content-Disposition: form-data; name=\"file2\"; filename\"a.html\"\r\n"
|
||||
"Content-Type: text/html\r\n\r\n"
|
||||
|
||||
"<!DOCTYPE html><title>Content of a.html.</title>\r\n\r\n"
|
||||
|
||||
#define MULTIPART_TEST "-----------------------------9051914041544843365972754266\r\n" \
|
||||
"Content-Disposition: form-data; name=\"text\"\r\n\r\n" \
|
||||
"text default\r\n" \
|
||||
"-----------------------------9051914041544843365972754266\r\n" \
|
||||
"Content-Disposition: form-data; name=\"file1\"; filename=\"a.txt\"\r\n" \
|
||||
"Content-Type: text/plain\r\n\r\n" \
|
||||
"Content of a.txt.\r\n\r\n" \
|
||||
"-----------------------------9051914041544843365972754266\r\n" \
|
||||
"Content-Disposition: form-data; name=\"file2\"; filename\"a.html\"\r\n" \
|
||||
"Content-Type: text/html\r\n\r\n" \
|
||||
"<!DOCTYPE html><title>Content of a.html.</title>\r\n\r\n" \
|
||||
"-----------------------------9051914041544843365972754266--"
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
int mime_multipart_test(void)
|
||||
{
|
||||
char* bound, *bound2;
|
||||
char* mem = get_mime_boundary(BOUNDARY_CONTENT_T2, &bound);
|
||||
char* mem2 = get_mime_boundary(BOUNDARY_CONTENT_T1, &bound2);
|
||||
assert(bound != NULL && bound2 != NULL);
|
||||
assert(strcmp(bound, BOUNDARY_RES_T) == 0 &&
|
||||
strcmp(bound2, BOUNDARY_RES_T) == 0);
|
||||
free(mem);
|
||||
free(mem2);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue