File tree 5 files changed +81
-0
lines changed
5 files changed +81
-0
lines changed Original file line number Diff line number Diff line change @@ -17,11 +17,16 @@ v0.23 + 1
17
17
the opportunity for concurrent operations and not committing any
18
18
changes until the unlock.
19
19
20
+
20
21
* ` git_diff_options ` added a new callback ` progress_cb ` to report on the
21
22
progress of the diff as files are being compared. The documentation of
22
23
the existing callback ` notify_cb ` was updated to reflect that it only
23
24
gets called when new deltas are added to the diff.
24
25
26
+ * ` git_stream_register_tls() ` lets you register a callback to be used
27
+ as the constructor for a TLS stream instead of the libgit2 built-in
28
+ one.
29
+
25
30
### API removals
26
31
27
32
### Breaking API changes
Original file line number Diff line number Diff line change @@ -39,6 +39,19 @@ typedef struct git_stream {
39
39
void (* free )(struct git_stream * );
40
40
} git_stream ;
41
41
42
+ typedef int (* git_stream_cb )(git_stream * * out , const char * host , const char * port );
43
+
44
+ /**
45
+ * Register a TLS stream constructor for the library to use
46
+ *
47
+ * If a constructor is already set, it will be overwritten. Pass
48
+ * `NULL` in order to deregister the current constructor.
49
+ *
50
+ * @param ctor the constructor to use
51
+ * @return 0 or an error code
52
+ */
53
+ GIT_EXTERN (int ) git_stream_register_tls (git_stream_cb ctor );
54
+
42
55
GIT_END_DECL
43
56
44
57
#endif
Original file line number Diff line number Diff line change @@ -62,6 +62,9 @@ GIT_INLINE(int) git_stream_close(git_stream *st)
62
62
63
63
GIT_INLINE (void ) git_stream_free (git_stream * st )
64
64
{
65
+ if (!st )
66
+ return ;
67
+
65
68
st -> free (st );
66
69
}
67
70
Original file line number Diff line number Diff line change 11
11
#include "openssl_stream.h"
12
12
#include "stransport_stream.h"
13
13
14
+ static git_stream_cb tls_ctor ;
15
+
16
+ int git_stream_register_tls (git_stream_cb ctor )
17
+ {
18
+ tls_ctor = ctor ;
19
+
20
+ return 0 ;
21
+ }
22
+
14
23
int git_tls_stream_new (git_stream * * out , const char * host , const char * port )
15
24
{
25
+
26
+ if (tls_ctor )
27
+ return tls_ctor (out , host , port );
28
+
16
29
#ifdef GIT_SECURE_TRANSPORT
17
30
return git_stransport_stream_new (out , host , port );
18
31
#elif defined(GIT_OPENSSL )
Original file line number Diff line number Diff line change
1
+ #include "clar_libgit2.h"
2
+ #include "git2/sys/stream.h"
3
+ #include "tls_stream.h"
4
+ #include "stream.h"
5
+
6
+ static git_stream test_stream ;
7
+ static int ctor_called ;
8
+
9
+ static int test_ctor (git_stream * * out , const char * host , const char * port )
10
+ {
11
+ GIT_UNUSED (host );
12
+ GIT_UNUSED (port );
13
+
14
+ ctor_called = 1 ;
15
+ * out = & test_stream ;
16
+
17
+ return 0 ;
18
+ }
19
+
20
+ void test_core_stream__register_tls (void )
21
+ {
22
+ git_stream * stream ;
23
+ int error ;
24
+
25
+ ctor_called = 0 ;
26
+ cl_git_pass (git_stream_register_tls (test_ctor ));
27
+ cl_git_pass (git_tls_stream_new (& stream , "localhost" , "443" ));
28
+ cl_assert_equal_i (1 , ctor_called );
29
+ cl_assert_equal_p (& test_stream , stream );
30
+
31
+ ctor_called = 0 ;
32
+ stream = NULL ;
33
+ cl_git_pass (git_stream_register_tls (NULL ));
34
+ error = git_tls_stream_new (& stream , "localhost" , "443" );
35
+
36
+ /* We don't have arbitrary TLS stream support on Windows */
37
+ #if GIT_WIN32
38
+ cl_git_fail_with (-1 , error );
39
+ #else
40
+ cl_git_pass (error );
41
+ #endif
42
+
43
+ cl_assert_equal_i (0 , ctor_called );
44
+ cl_assert (& test_stream != stream );
45
+
46
+ git_stream_free (stream );
47
+ }
You can’t perform that action at this time.
0 commit comments