1、HEADTITLE%s/HEAD, title);void htmlBody() BODYvoid htmlFooter() /BODY/HTMLvoid addTitleElement(char *title) H1/H1, title);/* cgivars.c * (C) Copyright 2000, Moreton Bay (). * see HTTP (www.w3.org) and RFC */stdlib.hsignal.herrno.hunistd.hsys/stat.hsys/time.hsys/wait.hstatic voidcatchchild() char buf4
2、0; pid_t pid; int status; /*signal(SIGCHLD, catchchild);*/ /* Unneeded */ pid = wait4(-1, &status, WUNTRACED, 0); if (WIFSTOPPED(status) sprintf(buf, sh %d: Child %d stoppedn, getpid(), pid); else Child %d diedn /if (intcrlf) / write(STDOUT, n, 1); write(STDOUT, buf, strlen(buf); setenv (NIOSSHELL,b
3、uf ,1);int execfile(cmd, bg, fplog) char *cmd; int bg; FILE *fplog; int pid; char *myargvMAXARGS; struct sigaction act; int j=0; /myargvj+ = strtok (/bin/nios2io wd 80681070 127, myargvj+ = strtok (cmd, while (jMAXARGS&(myargvj+=strtok(NULL,)!=NULL); if (bg=0) signal(SIGCHLD, SIG_DFL); /* * No magic
4、 characters in the expanded command, so do the fork and * exec ourself. If this fails with ENOEXEC, then run the * shell anyway since it might be a shell script. if (!(pid = vfork() int ci; /* * We are the child, so run the program. * First close any extra file descriptors we have opened. * be sure
5、not to modify any globals after the vfork ! */ signal(SIGINT, SIG_DFL); signal(SIGQUIT, SIG_DFL); execvp(myargv0, myargv); printf(%s: %sn, myargv0, (errno = ENOENT) ?Bad command or file name : strerror(errno); fprintf(fplog, _exit(0); if (pid = A ? (hex0 & 0xdf) - ) + 10 : (hex0 - 0); char_value *=
6、16; char_value += (hex1 (hex1 & (hex1 - return char_value;/* unescape_url */void unescape_url(char *url) int n, k; for(n=0, k=0;urlk;+n, +k) if(urln = urlk) = %) urln = hex2char(&urlk+1); k += 2; urln = 0;/* getRequestMethod * retn: from_method (GET or POST) on success, * -1 on failure. */int getReq
7、uestMethod() char *request_method; request_method = getenv(REQUEST_METHOD if(request_method = NULL) return -1;strcmp(request_method, GET) | !HEAD) ) form_method = GET; else if (!POST) form_method = POST; else /* wtf was it then?! return form_method;/* getGETvars getvars */char *getGETvars() int i; c
8、har *getvars; char *getinput; char *pairlist; int paircount = 0; char *nvpair; char *eqpos; getinput = getenv(QUERY_STRING if (getinput) getinput = strdup(getinput); /* Change all plusses back to spaces */ for(i=0; getinput & getinputi; i+) if(getinputi = +) getinputi = pairlist = (char *) malloc(25
9、6*sizeof(char *); paircount = 0; nvpair = getinput ? strtok(getinput, ) : NULL; while (nvpair) pairlistpaircount+= strdup(nvpair); if(!(paircount%256) pairlist = (char *) realloc(pairlist,(paircount+256)*sizeof(char *); nvpair = strtok(NULL, pairlistpaircount = 0; getvars = (char *) malloc(paircount
10、*2+1)*sizeof(char *); for (i= 0; ipaircount; i+) if(eqpos=strchr(pairlisti, = *eqpos = unescape_url(getvarsi*2+1 = strdup(eqpos+1); else unescape_url(getvarsi*2+1 = strdup( unescape_url(getvarsi*2 = strdup(pairlisti); getvarspaircount*2 = 0;pairlisti;i+) free(pairlisti); free(pairlist); free(getinpu
11、t); return getvars;/* getPOSTvars postvars */char *getPOSTvars() int i,j,k; int content_length; char *postvars; char *postinput; char *content_type; FILE *df; FILE *fplog = fopen(/log.txtw if( NULL = fplog ) %s nicht gefunden!, log.txt exit (1); content_type = getenv(CONTENT_TYPEcontent_type) no Con
12、tent typen fclose(fplog); /df = fopen(/content.html /fwrite(content_type,1,(int)strlen(content_type),df); /fclose(df); postinput = getenv(CONTENT_LENGTHpostinput) no Content lengthn if(!(content_length = atoi(postinput) (postinput = (char *) malloc(content_length+1) fread(postinput, content_length,
13、1, stdin) postinputcontent_length = /post.html /fwrite(postinput,1,content_length,df); /fprintf(fplog,wrote post.htmln char stringToFind=multipart/form-data; boundary= /for normal html post requests if (NULL = strstr(content_type, stringToFind) for(i=0;postinputi; if(postinputi = postinputi = pairli
14、st = (char *) malloc(256*sizeof(char *); nvpair = strtok(postinput, pairlistpaircount+ = strdup(nvpair); pairlist = (char *) realloc(pairlist, (paircount+256)*sizeof(char *); nvpair = strtok(NULL, pairlistpaircount = 0; postvars = (char *) malloc(paircount*2+1)*sizeof(char *); for(i = 0;iDEBUG: %s =
15、 %sn, i, postvarsi, postvarsi+1); if(strstr(postvarsi,LEDR if (*(postvarsi+4)=1 /ledR &= (10); ledR |= 10; else if (*(postvarsi+4)=21;32;43;54;65;76;87;98;9;B10;C11;D12;E13;F14;G15;H16;I17; ledR_changed=1; %s = %s : LEDR = %08Xn, i, postvarsi, postvarsi+1, ledR); else if(strstr(postvarsi,LEDG ledG |= 1 else if (*(postvarsi
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2