stream.h 1.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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);
}

18 19 20 21 22
GIT_INLINE(int) git_stream_is_encrypted(git_stream *st)
{
	return st->encrypted;
}

23 24 25 26 27 28 29 30 31 32
GIT_INLINE(int) git_stream_certificate(git_cert **out, git_stream *st)
{
	if (!st->encrypted) {
		giterr_set(GITERR_INVALID, "an unencrypted stream does not have a certificate");
		return -1;
	}

	return st->certificate(out, st);
}

33 34 35 36 37
GIT_INLINE(int) git_stream_supports_proxy(git_stream *st)
{
	return st->proxy_support;
}

38
GIT_INLINE(int) git_stream_set_proxy(git_stream *st, const git_proxy_options *proxy_opts)
39 40 41 42 43 44
{
	if (!st->proxy_support) {
		giterr_set(GITERR_INVALID, "proxy not supported on this stream");
		return -1;
	}

45
	return st->set_proxy(st, proxy_opts);
46 47
}

48 49 50 51 52
GIT_INLINE(ssize_t) git_stream_read(git_stream *st, void *data, size_t len)
{
	return st->read(st, data, len);
}

53
GIT_INLINE(ssize_t) git_stream_write(git_stream *st, const char *data, size_t len, int flags)
54 55 56 57 58 59 60 61 62 63 64
{
	return st->write(st, data, len, flags);
}

GIT_INLINE(int) git_stream_close(git_stream *st)
{
	return st->close(st);
}

GIT_INLINE(void) git_stream_free(git_stream *st)
{
65 66 67
	if (!st)
		return;

68
	st->free(st);
69 70 71
}

#endif