Skip to content

Commit b51789a

Browse files
tiennoupks-t
authored andcommitted
transports: make use of the GIT_CONTAINER_OF macro
1 parent 2e24647 commit b51789a

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

src/transports/http.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ static int http_stream_write_chunked(
11441144
const char *buffer,
11451145
size_t len)
11461146
{
1147-
http_stream *s = (http_stream *)stream;
1147+
http_stream *s = GIT_CONTAINER_OF(stream, http_stream, parent);
11481148
http_subtransport *t = OWNING_SUBTRANSPORT(s);
11491149

11501150
assert(t->connected);
@@ -1218,7 +1218,7 @@ static int http_stream_write_single(
12181218
const char *buffer,
12191219
size_t len)
12201220
{
1221-
http_stream *s = (http_stream *)stream;
1221+
http_stream *s = GIT_CONTAINER_OF(stream, http_stream, parent);
12221222
http_subtransport *t = OWNING_SUBTRANSPORT(s);
12231223
git_buf request = GIT_BUF_INIT;
12241224

@@ -1252,7 +1252,7 @@ static int http_stream_write_single(
12521252

12531253
static void http_stream_free(git_smart_subtransport_stream *stream)
12541254
{
1255-
http_stream *s = (http_stream *)stream;
1255+
http_stream *s = GIT_CONTAINER_OF(stream, http_stream, parent);
12561256

12571257
if (s->chunk_buffer)
12581258
git__free(s->chunk_buffer);
@@ -1365,7 +1365,7 @@ static int http_action(
13651365
const char *url,
13661366
git_smart_service_t action)
13671367
{
1368-
http_subtransport *t = (http_subtransport *)subtransport;
1368+
http_subtransport *t = GIT_CONTAINER_OF(subtransport, http_subtransport, parent);
13691369
int ret;
13701370

13711371
assert(stream);
@@ -1419,7 +1419,7 @@ static void free_auth_contexts(git_vector *contexts)
14191419

14201420
static int http_close(git_smart_subtransport *subtransport)
14211421
{
1422-
http_subtransport *t = (http_subtransport *) subtransport;
1422+
http_subtransport *t = GIT_CONTAINER_OF(subtransport, http_subtransport, parent);
14231423

14241424
clear_parser_state(t);
14251425

@@ -1459,7 +1459,7 @@ static int http_close(git_smart_subtransport *subtransport)
14591459

14601460
static void http_free(git_smart_subtransport *subtransport)
14611461
{
1462-
http_subtransport *t = (http_subtransport *) subtransport;
1462+
http_subtransport *t = GIT_CONTAINER_OF(subtransport, http_subtransport, parent);
14631463

14641464
http_close(subtransport);
14651465

src/transports/smart.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static int git_smart__set_callbacks(
6363
git_transport_certificate_check_cb certificate_check_cb,
6464
void *message_cb_payload)
6565
{
66-
transport_smart *t = (transport_smart *)transport;
66+
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
6767

6868
t->progress_cb = progress_cb;
6969
t->error_cb = error_cb;
@@ -128,7 +128,7 @@ static int git_smart__set_custom_headers(
128128
git_transport *transport,
129129
const git_strarray *custom_headers)
130130
{
131-
transport_smart *t = (transport_smart *)transport;
131+
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
132132
size_t i;
133133

134134
if (t->custom_headers.count)
@@ -212,7 +212,7 @@ static int git_smart__connect(
212212
int direction,
213213
int flags)
214214
{
215-
transport_smart *t = (transport_smart *)transport;
215+
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
216216
git_smart_subtransport_stream *stream;
217217
int error;
218218
git_pkt *pkt;
@@ -315,7 +315,7 @@ static int git_smart__connect(
315315

316316
static int git_smart__ls(const git_remote_head ***out, size_t *size, git_transport *transport)
317317
{
318-
transport_smart *t = (transport_smart *)transport;
318+
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
319319

320320
if (!t->have_refs) {
321321
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
330330

331331
int git_smart__negotiation_step(git_transport *transport, void *data, size_t len)
332332
{
333-
transport_smart *t = (transport_smart *)transport;
333+
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
334334
git_smart_subtransport_stream *stream;
335335
int error;
336336

@@ -387,21 +387,21 @@ int git_smart__get_push_stream(transport_smart *t, git_smart_subtransport_stream
387387

388388
static void git_smart__cancel(git_transport *transport)
389389
{
390-
transport_smart *t = (transport_smart *)transport;
390+
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
391391

392392
git_atomic_set(&t->cancelled, 1);
393393
}
394394

395395
static int git_smart__is_connected(git_transport *transport)
396396
{
397-
transport_smart *t = (transport_smart *)transport;
397+
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
398398

399399
return t->connected;
400400
}
401401

402402
static int git_smart__read_flags(git_transport *transport, int *flags)
403403
{
404-
transport_smart *t = (transport_smart *)transport;
404+
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
405405

406406
*flags = t->flags;
407407

@@ -410,7 +410,7 @@ static int git_smart__read_flags(git_transport *transport, int *flags)
410410

411411
static int git_smart__close(git_transport *transport)
412412
{
413-
transport_smart *t = (transport_smart *)transport;
413+
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
414414
git_vector *common = &t->common;
415415
unsigned int i;
416416
git_pkt *p;
@@ -447,7 +447,7 @@ static int git_smart__close(git_transport *transport)
447447

448448
static void git_smart__free(git_transport *transport)
449449
{
450-
transport_smart *t = (transport_smart *)transport;
450+
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
451451
git_vector *refs = &t->refs;
452452
unsigned int i;
453453
git_pkt *p;
@@ -479,7 +479,7 @@ static int ref_name_cmp(const void *a, const void *b)
479479

480480
int git_transport_smart_certificate_check(git_transport *transport, git_cert *cert, int valid, const char *hostname)
481481
{
482-
transport_smart *t = (transport_smart *)transport;
482+
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
483483

484484
assert(transport && cert && hostname);
485485

@@ -491,7 +491,7 @@ int git_transport_smart_certificate_check(git_transport *transport, git_cert *ce
491491

492492
int git_transport_smart_credentials(git_cred **out, git_transport *transport, const char *user, int methods)
493493
{
494-
transport_smart *t = (transport_smart *)transport;
494+
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
495495

496496
assert(out && transport);
497497

@@ -503,7 +503,7 @@ int git_transport_smart_credentials(git_cred **out, git_transport *transport, co
503503

504504
int git_transport_smart_proxy_options(git_proxy_options *out, git_transport *transport)
505505
{
506-
transport_smart *t = (transport_smart *) transport;
506+
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
507507
return git_proxy_options_dup(out, &t->proxy);
508508
}
509509

src/transports/ssh.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static int ssh_stream_read(
132132
size_t *bytes_read)
133133
{
134134
int rc;
135-
ssh_stream *s = (ssh_stream *)stream;
135+
ssh_stream *s = GIT_CONTAINER_OF(stream, ssh_stream, parent);
136136

137137
*bytes_read = 0;
138138

@@ -170,7 +170,7 @@ static int ssh_stream_write(
170170
const char *buffer,
171171
size_t len)
172172
{
173-
ssh_stream *s = (ssh_stream *)stream;
173+
ssh_stream *s = GIT_CONTAINER_OF(stream, ssh_stream, parent);
174174
size_t off = 0;
175175
ssize_t ret = 0;
176176

@@ -196,7 +196,7 @@ static int ssh_stream_write(
196196

197197
static void ssh_stream_free(git_smart_subtransport_stream *stream)
198198
{
199-
ssh_stream *s = (ssh_stream *)stream;
199+
ssh_stream *s = GIT_CONTAINER_OF(stream, ssh_stream, parent);
200200
ssh_subtransport *t;
201201

202202
if (!stream)
@@ -479,7 +479,7 @@ static int _git_ssh_session_create(
479479
{
480480
int rc = 0;
481481
LIBSSH2_SESSION* s;
482-
git_socket_stream *socket = (git_socket_stream *) io;
482+
git_socket_stream *socket = GIT_CONTAINER_OF(io, git_socket_stream, parent);
483483

484484
assert(session);
485485

@@ -730,7 +730,7 @@ static int _ssh_action(
730730
const char *url,
731731
git_smart_service_t action)
732732
{
733-
ssh_subtransport *t = (ssh_subtransport *) subtransport;
733+
ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent);
734734

735735
switch (action) {
736736
case GIT_SERVICE_UPLOADPACK_LS:
@@ -752,7 +752,7 @@ static int _ssh_action(
752752

753753
static int _ssh_close(git_smart_subtransport *subtransport)
754754
{
755-
ssh_subtransport *t = (ssh_subtransport *) subtransport;
755+
ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent);
756756

757757
assert(!t->current_stream);
758758

@@ -763,7 +763,7 @@ static int _ssh_close(git_smart_subtransport *subtransport)
763763

764764
static void _ssh_free(git_smart_subtransport *subtransport)
765765
{
766-
ssh_subtransport *t = (ssh_subtransport *) subtransport;
766+
ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent);
767767

768768
assert(!t->current_stream);
769769

0 commit comments

Comments
 (0)