Merge pull request #3388 from libgit2/cmn/smart-callbacks transport: provide a way to get the callbacks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
diff --git a/include/git2/sys/transport.h b/include/git2/sys/transport.h
index 867fbcb..4a75b08 100644
--- a/include/git2/sys/transport.h
+++ b/include/git2/sys/transport.h
@@ -211,6 +211,28 @@ GIT_EXTERN(int) git_transport_smart(
git_remote *owner,
/* (git_smart_subtransport_definition *) */ void *payload);
+/**
+ * Call the certificate check for this transport.
+ *
+ * @param transport a smart transport
+ * @param cert the certificate to pass to the caller
+ * @param valid whether we believe the certificate is valid
+ * @param hostname the hostname we connected to
+ * @return the return value of the callback
+ */
+GIT_EXTERN(int) git_transport_smart_certificate_check(git_transport *transport, git_cert *cert, int valid, const char *hostname);
+
+/**
+ * Call the credentials callback for this transport
+ *
+ * @param out the pointer where the creds are to be stored
+ * @param transport a smart transport
+ * @param user the user we saw on the url (if any)
+ * @param methods available methods for authentication
+ * @return the return value of the callback
+ */
+GIT_EXTERN(int) git_transport_smart_credentials(git_cred **out, git_transport *transport, const char *user, int methods);
+
/*
*** End of base transport interface ***
*** Begin interface for subtransports for the smart transport ***
diff --git a/include/git2/transport.h b/include/git2/transport.h
index fd55eac..0ec2416 100644
--- a/include/git2/transport.h
+++ b/include/git2/transport.h
@@ -307,6 +307,17 @@ GIT_EXTERN(int) git_cred_ssh_key_memory_new(
const char *privatekey,
const char *passphrase);
+
+/**
+ * Free a credential.
+ *
+ * This is only necessary if you own the object; that is, if you are a
+ * transport.
+ *
+ * @param cred the object to free
+ */
+GIT_EXTERN(void) git_cred_free(git_cred *cred);
+
/**
* Signature of a function which acquires a credential object.
*
diff --git a/src/transports/cred.c b/src/transports/cred.c
index 044b2a2..49ede48 100644
--- a/src/transports/cred.c
+++ b/src/transports/cred.c
@@ -378,3 +378,11 @@ int git_cred_username_new(git_cred **cred, const char *username)
*cred = (git_cred *) c;
return 0;
}
+
+void git_cred_free(git_cred *cred)
+{
+ if (!cred)
+ return;
+
+ cred->free(cred);
+}
diff --git a/src/transports/smart.c b/src/transports/smart.c
index 85a49e5..31a2dec 100644
--- a/src/transports/smart.c
+++ b/src/transports/smart.c
@@ -372,6 +372,20 @@ static int ref_name_cmp(const void *a, const void *b)
return strcmp(ref_a->head.name, ref_b->head.name);
}
+int git_transport_smart_certificate_check(git_transport *transport, git_cert *cert, int valid, const char *hostname)
+{
+ transport_smart *t = (transport_smart *)transport;
+
+ return t->certificate_check_cb(cert, valid, hostname, t->message_cb_payload);
+}
+
+int git_transport_smart_credentials(git_cred **out, git_transport *transport, const char *user, int methods)
+{
+ transport_smart *t = (transport_smart *)transport;
+
+ return t->cred_acquire_cb(out, t->url, user, methods, t->cred_acquire_payload);
+}
+
int git_transport_smart(git_transport **out, git_remote *owner, void *param)
{
transport_smart *t;