summaryrefslogtreecommitdiff
path: root/src/libgit2/stream.h
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-11-14 08:47:40 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2022-02-22 22:07:44 -0500
commitef4ab2988320005cbcb3db920e6b41f10b3c60cf (patch)
tree6609f213ad9d607e8df1f543919d3154c056c3ef /src/libgit2/stream.h
parent49e180c862dc7c6d1f62a53bf8756e25b3417968 (diff)
downloadlibgit2-ef4ab2988320005cbcb3db920e6b41f10b3c60cf.tar.gz
refactor: `src` is now `src/libgit2`
Diffstat (limited to 'src/libgit2/stream.h')
-rw-r--r--src/libgit2/stream.h86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/libgit2/stream.h b/src/libgit2/stream.h
new file mode 100644
index 000000000..f16b026fb
--- /dev/null
+++ b/src/libgit2/stream.h
@@ -0,0 +1,86 @@
+/*
+ * 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.
+ */
+#ifndef INCLUDE_stream_h__
+#define INCLUDE_stream_h__
+
+#include "common.h"
+#include "git2/sys/stream.h"
+
+GIT_INLINE(int) git_stream_connect(git_stream *st)
+{
+ return st->connect(st);
+}
+
+GIT_INLINE(int) git_stream_is_encrypted(git_stream *st)
+{
+ return st->encrypted;
+}
+
+GIT_INLINE(int) git_stream_certificate(git_cert **out, git_stream *st)
+{
+ if (!st->encrypted) {
+ git_error_set(GIT_ERROR_INVALID, "an unencrypted stream does not have a certificate");
+ return -1;
+ }
+
+ return st->certificate(out, st);
+}
+
+GIT_INLINE(int) git_stream_supports_proxy(git_stream *st)
+{
+ return st->proxy_support;
+}
+
+GIT_INLINE(int) git_stream_set_proxy(git_stream *st, const git_proxy_options *proxy_opts)
+{
+ if (!st->proxy_support) {
+ git_error_set(GIT_ERROR_INVALID, "proxy not supported on this stream");
+ return -1;
+ }
+
+ return st->set_proxy(st, proxy_opts);
+}
+
+GIT_INLINE(ssize_t) git_stream_read(git_stream *st, void *data, size_t len)
+{
+ return st->read(st, data, len);
+}
+
+GIT_INLINE(ssize_t) git_stream_write(git_stream *st, const char *data, size_t len, int flags)
+{
+ return st->write(st, data, len, flags);
+}
+
+GIT_INLINE(int) git_stream__write_full(git_stream *st, const char *data, size_t len, int flags)
+{
+ size_t total_written = 0;
+
+ while (total_written < len) {
+ ssize_t written = git_stream_write(st, data + total_written, len - total_written, flags);
+ if (written <= 0)
+ return -1;
+
+ total_written += written;
+ }
+
+ return 0;
+}
+
+GIT_INLINE(int) git_stream_close(git_stream *st)
+{
+ return st->close(st);
+}
+
+GIT_INLINE(void) git_stream_free(git_stream *st)
+{
+ if (!st)
+ return;
+
+ st->free(st);
+}
+
+#endif