From 2e1222695cd6c9b6d9a797bd5383e7618c3eea85 Mon Sep 17 00:00:00 2001 From: Paul Querna Date: Mon, 27 Sep 2004 20:00:52 +0000 Subject: rename structures. properly prefix all non-static functions with mod_gnutls_ fix build for GnuTLS 1.0.X. (redefine the changed structure names) --- include/mod_gnutls.h | 38 +++++++++++++++------- src/gnutls_io.c | 10 +++--- src/mod_gnutls.c | 89 +++++++++++++++++++++++++++------------------------- 3 files changed, 79 insertions(+), 58 deletions(-) diff --git a/include/mod_gnutls.h b/include/mod_gnutls.h index 70e641f..b1abd52 100644 --- a/include/mod_gnutls.h +++ b/include/mod_gnutls.h @@ -40,6 +40,21 @@ module AP_MODULE_DECLARE_DATA gnutls_module; #define GNUTLS_ENABLED_TRUE 1 +/** + * GnuTLS changed the names of several structures between 1.0.X and 1.1.X + * This is just a simple hack so we can compile with both versions. + * There is a full list in , But I am just + * doing this for a few types we use. + */ +#ifndef gnutls_certificate_credentials_t +#define gnutls_certificate_credentials_t gnutls_certificate_credentials +#define gnutls_anon_server_credentials_t gnutls_anon_server_credentials +#define gnutls_session_t gnutls_session +#define gnutls_transport_ptr_t gnutls_transport_ptr +#define gnutls_dh_params_t gnutls_dh_params +#define gnutls_rsa_params_t gnutls_rsa_params +#endif + typedef struct { gnutls_certificate_credentials_t certs; @@ -52,19 +67,18 @@ typedef struct int macs[16]; int protocol[16]; int compression[16]; -} gnutls_srvconf_rec; +} mod_gnutls_srvconf_rec; -typedef struct gnutls_handle_t gnutls_handle_t; -struct gnutls_handle_t +typedef struct { - gnutls_srvconf_rec *sc; + mod_gnutls_srvconf_rec *sc; gnutls_session_t session; ap_filter_t *input_filter; apr_bucket_brigade *input_bb; apr_read_type_e input_block; int status; int non_https; -}; +} mod_gnutls_handle_t; /** Functions in gnutls_io.c **/ @@ -79,9 +93,10 @@ struct gnutls_handle_t * @return result status */ apr_status_t mod_gnutls_filter_input(ap_filter_t * f, - apr_bucket_brigade * bb, - ap_input_mode_t mode, - apr_read_type_e block, apr_off_t readbytes); + apr_bucket_brigade * bb, + ap_input_mode_t mode, + apr_read_type_e block, + apr_off_t readbytes); /** * mod_gnutls_filter_output will filter the encrypt @@ -91,7 +106,8 @@ apr_status_t mod_gnutls_filter_input(ap_filter_t * f, * @param bb the bucket brigade, where to store the result to * @return result status */ -apr_status_t mod_gnutls_filter_output(ap_filter_t * f, apr_bucket_brigade * bb); +apr_status_t mod_gnutls_filter_output(ap_filter_t * f, + apr_bucket_brigade * bb); /** @@ -104,7 +120,7 @@ apr_status_t mod_gnutls_filter_output(ap_filter_t * f, apr_bucket_brigade * bb); * @return size length of the data stored in buffer */ ssize_t mod_gnutls_transport_read(gnutls_transport_ptr_t ptr, - void *buffer, size_t len); + void *buffer, size_t len); /** * mod_gnutls_transport_write is called from GnuTLS to @@ -116,7 +132,7 @@ ssize_t mod_gnutls_transport_read(gnutls_transport_ptr_t ptr, * @return size length of the data written */ ssize_t mod_gnutls_transport_write(gnutls_transport_ptr_t ptr, - const void *buffer, size_t len); + const void *buffer, size_t len); #endif /* __mod_gnutls_h_inc */ diff --git a/src/gnutls_io.c b/src/gnutls_io.c index 6b0a15b..1cb14a3 100644 --- a/src/gnutls_io.c +++ b/src/gnutls_io.c @@ -28,9 +28,9 @@ apr_status_t mod_gnutls_filter_input(ap_filter_t * f, apr_read_type_e block, apr_off_t readbytes) { - apr_bucket* b; + apr_bucket *b; apr_status_t status = APR_SUCCESS; - gnutls_handle_t *ctxt = (gnutls_handle_t *) f->ctx; + mod_gnutls_handle_t *ctxt = (mod_gnutls_handle_t *) f->ctx; if (f->c->aborted) { apr_bucket *bucket = apr_bucket_eos_create(f->c->bucket_alloc); @@ -61,7 +61,7 @@ apr_status_t mod_gnutls_filter_output(ap_filter_t * f, int ret, i; const char *buf = 0; apr_size_t bytes = 0; - gnutls_handle_t *ctxt = (gnutls_handle_t *) f->ctx; + mod_gnutls_handle_t *ctxt = (mod_gnutls_handle_t *) f->ctx; apr_status_t status = APR_SUCCESS; apr_read_type_e rblock = APR_NONBLOCK_READ; @@ -256,7 +256,7 @@ static apr_status_t brigade_consume(apr_bucket_brigade * bb, ssize_t mod_gnutls_transport_read(gnutls_transport_ptr_t ptr, void *buffer, size_t len) { - gnutls_handle_t *ctxt = ptr; + mod_gnutls_handle_t *ctxt = ptr; apr_status_t rc; apr_size_t in = len; /* If Len = 0, we don't do anything. */ @@ -295,7 +295,7 @@ ssize_t mod_gnutls_transport_read(gnutls_transport_ptr_t ptr, ssize_t mod_gnutls_transport_write(gnutls_transport_ptr_t ptr, const void *buffer, size_t len) { - gnutls_handle_t *ctxt = ptr; + mod_gnutls_handle_t *ctxt = ptr; // apr_bucket *bucket = apr_bucket_transient_create(in, inl, // outctx->bb-> diff --git a/src/mod_gnutls.c b/src/mod_gnutls.c index 14bf319..c34da5a 100644 --- a/src/mod_gnutls.c +++ b/src/mod_gnutls.c @@ -21,14 +21,14 @@ GCRY_THREAD_OPTION_PTHREAD_IMPL; #endif -static apr_status_t gnutls_cleanup_pre_config(void *data) +static apr_status_t mod_gnutls_cleanup_pre_config(void *data) { gnutls_global_deinit(); return APR_SUCCESS; } -static int gnutls_hook_pre_config(apr_pool_t * pconf, - apr_pool_t * plog, apr_pool_t * ptemp) +static int mod_gnutls_hook_pre_config(apr_pool_t * pconf, + apr_pool_t * plog, apr_pool_t * ptemp) { #if APR_HAS_THREADS @@ -37,7 +37,7 @@ static int gnutls_hook_pre_config(apr_pool_t * pconf, gnutls_global_init(); - apr_pool_cleanup_register(pconf, NULL, gnutls_cleanup_pre_config, + apr_pool_cleanup_register(pconf, NULL, mod_gnutls_cleanup_pre_config, apr_pool_cleanup_null); return OK; @@ -46,11 +46,11 @@ static int gnutls_hook_pre_config(apr_pool_t * pconf, #define DH_BITS 1024 #define RSA_BITS 512 -static int gnutls_hook_post_config(apr_pool_t * p, apr_pool_t * plog, - apr_pool_t * ptemp, - server_rec * base_server) +static int mod_gnutls_hook_post_config(apr_pool_t * p, apr_pool_t * plog, + apr_pool_t * ptemp, + server_rec * base_server) { - gnutls_srvconf_rec *sc; + mod_gnutls_srvconf_rec *sc; server_rec *s; gnutls_dh_params_t dh_params; gnutls_rsa_params_t rsa_params; @@ -63,8 +63,8 @@ static int gnutls_hook_post_config(apr_pool_t * p, apr_pool_t * plog, // gnutls_rsa_params_generate2(rsa_params, RSA_BITS); for (s = base_server; s; s = s->next) { - sc = (gnutls_srvconf_rec *) ap_get_module_config(s->module_config, - &gnutls_module); + sc = (mod_gnutls_srvconf_rec *) ap_get_module_config(s->module_config, + &gnutls_module); if (sc->cert_file != NULL && sc->key_file != NULL) { gnutls_certificate_set_x509_key_file(sc->certs, sc->cert_file, sc->key_file, @@ -84,11 +84,12 @@ static int gnutls_hook_post_config(apr_pool_t * p, apr_pool_t * plog, return OK; } -static const char *gnutls_hook_http_method(const request_rec * r) +static const char *mod_gnutls_hook_http_method(const request_rec * r) { - gnutls_srvconf_rec *sc = - (gnutls_srvconf_rec *) ap_get_module_config(r->server->module_config, - &gnutls_module); + mod_gnutls_srvconf_rec *sc = + (mod_gnutls_srvconf_rec *) ap_get_module_config(r->server-> + module_config, + &gnutls_module); if (sc->enabled == GNUTLS_ENABLED_FALSE) { return NULL; @@ -97,11 +98,12 @@ static const char *gnutls_hook_http_method(const request_rec * r) return "https"; } -static apr_port_t gnutls_hook_default_port(const request_rec * r) +static apr_port_t mod_gnutls_hook_default_port(const request_rec * r) { - gnutls_srvconf_rec *sc = - (gnutls_srvconf_rec *) ap_get_module_config(r->server->module_config, - &gnutls_module); + mod_gnutls_srvconf_rec *sc = + (mod_gnutls_srvconf_rec *) ap_get_module_config(r->server-> + module_config, + &gnutls_module); if (sc->enabled == GNUTLS_ENABLED_FALSE) { return 0; @@ -110,13 +112,13 @@ static apr_port_t gnutls_hook_default_port(const request_rec * r) return 443; } -static int gnutls_hook_pre_connection(conn_rec * c, void *csd) +static int mod_gnutls_hook_pre_connection(conn_rec * c, void *csd) { - gnutls_handle_t *ctxt; - gnutls_srvconf_rec *sc = - (gnutls_srvconf_rec *) ap_get_module_config(c->base_server-> - module_config, - &gnutls_module); + mod_gnutls_handle_t *ctxt; + mod_gnutls_srvconf_rec *sc = + (mod_gnutls_srvconf_rec *) ap_get_module_config(c->base_server-> + module_config, + &gnutls_module); if (!(sc && (sc->enabled == GNUTLS_ENABLED_TRUE))) { return DECLINED; @@ -160,10 +162,10 @@ static int gnutls_hook_pre_connection(conn_rec * c, void *csd) static const char *gnutls_set_cert_file(cmd_parms * parms, void *dummy, const char *arg) { - gnutls_srvconf_rec *sc = - (gnutls_srvconf_rec *) ap_get_module_config(parms->server-> - module_config, - &gnutls_module); + mod_gnutls_srvconf_rec *sc = + (mod_gnutls_srvconf_rec *) ap_get_module_config(parms->server-> + module_config, + &gnutls_module); sc->cert_file = apr_pstrdup(parms->pool, arg); return NULL; } @@ -171,10 +173,10 @@ static const char *gnutls_set_cert_file(cmd_parms * parms, void *dummy, static const char *gnutls_set_key_file(cmd_parms * parms, void *dummy, const char *arg) { - gnutls_srvconf_rec *sc = - (gnutls_srvconf_rec *) ap_get_module_config(parms->server-> - module_config, - &gnutls_module); + mod_gnutls_srvconf_rec *sc = + (mod_gnutls_srvconf_rec *) ap_get_module_config(parms->server-> + module_config, + &gnutls_module); sc->key_file = apr_pstrdup(parms->pool, arg); return NULL; } @@ -182,10 +184,10 @@ static const char *gnutls_set_key_file(cmd_parms * parms, void *dummy, static const char *gnutls_set_enabled(cmd_parms * parms, void *dummy, const char *arg) { - gnutls_srvconf_rec *sc = - (gnutls_srvconf_rec *) ap_get_module_config(parms->server-> - module_config, - &gnutls_module); + mod_gnutls_srvconf_rec *sc = + (mod_gnutls_srvconf_rec *) ap_get_module_config(parms->server-> + module_config, + &gnutls_module); if (!strcasecmp(arg, "On")) { sc->enabled = GNUTLS_ENABLED_TRUE; } @@ -224,13 +226,16 @@ static const command_rec gnutls_cmds[] = { static void gnutls_hooks(apr_pool_t * p) { - ap_hook_pre_connection(gnutls_hook_pre_connection, NULL, NULL, + ap_hook_pre_connection(mod_gnutls_hook_pre_connection, NULL, NULL, APR_HOOK_MIDDLE); - ap_hook_post_config(gnutls_hook_post_config, NULL, NULL, APR_HOOK_MIDDLE); - ap_hook_http_method(gnutls_hook_http_method, NULL, NULL, APR_HOOK_MIDDLE); - ap_hook_default_port(gnutls_hook_default_port, NULL, NULL, + ap_hook_post_config(mod_gnutls_hook_post_config, NULL, NULL, + APR_HOOK_MIDDLE); + ap_hook_http_method(mod_gnutls_hook_http_method, NULL, NULL, + APR_HOOK_MIDDLE); + ap_hook_default_port(mod_gnutls_hook_default_port, NULL, NULL, APR_HOOK_MIDDLE); - ap_hook_pre_config(gnutls_hook_pre_config, NULL, NULL, APR_HOOK_MIDDLE); + ap_hook_pre_config(mod_gnutls_hook_pre_config, NULL, NULL, + APR_HOOK_MIDDLE); /* TODO: HTTP Upgrade Filter */ /* ap_register_output_filter ("UPGRADE_FILTER", @@ -247,7 +252,7 @@ static void gnutls_hooks(apr_pool_t * p) static void *gnutls_config_server_create(apr_pool_t * p, server_rec * s) { int i; - gnutls_srvconf_rec *sc = apr_pcalloc(p, sizeof(*sc)); + mod_gnutls_srvconf_rec *sc = apr_pcalloc(p, sizeof(*sc)); sc->enabled = GNUTLS_ENABLED_FALSE; -- cgit