src/server/daemon/httprequest.c

branch
webdav
changeset 339
f4a34b0869c7
parent 333
bb536d4bc174
child 354
017eda1be105
equal deleted inserted replaced
338:c62ea2a2133b 339:f4a34b0869c7
373 } 373 }
374 374
375 // check for request body and prepare input buffer 375 // check for request body and prepare input buffer
376 char *ctlen_str = pblock_findkeyval(pb_key_content_length, rq->rq.headers); 376 char *ctlen_str = pblock_findkeyval(pb_key_content_length, rq->rq.headers);
377 if(ctlen_str) { 377 if(ctlen_str) {
378 int ctlen = atoi(ctlen_str); // TODO: use other func 378 int64_t ctlen;
379 379 if(util_strtoint(ctlen_str, &ctlen)) {
380 //printf("request body length: %d\n", ctlen); 380 netbuf *nb = sn->netbuf;
381 381 HttpStream *net_io = (HttpStream*)sn->sn.csd;
382 netbuf *nb = sn->netbuf; 382
383 HttpStream *net_io = (HttpStream*)sn->sn.csd; 383 // how many bytes are already read and in the buffer
384 384 int cur_input_available = nb->cursize - nb->pos;
385 // how many bytes are already read and in the buffer 385
386 int cur_input_available = nb->cursize - nb->pos; 386 if(cur_input_available >= ctlen) {
387 387 // we have the whole request body in the buffer and
388 if(cur_input_available >= ctlen) { 388 // maybe even more
389 // we have the whole request body in the buffer and 389 // no more read from the socket is necessary to get the body,
390 // maybe even more 390 // therefore disable it
391 // no more read from the socket is necessary to get the body, 391 net_io->max_read = 0;
392 // therefore disable it 392 } else {
393 net_io->max_read = 0; 393 // read still required to get the complete request body
394 } else { 394 net_io->max_read = ctlen - cur_input_available;
395 // read still required to get the complete request body 395 }
396 net_io->max_read = ctlen - cur_input_available; 396 //printf("request body length: %d\n", ctlen);
397 } 397 } // else: should we abort?
398 } 398 }
399 char *transfer_encoding = pblock_findkeyval(pb_key_transfer_encoding, rq->rq.headers); 399 char *transfer_encoding = pblock_findkeyval(pb_key_transfer_encoding, rq->rq.headers);
400 if(transfer_encoding) { 400 if(transfer_encoding) {
401 if(!strcmp(transfer_encoding, "chunked")) { 401 if(!strcmp(transfer_encoding, "chunked")) {
402 netbuf *nb = sn->netbuf; 402 netbuf *nb = sn->netbuf;
876 ret = nsapi_exec(d, sn, rq); 876 ret = nsapi_exec(d, sn, rq);
877 } 877 }
878 878
879 if(ret != REQ_NOACTION) { 879 if(ret != REQ_NOACTION) {
880 if(ret == REQ_PROCEED) { 880 if(ret == REQ_PROCEED) {
881 /* 881 // flush buffer and add termination if chunked encoding
882 * flush buffer and add termination if chunked encoding 882 // is enabled
883 * is enabled
884 */
885 net_finish(sn->sn.csd); 883 net_finish(sn->sn.csd);
886 } else if(ret == REQ_PROCESSING) { 884 } else if(ret == REQ_PROCESSING) {
887 // save nsapi context 885 // save nsapi context
888 rq->context.objset_index = i; 886 rq->context.objset_index = i;
889 887
915 // execute directives 913 // execute directives
916 for(int j=NCX_DI(rq);j<dt->ndir;j++) { 914 for(int j=NCX_DI(rq);j<dt->ndir;j++) {
917 if(ret == REQ_NOACTION) { 915 if(ret == REQ_NOACTION) {
918 directive *d = dt->dirs[j]; 916 directive *d = dt->dirs[j];
919 917
920 // check status code parameter 918 // check status code parameter
919 // Error SAFs can specify, for which status code they should
920 // be executed
921 char *status = pblock_findkeyval(pb_key_type, d->param); 921 char *status = pblock_findkeyval(pb_key_type, d->param);
922 if(status) { 922 if(status) {
923 int statuscode = atoi(status); 923 int64_t statuscode = -1;
924 if(statuscode != rq->rq.status_num) { 924 if(!util_strtoint(status, &statuscode)) {
925 log_ereport(
926 LOG_WARN,
927 "nsapi_error: directive '%s' ignored: invalid type parameter: integer status code expected",
928 d->func->name);
929 } else if(statuscode != rq->rq.status_num) {
925 continue; 930 continue;
926 } 931 }
927 } 932 }
928 933
929 // execute the saf 934 // execute the saf
935 // error handler 940 // error handler
936 break; 941 break;
937 } 942 }
938 if(ret != REQ_NOACTION) { 943 if(ret != REQ_NOACTION) {
939 if(ret == REQ_PROCEED) { 944 if(ret == REQ_PROCEED) {
940 /* 945 // flush buffer and add termination if chunked encoding
941 * flush buffer and add termination if chunked encoding 946 // is enabled
942 * is enabled
943 */
944 net_finish(sn->sn.csd); 947 net_finish(sn->sn.csd);
945 } else if(ret == REQ_PROCESSING) { 948 } else if(ret == REQ_PROCESSING) {
946 // save nsapi context 949 // save nsapi context
947 rq->context.objset_index = i; 950 rq->context.objset_index = i;
948 951

mercurial