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 //Declaration name in C language
102 enum
103 {
104 	GIT_STREAM_STANDARD = .git_stream_t.GIT_STREAM_STANDARD,
105 	GIT_STREAM_TLS = .git_stream_t.GIT_STREAM_TLS,
106 }
107 
108 /**
109  * Register stream constructors for the library to use
110  *
111  * If a registration structure is already set, it will be overwritten.
112  * Pass `NULL` in order to deregister the current constructor and return
113  * to the system defaults.
114  *
115  * The type parameter may be a bitwise AND of types.
116  *
117  * Params:
118  *      type = the type or types of stream to register
119  *      registration = the registration data
120  *
121  * Returns: 0 or an error code
122  */
123 //GIT_EXTERN
124 int git_stream_register(.git_stream_t type, .git_stream_registration* registration);
125 
126 deprecated:
127 
128 version (GIT_DEPRECATE_HARD) {
129 } else {
130 	/** @name Deprecated TLS Stream Registration Functions
131 	 *
132 	 * These functions are retained for backward compatibility.  The newer
133 	 * versions of these values should be preferred in all new code.
134 	 *
135 	 * There is no plan to remove these backward compatibility values at
136 	 * this time.
137 	 */
138 	/**@{*/
139 
140 	/**
141 	 * @deprecated Provide a git_stream_registration to git_stream_register
142 	 * @see git_stream_registration
143 	 */
144 	alias git_stream_cb = int function(.git_stream** out_, const (char)* host, const (char)* port);
145 
146 	/**
147 	 * Register a TLS stream constructor for the library to use.  This stream
148 	 * will not support HTTP CONNECT proxies.  This internally calls
149 	 * `git_stream_register` and is preserved for backward compatibility.
150 	 *
151 	 * This function is deprecated, but there is no plan to remove this
152 	 * function at this time.
153 	 *
154 	 * @deprecated Provide a git_stream_registration to git_stream_register
155 	 * @see git_stream_register
156 	 */
157 	//GIT_EXTERN
158 	int git_stream_register_tls(.git_stream_cb ctor);
159 }