nginx-0.0.7-2004-07-15-20:35:51 import
diff --git a/src/http/modules/ngx_http_access_handler.c b/src/http/modules/ngx_http_access_handler.c
index 95e4f77..a57526e 100644
--- a/src/http/modules/ngx_http_access_handler.c
+++ b/src/http/modules/ngx_http_access_handler.c
@@ -193,8 +193,11 @@
     ngx_http_conf_ctx_t        *ctx;
     ngx_http_core_main_conf_t  *cmcf;
 
+#if 0
     ctx = (ngx_http_conf_ctx_t *) cycle->conf_ctx[ngx_http_module.index];
     cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
+#endif
+    cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
 
     h = ngx_push_array(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers);
     if (h == NULL) {
diff --git a/src/http/modules/ngx_http_ssl_filter.c b/src/http/modules/ngx_http_ssl_filter.c
index 297f5c7..f64ef54 100644
--- a/src/http/modules/ngx_http_ssl_filter.c
+++ b/src/http/modules/ngx_http_ssl_filter.c
@@ -3,52 +3,41 @@
 #include <ngx_core.h>
 #include <ngx_http.h>
 
+/* STUB */
+#define NGX_SSL_ERROR   -11
+
 
 #define NGX_DEFLAUT_CERTIFICATE      "cert.pem"
 #define NGX_DEFLAUT_CERTIFICATE_KEY  "cert.pem"
 
 
-typedef struct {
-    ngx_flag_t   enable;
-    ngx_str_t    certificate;
-    ngx_str_t    certificate_key;
-
-    SSL_CTX     *ssl_ctx;
-} ngx_http_ssl_srv_conf_t;
-
-
-typedef struct {
-    SSL       *ssl;
-} ngx_http_ssl_ctx_t;
-
-
 static ngx_int_t ngx_http_ssl_create_ssl(ngx_http_request_t *r);
 static void ngx_http_ssl_error(ngx_uint_t level, ngx_log_t *log, int err,
                                char *fmt, ...);
 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);
-static ngx_int_t ngx_http_ssl_filter_init(ngx_cycle_t *cycle);
+static ngx_int_t ngx_http_ssl_init_process(ngx_cycle_t *cycle);
 
 
 static ngx_command_t  ngx_http_charset_filter_commands[] = {
 
-    { ngx_string("ssl_"),
-      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
+    { ngx_string("ssl"),
+      NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
       ngx_conf_set_flag_slot,
       NGX_HTTP_SRV_CONF_OFFSET,
       offsetof(ngx_http_ssl_srv_conf_t, enable),
       NULL },
 
     { ngx_string("ssl_certificate"),
-      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
+      NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
       ngx_conf_set_str_slot,
       NGX_HTTP_SRV_CONF_OFFSET,
       offsetof(ngx_http_ssl_srv_conf_t, certificate),
       NULL },
 
     { ngx_string("ssl_certificate_key"),
-      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
+      NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
       ngx_conf_set_str_slot,
       NGX_HTTP_SRV_CONF_OFFSET,
       offsetof(ngx_http_ssl_srv_conf_t, certificate_key),
@@ -75,10 +64,10 @@
 ngx_module_t  ngx_http_ssl_filter_module = {
     NGX_MODULE,
     &ngx_http_ssl_filter_module_ctx,       /* module context */
-    NULL,                                  /* module directives */
+    ngx_http_charset_filter_commands,      /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
-    ngx_http_ssl_filter_init,              /* init module */
-    NULL                                   /* init process */
+    NULL,                                  /* init module */
+    ngx_http_ssl_init_process              /* init process */
 };
 
 
@@ -86,7 +75,6 @@
 {
     int                  n;
     SSL                 *ssl;
-    ngx_http_ssl_ctx_t  *ctx;
     ngx_http_log_ctx_t  *log_ctx;
 
     if (r->connection->ssl == NULL) {
@@ -334,18 +322,16 @@
 
     ngx_conf_merge_value(conf->enable, prev->enable, 0);
 
+    if (conf->enable == 0) {
+        return NGX_CONF_OK;
+    }
+
     ngx_conf_merge_str_value(conf->certificate, prev->certificate,
                              NGX_DEFLAUT_CERTIFICATE);
 
     ngx_conf_merge_str_value(conf->certificate_key, prev->certificate_key,
                              NGX_DEFLAUT_CERTIFICATE_KEY);
 
-    /* STUB: where to move ??? */
-    SSL_library_init();
-    SSL_load_error_strings();
-
-    /* TODO: inherit ssl_ctx */
-
     /* TODO: configure methods */
 
     conf->ssl_ctx = SSL_CTX_new(SSLv23_server_method());
@@ -358,14 +344,16 @@
     if (SSL_CTX_use_certificate_file(conf->ssl_ctx, conf->certificate.data,
                                      SSL_FILETYPE_PEM) == 0) {
         ngx_http_ssl_error(NGX_LOG_EMERG, cf->log, 0,
-                           "SSL_CTX_use_certificate_file() failed");
+                           "SSL_CTX_use_certificate_file(\"%s\") failed",
+                           conf->certificate.data);
         return NGX_CONF_ERROR;
     }
 
     if (SSL_CTX_use_PrivateKey_file(conf->ssl_ctx, conf->certificate_key.data,
                                     SSL_FILETYPE_PEM) == 0) {
         ngx_http_ssl_error(NGX_LOG_EMERG, cf->log, 0,
-                           "SSL_CTX_use_PrivateKey_file() failed");
+                           "SSL_CTX_use_PrivateKey_file(\"%s\") failed",
+                           conf->certificate_key.data);
         return NGX_CONF_ERROR;
     }
 
@@ -373,15 +361,27 @@
 }
 
 
-static ngx_int_t ngx_http_ssl_filter_init(ngx_cycle_t *cycle)
+static ngx_int_t ngx_http_ssl_init_process(ngx_cycle_t *cycle)
 {
-#if 0
-    ngx_http_next_header_filter = ngx_http_top_header_filter;
-    ngx_http_top_header_filter = ngx_http_ssl_header_filter;
+    ngx_uint_t                   i;
+    ngx_http_ssl_srv_conf_t     *sscf;
+    ngx_http_core_srv_conf_t   **cscfp;
+    ngx_http_core_main_conf_t   *cmcf;
 
-    ngx_http_next_body_filter = ngx_http_top_body_filter;
-    ngx_http_top_body_filter = ngx_http_ssl_body_filter;
+    cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
+
+    cscfp = cmcf->servers.elts;
+
+    for (i = 0; i < cmcf->servers.nelts; i++) {
+        sscf = cscfp[i]->ctx->srv_conf[ngx_http_ssl_filter_module.ctx_index];
+
+        if (sscf->enable) {
+            cscfp[i]->recv = ngx_ssl_recv;
+#if 0
+            cscfp[i]->send_chain = ngx_ssl_send_chain;
 #endif
+        }
+    }
 
     return NGX_OK;
 }
diff --git a/src/http/modules/ngx_http_ssl_filter.h b/src/http/modules/ngx_http_ssl_filter.h
index a96a267..a42ee91 100644
--- a/src/http/modules/ngx_http_ssl_filter.h
+++ b/src/http/modules/ngx_http_ssl_filter.h
@@ -7,8 +7,13 @@
 #include <ngx_http.h>
 
 
-#define NGX_SSL_ERROR         -10
-#define NGX_SSL_HTTP_ERROR    -11
+typedef struct {
+    ngx_flag_t      enable;
+    ngx_str_t       certificate;
+    ngx_str_t       certificate_key;
+
+    ngx_ssl_ctx_t  *ssl_ctx;
+} ngx_http_ssl_srv_conf_t;
 
 
 ngx_int_t ngx_http_ssl_read(ngx_http_request_t *r, u_char *buf, size_t size);
@@ -19,4 +24,7 @@
 void ngx_http_ssl_close_connection(SSL *ssl, ngx_log_t *log);
 
 
+extern ngx_module_t  ngx_http_ssl_filter_module;
+
+
 #endif /* _NGX_HTTP_SSL_FILTER_H_INCLUDED_ */
diff --git a/src/http/ngx_http_config.h b/src/http/ngx_http_config.h
index 03c6347..647566a 100644
--- a/src/http/ngx_http_config.h
+++ b/src/http/ngx_http_config.h
@@ -43,8 +43,14 @@
 #define ngx_http_get_module_srv_conf(r, module)  r->srv_conf[module.ctx_index]
 #define ngx_http_get_module_loc_conf(r, module)  r->loc_conf[module.ctx_index]
 
-#define ngx_http_conf_module_main_conf(cf, module)                            \
+#define ngx_http_conf_get_module_main_conf(cf, module)                        \
             ((ngx_http_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index]
+#define ngx_http_conf_get_module_srv_conf(cf, module)                         \
+        ngx_http_conf_get_module_srv_conf_could_not_be_implemented()
+
+#define ngx_http_cycle_get_module_main_conf(cycle, module)                    \
+       ((ngx_http_conf_ctx_t *)                                               \
+           cycle->conf_ctx[ngx_http_module.index])->main_conf[module.ctx_index]
 
 
 
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index 001ed89..dc6e873 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -18,7 +18,7 @@
 static char *ngx_http_core_merge_loc_conf(ngx_conf_t *cf,
                                           void *parent, void *child);
 
-static ngx_int_t ngx_http_core_init(ngx_cycle_t *cycle);
+static ngx_int_t ngx_http_core_init_process(ngx_cycle_t *cycle);
 static char *ngx_server_block(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy);
 static int ngx_cmp_locations(const void *first, const void *second);
 static char *ngx_location_block(ngx_conf_t *cf, ngx_command_t *cmd,
@@ -303,8 +303,8 @@
     &ngx_http_core_module_ctx,             /* module context */
     ngx_http_core_commands,                /* module directives */
     NGX_HTTP_MODULE,                       /* module type */
-    ngx_http_core_init,                    /* init module */
-    NULL                                   /* init child */
+    NULL,                                  /* init module */
+    ngx_http_core_init_process             /* init process */
 };
 
 
@@ -822,15 +822,18 @@
 #endif
 
 
-static ngx_int_t ngx_http_core_init(ngx_cycle_t *cycle)
+static ngx_int_t ngx_http_core_init_process(ngx_cycle_t *cycle)
 {
-#if 0
-    ngx_http_handler_pt        *h;
-    ngx_http_conf_ctx_t        *ctx;
-    ngx_http_core_main_conf_t  *cmcf;
+    ngx_uint_t                   i;
+    ngx_http_core_srv_conf_t   **cscfp;
+    ngx_http_core_main_conf_t   *cmcf;
 
-    ctx = (ngx_http_conf_ctx_t *) cycle->conf_ctx[ngx_http_module.index];
-    cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];
+    cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module);
+
+#if 0
+    ngx_http_core_init_module:
+
+    ngx_http_handler_pt         *h;
 
     ngx_test_null(h, ngx_push_array(
                              &cmcf->phases[NGX_HTTP_TRANSLATE_PHASE].handlers),
@@ -838,6 +841,15 @@
     *h = ngx_http_delay_handler;
 #endif
 
+    cscfp = cmcf->servers.elts;
+
+    for (i = 0; i < cmcf->servers.nelts; i++) {
+        if (cscfp[i]->recv == NULL) {
+            cscfp[i]->recv = ngx_io.recv;
+            cscfp[i]->send_chain = ngx_io.send_chain;
+        }
+    }
+
     return NGX_OK;
 }
 
diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h
index 051486a..98e020b 100644
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -47,26 +47,34 @@
 
 
 typedef struct {
-    ngx_array_t  locations;    /* array of ngx_http_core_loc_conf_t,
-                                  used in the translation handler
-                                  and in the merge phase */
+    ngx_recv_pt           recv;
+    ngx_send_chain_pt     send_chain;
 
-    ngx_array_t  listen;       /* 'listen', array of ngx_http_listen_t */
-    ngx_array_t  server_names; /* 'server_name',
-                                  array of ngx_http_server_name_t */
+    /*
+     * array of ngx_http_core_loc_conf_t, used in the translation handler
+     * and in the merge phase
+     */
+    ngx_array_t           locations;
 
-    ngx_http_conf_ctx_t *ctx;  /* server ctx */
+    /* "listen", array of ngx_http_listen_t */
+    ngx_array_t           listen;
 
-    size_t       connection_pool_size;
-    size_t       request_pool_size;
-    size_t       client_header_buffer_size;
+    /* "server_name", array of ngx_http_server_name_t */
+    ngx_array_t           server_names;
 
-    ngx_msec_t   post_accept_timeout;
-    ngx_msec_t   client_header_timeout;
+    /* server ctx */
+    ngx_http_conf_ctx_t  *ctx;
 
-    ngx_uint_t   restrict_host_names;
+    size_t                connection_pool_size;
+    size_t                request_pool_size;
+    size_t                client_header_buffer_size;
 
-    ngx_flag_t   large_client_header;
+    ngx_msec_t            post_accept_timeout;
+    ngx_msec_t            client_header_timeout;
+
+    ngx_uint_t            restrict_host_names;
+
+    ngx_flag_t            large_client_header;
 } ngx_http_core_srv_conf_t;
 
 
diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c
index f565d2f..738f1eb 100644
--- a/src/http/ngx_http_header_filter.c
+++ b/src/http/ngx_http_header_filter.c
@@ -33,9 +33,6 @@
 };
 
 
-static ngx_http_output_body_filter_pt    write_filter;
-
-
 static char server_string[] = "Server: " NGINX_VER CRLF;
 
 
@@ -358,7 +355,7 @@
     ln->buf = b;
     ln->next = NULL;
 
-    return write_filter(r, ln);
+    return ngx_http_write_filter(r, ln);
 }
 
 
@@ -366,7 +363,5 @@
 {
     ngx_http_top_header_filter = ngx_http_header_filter;
 
-    write_filter = ngx_http_top_body_filter;
-
     return NGX_OK;
 }
diff --git a/src/http/ngx_http_log_handler.c b/src/http/ngx_http_log_handler.c
index 727cceb..4f63d01 100644
--- a/src/http/ngx_http_log_handler.c
+++ b/src/http/ngx_http_log_handler.c
@@ -656,7 +656,7 @@
                 return NGX_CONF_ERROR;
             }
 
-            lmcf = ngx_http_conf_module_main_conf(cf, ngx_http_log_module);
+            lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module);
             fmt = lmcf->formats.elts;
             /* the default "combined" format */
             log->ops = fmt[0].ops;
@@ -686,7 +686,7 @@
     }
 
     value = cf->args->elts;
-    lmcf = ngx_http_conf_module_main_conf(cf, ngx_http_log_module);
+    lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module);
 
     if (!(log = ngx_push_array(llcf->logs))) {
         return NGX_CONF_ERROR;
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index d0c92ed..49e8094 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -141,6 +141,9 @@
     ngx_http_server_name_t    *server_name;
     ngx_http_core_srv_conf_t  *cscf;
     ngx_http_core_loc_conf_t  *clcf;
+#if (NGX_HTTP_SSL)
+    ngx_http_ssl_srv_conf_t   *sscf;
+#endif
 
     c = rev->data;
 
@@ -229,9 +232,18 @@
     r->srv_conf = cscf->ctx->srv_conf;
     r->loc_conf = cscf->ctx->loc_conf;
 
-#if 1
-    r->ssl = 1;
-    r->filter_need_in_memory = 1;
+#if (NGX_HTTP_SSL)
+
+    sscf = ngx_http_get_module_srv_conf(r, ngx_http_ssl_filter_module);
+    if (sscf->enable) {
+        if (ngx_ssl_create_session(sscf->ssl_ctx, c) == NGX_ERROR) {
+            ngx_http_close_connection(c);
+            return;
+        }
+
+        r->filter_need_in_memory = 1;
+    }
+
 #endif
 
     server_name = cscf->server_names.elts;
@@ -820,22 +832,13 @@
         return NGX_AGAIN;
     }
 
-/* STUB */
-#if (NGX_OPENSSL)
-    if (r->ssl) {
-        n = ngx_http_ssl_read(r, r->header_in->last,
-                              r->header_in->end - r->header_in->last);
-    } else {
-#endif
-        n = ngx_recv(r->connection, r->header_in->last,
-                     r->header_in->end - r->header_in->last);
-#if (NGX_OPENSSL)
-    }
-#endif
+    cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
+
+    n = cscf->recv(r->connection, r->header_in->last,
+                   r->header_in->end - r->header_in->last);
 
     if (n == NGX_AGAIN) {
         if (!r->header_timeout_set) {
-            cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
             ngx_add_timer(rev, cscf->client_header_timeout);
             r->header_timeout_set = 1;
         }
diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h
index c315add..7abd57f 100644
--- a/src/http/ngx_http_request.h
+++ b/src/http/ngx_http_request.h
@@ -280,7 +280,6 @@
     unsigned             complex_uri:1;
     unsigned             header_timeout_set:1;
 
-    unsigned             ssl:1;
     unsigned             proxy:1;
     unsigned             bypass_cache:1;
     unsigned             no_cache:1;
diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c
index b0a82f5..92b7a85 100644
--- a/src/http/ngx_http_write_filter.c
+++ b/src/http/ngx_http_write_filter.c
@@ -53,12 +53,6 @@
                             sizeof(ngx_http_write_filter_ctx_t), NGX_ERROR);
     }
 
-#if (NGX_OPENSSL)
-    if (r->ssl && in == NULL && ctx->out == NULL) {
-        return ngx_http_ssl_shutdown(r);
-    }
-#endif
-
     size = 0;
     flush = 0;
     last = 0;
@@ -131,7 +125,7 @@
 
 /* STUB */
 #if (NGX_OPENSSL)
-    if (r->ssl) {
+    if (r->connection->ssl) {
         chain = ngx_http_ssl_write(r->connection, ctx->out,
                                    clcf->limit_rate ? clcf->limit_rate:
                                                       OFF_T_MAX_VALUE);