Read the request body and write it to fd 'script_out', using 'bb' * as temporary bucket brigade. If 'logbuf' is non-NULL, the first * logbufbytes of stdout are stored in logbuf. */
| 555 | * as temporary bucket brigade. If 'logbuf' is non-NULL, the first |
| 556 | * logbufbytes of stdout are stored in logbuf. */ |
| 557 | static apr_status_t cgi_handle_request(request_rec *r, apr_file_t *script_out, |
| 558 | apr_bucket_brigade *bb, |
| 559 | char *logbuf, apr_size_t logbufbytes) |
| 560 | { |
| 561 | int seen_eos = 0; |
| 562 | int child_stopped_reading = 0; |
| 563 | apr_status_t rv; |
| 564 | int dbpos = 0; |
| 565 | |
| 566 | do { |
| 567 | apr_bucket *bucket; |
| 568 | |
| 569 | rv = ap_get_brigade(r->input_filters, bb, AP_MODE_READBYTES, |
| 570 | APR_BLOCK_READ, HUGE_STRING_LEN); |
| 571 | |
| 572 | if (rv != APR_SUCCESS) { |
| 573 | return rv; |
| 574 | } |
| 575 | |
| 576 | for (bucket = APR_BRIGADE_FIRST(bb); |
| 577 | bucket != APR_BRIGADE_SENTINEL(bb); |
| 578 | bucket = APR_BUCKET_NEXT(bucket)) |
| 579 | { |
| 580 | const char *data; |
| 581 | apr_size_t len; |
| 582 | |
| 583 | if (APR_BUCKET_IS_EOS(bucket)) { |
| 584 | seen_eos = 1; |
| 585 | break; |
| 586 | } |
| 587 | |
| 588 | /* We can't do much with this. */ |
| 589 | if (APR_BUCKET_IS_FLUSH(bucket)) { |
| 590 | continue; |
| 591 | } |
| 592 | |
| 593 | /* If the child stopped, we still must read to EOS. */ |
| 594 | if (child_stopped_reading) { |
| 595 | continue; |
| 596 | } |
| 597 | |
| 598 | /* read */ |
| 599 | rv = apr_bucket_read(bucket, &data, &len, APR_BLOCK_READ); |
| 600 | if (rv) { |
| 601 | return rv; |
| 602 | } |
| 603 | |
| 604 | if (logbufbytes && dbpos < logbufbytes) { |
| 605 | int cursize; |
| 606 | |
| 607 | if ((dbpos + len) > logbufbytes) { |
| 608 | cursize = logbufbytes - dbpos; |
| 609 | } |
| 610 | else { |
| 611 | cursize = len; |
| 612 | } |
| 613 | memcpy(logbuf + dbpos, data, cursize); |
| 614 | dbpos += cursize; |
no test coverage detected