Ignore:
Timestamp:
Jul 10, 2020, 9:09:25 PM (4 years ago)
Author:
coas-nagasima
Message:

NTShellタスクを更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/ntshell/webserver/httpd.c

    r436 r441  
    5959#define FALSE 0
    6060
    61 extern ntstdio_t ntstdio;
     61extern ntstdio_t *ntstdio;
    6262SYSTIM httpd_time;
    6363struct httpd_state *uploding;
     
    6565
    6666/*  TCP 送受信ウィンドバッファ  */
     67#ifdef SUPPORT_INET6
     68uint8_t tcp6_swbuf1[TCP_SWBUF_SIZE];
     69uint8_t tcp6_rwbuf1[TCP_RWBUF_SIZE];
     70uint8_t tcp6_swbuf2[TCP_SWBUF_SIZE];
     71uint8_t tcp6_rwbuf2[TCP_RWBUF_SIZE];
     72#endif
     73
     74#ifdef SUPPORT_INET4
    6775uint8_t tcp_swbuf1[TCP_SWBUF_SIZE];
    6876uint8_t tcp_rwbuf1[TCP_RWBUF_SIZE];
    6977uint8_t tcp_swbuf2[TCP_SWBUF_SIZE];
    7078uint8_t tcp_rwbuf2[TCP_RWBUF_SIZE];
     79#endif
    7180
    7281#define ISO_nl      0x0a
     
    325334                        // アップロード先はSDカード
    326335                        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);
    328337                        if (!httpd_fs_create(s->filename, &s->file)) {
    329338                                goto error;
     
    333342                }
    334343                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);
    336345                        goto error;
    337346                }
     
    365374
    366375        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"
    368377                        "on last on_body callback call "
    369378                        "but it doesn't! ***\n\n");
     
    378387
    379388        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);
    381390                httpd_fs_close(&s->file);
    382391                memset(&s->file, 0, sizeof(s->file));
     
    403412        struct httpd_state *s = get_context(p);
    404413        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"
    406415                        "value in both on_message_complete and on_headers_complete "
    407416                        "but it doesn't! ***\n\n");
     
    412421                http_body_is_final(p) &&
    413422                !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"
    415424                        "on last on_body callback call "
    416425                        "but it doesn't! ***\n\n");
     
    484493                slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR);
    485494                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);
    487496                        s->state = STATE_CLOSING;
    488497                        break;
     
    497506                len = httpd_fs_read(&s->file, buf, len);
    498507                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);
    500509                        break;
    501510                }
     
    505514
    506515                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);
    508517                        s->state = STATE_CLOSING;
    509518                        break;
     
    511520        }
    512521
    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);
    514523        httpd_fs_close(&s->file);
    515524        s->file.len = 0;
     
    527536                slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR);
    528537                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);
    530539                        s->state = STATE_CLOSING;
    531540                        break;
     
    544553
    545554                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);
    547556                        s->state = STATE_CLOSING;
    548557                        break;
     
    690699                break;
    691700        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);
    693702                if (!httpd_fs_open(s->filename, sizeof(s->message.request_url), &s->file)) {
    694703                        s->filename = NULL;
     
    704713                break;
    705714        case OUT_STATE_WAIT_POST_BODY:
    706                 //ntstdio_printf(&ntstdio, "wait post body\n");
     715                //ntstdio_printf(ntstdio, "wait post body\n");
    707716                s->out.wait = true;
    708717                break;
    709718        case OUT_STATE_BODY_RECEIVED:
    710                 //ntstdio_printf(&ntstdio, "body received\n");
     719                //ntstdio_printf(ntstdio, "body received\n");
    711720                s->out.statushdr = http_header_200;
    712721                s->out.state = OUT_STATE_SEND_HEADER;
    713722                break;
    714723        case OUT_STATE_SEND_HEADER:
    715                 //ntstdio_printf(&ntstdio, "send header\n");
     724                //ntstdio_printf(ntstdio, "send header\n");
    716725                send_headers(s, s->out.statushdr);
    717726                break;
    718727        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);
    720729                send_file(s);
    721730                break;
    722731        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);
    724733                send_data(s);
    725734                break;
    726735        case OUT_STATE_SEND_END:
    727                 //ntstdio_printf(&ntstdio, "send end\n");
     736                //ntstdio_printf(ntstdio, "send end\n");
    728737                s->out.wait = true;
    729738                if (s->message.should_keep_alive && s->reset == 0) {
     
    783792        slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR);
    784793        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);
    786795                return;
    787796        }
     
    847856                                //}
    848857                        }
    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);
    850859                        uploding = NULL;
    851860                        s->state = STATE_CLOSING;
     
    855864                tcp_rel_buf(s->cepid, done);
    856865                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);
    858867                        uploding = NULL;
    859868                        s->state = STATE_CLOSING;
     
    880889                                        break;
    881890                                }
    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);
    883892                                s->state = STATE_CLOSING;
    884893                                break;
     
    918927
    919928        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);
    921930        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);
    923932
    924933        return E_PAR;
     
    936945                ret2 = get_tim(&httpd_time);
    937946                if (ret2 != E_OK) {
    938                         ntstdio_printf(&ntstdio, "get_tim\n");
     947                        ntstdio_printf(ntstdio, "get_tim\n");
    939948                        return;
    940949                }
     
    944953                        memset(&s->dst, 0, sizeof(s->dst));
    945954                        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);
    947956                                tslp_tsk(100 * 1000);   // TODO
    948957                                s->state = STATE_CLOSING;
     
    950959                        }
    951960                        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);
    953962                        memset(&s->in, 0, sizeof(s->in));
    954963                        memset(&s->out, 0, sizeof(s->out));
     
    965974                        break;
    966975                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);
    968977                        tcp_sht_cep(s->cepid);
    969978                        tcp_cls_cep(s->cepid, TMO_FEVR);
Note: See TracChangeset for help on using the changeset viewer.