/*
 * Internal redirect / subrequest handler, working on request_status hook
 */
static int scgi_request_status(int *status, request_rec *r)
{
    scgi_request_config *req_conf;

    if (   (*status == OK)
        && (req_conf = ap_get_module_config(r->request_config,
                                            &proxy_scgi_module))) {
        switch (req_conf->type) {
        case scgi_internal_redirect:
            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
                          "proxy: " PROXY_FUNCTION ": Internal redirect to %s",
                          req_conf->location);

            r->status_line = NULL;
            if (r->method_number != M_GET) {
                /* keep HEAD, which is passed around as M_GET, too */
                r->method = "GET";
                r->method_number = M_GET;
            }
            apr_table_unset(r->headers_in, "Content-Length");
            ap_internal_redirect_handler(req_conf->location, r);
            return OK;
            /* break; */

        case scgi_sendfile:
            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
                          "proxy: " PROXY_FUNCTION ": File subrequest to %s",
                          req_conf->location);
            do {
                request_rec *rr;

                rr = ap_sub_req_lookup_file(req_conf->location, r,
                                            r->output_filters);
                if (rr->status == HTTP_OK && rr->finfo.filetype != 0) {
                    /*
                     * We don't touch Content-Length here. It might be
                     * borked (there's plenty of room for a race condition).
                     * Either the backend sets it or it's gonna be chunked.
                     */
                    ap_run_sub_req(rr);
                }
                else {
                    ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
                                  "Subrequest to file '%s' not possible. "
                                  "(rr->status=%d, rr->finfo.filetype=%d)",
                                  req_conf->location, rr->status,
                                  rr->finfo.filetype);
                    *status = HTTP_INTERNAL_SERVER_ERROR;
                    return *status;
                }
            } while(0);

            return OK;
            /* break; */
        }
    }

    return DECLINED;
}
Exemplo n.º 2
0
static int papi_send_file (request_rec *r, const char *filename)
{	
	request_rec *rs = ap_sub_req_lookup_file (filename, r, NULL);
	ap_set_content_type (r, rs->content_type);
	int err = ap_run_sub_req (rs);
	if (err != OK)
		APACHE_LOG (APLOG_ERR, "Cookie_Handler: Exception handling %s (%d)",
					   filename, err);
	ap_destroy_sub_req (rs);
	return err;
}
/*============================================================================
 *============================================================================
 * This is the beginning of the cgi filter code moved from mod_include. This
 *   is the code required to handle the "exec" SSI directive.
 *============================================================================
 *============================================================================*/
static apr_status_t include_cgi(include_ctx_t *ctx, ap_filter_t *f,
                                apr_bucket_brigade *bb, char *s)
{
    request_rec *r = f->r;
    request_rec *rr = ap_sub_req_lookup_uri(s, r, f->next);
    int rr_status;

    if (rr->status != HTTP_OK) {
        ap_destroy_sub_req(rr);
        return APR_EGENERAL;
    }

    /* No hardwired path info or query allowed */
    if ((rr->path_info && rr->path_info[0]) || rr->args) {
        ap_destroy_sub_req(rr);
        return APR_EGENERAL;
    }
    if (rr->finfo.filetype != APR_REG) {
        ap_destroy_sub_req(rr);
        return APR_EGENERAL;
    }

    /* Script gets parameters of the *document*, for back compatibility */
    rr->path_info = r->path_info;       /* hard to get right; see mod_cgi.c */
    rr->args = r->args;

    /* Force sub_req to be treated as a CGI request, even if ordinary
     * typing rules would have called it something else.
     */
    ap_set_content_type(rr, CGI_MAGIC_TYPE);

    /* Run it. */
    rr_status = ap_run_sub_req(rr);
    if (ap_is_HTTP_REDIRECT(rr_status)) {
        const char *location = apr_table_get(rr->headers_out, "Location");

        if (location) {
            char *buffer;

            location = ap_escape_html(rr->pool, location);
            buffer = apr_pstrcat(ctx->pool, "<a href=\"", location, "\">",
                                 location, "</a>", NULL);

            APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_pool_create(buffer,
                                    strlen(buffer), ctx->pool,
                                    f->c->bucket_alloc));
        }
    }

    ap_destroy_sub_req(rr);

    return APR_SUCCESS;
}
Exemplo n.º 4
0
static int papi_send_file_with_cookies (request_rec *r, const char *filename, const char *lcook)
{
	
	request_rec *rs = ap_sub_req_lookup_file (filename, r, NULL);
	apr_table_set (r->err_headers_out, "Set-cookie", lcook);
	ap_set_content_type (r, rs->content_type);
	int err = ap_run_sub_req (rs);
	if (err != OK)
		APACHE_LOG (APLOG_ERR, "Cookie_Handler: Exception handling %s", filename);
	ap_destroy_sub_req (rs);
	return err;
}	
Exemplo n.º 5
0
static am_status_t set_custom_response(am_request_t *rq, const char *text, const char *cont_type) {
    request_rec *r = (request_rec *) (rq != NULL ? rq->ctx : NULL);
    if (r == NULL || !ISVALID(text)) return AM_EINVAL;
    if (rq->status == AM_INTERNAL_REDIRECT) {
        ap_internal_redirect(text, r);
        rq->status = AM_DONE;
    } else if (rq->status == AM_REDIRECT) {
        apr_table_add(r->headers_out, "Location", text);
        ap_custom_response(r, HTTP_MOVED_TEMPORARILY, text);
    } else {
        if (rq->status == AM_PDP_DONE) {
            request_rec *sr = ap_sub_req_method_uri(am_method_num_to_str(rq->method),
                    rq->post_data_url, r, NULL);

            sr->headers_in = r->headers_in;
            sr->notes = r->notes;

            am_log_debug(rq->instance_id, "set_custom_response(): issuing sub-request %s to %s",
                    sr->method, rq->post_data_url);

            ap_run_sub_req(sr);
            ap_destroy_sub_req(sr);
            rq->status = AM_DONE;

        } else {
            size_t tl = strlen(text);
            if (ISVALID(cont_type)) {
                ap_set_content_type(r, cont_type);
            }
            ap_set_content_length(r, tl);
            ap_rwrite(text, (int) tl, r);
            ap_custom_response(r,
                    am_status_value(rq->status == AM_SUCCESS ||
                    rq->status == AM_DONE ? AM_SUCCESS : rq->status), text);
            ap_rflush(r);
        }
    }
    am_log_info(rq->instance_id, "set_custom_response(): status: %s", am_strerror(rq->status));
    return AM_SUCCESS;
}
Exemplo n.º 6
0
/* {{{ proto bool virtual(string uri)
 Perform an apache sub-request */
PHP_FUNCTION(virtual)
{
	char *filename;
	size_t filename_len;
	request_rec *rr;

	if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) {
		return;
	}

	if (!(rr = php_apache_lookup_uri(filename))) {
		php_error_docref(NULL, E_WARNING, "Unable to include '%s' - URI lookup failed", filename);
		RETURN_FALSE;
	}

	if (rr->status != HTTP_OK) {
		php_error_docref(NULL, E_WARNING, "Unable to include '%s' - error finding URI", filename);
		ap_destroy_sub_req(rr);
		RETURN_FALSE;
	}

	/* Flush everything. */
	php_output_end_all();
	php_header();

	/* Ensure that the ap_r* layer for the main request is flushed, to
	 * work around http://issues.apache.org/bugzilla/show_bug.cgi?id=17629 */
	ap_rflush(rr->main);

	if (ap_run_sub_req(rr)) {
		php_error_docref(NULL, E_WARNING, "Unable to include '%s' - request execution failed", filename);
		ap_destroy_sub_req(rr);
		RETURN_FALSE;
	}
	ap_destroy_sub_req(rr);
	RETURN_TRUE;
}