rugged 0.27.10.1 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (297) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rugged/extconf.rb +23 -2
  3. data/ext/rugged/rugged.c +48 -2
  4. data/ext/rugged/rugged.h +5 -0
  5. data/ext/rugged/rugged_allocator.c +89 -0
  6. data/ext/rugged/rugged_blob.c +3 -3
  7. data/ext/rugged/rugged_branch.c +1 -1
  8. data/ext/rugged/rugged_commit.c +8 -8
  9. data/ext/rugged/rugged_config.c +1 -1
  10. data/ext/rugged/rugged_diff.c +24 -4
  11. data/ext/rugged/rugged_note.c +1 -1
  12. data/ext/rugged/rugged_repo.c +10 -10
  13. data/ext/rugged/rugged_settings.c +1 -1
  14. data/lib/rugged/version.rb +1 -1
  15. data/vendor/libgit2/CMakeLists.txt +69 -47
  16. data/vendor/libgit2/cmake/Modules/AddCFlagIfSupported.cmake +15 -1
  17. data/vendor/libgit2/cmake/Modules/EnableWarnings.cmake +5 -8
  18. data/vendor/libgit2/cmake/Modules/FindmbedTLS.cmake +93 -0
  19. data/vendor/libgit2/deps/http-parser/CMakeLists.txt +2 -0
  20. data/vendor/libgit2/deps/http-parser/{LICENSE-MIT → COPYING} +0 -0
  21. data/vendor/libgit2/deps/regex/COPYING +502 -0
  22. data/vendor/libgit2/deps/winhttp/COPYING.GPL +993 -0
  23. data/vendor/libgit2/deps/winhttp/COPYING.LGPL +502 -0
  24. data/vendor/libgit2/deps/zlib/CMakeLists.txt +1 -0
  25. data/vendor/libgit2/deps/zlib/COPYING +27 -0
  26. data/vendor/libgit2/include/git2.h +3 -0
  27. data/vendor/libgit2/include/git2/annotated_commit.h +9 -0
  28. data/vendor/libgit2/include/git2/apply.h +129 -0
  29. data/vendor/libgit2/include/git2/attr.h +19 -8
  30. data/vendor/libgit2/include/git2/blame.h +41 -24
  31. data/vendor/libgit2/include/git2/blob.h +1 -1
  32. data/vendor/libgit2/include/git2/branch.h +1 -1
  33. data/vendor/libgit2/include/git2/buffer.h +2 -2
  34. data/vendor/libgit2/include/git2/checkout.h +20 -19
  35. data/vendor/libgit2/include/git2/cherrypick.h +6 -4
  36. data/vendor/libgit2/include/git2/clone.h +11 -9
  37. data/vendor/libgit2/include/git2/commit.h +30 -2
  38. data/vendor/libgit2/include/git2/common.h +54 -4
  39. data/vendor/libgit2/include/git2/config.h +18 -7
  40. data/vendor/libgit2/include/git2/deprecated.h +253 -0
  41. data/vendor/libgit2/include/git2/describe.h +30 -7
  42. data/vendor/libgit2/include/git2/diff.h +193 -143
  43. data/vendor/libgit2/include/git2/errors.h +54 -46
  44. data/vendor/libgit2/include/git2/ignore.h +2 -2
  45. data/vendor/libgit2/include/git2/index.h +72 -51
  46. data/vendor/libgit2/include/git2/indexer.h +30 -4
  47. data/vendor/libgit2/include/git2/mailmap.h +115 -0
  48. data/vendor/libgit2/include/git2/merge.h +29 -8
  49. data/vendor/libgit2/include/git2/net.h +1 -1
  50. data/vendor/libgit2/include/git2/notes.h +1 -1
  51. data/vendor/libgit2/include/git2/object.h +16 -16
  52. data/vendor/libgit2/include/git2/odb.h +10 -10
  53. data/vendor/libgit2/include/git2/odb_backend.h +7 -7
  54. data/vendor/libgit2/include/git2/oid.h +1 -1
  55. data/vendor/libgit2/include/git2/pack.h +2 -2
  56. data/vendor/libgit2/include/git2/proxy.h +9 -5
  57. data/vendor/libgit2/include/git2/rebase.h +7 -4
  58. data/vendor/libgit2/include/git2/refs.h +14 -15
  59. data/vendor/libgit2/include/git2/refspec.h +17 -0
  60. data/vendor/libgit2/include/git2/remote.h +92 -16
  61. data/vendor/libgit2/include/git2/repository.h +52 -37
  62. data/vendor/libgit2/include/git2/revert.h +5 -3
  63. data/vendor/libgit2/include/git2/revwalk.h +7 -7
  64. data/vendor/libgit2/include/git2/signature.h +2 -2
  65. data/vendor/libgit2/include/git2/stash.h +13 -10
  66. data/vendor/libgit2/include/git2/status.h +8 -4
  67. data/vendor/libgit2/include/git2/submodule.h +11 -10
  68. data/vendor/libgit2/include/git2/sys/alloc.h +101 -0
  69. data/vendor/libgit2/include/git2/sys/commit.h +1 -1
  70. data/vendor/libgit2/include/git2/sys/config.h +13 -13
  71. data/vendor/libgit2/include/git2/sys/filter.h +6 -6
  72. data/vendor/libgit2/include/git2/sys/index.h +3 -0
  73. data/vendor/libgit2/include/git2/sys/mempack.h +35 -35
  74. data/vendor/libgit2/include/git2/sys/merge.h +9 -4
  75. data/vendor/libgit2/include/git2/sys/odb_backend.h +19 -19
  76. data/vendor/libgit2/include/git2/sys/path.h +64 -0
  77. data/vendor/libgit2/include/git2/sys/refdb_backend.h +19 -19
  78. data/vendor/libgit2/include/git2/sys/stream.h +92 -12
  79. data/vendor/libgit2/include/git2/sys/transport.h +127 -81
  80. data/vendor/libgit2/include/git2/tag.h +2 -2
  81. data/vendor/libgit2/include/git2/trace.h +1 -1
  82. data/vendor/libgit2/include/git2/transaction.h +1 -0
  83. data/vendor/libgit2/include/git2/transport.h +47 -18
  84. data/vendor/libgit2/include/git2/tree.h +3 -3
  85. data/vendor/libgit2/include/git2/types.h +35 -28
  86. data/vendor/libgit2/include/git2/version.h +4 -4
  87. data/vendor/libgit2/include/git2/worktree.h +47 -12
  88. data/vendor/libgit2/src/CMakeLists.txt +87 -26
  89. data/vendor/libgit2/src/alloc.c +55 -0
  90. data/vendor/libgit2/src/alloc.h +40 -0
  91. data/vendor/libgit2/src/annotated_commit.c +15 -8
  92. data/vendor/libgit2/src/apply.c +490 -14
  93. data/vendor/libgit2/src/apply.h +3 -1
  94. data/vendor/libgit2/src/array.h +2 -2
  95. data/vendor/libgit2/src/attr.c +11 -11
  96. data/vendor/libgit2/src/attr_file.c +20 -15
  97. data/vendor/libgit2/src/attrcache.c +11 -11
  98. data/vendor/libgit2/src/blame.c +30 -15
  99. data/vendor/libgit2/src/blame.h +1 -0
  100. data/vendor/libgit2/src/blame_git.c +16 -13
  101. data/vendor/libgit2/src/blob.c +50 -28
  102. data/vendor/libgit2/src/blob.h +18 -1
  103. data/vendor/libgit2/src/branch.c +38 -38
  104. data/vendor/libgit2/src/buf_text.c +7 -6
  105. data/vendor/libgit2/src/buffer.c +55 -50
  106. data/vendor/libgit2/src/buffer.h +1 -1
  107. data/vendor/libgit2/src/cache.c +16 -16
  108. data/vendor/libgit2/src/cache.h +2 -2
  109. data/vendor/libgit2/src/cc-compat.h +15 -3
  110. data/vendor/libgit2/src/checkout.c +83 -74
  111. data/vendor/libgit2/src/cherrypick.c +6 -6
  112. data/vendor/libgit2/src/clone.c +20 -20
  113. data/vendor/libgit2/src/commit.c +53 -33
  114. data/vendor/libgit2/src/commit.h +1 -0
  115. data/vendor/libgit2/src/commit_list.c +6 -10
  116. data/vendor/libgit2/src/common.h +32 -30
  117. data/vendor/libgit2/src/config.c +167 -147
  118. data/vendor/libgit2/src/config.h +1 -14
  119. data/vendor/libgit2/src/config_backend.h +84 -0
  120. data/vendor/libgit2/src/config_cache.c +7 -1
  121. data/vendor/libgit2/src/config_entries.c +259 -0
  122. data/vendor/libgit2/src/config_entries.h +23 -0
  123. data/vendor/libgit2/src/config_file.c +167 -439
  124. data/vendor/libgit2/src/config_mem.c +224 -0
  125. data/vendor/libgit2/src/config_parse.c +69 -38
  126. data/vendor/libgit2/src/config_parse.h +4 -4
  127. data/vendor/libgit2/src/crlf.c +215 -186
  128. data/vendor/libgit2/src/delta.c +25 -18
  129. data/vendor/libgit2/src/describe.c +23 -23
  130. data/vendor/libgit2/src/diff.c +12 -12
  131. data/vendor/libgit2/src/diff_driver.c +14 -15
  132. data/vendor/libgit2/src/diff_file.c +10 -10
  133. data/vendor/libgit2/src/diff_generate.c +29 -23
  134. data/vendor/libgit2/src/diff_generate.h +1 -1
  135. data/vendor/libgit2/src/diff_parse.c +3 -3
  136. data/vendor/libgit2/src/diff_print.c +17 -17
  137. data/vendor/libgit2/src/diff_stats.c +22 -7
  138. data/vendor/libgit2/src/diff_tform.c +12 -12
  139. data/vendor/libgit2/src/diff_xdiff.c +15 -3
  140. data/vendor/libgit2/src/errors.c +42 -20
  141. data/vendor/libgit2/src/features.h.in +2 -1
  142. data/vendor/libgit2/src/fetch.c +3 -3
  143. data/vendor/libgit2/src/fetchhead.c +16 -16
  144. data/vendor/libgit2/src/filebuf.c +28 -28
  145. data/vendor/libgit2/src/fileops.c +54 -54
  146. data/vendor/libgit2/src/fileops.h +1 -1
  147. data/vendor/libgit2/src/filter.c +30 -30
  148. data/vendor/libgit2/src/filter.h +0 -10
  149. data/vendor/libgit2/src/global.c +36 -23
  150. data/vendor/libgit2/src/hash.h +4 -1
  151. data/vendor/libgit2/src/hash/hash_collisiondetect.h +6 -2
  152. data/vendor/libgit2/src/hash/hash_common_crypto.h +5 -1
  153. data/vendor/libgit2/src/hash/hash_generic.h +5 -1
  154. data/vendor/libgit2/src/hash/hash_mbedtls.c +38 -0
  155. data/vendor/libgit2/src/hash/hash_mbedtls.h +24 -0
  156. data/vendor/libgit2/src/hash/hash_openssl.h +8 -4
  157. data/vendor/libgit2/src/hash/hash_win32.c +13 -13
  158. data/vendor/libgit2/src/hashsig.c +4 -4
  159. data/vendor/libgit2/src/idxmap.c +25 -5
  160. data/vendor/libgit2/src/idxmap.h +4 -18
  161. data/vendor/libgit2/src/ignore.c +9 -9
  162. data/vendor/libgit2/src/index.c +280 -198
  163. data/vendor/libgit2/src/index.h +16 -0
  164. data/vendor/libgit2/src/indexer.c +311 -139
  165. data/vendor/libgit2/src/integer.h +32 -22
  166. data/vendor/libgit2/src/iterator.c +116 -49
  167. data/vendor/libgit2/src/iterator.h +15 -0
  168. data/vendor/libgit2/src/khash.h +3 -1
  169. data/vendor/libgit2/src/mailmap.c +485 -0
  170. data/vendor/libgit2/src/mailmap.h +35 -0
  171. data/vendor/libgit2/src/merge.c +89 -59
  172. data/vendor/libgit2/src/merge_driver.c +7 -7
  173. data/vendor/libgit2/src/merge_file.c +1 -1
  174. data/vendor/libgit2/src/mwindow.c +8 -8
  175. data/vendor/libgit2/src/netops.c +22 -13
  176. data/vendor/libgit2/src/netops.h +2 -0
  177. data/vendor/libgit2/src/notes.c +15 -10
  178. data/vendor/libgit2/src/object.c +118 -67
  179. data/vendor/libgit2/src/object.h +20 -9
  180. data/vendor/libgit2/src/object_api.c +8 -8
  181. data/vendor/libgit2/src/odb.c +72 -72
  182. data/vendor/libgit2/src/odb.h +7 -7
  183. data/vendor/libgit2/src/odb_loose.c +46 -46
  184. data/vendor/libgit2/src/odb_mempack.c +14 -14
  185. data/vendor/libgit2/src/odb_pack.c +14 -10
  186. data/vendor/libgit2/src/offmap.c +30 -0
  187. data/vendor/libgit2/src/offmap.h +20 -11
  188. data/vendor/libgit2/src/oid.c +6 -6
  189. data/vendor/libgit2/src/oidmap.c +20 -0
  190. data/vendor/libgit2/src/oidmap.h +9 -12
  191. data/vendor/libgit2/src/pack-objects.c +71 -63
  192. data/vendor/libgit2/src/pack-objects.h +1 -7
  193. data/vendor/libgit2/src/pack.c +58 -58
  194. data/vendor/libgit2/src/pack.h +6 -6
  195. data/vendor/libgit2/src/parse.h +1 -1
  196. data/vendor/libgit2/src/patch.c +3 -3
  197. data/vendor/libgit2/src/patch_generate.c +18 -18
  198. data/vendor/libgit2/src/patch_parse.c +13 -13
  199. data/vendor/libgit2/src/path.c +93 -225
  200. data/vendor/libgit2/src/path.h +2 -84
  201. data/vendor/libgit2/src/pathspec.c +6 -6
  202. data/vendor/libgit2/src/posix.c +3 -3
  203. data/vendor/libgit2/src/proxy.c +1 -1
  204. data/vendor/libgit2/src/push.c +27 -26
  205. data/vendor/libgit2/src/push.h +2 -1
  206. data/vendor/libgit2/src/reader.c +265 -0
  207. data/vendor/libgit2/src/reader.h +107 -0
  208. data/vendor/libgit2/src/rebase.c +49 -52
  209. data/vendor/libgit2/src/refdb.c +3 -3
  210. data/vendor/libgit2/src/refdb_fs.c +181 -103
  211. data/vendor/libgit2/src/reflog.c +3 -3
  212. data/vendor/libgit2/src/refs.c +98 -74
  213. data/vendor/libgit2/src/refs.h +5 -3
  214. data/vendor/libgit2/src/refspec.c +47 -21
  215. data/vendor/libgit2/src/refspec.h +1 -1
  216. data/vendor/libgit2/src/remote.c +219 -166
  217. data/vendor/libgit2/src/remote.h +9 -0
  218. data/vendor/libgit2/src/repository.c +173 -133
  219. data/vendor/libgit2/src/repository.h +6 -3
  220. data/vendor/libgit2/src/reset.c +8 -8
  221. data/vendor/libgit2/src/revert.c +6 -6
  222. data/vendor/libgit2/src/revparse.c +30 -30
  223. data/vendor/libgit2/src/revwalk.c +60 -30
  224. data/vendor/libgit2/src/revwalk.h +2 -1
  225. data/vendor/libgit2/src/settings.c +42 -10
  226. data/vendor/libgit2/src/signature.c +11 -11
  227. data/vendor/libgit2/src/sortedcache.c +13 -13
  228. data/vendor/libgit2/src/stash.c +91 -45
  229. data/vendor/libgit2/src/status.c +13 -13
  230. data/vendor/libgit2/src/stdalloc.c +120 -0
  231. data/vendor/libgit2/src/{streams/curl.h → stdalloc.h} +6 -6
  232. data/vendor/libgit2/src/stream.h +17 -2
  233. data/vendor/libgit2/src/streams/mbedtls.c +483 -0
  234. data/vendor/libgit2/src/streams/mbedtls.h +23 -0
  235. data/vendor/libgit2/src/streams/openssl.c +204 -114
  236. data/vendor/libgit2/src/streams/openssl.h +4 -108
  237. data/vendor/libgit2/src/streams/registry.c +118 -0
  238. data/vendor/libgit2/src/streams/registry.h +19 -0
  239. data/vendor/libgit2/src/streams/socket.c +54 -29
  240. data/vendor/libgit2/src/streams/stransport.c +57 -32
  241. data/vendor/libgit2/src/streams/stransport.h +5 -0
  242. data/vendor/libgit2/src/streams/tls.c +50 -19
  243. data/vendor/libgit2/src/streams/tls.h +12 -4
  244. data/vendor/libgit2/src/strmap.c +22 -2
  245. data/vendor/libgit2/src/strmap.h +18 -15
  246. data/vendor/libgit2/src/submodule.c +179 -155
  247. data/vendor/libgit2/src/sysdir.c +18 -18
  248. data/vendor/libgit2/src/tag.c +31 -26
  249. data/vendor/libgit2/src/tag.h +2 -1
  250. data/vendor/libgit2/src/trace.c +1 -1
  251. data/vendor/libgit2/src/trace.h +1 -1
  252. data/vendor/libgit2/src/trailer.c +6 -6
  253. data/vendor/libgit2/src/transaction.c +23 -23
  254. data/vendor/libgit2/src/transport.c +5 -5
  255. data/vendor/libgit2/src/transports/auth.c +7 -4
  256. data/vendor/libgit2/src/transports/auth.h +1 -1
  257. data/vendor/libgit2/src/transports/auth_negotiate.c +12 -11
  258. data/vendor/libgit2/src/transports/cred.c +18 -18
  259. data/vendor/libgit2/src/transports/git.c +15 -15
  260. data/vendor/libgit2/src/transports/http.c +606 -216
  261. data/vendor/libgit2/src/transports/http.h +2 -0
  262. data/vendor/libgit2/src/transports/local.c +26 -26
  263. data/vendor/libgit2/src/transports/smart.c +54 -31
  264. data/vendor/libgit2/src/transports/smart.h +1 -2
  265. data/vendor/libgit2/src/transports/smart_pkt.c +43 -40
  266. data/vendor/libgit2/src/transports/smart_protocol.c +61 -57
  267. data/vendor/libgit2/src/transports/ssh.c +34 -33
  268. data/vendor/libgit2/src/transports/winhttp.c +99 -119
  269. data/vendor/libgit2/src/tree-cache.c +5 -5
  270. data/vendor/libgit2/src/tree.c +96 -121
  271. data/vendor/libgit2/src/tree.h +1 -12
  272. data/vendor/libgit2/src/unix/map.c +2 -2
  273. data/vendor/libgit2/src/util.c +22 -6
  274. data/vendor/libgit2/src/util.h +12 -135
  275. data/vendor/libgit2/src/vector.c +4 -4
  276. data/vendor/libgit2/src/win32/dir.c +3 -3
  277. data/vendor/libgit2/src/win32/findfile.c +3 -3
  278. data/vendor/libgit2/src/win32/map.c +6 -6
  279. data/vendor/libgit2/src/win32/msvc-compat.h +6 -0
  280. data/vendor/libgit2/src/win32/path_w32.c +101 -7
  281. data/vendor/libgit2/src/win32/path_w32.h +18 -0
  282. data/vendor/libgit2/src/win32/posix_w32.c +24 -43
  283. data/vendor/libgit2/src/win32/w32_buffer.c +2 -2
  284. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.c +96 -2
  285. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +28 -75
  286. data/vendor/libgit2/src/win32/w32_stack.c +2 -2
  287. data/vendor/libgit2/src/win32/w32_util.c +1 -69
  288. data/vendor/libgit2/src/win32/w32_util.h +1 -19
  289. data/vendor/libgit2/src/worktree.c +75 -54
  290. data/vendor/libgit2/src/worktree.h +2 -0
  291. data/vendor/libgit2/src/xdiff/xdiffi.c +7 -5
  292. data/vendor/libgit2/src/xdiff/xhistogram.c +1 -1
  293. data/vendor/libgit2/src/xdiff/xmerge.c +15 -15
  294. data/vendor/libgit2/src/zstream.c +4 -4
  295. metadata +33 -7
  296. data/vendor/libgit2/src/config_file.h +0 -73
  297. data/vendor/libgit2/src/streams/curl.c +0 -385
@@ -13,115 +13,11 @@
13
13
 
14
14
  extern int git_openssl_stream_global_init(void);
15
15
 
16
- extern int git_openssl_stream_new(git_stream **out, const char *host, const char *port);
17
-
18
- extern int git_openssl__set_cert_location(const char *file, const char *path);
19
-
20
- /*
21
- * OpenSSL 1.1 made BIO opaque so we have to use functions to interact with it
22
- * which do not exist in previous versions. We define these inline functions so
23
- * we can program against the interface instead of littering the implementation
24
- * with ifdefs.
25
- */
26
16
  #ifdef GIT_OPENSSL
27
- # include <openssl/ssl.h>
28
- # include <openssl/err.h>
29
- # include <openssl/x509v3.h>
30
- # include <openssl/bio.h>
31
-
32
-
33
-
34
- # if OPENSSL_VERSION_NUMBER < 0x10100000L || \
35
- (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L)
36
-
37
- GIT_INLINE(BIO_METHOD*) BIO_meth_new(int type, const char *name)
38
- {
39
- BIO_METHOD *meth = git__calloc(1, sizeof(BIO_METHOD));
40
- if (!meth) {
41
- return NULL;
42
- }
43
-
44
- meth->type = type;
45
- meth->name = name;
46
-
47
- return meth;
48
- }
49
-
50
- GIT_INLINE(void) BIO_meth_free(BIO_METHOD *biom)
51
- {
52
- git__free(biom);
53
- }
54
-
55
- GIT_INLINE(int) BIO_meth_set_write(BIO_METHOD *biom, int (*write) (BIO *, const char *, int))
56
- {
57
- biom->bwrite = write;
58
- return 1;
59
- }
60
-
61
- GIT_INLINE(int) BIO_meth_set_read(BIO_METHOD *biom, int (*read) (BIO *, char *, int))
62
- {
63
- biom->bread = read;
64
- return 1;
65
- }
66
-
67
- GIT_INLINE(int) BIO_meth_set_puts(BIO_METHOD *biom, int (*puts) (BIO *, const char *))
68
- {
69
- biom->bputs = puts;
70
- return 1;
71
- }
72
-
73
- GIT_INLINE(int) BIO_meth_set_gets(BIO_METHOD *biom, int (*gets) (BIO *, char *, int))
74
-
75
- {
76
- biom->bgets = gets;
77
- return 1;
78
- }
79
-
80
- GIT_INLINE(int) BIO_meth_set_ctrl(BIO_METHOD *biom, long (*ctrl) (BIO *, int, long, void *))
81
- {
82
- biom->ctrl = ctrl;
83
- return 1;
84
- }
85
-
86
- GIT_INLINE(int) BIO_meth_set_create(BIO_METHOD *biom, int (*create) (BIO *))
87
- {
88
- biom->create = create;
89
- return 1;
90
- }
91
-
92
- GIT_INLINE(int) BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *))
93
- {
94
- biom->destroy = destroy;
95
- return 1;
96
- }
97
-
98
- GIT_INLINE(int) BIO_get_new_index(void)
99
- {
100
- /* This exists as of 1.1 so before we'd just have 0 */
101
- return 0;
102
- }
103
-
104
- GIT_INLINE(void) BIO_set_init(BIO *b, int init)
105
- {
106
- b->init = init;
107
- }
108
-
109
- GIT_INLINE(void) BIO_set_data(BIO *a, void *ptr)
110
- {
111
- a->ptr = ptr;
112
- }
113
-
114
- GIT_INLINE(void*) BIO_get_data(BIO *a)
115
- {
116
- return a->ptr;
117
- }
118
-
119
- GIT_INLINE(const unsigned char *) ASN1_STRING_get0_data(const ASN1_STRING *x)
120
- {
121
- return ASN1_STRING_data((ASN1_STRING *)x);
122
- }
17
+ extern int git_openssl__set_cert_location(const char *file, const char *path);
123
18
 
124
- # endif // OpenSSL < 1.1
125
- #endif // GIT_OPENSSL
19
+ extern int git_openssl_stream_new(git_stream **out, const char *host, const char *port);
20
+ extern int git_openssl_stream_wrap(git_stream **out, git_stream *in, const char *host);
21
+ #endif
126
22
 
127
23
  #endif
@@ -0,0 +1,118 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+
8
+ #include "git2/errors.h"
9
+
10
+ #include "common.h"
11
+ #include "global.h"
12
+ #include "streams/tls.h"
13
+ #include "streams/mbedtls.h"
14
+ #include "streams/openssl.h"
15
+ #include "streams/stransport.h"
16
+
17
+ struct stream_registry {
18
+ git_rwlock lock;
19
+ git_stream_registration callbacks;
20
+ git_stream_registration tls_callbacks;
21
+ };
22
+
23
+ static struct stream_registry stream_registry;
24
+
25
+ static void shutdown_stream_registry(void)
26
+ {
27
+ git_rwlock_free(&stream_registry.lock);
28
+ }
29
+
30
+ int git_stream_registry_global_init(void)
31
+ {
32
+ if (git_rwlock_init(&stream_registry.lock) < 0)
33
+ return -1;
34
+
35
+ git__on_shutdown(shutdown_stream_registry);
36
+ return 0;
37
+ }
38
+
39
+ GIT_INLINE(void) stream_registration_cpy(
40
+ git_stream_registration *target,
41
+ git_stream_registration *src)
42
+ {
43
+ if (src)
44
+ memcpy(target, src, sizeof(git_stream_registration));
45
+ else
46
+ memset(target, 0, sizeof(git_stream_registration));
47
+ }
48
+
49
+ int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type)
50
+ {
51
+ git_stream_registration *target;
52
+ int error = GIT_ENOTFOUND;
53
+
54
+ assert(out);
55
+
56
+ switch(type) {
57
+ case GIT_STREAM_STANDARD:
58
+ target = &stream_registry.callbacks;
59
+ break;
60
+ case GIT_STREAM_TLS:
61
+ target = &stream_registry.tls_callbacks;
62
+ break;
63
+ default:
64
+ assert(0);
65
+ return -1;
66
+ }
67
+
68
+ if (git_rwlock_rdlock(&stream_registry.lock) < 0) {
69
+ git_error_set(GIT_ERROR_OS, "failed to lock stream registry");
70
+ return -1;
71
+ }
72
+
73
+ if (target->init) {
74
+ stream_registration_cpy(out, target);
75
+ error = 0;
76
+ }
77
+
78
+ git_rwlock_rdunlock(&stream_registry.lock);
79
+ return error;
80
+ }
81
+
82
+ int git_stream_register(git_stream_t type, git_stream_registration *registration)
83
+ {
84
+ assert(!registration || registration->init);
85
+
86
+ GIT_ERROR_CHECK_VERSION(registration, GIT_STREAM_VERSION, "stream_registration");
87
+
88
+ if (git_rwlock_wrlock(&stream_registry.lock) < 0) {
89
+ git_error_set(GIT_ERROR_OS, "failed to lock stream registry");
90
+ return -1;
91
+ }
92
+
93
+ if ((type & GIT_STREAM_STANDARD) == GIT_STREAM_STANDARD)
94
+ stream_registration_cpy(&stream_registry.callbacks, registration);
95
+
96
+ if ((type & GIT_STREAM_TLS) == GIT_STREAM_TLS)
97
+ stream_registration_cpy(&stream_registry.tls_callbacks, registration);
98
+
99
+ git_rwlock_wrunlock(&stream_registry.lock);
100
+ return 0;
101
+ }
102
+
103
+
104
+ int git_stream_register_tls(
105
+ int GIT_CALLBACK(ctor)(git_stream **out, const char *host, const char *port))
106
+ {
107
+ git_stream_registration registration = {0};
108
+
109
+ if (ctor) {
110
+ registration.version = GIT_STREAM_VERSION;
111
+ registration.init = ctor;
112
+ registration.wrap = NULL;
113
+
114
+ return git_stream_register(GIT_STREAM_TLS, &registration);
115
+ } else {
116
+ return git_stream_register(GIT_STREAM_TLS, NULL);
117
+ }
118
+ }
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
+ *
4
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
5
+ * a Linking Exception. For full terms see the included COPYING file.
6
+ */
7
+ #ifndef INCLUDE_streams_registry_h__
8
+ #define INCLUDE_streams_registry_h__
9
+
10
+ #include "common.h"
11
+ #include "git2/sys/stream.h"
12
+
13
+ /** Configure stream registry. */
14
+ int git_stream_registry_global_init(void);
15
+
16
+ /** Lookup a stream registration. */
17
+ extern int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type);
18
+
19
+ #endif
@@ -9,6 +9,7 @@
9
9
 
10
10
  #include "posix.h"
11
11
  #include "netops.h"
12
+ #include "registry.h"
12
13
  #include "stream.h"
13
14
 
14
15
  #ifndef _WIN32
@@ -34,16 +35,16 @@ static void net_set_error(const char *str)
34
35
  char * win32_error = git_win32_get_error_message(error);
35
36
 
36
37
  if (win32_error) {
37
- giterr_set(GITERR_NET, "%s: %s", str, win32_error);
38
+ git_error_set(GIT_ERROR_NET, "%s: %s", str, win32_error);
38
39
  git__free(win32_error);
39
40
  } else {
40
- giterr_set(GITERR_NET, str);
41
+ git_error_set(GIT_ERROR_NET, "%s", str);
41
42
  }
42
43
  }
43
44
  #else
44
45
  static void net_set_error(const char *str)
45
46
  {
46
- giterr_set(GITERR_NET, "%s: %s", str, strerror(errno));
47
+ git_error_set(GIT_ERROR_NET, "%s: %s", str, strerror(errno));
47
48
  }
48
49
  #endif
49
50
 
@@ -57,7 +58,7 @@ static int close_socket(GIT_SOCKET s)
57
58
  return -1;
58
59
 
59
60
  if (0 != WSACleanup()) {
60
- giterr_set(GITERR_OS, "winsock cleanup failed");
61
+ git_error_set(GIT_ERROR_OS, "winsock cleanup failed");
61
62
  return -1;
62
63
  }
63
64
 
@@ -68,7 +69,7 @@ static int close_socket(GIT_SOCKET s)
68
69
 
69
70
  }
70
71
 
71
- int socket_connect(git_stream *stream)
72
+ static int socket_connect(git_stream *stream)
72
73
  {
73
74
  struct addrinfo *info = NULL, *p;
74
75
  struct addrinfo hints;
@@ -82,13 +83,13 @@ int socket_connect(git_stream *stream)
82
83
  WSADATA wsd;
83
84
 
84
85
  if (WSAStartup(MAKEWORD(2,2), &wsd) != 0) {
85
- giterr_set(GITERR_OS, "winsock init failed");
86
+ git_error_set(GIT_ERROR_OS, "winsock init failed");
86
87
  return -1;
87
88
  }
88
89
 
89
90
  if (LOBYTE(wsd.wVersion) != 2 || HIBYTE(wsd.wVersion) != 2) {
90
91
  WSACleanup();
91
- giterr_set(GITERR_OS, "winsock init failed");
92
+ git_error_set(GIT_ERROR_OS, "winsock init failed");
92
93
  return -1;
93
94
  }
94
95
  #endif
@@ -98,7 +99,7 @@ int socket_connect(git_stream *stream)
98
99
  hints.ai_family = AF_UNSPEC;
99
100
 
100
101
  if ((ret = p_getaddrinfo(st->host, st->port, &hints, &info)) != 0) {
101
- giterr_set(GITERR_NET,
102
+ git_error_set(GIT_ERROR_NET,
102
103
  "failed to resolve address for %s: %s", st->host, p_gai_strerror(ret));
103
104
  return -1;
104
105
  }
@@ -119,7 +120,7 @@ int socket_connect(git_stream *stream)
119
120
 
120
121
  /* Oops, we couldn't connect to any address */
121
122
  if (s == INVALID_SOCKET && p == NULL) {
122
- giterr_set(GITERR_OS, "failed to connect to %s", st->host);
123
+ git_error_set(GIT_ERROR_OS, "failed to connect to %s", st->host);
123
124
  p_freeaddrinfo(info);
124
125
  return -1;
125
126
  }
@@ -129,27 +130,22 @@ int socket_connect(git_stream *stream)
129
130
  return 0;
130
131
  }
131
132
 
132
- ssize_t socket_write(git_stream *stream, const char *data, size_t len, int flags)
133
+ static ssize_t socket_write(git_stream *stream, const char *data, size_t len, int flags)
133
134
  {
134
- ssize_t ret;
135
- size_t off = 0;
136
135
  git_socket_stream *st = (git_socket_stream *) stream;
136
+ ssize_t written;
137
137
 
138
- while (off < len) {
139
- errno = 0;
140
- ret = p_send(st->s, data + off, len - off, flags);
141
- if (ret < 0) {
142
- net_set_error("Error sending data");
143
- return -1;
144
- }
138
+ errno = 0;
145
139
 
146
- off += ret;
140
+ if ((written = p_send(st->s, data, len, flags)) < 0) {
141
+ net_set_error("Error sending data");
142
+ return -1;
147
143
  }
148
144
 
149
- return off;
145
+ return written;
150
146
  }
151
147
 
152
- ssize_t socket_read(git_stream *stream, void *data, size_t len)
148
+ static ssize_t socket_read(git_stream *stream, void *data, size_t len)
153
149
  {
154
150
  ssize_t ret;
155
151
  git_socket_stream *st = (git_socket_stream *) stream;
@@ -160,7 +156,7 @@ ssize_t socket_read(git_stream *stream, void *data, size_t len)
160
156
  return ret;
161
157
  }
162
158
 
163
- int socket_close(git_stream *stream)
159
+ static int socket_close(git_stream *stream)
164
160
  {
165
161
  git_socket_stream *st = (git_socket_stream *) stream;
166
162
  int error;
@@ -171,7 +167,7 @@ int socket_close(git_stream *stream)
171
167
  return error;
172
168
  }
173
169
 
174
- void socket_free(git_stream *stream)
170
+ static void socket_free(git_stream *stream)
175
171
  {
176
172
  git_socket_stream *st = (git_socket_stream *) stream;
177
173
 
@@ -180,21 +176,24 @@ void socket_free(git_stream *stream)
180
176
  git__free(st);
181
177
  }
182
178
 
183
- int git_socket_stream_new(git_stream **out, const char *host, const char *port)
179
+ static int default_socket_stream_new(
180
+ git_stream **out,
181
+ const char *host,
182
+ const char *port)
184
183
  {
185
184
  git_socket_stream *st;
186
185
 
187
- assert(out && host);
186
+ assert(out && host && port);
188
187
 
189
188
  st = git__calloc(1, sizeof(git_socket_stream));
190
- GITERR_CHECK_ALLOC(st);
189
+ GIT_ERROR_CHECK_ALLOC(st);
191
190
 
192
191
  st->host = git__strdup(host);
193
- GITERR_CHECK_ALLOC(st->host);
192
+ GIT_ERROR_CHECK_ALLOC(st->host);
194
193
 
195
194
  if (port) {
196
195
  st->port = git__strdup(port);
197
- GITERR_CHECK_ALLOC(st->port);
196
+ GIT_ERROR_CHECK_ALLOC(st->port);
198
197
  }
199
198
 
200
199
  st->parent.version = GIT_STREAM_VERSION;
@@ -208,3 +207,29 @@ int git_socket_stream_new(git_stream **out, const char *host, const char *port)
208
207
  *out = (git_stream *) st;
209
208
  return 0;
210
209
  }
210
+
211
+ int git_socket_stream_new(
212
+ git_stream **out,
213
+ const char *host,
214
+ const char *port)
215
+ {
216
+ int (*init)(git_stream **, const char *, const char *) = NULL;
217
+ git_stream_registration custom = {0};
218
+ int error;
219
+
220
+ assert(out && host && port);
221
+
222
+ if ((error = git_stream_registry_lookup(&custom, GIT_STREAM_STANDARD)) == 0)
223
+ init = custom.init;
224
+ else if (error == GIT_ENOTFOUND)
225
+ init = default_socket_stream_new;
226
+ else
227
+ return error;
228
+
229
+ if (!init) {
230
+ git_error_set(GIT_ERROR_NET, "there is no socket stream available");
231
+ return -1;
232
+ }
233
+
234
+ return init(out, host, port);
235
+ }
@@ -16,26 +16,25 @@
16
16
  #include "git2/transport.h"
17
17
 
18
18
  #include "streams/socket.h"
19
- #include "streams/curl.h"
20
19
 
21
20
  static int stransport_error(OSStatus ret)
22
21
  {
23
22
  CFStringRef message;
24
23
 
25
24
  if (ret == noErr || ret == errSSLClosedGraceful) {
26
- giterr_clear();
25
+ git_error_clear();
27
26
  return 0;
28
27
  }
29
28
 
30
29
  #if !TARGET_OS_IPHONE
31
30
  message = SecCopyErrorMessageString(ret, NULL);
32
- GITERR_CHECK_ALLOC(message);
31
+ GIT_ERROR_CHECK_ALLOC(message);
33
32
 
34
- giterr_set(GITERR_NET, "SecureTransport error: %s", CFStringGetCStringPtr(message, kCFStringEncodingUTF8));
33
+ git_error_set(GIT_ERROR_NET, "SecureTransport error: %s", CFStringGetCStringPtr(message, kCFStringEncodingUTF8));
35
34
  CFRelease(message);
36
35
  #else
37
- giterr_set(GITERR_NET, "SecureTransport error: OSStatus %d", (unsigned int)ret);
38
- GIT_UNUSED(message);
36
+ git_error_set(GIT_ERROR_NET, "SecureTransport error: OSStatus %d", (unsigned int)ret);
37
+ GIT_UNUSED(message);
39
38
  #endif
40
39
 
41
40
  return -1;
@@ -44,6 +43,7 @@ static int stransport_error(OSStatus ret)
44
43
  typedef struct {
45
44
  git_stream parent;
46
45
  git_stream *io;
46
+ int owned;
47
47
  SSLContextRef ctx;
48
48
  CFDataRef der_data;
49
49
  git_cert_x509 cert_info;
@@ -57,12 +57,12 @@ static int stransport_connect(git_stream *stream)
57
57
  SecTrustResultType sec_res;
58
58
  OSStatus ret;
59
59
 
60
- if ((error = git_stream_connect(st->io)) < 0)
60
+ if (st->owned && (error = git_stream_connect(st->io)) < 0)
61
61
  return error;
62
62
 
63
63
  ret = SSLHandshake(st->ctx);
64
64
  if (ret != errSSLServerAuthCompleted) {
65
- giterr_set(GITERR_SSL, "unexpected return value from ssl handshake %d", ret);
65
+ git_error_set(GIT_ERROR_SSL, "unexpected return value from ssl handshake %d", (int)ret);
66
66
  return -1;
67
67
  }
68
68
 
@@ -78,13 +78,13 @@ static int stransport_connect(git_stream *stream)
78
78
  CFRelease(trust);
79
79
 
80
80
  if (sec_res == kSecTrustResultInvalid || sec_res == kSecTrustResultOtherError) {
81
- giterr_set(GITERR_SSL, "internal security trust error");
81
+ git_error_set(GIT_ERROR_SSL, "internal security trust error");
82
82
  return -1;
83
83
  }
84
84
 
85
85
  if (sec_res == kSecTrustResultDeny || sec_res == kSecTrustResultRecoverableTrustFailure ||
86
86
  sec_res == kSecTrustResultFatalTrustFailure) {
87
- giterr_set(GITERR_SSL, "untrusted connection error");
87
+ git_error_set(GIT_ERROR_SSL, "untrusted connection error");
88
88
  return GIT_ECERTIFICATE;
89
89
  }
90
90
 
@@ -112,7 +112,7 @@ static int stransport_certificate(git_cert **out, git_stream *stream)
112
112
  CFRelease(trust);
113
113
 
114
114
  if (st->der_data == NULL) {
115
- giterr_set(GITERR_SSL, "retrieved invalid certificate data");
115
+ git_error_set(GIT_ERROR_SSL, "retrieved invalid certificate data");
116
116
  return -1;
117
117
  }
118
118
 
@@ -149,9 +149,8 @@ static OSStatus write_cb(SSLConnectionRef conn, const void *data, size_t *len)
149
149
  {
150
150
  git_stream *io = (git_stream *) conn;
151
151
 
152
- if (git_stream_write(io, data, *len, 0) < 0) {
152
+ if (git_stream__write_full(io, data, *len, 0) < 0)
153
153
  return -36; /* "ioErr" from MacErrors.h which is not available on iOS */
154
- }
155
154
 
156
155
  return noErr;
157
156
  }
@@ -164,11 +163,12 @@ static ssize_t stransport_write(git_stream *stream, const char *data, size_t len
164
163
 
165
164
  GIT_UNUSED(flags);
166
165
 
167
- data_len = len;
166
+ data_len = min(len, SSIZE_MAX);
168
167
  if ((ret = SSLWrite(st->ctx, data, data_len, &processed)) != noErr)
169
168
  return stransport_error(ret);
170
169
 
171
- return processed;
170
+ assert(processed < SSIZE_MAX);
171
+ return (ssize_t)processed;
172
172
  }
173
173
 
174
174
  /*
@@ -226,45 +226,42 @@ static int stransport_close(git_stream *stream)
226
226
  if (ret != noErr && ret != errSSLClosedGraceful)
227
227
  return stransport_error(ret);
228
228
 
229
- return git_stream_close(st->io);
229
+ return st->owned ? git_stream_close(st->io) : 0;
230
230
  }
231
231
 
232
232
  static void stransport_free(git_stream *stream)
233
233
  {
234
234
  stransport_stream *st = (stransport_stream *) stream;
235
235
 
236
- git_stream_free(st->io);
236
+ if (st->owned)
237
+ git_stream_free(st->io);
238
+
237
239
  CFRelease(st->ctx);
238
240
  if (st->der_data)
239
241
  CFRelease(st->der_data);
240
242
  git__free(st);
241
243
  }
242
244
 
243
- int git_stransport_stream_new(git_stream **out, const char *host, const char *port)
245
+ static int stransport_wrap(
246
+ git_stream **out,
247
+ git_stream *in,
248
+ const char *host,
249
+ int owned)
244
250
  {
245
251
  stransport_stream *st;
246
- int error;
247
252
  OSStatus ret;
248
253
 
249
- assert(out && host);
254
+ assert(out && in && host);
250
255
 
251
256
  st = git__calloc(1, sizeof(stransport_stream));
252
- GITERR_CHECK_ALLOC(st);
253
-
254
- #ifdef GIT_CURL
255
- error = git_curl_stream_new(&st->io, host, port);
256
- #else
257
- error = git_socket_stream_new(&st->io, host, port);
258
- #endif
257
+ GIT_ERROR_CHECK_ALLOC(st);
259
258
 
260
- if (error < 0){
261
- git__free(st);
262
- return error;
263
- }
259
+ st->io = in;
260
+ st->owned = owned;
264
261
 
265
262
  st->ctx = SSLCreateContext(NULL, kSSLClientSide, kSSLStreamType);
266
263
  if (!st->ctx) {
267
- giterr_set(GITERR_NET, "failed to create SSL context");
264
+ git_error_set(GIT_ERROR_NET, "failed to create SSL context");
268
265
  git__free(st);
269
266
  return -1;
270
267
  }
@@ -295,4 +292,32 @@ int git_stransport_stream_new(git_stream **out, const char *host, const char *po
295
292
  return 0;
296
293
  }
297
294
 
295
+ int git_stransport_stream_wrap(
296
+ git_stream **out,
297
+ git_stream *in,
298
+ const char *host)
299
+ {
300
+ return stransport_wrap(out, in, host, 0);
301
+ }
302
+
303
+ int git_stransport_stream_new(git_stream **out, const char *host, const char *port)
304
+ {
305
+ git_stream *stream = NULL;
306
+ int error;
307
+
308
+ assert(out && host);
309
+
310
+ error = git_socket_stream_new(&stream, host, port);
311
+
312
+ if (!error)
313
+ error = stransport_wrap(out, stream, host, 1);
314
+
315
+ if (error < 0 && stream) {
316
+ git_stream_close(stream);
317
+ git_stream_free(stream);
318
+ }
319
+
320
+ return error;
321
+ }
322
+
298
323
  #endif