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

Function set_error_document

server/core.c:1667–1747  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1665}
1666
1667static const char *set_error_document(cmd_parms *cmd, void *conf_,
1668 const char *errno_str, const char *msg)
1669{
1670 core_dir_config *conf = conf_;
1671 int error_number, index_number, idx500;
1672 enum { MSG, LOCAL_PATH, REMOTE_PATH } what = MSG;
1673
1674 /* 1st parameter should be a 3 digit number, which we recognize;
1675 * convert it into an array index
1676 */
1677 error_number = atoi(errno_str);
1678 idx500 = ap_index_of_response(HTTP_INTERNAL_SERVER_ERROR);
1679
1680 if (error_number == HTTP_INTERNAL_SERVER_ERROR) {
1681 index_number = idx500;
1682 }
1683 else if ((index_number = ap_index_of_response(error_number)) == idx500) {
1684 return apr_pstrcat(cmd->pool, "Unsupported HTTP response code ",
1685 errno_str, NULL);
1686 }
1687
1688 /* Heuristic to determine second argument. */
1689 if (ap_strchr_c(msg,' '))
1690 what = MSG;
1691 else if (msg[0] == '/')
1692 what = LOCAL_PATH;
1693 else if (ap_is_url(msg))
1694 what = REMOTE_PATH;
1695 else
1696 what = MSG;
1697
1698 /* The entry should be ignored if it is a full URL for a 401 error */
1699
1700 if (error_number == 401 && what == REMOTE_PATH) {
1701 ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, cmd->server, APLOGNO(00113)
1702 "%s:%d cannot use a full URL in a 401 ErrorDocument "
1703 "directive --- ignoring!", cmd->directive->filename, cmd->directive->line_num);
1704 }
1705 else { /* Store it... */
1706 if (conf->response_code_exprs == NULL) {
1707 conf->response_code_exprs = apr_hash_make(cmd->pool);
1708 }
1709
1710 if (ap_cstr_casecmp(msg, "default") == 0) {
1711 /* special case: ErrorDocument 404 default restores the
1712 * canned server error response
1713 */
1714 apr_hash_set(conf->response_code_exprs,
1715 apr_pmemdup(cmd->pool, &index_number, sizeof(index_number)),
1716 sizeof(index_number), &errordocument_default);
1717 }
1718 else {
1719 ap_expr_info_t *expr;
1720 const char *expr_err = NULL;
1721
1722 /* hack. Prefix a " if it is a msg; as that is what
1723 * http_protocol.c relies on to distinguish between
1724 * a msg and a (local) path.

Callers

nothing calls this directly

Calls 5

ap_index_of_responseFunction · 0.85
ap_strchr_cFunction · 0.85
ap_is_urlFunction · 0.85
ap_cstr_casecmpFunction · 0.85
ap_log_errorFunction · 0.50

Tested by

no test coverage detected