summaryrefslogtreecommitdiff
path: root/src/streams
diff options
context:
space:
mode:
Diffstat (limited to 'src/streams')
-rw-r--r--src/streams/registry.c49
-rw-r--r--src/streams/registry.h2
-rw-r--r--src/streams/socket.c2
-rw-r--r--src/streams/tls.c4
4 files changed, 37 insertions, 20 deletions
diff --git a/src/streams/registry.c b/src/streams/registry.c
index 210e2d024..02fd3491b 100644
--- a/src/streams/registry.c
+++ b/src/streams/registry.c
@@ -36,22 +36,42 @@ int git_stream_registry_global_init(void)
return 0;
}
-int git_stream_registry_lookup(git_stream_registration *out, int tls)
+GIT_INLINE(void) stream_registration_cpy(
+ git_stream_registration *target,
+ git_stream_registration *src)
{
- git_stream_registration *target = tls ?
- &stream_registry.callbacks :
- &stream_registry.tls_callbacks;
+ if (src)
+ memcpy(target, src, sizeof(git_stream_registration));
+ else
+ memset(target, 0, sizeof(git_stream_registration));
+}
+
+int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type)
+{
+ git_stream_registration *target;
int error = GIT_ENOTFOUND;
assert(out);
+ switch(type) {
+ case GIT_STREAM_STANDARD:
+ target = &stream_registry.callbacks;
+ break;
+ case GIT_STREAM_TLS:
+ target = &stream_registry.tls_callbacks;
+ break;
+ default:
+ assert(0);
+ return -1;
+ }
+
if (git_rwlock_rdlock(&stream_registry.lock) < 0) {
giterr_set(GITERR_OS, "failed to lock stream registry");
return -1;
}
if (target->init) {
- memcpy(out, target, sizeof(git_stream_registration));
+ stream_registration_cpy(out, target);
error = 0;
}
@@ -59,12 +79,8 @@ int git_stream_registry_lookup(git_stream_registration *out, int tls)
return error;
}
-int git_stream_register(int tls, git_stream_registration *registration)
+int git_stream_register(git_stream_t type, git_stream_registration *registration)
{
- git_stream_registration *target = tls ?
- &stream_registry.callbacks :
- &stream_registry.tls_callbacks;
-
assert(!registration || registration->init);
GITERR_CHECK_VERSION(registration, GIT_STREAM_VERSION, "stream_registration");
@@ -74,10 +90,11 @@ int git_stream_register(int tls, git_stream_registration *registration)
return -1;
}
- if (registration)
- memcpy(target, registration, sizeof(git_stream_registration));
- else
- memset(target, 0, sizeof(git_stream_registration));
+ if ((type & GIT_STREAM_STANDARD) == GIT_STREAM_STANDARD)
+ stream_registration_cpy(&stream_registry.callbacks, registration);
+
+ if ((type & GIT_STREAM_TLS) == GIT_STREAM_TLS)
+ stream_registration_cpy(&stream_registry.tls_callbacks, registration);
git_rwlock_wrunlock(&stream_registry.lock);
return 0;
@@ -92,8 +109,8 @@ int git_stream_register_tls(git_stream_cb ctor)
registration.init = ctor;
registration.wrap = NULL;
- return git_stream_register(1, &registration);
+ return git_stream_register(GIT_STREAM_TLS, &registration);
} else {
- return git_stream_register(1, NULL);
+ return git_stream_register(GIT_STREAM_TLS, NULL);
}
}
diff --git a/src/streams/registry.h b/src/streams/registry.h
index 92f87a7bc..adc2b8bdf 100644
--- a/src/streams/registry.h
+++ b/src/streams/registry.h
@@ -14,6 +14,6 @@
int git_stream_registry_global_init(void);
/** Lookup a stream registration. */
-extern int git_stream_registry_lookup(git_stream_registration *out, int tls);
+extern int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type);
#endif
diff --git a/src/streams/socket.c b/src/streams/socket.c
index 21f7fea06..732b45940 100644
--- a/src/streams/socket.c
+++ b/src/streams/socket.c
@@ -224,7 +224,7 @@ int git_socket_stream_new(
assert(out && host && port);
- if ((error = git_stream_registry_lookup(&custom, 0)) == 0)
+ if ((error = git_stream_registry_lookup(&custom, GIT_STREAM_STANDARD)) == 0)
init = custom.init;
else if (error == GIT_ENOTFOUND)
init = default_socket_stream_new;
diff --git a/src/streams/tls.c b/src/streams/tls.c
index 0e10697cd..0ea47fb2f 100644
--- a/src/streams/tls.c
+++ b/src/streams/tls.c
@@ -23,7 +23,7 @@ int git_tls_stream_new(git_stream **out, const char *host, const char *port)
assert(out && host && port);
- if ((error = git_stream_registry_lookup(&custom, 1)) == 0) {
+ if ((error = git_stream_registry_lookup(&custom, GIT_STREAM_TLS)) == 0) {
init = custom.init;
} else if (error == GIT_ENOTFOUND) {
#ifdef GIT_SECURE_TRANSPORT
@@ -52,7 +52,7 @@ int git_tls_stream_wrap(git_stream **out, git_stream *in, const char *host)
assert(out && in);
- if (git_stream_registry_lookup(&custom, 1) == 0) {
+ if (git_stream_registry_lookup(&custom, GIT_STREAM_TLS) == 0) {
wrap = custom.wrap;
} else {
#ifdef GIT_SECURE_TRANSPORT