Changeset 6646
- Timestamp:
- Aug 26, 2008, 3:22:00 PM (15 years ago)
- Location:
- trunk/third-party/shttpd
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/third-party/shttpd/config.h
r6645 r6646 16 16 #define HTPASSWD ".htpasswd" /* Passwords file name */ 17 17 #define URI_MAX 16384 /* Default max request size */ 18 #define IO_BUFSIZE 65536 /* IO buffer size */ 18 19 #define LISTENING_PORTS "80" /* Default listening ports */ 19 20 #define INDEX_FILES "index.html,index.htm,index.php,index.cgi" -
trunk/third-party/shttpd/log.c
r6644 r6646 17 17 _shttpd_elog(int flags, struct conn *c, const char *fmt, ...) 18 18 { 19 char date[64], buf[URI_MAX];20 int len;21 19 FILE *fp = c == NULL ? NULL : c->ctx->error_log; 22 20 va_list ap; … … 30 28 } 31 29 32 strftime(date, sizeof(date), "%a %b %d %H:%M:%S %Y", 33 localtime(&_shttpd_current_time)); 30 if (fp != NULL && (flags & (E_FATAL | E_LOG))) { 31 char date[64]; 32 char *buf = malloc( URI_MAX ); 33 int len; 34 34 35 len = _shttpd_snprintf(buf, sizeof(buf), 36 "[%s] [error] [client %s] \"%s\" ", 37 date, c ? inet_ntoa(c->sa.u.sin.sin_addr) : "-", 38 c && c->request ? c->request : "-"); 35 strftime(date, sizeof(date), "%a %b %d %H:%M:%S %Y", 36 localtime(&_shttpd_current_time)); 39 37 40 va_start(ap, fmt); 41 (void) vsnprintf(buf + len, sizeof(buf) - len, fmt, ap); 42 va_end(ap); 38 len = _shttpd_snprintf(buf, URI_MAX, 39 "[%s] [error] [client %s] \"%s\" ", 40 date, c ? inet_ntoa(c->sa.u.sin.sin_addr) : "-", 41 c && c->request ? c->request : "-"); 43 42 44 buf[sizeof(buf) - 1] = '\0'; 43 va_start(ap, fmt); 44 (void) vsnprintf(buf + len, URI_MAX - len, fmt, ap); 45 va_end(ap); 45 46 46 if (fp != NULL && (flags & (E_FATAL | E_LOG))) { 47 buf[URI_MAX - 1] = '\0'; 48 47 49 (void) fprintf(fp, "%s\n", buf); 48 50 (void) fflush(fp); 51 52 free(buf); 49 53 } 50 54 … … 58 62 static const struct vec dash = {"-", 1}; 59 63 60 const struct vec *user = &c->ch.user.v_vec; 61 const struct vec *referer = &c->ch.referer.v_vec; 62 const struct vec *user_agent = &c->ch.useragent.v_vec; 63 char date[64], buf[URI_MAX], *q1 = "\"", *q2 = "\""; 64 const struct vec *user; 65 const struct vec *referer; 66 const struct vec *user_agent; 67 char date[64], *buf, *q1, *q2; 68 69 if (fp == NULL) 70 return; 71 72 user = &c->ch.user.v_vec; 73 referer = &c->ch.referer.v_vec; 74 user_agent = &c->ch.useragent.v_vec; 75 q1 = q2 = "\""; 64 76 65 77 if (user->len == 0) … … 79 91 localtime(&c->birth_time)); 80 92 81 (void) _shttpd_snprintf(buf, sizeof(buf), 93 buf = malloc(URI_MAX); 94 95 (void) _shttpd_snprintf(buf, URI_MAX, 82 96 "%s - %.*s [%s %+05d] \"%s\" %d %lu %s%.*s%s %s%.*s%s", 83 97 inet_ntoa(c->sa.u.sin.sin_addr), user->len, user->ptr, … … 87 101 q2, user_agent->len, user_agent->ptr, q2); 88 102 89 if (fp != NULL) {90 (void) fprintf(fp, "%s\n", buf);91 (void) fflush(fp); 92 }103 (void) fprintf(fp, "%s\n", buf); 104 (void) fflush(fp); 105 106 free(buf); 93 107 } -
trunk/third-party/shttpd/shttpd.c
r6645 r6646 534 534 decide_what_to_do(struct conn *c) 535 535 { 536 char path[URI_MAX], buf[1024], *root; 536 char *path; 537 const char *root; 537 538 struct vec alias_uri, alias_path; 538 539 struct stat st; … … 549 550 550 551 root = c->ctx->options[OPT_ROOT]; 551 if (strlen(c->uri) + strlen(root) >= sizeof(path)) {552 if (strlen(c->uri) + strlen(root) >= URI_MAX) { 552 553 _shttpd_send_server_error(c, 400, "URI is too long"); 553 554 return; 554 555 } 555 556 556 (void) _shttpd_snprintf(path, sizeof(path), "%s%s", root, c->uri); 557 path = malloc( URI_MAX ); 558 (void) _shttpd_snprintf(path, URI_MAX, "%s%s", root, c->uri); 557 559 558 560 /* User may use the aliases - check URI for mount point */ 559 561 if (is_alias(c->ctx, c->uri, &alias_uri, &alias_path) != NULL) { 560 (void) _shttpd_snprintf(path, sizeof(path), "%.*s%s",562 (void) _shttpd_snprintf(path, URI_MAX, "%.*s%s", 561 563 alias_path.len, alias_path.ptr, c->uri + alias_uri.len); 562 564 DBG(("using alias %.*s -> %.*s", alias_uri.len, alias_uri.ptr, … … 613 615 _shttpd_send_server_error(c, 404, "Not Found"); 614 616 } else if (S_ISDIR(st.st_mode) && path[strlen(path) - 1] != '/') { 617 char buf[1024]; 615 618 (void) _shttpd_snprintf(buf, sizeof(buf), 616 619 "Moved Permanently\r\nLocation: %s/", c->uri); 617 620 _shttpd_send_server_error(c, 301, buf); 618 621 } else if (S_ISDIR(st.st_mode) && 619 find_index_file(c, path, sizeof(path)- 1, &st) == -1 &&622 find_index_file(c, path, URI_MAX - 1, &st) == -1 && 620 623 !IS_TRUE(c->ctx, OPT_DIR_LIST)) { 621 624 _shttpd_send_server_error(c, 403, "Directory Listing Denied"); … … 656 659 _shttpd_send_server_error(c, 500, "Internal Error"); 657 660 } 661 662 free(path); 658 663 } 659 664 … … 782 787 SSL_free(ssl); 783 788 #endif /* NO_SSL */ 784 } else if ((c = calloc(1, sizeof(*c) + 2 * URI_MAX)) == NULL) {789 } else if ((c = calloc(1, sizeof(*c) + 2 * IO_BUFSIZE)) == NULL) { 785 790 #if !defined(NO_SSL) 786 791 if (ssl) … … 809 814 /* Set IO buffers */ 810 815 c->loc.io.buf = (char *) (c + 1); 811 c->rem.io.buf = c->loc.io.buf + URI_MAX;812 c->loc.io.size = c->rem.io.size = URI_MAX;816 c->rem.io.buf = c->loc.io.buf + IO_BUFSIZE; 817 c->loc.io.size = c->rem.io.size = IO_BUFSIZE; 813 818 814 819 #if !defined(NO_SSL)
Note: See TracChangeset
for help on using the changeset viewer.