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 	 * @param out_ The created stream
61 	 * @param host The hostname to connect to; may be a hostname or
62 	 *             IP address
63 	 * @param port The port to connect to; may be a port number or
64 	 *             service name
65 	 * @return 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 	 * @param out_ The created stream
76 	 * @param in An existing stream to add TLS to
77 	 * @param host The hostname that the stream is connected to,
78 	 *             for certificate validation
79 	 * @return 0 or an error code
80 	 */
81 	int function(.git_stream** out_, .git_stream* in_, const (char)* host) wrap;
82 }
83 
84 /**
85  * The type of stream to register.
86  */
87 enum git_stream_t
88 {
89 	/**
90 	 * A standard (non-TLS) socket.
91 	 */
92 	GIT_STREAM_STANDARD = 1,
93 
94 	/**
95 	 * A TLS-encrypted socket.
96 	 */
97 	GIT_STREAM_TLS = 2,
98 }
99 
100 /**
101  * Register stream constructors for the library to use
102  *
103  * If a registration structure is already set, it will be overwritten.
104  * Pass `NULL` in order to deregister the current constructor and return
105  * to the system defaults.
106  *
107  * The type parameter may be a bitwise AND of types.
108  *
109  * @param type the type or types of stream to register
110  * @param registration the registration data
111  * @return 0 or an error code
112  */
113 //GIT_EXTERN
114 int git_stream_register(.git_stream_t type, .git_stream_registration* registration);
115 
116 deprecated:
117 
118 version (GIT_DEPRECATE_HARD) {
119 } else {
120 	/** @name Deprecated TLS Stream Registration Functions
121 	 *
122 	 * These functions are retained for backward compatibility.  The newer
123 	 * versions of these values should be preferred in all new code.
124 	 *
125 	 * There is no plan to remove these backward compatibility values at
126 	 * this time.
127 	 */
128 	/**@{*/
129 
130 	/**
131 	 * @deprecated Provide a git_stream_registration to git_stream_register
132 	 * @see git_stream_registration
133 	 */
134 	alias git_stream_cb = int function(.git_stream** out_, const (char)* host, const (char)* port);
135 
136 	/**
137 	 * Register a TLS stream constructor for the library to use.  This stream
138 	 * will not support HTTP CONNECT proxies.  This internally calls
139 	 * `git_stream_register` and is preserved for backward compatibility.
140 	 *
141 	 * This function is deprecated, but there is no plan to remove this
142 	 * function at this time.
143 	 *
144 	 * @deprecated Provide a git_stream_registration to git_stream_register
145 	 * @see git_stream_register
146 	 */
147 	//GIT_EXTERN
148 	int git_stream_register_tls(.git_stream_cb ctor);
149 }