Blame src/openssl_stream.h

Packit Service 20376f
/*
Packit Service 20376f
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit Service 20376f
 *
Packit Service 20376f
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit Service 20376f
 * a Linking Exception. For full terms see the included COPYING file.
Packit Service 20376f
 */
Packit Service 20376f
#ifndef INCLUDE_openssl_stream_h__
Packit Service 20376f
#define INCLUDE_openssl_stream_h__
Packit Service 20376f
Packit Service 20376f
#include "git2/sys/stream.h"
Packit Service 20376f
Packit Service 20376f
extern int git_openssl_stream_global_init(void);
Packit Service 20376f
Packit Service 20376f
extern int git_openssl_stream_new(git_stream **out, const char *host, const char *port);
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * OpenSSL 1.1 made BIO opaque so we have to use functions to interact with it
Packit Service 20376f
 * which do not exist in previous versions. We define these inline functions so
Packit Service 20376f
 * we can program against the interface instead of littering the implementation
Packit Service 20376f
 * with ifdefs.
Packit Service 20376f
 */
Packit Service 20376f
#ifdef GIT_OPENSSL
Packit Service 20376f
# include <openssl/ssl.h>
Packit Service 20376f
# include <openssl/err.h>
Packit Service 20376f
# include <openssl/x509v3.h>
Packit Service 20376f
# include <openssl/bio.h>
Packit Service 20376f
Packit Service 20376f
Packit Service 20376f
Packit Service 20376f
# if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(BIO_METHOD*) BIO_meth_new(int type, const char *name)
Packit Service 20376f
{
Packit Service 20376f
	BIO_METHOD *meth = git__calloc(1, sizeof(BIO_METHOD));
Packit Service 20376f
	if (!meth) {
Packit Service 20376f
		return NULL;
Packit Service 20376f
	}
Packit Service 20376f
Packit Service 20376f
	meth->type = type;
Packit Service 20376f
	meth->name = name;
Packit Service 20376f
Packit Service 20376f
	return meth;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(void) BIO_meth_free(BIO_METHOD *biom)
Packit Service 20376f
{
Packit Service 20376f
	git__free(biom);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(int) BIO_meth_set_write(BIO_METHOD *biom, int (*write) (BIO *, const char *, int))
Packit Service 20376f
{
Packit Service 20376f
	biom->bwrite = write;
Packit Service 20376f
	return 1;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(int) BIO_meth_set_read(BIO_METHOD *biom, int (*read) (BIO *, char *, int))
Packit Service 20376f
{
Packit Service 20376f
	biom->bread = read;
Packit Service 20376f
	return 1;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(int) BIO_meth_set_puts(BIO_METHOD *biom, int (*puts) (BIO *, const char *))
Packit Service 20376f
{
Packit Service 20376f
	biom->bputs = puts;
Packit Service 20376f
	return 1;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(int) BIO_meth_set_gets(BIO_METHOD *biom, int (*gets) (BIO *, char *, int))
Packit Service 20376f
Packit Service 20376f
{
Packit Service 20376f
	biom->bgets = gets;
Packit Service 20376f
	return 1;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(int) BIO_meth_set_ctrl(BIO_METHOD *biom, long (*ctrl) (BIO *, int, long, void *))
Packit Service 20376f
{
Packit Service 20376f
	biom->ctrl = ctrl;
Packit Service 20376f
	return 1;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(int) BIO_meth_set_create(BIO_METHOD *biom, int (*create) (BIO *))
Packit Service 20376f
{
Packit Service 20376f
	biom->create = create;
Packit Service 20376f
	return 1;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(int) BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *))
Packit Service 20376f
{
Packit Service 20376f
	biom->destroy = destroy;
Packit Service 20376f
	return 1;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(int) BIO_get_new_index(void)
Packit Service 20376f
{
Packit Service 20376f
	/* This exists as of 1.1 so before we'd just have 0 */
Packit Service 20376f
	return 0;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(void) BIO_set_init(BIO *b, int init)
Packit Service 20376f
{
Packit Service 20376f
	b->init = init;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(void) BIO_set_data(BIO *a, void *ptr)
Packit Service 20376f
{
Packit Service 20376f
	a->ptr = ptr;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(void*) BIO_get_data(BIO *a)
Packit Service 20376f
{
Packit Service 20376f
	return a->ptr;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(const unsigned char *) ASN1_STRING_get0_data(const ASN1_STRING *x)
Packit Service 20376f
{
Packit Service 20376f
	return ASN1_STRING_data((ASN1_STRING *)x);
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
# endif // OpenSSL < 1.1
Packit Service 20376f
#endif // GIT_OPENSSL
Packit Service 20376f
Packit Service 20376f
#endif