tls_stream.c 875 Bytes
Newer Older
1 2 3 4 5 6 7
/*
 * Copyright (C) the libgit2 contributors. All rights reserved.
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */

8 9
#include "tls_stream.h"

10 11 12 13 14
#include "git2/errors.h"

#include "openssl_stream.h"
#include "stransport_stream.h"

15 16 17 18 19 20 21 22 23
static git_stream_cb tls_ctor;

int git_stream_register_tls(git_stream_cb ctor)
{
	tls_ctor = ctor;

	return 0;
}

24 25
int git_tls_stream_new(git_stream **out, const char *host, const char *port)
{
26 27 28 29

	if (tls_ctor)
		return tls_ctor(out, host, port);

30 31
#ifdef GIT_SECURE_TRANSPORT
	return git_stransport_stream_new(out, host, port);
32
#elif defined(GIT_OPENSSL)
33 34 35 36 37 38 39 40 41 42
	return git_openssl_stream_new(out, host, port);
#else
	GIT_UNUSED(out);
	GIT_UNUSED(host);
	GIT_UNUSED(port);

	giterr_set(GITERR_SSL, "there is no TLS stream available");
	return -1;
#endif
}