git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Grégoire Barbier" <gb@gbarbier.org>
To: git@vger.kernel.org
Cc: gitster@pobox.com, "Grégoire Barbier" <gb@gbarbier.org>
Subject: [PATCH] http-push: more explicit error message with bad URL or password
Date: Sat, 19 Jan 2008 16:22:49 +0100	[thread overview]
Message-ID: <1200756171-11696-3-git-send-email-gb@gbarbier.org> (raw)
In-Reply-To: <1200756171-11696-2-git-send-email-gb@gbarbier.org>

Previously, when URL or password where not set correctly (or when some network
errors occur), the error message was "no DAV locking support".
---
 http-push.c |    6 ++++++
 http.c      |   25 +++++++++++++++++++++++++
 http.h      |    1 +
 3 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/http-push.c b/http-push.c
index e1984d3..c984d84 100644
--- a/http-push.c
+++ b/http-push.c
@@ -2228,6 +2228,12 @@ int main(int argc, char **argv)
 
 	no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
 
+	if (!http_test_connection(remote->url)) {
+		fprintf(stderr, "Error: cannot access to remote URL (maybe malformed URL, network error or bad credentials)\n");
+		rc = 1;
+		goto cleanup;
+	}
+
 	/* Verify DAV compliance/lock support */
 	if (!locking_available()) {
 		fprintf(stderr, "Error: no DAV locking support on remote repo %s\n", remote->url);
diff --git a/http.c b/http.c
index d2c11ae..8b04ae9 100644
--- a/http.c
+++ b/http.c
@@ -634,3 +634,28 @@ int http_fetch_ref(const char *base, const char *ref, unsigned char *sha1)
 	free(url);
 	return ret;
 }
+
+int http_test_connection(const char *url)
+{
+	struct strbuf buffer = STRBUF_INIT;
+	struct active_request_slot *slot;
+	struct slot_results results;
+	int ret = 0;
+
+	slot = get_active_slot();
+	slot->results = &results;
+	curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
+	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
+	curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL);
+	curl_easy_setopt(slot->curl, CURLOPT_URL, url);
+	if (start_active_slot(slot)) {
+		run_active_slot(slot);
+		if (results.curl_result == CURLE_OK)
+			ret = -1;
+		else
+			error("Cannot access to URL %s, return code %d", url, results.curl_result);
+	} else
+		error("Unable to start request");
+	strbuf_release(&buffer);
+	return ret;
+}
diff --git a/http.h b/http.h
index aeba930..b353007 100644
--- a/http.h
+++ b/http.h
@@ -77,6 +77,7 @@ extern void step_active_slots(void);
 
 extern void http_init(void);
 extern void http_cleanup(void);
+extern int http_test_connection(const char *url);
 
 extern int data_received;
 extern int active_requests;
-- 
1.5.4.rc3.52.g9a5bd-dirty

  reply	other threads:[~2008-01-19 15:24 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-19 15:22 [PATCH] http-push: fix webdav lock leak Grégoire Barbier
2008-01-19 15:22 ` [PATCH] http-push: fail when info/refs exists and is already locked Grégoire Barbier
2008-01-19 15:22   ` Grégoire Barbier [this message]
2008-01-19 15:22     ` [PATCH] http-push and http-fetch: handle URLs without leading / Grégoire Barbier
2008-01-19 15:22       ` [PATCH] added #define DEFAULT_MAX_REQUESTS for USE_CURL_MULTI mode Grégoire Barbier
2008-01-21  0:13         ` Junio C Hamano
2008-01-21  9:57           ` Grégoire Barbier
2008-01-21 10:19             ` Junio C Hamano
2008-01-19 15:29       ` [PATCH] http-push and http-fetch: handle URLs without leading / Mike Hommey
2008-01-19 23:16         ` Johannes Schindelin
2008-01-19 23:14       ` Johannes Schindelin
2008-01-20 23:00     ` [PATCH] http-push: more explicit error message with bad URL or password Junio C Hamano
2008-01-19 23:08 ` [PATCH] http-push: fix webdav lock leak Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1200756171-11696-3-git-send-email-gb@gbarbier.org \
    --to=gb@gbarbier.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).