MCPcopy Create free account
hub / github.com/apache/httpd / include_cgi

Function include_cgi

modules/generators/mod_cgi.c:645–697  ·  view source on GitHub ↗

============================================================================ *============================================================================ * This is the beginning of the cgi filter code moved from mod_include. This * is the code required to handle the "exec" SSI directive. *============================================================================ *========================

Source from the content-addressed store, hash-verified

643 *============================================================================
644 *============================================================================*/
645static apr_status_t include_cgi(include_ctx_t *ctx, ap_filter_t *f,
646 apr_bucket_brigade *bb, char *s)
647{
648 request_rec *r = f->r;
649 request_rec *rr = ap_sub_req_lookup_uri(s, r, f->next);
650 int rr_status;
651
652 if (rr->status != HTTP_OK) {
653 ap_destroy_sub_req(rr);
654 return APR_EGENERAL;
655 }
656
657 /* No hardwired path info or query allowed */
658 if ((rr->path_info && rr->path_info[0]) || rr->args) {
659 ap_destroy_sub_req(rr);
660 return APR_EGENERAL;
661 }
662 if (rr->finfo.filetype != APR_REG) {
663 ap_destroy_sub_req(rr);
664 return APR_EGENERAL;
665 }
666
667 /* Script gets parameters of the *document*, for back compatibility */
668 rr->path_info = r->path_info; /* hard to get right; see mod_cgi.c */
669 rr->args = r->args;
670
671 /* Force sub_req to be treated as a CGI request, even if ordinary
672 * typing rules would have called it something else.
673 */
674 ap_set_content_type_ex(rr, CGI_MAGIC_TYPE, 1);
675
676 /* Run it. */
677 rr_status = ap_run_sub_req(rr);
678 if (ap_is_HTTP_REDIRECT(rr_status)) {
679 const char *location = apr_table_get(rr->headers_out, "Location");
680
681 if (location) {
682 char *buffer;
683
684 location = ap_escape_html(rr->pool, location);
685 buffer = apr_pstrcat(ctx->pool, "<a href=\"", location, "\">",
686 location, "</a>", NULL);
687
688 APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_pool_create(buffer,
689 strlen(buffer), ctx->pool,
690 f->c->bucket_alloc));
691 }
692 }
693
694 ap_destroy_sub_req(rr);
695
696 return APR_SUCCESS;
697}
698
699static apr_status_t include_cmd(include_ctx_t *ctx, ap_filter_t *f,
700 apr_bucket_brigade *bb, const char *command)

Callers 1

cgi_handle_execFunction · 0.70

Calls 4

ap_sub_req_lookup_uriFunction · 0.85
ap_destroy_sub_reqFunction · 0.85
ap_set_content_type_exFunction · 0.85
ap_run_sub_reqFunction · 0.85

Tested by

no test coverage detected