static void ssh_stream_free(git_smart_subtransport_stream *stream) { ssh_stream *s = (ssh_stream *)stream; ssh_subtransport *t = OWNING_SUBTRANSPORT(s); int ret; GIT_UNUSED(ret); t->current_stream = NULL; if (s->channel) { libssh2_channel_close(s->channel); libssh2_channel_free(s->channel); s->channel = NULL; } if (s->session) { libssh2_session_free(s->session); s->session = NULL; } if (s->socket.socket) { (void)gitno_close(&s->socket); /* can't do anything here with error return value */ } git__free(s->url); git__free(s); }
static int http_connect(http_subtransport *t) { int flags = 0; if (t->connected && http_should_keep_alive(&t->parser) && http_body_is_final(&t->parser)) return 0; if (t->socket.socket) gitno_close(&t->socket); if (t->connection_data.use_ssl) { int tflags; if (t->owner->parent.read_flags(&t->owner->parent, &tflags) < 0) return -1; flags |= GITNO_CONNECT_SSL; if (GIT_TRANSPORTFLAGS_NO_CHECK_CERT & tflags) flags |= GITNO_CONNECT_SSL_NO_CHECK_CERT; } if (gitno_connect(&t->socket, t->connection_data.host, t->connection_data.port, flags) < 0) return -1; t->connected = 1; return 0; }
/* * Parse the URL and connect to a server, storing the socket in * out. For convenience this also takes care of asking for the remote * refs */ static int do_connect(transport_git *t, const char *url) { char *host, *port; const char prefix[] = "git://"; if (!git__prefixcmp(url, prefix)) url += strlen(prefix); if (gitno_extract_host_and_port(&host, &port, url, GIT_DEFAULT_PORT) < 0) return -1; if (gitno_connect((git_transport *)t, host, port) < 0) goto on_error; if (send_request((git_transport *)t, NULL, url) < 0) goto on_error; git__free(host); git__free(port); return 0; on_error: git__free(host); git__free(port); gitno_close(t->parent.socket); return -1; }
static int http_close(git_smart_subtransport *subtransport) { http_subtransport *t = (http_subtransport *) subtransport; clear_parser_state(t); if (t->socket.socket) { gitno_close(&t->socket); memset(&t->socket, 0x0, sizeof(gitno_socket)); } if (t->cred) { t->cred->free(t->cred); t->cred = NULL; } if (t->url_cred) { t->url_cred->free(t->url_cred); t->url_cred = NULL; } gitno_connection_data_free_ptrs(&t->connection_data); return 0; }
/* * Parse the URL and connect to a server, storing the socket in * out. For convenience this also takes care of asking for the remote * refs */ static int do_connect(transport_git *t, const char *url) { char *host, *port; const char prefix[] = "git://"; int error; t->socket = INVALID_SOCKET; if (!git__prefixcmp(url, prefix)) url += strlen(prefix); if (gitno_extract_host_and_port(&host, &port, url, GIT_DEFAULT_PORT) < 0) return -1; if ((error = gitno_connect(&t->socket, host, port)) == 0) { error = send_request(t->socket, NULL, url); } git__free(host); git__free(port); if (error < 0 && t->socket != INVALID_SOCKET) { gitno_close(t->socket); t->socket = INVALID_SOCKET; } if (t->socket == INVALID_SOCKET) { giterr_set(GITERR_NET, "Failed to connect to the host"); return -1; } return 0; }
static int http_close(git_smart_subtransport *subtransport) { http_subtransport *t = (http_subtransport *) subtransport; clear_parser_state(t); if (t->socket.socket) { gitno_close(&t->socket); memset(&t->socket, 0x0, sizeof(gitno_socket)); } if (t->cred) { t->cred->free(t->cred); t->cred = NULL; } if (t->host) { git__free(t->host); t->host = NULL; } if (t->port) { git__free(t->port); t->port = NULL; } return 0; }
static void ssh_stream_free(git_smart_subtransport_stream *stream) { ssh_stream *s = (ssh_stream *)stream; ssh_subtransport *t = OWNING_SUBTRANSPORT(s); int ret; GIT_UNUSED(ret); t->current_stream = NULL; if (s->channel) { libssh2_channel_close(s->channel); libssh2_channel_free(s->channel); s->channel = NULL; } if (s->session) { libssh2_session_free(s->session), s->session = NULL; } if (s->socket.socket) { ret = gitno_close(&s->socket); assert(!ret); } git__free(s->url); git__free(s); }
static int http_close(git_transport *transport) { transport_http *t = (transport_http *) transport; if (gitno_close(t->socket) < 0) { giterr_set(GITERR_OS, "Failed to close the socket: %s", strerror(errno)); return -1; } return 0; }
static int http_close(git_transport *transport) { if (gitno_ssl_teardown(transport) < 0) return -1; if (gitno_close(transport->socket) < 0) { giterr_set(GITERR_OS, "Failed to close the socket: %s", strerror(errno)); return -1; } transport->connected = 0; return 0; }
int gitno_connect(git_transport *t, const char *host, const char *port) { struct addrinfo *info = NULL, *p; struct addrinfo hints; int ret; GIT_SOCKET s = INVALID_SOCKET; memset(&hints, 0x0, sizeof(struct addrinfo)); hints.ai_socktype = SOCK_STREAM; hints.ai_family = AF_UNSPEC; if ((ret = p_getaddrinfo(host, port, &hints, &info)) < 0) { giterr_set(GITERR_NET, "Failed to resolve address for %s: %s", host, p_gai_strerror(ret)); return -1; } for (p = info; p != NULL; p = p->ai_next) { s = socket(p->ai_family, p->ai_socktype, p->ai_protocol); if (s == INVALID_SOCKET) { net_set_error("error creating socket"); break; } if (connect(s, p->ai_addr, (socklen_t)p->ai_addrlen) == 0) break; /* If we can't connect, try the next one */ gitno_close(s); s = INVALID_SOCKET; } /* Oops, we couldn't connect to any address */ if (s == INVALID_SOCKET && p == NULL) { giterr_set(GITERR_OS, "Failed to connect to %s", host); return -1; } t->socket = s; p_freeaddrinfo(info); if (t->use_ssl && ssl_setup(t, host) < 0) return -1; return 0; }
static void git_stream_free(git_smart_subtransport_stream *stream) { git_stream *s = (git_stream *)stream; git_subtransport *t = OWNING_SUBTRANSPORT(s); int ret; GIT_UNUSED(ret); t->current_stream = NULL; if (s->socket.socket) { ret = gitno_close(&s->socket); assert(!ret); } git__free(s->url); git__free(s); }
static int git_close(git_transport *t) { git_buf buf = GIT_BUF_INIT; if (git_pkt_buffer_flush(&buf) < 0) return -1; /* Can't do anything if there's an error, so don't bother checking */ gitno_send(t, buf.ptr, buf.size, 0); git_buf_free(&buf); if (gitno_close(t->socket) < 0) { giterr_set(GITERR_NET, "Failed to close socket"); return -1; } t->connected = 0; #ifdef GIT_WIN32 WSACleanup(); #endif return 0; }
static int http_action( git_smart_subtransport_stream **stream, git_smart_subtransport *subtransport, const char *url, git_smart_service_t action) { http_subtransport *t = (http_subtransport *)subtransport; const char *default_port = NULL; int flags = 0, ret; if (!stream) return -1; if (!t->host || !t->port || !t->path) { if (!git__prefixcmp(url, prefix_http)) { url = url + strlen(prefix_http); default_port = "80"; } if (!git__prefixcmp(url, prefix_https)) { url += strlen(prefix_https); default_port = "443"; t->use_ssl = 1; } if (!default_port) return -1; if ((ret = gitno_extract_host_and_port(&t->host, &t->port, url, default_port)) < 0) return ret; t->path = strchr(url, '/'); } if (!t->connected || !http_should_keep_alive(&t->parser) || !http_body_is_final(&t->parser)) { if (t->socket.socket) gitno_close(&t->socket); if (t->use_ssl) { int transport_flags; if (t->owner->parent.read_flags(&t->owner->parent, &transport_flags) < 0) return -1; flags |= GITNO_CONNECT_SSL; if (GIT_TRANSPORTFLAGS_NO_CHECK_CERT & transport_flags) flags |= GITNO_CONNECT_SSL_NO_CHECK_CERT; } if (gitno_connect(&t->socket, t->host, t->port, flags) < 0) return -1; t->connected = 1; } switch (action) { case GIT_SERVICE_UPLOADPACK_LS: return http_uploadpack_ls(t, stream); case GIT_SERVICE_UPLOADPACK: return http_uploadpack(t, stream); case GIT_SERVICE_RECEIVEPACK_LS: return http_receivepack_ls(t, stream); case GIT_SERVICE_RECEIVEPACK: return http_receivepack(t, stream); } *stream = NULL; return -1; }