void h2o_proxy_register_reverse_proxy(h2o_pathconf_t *pathconf, h2o_url_t *upstream, h2o_proxy_config_vars_t *config) { struct sockaddr_un sa; const char *to_sa_err; struct rp_handler_t *self = (void *)h2o_create_handler(pathconf, sizeof(*self)); self->super.on_context_init = on_context_init; self->super.on_context_dispose = on_context_dispose; self->super.dispose = on_handler_dispose; self->super.on_req = on_req; to_sa_err = h2o_url_host_to_sun(upstream->host, &sa); if (config->keepalive_timeout != 0) { self->sockpool = h2o_mem_alloc(sizeof(*self->sockpool)); int is_ssl = upstream->scheme == &H2O_URL_SCHEME_HTTPS; if (to_sa_err == h2o_url_host_to_sun_err_is_not_unix_socket) { h2o_socketpool_init_by_hostport(self->sockpool, upstream->host, h2o_url_get_port(upstream), is_ssl, SIZE_MAX /* FIXME */); } else { assert(to_sa_err == NULL); h2o_socketpool_init_by_address(self->sockpool, (void *)&sa, sizeof(sa), is_ssl, SIZE_MAX /* FIXME */); } } h2o_url_copy(NULL, &self->upstream, upstream); if (to_sa_err) { h2o_strtolower(self->upstream.host.base, self->upstream.host.len); } self->config = *config; if (self->config.ssl_ctx != NULL) SSL_CTX_up_ref(self->config.ssl_ctx); }
void h2o_socketpool_set_ssl_ctx(h2o_socketpool_t *pool, SSL_CTX *ssl_ctx) { if (pool->_ssl_ctx != NULL) SSL_CTX_free(pool->_ssl_ctx); if (ssl_ctx != NULL) SSL_CTX_up_ref(ssl_ctx); pool->_ssl_ctx = ssl_ctx; }
static void tlso_ctx_ref( tls_ctx *ctx ) { tlso_ctx *c = (tlso_ctx *)ctx; #if OPENSSL_VERSION_NUMBER < 0x10100000 #define SSL_CTX_up_ref(ctx) CRYPTO_add( &(ctx->references), 1, CRYPTO_LOCK_SSL_CTX ) #endif SSL_CTX_up_ref( c ); }
int mosquitto_opts_set(struct mosquitto *mosq, enum mosq_opt_t option, void *value) { int ival; if(!mosq || !value) return MOSQ_ERR_INVAL; switch(option){ case MOSQ_OPT_PROTOCOL_VERSION: ival = *((int *)value); if(ival == MQTT_PROTOCOL_V31){ mosq->protocol = mosq_p_mqtt31; }else if(ival == MQTT_PROTOCOL_V311){ mosq->protocol = mosq_p_mqtt311; }else{ return MOSQ_ERR_INVAL; } break; case MOSQ_OPT_SSL_CTX: #ifdef WITH_TLS mosq->ssl_ctx = (SSL_CTX *)value; if(mosq->ssl_ctx){ #if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && !defined(LIBRESSL_VERSION_NUMBER) SSL_CTX_up_ref(mosq->ssl_ctx); #else CRYPTO_add(&(mosq->ssl_ctx)->references, 1, CRYPTO_LOCK_SSL_CTX); #endif } break; #else return MOSQ_ERR_NOT_SUPPORTED; #endif case MOSQ_OPT_SSL_CTX_WITH_DEFAULTS: #if defined(WITH_TLS) && OPENSSL_VERSION_NUMBER >= 0x10100000L mosq->ssl_ctx_defaults = true; break; #else return MOSQ_ERR_NOT_SUPPORTED; #endif default: return MOSQ_ERR_INVAL; } return MOSQ_ERR_SUCCESS; }