]>
git.proxmox.com Git - libgit2.git/blob - include/git2/sys/stream.h
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.
7 #ifndef INCLUDE_sys_git_stream_h__
8 #define INCLUDE_sys_git_stream_h__
10 #include "git2/common.h"
11 #include "git2/types.h"
12 #include "git2/proxy.h"
16 #define GIT_STREAM_VERSION 1
19 * Every stream must have this struct as its first element, so the
20 * API can talk to it. You'd define your stream as
27 * and fill the functions
29 typedef struct git_stream
{
34 int GIT_CALLBACK(connect
)(struct git_stream
*);
35 int GIT_CALLBACK(certificate
)(git_cert
**, struct git_stream
*);
36 int GIT_CALLBACK(set_proxy
)(struct git_stream
*, const git_proxy_options
*proxy_opts
);
37 ssize_t
GIT_CALLBACK(read
)(struct git_stream
*, void *, size_t);
38 ssize_t
GIT_CALLBACK(write
)(struct git_stream
*, const char *, size_t, int);
39 int GIT_CALLBACK(close
)(struct git_stream
*);
40 void GIT_CALLBACK(free
)(struct git_stream
*);
44 /** The `version` field should be set to `GIT_STREAM_VERSION`. */
48 * Called to create a new connection to a given host.
50 * @param out The created stream
51 * @param host The hostname to connect to; may be a hostname or
53 * @param port The port to connect to; may be a port number or
55 * @return 0 or an error code
57 int GIT_CALLBACK(init
)(git_stream
**out
, const char *host
, const char *port
);
60 * Called to create a new connection on top of the given stream. If
61 * this is a TLS stream, then this function may be used to proxy a
62 * TLS stream over an HTTP CONNECT session. If this is unset, then
63 * HTTP CONNECT proxies will not be supported.
65 * @param out The created stream
66 * @param in An existing stream to add TLS to
67 * @param host The hostname that the stream is connected to,
68 * for certificate validation
69 * @return 0 or an error code
71 int GIT_CALLBACK(wrap
)(git_stream
**out
, git_stream
*in
, const char *host
);
72 } git_stream_registration
;
75 * The type of stream to register.
78 /** A standard (non-TLS) socket. */
79 GIT_STREAM_STANDARD
= 1,
81 /** A TLS-encrypted socket. */
86 * Register stream constructors for the library to use
88 * If a registration structure is already set, it will be overwritten.
89 * Pass `NULL` in order to deregister the current constructor and return
90 * to the system defaults.
92 * The type parameter may be a bitwise AND of types.
94 * @param type the type or types of stream to register
95 * @param registration the registration data
96 * @return 0 or an error code
98 GIT_EXTERN(int) git_stream_register(
99 git_stream_t type
, git_stream_registration
*registration
);
101 #ifndef GIT_DEPRECATE_HARD
103 /** @name Deprecated TLS Stream Registration Functions
105 * These functions are retained for backward compatibility. The newer
106 * versions of these values should be preferred in all new code.
108 * There is no plan to remove these backward compatibility values at
114 * @deprecated Provide a git_stream_registration to git_stream_register
115 * @see git_stream_registration
117 typedef int GIT_CALLBACK(git_stream_cb
)(git_stream
**out
, const char *host
, const char *port
);
120 * Register a TLS stream constructor for the library to use. This stream
121 * will not support HTTP CONNECT proxies. This internally calls
122 * `git_stream_register` and is preserved for backward compatibility.
124 * This function is deprecated, but there is no plan to remove this
125 * function at this time.
127 * @deprecated Provide a git_stream_registration to git_stream_register
128 * @see git_stream_register
130 GIT_EXTERN(int) git_stream_register_tls(git_stream_cb ctor
);