*** http-gw.c 1997/08/19 19:17:30 1.14 --- http-gw.c 1998/02/06 23:32:25 *************** *** 14,20 **** * 13-Jun-1996 Screening functions for Java, JavaScript. (carl@hdshq.com) * 27-Jun-1996 Added screening for ActiveX. (carl@hdshq.com) */ ! static char RcsId[] = "$Header: /home/rmurphy/fwtk/fwtk/http-gw/RCS/http-gw.c,v 1.14 1997/08/19 19:17:30 rick Exp $"; #include "http-gw.h" --- 14,20 ---- * 13-Jun-1996 Screening functions for Java, JavaScript. (carl@hdshq.com) * 27-Jun-1996 Added screening for ActiveX. (carl@hdshq.com) */ ! static char RcsId[] = "$Header: /home/rmurphy/fwtk/fwtk/http-gw/RCS/http-gw.c,v 1.17 1998/02/06 23:32:20 rmurphy Exp $"; #include "http-gw.h" *************** *** 78,83 **** --- 78,85 ---- static char *html_readptr; static int html_len; + static char *html_headers; + static int html_hlen; int html_read(rfd, buf, cnt) int rfd, cnt; *************** *** 86,91 **** --- 88,106 ---- int x; if( rfd == -1){ + if(html_headers != NULL) { + if(html_hlen < cnt) + cnt = html_hlen; + if(cnt != 0) { + for (x=0; x < cnt; x++) + *buf++ = *html_headers++; + html_hlen -= cnt; + if(html_hlen <= 0) + html_headers = NULL; + return cnt; + } + html_headers = NULL; + } if( html_len <= 0) return 0; if( html_len < cnt) *************** *** 123,128 **** --- 138,156 ---- p = (char *) t->data; if( ishtml){ + static char response[512]; + char *p1; + + p1 = strrchr(t->name, '.'); + if (p1 && !strncmp(p1, ".gif", 4)) { + sprintf(response, + "HTTP/1.0 200 OK\r\nContent-type: image/gif\r\nContent-length: %d\r\n\r\n", len); + } else { + sprintf(response, + "HTTP/1.0 200 OK\r\nContent-type: text/html\r\nContent-length: %d\r\n\r\n", len); + } + html_headers = response; + html_hlen = strlen(response); html_readptr = p; html_len = len; return 2; *************** *** 1188,1194 **** cnt = sizeof(http_buffer); if( (n = html_read(rfd, http_buffer, cnt)) > 0){ inbytcnt += n; ! if( n != net_write(sockfd, http_buffer, n)) goto broken; }else break; --- 1216,1222 ---- cnt = sizeof(http_buffer); if( (n = html_read(rfd, http_buffer, cnt)) > 0){ inbytcnt += n; ! if( sockfd != -1 && n != net_write(sockfd, http_buffer, n)) goto broken; }else break; *************** *** 1326,1332 **** cnt = sizeof(http_buffer); if( len > 0 && cnt > len) cnt = len; ! if( (n = net_read(rfd, http_buffer, cnt)) > 0){ inbytcnt += n; if( sockfd != -1)net_write(sockfd, http_buffer, n); if( len > 0) --- 1354,1360 ---- cnt = sizeof(http_buffer); if( len > 0 && cnt > len) cnt = len; ! if( (n = html_read(rfd, http_buffer, cnt)) > 0){ inbytcnt += n; if( sockfd != -1)net_write(sockfd, http_buffer, n); if( len > 0) *************** *** 1616,1622 **** while(1){ bp = errbuf; ! cnt = net_read(rfd, errbuf, sizeof(errbuf)); if( first && (rem_type & TYPE_PLUS)){ first = 0; --- 1644,1650 ---- while(1){ bp = errbuf; ! cnt = html_read(rfd, errbuf, sizeof(errbuf)); if( first && (rem_type & TYPE_PLUS)){ first = 0; *************** *** 1826,1832 **** if( cnt > sizeof(http_buffer)) cnt = sizeof(http_buffer); ! cnt = net_read(sockfd, http_buffer, cnt); if( cnt <= 0) break; if( rfd != -1){ /* allow write? */ --- 1854,1860 ---- if( cnt > sizeof(http_buffer)) cnt = sizeof(http_buffer); ! cnt = html_read(sockfd, http_buffer, cnt); if( cnt <= 0) break; if( rfd != -1){ /* allow write? */ *** hmain.c 1998/01/13 23:15:24 1.11 --- hmain.c 1998/02/06 23:32:16 *************** *** 16,22 **** * 27-Jul-1996 Implement ActiveX screening (cvc) */ ! static char RcsId[] = "$Header: /home/rmurphy/fwtk/fwtk/http-gw/RCS/hmain.c,v 1.11 1998/01/13 23:15:24 rmurphy Exp $"; int nojava=0; /* set on to block Java */ int nojavascript=0; /* set on to block JavaScript */ --- 16,22 ---- * 27-Jul-1996 Implement ActiveX screening (cvc) */ ! static char RcsId[] = "$Header: /home/rmurphy/fwtk/fwtk/http-gw/RCS/hmain.c,v 1.12 1998/02/06 23:32:11 rmurphy Exp $"; int nojava=0; /* set on to block Java */ int nojavascript=0; /* set on to block JavaScript */ *************** *** 854,865 **** int ret = -1; while(1) { ! if(net_read(fd,(char *)&buf[x],1) != 1) goto done; /* get \r\n - read a char and throw it away */ if(buf[x] == '\r') { ! if(net_read(fd,(char *)&buf[x],1) != 1) goto done; buf[x] = '\0'; ret = x; --- 854,865 ---- int ret = -1; while(1) { ! if(html_read(fd,(char *)&buf[x],1) != 1) goto done; /* get \r\n - read a char and throw it away */ if(buf[x] == '\r') { ! if(html_read(fd,(char *)&buf[x],1) != 1) goto done; buf[x] = '\0'; ret = x; *************** *** 876,888 **** unsigned char j; unsigned char jbuf[4]; ! if(net_read(fd,&j,1) != 1) goto done; switch(j) { case WILL: case WONT: ! if(net_read(fd,(char *)&j,1) != 1) goto done; jbuf[0] = IAC; jbuf[1] = DONT; --- 876,888 ---- unsigned char j; unsigned char jbuf[4]; ! if(html_read(fd,&j,1) != 1) goto done; switch(j) { case WILL: case WONT: ! if(html_read(fd,(char *)&j,1) != 1) goto done; jbuf[0] = IAC; jbuf[1] = DONT; *************** *** 892,898 **** continue; case DO: case DONT: ! if(net_read(fd,(char *)&j,1) != 1) goto done; jbuf[0] = IAC; jbuf[1] = WONT; --- 892,898 ---- continue; case DO: case DONT: ! if(html_read(fd,(char *)&j,1) != 1) goto done; jbuf[0] = IAC; jbuf[1] = WONT; *************** *** 904,910 **** x = 0; continue; case IP: ! if(net_read(fd,(char *)&j,1) != 1) goto done; if(j == DM) x = 0; --- 904,910 ---- x = 0; continue; case IP: ! if(html_read(fd,(char *)&j,1) != 1) goto done; if(j == DM) x = 0; *************** *** 1062,1068 **** return(1); } if( FD_ISSET(0, &rdset)){ ! cnt = net_read(0, buf, 8192); if( cnt == 0) break; if( cnt < 0){ --- 1062,1068 ---- return(1); } if( FD_ISSET(0, &rdset)){ ! cnt = html_read(0, buf, 8192); if( cnt == 0) break; if( cnt < 0){ *************** *** 1075,1081 **** outbytcnt += cnt; } if( FD_ISSET(rfd, &rdset)){ ! cnt = net_read(rfd, buf, 8192); if( cnt == 0) break; if( cnt < 0){ --- 1075,1081 ---- outbytcnt += cnt; } if( FD_ISSET(rfd, &rdset)){ ! cnt = html_read(rfd, buf, 8192); if( cnt == 0) break; if( cnt < 0){ *************** *** 1139,1145 **** { int xstate = 0; /* simple state machine. */ while (1) { ! if (net_read(0, buf, 1) != 1) return; if ((xstate == 0 || xstate ==1) && buf[0] == '\n') { break; } else if (xstate == 0 && buf[0] == '\r') { --- 1139,1145 ---- { int xstate = 0; /* simple state machine. */ while (1) { ! if (html_read(0, buf, 1) != 1) return; if ((xstate == 0 || xstate ==1) && buf[0] == '\n') { break; } else if (xstate == 0 && buf[0] == '\r') { *************** *** 1167,1173 **** return(1); } if( FD_ISSET(0, &rdset)){ ! cnt = net_read(0, buf, 8192); if( cnt == 0) break; if( cnt < 0){ --- 1167,1173 ---- return(1); } if( FD_ISSET(0, &rdset)){ ! cnt = html_read(0, buf, 8192); if( cnt == 0) break; if( cnt < 0){ *************** *** 1180,1186 **** outbytcnt += cnt; } if( FD_ISSET(rfd, &rdset)){ ! cnt = net_read(rfd, buf, 8192); if( cnt == 0) break; if( cnt < 0){ --- 1180,1186 ---- outbytcnt += cnt; } if( FD_ISSET(rfd, &rdset)){ ! cnt = html_read(rfd, buf, 8192); if( cnt == 0) break; if( cnt < 0){