Skip to content

Commit 3c4c96e

Browse files
Add Stream (Advanced) bindings
1 parent f3233fb commit 3c4c96e

6 files changed

Lines changed: 462 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the swift-libgit2 open source project.
4+
//
5+
// Copyright (c) Margins Technologies LLC.
6+
// Licensed under the Apache License, Version 2.0.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
import CLibgit2
11+
12+
13+
14+
/// The callback invoked to create a new connection to the given host and port.
15+
/// - Parameters:
16+
/// - out: The pointer in which to store the stream.
17+
/// - host: The name of the host to which to connect the stream.
18+
/// - port: The port to which to connect the stream.
19+
/// - Returns: `0` on success, or an error code.
20+
///
21+
/// ## Discussion
22+
///
23+
/// - Warning: This is deprecated in libgit2 and will be removed in the next
24+
/// major release. Use ``GitStreamRegistration/Initialize`` instead.
25+
///
26+
/// ## C Equivalent
27+
///
28+
/// [`git_stream_cb()`](https://libgit2.org/docs/reference/main/sys/stream/git_stream_cb.html)
29+
public typealias GitStreamCB = @convention(c)
30+
(
31+
UnsafeMutablePointer<UnsafeMutablePointer<git_stream>?>?,
32+
UnsafePointer<CChar>?,
33+
UnsafePointer<CChar>?
34+
) -> Int32
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the swift-libgit2 open source project.
4+
//
5+
// Copyright (c) Margins Technologies LLC.
6+
// Licensed under the Apache License, Version 2.0.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
import CLibgit2
11+
12+
13+
14+
/// The type of stream.
15+
///
16+
/// ## C Equivalent
17+
///
18+
/// [`git_stream_t`](https://libgit2.org/docs/reference/main/sys/stream/git_stream_t.html)
19+
public enum GitStreamT: UInt32, CEnum
20+
{
21+
/// A standard non-TLS socket.
22+
case gitStreamStandard = 1
23+
24+
/// A TLS-encrypted socket.
25+
case gitStreamTLS = 2
26+
27+
28+
29+
/// Initializes a ``GitStreamT`` instance from the given `git_stream_t`
30+
/// instance.
31+
/// - Parameter stream: The `git_stream_t` instance to use.
32+
internal init?(
33+
cValue stream: git_stream_t
34+
)
35+
{
36+
switch stream
37+
{
38+
case GIT_STREAM_STANDARD : self = .gitStreamStandard
39+
case GIT_STREAM_TLS : self = .gitStreamTLS
40+
default : return nil
41+
}
42+
}
43+
44+
45+
46+
/// Converts the ``GitStreamT`` instance into a `git_stream_t` instance.
47+
/// - Returns: The `git_stream_t` instance.
48+
internal func cValue() -> git_stream_t
49+
{
50+
switch self
51+
{
52+
case .gitStreamStandard : return GIT_STREAM_STANDARD
53+
case .gitStreamTLS : return GIT_STREAM_TLS
54+
}
55+
}
56+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the swift-libgit2 open source project.
4+
//
5+
// Copyright (c) Margins Technologies LLC.
6+
// Licensed under the Apache License, Version 2.0.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
import CLibgit2
11+
12+
13+
14+
/// Registers the specified stream constructor.
15+
/// - Parameters:
16+
/// - type: The type of stream to register.
17+
/// - registration: The stream registration information to use. Pass `nil`
18+
/// to unregister the stream and use the system defaults.
19+
/// - Returns: A ``GitErrorCode`` instance.
20+
///
21+
/// ## Discussion
22+
///
23+
/// If the specified stream constructor has already been registered, it will
24+
/// be overwritten.
25+
///
26+
/// ## C Equivalent
27+
///
28+
/// [`git_stream_register()`](https://libgit2.org/docs/reference/main/sys/stream/git_stream_register.html)
29+
public func gitStreamRegister(
30+
type : GitStreamT,
31+
registration : UnsafeMutablePointer<git_stream_registration>?
32+
) -> GitErrorCode
33+
{
34+
return withCConversion
35+
{
36+
return git_stream_register(
37+
type.cValue(),
38+
registration
39+
)
40+
}
41+
}
42+
43+
44+
45+
/// Registers a TLS stream constructor.
46+
/// - Parameter ctor: The ``GitStreamCB`` callback to invoke to create a new
47+
/// connection. Pass `nil` to unregister the stream and use the system defaults.
48+
/// - Returns: A ``GitErrorCode`` instance.
49+
///
50+
/// ## Discussion
51+
///
52+
/// - Note: This function does not support HTTP CONNECT proxies.
53+
///
54+
/// - Warning: This is deprecated in libgit2 and will be removed in the next
55+
/// major release. Use ``GitStreamRegistration/Initialize`` instead.
56+
///
57+
/// ## C Equivalent
58+
///
59+
/// [`git_stream_register_tls()`](https://libgit2.org/docs/reference/main/sys/stream/git_stream_register_tls.html)
60+
public func gitStreamRegisterTLS(
61+
ctor: GitStreamCB?
62+
) -> GitErrorCode
63+
{
64+
return withCConversion
65+
{
66+
return git_stream_register_tls(ctor)
67+
}
68+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the swift-libgit2 open source project.
4+
//
5+
// Copyright (c) Margins Technologies LLC.
6+
// Licensed under the Apache License, Version 2.0.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
/// The current version for ``GitStream``.
11+
///
12+
/// ## C Equivalent
13+
///
14+
/// [`GIT_STREAM_VERSION`](https://libgit2.org/docs/reference/main/sys/stream/GIT_STREAM_VERSION.html)
15+
public let gitStreamVersion: Int32 = 1

0 commit comments

Comments
 (0)