Annotation of libaitwww/example/test.c, revision 1.1.2.4
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);
! 13: printf("name=%s(%hhx) value=%s(%hhx)\n", c->cgi_name, *c->cgi_name, c->cgi_value, *c->cgi_value);
! 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"));
! 36: cgi1 = www_parseQuery("blahA=this is a string&blahB=this is another string");
! 37: if (!cgi1) {
! 38: printf("Error:: #%d - %s\n", www_GetErrno(), www_GetError());
! 39: www_closeCGI(&cgi);
! 40: return 2;
! 41: }
! 42: printf("\n%s\n%s\n", www_getValue(cgi1, "blahA"), www_getValue(cgi1, "blahB"));
! 43:
! 44: printf("cgi num pairs=%d\n", www_listPairs(cgi, showPair, ".oOo."));
1.1.2.1 misho 45:
1.1.2.2 misho 46: www_closeCGI(&cgi);
47:
1.1.2.4 ! misho 48: www_addValue(cgi1, "oho", "boho");
! 49: printf("\n%s\n", www_getValue(cgi1, "oho"));
! 50: www_delPair(cgi1, "oho");
! 51: printf("\n%s\n", www_getValue(cgi1, "oho"));
! 52: www_delPair(cgi1, "oho");
! 53:
! 54: printf("cgi1 num pairs=%d\n", www_listPairs(cgi1, showPair, NULL));
! 55:
! 56: www_closeCGI(&cgi1);
! 57: } else {
! 58: /* POST test */
! 59: putenv("REQUEST_METHOD=POST");
! 60: putenv("CONTENT_LENGTH=1000");
! 61: putenv("CONTENT_TYPE=application/x-www-form-urlencoded");
! 62: cgi = www_initCGI();
! 63: if (!cgi) {
! 64: printf("Error:: #%d - %s\n", www_GetErrno(), www_GetError());
! 65: return 1;
! 66: }
1.1.2.2 misho 67:
1.1.2.4 ! misho 68: printf("blah=%s\n", www_getValue(cgi, "blah"));
1.1.2.1 misho 69:
1.1.2.4 ! misho 70: printf("num pairs=%d\n", www_listPairs(cgi, showPair, argv[1]));
1.1.2.2 misho 71:
1.1.2.4 ! misho 72: www_closeCGI(&cgi);
! 73: }
1.1.2.1 misho 74: return 0;
75: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>