transports: make use of the `GIT_CONTAINER_OF` macro
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
diff --git a/src/transports/http.c b/src/transports/http.c
index 80ba5ba..9d77e62 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -1144,7 +1144,7 @@ static int http_stream_write_chunked(
const char *buffer,
size_t len)
{
- http_stream *s = (http_stream *)stream;
+ http_stream *s = GIT_CONTAINER_OF(stream, http_stream, parent);
http_subtransport *t = OWNING_SUBTRANSPORT(s);
assert(t->connected);
@@ -1218,7 +1218,7 @@ static int http_stream_write_single(
const char *buffer,
size_t len)
{
- http_stream *s = (http_stream *)stream;
+ http_stream *s = GIT_CONTAINER_OF(stream, http_stream, parent);
http_subtransport *t = OWNING_SUBTRANSPORT(s);
git_buf request = GIT_BUF_INIT;
@@ -1252,7 +1252,7 @@ on_error:
static void http_stream_free(git_smart_subtransport_stream *stream)
{
- http_stream *s = (http_stream *)stream;
+ http_stream *s = GIT_CONTAINER_OF(stream, http_stream, parent);
if (s->chunk_buffer)
git__free(s->chunk_buffer);
@@ -1365,7 +1365,7 @@ static int http_action(
const char *url,
git_smart_service_t action)
{
- http_subtransport *t = (http_subtransport *)subtransport;
+ http_subtransport *t = GIT_CONTAINER_OF(subtransport, http_subtransport, parent);
int ret;
assert(stream);
@@ -1419,7 +1419,7 @@ static void free_auth_contexts(git_vector *contexts)
static int http_close(git_smart_subtransport *subtransport)
{
- http_subtransport *t = (http_subtransport *) subtransport;
+ http_subtransport *t = GIT_CONTAINER_OF(subtransport, http_subtransport, parent);
clear_parser_state(t);
@@ -1459,7 +1459,7 @@ static int http_close(git_smart_subtransport *subtransport)
static void http_free(git_smart_subtransport *subtransport)
{
- http_subtransport *t = (http_subtransport *) subtransport;
+ http_subtransport *t = GIT_CONTAINER_OF(subtransport, http_subtransport, parent);
http_close(subtransport);
diff --git a/src/transports/smart.c b/src/transports/smart.c
index fd7113c..7f66ae0 100644
--- a/src/transports/smart.c
+++ b/src/transports/smart.c
@@ -63,7 +63,7 @@ static int git_smart__set_callbacks(
git_transport_certificate_check_cb certificate_check_cb,
void *message_cb_payload)
{
- transport_smart *t = (transport_smart *)transport;
+ transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
t->progress_cb = progress_cb;
t->error_cb = error_cb;
@@ -128,7 +128,7 @@ static int git_smart__set_custom_headers(
git_transport *transport,
const git_strarray *custom_headers)
{
- transport_smart *t = (transport_smart *)transport;
+ transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
size_t i;
if (t->custom_headers.count)
@@ -212,7 +212,7 @@ static int git_smart__connect(
int direction,
int flags)
{
- transport_smart *t = (transport_smart *)transport;
+ transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
git_smart_subtransport_stream *stream;
int error;
git_pkt *pkt;
@@ -315,7 +315,7 @@ cleanup:
static int git_smart__ls(const git_remote_head ***out, size_t *size, git_transport *transport)
{
- transport_smart *t = (transport_smart *)transport;
+ transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
if (!t->have_refs) {
git_error_set(GIT_ERROR_NET, "the transport has not yet loaded the refs");
@@ -330,7 +330,7 @@ static int git_smart__ls(const git_remote_head ***out, size_t *size, git_transpo
int git_smart__negotiation_step(git_transport *transport, void *data, size_t len)
{
- transport_smart *t = (transport_smart *)transport;
+ transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
git_smart_subtransport_stream *stream;
int error;
@@ -387,21 +387,21 @@ int git_smart__get_push_stream(transport_smart *t, git_smart_subtransport_stream
static void git_smart__cancel(git_transport *transport)
{
- transport_smart *t = (transport_smart *)transport;
+ transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
git_atomic_set(&t->cancelled, 1);
}
static int git_smart__is_connected(git_transport *transport)
{
- transport_smart *t = (transport_smart *)transport;
+ transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
return t->connected;
}
static int git_smart__read_flags(git_transport *transport, int *flags)
{
- transport_smart *t = (transport_smart *)transport;
+ transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
*flags = t->flags;
@@ -410,7 +410,7 @@ static int git_smart__read_flags(git_transport *transport, int *flags)
static int git_smart__close(git_transport *transport)
{
- transport_smart *t = (transport_smart *)transport;
+ transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
git_vector *common = &t->common;
unsigned int i;
git_pkt *p;
@@ -447,7 +447,7 @@ static int git_smart__close(git_transport *transport)
static void git_smart__free(git_transport *transport)
{
- transport_smart *t = (transport_smart *)transport;
+ transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
git_vector *refs = &t->refs;
unsigned int i;
git_pkt *p;
@@ -479,7 +479,7 @@ static int ref_name_cmp(const void *a, const void *b)
int git_transport_smart_certificate_check(git_transport *transport, git_cert *cert, int valid, const char *hostname)
{
- transport_smart *t = (transport_smart *)transport;
+ transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
assert(transport && cert && hostname);
@@ -491,7 +491,7 @@ int git_transport_smart_certificate_check(git_transport *transport, git_cert *ce
int git_transport_smart_credentials(git_cred **out, git_transport *transport, const char *user, int methods)
{
- transport_smart *t = (transport_smart *)transport;
+ transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
assert(out && transport);
@@ -503,7 +503,7 @@ int git_transport_smart_credentials(git_cred **out, git_transport *transport, co
int git_transport_smart_proxy_options(git_proxy_options *out, git_transport *transport)
{
- transport_smart *t = (transport_smart *) transport;
+ transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
return git_proxy_options_dup(out, &t->proxy);
}
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index 5a6058f..9b5d8a5 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -132,7 +132,7 @@ static int ssh_stream_read(
size_t *bytes_read)
{
int rc;
- ssh_stream *s = (ssh_stream *)stream;
+ ssh_stream *s = GIT_CONTAINER_OF(stream, ssh_stream, parent);
*bytes_read = 0;
@@ -170,7 +170,7 @@ static int ssh_stream_write(
const char *buffer,
size_t len)
{
- ssh_stream *s = (ssh_stream *)stream;
+ ssh_stream *s = GIT_CONTAINER_OF(stream, ssh_stream, parent);
size_t off = 0;
ssize_t ret = 0;
@@ -196,7 +196,7 @@ static int ssh_stream_write(
static void ssh_stream_free(git_smart_subtransport_stream *stream)
{
- ssh_stream *s = (ssh_stream *)stream;
+ ssh_stream *s = GIT_CONTAINER_OF(stream, ssh_stream, parent);
ssh_subtransport *t;
if (!stream)
@@ -479,7 +479,7 @@ static int _git_ssh_session_create(
{
int rc = 0;
LIBSSH2_SESSION* s;
- git_socket_stream *socket = (git_socket_stream *) io;
+ git_socket_stream *socket = GIT_CONTAINER_OF(io, git_socket_stream, parent);
assert(session);
@@ -730,7 +730,7 @@ static int _ssh_action(
const char *url,
git_smart_service_t action)
{
- ssh_subtransport *t = (ssh_subtransport *) subtransport;
+ ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent);
switch (action) {
case GIT_SERVICE_UPLOADPACK_LS:
@@ -752,7 +752,7 @@ static int _ssh_action(
static int _ssh_close(git_smart_subtransport *subtransport)
{
- ssh_subtransport *t = (ssh_subtransport *) subtransport;
+ ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent);
assert(!t->current_stream);
@@ -763,7 +763,7 @@ static int _ssh_close(git_smart_subtransport *subtransport)
static void _ssh_free(git_smart_subtransport *subtransport)
{
- ssh_subtransport *t = (ssh_subtransport *) subtransport;
+ ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent);
assert(!t->current_stream);