Commit 59bccf33 by Ben Straub

Add a payload param to git_cred_acquire_cb

Fixes #1128.
parent 72629a10
...@@ -313,7 +313,8 @@ GIT_EXTERN(void) git_remote_check_cert(git_remote *remote, int check); ...@@ -313,7 +313,8 @@ GIT_EXTERN(void) git_remote_check_cert(git_remote *remote, int check);
*/ */
GIT_EXTERN(void) git_remote_set_cred_acquire_cb( GIT_EXTERN(void) git_remote_set_cred_acquire_cb(
git_remote *remote, git_remote *remote,
git_cred_acquire_cb cred_acquire_cb); git_cred_acquire_cb cred_acquire_cb,
void *payload);
/** /**
* Sets a custom transport for the remote. The caller can use this function * Sets a custom transport for the remote. The caller can use this function
......
...@@ -65,7 +65,8 @@ GIT_EXTERN(int) git_cred_userpass_plaintext_new( ...@@ -65,7 +65,8 @@ GIT_EXTERN(int) git_cred_userpass_plaintext_new(
typedef int (*git_cred_acquire_cb)( typedef int (*git_cred_acquire_cb)(
git_cred **cred, git_cred **cred,
const char *url, const char *url,
unsigned int allowed_types); unsigned int allowed_types,
void *payload);
/* /*
*** End interface for credentials acquisition *** *** End interface for credentials acquisition ***
...@@ -94,6 +95,7 @@ typedef struct git_transport { ...@@ -94,6 +95,7 @@ typedef struct git_transport {
int (*connect)(struct git_transport *transport, int (*connect)(struct git_transport *transport,
const char *url, const char *url,
git_cred_acquire_cb cred_acquire_cb, git_cred_acquire_cb cred_acquire_cb,
void *cred_acquire_payload,
int direction, int direction,
int flags); int flags);
......
...@@ -90,10 +90,9 @@ int git_remote_new(git_remote **out, git_repository *repo, const char *name, con ...@@ -90,10 +90,9 @@ int git_remote_new(git_remote **out, git_repository *repo, const char *name, con
/* name is optional */ /* name is optional */
assert(out && repo && url); assert(out && repo && url);
remote = git__malloc(sizeof(git_remote)); remote = git__calloc(1, sizeof(git_remote));
GITERR_CHECK_ALLOC(remote); GITERR_CHECK_ALLOC(remote);
memset(remote, 0x0, sizeof(git_remote));
remote->repo = repo; remote->repo = repo;
remote->check_cert = 1; remote->check_cert = 1;
remote->update_fetchhead = 1; remote->update_fetchhead = 1;
...@@ -509,7 +508,7 @@ int git_remote_connect(git_remote *remote, git_direction direction) ...@@ -509,7 +508,7 @@ int git_remote_connect(git_remote *remote, git_direction direction)
if (!remote->check_cert) if (!remote->check_cert)
flags |= GIT_TRANSPORTFLAGS_NO_CHECK_CERT; flags |= GIT_TRANSPORTFLAGS_NO_CHECK_CERT;
if (t->connect(t, url, remote->cred_acquire_cb, direction, flags) < 0) if (t->connect(t, url, remote->cred_acquire_cb, remote->cred_acquire_payload, direction, flags) < 0)
goto on_error; goto on_error;
remote->transport = t; remote->transport = t;
...@@ -1019,11 +1018,13 @@ int git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callbacks ...@@ -1019,11 +1018,13 @@ int git_remote_set_callbacks(git_remote *remote, git_remote_callbacks *callbacks
void git_remote_set_cred_acquire_cb( void git_remote_set_cred_acquire_cb(
git_remote *remote, git_remote *remote,
git_cred_acquire_cb cred_acquire_cb) git_cred_acquire_cb cred_acquire_cb,
void *payload)
{ {
assert(remote); assert(remote);
remote->cred_acquire_cb = cred_acquire_cb; remote->cred_acquire_cb = cred_acquire_cb;
remote->cred_acquire_payload = payload;
} }
int git_remote_set_transport(git_remote *remote, git_transport *transport) int git_remote_set_transport(git_remote *remote, git_transport *transport)
......
...@@ -23,6 +23,7 @@ struct git_remote { ...@@ -23,6 +23,7 @@ struct git_remote {
struct git_refspec fetch; struct git_refspec fetch;
struct git_refspec push; struct git_refspec push;
git_cred_acquire_cb cred_acquire_cb; git_cred_acquire_cb cred_acquire_cb;
void *cred_acquire_payload;
git_transport *transport; git_transport *transport;
git_repository *repo; git_repository *repo;
git_remote_callbacks callbacks; git_remote_callbacks callbacks;
......
...@@ -256,7 +256,8 @@ static int on_headers_complete(http_parser *parser) ...@@ -256,7 +256,8 @@ static int on_headers_complete(http_parser *parser)
if (t->owner->cred_acquire_cb(&t->cred, if (t->owner->cred_acquire_cb(&t->cred,
t->owner->url, t->owner->url,
allowed_types) < 0) allowed_types,
t->owner->cred_acquire_payload) < 0)
return PARSE_ERROR_GENERIC; return PARSE_ERROR_GENERIC;
assert(t->cred); assert(t->cred);
......
...@@ -143,6 +143,7 @@ static int local_connect( ...@@ -143,6 +143,7 @@ static int local_connect(
git_transport *transport, git_transport *transport,
const char *url, const char *url,
git_cred_acquire_cb cred_acquire_cb, git_cred_acquire_cb cred_acquire_cb,
void *cred_acquire_payload,
int direction, int flags) int direction, int flags)
{ {
git_repository *repo; git_repository *repo;
...@@ -152,6 +153,7 @@ static int local_connect( ...@@ -152,6 +153,7 @@ static int local_connect(
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
GIT_UNUSED(cred_acquire_cb); GIT_UNUSED(cred_acquire_cb);
GIT_UNUSED(cred_acquire_payload);
t->url = git__strdup(url); t->url = git__strdup(url);
GITERR_CHECK_ALLOC(t->url); GITERR_CHECK_ALLOC(t->url);
......
...@@ -62,6 +62,7 @@ static int git_smart__connect( ...@@ -62,6 +62,7 @@ static int git_smart__connect(
git_transport *transport, git_transport *transport,
const char *url, const char *url,
git_cred_acquire_cb cred_acquire_cb, git_cred_acquire_cb cred_acquire_cb,
void *cred_acquire_payload,
int direction, int direction,
int flags) int flags)
{ {
...@@ -81,6 +82,7 @@ static int git_smart__connect( ...@@ -81,6 +82,7 @@ static int git_smart__connect(
t->direction = direction; t->direction = direction;
t->flags = flags; t->flags = flags;
t->cred_acquire_cb = cred_acquire_cb; t->cred_acquire_cb = cred_acquire_cb;
t->cred_acquire_payload = cred_acquire_payload;
if (GIT_DIRECTION_FETCH == t->direction) if (GIT_DIRECTION_FETCH == t->direction)
service = GIT_SERVICE_UPLOADPACK_LS; service = GIT_SERVICE_UPLOADPACK_LS;
......
...@@ -125,6 +125,7 @@ typedef struct { ...@@ -125,6 +125,7 @@ typedef struct {
git_remote *owner; git_remote *owner;
char *url; char *url;
git_cred_acquire_cb cred_acquire_cb; git_cred_acquire_cb cred_acquire_cb;
void *cred_acquire_payload;
int direction; int direction;
int flags; int flags;
git_transport_message_cb progress_cb; git_transport_message_cb progress_cb;
......
...@@ -694,12 +694,13 @@ int git_smart__push(git_transport *transport, git_push *push) ...@@ -694,12 +694,13 @@ int git_smart__push(git_transport *transport, git_push *push)
* the data from the push report to do this without another network call */ * the data from the push report to do this without another network call */
if (push->specs.length) { if (push->specs.length) {
git_cred_acquire_cb cred_cb = t->cred_acquire_cb; git_cred_acquire_cb cred_cb = t->cred_acquire_cb;
void *cred_payload = t->cred_acquire_payload;
int flags = t->flags; int flags = t->flags;
url = git__strdup(t->url); url = git__strdup(t->url);
if (!url || t->parent.close(&t->parent) < 0 || if (!url || t->parent.close(&t->parent) < 0 ||
t->parent.connect(&t->parent, url, cred_cb, GIT_DIRECTION_PUSH, flags)) t->parent.connect(&t->parent, url, cred_cb, cred_payload, GIT_DIRECTION_PUSH, flags))
goto on_error; goto on_error;
} }
......
...@@ -27,10 +27,12 @@ static git_oid _oid_b1; ...@@ -27,10 +27,12 @@ static git_oid _oid_b1;
/* git_oid *oid, git_repository *repo, (string literal) blob */ /* git_oid *oid, git_repository *repo, (string literal) blob */
#define CREATE_BLOB(oid, repo, blob) git_blob_create_frombuffer(oid, repo, blob, sizeof(blob) - 1) #define CREATE_BLOB(oid, repo, blob) git_blob_create_frombuffer(oid, repo, blob, sizeof(blob) - 1)
static int cred_acquire_cb(git_cred **cred, const char *url, unsigned int allowed_types) static int cred_acquire_cb(git_cred **cred, const char *url, unsigned int allowed_types, void *payload)
{ {
GIT_UNUSED(url); GIT_UNUSED(url);
*((bool*)payload) = true;
if ((GIT_CREDTYPE_USERPASS_PLAINTEXT & allowed_types) == 0 || if ((GIT_CREDTYPE_USERPASS_PLAINTEXT & allowed_types) == 0 ||
git_cred_userpass_plaintext_new(cred, _remote_user, _remote_pass) < 0) git_cred_userpass_plaintext_new(cred, _remote_user, _remote_pass) < 0)
return -1; return -1;
...@@ -130,6 +132,7 @@ void test_network_push__initialize(void) ...@@ -130,6 +132,7 @@ void test_network_push__initialize(void)
git_vector delete_specs = GIT_VECTOR_INIT; git_vector delete_specs = GIT_VECTOR_INIT;
size_t i; size_t i;
char *curr_del_spec; char *curr_del_spec;
bool cred_acquire_called = false;
_repo = cl_git_sandbox_init("push_src"); _repo = cl_git_sandbox_init("push_src");
...@@ -165,7 +168,7 @@ void test_network_push__initialize(void) ...@@ -165,7 +168,7 @@ void test_network_push__initialize(void)
if (_remote_url) { if (_remote_url) {
cl_git_pass(git_remote_add(&_remote, _repo, "test", _remote_url)); cl_git_pass(git_remote_add(&_remote, _repo, "test", _remote_url));
git_remote_set_cred_acquire_cb(_remote, cred_acquire_cb); git_remote_set_cred_acquire_cb(_remote, cred_acquire_cb, &cred_acquire_called);
record_callbacks_data_clear(&_record_cbs_data); record_callbacks_data_clear(&_record_cbs_data);
git_remote_set_callbacks(_remote, &_record_cbs); git_remote_set_callbacks(_remote, &_record_cbs);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment