Changeset 331 for EcnlProtoTool/trunk/ntshell/webserver/httpd.c
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/ntshell/webserver/httpd.c
r321 r331 43 43 #include "syssvc/syslog.h" 44 44 #include "http-strings.h" 45 #include <tinet_defs.h> 46 #include <tinet_config.h> 45 47 #include "netinet/in.h" 46 48 #include "netinet/in_var.h" 49 #include "netinet/in_itron.h" 47 50 #include "httpd.h" 48 51 #include "httpd-fs.h" … … 50 53 #include "base64.h" 51 54 #include "sha1.h" 52 #include "ntstdio.h" 55 #include "util/ntstdio.h" 56 #include "core/ntlibc.h" 53 57 54 58 #define TRUE 1 … … 82 86 83 87 #ifndef _MSC_VER 88 #define strnlen httpd_strnlen 84 89 /* strnlen() is a POSIX.2008 addition. Can't rely on it being available so 85 90 * define it ourselves. … … 99 104 void strcpy_s(char *dst, int size, const char *src) 100 105 { 101 int slen = strlen(src);106 int slen = ntlibc_strlen(src); 102 107 if (slen >= size) 103 108 slen = size - 1; … … 108 113 void strcat_s(char *dst, int size, const char *src) 109 114 { 110 int dlen = strlen(dst);111 int slen = strlen(src);115 int dlen = ntlibc_strlen(dst); 116 int slen = ntlibc_strlen(src); 112 117 if (dlen + slen >= size) 113 118 slen = size - 1 - dlen; … … 223 228 struct message *m = &s->message; 224 229 225 if ( strncmp("Referer", buf, len) == 0) {230 if (ntlibc_strncmp("Referer", buf, len) == 0) { 226 231 m->num_headers = 1; 227 232 } 228 else if ( strncmp("Host", buf, len) == 0) {233 else if (ntlibc_strncmp("Host", buf, len) == 0) { 229 234 m->num_headers = 2; 230 235 } 231 else if ( strncmp("Upgrade", buf, len) == 0) {236 else if (ntlibc_strncmp("Upgrade", buf, len) == 0) { 232 237 m->num_headers = 3; 233 238 } 234 else if ( strncmp("Connection", buf, len) == 0) {239 else if (ntlibc_strncmp("Connection", buf, len) == 0) { 235 240 m->num_headers = 4; 236 241 } 237 else if ( strncmp("Sec-WebSocket-Key", buf, len) == 0) {242 else if (ntlibc_strncmp("Sec-WebSocket-Key", buf, len) == 0) { 238 243 m->num_headers = 5; 239 244 } 240 else if ( strncmp("Origin", buf, len) == 0) {245 else if (ntlibc_strncmp("Origin", buf, len) == 0) { 241 246 m->num_headers = 6; 242 247 } 243 else if ( strncmp("Sec-WebSocket-Protocol", buf, len) == 0) {248 else if (ntlibc_strncmp("Sec-WebSocket-Protocol", buf, len) == 0) { 244 249 m->num_headers = 7; 245 250 } 246 else if ( strncmp("Sec-WebSocket-Version", buf, len) == 0) {251 else if (ntlibc_strncmp("Sec-WebSocket-Version", buf, len) == 0) { 247 252 m->num_headers = 8; 248 253 } … … 329 334 s->in.state = IN_STATE_UPLOAD; 330 335 } 331 else if ( strcmp(s->filename, uploding->filename) == 0) {336 else if (ntlibc_strcmp(s->filename, uploding->filename) == 0) { 332 337 ntstdio_printf(&ntstdio, "collision: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 333 338 goto error; … … 559 564 char *ptr; 560 565 561 len = strlen(statushdr);566 len = ntlibc_strlen(statushdr); 562 567 tcp_snd_dat(s->cepid, (void *)statushdr, len, TMO_FEVR); 563 568 … … 574 579 tcp_snd_dat(s->cepid, "/~", len, TMO_FEVR); 575 580 } 576 len = strlen(s->filename);581 len = ntlibc_strlen(s->filename); 577 582 tcp_snd_dat(s->cepid, s->filename, len, TMO_FEVR); 578 583 if (s->query != NULL) { 579 584 tcp_snd_dat(s->cepid, "?", 1, TMO_FEVR); 580 len = strlen(s->query);585 len = ntlibc_strlen(s->query); 581 586 tcp_snd_dat(s->cepid, s->query, len, TMO_FEVR); 582 587 } … … 590 595 tcp_snd_dat(s->cepid, (void *)http_content_type_binary, len, TMO_FEVR); 591 596 } 592 else if ( strncmp(http_html, ptr, sizeof(http_html) - 1) == 0 ||593 strncmp(http_htm, ptr, sizeof(http_htm) - 1) == 0) {597 else if (ntlibc_strncmp(http_html, ptr, sizeof(http_html) - 1) == 0 || 598 ntlibc_strncmp(http_htm, ptr, sizeof(http_htm) - 1) == 0) { 594 599 len = sizeof(http_content_type_html) - 1; 595 600 tcp_snd_dat(s->cepid, (void *)http_content_type_html, len, TMO_FEVR); 596 601 } 597 else if ( strncmp(http_css, ptr, sizeof(http_css) - 1) == 0) {602 else if (ntlibc_strncmp(http_css, ptr, sizeof(http_css) - 1) == 0) { 598 603 len = sizeof(http_content_type_css) - 1; 599 604 tcp_snd_dat(s->cepid, (void *)http_content_type_css, len, TMO_FEVR); 600 605 } 601 else if ( strncmp(http_js, ptr, sizeof(http_js) - 1) == 0) {606 else if (ntlibc_strncmp(http_js, ptr, sizeof(http_js) - 1) == 0) { 602 607 len = sizeof(http_content_type_js) - 1; 603 608 tcp_snd_dat(s->cepid, (void *)http_content_type_js, len, TMO_FEVR); 604 609 } 605 else if ( strncmp(http_json, ptr, sizeof(http_json) - 1) == 0) {610 else if (ntlibc_strncmp(http_json, ptr, sizeof(http_json) - 1) == 0) { 606 611 len = sizeof(http_content_type_json) - 1; 607 612 tcp_snd_dat(s->cepid, (void *)http_content_type_json, len, TMO_FEVR); 608 613 } 609 else if ( strncmp(http_png, ptr, sizeof(http_png) - 1) == 0) {614 else if (ntlibc_strncmp(http_png, ptr, sizeof(http_png) - 1) == 0) { 610 615 len = sizeof(http_content_type_png) - 1; 611 616 tcp_snd_dat(s->cepid, (void *)http_content_type_png, len, TMO_FEVR); 612 617 } 613 else if ( strncmp(http_gif, ptr, sizeof(http_gif) - 1) == 0) {618 else if (ntlibc_strncmp(http_gif, ptr, sizeof(http_gif) - 1) == 0) { 614 619 len = sizeof(http_content_type_gif) - 1; 615 620 tcp_snd_dat(s->cepid, (void *)http_content_type_gif, len, TMO_FEVR); 616 621 } 617 else if ( strncmp(http_jpg, ptr, sizeof(http_jpg) - 1) == 0) {622 else if (ntlibc_strncmp(http_jpg, ptr, sizeof(http_jpg) - 1) == 0) { 618 623 len = sizeof(http_content_type_jpg) - 1; 619 624 tcp_snd_dat(s->cepid, (void *)http_content_type_jpg, len, TMO_FEVR); 620 625 } 621 else if ( strncmp(http_svg, ptr, sizeof(http_svg) - 1) == 0) {626 else if (ntlibc_strncmp(http_svg, ptr, sizeof(http_svg) - 1) == 0) { 622 627 len = sizeof(http_content_type_svg) - 1; 623 628 tcp_snd_dat(s->cepid, (void *)http_content_type_svg, len, TMO_FEVR); 624 629 } 625 else if ( strncmp(http_text, ptr, sizeof(http_text) - 1) == 0) {630 else if (ntlibc_strncmp(http_text, ptr, sizeof(http_text) - 1) == 0) { 626 631 len = sizeof(http_content_type_text) - 1; 627 632 tcp_snd_dat(s->cepid, (void *)http_content_type_text, len, TMO_FEVR); 628 633 } 629 else if ( strncmp(http_eot, ptr, sizeof(http_eot) - 1) == 0) {634 else if (ntlibc_strncmp(http_eot, ptr, sizeof(http_eot) - 1) == 0) { 630 635 len = sizeof(http_content_type_eot) - 1; 631 636 tcp_snd_dat(s->cepid, (void *)http_content_type_eot, len, TMO_FEVR); 632 637 } 633 else if ( strncmp(http_ttf, ptr, sizeof(http_ttf) - 1) == 0) {638 else if (ntlibc_strncmp(http_ttf, ptr, sizeof(http_ttf) - 1) == 0) { 634 639 len = sizeof(http_content_type_ttf) - 1; 635 640 tcp_snd_dat(s->cepid, (void *)http_content_type_ttf, len, TMO_FEVR); 636 641 } 637 else if ( strncmp(http_woff, ptr, sizeof(http_woff) - 1) == 0) {642 else if (ntlibc_strncmp(http_woff, ptr, sizeof(http_woff) - 1) == 0) { 638 643 len = sizeof(http_content_type_woff) - 1; 639 644 tcp_snd_dat(s->cepid, (void *)http_content_type_woff, len, TMO_FEVR); 640 645 } 641 else if ( strncmp(http_woff2, ptr, sizeof(http_woff2) - 1) == 0) {646 else if (ntlibc_strncmp(http_woff2, ptr, sizeof(http_woff2) - 1) == 0) { 642 647 len = sizeof(http_content_type_woff2) - 1; 643 648 tcp_snd_dat(s->cepid, (void *)http_content_type_woff2, len, TMO_FEVR); 644 649 } 645 else if ( strncmp(http_ico, ptr, sizeof(http_ico) - 1) == 0) {650 else if (ntlibc_strncmp(http_ico, ptr, sizeof(http_ico) - 1) == 0) { 646 651 len = sizeof(http_content_type_ico) - 1; 647 652 tcp_snd_dat(s->cepid, (void *)http_content_type_ico, len, TMO_FEVR); … … 656 661 tcp_snd_dat(s->cepid, (void *)http_content_length, len, TMO_FEVR); 657 662 ntstdio_snprintf(s->temp, sizeof(s->temp), "%d\r\n", s->file.len); 658 tcp_snd_dat(s->cepid, (void *)s->temp, strlen(s->temp), TMO_FEVR);663 tcp_snd_dat(s->cepid, (void *)s->temp, ntlibc_strlen(s->temp), TMO_FEVR); 659 664 } 660 665 … … 732 737 int len; 733 738 734 len = strlen(statushdr);739 len = ntlibc_strlen(statushdr); 735 740 tcp_snd_dat(s->cepid, (void *)statushdr, len, TMO_FEVR); 736 741 737 742 len = sizeof(http_upgrade) - 1; 738 743 tcp_snd_dat(s->cepid, (void *)http_upgrade, len, TMO_FEVR); 739 len = strlen(s->message.upgrade);744 len = ntlibc_strlen(s->message.upgrade); 740 745 tcp_snd_dat(s->cepid, s->message.upgrade, len, TMO_FEVR); 741 746 len = sizeof(http_crnl) - 1; … … 744 749 len = sizeof(http_connection) - 1; 745 750 tcp_snd_dat(s->cepid, (void *)http_connection, len, TMO_FEVR); 746 len = strlen(s->message.connection);751 len = ntlibc_strlen(s->message.connection); 747 752 tcp_snd_dat(s->cepid, s->message.connection, len, TMO_FEVR); 748 753 len = sizeof(http_crnl) - 1; … … 751 756 len = sizeof(http_sec_websocket_accept) - 1; 752 757 tcp_snd_dat(s->cepid, (void *)http_sec_websocket_accept, len, TMO_FEVR); 753 len = strlen(s->message.response_key);758 len = ntlibc_strlen(s->message.response_key); 754 759 tcp_snd_dat(s->cepid, s->message.response_key, len, TMO_FEVR); 755 760 len = sizeof(http_crnl) - 1; … … 758 763 len = sizeof(http_sec_websocket_protocol) - 1; 759 764 tcp_snd_dat(s->cepid, (void *)http_sec_websocket_protocol, len, TMO_FEVR); 760 len = strlen(s->message.sec_websocket_protocol);765 len = ntlibc_strlen(s->message.sec_websocket_protocol); 761 766 tcp_snd_dat(s->cepid, s->message.sec_websocket_protocol, len, TMO_FEVR); 762 767 len = sizeof(http_crnl) - 1;
Note:
See TracChangeset
for help on using the changeset viewer.