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