diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2018-11-18 10:29:07 +0000 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2018-11-28 15:46:57 +0000 |
| commit | df2cc1087f6de8718319e5bcc65ca8e0e07b717e (patch) | |
| tree | 02264b646329a5eeca8940fa8557e714e303a50f /src/streams/socket.c | |
| parent | 0467606ff4dbf57401c8b58188652df821ec865b (diff) | |
| download | libgit2-df2cc1087f6de8718319e5bcc65ca8e0e07b717e.tar.gz | |
stream: provide generic registration API
Update the new stream registration API to be `git_stream_register`
which takes a registration structure and a TLS boolean. This allows
callers to register non-TLS streams as well as TLS streams.
Provide `git_stream_register_tls` that takes just the init callback for
backward compatibliity.
Diffstat (limited to 'src/streams/socket.c')
| -rw-r--r-- | src/streams/socket.c | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/streams/socket.c b/src/streams/socket.c index 0c6073b66..21f7fea06 100644 --- a/src/streams/socket.c +++ b/src/streams/socket.c @@ -9,6 +9,7 @@ #include "posix.h" #include "netops.h" +#include "registry.h" #include "stream.h" #ifndef _WIN32 @@ -180,11 +181,14 @@ void socket_free(git_stream *stream) git__free(st); } -int git_socket_stream_new(git_stream **out, const char *host, const char *port) +static int default_socket_stream_new( + git_stream **out, + const char *host, + const char *port) { git_socket_stream *st; - assert(out && host); + assert(out && host && port); st = git__calloc(1, sizeof(git_socket_stream)); GITERR_CHECK_ALLOC(st); @@ -208,3 +212,29 @@ int git_socket_stream_new(git_stream **out, const char *host, const char *port) *out = (git_stream *) st; return 0; } + +int git_socket_stream_new( + git_stream **out, + const char *host, + const char *port) +{ + int (*init)(git_stream **, const char *, const char *) = NULL; + git_stream_registration custom = {0}; + int error; + + assert(out && host && port); + + if ((error = git_stream_registry_lookup(&custom, 0)) == 0) + init = custom.init; + else if (error == GIT_ENOTFOUND) + init = default_socket_stream_new; + else + return error; + + if (!init) { + giterr_set(GITERR_NET, "there is no socket stream available"); + return -1; + } + + return init(out, host, port); +} |
