1 /*
2  * Copyright (C) the libgit2 contributors. All rights reserved.
3  *
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.
6  */
7 /**
8  * License: GPL-2.0(Linking Exception)
9  */
10 module libgit2.sys.stream;
11 
12 
13 private static import core.sys.posix.sys.types;
14 private static import libgit2.proxy;
15 private static import libgit2.types;
16 private import libgit2.common: GIT_EXTERN;
17 
18 extern (C):
19 nothrow @nogc:
20 
21 enum GIT_STREAM_VERSION = 1;
22 
23 version (Posix):
24 
25 //ToDo: ssize_t
26 
27 /**
28  * Every stream must have this struct as its first element, so the
29  * API can talk to it. You'd define your stream as
30  *
31  *     struct my_stream {
32  *             .git_stream parent;
33  *             ...
34  *     }
35  *
36  * and fill the functions
37  */
38 struct git_stream
39 {
40 	int version_;
41 
42 	int encrypted;
43 	int proxy_support;
44 	int function(.git_stream*) connect;
45 	int function(libgit2.types.git_cert**,  .git_stream*) certificate;
46 	int function(.git_stream*, const (libgit2.proxy.git_proxy_options)* proxy_opts) set_proxy;
47 	core.sys.posix.sys.types.ssize_t function(.git_stream*, void*, size_t) read;
48 	core.sys.posix.sys.types.ssize_t function(.git_stream*, const (char)*, size_t, int) write;
49 	int function(.git_stream*) close;
50 	void function(.git_stream*) free;
51 }
52 
53 struct git_stream_registration
54 {
55 	/**
56 	 * The `version` field should be set to `GIT_STREAM_VERSION`.
57 	 */
58 	int version_;
59 
60 	/**
61 	 * Called to create a new connection to a given host.
62 	 *
63 	 * Params:
64 	 *      out_ = The created stream
65 	 *      host = The hostname to connect to; may be a hostname or IP address
66 	 *      port = The port to connect to; may be a port number or service name
67 	 *
68 	 * Returns: 0 or an error code
69 	 */
70 	int function(.git_stream** out_, const (char)* host, const (char)* port) init;
71 
72 	/**
73 	 * Called to create a new connection on top of the given stream.  If
74 	 * this is a TLS stream, then this function may be used to proxy a
75 	 * TLS stream over an HTTP CONNECT session.  If this is unset, then
76 	 * HTTP CONNECT proxies will not be supported.
77 	 *
78 	 * Params:
79 	 *      out_ = The created stream
80 	 *      in_ = An existing stream to add TLS to
81 	 *      host = The hostname that the stream is connected to, for certificate validation
82 	 *
83 	 * Returns: 0 or an error code
84 	 */
85 	int function(.git_stream** out_, .git_stream* in_, const (char)* host) wrap;
86 }
87 
88 /**
89  * The type of stream to register.
90  */
91 enum git_stream_t
92 {
93 	/**
94 	 * A standard (non-TLS) socket.
95 	 */
96 	GIT_STREAM_STANDARD = 1,
97 
98 	/**
99 	 * A TLS-encrypted socket.
100 	 */
101 	GIT_STREAM_TLS = 2,
102 }
103 
104 //Declaration name in C language
105 enum
106 {
107 	GIT_STREAM_STANDARD = .git_stream_t.GIT_STREAM_STANDARD,
108 	GIT_STREAM_TLS = .git_stream_t.GIT_STREAM_TLS,
109 }
110 
111 /**
112  * Register stream constructors for the library to use
113  *
114  * If a registration structure is already set, it will be overwritten.
115  * Pass `null` in order to deregister the current constructor and return
116  * to the system defaults.
117  *
118  * The type parameter may be a bitwise AND of types.
119  *
120  * Params:
121  *      type = the type or types of stream to register
122  *      registration = the registration data
123  *
124  * Returns: 0 or an error code
125  */
126 @GIT_EXTERN
127 int git_stream_register(.git_stream_t type, .git_stream_registration* registration);
128 
129 deprecated:
130 
131 version (GIT_DEPRECATE_HARD) {
132 } else {
133 	/* @name Deprecated TLS Stream Registration Functions
134 	 *
135 	 * These functions are retained for backward compatibility.  The newer
136 	 * versions of these values should be preferred in all new code.
137 	 *
138 	 * There is no plan to remove these backward compatibility values at
139 	 * this time.
140 	 */
141 	/*@{*/
142 
143 	/*
144 	 * @deprecated Provide a git_stream_registration to git_stream_register
145 	 * @see git_stream_registration
146 	 */
147 	alias git_stream_cb = int function(.git_stream** out_, const (char)* host, const (char)* port);
148 
149 	/**
150 	 * Register a TLS stream constructor for the library to use.  This stream
151 	 * will not support HTTP CONNECT proxies.  This internally calls
152 	 * `git_stream_register` and is preserved for backward compatibility.
153 	 *
154 	 * This function is deprecated, but there is no plan to remove this
155 	 * function at this time.
156 	 *
157 	 * @deprecated Provide a git_stream_registration to git_stream_register
158 	 * @see git_stream_register
159 	 */
160 	@GIT_EXTERN
161 	int git_stream_register_tls(.git_stream_cb ctor);
162 }