Changeset 441 for EcnlProtoTool/trunk/ntshell/webserver/httpd.c
- Timestamp:
- Jul 10, 2020, 9:09:25 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/ntshell/webserver/httpd.c
r436 r441 59 59 #define FALSE 0 60 60 61 extern ntstdio_t ntstdio;61 extern ntstdio_t *ntstdio; 62 62 SYSTIM httpd_time; 63 63 struct httpd_state *uploding; … … 65 65 66 66 /* TCP 送受信ウィンドバッファ */ 67 #ifdef SUPPORT_INET6 68 uint8_t tcp6_swbuf1[TCP_SWBUF_SIZE]; 69 uint8_t tcp6_rwbuf1[TCP_RWBUF_SIZE]; 70 uint8_t tcp6_swbuf2[TCP_SWBUF_SIZE]; 71 uint8_t tcp6_rwbuf2[TCP_RWBUF_SIZE]; 72 #endif 73 74 #ifdef SUPPORT_INET4 67 75 uint8_t tcp_swbuf1[TCP_SWBUF_SIZE]; 68 76 uint8_t tcp_rwbuf1[TCP_RWBUF_SIZE]; 69 77 uint8_t tcp_swbuf2[TCP_SWBUF_SIZE]; 70 78 uint8_t tcp_rwbuf2[TCP_RWBUF_SIZE]; 79 #endif 71 80 72 81 #define ISO_nl 0x0a … … 325 334 // アップロード先はSDカード 326 335 s->filename[0] = '1'; 327 ntstdio_printf( &ntstdio, "create: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);336 ntstdio_printf(ntstdio, "create: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 328 337 if (!httpd_fs_create(s->filename, &s->file)) { 329 338 goto error; … … 333 342 } 334 343 else if (ntlibc_strcmp(s->filename, uploding->filename) == 0) { 335 ntstdio_printf( &ntstdio, "collision: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);344 ntstdio_printf(ntstdio, "collision: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 336 345 goto error; 337 346 } … … 365 374 366 375 if (s->message.body_is_final) { 367 ntstdio_printf( &ntstdio, "\n\n *** Error http_body_is_final() should return 1 \n"376 ntstdio_printf(ntstdio, "\n\n *** Error http_body_is_final() should return 1 \n" 368 377 "on last on_body callback call " 369 378 "but it doesn't! ***\n\n"); … … 378 387 379 388 if (s->message.body_is_final) { 380 ntstdio_printf( &ntstdio, "close: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);389 ntstdio_printf(ntstdio, "close: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 381 390 httpd_fs_close(&s->file); 382 391 memset(&s->file, 0, sizeof(s->file)); … … 403 412 struct httpd_state *s = get_context(p); 404 413 if (s->message.should_keep_alive != http_should_keep_alive(p)) { 405 ntstdio_printf( &ntstdio, "\n\n *** Error http_should_keep_alive() should have same \n"414 ntstdio_printf(ntstdio, "\n\n *** Error http_should_keep_alive() should have same \n" 406 415 "value in both on_message_complete and on_headers_complete " 407 416 "but it doesn't! ***\n\n"); … … 412 421 http_body_is_final(p) && 413 422 !s->message.body_is_final) { 414 ntstdio_printf( &ntstdio, "\n\n *** Error http_body_is_final() should return 1 \n"423 ntstdio_printf(ntstdio, "\n\n *** Error http_body_is_final() should return 1 \n" 415 424 "on last on_body callback call " 416 425 "but it doesn't! ***\n\n"); … … 484 493 slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR); 485 494 if (slen < 0) { 486 ntstdio_printf( &ntstdio, "send_file#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);495 ntstdio_printf(ntstdio, "send_file#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 487 496 s->state = STATE_CLOSING; 488 497 break; … … 497 506 len = httpd_fs_read(&s->file, buf, len); 498 507 if (len <= 0) { 499 ntstdio_printf( &ntstdio, "send_file#httpd_fs_read(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, len);508 ntstdio_printf(ntstdio, "send_file#httpd_fs_read(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, len); 500 509 break; 501 510 } … … 505 514 506 515 if ((slen = tcp_snd_buf(s->cepid, len)) != E_OK) { 507 ntstdio_printf( &ntstdio, "send_file#tcp_snd_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);516 ntstdio_printf(ntstdio, "send_file#tcp_snd_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 508 517 s->state = STATE_CLOSING; 509 518 break; … … 511 520 } 512 521 513 ntstdio_printf( &ntstdio, "close: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);522 ntstdio_printf(ntstdio, "close: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 514 523 httpd_fs_close(&s->file); 515 524 s->file.len = 0; … … 527 536 slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR); 528 537 if (slen < 0) { 529 ntstdio_printf( &ntstdio, "send_data#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);538 ntstdio_printf(ntstdio, "send_data#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 530 539 s->state = STATE_CLOSING; 531 540 break; … … 544 553 545 554 if ((slen = tcp_snd_buf(s->cepid, len)) != E_OK) { 546 ntstdio_printf( &ntstdio, "send_data#tcp_snd_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);555 ntstdio_printf(ntstdio, "send_data#tcp_snd_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 547 556 s->state = STATE_CLOSING; 548 557 break; … … 690 699 break; 691 700 case OUT_STATE_OPEN_GET_FILE: 692 ntstdio_printf( &ntstdio, "open: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);701 ntstdio_printf(ntstdio, "open: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename); 693 702 if (!httpd_fs_open(s->filename, sizeof(s->message.request_url), &s->file)) { 694 703 s->filename = NULL; … … 704 713 break; 705 714 case OUT_STATE_WAIT_POST_BODY: 706 //ntstdio_printf( &ntstdio, "wait post body\n");715 //ntstdio_printf(ntstdio, "wait post body\n"); 707 716 s->out.wait = true; 708 717 break; 709 718 case OUT_STATE_BODY_RECEIVED: 710 //ntstdio_printf( &ntstdio, "body received\n");719 //ntstdio_printf(ntstdio, "body received\n"); 711 720 s->out.statushdr = http_header_200; 712 721 s->out.state = OUT_STATE_SEND_HEADER; 713 722 break; 714 723 case OUT_STATE_SEND_HEADER: 715 //ntstdio_printf( &ntstdio, "send header\n");724 //ntstdio_printf(ntstdio, "send header\n"); 716 725 send_headers(s, s->out.statushdr); 717 726 break; 718 727 case OUT_STATE_SEND_FILE: 719 //ntstdio_printf( &ntstdio, "send file %d\n", s->file.len);728 //ntstdio_printf(ntstdio, "send file %d\n", s->file.len); 720 729 send_file(s); 721 730 break; 722 731 case OUT_STATE_SEND_DATA: 723 //ntstdio_printf( &ntstdio, "send data %d\n", s->response_len);732 //ntstdio_printf(ntstdio, "send data %d\n", s->response_len); 724 733 send_data(s); 725 734 break; 726 735 case OUT_STATE_SEND_END: 727 //ntstdio_printf( &ntstdio, "send end\n");736 //ntstdio_printf(ntstdio, "send end\n"); 728 737 s->out.wait = true; 729 738 if (s->message.should_keep_alive && s->reset == 0) { … … 783 792 slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR); 784 793 if (slen < 0) { 785 ntstdio_printf( &ntstdio, "send_ws_data#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);794 ntstdio_printf(ntstdio, "send_ws_data#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen); 786 795 return; 787 796 } … … 847 856 //} 848 857 } 849 ntstdio_printf( &ntstdio, "handle_input#tcp_rcv_buf#%d(%s.%d) => %d\n", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len);858 ntstdio_printf(ntstdio, "handle_input#tcp_rcv_buf#%d(%s.%d) => %d\n", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len); 850 859 uploding = NULL; 851 860 s->state = STATE_CLOSING; … … 855 864 tcp_rel_buf(s->cepid, done); 856 865 if (s->parser.http_errno != HPE_OK) { 857 ntstdio_printf( &ntstdio, "http_parser error %s.%d => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->parser.http_errno);866 ntstdio_printf(ntstdio, "http_parser error %s.%d => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->parser.http_errno); 858 867 uploding = NULL; 859 868 s->state = STATE_CLOSING; … … 880 889 break; 881 890 } 882 ntstdio_printf( &ntstdio, "handle_input#tcp_rcv_buf#%d(%s.%d) => %d\n", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len);891 ntstdio_printf(ntstdio, "handle_input#tcp_rcv_buf#%d(%s.%d) => %d\n", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len); 883 892 s->state = STATE_CLOSING; 884 893 break; … … 918 927 919 928 if (s == NULL) 920 ntstdio_printf( &ntstdio, "callback_nblk_tcp(%d, %d)\n", fncd, cepid);929 ntstdio_printf(ntstdio, "callback_nblk_tcp(%d, %d)\n", fncd, cepid); 921 930 else 922 ntstdio_printf( &ntstdio, "callback_nblk_tcp(%d, %s.%d)\n", fncd, s->addr, ((T_IPV4EP *)s->dst)->portno);931 ntstdio_printf(ntstdio, "callback_nblk_tcp(%d, %s.%d)\n", fncd, s->addr, ((T_IPV4EP *)s->dst)->portno); 923 932 924 933 return E_PAR; … … 936 945 ret2 = get_tim(&httpd_time); 937 946 if (ret2 != E_OK) { 938 ntstdio_printf( &ntstdio, "get_tim\n");947 ntstdio_printf(ntstdio, "get_tim\n"); 939 948 return; 940 949 } … … 944 953 memset(&s->dst, 0, sizeof(s->dst)); 945 954 if ((ret = tcp_acp_cep(s->cepid, TCP_REPID, (T_IPV4EP *)s->dst, TMO_FEVR)) != E_OK) { 946 ntstdio_printf( &ntstdio, "tcp_acp_cep(%d) => %d\n", s->cepid, ret);955 ntstdio_printf(ntstdio, "tcp_acp_cep(%d) => %d\n", s->cepid, ret); 947 956 tslp_tsk(100 * 1000); // TODO 948 957 s->state = STATE_CLOSING; … … 950 959 } 951 960 IP2STR(s->addr, &((T_IPV4EP *)s->dst)->ipaddr); 952 ntstdio_printf( &ntstdio, "connected: %s.%d\n", s->addr, ((T_IPV4EP *)s->dst)->portno);961 ntstdio_printf(ntstdio, "connected: %s.%d\n", s->addr, ((T_IPV4EP *)s->dst)->portno); 953 962 memset(&s->in, 0, sizeof(s->in)); 954 963 memset(&s->out, 0, sizeof(s->out)); … … 965 974 break; 966 975 case STATE_CLOSING: 967 ntstdio_printf( &ntstdio, "close: %s.%d\n", s->addr, ((T_IPV4EP *)s->dst)->portno);976 ntstdio_printf(ntstdio, "close: %s.%d\n", s->addr, ((T_IPV4EP *)s->dst)->portno); 968 977 tcp_sht_cep(s->cepid); 969 978 tcp_cls_cep(s->cepid, TMO_FEVR);
Note:
See TracChangeset
for help on using the changeset viewer.