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