2 * Copyright (C) the libgit2 contributors. All rights reserved.
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
8 #include "git2/errors.h"
11 #include "streams/registry.h"
12 #include "streams/tls.h"
13 #include "streams/mbedtls.h"
14 #include "streams/openssl.h"
15 #include "streams/stransport.h"
17 int git_tls_stream_new(git_stream
**out
, const char *host
, const char *port
)
19 int (*init
)(git_stream
**, const char *, const char *) = NULL
;
20 git_stream_registration custom
= {0};
27 if ((error
= git_stream_registry_lookup(&custom
, GIT_STREAM_TLS
)) == 0) {
29 } else if (error
== GIT_ENOTFOUND
) {
30 #ifdef GIT_SECURE_TRANSPORT
31 init
= git_stransport_stream_new
;
32 #elif defined(GIT_OPENSSL)
33 init
= git_openssl_stream_new
;
34 #elif defined(GIT_MBEDTLS)
35 init
= git_mbedtls_stream_new
;
42 git_error_set(GIT_ERROR_SSL
, "there is no TLS stream available");
46 return init(out
, host
, port
);
49 int git_tls_stream_wrap(git_stream
**out
, git_stream
*in
, const char *host
)
51 int (*wrap
)(git_stream
**, git_stream
*, const char *) = NULL
;
52 git_stream_registration custom
= {0};
57 if (git_stream_registry_lookup(&custom
, GIT_STREAM_TLS
) == 0) {
60 #ifdef GIT_SECURE_TRANSPORT
61 wrap
= git_stransport_stream_wrap
;
62 #elif defined(GIT_OPENSSL)
63 wrap
= git_openssl_stream_wrap
;
64 #elif defined(GIT_MBEDTLS)
65 wrap
= git_mbedtls_stream_wrap
;
70 git_error_set(GIT_ERROR_SSL
, "there is no TLS stream available");
74 return wrap(out
, in
, host
);