Annotation of libaitwww/example/test.c, revision 1.1.2.6
1.1.2.1 misho 1: #include <stdio.h>
2: #include <stdlib.h>
3: #include <aitwww.h>
4:
5:
1.1.2.4 misho 6: static int
7: showPair(struct tagCGI *c, void *arg)
8: {
9: if (arg)
10: printf("ARG=%s ... ", arg);
11:
12: printf("next=%p ... ", c->cgi_node.sle_next);
1.1.2.5 misho 13: printf("name=%s value=%s\n", c->cgi_name, c->cgi_value);
1.1.2.4 misho 14: return 0;
15: }
16:
17:
1.1.2.1 misho 18: int
1.1.2.4 misho 19: main(int argc, char **argv)
1.1.2.1 misho 20: {
1.1.2.2 misho 21: int ret;
22: cgi_t *cgi, *cgi1;
1.1.2.1 misho 23:
1.1.2.4 misho 24: if (argc < 2) {
25: /* GET test */
26: putenv("QUERY_STRING=test1=abra+kadabra&testche=piuk%20mdaa");
27: putenv("CONENT_LENGTH=390");
28: putenv("REQUEST_METHOD=GET");
29: cgi = www_initCGI();
30: if (!cgi) {
31: printf("Error:: #%d - %s\n", www_GetErrno(), www_GetError());
32: return 1;
33: }
34:
35: printf("%s\n%s\n", www_getValue(cgi, "testche"), www_getValue(cgi, "test1"));
1.1.2.5 misho 36:
1.1.2.4 misho 37: cgi1 = www_parseQuery("blahA=this is a string&blahB=this is another string");
38: if (!cgi1) {
39: printf("Error:: #%d - %s\n", www_GetErrno(), www_GetError());
40: www_closeCGI(&cgi);
41: return 2;
42: }
43: printf("\n%s\n%s\n", www_getValue(cgi1, "blahA"), www_getValue(cgi1, "blahB"));
44:
45: printf("cgi num pairs=%d\n", www_listPairs(cgi, showPair, ".oOo."));
1.1.2.1 misho 46:
1.1.2.2 misho 47: www_closeCGI(&cgi);
48:
1.1.2.4 misho 49: www_addValue(cgi1, "oho", "boho");
50: printf("\n%s\n", www_getValue(cgi1, "oho"));
51: www_delPair(cgi1, "oho");
52: printf("\n%s\n", www_getValue(cgi1, "oho"));
53: www_delPair(cgi1, "oho");
54:
55: printf("cgi1 num pairs=%d\n", www_listPairs(cgi1, showPair, NULL));
56:
57: www_closeCGI(&cgi1);
58: } else {
1.1.2.5 misho 59: /* POST test */
1.1.2.4 misho 60: putenv("REQUEST_METHOD=POST");
61: putenv("CONTENT_LENGTH=1000");
1.1.2.5 misho 62: if (!strcmp(argv[1], "multi"))
1.1.2.6 ! misho 63: putenv("CONTENT_TYPE=multipart/form-data; boundary=012345678909876543210");
1.1.2.5 misho 64: else
65: putenv("CONTENT_TYPE=application/x-www-form-urlencoded");
66:
1.1.2.4 misho 67: cgi = www_initCGI();
68: if (!cgi) {
69: printf("Error:: #%d - %s\n", www_GetErrno(), www_GetError());
70: return 1;
71: }
1.1.2.2 misho 72:
1.1.2.4 misho 73: printf("blah=%s\n", www_getValue(cgi, "blah"));
1.1.2.1 misho 74:
1.1.2.4 misho 75: printf("num pairs=%d\n", www_listPairs(cgi, showPair, argv[1]));
1.1.2.2 misho 76:
1.1.2.4 misho 77: www_closeCGI(&cgi);
78: }
1.1.2.1 misho 79: return 0;
80: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>