File:
[ELWIX - Embedded LightWeight unIX -] /
libaitwww /
example /
test.c
Revision
1.4:
download - view:
text,
annotated -
select for diffs -
revision graph
Thu May 30 09:25:35 2013 UTC (11 years, 3 months ago) by
misho
Branches:
MAIN
CVS tags:
www3_4,
www3_3,
www3_2,
www3_1,
WWW3_3,
WWW3_2,
WWW3_1,
WWW3_0,
HEAD
version 3.0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <aitwww.h>
static int
showPair(struct tagCGI *c, void *arg)
{
if (arg)
printf("ARG=%s ... ", arg);
printf("next=%p ... ", c->cgi_node.sle_next);
printf("name=%s value=%s\n", AIT_GET_STR(c->cgi_name), AIT_GET_STR(c->cgi_value));
return 0;
}
int
main(int argc, char **argv)
{
int ret;
cgi_t *cgi, *cgi1;
if (argc < 2) {
/* GET test */
putenv("QUERY_STRING=test1=abra+kadabra&testche=piuk%20mdaa");
putenv("CONENT_LENGTH=390");
putenv("REQUEST_METHOD=GET");
cgi = www_initCGI();
if (!cgi) {
printf("Error:: #%d - %s\n", www_GetErrno(), www_GetError());
return 1;
}
printf("%s\n%s\n", www_getValue(cgi, "testche"), www_getValue(cgi, "test1"));
cgi1 = www_parseQuery("blahA=this%20is+a%20string&blahB=this is another string");
if (!cgi1) {
printf("Error:: #%d - %s\n", www_GetErrno(), www_GetError());
www_closeCGI(&cgi);
return 2;
}
printf("\n%s\n%s\n", www_getValue(cgi1, "blahA"), www_getValue(cgi1, "blahB"));
printf("cgi num pairs=%d\n", www_listPairs(cgi, showPair, ".oOo."));
www_closeCGI(&cgi);
www_addValue(cgi1, "oho", "boho");
printf("\n%s\n", www_getValue(cgi1, "oho"));
www_delPair(cgi1, "oho");
printf("\n%s\n", www_getValue(cgi1, "oho"));
www_delPair(cgi1, "oho");
printf("cgi1 num pairs=%d\n", www_listPairs(cgi1, showPair, NULL));
www_closeCGI(&cgi1);
} else {
/* POST test */
putenv("REQUEST_METHOD=POST");
putenv("CONTENT_LENGTH=1000");
if (!strcmp(argv[1], "multi"))
putenv("CONTENT_TYPE=multipart/form-data; boundary=012345678909876543210");
else
putenv("CONTENT_TYPE=application/x-www-form-urlencoded");
cgi = www_initCGI();
if (!cgi) {
printf("Error:: #%d - %s\n", www_GetErrno(), www_GetError());
return 1;
}
printf("blah=%s\n", www_getValue(cgi, "blah"));
printf("num pairs=%d\n", www_listPairs(cgi, showPair, argv[1]));
www_closeCGI(&cgi);
}
return 0;
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>