Пример #1
0
static void dill_tls_init(void) {
    static int init = 0;
    if(dill_slow(!init)) {
        SSL_library_init();
        SSL_load_error_strings();
        /* Create our own custom BIO type. */
        int idx = BIO_get_new_index();
        dill_tls_cbio = BIO_meth_new(idx, "bsock");
        dill_assert(dill_tls_cbio);
        int rc = BIO_meth_set_create(dill_tls_cbio, dill_tls_cbio_create);
        dill_assert(rc == 1);
        rc = BIO_meth_set_destroy(dill_tls_cbio, dill_tls_cbio_destroy);
        dill_assert(rc == 1);
        rc = BIO_meth_set_write(dill_tls_cbio, dill_tls_cbio_write);
        dill_assert(rc == 1);
        rc = BIO_meth_set_read(dill_tls_cbio, dill_tls_cbio_read);
        dill_assert(rc == 1);
        rc = BIO_meth_set_ctrl(dill_tls_cbio, dill_tls_cbio_ctrl);
        dill_assert(rc == 1);
        /* Deallocate the method once the process exits. */
        rc = atexit(dill_tls_term);
        dill_assert(rc == 0);
        init = 1;
    }
}
Пример #2
0
static int init_bio_method(void)
{
	/* Set up the BIO_METHOD we use for wrapping our own stream implementations */
	git_stream_bio_method = BIO_meth_new(BIO_TYPE_SOURCE_SINK | BIO_get_new_index(), "git_stream");
	GITERR_CHECK_ALLOC(git_stream_bio_method);

	BIO_meth_set_write(git_stream_bio_method, bio_write);
	BIO_meth_set_read(git_stream_bio_method, bio_read);
	BIO_meth_set_puts(git_stream_bio_method, bio_puts);
	BIO_meth_set_gets(git_stream_bio_method, bio_gets);
	BIO_meth_set_ctrl(git_stream_bio_method, bio_ctrl);
	BIO_meth_set_create(git_stream_bio_method, bio_create);
	BIO_meth_set_destroy(git_stream_bio_method, bio_destroy);

	return 0;
}
Пример #3
0
static BIO_METHOD *
my_BIO_s_socket(void)
{
	if (!my_bio_methods)
	{
		BIO_METHOD *biom = (BIO_METHOD *) BIO_s_socket();
#ifdef HAVE_BIO_METH_NEW
		int			my_bio_index;

		my_bio_index = BIO_get_new_index();
		if (my_bio_index == -1)
			return NULL;
		my_bio_methods = BIO_meth_new(my_bio_index, "PostgreSQL backend socket");
		if (!my_bio_methods)
			return NULL;
		if (!BIO_meth_set_write(my_bio_methods, my_sock_write) ||
			!BIO_meth_set_read(my_bio_methods, my_sock_read) ||
			!BIO_meth_set_gets(my_bio_methods, BIO_meth_get_gets(biom)) ||
			!BIO_meth_set_puts(my_bio_methods, BIO_meth_get_puts(biom)) ||
			!BIO_meth_set_ctrl(my_bio_methods, BIO_meth_get_ctrl(biom)) ||
			!BIO_meth_set_create(my_bio_methods, BIO_meth_get_create(biom)) ||
			!BIO_meth_set_destroy(my_bio_methods, BIO_meth_get_destroy(biom)) ||
			!BIO_meth_set_callback_ctrl(my_bio_methods, BIO_meth_get_callback_ctrl(biom)))
		{
			BIO_meth_free(my_bio_methods);
			my_bio_methods = NULL;
			return NULL;
		}
#else
		my_bio_methods = malloc(sizeof(BIO_METHOD));
		if (!my_bio_methods)
			return NULL;
		memcpy(my_bio_methods, biom, sizeof(BIO_METHOD));
		my_bio_methods->bread = my_sock_read;
		my_bio_methods->bwrite = my_sock_write;
#endif
	}
	return my_bio_methods;
}