http: propagate the credentials callback's error code

When we ask for credentials, the user may choose to return EUSER to
indicate that an error has happened on its end and it wants to be given
back control.

We must therefore pass that back to the user instead of mentioning that
it was on_headers_complete() that returned an error code. Since we can,
we return the exact error code from the user (other than PASSTHROUGH)
since it doesn't cost anything, though using other error codes aren't
recommended.
This commit is contained in:
Carlos Martín Nieto 2015-08-15 18:15:23 +02:00
parent 755004eaed
commit 11bca2d265

View File

@ -36,6 +36,8 @@ static const char *post_verb = "POST";
#define PARSE_ERROR_GENERIC -1 #define PARSE_ERROR_GENERIC -1
#define PARSE_ERROR_REPLAY -2 #define PARSE_ERROR_REPLAY -2
/** Look at the user field */
#define PARSE_ERROR_EXT -3
#define CHUNK_SIZE 4096 #define CHUNK_SIZE 4096
@ -78,6 +80,7 @@ typedef struct {
git_vector www_authenticate; git_vector www_authenticate;
enum last_cb last_cb; enum last_cb last_cb;
int parse_error; int parse_error;
int error;
unsigned parse_finished : 1; unsigned parse_finished : 1;
/* Authentication */ /* Authentication */
@ -351,7 +354,8 @@ static int on_headers_complete(http_parser *parser)
if (error == GIT_PASSTHROUGH) { if (error == GIT_PASSTHROUGH) {
no_callback = 1; no_callback = 1;
} else if (error < 0) { } else if (error < 0) {
return PARSE_ERROR_GENERIC; t->error = error;
return t->parse_error = PARSE_ERROR_EXT;
} else { } else {
assert(t->cred); assert(t->cred);
@ -712,6 +716,10 @@ replay:
goto replay; goto replay;
} }
if (t->parse_error == PARSE_ERROR_EXT) {
return t->error;
}
if (t->parse_error < 0) if (t->parse_error < 0)
return -1; return -1;