mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-18 19:31:02 +00:00
Publish mongoose src and tests
CL: Mongoose Web Server: Publish sources and tests Resolves https://github.com/cesanta/mongoose/issues/745 PUBLISHED_FROM=7ecd7a3c518cfa614a6ba0838678dcb91b75a8c0
This commit is contained in:
1 parent
0ab1c7ef76
commit
8742fac5d8
94 files changed
+24967
No files matched your search
@@ -0,0 +1,14 @@
|
||||
# set OPENSSL_LIB to the directory containing openssl libcrypto
|
||||
|
||||
OPENSSL_LIB = /usr/lib
|
||||
|
||||
CFLAGS = -I ..
|
||||
LDFLAGS = -L .. -L $(OPENSSL_LIB)
|
||||
|
||||
all: test.sh test
|
||||
./test.sh
|
||||
|
||||
test: test.o ../libccgi.a
|
||||
$(CC) -o test $(LDFLAGS) test.o -lccgi -lcrypto
|
||||
|
||||
test.o: test.c ../ccgi.h
|
||||
@@ -0,0 +1,141 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <ccgi.h>
|
||||
|
||||
static void
|
||||
dumplist(CGI_varlist *vl) {
|
||||
const char *name;
|
||||
CGI_value *value;
|
||||
int i;
|
||||
|
||||
for (name = CGI_first_name(vl); name != 0;
|
||||
name = CGI_next_name(vl))
|
||||
{
|
||||
value = CGI_lookup_all(vl, 0);
|
||||
for (i = 0; value[i] != 0; i++) {
|
||||
printf("%s [%d] >>%s<<\n", name, i, value[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv) {
|
||||
CGI_varlist *vl;
|
||||
char *p;
|
||||
CGI_value *value;
|
||||
int i;
|
||||
|
||||
if (strcmp(argv[1], "CGI_get_cookie") == 0) {
|
||||
vl = CGI_get_cookie(0);
|
||||
dumplist(vl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "CGI_get_query") == 0) {
|
||||
vl = CGI_get_query(0);
|
||||
dumplist(vl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "CGI_decode_query") == 0) {
|
||||
vl = CGI_decode_query(0, argv[2]);
|
||||
dumplist(vl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "CGI_get_post") == 0) {
|
||||
vl = CGI_get_post(0, 0);
|
||||
dumplist(vl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "upload") == 0) {
|
||||
vl = CGI_get_post(0, "./cgi-upload-XXXXXX");
|
||||
value = CGI_lookup_all(vl, "upload");
|
||||
dumplist(vl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "CGI_add_var") == 0) {
|
||||
vl = 0;
|
||||
for (i = 2; i + 1 < argc; i += 2) {
|
||||
vl = CGI_add_var(vl, argv[i], argv[i + 1]);
|
||||
}
|
||||
dumplist(vl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "CGI_encode_varlist") == 0) {
|
||||
vl = 0;
|
||||
for (i = 2; i + 1 < argc; i += 2) {
|
||||
vl = CGI_add_var(vl, argv[i], argv[i + 1]);
|
||||
}
|
||||
dumplist(vl);
|
||||
p = CGI_encode_varlist(vl, ".-_");
|
||||
fputs(p, stdout);
|
||||
fputc('\n', stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (strcmp(argv[1], "CGI_encode_url") == 0) {
|
||||
p = CGI_encode_url(argv[2], ".-_");
|
||||
fputs(p, stdout);
|
||||
fputc('\n', stdout);
|
||||
p = CGI_decode_url(p);
|
||||
fputs(p, stdout);
|
||||
fputc('\n', stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "CGI_encode_query") == 0) {
|
||||
p = CGI_encode_query(".-_", argv[2], argv[3], argv[4], argv[5],
|
||||
argv[6], argv[7], argv[8], argv[9], argv[10], argv[11],
|
||||
argv[12], argv[13], argv[14], argv[15], argv[16], argv[17],
|
||||
argv[18], argv[19], argv[20], argv[21], (char *)0);
|
||||
fputs(p, stdout);
|
||||
fputc('\n', stdout);
|
||||
vl = CGI_decode_query(0, p);
|
||||
dumplist(vl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "CGI_encode_base64") == 0) {
|
||||
p = argv[2];
|
||||
p = CGI_encode_base64(p, strlen(p));
|
||||
fputs(p, stdout);
|
||||
fputc('\n', stdout);
|
||||
p = (char *) CGI_decode_base64(p, &i);
|
||||
fwrite(p, i, 1, stdout);
|
||||
fputc('\n', stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "CGI_encode_hex") == 0) {
|
||||
p = argv[2];
|
||||
p = CGI_encode_hex(p, strlen(p));
|
||||
fputs(p, stdout);
|
||||
fputc('\n', stdout);
|
||||
p = (char *) CGI_decode_hex(p, &i);
|
||||
fwrite(p, i, 1, stdout);
|
||||
fputc('\n', stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "CGI_encode_entity") == 0) {
|
||||
p = CGI_encode_entity(argv[2]);
|
||||
fputs(p, stdout);
|
||||
fputc('\n', stdout);
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(argv[1], "CGI_encrypt") == 0) {
|
||||
const char *pw = "This is my C CGI test password";
|
||||
p = argv[2];
|
||||
p = CGI_encrypt(p, strlen(p), pw);
|
||||
printf("enc len = %d\n", strlen(p));
|
||||
p = CGI_decrypt(p , &i, pw);
|
||||
printf("dec len = %d %s\n", i, p);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Executable
+337
@@ -0,0 +1,337 @@
|
||||
#! /bin/sh
|
||||
|
||||
PATH=/bin:/usr/bin
|
||||
|
||||
# Regression tests for the CGI library
|
||||
# Usage: ./test.sh [ -r ]
|
||||
# The -r option causes the script to edit itself and renumber
|
||||
# the tests in case any are added or removed.
|
||||
|
||||
# renumber the tests in this script
|
||||
|
||||
renumber() {
|
||||
cp $0 $0.old &&
|
||||
awk '/^TEST=[0-9].* ######/ {
|
||||
printf("TEST=%d ########################################\n", ++i);
|
||||
next }
|
||||
{ print }' $0.old > $0 &&
|
||||
/bin/rm $0.old
|
||||
exit
|
||||
}
|
||||
|
||||
check () {
|
||||
echo
|
||||
if diff -c expected result; then
|
||||
echo "Test $TEST success"
|
||||
else
|
||||
echo "Test $TEST failure"
|
||||
fi
|
||||
}
|
||||
|
||||
test "X$1" = X-r && renumber
|
||||
|
||||
TEST=1 ########################################
|
||||
|
||||
# Testing CGI_get_query
|
||||
|
||||
Q='one=This+is+a+test&two=%22Bob+Smith%22+%3Cbob%40gmail.com%3E&'
|
||||
Q=$Q'varnovalue&eq=un=encoded=eq==&one=second+value&the+end'
|
||||
|
||||
QUERY_STRING=$Q ./test CGI_get_query > result 2>&1
|
||||
|
||||
cat > expected <<'E-O-F'
|
||||
one [0] >>This is a test<<
|
||||
one [1] >>second value<<
|
||||
two [0] >>"Bob Smith" <bob@gmail.com><<
|
||||
varnovalue [0] >><<
|
||||
eq [0] >>un=encoded=eq==<<
|
||||
the end [0] >><<
|
||||
E-O-F
|
||||
|
||||
check
|
||||
|
||||
TEST=2 ########################################
|
||||
|
||||
# Testing CGI_get_post
|
||||
|
||||
CONTENT_TYPE=application/x-www-form-urlencoded \
|
||||
CONTENT_LENGTH=60 \
|
||||
./test CGI_get_post > result 2>&1 <<'E-O-F'
|
||||
one=This+is+a+test&two=%22Bob+Smith%22+%3Cbob%40gmail.com%3E
|
||||
E-O-F
|
||||
|
||||
cat > expected <<'E-O-F'
|
||||
one [0] >>This is a test<<
|
||||
two [0] >>"Bob Smith" <bob@gmail.com><<
|
||||
E-O-F
|
||||
|
||||
check
|
||||
|
||||
TEST=3 ########################################
|
||||
|
||||
# Testing CGI_get_post multipart/form-data
|
||||
|
||||
CONTENT_TYPE='multipart/form-data; boundary=----12345' \
|
||||
./test CGI_get_post > result 2>&1 <<'E-O-F'
|
||||
------12345
|
||||
Content-Disposition: form-data; name="textvar1"
|
||||
|
||||
|
||||
------12345
|
||||
Content-Disposition: form-data; name="doublevar"
|
||||
|
||||
Text data here
|
||||
------12345
|
||||
Content-Disposition: form-data; name="cbvar1"
|
||||
|
||||
cb #1
|
||||
------12345
|
||||
Content-Disposition: form-data; name="cbvar1"
|
||||
|
||||
cb #3
|
||||
------12345
|
||||
Content-Disposition: form-data; name="rbvar1"
|
||||
|
||||
rb #3
|
||||
------12345
|
||||
Content-Disposition: form-data; name="selvar1"
|
||||
|
||||
selval1
|
||||
------12345
|
||||
Content-Disposition: form-data; name="selvar1"
|
||||
|
||||
selval3
|
||||
------12345
|
||||
Content-Disposition: form-data; name="selvar1"
|
||||
|
||||
selval4
|
||||
------12345
|
||||
Content-Disposition: form-data; name="selvar1"
|
||||
|
||||
selval7
|
||||
------12345
|
||||
Content-Disposition: form-data; name="textarea1"
|
||||
|
||||
Initial Line 1
|
||||
Initial Line 2
|
||||
Added Line
|
||||
Another Line
|
||||
------12345
|
||||
Content-Disposition: form-data; name="doublevar"
|
||||
|
||||
OK
|
||||
------12345
|
||||
Content-Disposition: form-data; name="hidden"
|
||||
|
||||
This is three
|
||||
lines of hidden
|
||||
form data
|
||||
------12345--
|
||||
E-O-F
|
||||
|
||||
cat > expected <<'E-O-F'
|
||||
textvar1 [0] >><<
|
||||
doublevar [0] >>Text data here<<
|
||||
doublevar [1] >>OK<<
|
||||
cbvar1 [0] >>cb #1<<
|
||||
cbvar1 [1] >>cb #3<<
|
||||
rbvar1 [0] >>rb #3<<
|
||||
selvar1 [0] >>selval1<<
|
||||
selvar1 [1] >>selval3<<
|
||||
selvar1 [2] >>selval4<<
|
||||
selvar1 [3] >>selval7<<
|
||||
textarea1 [0] >>Initial Line 1
|
||||
Initial Line 2
|
||||
Added Line
|
||||
Another Line<<
|
||||
hidden [0] >>This is three
|
||||
lines of hidden
|
||||
form data<<
|
||||
E-O-F
|
||||
|
||||
check
|
||||
|
||||
TEST=4 ########################################
|
||||
|
||||
# Testing CGI_get_cookie
|
||||
|
||||
HTTP_COOKIE='cookie1=cookie1data; cookie2=cookie2data; cookie3=more-stuff;' \
|
||||
./test CGI_get_cookie > result 2>&1
|
||||
|
||||
cat > expected <<'E-O-F'
|
||||
cookie1 [0] >>cookie1data<<
|
||||
cookie2 [0] >>cookie2data<<
|
||||
cookie3 [0] >>more-stuff<<
|
||||
E-O-F
|
||||
|
||||
check
|
||||
|
||||
TEST=5 ########################################
|
||||
|
||||
# Testing upload
|
||||
|
||||
/bin/rm -f cgi-upload-??????
|
||||
CONTENT_TYPE='multipart/form-data; boundary=----12345' \
|
||||
./test upload > result 2> result <<'E-O-F'
|
||||
------12345
|
||||
Content-Disposition: form-data; name="var1"
|
||||
|
||||
Value # 1
|
||||
------12345
|
||||
Content-Disposition: form-data; name="upload"; filename="input"
|
||||
|
||||
This is a test uploaded file
|
||||
Here is the second line.
|
||||
The quick brown fox jumped over the lazy dog
|
||||
(or was that a hog?)
|
||||
Now is the time for
|
||||
all good men
|
||||
to come to the aid of
|
||||
their party!
|
||||
|
||||
------12345--
|
||||
E-O-F
|
||||
|
||||
F=` echo ./cgi-upload-?????? `
|
||||
|
||||
cat $F >> result
|
||||
|
||||
/bin/rm -f $F
|
||||
|
||||
cat > expected << E-O-F
|
||||
var1 [0] >>Value # 1<<
|
||||
upload [0] >>$F<<
|
||||
upload [1] >>input<<
|
||||
This is a test uploaded file
|
||||
Here is the second line.
|
||||
The quick brown fox jumped over the lazy dog
|
||||
(or was that a hog?)
|
||||
Now is the time for
|
||||
all good men
|
||||
to come to the aid of
|
||||
their party!
|
||||
E-O-F
|
||||
|
||||
check
|
||||
|
||||
TEST=6 ########################################
|
||||
|
||||
# Testing CGI_add_var
|
||||
|
||||
./test CGI_add_var one 'first value' two 'value # 2' \
|
||||
three '3rd-var' two 200% > result 2>&1
|
||||
|
||||
cat > expected <<'E-O-F'
|
||||
one [0] >>first value<<
|
||||
two [0] >>value # 2<<
|
||||
two [1] >>200%<<
|
||||
three [0] >>3rd-var<<
|
||||
E-O-F
|
||||
|
||||
check
|
||||
|
||||
TEST=7 ########################################
|
||||
|
||||
# Testing CGI_encode_varlist
|
||||
|
||||
./test CGI_encode_varlist one 'first value' two 'value # 2' \
|
||||
three '3rd-var' two 200% > result 2>&1
|
||||
|
||||
cat > expected <<'E-O-F'
|
||||
one [0] >>first value<<
|
||||
two [0] >>value # 2<<
|
||||
two [1] >>200%<<
|
||||
three [0] >>3rd-var<<
|
||||
one=first+value&two=value+%23+2&two=200%25&three=3rd-var
|
||||
E-O-F
|
||||
|
||||
check
|
||||
|
||||
TEST=8 ########################################
|
||||
|
||||
# Testing CGI_encode_query
|
||||
|
||||
./test CGI_encode_query one 'first value' two 'value # 2' \
|
||||
three '3rd-var' two 200% > result 2>&1
|
||||
|
||||
cat > expected <<'E-O-F'
|
||||
one=first+value&two=value+%23+2&three=3rd-var&two=200%25
|
||||
one [0] >>first value<<
|
||||
two [0] >>value # 2<<
|
||||
two [1] >>200%<<
|
||||
three [0] >>3rd-var<<
|
||||
E-O-F
|
||||
|
||||
check
|
||||
|
||||
TEST=9 ########################################
|
||||
|
||||
# Testing CGI_encode_url
|
||||
|
||||
./test CGI_encode_url '/etc/passwd holds Unix(TM) accounts.' > result 2>&1
|
||||
|
||||
cat > expected <<'E-O-F'
|
||||
%2Fetc%2Fpasswd+holds+Unix%28TM%29+accounts.
|
||||
/etc/passwd holds Unix(TM) accounts.
|
||||
E-O-F
|
||||
|
||||
check
|
||||
|
||||
|
||||
TEST=10 ########################################
|
||||
|
||||
# Testing CGI_encode_entity
|
||||
|
||||
./test CGI_encode_entity \
|
||||
'if (i > 20 && i < 200) {
|
||||
fputs("OK\n", stdout);
|
||||
}' > result 2>&1
|
||||
cat > expected <<'E-O-F'
|
||||
if (i > 20 && i < 200) { fputs("OK\n", stdout); }
|
||||
E-O-F
|
||||
|
||||
check
|
||||
|
||||
TEST=11 ########################################
|
||||
|
||||
# Testing CGI_encode_base64
|
||||
|
||||
./test CGI_encode_base64 'Now is the time for the quick brown fox, ...' \
|
||||
> result 2>&1
|
||||
cat > expected <<'E-O-F'
|
||||
Tm93IGlzIHRoZSB0aW1lIGZvciB0aGUgcXVpY2sgYnJvd24gZm94LCAuLi4=
|
||||
Now is the time for the quick brown fox, ...
|
||||
E-O-F
|
||||
|
||||
check
|
||||
|
||||
TEST=12 ########################################
|
||||
|
||||
# Testing CGI_encode_hex
|
||||
|
||||
./test CGI_encode_hex 'Now is the time for the quick brown fox, ...' \
|
||||
> result 2>&1
|
||||
cat > expected <<'E-O-F'
|
||||
4E6F77206973207468652074696D6520666F722074686520717569636B2062726F776E20666F782C202E2E2E
|
||||
Now is the time for the quick brown fox, ...
|
||||
E-O-F
|
||||
|
||||
check
|
||||
|
||||
TEST=13 ########################################
|
||||
|
||||
# Testing CGI_encrypt
|
||||
|
||||
./test CGI_encrypt 'Now is the time for the quick brown fox, ...' \
|
||||
> result 2>&1
|
||||
cat > expected <<'E-O-F'
|
||||
enc len = 120
|
||||
dec len = 44 Now is the time for the quick brown fox, ...
|
||||
E-O-F
|
||||
|
||||
check
|
||||
|
||||
|
||||
# clean up
|
||||
|
||||
/bin/rm -f result expected cgi-upload-??????
|
||||
Reference in new issue
Block a user