Skip to content

Commit 75f7b96

Browse files
author
Stefan Fritsch
committed
Implement "HTTPS" and "IPV6" vars in ap_expr
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1032170 13f79535-47bb-0310-9956-ffa450edef68
1 parent a1165f4 commit 75f7b96

1 file changed

Lines changed: 57 additions & 5 deletions

File tree

server/util_expr_eval.c

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,50 @@ static const char *unescape_func(ap_expr_eval_ctx *ctx, const char *name, const
759759

760760
}
761761

762+
APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
763+
static APR_OPTIONAL_FN_TYPE(ssl_is_https) *is_https = NULL;
764+
765+
static const char *conn_var_names[] = {
766+
"REMOTE_ADDR", /* 0 */
767+
"HTTPS", /* 1 */
768+
"IPV6", /* 2 */
769+
NULL
770+
};
771+
772+
static const char *conn_var_fn(ap_expr_eval_ctx *ctx, const void *data)
773+
{
774+
int index = ((const char **)data - conn_var_names);
775+
conn_rec *c = ctx->c;
776+
if (!c)
777+
return "";
778+
779+
switch (index) {
780+
case 0:
781+
return c->remote_ip;
782+
case 1:
783+
if (is_https && is_https(c))
784+
return "on";
785+
else
786+
return "off";
787+
case 2:
788+
#if APR_HAVE_IPV6
789+
{
790+
apr_sockaddr_t *addr = c->remote_addr;
791+
if (addr->family == AF_INET6
792+
&& !IN6_IS_ADDR_V4MAPPED((struct in6_addr *)addr->ipaddr_ptr))
793+
return "on";
794+
else
795+
return "off";
796+
}
797+
#else
798+
return "off";
799+
#endif
800+
default:
801+
ap_assert(0);
802+
return NULL;
803+
}
804+
}
805+
762806
static const char *request_var_names[] = {
763807
"REQUEST_METHOD", /* 0 */
764808
"REQUEST_SCHEME", /* 1 */
@@ -778,8 +822,7 @@ static const char *request_var_names[] = {
778822
"DOCUMENT_ROOT", /* 15 */
779823
"AUTH_TYPE", /* 16 */
780824
"THE_REQUEST", /* 17 */
781-
"REMOTE_ADDR", /* 18 */
782-
"CONTENT_TYPE", /* 19 */
825+
"CONTENT_TYPE", /* 18 */
783826
NULL
784827
};
785828

@@ -829,8 +872,6 @@ static const char *request_var_fn(ap_expr_eval_ctx *ctx, const void *data)
829872
case 17:
830873
return r->the_request;
831874
case 18:
832-
return ctx->c->remote_ip;
833-
case 19:
834875
return r->content_type;
835876
default:
836877
ap_assert(0);
@@ -932,6 +973,7 @@ static const struct expr_provider_multi var_providers[] = {
932973
{ misc_var_fn, misc_var_names },
933974
{ req_header_var_fn, req_header_var_names },
934975
{ request_var_fn, request_var_names },
976+
{ conn_var_fn, conn_var_names },
935977
{ NULL, NULL }
936978
};
937979

@@ -963,7 +1005,7 @@ static int core_expr_lookup(ap_expr_lookup_parms *parms)
9631005
*parms->data = name;
9641006
return OK;
9651007
}
966-
name++;
1008+
name++;
9671009
}
9681010
prov++;
9691011
}
@@ -1016,9 +1058,19 @@ static int expr_lookup_not_found(ap_expr_lookup_parms *parms)
10161058
return !OK;
10171059
}
10181060

1061+
static int ap_expr_post_config(apr_pool_t *pconf, apr_pool_t *plog,
1062+
apr_pool_t *ptemp, server_rec *s)
1063+
{
1064+
is_https = APR_RETRIEVE_OPTIONAL_FN(ssl_is_https);
1065+
apr_pool_cleanup_register(pconf, &is_https, ap_pool_cleanup_set_null,
1066+
apr_pool_cleanup_null);
1067+
return OK;
1068+
}
1069+
10191070
void ap_expr_init(apr_pool_t *p)
10201071
{
10211072
ap_hook_expr_lookup(core_expr_lookup, NULL, NULL, APR_HOOK_MIDDLE);
10221073
ap_hook_expr_lookup(expr_lookup_not_found, NULL, NULL, APR_HOOK_REALLY_LAST);
1074+
ap_hook_post_config(ap_expr_post_config, NULL, NULL, APR_HOOK_MIDDLE);
10231075
}
10241076

0 commit comments

Comments
 (0)