ImageVerifierCode 换一换
你正在下载:

cgi.docx

[预览]
格式:DOCX , 页数:33 ,大小:21.09KB ,
资源ID:1272899      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-1272899.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(cgi.docx)为本站会员(b****1)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

cgi.docx

1、cgi/* cgi.c */#include #include #include cgivars.h#include htmllib.h#include template.hint main() char *postvars = NULL; /* POST request data repository */ char *getvars = NULL; /* GET request data repository */ int form_method; /* POST = 1, GET = 0 */ form_method = getRequestMethod(); if(form_metho

2、d = POST) getvars = getGETvars(); postvars = getPOSTvars(); else if(form_method = GET) getvars = getGETvars(); htmlHeader(Demo Web Page); htmlBody(); template_page(postvars, form_method); htmlFooter(); cleanUp(form_method, getvars, postvars); fflush(stdout); return(0);/* htmllib.c * HTML common libr

3、ary functions for the CGI programs. */#include #include htmllib.hvoid htmlHeader(char *title) printf(Content-type: text/htmlnn%s, title);void htmlBody() printf();void htmlFooter() printf();void addTitleElement(char *title) printf(%s, title);/* cgivars.c * (C) Copyright 2000, Moreton Bay (). * see HT

4、TP (www.w3.org) and RFC */ #include cgivars.h#include #include #include #include #include #include #include #include #include static voidcatchchild() char buf40; pid_t pid; int status; /*signal(SIGCHLD, catchchild);*/ /* Unneeded */ pid = wait4(-1, &status, WUNTRACED, 0); if (WIFSTOPPED(status) spri

5、ntf(buf, sh %d: Child %d stoppedn, getpid(), pid); else sprintf(buf, sh %d: Child %d diedn, getpid(), pid); /if (intcrlf) / write(STDOUT, n, 1); write(STDOUT, buf, strlen(buf); setenv (NIOSSHELL,buf ,1);int execfile(cmd, bg, fplog) char *cmd; int bg; FILE *fplog; int pid; char *myargvMAXARGS; struct

6、 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 characters in the expanded command, so do the fork and * exec ourself. If this fails with ENOEXE

7、C, 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 not to modify any globals after the vfork ! */ signal(SIGINT, SIG_DFL); signal(SIGQUIT, SIG_DF

8、L); signal(SIGCHLD, SIG_DFL); execvp(myargv0, myargv); printf(%s: %sn, myargv0, (errno = ENOENT) ? Bad command or file name : strerror(errno); fprintf(fplog, %s: %sn, myargv0, (errno = ENOENT) ? Bad command or file name : strerror(errno); _exit(0); if (pid = A ? (hex0 & 0xdf) - A) + 10 : (hex0 - 0);

9、 char_value *= 16; char_value += (hex1 = A ? (hex1 & 0xdf) - A) + 10 : (hex1 - 0); return char_value;/* unescape_url */* RFC */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

10、 or POST) on success, * -1 on failure. */int getRequestMethod() char *request_method; int form_method; request_method = getenv(REQUEST_METHOD); if(request_method = NULL) return -1; if (!strcmp(request_method, GET) | !strcmp(request_method, HEAD) ) form_method = GET; else if (!strcmp(request_method,

11、POST) form_method = POST; else /* wtf was it then?! */ return -1; return form_method;/* getGETvars * retn: getvars */char *getGETvars() int i; char *getvars; char *getinput; char *pairlist; int paircount = 0; char *nvpair; char *eqpos; getinput = getenv(QUERY_STRING); if (getinput) getinput = strdup

12、(getinput); /* Change all plusses back to spaces */ for(i=0; getinput & getinputi; i+) if(getinputi = +) getinputi = ; pairlist = (char *) malloc(256*sizeof(char *); paircount = 0; nvpair = getinput ? strtok(getinput, &) : NULL; while (nvpair) pairlistpaircount+= strdup(nvpair); if(!(paircount%256)

13、pairlist = (char *) realloc(pairlist,(paircount+256)*sizeof(char *); nvpair = strtok(NULL, &); pairlistpaircount = 0; getvars = (char *) malloc(paircount*2+1)*sizeof(char *); for (i= 0; ipaircount; i+) if(eqpos=strchr(pairlisti, =) *eqpos = 0; unescape_url(getvarsi*2+1 = strdup(eqpos+1); else unesca

14、pe_url(getvarsi*2+1 = strdup(); unescape_url(getvarsi*2 = strdup(pairlisti); getvarspaircount*2 = 0; for(i=0;pairlisti;i+) free(pairlisti); free(pairlist); if (getinput) free(getinput); return getvars;/* getPOSTvars * retn: postvars */char *getPOSTvars() int i,j,k; int content_length; char *postvars

15、; char *postinput; char *pairlist; int paircount = 0; char *nvpair; char *eqpos; char *content_type; FILE *df; FILE *fplog = fopen(/log.txt,w); if( NULL = fplog ) printf(%s nicht gefunden!n, log.txt); exit (1); content_type = getenv(CONTENT_TYPE); if (!content_type) fprintf(fplog,no Content typen);

16、fclose(fplog); exit (1); /df = fopen(/content.html, w); /fwrite(content_type,1,(int)strlen(content_type),df); /fclose(df); postinput = getenv(CONTENT_LENGTH); if (!postinput) fprintf(fplog,no Content lengthn); fclose(fplog); exit (1); if(!(content_length = atoi(postinput) fprintf(fplog,no Content ty

17、pen); fclose(fplog); exit (1); if(!(postinput = (char *) malloc(content_length+1) fprintf(fplog,no Content typen); fclose(fplog); exit (1); if (!fread(postinput, content_length, 1, stdin) fprintf(fplog,no Content typen); fclose(fplog); exit (1); postinputcontent_length = 0; /df = fopen(/post.html, w

18、); /fwrite(postinput,1,content_length,df); /fclose(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;i+) if(postinputi = +) postinputi = ; pairlist = (char *) malloc

19、(256*sizeof(char *); paircount = 0; nvpair = strtok(postinput, &); while (nvpair) pairlistpaircount+ = strdup(nvpair); if(!(paircount%256) pairlist = (char *) realloc(pairlist, (paircount+256)*sizeof(char *); nvpair = strtok(NULL, &); pairlistpaircount = 0; postvars = (char *) malloc(paircount*2+1)*

20、sizeof(char *); for(i = 0;ipaircount;i+) if(eqpos = strchr(pairlisti, =) *eqpos= 0; unescape_url(postvarsi*2+1 = strdup(eqpos+1); else unescape_url(postvarsi*2+1 = strdup(); unescape_url(postvarsi*2= strdup(pairlisti); postvarspaircount*2 = 0; for(i=0;pairlisti;i+) free(pairlisti); free(pairlist); f

21、ree(postinput); fprintf(fplog,extracted all pairsn); unsigned long ledG=0;/read value unsigned long ledR=0; unsigned long buttons=0; unsigned long switches=0; char lcd117 = ; lcd116=0x00; char lcd217 = ; lcd216=0x00; char sevseg9= 0, 0, 0, 0, 0, 0, 0, 0, 0x00 ; unsigned long seg = 0; int lcd_changed

22、=0; int seg7_changed=0; int ledR_changed=0; int ledG_changed=0; for (i=0; postvarsi; i+= 2) fprintf(fplog,DEBUG: %s = %sn, i, postvarsi, postvarsi+1); if(strstr(postvarsi,LEDR) if (*(postvarsi+4)=1) /ledR &= (10); ledR |= 10; else if (*(postvarsi+4)=2) ledR |= 11; else if (*(postvarsi+4)=3) ledR |=

23、12; else if (*(postvarsi+4)=4) ledR |= 13; else if (*(postvarsi+4)=5) ledR |= 14; else if (*(postvarsi+4)=6) ledR |= 15; else if (*(postvarsi+4)=7) ledR |= 16; else if (*(postvarsi+4)=8) ledR |= 17; else if (*(postvarsi+4)=9) ledR |= 18; else if (*(postvarsi+4)=A) ledR |= 19; else if (*(postvarsi+4)

24、=B) ledR |= 110; else if (*(postvarsi+4)=C) ledR |= 111; else if (*(postvarsi+4)=D) ledR |= 112; else if (*(postvarsi+4)=E) ledR |= 113; else if (*(postvarsi+4)=F) ledR |= 114; else if (*(postvarsi+4)=G) ledR |= 115; else if (*(postvarsi+4)=H) ledR |= 116; else if (*(postvarsi+4)=I) ledR |= 117; ledR_changed=1; fprintf(fplog,DEBUG: %s = %s : LEDR = %08Xn, i, postvarsi, postvarsi+1, ledR); else if(strstr(postvarsi,LEDG) if (*(postvarsi+4)=1) ledG |= 10; else if (*(postvarsi+4)=2) ledG |= 11; else if (*(postvarsi+4)=3) ledG |= 12; else if (*(postvarsi

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2