Annotation of libaitwww/example/test.c, revision 1.3
1.2 misho 1: #include <stdio.h>
2: #include <stdlib.h>
3: #include <aitwww.h>
4:
5:
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.3 ! misho 13: printf("name=%s value=%s\n", AIT_GET_STR(c->cgi_name), AIT_GET_STR(c->cgi_value));
1.2 misho 14: return 0;
15: }
16:
17:
18: int
19: main(int argc, char **argv)
20: {
21: int ret;
22: cgi_t *cgi, *cgi1;
23:
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"));
36:
1.3 ! misho 37: cgi1 = www_parseQuery("blahA=this%20is+a%20string&blahB=this is another string");
1.2 misho 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."));
46:
47: www_closeCGI(&cgi);
48:
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 {
59: /* POST test */
60: putenv("REQUEST_METHOD=POST");
61: putenv("CONTENT_LENGTH=1000");
62: if (!strcmp(argv[1], "multi"))
63: putenv("CONTENT_TYPE=multipart/form-data; boundary=012345678909876543210");
64: else
65: putenv("CONTENT_TYPE=application/x-www-form-urlencoded");
66:
67: cgi = www_initCGI();
68: if (!cgi) {
69: printf("Error:: #%d - %s\n", www_GetErrno(), www_GetError());
70: return 1;
71: }
72:
73: printf("blah=%s\n", www_getValue(cgi, "blah"));
74:
75: printf("num pairs=%d\n", www_listPairs(cgi, showPair, argv[1]));
76:
77: www_closeCGI(&cgi);
78: }
79: return 0;
80: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>