Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Fixes to the CGI handling in althttpd.c. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
6faf1e47b91142fb7e9a39505a8fd79b |
User & Date: | drh 2018-08-08 17:36:12.773 |
Context
2018-08-15
| ||
13:21 | Pre-expand key railroad diagrams in the windowfunctions.html page. (check-in: 61483bc834 user: drh tags: trunk) | |
2018-08-08
| ||
17:36 | Fixes to the CGI handling in althttpd.c. (check-in: 6faf1e47b9 user: drh tags: trunk) | |
2018-08-06
| ||
01:42 | Fix typos in the windowfunction documentation. (check-in: ab3b52646c user: drh tags: trunk) | |
Changes
Changes to misc/althttpd.c.
︙ | ︙ | |||
785 786 787 788 789 790 791 | static int CheckBasicAuthorization(const char *zAuthFile){ FILE *in; char *zRealm = "unknown realm"; char *zLoginPswd; char *zName; char zLine[2000]; | | | 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 | static int CheckBasicAuthorization(const char *zAuthFile){ FILE *in; char *zRealm = "unknown realm"; char *zLoginPswd; char *zName; char zLine[2000]; in = fopen(zAuthFile, "rb"); if( in==0 ){ NotFound(150); /* LOG: Cannot open -auth file */ return 0; } if( zAuthArg ) Decode64(zAuthArg); while( fgets(zLine, sizeof(zLine), in) ){ char *zFieldName; |
︙ | ︙ | |||
1393 1394 1395 1396 1397 1398 1399 | } sprintf(zTmpNamBuf, "/tmp/-post-data-XXXXXX"); zTmpNam = zTmpNamBuf; if( mkstemp(zTmpNam)<0 ){ Malfunction(280, /* LOG: mkstemp() failed */ "Cannot create a temp file in which to store POST data"); } | | | 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 | } sprintf(zTmpNamBuf, "/tmp/-post-data-XXXXXX"); zTmpNam = zTmpNamBuf; if( mkstemp(zTmpNam)<0 ){ Malfunction(280, /* LOG: mkstemp() failed */ "Cannot create a temp file in which to store POST data"); } out = fopen(zTmpNam,"wb"); if( out==0 ){ StartResponse("500 Cannot create /tmp file"); nOut += printf( "Content-type: text/plain\r\n" "\r\n" "Could not open \"%s\" for writing\n", zTmpNam ); |
︙ | ︙ | |||
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 | { "SCRIPT_NAME", &zRealScript }, { "SERVER_NAME", &zServerName }, { "SERVER_PORT", &zServerPort }, { "SERVER_PROTOCOL", &zProtocol }, }; char *zBaseFilename; /* Filename without directory prefix */ int seenContentLength = 0; /* True if Content-length: header seen */ int nRes = 0; /* Bytes of payload */ int nMalloc = 0; /* Bytes of space allocated to aRes */ char *aRes = 0; /* Payload */ /* If its executable, it must be a CGI program. Start by ** changing directories to the directory holding the program. */ | > | 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 | { "SCRIPT_NAME", &zRealScript }, { "SERVER_NAME", &zServerName }, { "SERVER_PORT", &zServerPort }, { "SERVER_PROTOCOL", &zProtocol }, }; char *zBaseFilename; /* Filename without directory prefix */ int seenContentLength = 0; /* True if Content-length: header seen */ int contentLength = 0; /* The content length */ int nRes = 0; /* Bytes of payload */ int nMalloc = 0; /* Bytes of space allocated to aRes */ char *aRes = 0; /* Payload */ /* If its executable, it must be a CGI program. Start by ** changing directories to the directory holding the program. */ |
︙ | ︙ | |||
1692 1693 1694 1695 1696 1697 1698 | } close(px[1]); for(i=3; close(i)==0; i++){} execl(zBaseFilename, zBaseFilename, (char*)0); exit(0); } close(px[1]); | | | 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 | } close(px[1]); for(i=3; close(i)==0; i++){} execl(zBaseFilename, zBaseFilename, (char*)0); exit(0); } close(px[1]); in = fdopen(px[0], "rb"); } if( in==0 ){ CgiError(); } /* Read and process the first line of the header returned by the ** CGI script. |
︙ | ︙ | |||
1717 1718 1719 1720 1721 1722 1723 | int i; for(i=7; isspace(zLine[i]); i++){} nOut += printf("%s %s", zProtocol, &zLine[i]); strncpy(zReplyStatus, &zLine[i], 3); zReplyStatus[3] = 0; statusSent = 1; }else{ | > | > | | 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 | int i; for(i=7; isspace(zLine[i]); i++){} nOut += printf("%s %s", zProtocol, &zLine[i]); strncpy(zReplyStatus, &zLine[i], 3); zReplyStatus[3] = 0; statusSent = 1; }else{ /* 123456789 12345 */ if( strncasecmp(zLine, "Content-length:", 15)==0 ){ seenContentLength = 1; contentLength = atoi(zLine+15); } StartResponse("200 OK"); nOut += printf("%s",zLine); } } /* Copy everything else thru without change or analysis. */ StartResponse("200 OK"); if( useTimeout ) alarm(60*5); if( seenContentLength ){ nOut += printf("%s", zLine); while( (contentLength--)>0 && (c = getc(in))!=EOF ){ putc(c,stdout); nOut++; } }else{ nRes = 0; nMalloc = 1000; aRes = malloc(nMalloc+1); |
︙ | ︙ | |||
1783 1784 1785 1786 1787 1788 1789 | nOut += printf("Cache-Control: max-age=%d\r\n", mxAge); nOut += printf("ETag: \"%s\"\r\n", zETag); nOut += printf("\r\n"); fflush(stdout); MakeLogEntry(0, 470); /* LOG: ETag Cache Hit */ return; } | | | 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 | nOut += printf("Cache-Control: max-age=%d\r\n", mxAge); nOut += printf("ETag: \"%s\"\r\n", zETag); nOut += printf("\r\n"); fflush(stdout); MakeLogEntry(0, 470); /* LOG: ETag Cache Hit */ return; } in = fopen(zFile,"rb"); if( in==0 ) NotFound(480); /* LOG: fopen() failed for static content */ StartResponse("200 OK"); nOut += DateTag("Last-Modified", statbuf.st_mtime); nOut += printf("Cache-Control: max-age=%d\r\n", mxAge); nOut += printf("ETag: \"%s\"\r\n", zETag); nOut += printf("Content-type: %s\r\n",zContentType); nOut += printf("Content-length: %d\r\n\r\n",(int)statbuf.st_size); |
︙ | ︙ |