Lines Matching refs:hc

150  static void add_response( httpd_conn* hc, char* str );
151 -static void send_mime( httpd_conn* hc, int status, char* title, char* encodings, char* extraheads,…
152 +static void send_mime( httpd_conn* hc, int status, char* title, char* encodings, char* extraheads,…
153 …static void send_response( httpd_conn* hc, int status, char* title, char* extraheads, char* form, …
154 static void send_response_tail( httpd_conn* hc );
226 if ( hc->responselen > 0 )
229 …ntf("**RESPONSE [%d]** len = %d\n%*.*s\n", hc->conn_fd, hc->responselen, hc->responselen, hc->resp…
231 (void) write( hc->conn_fd, hc->response, hc->responselen );
232 hc->responselen = 0;
246 -send_mime( httpd_conn* hc, int status, char* title, char* encodings, char* extraheads, char* type,…
247 +send_mime( httpd_conn* hc, int status, char* title, char* encodings, char* extraheads, char* type,…
260 hc->status = status;
261 hc->bytes_to_send = length;
262 if ( hc->mime_flag )
273 - fixed_type, sizeof(fixed_type), type, hc->hs->charset );
276 - hc->protocol, status, title, EXPOSED_SERVER_SOFTWARE, fixed_type,
278 - add_response( hc, buf );
289 + if (hc->response) {
290 + s.c = hc->response;
292 + s.a = hc->maxresponse;
293 + hc->response = 0;
294 + hc->maxresponse = 0;
304 + smart_str_appends(&s, hc->hs->charset);
320 - add_response( hc, buf );
329 - (long) hc->init_byte_loc, (long) hc->end_byte_loc, length,
330 - (long) ( hc->end_byte_loc - hc->init_byte_loc + 1 ) );
331 - add_response( hc, buf );
334 + smart_str_append_long(&s, hc->init_byte_loc);
336 + smart_str_append_long(&s, hc->end_byte_loc);
340 + smart_str_append_long(&s, hc->end_byte_loc - hc->init_byte_loc + 1);
348 - add_response( hc, buf );
354 + hc->do_keep_alive = 0;
357 - add_response( hc, extraheads );
358 - add_response( hc, "\r\n" );
360 + if (hc->do_keep_alive) {
367 + if (hc->response) {
368 + free(hc->response);
370 + hc->response = s.c;
371 + hc->maxresponse = s.a;
372 + hc->responselen = s.len;
381 - send_mime( hc, status, title, "", extraheads, "text/html", -1, 0 );
382 + send_mime( hc, status, title, "", extraheads, "text/html", -1, 0, 0, 0 );
399 - send_mime( hc, status, title, "", extraheads, "text/html", -1, 0 );
400 + send_mime( hc, status, title, "", extraheads, "text/html", -1, 0, 0, 0 );
405 if ( hc->tildemapped )
408 + if ( hc->hostname[0] == '.' || strchr( hc->hostname, '/' ) != (char*) 0 )
427 +httpd_request_reset(httpd_conn* hc, int preserve_read_buf )
430 + hc->read_idx = 0;
431 + hc->checked_idx = 0;
434 + if (hc->read_buf_is_mmap) {
435 + hc->read_buf_is_mmap = 0;
436 + munmap(hc->read_buf, hc->read_size);
437 + hc->read_buf = NULL;
438 + hc->read_size = 0;
439 + httpd_realloc_str( &hc->read_buf, &hc->read_size, 500 );
441 + hc->checked_state = CHST_FIRSTWORD;
442 + hc->method = METHOD_UNKNOWN;
443 + hc->status = 0;
444 + hc->bytes_to_send = 0;
445 + hc->bytes_sent = 0;
446 + hc->encodedurl = "";
447 + hc->decodedurl[0] = '\0';
448 + hc->protocol = "UNKNOWN";
449 + hc->origfilename[0] = '\0';
450 + hc->expnfilename[0] = '\0';
451 + hc->encodings[0] = '\0';
452 + hc->pathinfo[0] = '\0';
453 + hc->query[0] = '\0';
454 + hc->referer = "";
455 + hc->useragent = "";
456 + hc->accept[0] = '\0';
457 + hc->accepte[0] = '\0';
458 + hc->acceptl = "";
459 + hc->cookie = "";
460 + hc->contenttype = "";
461 + hc->reqhost[0] = '\0';
462 + hc->hdrhost = "";
463 + hc->hostdir[0] = '\0';
464 + hc->authorization = "";
465 + hc->remoteuser[0] = '\0';
466 + hc->response[0] = '\0';
468 + hc->altdir[0] = '\0';
470 + hc->responselen = 0;
471 + hc->if_modified_since = (time_t) -1;
472 + hc->range_if = (time_t) -1;
473 + hc->contentlength = -1;
474 + hc->type = "";
475 + hc->hostname = (char*) 0;
476 + hc->mime_flag = 1;
477 + hc->one_one = 0;
478 + hc->got_range = 0;
479 + hc->tildemapped = 0;
480 + hc->init_byte_loc = 0;
481 + hc->end_byte_loc = -1;
482 + hc->keep_alive = 0;
483 + hc->do_keep_alive = 0;
484 + hc->should_linger = 0;
485 + hc->file_address = (char*) 0;
486 + hc->read_body_into_mem = 0;
491 httpd_get_conn( httpd_server* hs, int listen_fd, httpd_conn* hc )
496 hc->read_size = 0;
497 httpd_realloc_str( &hc->read_buf, &hc->read_size, 500 );
498 + hc->read_buf_is_mmap = 0;
499 hc->maxdecodedurl =
500 hc->maxorigfilename = hc->maxexpnfilename = hc->maxencodings =
501 hc->maxpathinfo = hc->maxquery = hc->maxaccept =
503 httpd_realloc_str( &hc->reqhost, &hc->maxreqhost, 0 );
504 httpd_realloc_str( &hc->hostdir, &hc->maxhostdir, 0 );
505 httpd_realloc_str( &hc->remoteuser, &hc->maxremoteuser, 0 );
506 - httpd_realloc_str( &hc->response, &hc->maxresponse, 0 );
507 + httpd_realloc_str( &hc->response, &hc->maxresponse, 350 );
509 httpd_realloc_str( &hc->altdir, &hc->maxaltdir, 0 );
511 hc->initialized = 1;
513 + if (hc->read_buf_is_mmap) {
514 + hc->read_buf_is_mmap = 0;
515 + munmap(hc->read_buf, hc->read_size);
516 + hc->read_buf = NULL;
517 + hc->read_size = 0;
518 + httpd_realloc_str( &hc->read_buf, &hc->read_size, 500 );
524 hc->hs = hs;
525 memset( &hc->client_addr, 0, sizeof(hc->client_addr) );
526 memcpy( &hc->client_addr, &sa, sockaddr_len( &sa ) );
527 - hc->read_idx = 0;
528 - hc->checked_idx = 0;
529 - hc->checked_state = CHST_FIRSTWORD;
530 - hc->method = METHOD_UNKNOWN;
531 - hc->status = 0;
532 - hc->bytes_to_send = 0;
533 - hc->bytes_sent = 0;
534 - hc->encodedurl = "";
535 - hc->decodedurl[0] = '\0';
536 - hc->protocol = "UNKNOWN";
537 - hc->origfilename[0] = '\0';
538 - hc->expnfilename[0] = '\0';
539 - hc->encodings[0] = '\0';
540 - hc->pathinfo[0] = '\0';
541 - hc->query[0] = '\0';
542 - hc->referer = "";
543 - hc->useragent = "";
544 - hc->accept[0] = '\0';
545 - hc->accepte[0] = '\0';
546 - hc->acceptl = "";
547 - hc->cookie = "";
548 - hc->contenttype = "";
549 - hc->reqhost[0] = '\0';
550 - hc->hdrhost = "";
551 - hc->hostdir[0] = '\0';
552 - hc->authorization = "";
553 - hc->remoteuser[0] = '\0';
554 - hc->response[0] = '\0';
556 - hc->altdir[0] = '\0';
558 - hc->responselen = 0;
559 - hc->if_modified_since = (time_t) -1;
560 - hc->range_if = (time_t) -1;
561 - hc->contentlength = -1;
562 - hc->type = "";
563 - hc->hostname = (char*) 0;
564 - hc->mime_flag = 1;
565 - hc->one_one = 0;
566 - hc->got_range = 0;
567 - hc->tildemapped = 0;
568 - hc->init_byte_loc = 0;
569 - hc->end_byte_loc = -1;
570 - hc->keep_alive = 0;
571 - hc->should_linger = 0;
572 - hc->file_address = (char*) 0;
576 +printf("doing httpd_get_con(%d)\n", hc->conn_fd);
579 + return httpd_request_reset(hc, 0);
588 +printf("**REQUEST [%d]**\n%*.*s\n", hc->conn_fd, hc->read_idx, hc->read_idx, hc->read_buf);
590 for ( ; hc->checked_idx < hc->read_idx; ++hc->checked_idx )
592 c = hc->read_buf[hc->checked_idx];
599 hc->one_one = 1;
600 + hc->keep_alive = 1;
601 + hc->do_keep_alive = 1;
610 + hc->do_keep_alive = 1;
611 hc->keep_alive = 1;
619 +printf("one_one = %d keep_alive = %d\n", hc->one_one, hc->keep_alive);
621 if ( hc->one_one )
637 - if ( hc->keep_alive )
638 - hc->should_linger = 1;
639 + if ( hc->do_keep_alive &&
640 + ( strstr(hc->useragent, "Mozilla/2") != NULL ||
641 + strstr(hc->useragent, "MSIE 4.0b2;") != NULL))
642 + hc->do_keep_alive = 0;
650 -httpd_close_conn( httpd_conn* hc, struct timeval* nowP )
652 - make_log_entry( hc, nowP );
653 +httpd_complete_request( httpd_conn* hc, struct timeval* nowP)
655 + if (hc->method != METHOD_UNKNOWN)
656 + make_log_entry( hc, nowP );
658 - if ( hc->file_address != (char*) 0 )
659 + if ( hc->file_address == (char*) 1 )
661 + thttpd_closed_conn(hc->conn_fd);
662 + } else if ( hc->file_address != (char*) 0 )
664 mmc_unmap( hc->file_address, &(hc->sb), nowP );
665 hc->file_address = (char*) 0;
670 +httpd_close_conn( httpd_conn* hc, struct timeval* nowP )
672 if ( hc->conn_fd >= 0 )
674 (void) close( hc->conn_fd );
677 if ( hc->initialized )
679 - free( (void*) hc->read_buf );
681 + if ( hc->read_buf_is_mmap ) {
682 + munmap( hc->read_buf, hc->read_size );
684 + free( (void*) hc->read_buf );
686 free( (void*) hc->decodedurl );
687 free( (void*) hc->origfilename );
688 free( (void*) hc->expnfilename );
693 - send_mime( hc, 200, ok200title, "", "", "text/html", -1, hc->sb.st_mtime );
694 + send_mime( hc, 200, ok200title, "", "", "text/html", -1, hc->sb.st_mtime, 0, 0 );
695 if ( hc->method == METHOD_HEAD )
697 else if ( hc->method == METHOD_GET )
699 post_post_garbage_hack( httpd_conn* hc )
704 - r = recv( hc->conn_fd, buf, sizeof(buf), MSG_PEEK );
706 - (void) read( hc->conn_fd, buf, r );
707 + fcntl(hc->conn_fd, F_SETFL, O_NONBLOCK);
708 + (void) read( hc->conn_fd, buf, 2 );
719 + hc->do_keep_alive = 0;
721 if ( hc->method == METHOD_GET || hc->method == METHOD_POST )
723 httpd_clear_ndelay( hc->conn_fd );
730 expnlen = strlen( hc->expnfilename );
733 match( hc->hs->cgi_pattern, hc->expnfilename ) )
734 return cgi( hc );
736 + if ( hc->hs->php_pattern != (char*) 0 &&
737 + match( hc->hs->php_pattern, hc->expnfilename)) {
738 + return thttpd_php_request( hc, 0 );
741 + if ( hc->hs->phps_pattern != (char*) 0 &&
742 + match( hc->hs->phps_pattern, hc->expnfilename)) {
743 + return thttpd_php_request( hc, 1 );
750 hc->end_byte_loc = hc->sb.st_size - 1;
752 figure_mime( hc );
753 + if ( strncmp(hc->decodedurl, "/nocache/", sizeof("/nocache/") - 1 ) == 0 )
756 if ( hc->method == METHOD_HEAD )
759 hc, 200, ok200title, hc->encodings, "", hc->type, hc->sb.st_size,
760 - hc->sb.st_mtime );
761 + hc->sb.st_mtime, 0, 0 );
763 - else if ( hc->if_modified_since != (time_t) -1 &&
764 + else if ( !nocache && hc->if_modified_since != (time_t) -1 &&
765 hc->if_modified_since >= hc->sb.st_mtime )
767 - hc->method = METHOD_HEAD;
769 - hc, 304, err304title, hc->encodings, "", hc->type, hc->sb.st_size,
770 - hc->sb.st_mtime );
771 + hc, 304, err304title, hc->encodings, "", hc->type, -1,
772 + hc->sb.st_mtime, 0, 0 );
776 - hc->file_address = mmc_map( hc->expnfilename, &(hc->sb), nowP );
789 + hc->file_address = mmc_map( hc->expnfilename, &(hc->sb), nowP, nocache, &lm, &lml );
790 if ( hc->file_address == (char*) 0 )
792 httpd_send_err( hc, 500, err500title, "", err500form, hc->encodedurl );
797 - hc, 200, ok200title, hc->encodings, "", hc->type, hc->sb.st_size,
798 - hc->sb.st_mtime );
799 + hc, 200, ok200title, hc->encodings, extraheads, hc->type, hc->sb.st_size,
800 + hc->sb.st_mtime, lm, lml );
813 make_log_entry( httpd_conn* hc, struct timeval* nowP )
816 if ( hc->hs->no_log )
826 if ( hc->remoteuser[0] != '\0' )
827 - ru = hc->remoteuser;
828 + ru = hc->remoteuser;
836 - if ( hc->hs->vhost && ! hc->tildemapped )
839 - hc->hostname == (char*) 0 ? hc->hs->server_hostname : hc->hostname,
840 - hc->encodedurl );
843 - "%.200s", hc->encodedurl );
845 - if ( (long) hc->bytes_sent >= 0 )
847 - "%ld", (long) hc->bytes_sent );
852 if ( hc->hs->logfp != (FILE*) 0 )
889 - (void) fprintf( hc->hs->logfp,
891 - httpd_ntoa( &hc->client_addr ), ru, date,
892 - httpd_method_str( hc->method ), url, hc->protocol,
893 - hc->status, bytes, hc->referer, hc->useragent );
894 - (void) fflush( hc->hs->logfp ); /* don't need to flush every time */
899 - httpd_ntoa( &hc->client_addr ), ru,
900 - httpd_method_str( hc->method ), url, hc->protocol,
901 - hc->status, bytes, hc->referer, hc->useragent );
905 + smart_str_appends(&bentries, httpd_ntoa(&hc->client_addr));
909 + smart_str_appendl(&bentries, hc->hs->log_date, hc->hs->log_date_len);
911 + smart_str_appends(&bentries, httpd_method_str(hc->method));
914 + if (hc->hs->vhost && ! hc->tildemapped) {
916 + if (hc->hostname)
917 + smart_str_appends(&bentries, hc->hostname);
919 + smart_str_appends(&bentries, hc->hs->server_hostname);
921 + smart_str_appends(&bentries, hc->encodedurl);
924 + smart_str_appends(&bentries, hc->protocol);
926 + smart_str_append_long(&bentries, hc->status);
927 + if (hc->bytes_sent >= 0) {
929 + smart_str_append_long(&bentries, hc->bytes_sent);
934 + smart_str_appends(&bentries, hc->referer);
936 + smart_str_appends(&bentries, hc->useragent);
940 + int fd = fileno(hc->hs->logfp);
1030 extern void httpd_close_conn( httpd_conn* hc, struct timeval* nowP );
1031 +void httpd_complete_request( httpd_conn* hc, struct timeval* nowP);
1032 +int httpd_request_reset(httpd_conn* hc,int );
1440 httpd_conn* hc;
1540 - httpd_conn* hc;
1622 connects[cnum].hc = (httpd_conn*) 0;
1646 - hc = c->hc;
1648 - fdwatch_check_fd( hc->conn_fd ) )
1651 - fdwatch_check_fd( hc->conn_fd ) )
1654 - fdwatch_check_fd( hc->conn_fd ) )
1657 + fdwatch_check_fd(c->hc->conn_fd);
1695 + httpd_complete_request( connects[cnum].hc, &tv );
1696 httpd_close_conn( connects[cnum].hc, &tv );
1698 if ( connects[cnum].hc != (httpd_conn*) 0 )
1700 httpd_destroy_conn( connects[cnum].hc );
1731 if ( c->hc == (httpd_conn*) 0 )
1760 httpd_set_ndelay( c->hc->conn_fd );
1765 +#define FIXUP(x) if (hc->x >= oldptr && hc->x < pe) hc->x += d
1768 +realign_hc(httpd_conn *hc, char *oldptr)
1770 + int d = hc->read_buf - oldptr;
1771 + char *pe = oldptr + hc->checked_idx;
1789 + httpd_conn *hc = c->hc;
1791 + char *oldptr = hc->read_buf;
1795 + hc->read_body_into_mem = 0;
1797 + already = hc->read_idx - hc->checked_idx;
1798 + missing = hc->contentlength - already;
1806 + size_t sz = hc->contentlength + hc->checked_idx + 10;
1815 + memcpy(p, hc->read_buf, hc->read_idx);
1816 + free(hc->read_buf);
1817 + hc->read_size = sz;
1818 + hc->read_buf = p;
1819 + hc->read_buf_is_mmap = 1;
1824 + if (!hc->read_buf_is_mmap) {
1829 + httpd_realloc_str(&hc->read_buf, &hc->read_size, hc->checked_idx + hc->contentlength + 10);
1831 + if (oldptr != hc->read_buf) realign_hc(hc, oldptr);
1833 + fdwatch_del_fd( hc->conn_fd );
1834 + fdwatch_add_fd( hc->conn_fd, c, FDW_READ );
1840 + httpd_conn *hc = c->hc;
1848 + fdwatch_del_fd( hc->conn_fd );
1849 + fdwatch_add_fd( hc->conn_fd, c, FDW_WRITE );
1860 httpd_conn* hc = c->hc;
1864 if ( hc->read_size > 5000 )
1866 httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" );
1878 - httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" );
1882 + httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" );
1899 + if (c->hc->file_address == (char *) 1) {
1904 + if (sz > 0) hc->read_idx += sz;
1910 + if ( hc->keep_alive ) {
1916 + hc->keep_alive = 0;
1920 - hc->read_idx += sz;
1926 + httpd_conn* hc = c->hc;
1929 switch ( httpd_got_request( hc ) )
1934 httpd_send_err( hc, 400, httpd_err400title, "", httpd_err400form, "" );
1941 if ( httpd_parse_request( hc ) < 0 )
1951 hc, 503, httpd_err503title, "", httpd_err503form, hc->encodedurl );
1961 + httpd_conn *hc = c->hc;
1963 if ( httpd_start_request( hc, tvP ) < 0 )
1971 + if ( hc->read_body_into_mem ) {
1977 if ( hc->got_range )
1982 c->bytes_sent = hc->bytes_sent;
1987 + if (hc->file_address == (char *) 1) {
2016 - fdwatch_del_fd( hc->conn_fd );
2017 - fdwatch_add_fd( hc->conn_fd, c, FDW_WRITE );
2026 iv[1].iov_base = &(hc->file_address[c->bytes_sent]);
2028 sz = writev( hc->conn_fd, iv, 2 );
2030 …tf("**RESPONSE2 [%d]** len = %d\n%*.*s\n", hc->conn_fd, hc->responselen, hc->responselen, hc->resp…
2038 syslog( LOG_ERR, "write - %m sending %.80s", hc->encodedurl );
2048 if ( hc->responselen > 0 )
2053 int newlen = hc->responselen - sz;
2054 - (void) memcpy( hc->response, &(hc->response[sz]), newlen );
2055 + (void) memmove( hc->response, &(hc->response[sz]), newlen );
2056 hc->responselen = newlen;
2085 + httpd_conn *hc = c->hc;
2088 + n = read(hc->conn_fd, hc->read_buf + hc->read_idx,
2089 + hc->contentlength - (hc->read_idx - hc->checked_idx));
2100 + hc->read_idx += n;
2102 + if (hc->contentlength == hc->read_idx - hc->checked_idx) {
2111 + httpd_conn* hc = c->hc;
2112 + int n = send(hc->conn_fd, hc->response, hc->responselen, 0);
2125 + if (n == hc->responselen) {
2127 + hc->response = realloc(hc->response, hc->maxresponse + 1);
2128 + hc->responselen = 0;
2134 + hc->responselen -= n;
2136 + memmove(hc->response, hc->response + n, hc->responselen);
2153 - httpd_write_response( c->hc );
2154 + if (c->hc->responselen && c->conn_state != CNST_SENDING_RESP) {
2176 - if ( c->hc->should_linger )
2178 + if ( c->hc->do_keep_alive && doKeep)
2181 + httpd_conn *hc = c->hc;
2189 + httpd_complete_request( c->hc, tvP );
2191 fdwatch_del_fd( c->hc->conn_fd );
2192 fdwatch_add_fd( c->hc->conn_fd, c, FDW_READ );
2194 + httpd_request_reset( c->hc, 1 );
2196 + hc->read_idx -= hc->checked_idx;
2197 + memmove(hc->read_buf, hc->read_buf + hc->checked_idx, hc->read_idx);
2198 + hc->checked_idx = 0;
2201 httpd_set_ndelay( c->hc->conn_fd );
2204 + else if ( c->hc->should_linger )
2216 + httpd_complete_request( c->hc, tvP );
2218 + fdwatch_del_fd( c->hc->conn_fd );
2219 + fdwatch_add_fd( c->hc->conn_fd, c, FDW_READ );
2221 + httpd_set_ndelay( c->hc->conn_fd );
2226 + httpd_complete_request( c->hc, tvP );
2253 - httpd_ntoa( &c->hc->client_addr ) );
2254 - httpd_send_err( c->hc, 408, httpd_err408title, "", httpd_err408form, "" );
2271 - httpd_ntoa( &c->hc->client_addr ) );