aboutsummaryrefslogtreecommitdiff
path: root/src/http/modules/ngx_http_ssl_module.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/http/modules/ngx_http_ssl_module.c')
-rw-r--r--src/http/modules/ngx_http_ssl_module.c70
1 files changed, 69 insertions, 1 deletions
diff --git a/src/http/modules/ngx_http_ssl_module.c b/src/http/modules/ngx_http_ssl_module.c
index 55f7b48a7..a70c7f2f5 100644
--- a/src/http/modules/ngx_http_ssl_module.c
+++ b/src/http/modules/ngx_http_ssl_module.c
@@ -9,11 +9,18 @@
#include <ngx_http.h>
+typedef u_char *(*ngx_ssl_variable_handler_pt)(ngx_connection_t *);
+
+
#define NGX_DEFLAUT_CERTIFICATE "cert.pem"
#define NGX_DEFLAUT_CERTIFICATE_KEY "cert.pem"
#define NGX_DEFLAUT_CIPHERS "ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP"
+static ngx_int_t ngx_http_ssl_variable(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data);
+
+static ngx_int_t ngx_http_ssl_add_variables(ngx_conf_t *cf);
static void *ngx_http_ssl_create_srv_conf(ngx_conf_t *cf);
static char *ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf,
void *parent, void *child);
@@ -97,7 +104,7 @@ static ngx_command_t ngx_http_ssl_commands[] = {
static ngx_http_module_t ngx_http_ssl_module_ctx = {
- NULL, /* preconfiguration */
+ ngx_http_ssl_add_variables, /* preconfiguration */
NULL, /* postconfiguration */
NULL, /* create main configuration */
@@ -127,9 +134,70 @@ ngx_module_t ngx_http_ssl_module = {
};
+static ngx_http_variable_t ngx_http_ssl_vars[] = {
+
+ { ngx_string("ssl_protocol"), ngx_http_ssl_variable,
+ (uintptr_t) ngx_ssl_get_protocol, NGX_HTTP_VAR_CHANGABLE, 0 },
+
+ { ngx_string("ssl_cipher"), ngx_http_ssl_variable,
+ (uintptr_t) ngx_ssl_get_cipher_name, NGX_HTTP_VAR_CHANGABLE, 0 },
+
+ { ngx_null_string, NULL, 0, 0, 0 }
+};
+
+
static u_char ngx_http_session_id_ctx[] = "HTTP";
+static ngx_int_t
+ngx_http_ssl_variable(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data)
+{
+ ngx_ssl_variable_handler_pt handler = (ngx_ssl_variable_handler_pt) data;
+
+ size_t len;
+ u_char *name;
+
+ if (r->connection->ssl) {
+
+ name = handler(r->connection);
+
+ for (len = 0; name[len]; len++) { /* void */ }
+
+ v->len = len;
+ v->valid = 1;
+ v->no_cachable = 0;
+ v->not_found = 0;
+ v->data = name;
+
+ return NGX_OK;
+ }
+
+ v->not_found = 1;
+
+ return NGX_OK;
+}
+
+
+static ngx_int_t
+ngx_http_ssl_add_variables(ngx_conf_t *cf)
+{
+ ngx_http_variable_t *var, *v;
+
+ for (v = ngx_http_ssl_vars; v->name.len; v++) {
+ var = ngx_http_add_variable(cf, &v->name, v->flags);
+ if (var == NULL) {
+ return NGX_ERROR;
+ }
+
+ var->handler = v->handler;
+ var->data = v->data;
+ }
+
+ return NGX_OK;
+}
+
+
static void *
ngx_http_ssl_create_srv_conf(ngx_conf_t *cf)
{