1 module deimos.git2.transport;
2 
3 import deimos.git2.indexer;
4 import deimos.git2.net;
5 import deimos.git2.util;
6 import deimos.git2.types;
7 
8 extern (C):
9 
10 version (GIT_SSH)
11 {
12     static assert(0, "dlibgit does not support SSH yet.");
13     // import ssh2;
14 }
15 
16 enum git_credtype_t {
17 	GIT_CREDTYPE_USERPASS_PLAINTEXT = (1u << 0),
18 	GIT_CREDTYPE_SSH_KEY = (1u << 1),
19 	GIT_CREDTYPE_SSH_CUSTOM = (1u << 2),
20 	GIT_CREDTYPE_DEFAULT = (1u << 3),
21 }
22 mixin _ExportEnumMembers!git_credtype_t;
23 
24 struct git_cred {
25 	git_credtype_t credtype;
26 	void function(git_cred *cred) free;
27 }
28 
29 struct git_cred_userpass_plaintext {
30 	git_cred parent;
31 	char *username;
32 	char *password;
33 }
34 
35 version (GIT_SSH) {
36 	//typedef LIBSSH2_USERAUTH_PUBLICKEY_SIGN_FUNC((*git_cred_sign_callback));
37     static assert(0, "dlibgit does not support SSH yet.");
38 } else {
39 	alias git_cred_sign_callback = int function(void *, ...);
40 }
41 
42 struct git_cred_ssh_key {
43 	git_cred parent;
44 	char *username;
45 	char *publickey;
46 	char *privatekey;
47 	char *passphrase;
48 }
49 
50 struct git_cred_ssh_custom {
51 	git_cred parent;
52 	char *username;
53 	char *publickey;
54 	size_t publickey_len;
55 	void *sign_callback;
56 	void *sign_data;
57 }
58 
59 alias git_cred_default = git_cred;
60 
61 int git_cred_has_username(git_cred *cred);
62 
63 int git_cred_userpass_plaintext_new(
64 	git_cred **out_,
65 	const(char)* username,
66 	const(char)* password);
67 
68 int git_cred_ssh_key_new(
69 	git_cred **out_,
70 	const(char)* username,
71 	const(char)* publickey,
72 	const(char)* privatekey,
73 	const(char)* passphrase);
74 int git_cred_ssh_custom_new(
75 	git_cred **out_,
76 	const(char)* username,
77 	const(char)* publickey,
78 	size_t publickey_len,
79 	git_cred_sign_callback sign_fn,
80 	void *sign_data);
81 int git_cred_default_new(git_cred **out_);
82 
83 alias git_cred_acquire_cb = int function(
84 	git_cred **cred,
85 	const(char)* url,
86 	const(char)* username_from_url,
87 	uint allowed_types,
88 	void *payload);
89 
90 enum git_transport_flags_t {
91 	GIT_TRANSPORTFLAGS_NONE = 0,
92 	GIT_TRANSPORTFLAGS_NO_CHECK_CERT = 1
93 }
94 mixin _ExportEnumMembers!git_transport_flags_t;
95 
96 alias git_transport_message_cb = int function(const(char)* str, int len, void *data);
97 
98 struct git_transport
99 {
100 	uint version_ = GIT_TRANSPORT_VERSION;
101 	int function(git_transport *transport,
102 		git_transport_message_cb progress_cb,
103 		git_transport_message_cb error_cb,
104 		void *payload) set_callbacks;
105 	int function(git_transport *transport,
106 		const(char)* url,
107 		git_cred_acquire_cb cred_acquire_cb,
108 		void *cred_acquire_payload,
109 		int direction,
110 		int flags) connect;
111 	int function(
112 		const(git_remote_head)*** out_,
113 		size_t *size,
114 		git_transport *transport) ls;
115 	int function(git_transport *transport, git_push *push) push;
116 	int function(git_transport *transport,
117 		git_repository *repo,
118 		const(git_remote_head**) refs_,
119 		size_t count) negotiate_fetch;
120 	int function(git_transport *transport,
121 		git_repository *repo,
122 		git_transfer_progress *stats,
123 		git_transfer_progress_callback progress_cb,
124 		void *progress_payload) download_pack;
125 	int function(git_transport *transport) is_connected;
126 	int function(git_transport *transport, int *flags) read_flags;
127 	void function(git_transport *transport) cancel;
128 	int function(git_transport *transport) close;
129 	void function(git_transport *transport) free;
130 }
131 
132 enum GIT_TRANSPORT_VERSION = 1;
133 enum git_transport GIT_TRANSPORT_INIT = { GIT_TRANSPORT_VERSION };
134 
135 int git_transport_new(git_transport **out_, git_remote *owner, const(char)* url);
136 
137 alias git_transport_cb = int function(git_transport **out_, git_remote *owner, void *param);
138 
139 int git_transport_register(
140 	const(char) *prefix,
141 	uint priority,
142 	git_transport_cb cb,
143 	void *param);
144 int git_transport_unregister(
145 	const(char) *prefix,
146 	uint priority);
147 int git_transport_dummy(
148 	git_transport **out_,
149 	git_remote *owner,
150 	/* NULL */ void *payload);
151 int git_transport_local(
152 	git_transport **out_,
153 	git_remote *owner,
154 	/* NULL */ void *payload);
155 int git_transport_smart(
156 	git_transport **out_,
157 	git_remote *owner,
158 	/* (git_smart_subtransport_definition *) */ void *payload);
159 enum git_smart_service_t {
160 	GIT_SERVICE_UPLOADPACK_LS = 1,
161 	GIT_SERVICE_UPLOADPACK = 2,
162 	GIT_SERVICE_RECEIVEPACK_LS = 3,
163 	GIT_SERVICE_RECEIVEPACK = 4,
164 }
165 mixin _ExportEnumMembers!git_smart_service_t;
166 
167 struct git_smart_subtransport_stream {
168 	git_smart_subtransport *subtransport;
169 	int function(
170 		git_smart_subtransport_stream *stream,
171 		char *buffer,
172 		size_t buf_size,
173 		size_t *bytes_read) read;
174 	int function(
175 		git_smart_subtransport_stream *stream,
176 		const(char)* buffer,
177 		size_t len) write;
178 	void function(
179 		git_smart_subtransport_stream *stream) free;
180 }
181 
182 struct git_smart_subtransport {
183 	int function(
184 			git_smart_subtransport_stream **out_,
185 			git_smart_subtransport *transport,
186 			const(char)* url,
187 			git_smart_service_t action) action;
188 	int function(git_smart_subtransport *transport) close;
189 	void function(git_smart_subtransport *transport) free;
190 }
191 
192 alias git_smart_subtransport_cb = int function(
193 	git_smart_subtransport **out_,
194 	git_transport* owner);
195 
196 struct git_smart_subtransport_definition {
197 	git_smart_subtransport_cb callback;
198 	uint rpc;
199 }
200 
201 int git_smart_subtransport_http(
202 	git_smart_subtransport **out_,
203 	git_transport* owner);
204 int git_smart_subtransport_git(
205 	git_smart_subtransport **out_,
206 	git_transport* owner);
207 int git_smart_subtransport_ssh(
208 	git_smart_subtransport **out_,
209 	git_transport* owner);