⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thttpd_patch

📁 php-4.4.7学习linux时下载的源代码
💻
📖 第 1 页 / 共 5 页
字号:
+    hc->range_if = (time_t) -1;+    hc->contentlength = -1;+    hc->type = "";+    hc->hostname = (char*) 0;+    hc->mime_flag = 1;+    hc->one_one = 0;+    hc->got_range = 0;+    hc->tildemapped = 0;+    hc->init_byte_loc = 0;+    hc->end_byte_loc = -1;+    hc->keep_alive = 0;+    hc->do_keep_alive = 0;+    hc->should_linger = 0;+    hc->file_address = (char*) 0;+    hc->read_body_into_mem = 0;+    return GC_OK;+}++int httpd_get_conn( httpd_server* hs, int listen_fd, httpd_conn* hc )     {     httpd_sockaddr sa;@@ -1612,6 +1759,7 @@ 	{ 	hc->read_size = 0; 	httpd_realloc_str( &hc->read_buf, &hc->read_size, 500 );+	hc->read_buf_is_mmap = 0; 	hc->maxdecodedurl = 	    hc->maxorigfilename = hc->maxexpnfilename = hc->maxencodings = 	    hc->maxpathinfo = hc->maxquery = hc->maxaccept =@@ -1631,12 +1779,19 @@ 	httpd_realloc_str( &hc->reqhost, &hc->maxreqhost, 0 ); 	httpd_realloc_str( &hc->hostdir, &hc->maxhostdir, 0 ); 	httpd_realloc_str( &hc->remoteuser, &hc->maxremoteuser, 0 );-	httpd_realloc_str( &hc->response, &hc->maxresponse, 0 );+	httpd_realloc_str( &hc->response, &hc->maxresponse, 350 ); #ifdef TILDE_MAP_2 	httpd_realloc_str( &hc->altdir, &hc->maxaltdir, 0 ); #endif /* TILDE_MAP_2 */ 	hc->initialized = 1; 	}+		if (hc->read_buf_is_mmap) {+			hc->read_buf_is_mmap = 0;+			munmap(hc->read_buf, hc->read_size);+			hc->read_buf = NULL;+			hc->read_size = 0;+			httpd_realloc_str( &hc->read_buf, &hc->read_size, 500 );+		}      /* Accept the new connection. */     sz = sizeof(sa);@@ -1657,53 +1812,12 @@     hc->hs = hs;     memset( &hc->client_addr, 0, sizeof(hc->client_addr) );     memcpy( &hc->client_addr, &sa, sockaddr_len( &sa ) );-    hc->read_idx = 0;-    hc->checked_idx = 0;-    hc->checked_state = CHST_FIRSTWORD;-    hc->method = METHOD_UNKNOWN;-    hc->status = 0;-    hc->bytes_to_send = 0;-    hc->bytes_sent = 0;-    hc->encodedurl = "";-    hc->decodedurl[0] = '\0';-    hc->protocol = "UNKNOWN";-    hc->origfilename[0] = '\0';-    hc->expnfilename[0] = '\0';-    hc->encodings[0] = '\0';-    hc->pathinfo[0] = '\0';-    hc->query[0] = '\0';-    hc->referer = "";-    hc->useragent = "";-    hc->accept[0] = '\0';-    hc->accepte[0] = '\0';-    hc->acceptl = "";-    hc->cookie = "";-    hc->contenttype = "";-    hc->reqhost[0] = '\0';-    hc->hdrhost = "";-    hc->hostdir[0] = '\0';-    hc->authorization = "";-    hc->remoteuser[0] = '\0';-    hc->response[0] = '\0';-#ifdef TILDE_MAP_2-    hc->altdir[0] = '\0';-#endif /* TILDE_MAP_2 */-    hc->responselen = 0;-    hc->if_modified_since = (time_t) -1;-    hc->range_if = (time_t) -1;-    hc->contentlength = -1;-    hc->type = "";-    hc->hostname = (char*) 0;-    hc->mime_flag = 1;-    hc->one_one = 0;-    hc->got_range = 0;-    hc->tildemapped = 0;-    hc->init_byte_loc = 0;-    hc->end_byte_loc = -1;-    hc->keep_alive = 0;-    hc->should_linger = 0;-    hc->file_address = (char*) 0;-    return GC_OK;++/*+printf("doing httpd_get_con(%d)\n", hc->conn_fd);+*/++    return httpd_request_reset(hc, 0);     }  @@ -1720,6 +1834,9 @@     {     char c; +/*+printf("**REQUEST [%d]**\n%*.*s\n", hc->conn_fd, hc->read_idx, hc->read_idx, hc->read_buf);+*/     for ( ; hc->checked_idx < hc->read_idx; ++hc->checked_idx ) 	{ 	c = hc->read_buf[hc->checked_idx];@@ -1912,8 +2029,11 @@ 	    eol = strpbrk( protocol, " \t\n\r" ); 	    if ( eol != (char*) 0 ) 		*eol = '\0';-	    if ( strcasecmp( protocol, "HTTP/1.0" ) != 0 )+	    if ( strcasecmp( protocol, "HTTP/1.0" ) != 0 ) { 		hc->one_one = 1;+		hc->keep_alive = 1;+		hc->do_keep_alive = 1;+		} 	    } 	}     /* Check for HTTP/1.1 absolute URL. */@@ -2129,6 +2249,7 @@ 		cp = &buf[11]; 		cp += strspn( cp, " \t" ); 		if ( strcasecmp( cp, "keep-alive" ) == 0 )+		    hc->do_keep_alive = 1; 		    hc->keep_alive = 1; 		} #ifdef LOG_UNKNOWN_HEADERS@@ -2168,6 +2289,9 @@ 	    } 	} +/*+printf("one_one = %d   keep_alive = %d\n", hc->one_one, hc->keep_alive);+*/     if ( hc->one_one ) 	{ 	/* Check that HTTP/1.1 requests specify a host, as required. */@@ -2177,14 +2301,14 @@ 	    return -1; 	    } -	/* If the client wants to do keep-alives, it might also be doing-	** pipelining.  There's no way for us to tell.  Since we don't-	** implement keep-alives yet, if we close such a connection there-	** might be unread pipelined requests waiting.  So, we have to-	** do a lingering close.+	/*+	**  Disable keep alive support for bad browsers, +	**    list taken from Apache 1.3.19 	*/-	if ( hc->keep_alive )-	    hc->should_linger = 1;+	if ( hc->do_keep_alive && +	    ( strstr(hc->useragent, "Mozilla/2") != NULL ||+	      strstr(hc->useragent, "MSIE 4.0b2;") != NULL))+		hc->do_keep_alive = 0; 	}      /* Ok, the request has been parsed.  Now we resolve stuff that@@ -2349,15 +2473,24 @@   void-httpd_close_conn( httpd_conn* hc, struct timeval* nowP )-    {-    make_log_entry( hc, nowP );+httpd_complete_request( httpd_conn* hc, struct timeval* nowP)+{+	if (hc->method != METHOD_UNKNOWN)+		make_log_entry( hc, nowP ); -    if ( hc->file_address != (char*) 0 )+	if ( hc->file_address == (char*) 1 )+    {+	thttpd_closed_conn(hc->conn_fd);+    } else if ( hc->file_address != (char*) 0 ) 	{ 	mmc_unmap( hc->file_address, &(hc->sb), nowP ); 	hc->file_address = (char*) 0; 	}+	}++void+httpd_close_conn( httpd_conn* hc, struct timeval* nowP )+{     if ( hc->conn_fd >= 0 ) 	{ 	(void) close( hc->conn_fd );@@ -2370,7 +2503,12 @@     {     if ( hc->initialized ) 	{-	free( (void*) hc->read_buf );++	if ( hc->read_buf_is_mmap ) {+	    munmap( hc->read_buf, hc->read_size );+	} else {+	    free( (void*) hc->read_buf );+	} 	free( (void*) hc->decodedurl ); 	free( (void*) hc->origfilename ); 	free( (void*) hc->expnfilename );@@ -2556,7 +2694,7 @@ 	return -1; 	} -    send_mime( hc, 200, ok200title, "", "", "text/html", -1, hc->sb.st_mtime );+    send_mime( hc, 200, ok200title, "", "", "text/html", -1, hc->sb.st_mtime, 0, 0 );     if ( hc->method == METHOD_HEAD ) 	closedir( dirp );     else if ( hc->method == METHOD_GET )@@ -3026,11 +3164,9 @@ post_post_garbage_hack( httpd_conn* hc )     {     char buf[2];-    int r; -    r = recv( hc->conn_fd, buf, sizeof(buf), MSG_PEEK );-    if ( r > 0 )-	(void) read( hc->conn_fd, buf, r );+	fcntl(hc->conn_fd, F_SETFL, O_NONBLOCK);+	(void) read( hc->conn_fd, buf, 2 );     }  @@ -3313,6 +3449,11 @@     int r;     ClientData client_data; +    /*+    **  We are not going to leave the socket open after a CGI... too hard+    */+    hc->do_keep_alive = 0;+     if ( hc->method == METHOD_GET || hc->method == METHOD_POST ) 	{ 	httpd_clear_ndelay( hc->conn_fd );@@ -3369,6 +3510,7 @@     int expnlen, indxlen;     char* cp;     char* pi;+    int nocache = 0;      expnlen = strlen( hc->expnfilename ); @@ -3561,6 +3703,16 @@ 	 match( hc->hs->cgi_pattern, hc->expnfilename ) ) 	return cgi( hc ); +	if ( hc->hs->php_pattern != (char*) 0 &&+			match( hc->hs->php_pattern, hc->expnfilename)) {+		return thttpd_php_request( hc, 0 );+	}++	if ( hc->hs->phps_pattern != (char*) 0 &&+			match( hc->hs->phps_pattern, hc->expnfilename)) {+		return thttpd_php_request( hc, 1 );+	}+     /* It's not CGI.  If it's executable or there's pathinfo, someone's     ** trying to either serve or run a non-CGI file as CGI.   Either case     ** is prohibited.@@ -3594,32 +3746,46 @@ 	hc->end_byte_loc = hc->sb.st_size - 1;      figure_mime( hc );+    if ( strncmp(hc->decodedurl, "/nocache/", sizeof("/nocache/") - 1 ) == 0 )+	nocache = 1;      if ( hc->method == METHOD_HEAD ) 	{ 	send_mime( 	    hc, 200, ok200title, hc->encodings, "", hc->type, hc->sb.st_size,-	    hc->sb.st_mtime );+	    hc->sb.st_mtime, 0, 0 ); 	}-    else if ( hc->if_modified_since != (time_t) -1 &&+    else if ( !nocache && hc->if_modified_since != (time_t) -1 && 	 hc->if_modified_since >= hc->sb.st_mtime ) 	{-	hc->method = METHOD_HEAD; 	send_mime(-	    hc, 304, err304title, hc->encodings, "", hc->type, hc->sb.st_size,-	    hc->sb.st_mtime );+	    hc, 304, err304title, hc->encodings, "", hc->type, -1,+	    hc->sb.st_mtime, 0, 0 ); 	}     else 	{-	hc->file_address = mmc_map( hc->expnfilename, &(hc->sb), nowP );+	char *extraheads = "";+	char *lm;+	size_t lml;++	if ( nocache ) +	    {+	    extraheads = "Expires: Thu, 19 Nov 1981 08:52:00 GMT\r\n"+		"Cache-Control: no-store, no-cache, must-revalidate, "+		"post-check=0, pre-check=0\r\n"+		"Pragma: no-cache\r\n";+	    }+		+	hc->file_address = mmc_map( hc->expnfilename, &(hc->sb), nowP, nocache, &lm, &lml ); 	if ( hc->file_address == (char*) 0 ) 	    { 	    httpd_send_err( hc, 500, err500title, "", err500form, hc->encodedurl ); 	    return -1; 	    }+ 	send_mime(-	    hc, 200, ok200title, hc->encodings, "", hc->type, hc->sb.st_size,-	    hc->sb.st_mtime );+	    hc, 200, ok200title, hc->encodings, extraheads, hc->type, hc->sb.st_size,+	    hc->sb.st_mtime, lm, lml ); 	}      return 0;@@ -3638,6 +3804,9 @@     return r;     } +#define smart_str_append_const(a,b) smart_str_appendl(a,b,sizeof(b)-1)++static smart_str bentries;  static void make_log_entry( httpd_conn* hc, struct timeval* nowP )@@ -3648,88 +3817,62 @@      if ( hc->hs->no_log ) 	return;--    /* This is straight CERN Combined Log Format - the only tweak-    ** being that if we're using syslog() we leave out the date, because-    ** syslogd puts it in.  The included syslogtocern script turns the-    ** results into true CERN format.-    */-     /* Format remote user. */     if ( hc->remoteuser[0] != '\0' )-	ru = hc->remoteuser;+    ru = hc->remoteuser;     else-	ru = "-";+    ru = "-";     /* If we're vhosting, prepend the hostname to the url.  This is     ** a little weird, perhaps writing separate log files for     ** each vhost would make more sense.     */-    if ( hc->hs->vhost && ! hc->tildemapped )-	(void) my_snprintf( url, sizeof(url),-	    "/%.100s%.200s",-	    hc->hostname == (char*) 0 ? hc->hs->server_hostname : hc->hostname,-	    hc->encodedurl );-    else-	(void) my_snprintf( url, sizeof(url),-	    "%.200s", hc->encodedurl );-    /* Format the bytes. */-    if ( (long) hc->bytes_sent >= 0 )-	(void) my_snprintf( bytes, sizeof(bytes),-	    "%ld", (long) hc->bytes_sent );-    else-	(void) strcpy( bytes, "-" );      /* Logfile or syslog? */     if ( hc->hs->logfp != (FILE*) 0 )-	{-	time_t now;-	struct tm* t;-	const char* cernfmt_nozone = "%d/%b/%Y:%H:%M:%S";-	char date_nozone[100];-	int zone;-	char sign;-	char date[100];--	/* Get the current time, if necessary. */-	if ( nowP != (struct timeval*) 0 )-	    now = nowP->tv_sec;-	else-	    now = time( (time_t*) 0 );-	/* Format the time, forcing a numeric timezone (some log analyzers-	** are stoooopid about this).-	*/-	t = localtime( &now );-	(void) strftime( date_nozone, sizeof(date_nozone), cernfmt_nozone, t );-#ifdef HAVE_TM_GMTOFF-	zone = t->tm_gmtoff / 60L;-#else-	zone = -timezone / 60L;-	/* Probably have to add something about daylight time here. */-#endif-	if ( zone >= 0 )-	    sign = '+';-	else-	    {-	    sign = '-';-	    zone = -zone;-	    }-	zone = ( zone / 60 ) * 100 + zone % 60;-	(void) my_snprintf( date, sizeof(date),-	    "%s %c%04d", date_nozone, sign, zone );-	/* And write the log entry. */-	(void) fprintf( hc->hs->logfp,-	    "%.80s - %.80s [%s] \"%.80s %.300s %.80s\" %d %s \"%.200s\" \"%.80s\"\n",-	    httpd_ntoa( &hc->client_addr ), ru, date,-	    httpd_method_str( hc->method ), url, hc->protocol,-	    hc->status, bytes, hc->referer, hc->useragent );-	(void) fflush( hc->hs->logfp );	/* don't need to flush every time */-	}-    else-	syslog( LOG_INFO,-	    "%.80s - %.80s \"%.80s %.200s %.80s\" %d %s \"%.200s\" \"%.80s\"",-	    httpd_ntoa( &hc->client_addr ), ru,-	    httpd_method_str( hc->method ), url, hc->protocol,-	    hc->status, bytes, hc->referer, hc->useragent );+    {+    /* XXXXXXX */++    smart_str_appends(&bentries, httpd_ntoa(&hc->client_addr));+    smart_str_append_const(&bentries, " - ");+    smart_str_appends(&bentries, ru);+    smart_str_append_const(&bentries, " [");+    smart_str_appendl(&bentries, hc->hs->log_date, hc->hs->log_date_len);+    smart_str_append_const(&bentries, "] \"");+    smart_str_appends(&bentries, httpd_method_str(hc->method));+    smart_str_appendc(&bentries, ' ');++    if (hc->hs->vhost && ! hc->tildemapped) {+        smart_str_appendc(&bentries, '/');+        if (hc->hostname)+            smart_str_appends(&bentries, hc->hostname);+        else+            smart_str_appends(&bentries, hc->hs->server_hostname);+    }+    smart_str_appends(&bentries, hc->encodedurl);++    smart_str_appendc(&bentries, ' ');+    smart_str_appends(&bentries, hc->protocol);+    smart_str_append_const(&bentries, "\" ");+    smart_str_append_long(&bentries, hc->status);+    if (hc->bytes_sent >= 0) {+        smart_str_appendc(&bentries, ' ');+        smart_str_append_long(&bentries, hc->bytes_sent);+        smart_str_append_const(&bentries, " \"");+    } else {+        smart_str_append_const(&bentries, " - \"");+    }+    smart_str_appends(&bentries, hc->referer);+    smart_str_append_const(&bentries, "\" \"");+    smart_str_appends(&bentries, hc->useragent);+    smart_str_append_const(&bentries, "\"\n");++    if (bentries.len > 16384) {+        int fd = fileno(hc->hs->logfp);+        write(fd, bentries.c, bentries.len);+        bentries.len = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -