File:  [ELWIX - Embedded LightWeight unIX -] / libaitwww / example / test.c
Revision 1.1.2.4: download - view: text, annotated - select for diffs - revision graph
Fri Mar 9 12:33:41 2012 UTC (12 years, 3 months ago) by misho
Branches: www1_0
add new function for easy dump CGI session elements

    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);
   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: 
   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: 		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."));
   45: 
   46: 		www_closeCGI(&cgi);
   47: 
   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: 		}
   67: 
   68: 		printf("blah=%s\n", www_getValue(cgi, "blah"));
   69: 
   70: 		printf("num pairs=%d\n", www_listPairs(cgi, showPair, argv[1]));
   71: 
   72: 		www_closeCGI(&cgi);
   73: 	}
   74: 	return 0;
   75: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>