rugged 0.27.7 → 0.27.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (409) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rugged/version.rb +1 -1
  3. data/vendor/libgit2/AUTHORS +1 -0
  4. data/vendor/libgit2/CMakeLists.txt +99 -51
  5. data/vendor/libgit2/COPYING +28 -0
  6. data/vendor/libgit2/cmake/Modules/AddCFlagIfSupported.cmake +15 -1
  7. data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.c.in +29 -0
  8. data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.cmake +96 -0
  9. data/vendor/libgit2/cmake/Modules/EnableWarnings.cmake +9 -8
  10. data/vendor/libgit2/cmake/Modules/FindCoreFoundation.cmake +2 -2
  11. data/vendor/libgit2/cmake/Modules/FindGSSAPI.cmake +1 -1
  12. data/vendor/libgit2/cmake/Modules/FindGSSFramework.cmake +28 -0
  13. data/vendor/libgit2/cmake/Modules/FindIconv.cmake +11 -6
  14. data/vendor/libgit2/cmake/Modules/FindPCRE.cmake +38 -0
  15. data/vendor/libgit2/cmake/Modules/FindPCRE2.cmake +37 -0
  16. data/vendor/libgit2/cmake/Modules/FindSecurity.cmake +2 -2
  17. data/vendor/libgit2/cmake/Modules/FindStatNsec.cmake +6 -0
  18. data/vendor/libgit2/cmake/Modules/PkgBuildConfig.cmake +110 -0
  19. data/vendor/libgit2/cmake/Modules/SelectGSSAPI.cmake +53 -0
  20. data/vendor/libgit2/cmake/Modules/SelectHTTPSBackend.cmake +124 -0
  21. data/vendor/libgit2/cmake/Modules/SelectHashes.cmake +66 -0
  22. data/vendor/libgit2/deps/http-parser/http_parser.c +11 -6
  23. data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +21 -0
  24. data/vendor/libgit2/deps/ntlmclient/compat.h +33 -0
  25. data/vendor/libgit2/deps/ntlmclient/crypt.h +64 -0
  26. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.c +120 -0
  27. data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.h +18 -0
  28. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.c +145 -0
  29. data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.h +18 -0
  30. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +130 -0
  31. data/vendor/libgit2/deps/ntlmclient/crypt_openssl.h +21 -0
  32. data/vendor/libgit2/deps/ntlmclient/ntlm.c +1420 -0
  33. data/vendor/libgit2/deps/ntlmclient/ntlm.h +174 -0
  34. data/vendor/libgit2/deps/ntlmclient/ntlmclient.h +320 -0
  35. data/vendor/libgit2/deps/ntlmclient/unicode.h +36 -0
  36. data/vendor/libgit2/deps/ntlmclient/unicode_builtin.c +445 -0
  37. data/vendor/libgit2/deps/ntlmclient/unicode_iconv.c +201 -0
  38. data/vendor/libgit2/deps/ntlmclient/utf8.h +1257 -0
  39. data/vendor/libgit2/deps/ntlmclient/util.c +21 -0
  40. data/vendor/libgit2/deps/ntlmclient/util.h +14 -0
  41. data/vendor/libgit2/deps/pcre/CMakeLists.txt +140 -0
  42. data/vendor/libgit2/deps/pcre/COPYING +5 -0
  43. data/vendor/libgit2/deps/pcre/cmake/COPYING-CMAKE-SCRIPTS +22 -0
  44. data/vendor/libgit2/deps/pcre/cmake/FindEditline.cmake +17 -0
  45. data/vendor/libgit2/deps/pcre/cmake/FindPackageHandleStandardArgs.cmake +58 -0
  46. data/vendor/libgit2/deps/pcre/cmake/FindReadline.cmake +29 -0
  47. data/vendor/libgit2/deps/pcre/config.h.in +57 -0
  48. data/vendor/libgit2/deps/pcre/pcre.h +641 -0
  49. data/vendor/libgit2/deps/pcre/pcre_byte_order.c +319 -0
  50. data/vendor/libgit2/deps/pcre/pcre_chartables.c +198 -0
  51. data/vendor/libgit2/deps/pcre/pcre_compile.c +9800 -0
  52. data/vendor/libgit2/deps/pcre/pcre_config.c +190 -0
  53. data/vendor/libgit2/deps/pcre/pcre_dfa_exec.c +3676 -0
  54. data/vendor/libgit2/deps/pcre/pcre_exec.c +7173 -0
  55. data/vendor/libgit2/deps/pcre/pcre_fullinfo.c +245 -0
  56. data/vendor/libgit2/deps/pcre/pcre_get.c +669 -0
  57. data/vendor/libgit2/deps/pcre/pcre_globals.c +86 -0
  58. data/vendor/libgit2/deps/pcre/pcre_internal.h +2787 -0
  59. data/vendor/libgit2/deps/pcre/pcre_jit_compile.c +11913 -0
  60. data/vendor/libgit2/deps/pcre/pcre_maketables.c +156 -0
  61. data/vendor/libgit2/deps/pcre/pcre_newline.c +210 -0
  62. data/vendor/libgit2/deps/pcre/pcre_ord2utf8.c +94 -0
  63. data/vendor/libgit2/deps/pcre/pcre_printint.c +834 -0
  64. data/vendor/libgit2/deps/pcre/pcre_refcount.c +92 -0
  65. data/vendor/libgit2/deps/pcre/pcre_string_utils.c +211 -0
  66. data/vendor/libgit2/deps/pcre/pcre_study.c +1686 -0
  67. data/vendor/libgit2/deps/pcre/pcre_tables.c +727 -0
  68. data/vendor/libgit2/deps/pcre/pcre_ucd.c +3644 -0
  69. data/vendor/libgit2/deps/pcre/pcre_valid_utf8.c +301 -0
  70. data/vendor/libgit2/deps/pcre/pcre_version.c +98 -0
  71. data/vendor/libgit2/deps/pcre/pcre_xclass.c +268 -0
  72. data/vendor/libgit2/deps/pcre/pcreposix.c +421 -0
  73. data/vendor/libgit2/deps/pcre/pcreposix.h +117 -0
  74. data/vendor/libgit2/deps/pcre/ucp.h +224 -0
  75. data/vendor/libgit2/deps/winhttp/COPYING.GPL +993 -0
  76. data/vendor/libgit2/deps/winhttp/COPYING.LGPL +502 -0
  77. data/vendor/libgit2/deps/zlib/CMakeLists.txt +1 -0
  78. data/vendor/libgit2/deps/zlib/COPYING +27 -0
  79. data/vendor/libgit2/deps/zlib/adler32.c +0 -7
  80. data/vendor/libgit2/deps/zlib/crc32.c +0 -7
  81. data/vendor/libgit2/include/git2/annotated_commit.h +9 -0
  82. data/vendor/libgit2/include/git2/apply.h +149 -0
  83. data/vendor/libgit2/include/git2/attr.h +20 -13
  84. data/vendor/libgit2/include/git2/blame.h +4 -4
  85. data/vendor/libgit2/include/git2/blob.h +44 -12
  86. data/vendor/libgit2/include/git2/buffer.h +20 -26
  87. data/vendor/libgit2/include/git2/cert.h +135 -0
  88. data/vendor/libgit2/include/git2/checkout.h +53 -21
  89. data/vendor/libgit2/include/git2/cherrypick.h +3 -3
  90. data/vendor/libgit2/include/git2/clone.h +5 -5
  91. data/vendor/libgit2/include/git2/commit.h +25 -3
  92. data/vendor/libgit2/include/git2/common.h +35 -10
  93. data/vendor/libgit2/include/git2/config.h +29 -19
  94. data/vendor/libgit2/include/git2/cred.h +308 -0
  95. data/vendor/libgit2/include/git2/deprecated.h +493 -0
  96. data/vendor/libgit2/include/git2/describe.h +4 -4
  97. data/vendor/libgit2/include/git2/diff.h +177 -135
  98. data/vendor/libgit2/include/git2/errors.h +53 -46
  99. data/vendor/libgit2/include/git2/filter.h +8 -0
  100. data/vendor/libgit2/include/git2/index.h +74 -52
  101. data/vendor/libgit2/include/git2/indexer.h +76 -6
  102. data/vendor/libgit2/include/git2/merge.h +25 -10
  103. data/vendor/libgit2/include/git2/net.h +0 -5
  104. data/vendor/libgit2/include/git2/notes.h +1 -1
  105. data/vendor/libgit2/include/git2/object.h +17 -29
  106. data/vendor/libgit2/include/git2/odb.h +12 -11
  107. data/vendor/libgit2/include/git2/odb_backend.h +10 -9
  108. data/vendor/libgit2/include/git2/oid.h +2 -2
  109. data/vendor/libgit2/include/git2/pack.h +14 -3
  110. data/vendor/libgit2/include/git2/proxy.h +5 -3
  111. data/vendor/libgit2/include/git2/rebase.h +46 -2
  112. data/vendor/libgit2/include/git2/refs.h +34 -16
  113. data/vendor/libgit2/include/git2/remote.h +111 -14
  114. data/vendor/libgit2/include/git2/repository.h +69 -34
  115. data/vendor/libgit2/include/git2/revert.h +1 -1
  116. data/vendor/libgit2/include/git2/revwalk.h +7 -7
  117. data/vendor/libgit2/include/git2/signature.h +2 -2
  118. data/vendor/libgit2/include/git2/stash.h +5 -5
  119. data/vendor/libgit2/include/git2/status.h +26 -17
  120. data/vendor/libgit2/include/git2/submodule.h +23 -6
  121. data/vendor/libgit2/include/git2/sys/alloc.h +18 -18
  122. data/vendor/libgit2/include/git2/sys/commit.h +1 -1
  123. data/vendor/libgit2/include/git2/sys/config.h +13 -13
  124. data/vendor/libgit2/include/git2/sys/cred.h +90 -0
  125. data/vendor/libgit2/include/git2/sys/filter.h +6 -6
  126. data/vendor/libgit2/include/git2/sys/merge.h +3 -3
  127. data/vendor/libgit2/include/git2/sys/odb_backend.h +66 -22
  128. data/vendor/libgit2/include/git2/sys/path.h +14 -5
  129. data/vendor/libgit2/include/git2/sys/refdb_backend.h +76 -40
  130. data/vendor/libgit2/include/git2/sys/repository.h +5 -1
  131. data/vendor/libgit2/include/git2/sys/stream.h +92 -12
  132. data/vendor/libgit2/include/git2/sys/transport.h +129 -83
  133. data/vendor/libgit2/include/git2/tag.h +13 -4
  134. data/vendor/libgit2/include/git2/trace.h +2 -2
  135. data/vendor/libgit2/include/git2/transport.h +11 -311
  136. data/vendor/libgit2/include/git2/tree.h +4 -4
  137. data/vendor/libgit2/include/git2/types.h +25 -106
  138. data/vendor/libgit2/include/git2/version.h +3 -3
  139. data/vendor/libgit2/include/git2/worktree.h +5 -5
  140. data/vendor/libgit2/include/git2.h +4 -0
  141. data/vendor/libgit2/src/CMakeLists.txt +104 -235
  142. data/vendor/libgit2/src/alloc.c +14 -18
  143. data/vendor/libgit2/src/{stdalloc.c → allocators/stdalloc.c} +7 -8
  144. data/vendor/libgit2/src/{stdalloc.h → allocators/stdalloc.h} +4 -4
  145. data/vendor/libgit2/src/allocators/win32_crtdbg.c +118 -0
  146. data/vendor/libgit2/src/{transports/cred.h → allocators/win32_crtdbg.h} +5 -4
  147. data/vendor/libgit2/src/annotated_commit.c +18 -11
  148. data/vendor/libgit2/src/apply.c +535 -28
  149. data/vendor/libgit2/src/apply.h +3 -1
  150. data/vendor/libgit2/src/array.h +2 -2
  151. data/vendor/libgit2/src/attr.c +77 -71
  152. data/vendor/libgit2/src/attr_file.c +203 -117
  153. data/vendor/libgit2/src/attr_file.h +9 -9
  154. data/vendor/libgit2/src/attrcache.c +49 -51
  155. data/vendor/libgit2/src/attrcache.h +2 -1
  156. data/vendor/libgit2/src/blame.c +38 -18
  157. data/vendor/libgit2/src/blame.h +1 -1
  158. data/vendor/libgit2/src/blame_git.c +29 -15
  159. data/vendor/libgit2/src/blob.c +123 -37
  160. data/vendor/libgit2/src/blob.h +19 -2
  161. data/vendor/libgit2/src/branch.c +47 -23
  162. data/vendor/libgit2/src/buf_text.c +7 -6
  163. data/vendor/libgit2/src/buffer.c +60 -53
  164. data/vendor/libgit2/src/cache.c +38 -45
  165. data/vendor/libgit2/src/cache.h +3 -3
  166. data/vendor/libgit2/src/cc-compat.h +20 -3
  167. data/vendor/libgit2/src/checkout.c +77 -67
  168. data/vendor/libgit2/src/cherrypick.c +12 -6
  169. data/vendor/libgit2/src/clone.c +36 -14
  170. data/vendor/libgit2/src/clone.h +4 -0
  171. data/vendor/libgit2/src/commit.c +103 -48
  172. data/vendor/libgit2/src/commit.h +7 -0
  173. data/vendor/libgit2/src/commit_list.c +36 -78
  174. data/vendor/libgit2/src/commit_list.h +2 -2
  175. data/vendor/libgit2/src/common.h +24 -90
  176. data/vendor/libgit2/src/config.c +203 -176
  177. data/vendor/libgit2/src/config.h +8 -20
  178. data/vendor/libgit2/src/config_backend.h +96 -0
  179. data/vendor/libgit2/src/config_cache.c +41 -35
  180. data/vendor/libgit2/src/config_entries.c +229 -0
  181. data/vendor/libgit2/src/config_entries.h +24 -0
  182. data/vendor/libgit2/src/config_file.c +422 -680
  183. data/vendor/libgit2/src/config_mem.c +220 -0
  184. data/vendor/libgit2/src/config_parse.c +96 -68
  185. data/vendor/libgit2/src/config_parse.h +15 -14
  186. data/vendor/libgit2/src/config_snapshot.c +206 -0
  187. data/vendor/libgit2/src/crlf.c +219 -196
  188. data/vendor/libgit2/src/delta.c +25 -18
  189. data/vendor/libgit2/src/describe.c +42 -41
  190. data/vendor/libgit2/src/diff.c +52 -67
  191. data/vendor/libgit2/src/diff.h +2 -1
  192. data/vendor/libgit2/src/diff_driver.c +44 -46
  193. data/vendor/libgit2/src/diff_file.c +16 -14
  194. data/vendor/libgit2/src/diff_file.h +1 -1
  195. data/vendor/libgit2/src/diff_generate.c +158 -103
  196. data/vendor/libgit2/src/diff_generate.h +3 -3
  197. data/vendor/libgit2/src/diff_parse.c +4 -4
  198. data/vendor/libgit2/src/diff_print.c +34 -22
  199. data/vendor/libgit2/src/diff_stats.c +22 -7
  200. data/vendor/libgit2/src/diff_tform.c +18 -16
  201. data/vendor/libgit2/src/diff_xdiff.c +3 -3
  202. data/vendor/libgit2/src/errors.c +51 -39
  203. data/vendor/libgit2/src/errors.h +81 -0
  204. data/vendor/libgit2/src/features.h.in +9 -3
  205. data/vendor/libgit2/src/fetch.c +8 -3
  206. data/vendor/libgit2/src/fetchhead.c +12 -12
  207. data/vendor/libgit2/src/filebuf.c +28 -32
  208. data/vendor/libgit2/src/filebuf.h +2 -2
  209. data/vendor/libgit2/src/filter.c +47 -33
  210. data/vendor/libgit2/src/filter.h +0 -10
  211. data/vendor/libgit2/src/{fileops.c → futils.c} +70 -63
  212. data/vendor/libgit2/src/{fileops.h → futils.h} +6 -6
  213. data/vendor/libgit2/src/global.c +35 -55
  214. data/vendor/libgit2/src/global.h +0 -2
  215. data/vendor/libgit2/src/hash/sha1/collisiondetect.c +48 -0
  216. data/vendor/libgit2/src/hash/sha1/collisiondetect.h +19 -0
  217. data/vendor/libgit2/src/hash/{hash_common_crypto.h → sha1/common_crypto.c} +17 -17
  218. data/vendor/libgit2/src/hash/sha1/common_crypto.h +19 -0
  219. data/vendor/libgit2/src/hash/{hash_generic.c → sha1/generic.c} +22 -10
  220. data/vendor/libgit2/src/hash/{hash_generic.h → sha1/generic.h} +4 -10
  221. data/vendor/libgit2/src/hash/{hash_mbedtls.c → sha1/mbedtls.c} +15 -7
  222. data/vendor/libgit2/src/hash/{hash_mbedtls.h → sha1/mbedtls.h} +6 -7
  223. data/vendor/libgit2/src/hash/sha1/openssl.c +59 -0
  224. data/vendor/libgit2/src/hash/sha1/openssl.h +19 -0
  225. data/vendor/libgit2/src/hash/{sha1dc → sha1/sha1dc}/sha1.c +14 -3
  226. data/vendor/libgit2/src/hash/{hash_win32.c → sha1/win32.c} +47 -37
  227. data/vendor/libgit2/src/hash/{hash_win32.h → sha1/win32.h} +6 -19
  228. data/vendor/libgit2/src/hash/sha1.h +38 -0
  229. data/vendor/libgit2/src/hash.c +61 -0
  230. data/vendor/libgit2/src/hash.h +20 -21
  231. data/vendor/libgit2/src/hashsig.c +5 -5
  232. data/vendor/libgit2/src/idxmap.c +107 -61
  233. data/vendor/libgit2/src/idxmap.h +153 -31
  234. data/vendor/libgit2/src/ignore.c +38 -42
  235. data/vendor/libgit2/src/index.c +264 -199
  236. data/vendor/libgit2/src/index.h +7 -1
  237. data/vendor/libgit2/src/indexer.c +338 -167
  238. data/vendor/libgit2/src/integer.h +71 -26
  239. data/vendor/libgit2/src/iterator.c +134 -62
  240. data/vendor/libgit2/src/iterator.h +15 -0
  241. data/vendor/libgit2/src/mailmap.c +8 -8
  242. data/vendor/libgit2/src/map.h +1 -1
  243. data/vendor/libgit2/src/merge.c +137 -93
  244. data/vendor/libgit2/src/merge_driver.c +11 -11
  245. data/vendor/libgit2/src/merge_file.c +2 -2
  246. data/vendor/libgit2/src/mwindow.c +24 -29
  247. data/vendor/libgit2/src/mwindow.h +4 -4
  248. data/vendor/libgit2/src/net.c +184 -0
  249. data/vendor/libgit2/src/net.h +36 -0
  250. data/vendor/libgit2/src/netops.c +55 -156
  251. data/vendor/libgit2/src/netops.h +3 -23
  252. data/vendor/libgit2/src/notes.c +14 -9
  253. data/vendor/libgit2/src/object.c +120 -69
  254. data/vendor/libgit2/src/object.h +22 -9
  255. data/vendor/libgit2/src/object_api.c +8 -8
  256. data/vendor/libgit2/src/odb.c +111 -88
  257. data/vendor/libgit2/src/odb.h +8 -7
  258. data/vendor/libgit2/src/odb_loose.c +58 -47
  259. data/vendor/libgit2/src/odb_mempack.c +21 -34
  260. data/vendor/libgit2/src/odb_pack.c +17 -13
  261. data/vendor/libgit2/src/offmap.c +53 -35
  262. data/vendor/libgit2/src/offmap.h +108 -21
  263. data/vendor/libgit2/src/oid.c +12 -7
  264. data/vendor/libgit2/src/oidmap.c +49 -47
  265. data/vendor/libgit2/src/oidmap.h +101 -24
  266. data/vendor/libgit2/src/pack-objects.c +87 -86
  267. data/vendor/libgit2/src/pack-objects.h +2 -8
  268. data/vendor/libgit2/src/pack.c +94 -96
  269. data/vendor/libgit2/src/pack.h +16 -18
  270. data/vendor/libgit2/src/parse.c +17 -4
  271. data/vendor/libgit2/src/parse.h +3 -3
  272. data/vendor/libgit2/src/patch.c +3 -3
  273. data/vendor/libgit2/src/patch_generate.c +18 -18
  274. data/vendor/libgit2/src/patch_parse.c +147 -79
  275. data/vendor/libgit2/src/path.c +207 -62
  276. data/vendor/libgit2/src/path.h +14 -0
  277. data/vendor/libgit2/src/pathspec.c +18 -18
  278. data/vendor/libgit2/src/pool.c +26 -22
  279. data/vendor/libgit2/src/pool.h +7 -7
  280. data/vendor/libgit2/src/posix.c +10 -10
  281. data/vendor/libgit2/src/posix.h +12 -1
  282. data/vendor/libgit2/src/proxy.c +8 -3
  283. data/vendor/libgit2/src/push.c +35 -29
  284. data/vendor/libgit2/src/push.h +2 -1
  285. data/vendor/libgit2/src/reader.c +265 -0
  286. data/vendor/libgit2/src/reader.h +107 -0
  287. data/vendor/libgit2/src/rebase.c +97 -38
  288. data/vendor/libgit2/src/refdb.c +15 -3
  289. data/vendor/libgit2/src/refdb_fs.c +318 -222
  290. data/vendor/libgit2/src/reflog.c +13 -15
  291. data/vendor/libgit2/src/refs.c +122 -89
  292. data/vendor/libgit2/src/refs.h +5 -3
  293. data/vendor/libgit2/src/refspec.c +27 -33
  294. data/vendor/libgit2/src/regexp.c +221 -0
  295. data/vendor/libgit2/src/regexp.h +97 -0
  296. data/vendor/libgit2/src/remote.c +229 -178
  297. data/vendor/libgit2/src/remote.h +11 -2
  298. data/vendor/libgit2/src/repository.c +227 -172
  299. data/vendor/libgit2/src/repository.h +52 -40
  300. data/vendor/libgit2/src/reset.c +7 -7
  301. data/vendor/libgit2/src/revert.c +11 -6
  302. data/vendor/libgit2/src/revparse.c +46 -46
  303. data/vendor/libgit2/src/revwalk.c +89 -54
  304. data/vendor/libgit2/src/revwalk.h +20 -0
  305. data/vendor/libgit2/src/settings.c +22 -9
  306. data/vendor/libgit2/src/signature.c +15 -13
  307. data/vendor/libgit2/src/sortedcache.c +22 -36
  308. data/vendor/libgit2/src/sortedcache.h +1 -1
  309. data/vendor/libgit2/src/stash.c +56 -76
  310. data/vendor/libgit2/src/status.c +27 -21
  311. data/vendor/libgit2/src/stream.h +17 -2
  312. data/vendor/libgit2/src/streams/mbedtls.c +100 -80
  313. data/vendor/libgit2/src/streams/mbedtls.h +5 -2
  314. data/vendor/libgit2/src/streams/openssl.c +93 -81
  315. data/vendor/libgit2/src/streams/openssl.h +5 -2
  316. data/vendor/libgit2/src/streams/registry.c +118 -0
  317. data/vendor/libgit2/src/streams/registry.h +19 -0
  318. data/vendor/libgit2/src/streams/socket.c +55 -30
  319. data/vendor/libgit2/src/streams/stransport.c +57 -32
  320. data/vendor/libgit2/src/streams/stransport.h +5 -0
  321. data/vendor/libgit2/src/streams/tls.c +48 -20
  322. data/vendor/libgit2/src/streams/tls.h +12 -4
  323. data/vendor/libgit2/src/strmap.c +47 -74
  324. data/vendor/libgit2/src/strmap.h +108 -33
  325. data/vendor/libgit2/src/submodule.c +190 -169
  326. data/vendor/libgit2/src/submodule.h +1 -1
  327. data/vendor/libgit2/src/sysdir.c +25 -15
  328. data/vendor/libgit2/src/tag.c +39 -26
  329. data/vendor/libgit2/src/tag.h +2 -1
  330. data/vendor/libgit2/src/trace.c +2 -2
  331. data/vendor/libgit2/src/trace.h +2 -2
  332. data/vendor/libgit2/src/trailer.c +46 -32
  333. data/vendor/libgit2/src/transaction.c +30 -29
  334. data/vendor/libgit2/src/transport.c +3 -3
  335. data/vendor/libgit2/src/transports/auth.c +14 -10
  336. data/vendor/libgit2/src/transports/auth.h +10 -3
  337. data/vendor/libgit2/src/transports/auth_negotiate.c +31 -16
  338. data/vendor/libgit2/src/transports/auth_negotiate.h +2 -2
  339. data/vendor/libgit2/src/transports/auth_ntlm.c +223 -0
  340. data/vendor/libgit2/src/transports/auth_ntlm.h +35 -0
  341. data/vendor/libgit2/src/transports/cred.c +24 -24
  342. data/vendor/libgit2/src/transports/git.c +25 -30
  343. data/vendor/libgit2/src/transports/http.c +871 -335
  344. data/vendor/libgit2/src/transports/http.h +2 -0
  345. data/vendor/libgit2/src/transports/local.c +28 -28
  346. data/vendor/libgit2/src/transports/smart.c +64 -46
  347. data/vendor/libgit2/src/transports/smart.h +5 -6
  348. data/vendor/libgit2/src/transports/smart_pkt.c +162 -151
  349. data/vendor/libgit2/src/transports/smart_protocol.c +64 -94
  350. data/vendor/libgit2/src/transports/ssh.c +76 -65
  351. data/vendor/libgit2/src/transports/winhttp.c +328 -319
  352. data/vendor/libgit2/src/tree-cache.c +21 -14
  353. data/vendor/libgit2/src/tree.c +119 -112
  354. data/vendor/libgit2/src/tree.h +1 -0
  355. data/vendor/libgit2/src/unix/map.c +3 -3
  356. data/vendor/libgit2/src/unix/posix.h +1 -11
  357. data/vendor/libgit2/src/userdiff.h +3 -1
  358. data/vendor/libgit2/src/util.c +154 -93
  359. data/vendor/libgit2/src/util.h +19 -23
  360. data/vendor/libgit2/src/vector.c +15 -10
  361. data/vendor/libgit2/src/wildmatch.c +320 -0
  362. data/vendor/libgit2/src/wildmatch.h +23 -0
  363. data/vendor/libgit2/src/win32/dir.c +3 -3
  364. data/vendor/libgit2/src/win32/findfile.c +1 -1
  365. data/vendor/libgit2/src/win32/map.c +9 -11
  366. data/vendor/libgit2/src/win32/msvc-compat.h +6 -0
  367. data/vendor/libgit2/src/win32/path_w32.c +113 -9
  368. data/vendor/libgit2/src/win32/path_w32.h +18 -29
  369. data/vendor/libgit2/src/win32/posix.h +1 -4
  370. data/vendor/libgit2/src/win32/posix_w32.c +69 -44
  371. data/vendor/libgit2/src/win32/precompiled.h +0 -2
  372. data/vendor/libgit2/src/win32/thread.c +5 -10
  373. data/vendor/libgit2/src/win32/w32_buffer.c +9 -5
  374. data/vendor/libgit2/src/win32/w32_common.h +39 -0
  375. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.c +2 -95
  376. data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +0 -2
  377. data/vendor/libgit2/src/win32/w32_stack.c +6 -11
  378. data/vendor/libgit2/src/win32/w32_stack.h +3 -3
  379. data/vendor/libgit2/src/win32/w32_util.c +27 -64
  380. data/vendor/libgit2/src/win32/w32_util.h +5 -49
  381. data/vendor/libgit2/src/worktree.c +44 -30
  382. data/vendor/libgit2/src/xdiff/xdiffi.c +5 -5
  383. data/vendor/libgit2/src/xdiff/xhistogram.c +1 -1
  384. data/vendor/libgit2/src/xdiff/xmerge.c +27 -15
  385. data/vendor/libgit2/src/xdiff/xpatience.c +3 -0
  386. data/vendor/libgit2/src/zstream.c +4 -4
  387. metadata +115 -38
  388. data/vendor/libgit2/deps/regex/CMakeLists.txt +0 -2
  389. data/vendor/libgit2/deps/regex/config.h +0 -7
  390. data/vendor/libgit2/deps/regex/regcomp.c +0 -3857
  391. data/vendor/libgit2/deps/regex/regex.c +0 -92
  392. data/vendor/libgit2/deps/regex/regex.h +0 -582
  393. data/vendor/libgit2/deps/regex/regex_internal.c +0 -1744
  394. data/vendor/libgit2/deps/regex/regex_internal.h +0 -819
  395. data/vendor/libgit2/deps/regex/regexec.c +0 -4369
  396. data/vendor/libgit2/include/git2/inttypes.h +0 -309
  397. data/vendor/libgit2/include/git2/sys/time.h +0 -31
  398. data/vendor/libgit2/libgit2.pc.in +0 -13
  399. data/vendor/libgit2/src/config_file.h +0 -73
  400. data/vendor/libgit2/src/fnmatch.c +0 -248
  401. data/vendor/libgit2/src/fnmatch.h +0 -48
  402. data/vendor/libgit2/src/hash/hash_collisiondetect.h +0 -47
  403. data/vendor/libgit2/src/hash/hash_openssl.h +0 -59
  404. data/vendor/libgit2/src/streams/curl.c +0 -385
  405. data/vendor/libgit2/src/streams/curl.h +0 -17
  406. /data/vendor/libgit2/deps/http-parser/{LICENSE-MIT → COPYING} +0 -0
  407. /data/vendor/libgit2/src/hash/{sha1dc → sha1/sha1dc}/sha1.h +0 -0
  408. /data/vendor/libgit2/src/hash/{sha1dc → sha1/sha1dc}/ubc_check.c +0 -0
  409. /data/vendor/libgit2/src/hash/{sha1dc → sha1/sha1dc}/ubc_check.h +0 -0
@@ -19,6 +19,7 @@
19
19
  #include "repository.h"
20
20
  #include "global.h"
21
21
  #include "http.h"
22
+ #include "git2/sys/cred.h"
22
23
 
23
24
  #include <wincrypt.h>
24
25
  #include <winhttp.h>
@@ -48,6 +49,14 @@
48
49
  # define WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2 0x00000800
49
50
  #endif
50
51
 
52
+ #ifndef HTTP_STATUS_PERMANENT_REDIRECT
53
+ # define HTTP_STATUS_PERMANENT_REDIRECT 308
54
+ #endif
55
+
56
+ #ifndef DWORD_MAX
57
+ # define DWORD_MAX 0xffffffff
58
+ #endif
59
+
51
60
  static const char *prefix_https = "https://";
52
61
  static const char *upload_pack_service = "upload-pack";
53
62
  static const char *upload_pack_ls_service_url = "/info/refs?service=git-upload-pack";
@@ -101,23 +110,43 @@ typedef struct {
101
110
  } winhttp_stream;
102
111
 
103
112
  typedef struct {
104
- git_smart_subtransport parent;
105
- transport_smart *owner;
106
- gitno_connection_data connection_data;
107
- gitno_connection_data proxy_connection_data;
113
+ git_net_url url;
108
114
  git_cred *cred;
109
- git_cred *url_cred;
110
- git_cred *proxy_cred;
111
115
  int auth_mechanisms;
116
+ bool url_cred_presented;
117
+ } winhttp_server;
118
+
119
+ typedef struct {
120
+ git_smart_subtransport parent;
121
+ transport_smart *owner;
122
+
123
+ winhttp_server server;
124
+ winhttp_server proxy;
125
+
112
126
  HINTERNET session;
113
127
  HINTERNET connection;
114
128
  } winhttp_subtransport;
115
129
 
116
- static int _apply_userpass_credential(HINTERNET request, DWORD target, DWORD scheme, git_cred *cred)
130
+ static int apply_userpass_credentials(HINTERNET request, DWORD target, int mechanisms, git_cred *cred)
117
131
  {
118
132
  git_cred_userpass_plaintext *c = (git_cred_userpass_plaintext *)cred;
119
- wchar_t *user, *pass;
133
+ wchar_t *user = NULL, *pass = NULL;
120
134
  int user_len = 0, pass_len = 0, error = 0;
135
+ DWORD native_scheme;
136
+
137
+ if (mechanisms & GIT_WINHTTP_AUTH_NEGOTIATE) {
138
+ native_scheme = WINHTTP_AUTH_SCHEME_NEGOTIATE;
139
+ } else if (mechanisms & GIT_WINHTTP_AUTH_NTLM) {
140
+ native_scheme = WINHTTP_AUTH_SCHEME_NTLM;
141
+ } else if (mechanisms & GIT_WINHTTP_AUTH_DIGEST) {
142
+ native_scheme = WINHTTP_AUTH_SCHEME_DIGEST;
143
+ } else if (mechanisms & GIT_WINHTTP_AUTH_BASIC) {
144
+ native_scheme = WINHTTP_AUTH_SCHEME_BASIC;
145
+ } else {
146
+ git_error_set(GIT_ERROR_NET, "invalid authentication scheme");
147
+ error = -1;
148
+ goto done;
149
+ }
121
150
 
122
151
  if ((error = user_len = git__utf8_to_16_alloc(&user, c->username)) < 0)
123
152
  goto done;
@@ -125,8 +154,8 @@ static int _apply_userpass_credential(HINTERNET request, DWORD target, DWORD sch
125
154
  if ((error = pass_len = git__utf8_to_16_alloc(&pass, c->password)) < 0)
126
155
  goto done;
127
156
 
128
- if (!WinHttpSetCredentials(request, target, scheme, user, pass, NULL)) {
129
- giterr_set(GITERR_OS, "failed to set credentials");
157
+ if (!WinHttpSetCredentials(request, target, native_scheme, user, pass, NULL)) {
158
+ git_error_set(GIT_ERROR_OS, "failed to set credentials");
130
159
  error = -1;
131
160
  }
132
161
 
@@ -143,90 +172,74 @@ done:
143
172
  return error;
144
173
  }
145
174
 
146
- static int apply_userpass_credential_proxy(HINTERNET request, git_cred *cred, int mechanisms)
147
- {
148
- if (GIT_WINHTTP_AUTH_DIGEST & mechanisms) {
149
- return _apply_userpass_credential(request, WINHTTP_AUTH_TARGET_PROXY,
150
- WINHTTP_AUTH_SCHEME_DIGEST, cred);
151
- }
152
-
153
- return _apply_userpass_credential(request, WINHTTP_AUTH_TARGET_PROXY,
154
- WINHTTP_AUTH_SCHEME_BASIC, cred);
155
- }
156
-
157
- static int apply_userpass_credential(HINTERNET request, int mechanisms, git_cred *cred)
175
+ static int apply_default_credentials(HINTERNET request, DWORD target, int mechanisms)
158
176
  {
159
- DWORD native_scheme;
177
+ DWORD autologon_level = WINHTTP_AUTOLOGON_SECURITY_LEVEL_LOW;
178
+ DWORD native_scheme = 0;
160
179
 
161
- if ((mechanisms & GIT_WINHTTP_AUTH_NTLM) ||
162
- (mechanisms & GIT_WINHTTP_AUTH_NEGOTIATE)) {
180
+ if ((mechanisms & GIT_WINHTTP_AUTH_NEGOTIATE) != 0) {
181
+ native_scheme = WINHTTP_AUTH_SCHEME_NEGOTIATE;
182
+ } else if ((mechanisms & GIT_WINHTTP_AUTH_NTLM) != 0) {
163
183
  native_scheme = WINHTTP_AUTH_SCHEME_NTLM;
164
- } else if (mechanisms & GIT_WINHTTP_AUTH_BASIC) {
165
- native_scheme = WINHTTP_AUTH_SCHEME_BASIC;
166
184
  } else {
167
- giterr_set(GITERR_NET, "invalid authentication scheme");
185
+ git_error_set(GIT_ERROR_NET, "invalid authentication scheme");
168
186
  return -1;
169
187
  }
170
188
 
171
- return _apply_userpass_credential(request, WINHTTP_AUTH_TARGET_SERVER,
172
- native_scheme, cred);
173
- }
174
-
175
- static int apply_default_credentials(HINTERNET request, int mechanisms)
176
- {
177
- /* Either the caller explicitly requested that default credentials be passed,
178
- * or our fallback credential callback was invoked and checked that the target
179
- * URI was in the appropriate Internet Explorer security zone. By setting this
180
- * flag, we guarantee that the credentials are delivered by WinHTTP. The default
181
- * is "medium" which applies to the intranet and sounds like it would correspond
182
- * to Internet Explorer security zones, but in fact does not. */
183
- DWORD data = WINHTTP_AUTOLOGON_SECURITY_LEVEL_LOW;
184
- DWORD native_scheme = 0;
185
-
186
- if ((mechanisms & GIT_WINHTTP_AUTH_NTLM) != 0)
187
- native_scheme |= WINHTTP_AUTH_SCHEME_NTLM;
188
-
189
- if ((mechanisms & GIT_WINHTTP_AUTH_NEGOTIATE) != 0)
190
- native_scheme |= WINHTTP_AUTH_SCHEME_NEGOTIATE;
191
-
192
- if (!native_scheme) {
193
- giterr_set(GITERR_NET, "invalid authentication scheme");
189
+ /*
190
+ * Autologon policy must be "low" to use default creds.
191
+ * This is safe as the user has explicitly requested it.
192
+ */
193
+ if (!WinHttpSetOption(request, WINHTTP_OPTION_AUTOLOGON_POLICY, &autologon_level, sizeof(DWORD))) {
194
+ git_error_set(GIT_ERROR_OS, "could not configure logon policy");
194
195
  return -1;
195
196
  }
196
197
 
197
- if (!WinHttpSetOption(request, WINHTTP_OPTION_AUTOLOGON_POLICY, &data, sizeof(DWORD)))
198
- return -1;
199
-
200
- if (!WinHttpSetCredentials(request, WINHTTP_AUTH_TARGET_SERVER, native_scheme, NULL, NULL, NULL))
198
+ if (!WinHttpSetCredentials(request, target, native_scheme, NULL, NULL, NULL)) {
199
+ git_error_set(GIT_ERROR_OS, "could not configure credentials");
201
200
  return -1;
201
+ }
202
202
 
203
203
  return 0;
204
204
  }
205
205
 
206
- static int fallback_cred_acquire_cb(
206
+ static int acquire_url_cred(
207
207
  git_cred **cred,
208
- const char *url,
209
- const char *username_from_url,
210
208
  unsigned int allowed_types,
211
- void *payload)
209
+ const char *username,
210
+ const char *password)
212
211
  {
213
- int error = 1;
212
+ if (allowed_types & GIT_CREDTYPE_USERPASS_PLAINTEXT)
213
+ return git_cred_userpass_plaintext_new(cred, username, password);
214
+
215
+ if ((allowed_types & GIT_CREDTYPE_DEFAULT) && *username == '\0' && *password == '\0')
216
+ return git_cred_default_new(cred);
214
217
 
215
- GIT_UNUSED(username_from_url);
216
- GIT_UNUSED(payload);
218
+ return 1;
219
+ }
220
+
221
+ static int acquire_fallback_cred(
222
+ git_cred **cred,
223
+ const char *url,
224
+ unsigned int allowed_types)
225
+ {
226
+ int error = 1;
217
227
 
218
228
  /* If the target URI supports integrated Windows authentication
219
229
  * as an authentication mechanism */
220
230
  if (GIT_CREDTYPE_DEFAULT & allowed_types) {
221
231
  wchar_t *wide_url;
232
+ HRESULT hCoInitResult;
222
233
 
223
234
  /* Convert URL to wide characters */
224
235
  if (git__utf8_to_16_alloc(&wide_url, url) < 0) {
225
- giterr_set(GITERR_OS, "failed to convert string to wide form");
236
+ git_error_set(GIT_ERROR_OS, "failed to convert string to wide form");
226
237
  return -1;
227
238
  }
228
239
 
229
- if (SUCCEEDED(CoInitializeEx(NULL, COINIT_MULTITHREADED))) {
240
+ hCoInitResult = CoInitializeEx(NULL, COINIT_MULTITHREADED);
241
+
242
+ if (SUCCEEDED(hCoInitResult) || hCoInitResult == RPC_E_CHANGED_MODE) {
230
243
  IInternetSecurityManager* pISM;
231
244
 
232
245
  /* And if the target URI is in the My Computer, Intranet, or Trusted zones */
@@ -250,7 +263,9 @@ static int fallback_cred_acquire_cb(
250
263
  pISM->lpVtbl->Release(pISM);
251
264
  }
252
265
 
253
- CoUninitialize();
266
+ /* Only unitialize if the call to CoInitializeEx was successful. */
267
+ if (SUCCEEDED(hCoInitResult))
268
+ CoUninitialize();
254
269
  }
255
270
 
256
271
  git__free(wide_url);
@@ -269,29 +284,32 @@ static int certificate_check(winhttp_stream *s, int valid)
269
284
 
270
285
  /* If there is no override, we should fail if WinHTTP doesn't think it's fine */
271
286
  if (t->owner->certificate_check_cb == NULL && !valid) {
272
- if (!giterr_last())
273
- giterr_set(GITERR_NET, "unknown certificate check failure");
287
+ if (!git_error_last())
288
+ git_error_set(GIT_ERROR_NET, "unknown certificate check failure");
274
289
 
275
290
  return GIT_ECERTIFICATE;
276
291
  }
277
292
 
278
- if (t->owner->certificate_check_cb == NULL || !t->connection_data.use_ssl)
293
+ if (t->owner->certificate_check_cb == NULL || git__strcmp(t->server.url.scheme, "https") != 0)
279
294
  return 0;
280
295
 
281
296
  if (!WinHttpQueryOption(s->request, WINHTTP_OPTION_SERVER_CERT_CONTEXT, &cert_ctx, &cert_ctx_size)) {
282
- giterr_set(GITERR_OS, "failed to get server certificate");
297
+ git_error_set(GIT_ERROR_OS, "failed to get server certificate");
283
298
  return -1;
284
299
  }
285
300
 
286
- giterr_clear();
301
+ git_error_clear();
287
302
  cert.parent.cert_type = GIT_CERT_X509;
288
303
  cert.data = cert_ctx->pbCertEncoded;
289
304
  cert.len = cert_ctx->cbCertEncoded;
290
- error = t->owner->certificate_check_cb((git_cert *) &cert, valid, t->connection_data.host, t->owner->message_cb_payload);
305
+ error = t->owner->certificate_check_cb((git_cert *) &cert, valid, t->server.url.host, t->owner->message_cb_payload);
291
306
  CertFreeCertificateContext(cert_ctx);
292
307
 
293
- if (error < 0 && !giterr_last())
294
- giterr_set(GITERR_NET, "user cancelled certificate check");
308
+ if (error == GIT_PASSTHROUGH)
309
+ error = valid ? 0 : GIT_ECERTIFICATE;
310
+
311
+ if (error < 0 && !git_error_last())
312
+ git_error_set(GIT_ERROR_NET, "user cancelled certificate check");
295
313
 
296
314
  return error;
297
315
  }
@@ -321,37 +339,26 @@ static void winhttp_stream_close(winhttp_stream *s)
321
339
  s->sent_request = 0;
322
340
  }
323
341
 
324
- /**
325
- * Extract the url and password from a URL. The outputs are pointers
326
- * into the input.
327
- */
328
- static int userpass_from_url(wchar_t **user, int *user_len,
329
- wchar_t **pass, int *pass_len,
330
- const wchar_t *url, int url_len)
342
+ static int apply_credentials(
343
+ HINTERNET request,
344
+ git_net_url *url,
345
+ int target,
346
+ git_cred *creds,
347
+ int mechanisms)
331
348
  {
332
- URL_COMPONENTS components = { 0 };
349
+ int error = 0;
333
350
 
334
- components.dwStructSize = sizeof(components);
335
- /* These tell WinHttpCrackUrl that we're interested in the fields */
336
- components.dwUserNameLength = 1;
337
- components.dwPasswordLength = 1;
338
-
339
- if (!WinHttpCrackUrl(url, url_len, 0, &components)) {
340
- giterr_set(GITERR_OS, "failed to extract user/pass from url");
341
- return -1;
342
- }
351
+ GIT_UNUSED(url);
343
352
 
344
- *user = components.lpszUserName;
345
- *user_len = components.dwUserNameLength;
346
- *pass = components.lpszPassword;
347
- *pass_len = components.dwPasswordLength;
353
+ /* If we have creds, just apply them */
354
+ if (creds && creds->credtype == GIT_CREDTYPE_USERPASS_PLAINTEXT)
355
+ error = apply_userpass_credentials(request, target, mechanisms, creds);
356
+ else if (creds && creds->credtype == GIT_CREDTYPE_DEFAULT)
357
+ error = apply_default_credentials(request, target, mechanisms);
348
358
 
349
- return 0;
359
+ return error;
350
360
  }
351
361
 
352
- #define SCHEME_HTTP "http://"
353
- #define SCHEME_HTTPS "https://"
354
-
355
362
  static int winhttp_stream_connect(winhttp_stream *s)
356
363
  {
357
364
  winhttp_subtransport *t = OWNING_SUBTRANSPORT(s);
@@ -364,18 +371,20 @@ static int winhttp_stream_connect(winhttp_stream *s)
364
371
  unsigned long disable_redirects = WINHTTP_DISABLE_REDIRECTS;
365
372
  int default_timeout = TIMEOUT_INFINITE;
366
373
  int default_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
374
+ DWORD autologon_policy = WINHTTP_AUTOLOGON_SECURITY_LEVEL_HIGH;
375
+
367
376
  size_t i;
368
377
  const git_proxy_options *proxy_opts;
369
378
 
370
379
  /* Prepare URL */
371
- git_buf_printf(&buf, "%s%s", t->connection_data.path, s->service_url);
380
+ git_buf_printf(&buf, "%s%s", t->server.url.path, s->service_url);
372
381
 
373
382
  if (git_buf_oom(&buf))
374
383
  return -1;
375
384
 
376
385
  /* Convert URL to wide characters */
377
386
  if (git__utf8_to_16_alloc(&s->request_uri, git_buf_cstr(&buf)) < 0) {
378
- giterr_set(GITERR_OS, "failed to convert string to wide form");
387
+ git_error_set(GIT_ERROR_OS, "failed to convert string to wide form");
379
388
  goto on_error;
380
389
  }
381
390
 
@@ -387,27 +396,31 @@ static int winhttp_stream_connect(winhttp_stream *s)
387
396
  NULL,
388
397
  WINHTTP_NO_REFERER,
389
398
  types,
390
- t->connection_data.use_ssl ? WINHTTP_FLAG_SECURE : 0);
399
+ git__strcmp(t->server.url.scheme, "https") == 0 ? WINHTTP_FLAG_SECURE : 0);
391
400
 
392
401
  if (!s->request) {
393
- giterr_set(GITERR_OS, "failed to open request");
402
+ git_error_set(GIT_ERROR_OS, "failed to open request");
394
403
  goto on_error;
395
404
  }
396
405
 
406
+ /* Never attempt default credentials; we'll provide them explicitly. */
407
+ if (!WinHttpSetOption(s->request, WINHTTP_OPTION_AUTOLOGON_POLICY, &autologon_policy, sizeof(DWORD)))
408
+ return -1;
409
+
397
410
  if (!WinHttpSetTimeouts(s->request, default_timeout, default_connect_timeout, default_timeout, default_timeout)) {
398
- giterr_set(GITERR_OS, "failed to set timeouts for WinHTTP");
411
+ git_error_set(GIT_ERROR_OS, "failed to set timeouts for WinHTTP");
399
412
  goto on_error;
400
413
  }
401
414
 
402
415
  proxy_opts = &t->owner->proxy;
403
416
  if (proxy_opts->type == GIT_PROXY_AUTO) {
404
417
  /* Set proxy if necessary */
405
- if (git_remote__get_http_proxy(t->owner->owner, !!t->connection_data.use_ssl, &proxy_url) < 0)
418
+ if (git_remote__get_http_proxy(t->owner->owner, (strcmp(t->server.url.scheme, "https") == 0), &proxy_url) < 0)
406
419
  goto on_error;
407
420
  }
408
421
  else if (proxy_opts->type == GIT_PROXY_SPECIFIED) {
409
422
  proxy_url = git__strdup(proxy_opts->url);
410
- GITERR_CHECK_ALLOC(proxy_url);
423
+ GIT_ERROR_CHECK_ALLOC(proxy_url);
411
424
  }
412
425
 
413
426
  if (proxy_url) {
@@ -415,38 +428,24 @@ static int winhttp_stream_connect(winhttp_stream *s)
415
428
  WINHTTP_PROXY_INFO proxy_info;
416
429
  wchar_t *proxy_wide;
417
430
 
418
- if (!git__prefixcmp(proxy_url, SCHEME_HTTP)) {
419
- t->proxy_connection_data.use_ssl = false;
420
- } else if (!git__prefixcmp(proxy_url, SCHEME_HTTPS)) {
421
- t->proxy_connection_data.use_ssl = true;
422
- } else {
423
- giterr_set(GITERR_NET, "invalid URL: '%s'", proxy_url);
424
- return -1;
425
- }
431
+ git_net_url_dispose(&t->proxy.url);
426
432
 
427
- gitno_connection_data_free_ptrs(&t->proxy_connection_data);
428
-
429
- if ((error = gitno_extract_url_parts(&t->proxy_connection_data.host, &t->proxy_connection_data.port, NULL,
430
- &t->proxy_connection_data.user, &t->proxy_connection_data.pass, proxy_url, NULL)) < 0)
433
+ if ((error = git_net_url_parse(&t->proxy.url, proxy_url)) < 0)
431
434
  goto on_error;
432
435
 
433
- if (t->proxy_connection_data.user && t->proxy_connection_data.pass) {
434
- if (t->proxy_cred) {
435
- t->proxy_cred->free(t->proxy_cred);
436
- }
437
-
438
- if ((error = git_cred_userpass_plaintext_new(&t->proxy_cred, t->proxy_connection_data.user, t->proxy_connection_data.pass)) < 0)
439
- goto on_error;
436
+ if (strcmp(t->proxy.url.scheme, "http") != 0 && strcmp(t->proxy.url.scheme, "https") != 0) {
437
+ git_error_set(GIT_ERROR_NET, "invalid URL: '%s'", proxy_url);
438
+ error = -1;
439
+ goto on_error;
440
440
  }
441
441
 
442
- if (t->proxy_connection_data.use_ssl)
443
- git_buf_PUTS(&processed_url, SCHEME_HTTPS);
444
- else
445
- git_buf_PUTS(&processed_url, SCHEME_HTTP);
442
+ git_buf_puts(&processed_url, t->proxy.url.scheme);
443
+ git_buf_PUTS(&processed_url, "://");
446
444
 
447
- git_buf_puts(&processed_url, t->proxy_connection_data.host);
448
- if (t->proxy_connection_data.port)
449
- git_buf_printf(&processed_url, ":%s", t->proxy_connection_data.port);
445
+ git_buf_puts(&processed_url, t->proxy.url.host);
446
+
447
+ if (!git_net_url_is_default_port(&t->proxy.url))
448
+ git_buf_printf(&processed_url, ":%s", t->proxy.url.port);
450
449
 
451
450
  if (git_buf_oom(&processed_url)) {
452
451
  error = -1;
@@ -467,20 +466,15 @@ static int winhttp_stream_connect(winhttp_stream *s)
467
466
  WINHTTP_OPTION_PROXY,
468
467
  &proxy_info,
469
468
  sizeof(WINHTTP_PROXY_INFO))) {
470
- giterr_set(GITERR_OS, "failed to set proxy");
469
+ git_error_set(GIT_ERROR_OS, "failed to set proxy");
471
470
  git__free(proxy_wide);
472
471
  goto on_error;
473
472
  }
474
473
 
475
474
  git__free(proxy_wide);
476
475
 
477
- if (t->proxy_cred) {
478
- if (t->proxy_cred->credtype == GIT_CREDTYPE_USERPASS_PLAINTEXT) {
479
- if ((error = apply_userpass_credential_proxy(s->request, t->proxy_cred, t->auth_mechanisms)) < 0)
480
- goto on_error;
481
- }
482
- }
483
-
476
+ if ((error = apply_credentials(s->request, &t->proxy.url, WINHTTP_AUTH_TARGET_PROXY, t->proxy.cred, t->proxy.auth_mechanisms)) < 0)
477
+ goto on_error;
484
478
  }
485
479
 
486
480
  /* Disable WinHTTP redirects so we can handle them manually. Why, you ask?
@@ -490,7 +484,8 @@ static int winhttp_stream_connect(winhttp_stream *s)
490
484
  WINHTTP_OPTION_DISABLE_FEATURE,
491
485
  &disable_redirects,
492
486
  sizeof(disable_redirects))) {
493
- giterr_set(GITERR_OS, "failed to disable redirects");
487
+ git_error_set(GIT_ERROR_OS, "failed to disable redirects");
488
+ error = -1;
494
489
  goto on_error;
495
490
  }
496
491
 
@@ -504,7 +499,7 @@ static int winhttp_stream_connect(winhttp_stream *s)
504
499
 
505
500
  /* Send Pragma: no-cache header */
506
501
  if (!WinHttpAddRequestHeaders(s->request, pragma_nocache, (ULONG) -1L, WINHTTP_ADDREQ_FLAG_ADD)) {
507
- giterr_set(GITERR_OS, "failed to add a header to the request");
502
+ git_error_set(GIT_ERROR_OS, "failed to add a header to the request");
508
503
  goto on_error;
509
504
  }
510
505
 
@@ -517,13 +512,13 @@ static int winhttp_stream_connect(winhttp_stream *s)
517
512
  goto on_error;
518
513
 
519
514
  if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_buf_cstr(&buf)) < 0) {
520
- giterr_set(GITERR_OS, "failed to convert content-type to wide characters");
515
+ git_error_set(GIT_ERROR_OS, "failed to convert content-type to wide characters");
521
516
  goto on_error;
522
517
  }
523
518
 
524
519
  if (!WinHttpAddRequestHeaders(s->request, ct, (ULONG)-1L,
525
520
  WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE)) {
526
- giterr_set(GITERR_OS, "failed to add a header to the request");
521
+ git_error_set(GIT_ERROR_OS, "failed to add a header to the request");
527
522
  goto on_error;
528
523
  }
529
524
 
@@ -534,13 +529,13 @@ static int winhttp_stream_connect(winhttp_stream *s)
534
529
  goto on_error;
535
530
 
536
531
  if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_buf_cstr(&buf)) < 0) {
537
- giterr_set(GITERR_OS, "failed to convert accept header to wide characters");
532
+ git_error_set(GIT_ERROR_OS, "failed to convert accept header to wide characters");
538
533
  goto on_error;
539
534
  }
540
535
 
541
536
  if (!WinHttpAddRequestHeaders(s->request, ct, (ULONG)-1L,
542
537
  WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE)) {
543
- giterr_set(GITERR_OS, "failed to add a header to the request");
538
+ git_error_set(GIT_ERROR_OS, "failed to add a header to the request");
544
539
  goto on_error;
545
540
  }
546
541
  }
@@ -550,46 +545,29 @@ static int winhttp_stream_connect(winhttp_stream *s)
550
545
  git_buf_clear(&buf);
551
546
  git_buf_puts(&buf, t->owner->custom_headers.strings[i]);
552
547
  if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_buf_cstr(&buf)) < 0) {
553
- giterr_set(GITERR_OS, "failed to convert custom header to wide characters");
548
+ git_error_set(GIT_ERROR_OS, "failed to convert custom header to wide characters");
554
549
  goto on_error;
555
550
  }
556
551
 
557
552
  if (!WinHttpAddRequestHeaders(s->request, ct, (ULONG)-1L,
558
553
  WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE)) {
559
- giterr_set(GITERR_OS, "failed to add a header to the request");
554
+ git_error_set(GIT_ERROR_OS, "failed to add a header to the request");
560
555
  goto on_error;
561
556
  }
562
557
  }
563
558
  }
564
559
 
565
560
  /* If requested, disable certificate validation */
566
- if (t->connection_data.use_ssl) {
561
+ if (strcmp(t->server.url.scheme, "https") == 0) {
567
562
  int flags;
568
563
 
569
564
  if (t->owner->parent.read_flags(&t->owner->parent, &flags) < 0)
570
565
  goto on_error;
571
566
  }
572
567
 
573
- /* If we have a credential on the subtransport, apply it to the request */
574
- if (t->cred &&
575
- t->cred->credtype == GIT_CREDTYPE_USERPASS_PLAINTEXT &&
576
- apply_userpass_credential(s->request, t->auth_mechanisms, t->cred) < 0)
577
- goto on_error;
578
- else if (t->cred &&
579
- t->cred->credtype == GIT_CREDTYPE_DEFAULT &&
580
- apply_default_credentials(s->request, t->auth_mechanisms) < 0)
568
+ if ((error = apply_credentials(s->request, &t->server.url, WINHTTP_AUTH_TARGET_SERVER, t->server.cred, t->server.auth_mechanisms)) < 0)
581
569
  goto on_error;
582
570
 
583
- /* If no other credentials have been applied and the URL has username and
584
- * password, use those */
585
- if (!t->cred && t->connection_data.user && t->connection_data.pass) {
586
- if (!t->url_cred &&
587
- git_cred_userpass_plaintext_new(&t->url_cred, t->connection_data.user, t->connection_data.pass) < 0)
588
- goto on_error;
589
- if (apply_userpass_credential(s->request, GIT_WINHTTP_AUTH_BASIC, t->url_cred) < 0)
590
- goto on_error;
591
- }
592
-
593
571
  /* We've done everything up to calling WinHttpSendRequest. */
594
572
 
595
573
  error = 0;
@@ -604,9 +582,9 @@ on_error:
604
582
  }
605
583
 
606
584
  static int parse_unauthorized_response(
607
- HINTERNET request,
608
585
  int *allowed_types,
609
- int *allowed_mechanisms)
586
+ int *allowed_mechanisms,
587
+ HINTERNET request)
610
588
  {
611
589
  DWORD supported, first, target;
612
590
 
@@ -617,7 +595,7 @@ static int parse_unauthorized_response(
617
595
  * We can assume this was already done, since we know we are unauthorized.
618
596
  */
619
597
  if (!WinHttpQueryAuthSchemes(request, &supported, &first, &target)) {
620
- giterr_set(GITERR_OS, "failed to parse supported auth schemes");
598
+ git_error_set(GIT_ERROR_OS, "failed to parse supported auth schemes");
621
599
  return -1;
622
600
  }
623
601
 
@@ -651,7 +629,7 @@ static int write_chunk(HINTERNET request, const char *buffer, size_t len)
651
629
  git_buf buf = GIT_BUF_INIT;
652
630
 
653
631
  /* Chunk header */
654
- git_buf_printf(&buf, "%X\r\n", len);
632
+ git_buf_printf(&buf, "%"PRIXZ"\r\n", len);
655
633
 
656
634
  if (git_buf_oom(&buf))
657
635
  return -1;
@@ -660,7 +638,7 @@ static int write_chunk(HINTERNET request, const char *buffer, size_t len)
660
638
  git_buf_cstr(&buf), (DWORD)git_buf_len(&buf),
661
639
  &bytes_written)) {
662
640
  git_buf_dispose(&buf);
663
- giterr_set(GITERR_OS, "failed to write chunk header");
641
+ git_error_set(GIT_ERROR_OS, "failed to write chunk header");
664
642
  return -1;
665
643
  }
666
644
 
@@ -670,7 +648,7 @@ static int write_chunk(HINTERNET request, const char *buffer, size_t len)
670
648
  if (!WinHttpWriteData(request,
671
649
  buffer, (DWORD)len,
672
650
  &bytes_written)) {
673
- giterr_set(GITERR_OS, "failed to write chunk");
651
+ git_error_set(GIT_ERROR_OS, "failed to write chunk");
674
652
  return -1;
675
653
  }
676
654
 
@@ -678,7 +656,7 @@ static int write_chunk(HINTERNET request, const char *buffer, size_t len)
678
656
  if (!WinHttpWriteData(request,
679
657
  "\r\n", 2,
680
658
  &bytes_written)) {
681
- giterr_set(GITERR_OS, "failed to write chunk footer");
659
+ git_error_set(GIT_ERROR_OS, "failed to write chunk footer");
682
660
  return -1;
683
661
  }
684
662
 
@@ -691,7 +669,7 @@ static int winhttp_close_connection(winhttp_subtransport *t)
691
669
 
692
670
  if (t->connection) {
693
671
  if (!WinHttpCloseHandle(t->connection)) {
694
- giterr_set(GITERR_OS, "unable to close connection");
672
+ git_error_set(GIT_ERROR_OS, "unable to close connection");
695
673
  ret = -1;
696
674
  }
697
675
 
@@ -700,7 +678,7 @@ static int winhttp_close_connection(winhttp_subtransport *t)
700
678
 
701
679
  if (t->session) {
702
680
  if (!WinHttpCloseHandle(t->session)) {
703
- giterr_set(GITERR_OS, "unable to close session");
681
+ git_error_set(GIT_ERROR_OS, "unable to close session");
704
682
  ret = -1;
705
683
  }
706
684
 
@@ -719,27 +697,31 @@ static void CALLBACK winhttp_status(
719
697
  {
720
698
  DWORD status;
721
699
 
700
+ GIT_UNUSED(connection);
701
+ GIT_UNUSED(ctx);
702
+ GIT_UNUSED(info_len);
703
+
722
704
  if (code != WINHTTP_CALLBACK_STATUS_SECURE_FAILURE)
723
705
  return;
724
706
 
725
707
  status = *((DWORD *)info);
726
708
 
727
709
  if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_CN_INVALID))
728
- giterr_set(GITERR_NET, "SSL certificate issued for different common name");
710
+ git_error_set(GIT_ERROR_NET, "SSL certificate issued for different common name");
729
711
  else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_DATE_INVALID))
730
- giterr_set(GITERR_NET, "SSL certificate has expired");
712
+ git_error_set(GIT_ERROR_NET, "SSL certificate has expired");
731
713
  else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CA))
732
- giterr_set(GITERR_NET, "SSL certificate signed by unknown CA");
714
+ git_error_set(GIT_ERROR_NET, "SSL certificate signed by unknown CA");
733
715
  else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CERT))
734
- giterr_set(GITERR_NET, "SSL certificate is invalid");
716
+ git_error_set(GIT_ERROR_NET, "SSL certificate is invalid");
735
717
  else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_REV_FAILED))
736
- giterr_set(GITERR_NET, "certificate revocation check failed");
718
+ git_error_set(GIT_ERROR_NET, "certificate revocation check failed");
737
719
  else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_CERT_REVOKED))
738
- giterr_set(GITERR_NET, "SSL certificate was revoked");
720
+ git_error_set(GIT_ERROR_NET, "SSL certificate was revoked");
739
721
  else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR))
740
- giterr_set(GITERR_NET, "security libraries could not be loaded");
722
+ git_error_set(GIT_ERROR_NET, "security libraries could not be loaded");
741
723
  else
742
- giterr_set(GITERR_NET, "unknown security error %d", status);
724
+ git_error_set(GIT_ERROR_NET, "unknown security error %lu", status);
743
725
  }
744
726
 
745
727
  static int winhttp_connect(
@@ -761,12 +743,13 @@ static int winhttp_connect(
761
743
  t->connection = NULL;
762
744
 
763
745
  /* Prepare port */
764
- if (git__strtol32(&port, t->connection_data.port, NULL, 10) < 0)
746
+ if (git__strntol32(&port, t->server.url.port,
747
+ strlen(t->server.url.port), NULL, 10) < 0)
765
748
  return -1;
766
749
 
767
750
  /* Prepare host */
768
- if (git__utf8_to_16_alloc(&wide_host, t->connection_data.host) < 0) {
769
- giterr_set(GITERR_OS, "unable to convert host to wide characters");
751
+ if (git__utf8_to_16_alloc(&wide_host, t->server.url.host) < 0) {
752
+ git_error_set(GIT_ERROR_OS, "unable to convert host to wide characters");
770
753
  return -1;
771
754
  }
772
755
 
@@ -777,7 +760,7 @@ static int winhttp_connect(
777
760
  }
778
761
 
779
762
  if (git__utf8_to_16_alloc(&wide_ua, git_buf_cstr(&ua)) < 0) {
780
- giterr_set(GITERR_OS, "unable to convert host to wide characters");
763
+ git_error_set(GIT_ERROR_OS, "unable to convert host to wide characters");
781
764
  git__free(wide_host);
782
765
  git_buf_dispose(&ua);
783
766
  return -1;
@@ -794,7 +777,7 @@ static int winhttp_connect(
794
777
  0);
795
778
 
796
779
  if (!t->session) {
797
- giterr_set(GITERR_OS, "failed to init WinHTTP");
780
+ git_error_set(GIT_ERROR_OS, "failed to init WinHTTP");
798
781
  goto on_error;
799
782
  }
800
783
 
@@ -809,7 +792,7 @@ static int winhttp_connect(
809
792
  sizeof(protocols));
810
793
 
811
794
  if (!WinHttpSetTimeouts(t->session, default_timeout, default_connect_timeout, default_timeout, default_timeout)) {
812
- giterr_set(GITERR_OS, "failed to set timeouts for WinHTTP");
795
+ git_error_set(GIT_ERROR_OS, "failed to set timeouts for WinHTTP");
813
796
  goto on_error;
814
797
  }
815
798
 
@@ -822,12 +805,12 @@ static int winhttp_connect(
822
805
  0);
823
806
 
824
807
  if (!t->connection) {
825
- giterr_set(GITERR_OS, "failed to connect to host");
808
+ git_error_set(GIT_ERROR_OS, "failed to connect to host");
826
809
  goto on_error;
827
810
  }
828
811
 
829
812
  if (WinHttpSetStatusCallback(t->connection, winhttp_status, WINHTTP_CALLBACK_FLAG_SECURE_FAILURE, 0) == WINHTTP_INVALID_STATUS_CALLBACK) {
830
- giterr_set(GITERR_OS, "failed to set status callback");
813
+ git_error_set(GIT_ERROR_OS, "failed to set status callback");
831
814
  goto on_error;
832
815
  }
833
816
 
@@ -845,23 +828,32 @@ on_error:
845
828
 
846
829
  static int do_send_request(winhttp_stream *s, size_t len, int ignore_length)
847
830
  {
848
- if (ignore_length) {
849
- if (!WinHttpSendRequest(s->request,
850
- WINHTTP_NO_ADDITIONAL_HEADERS, 0,
851
- WINHTTP_NO_REQUEST_DATA, 0,
852
- WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH, 0)) {
853
- return -1;
854
- }
855
- } else {
856
- if (!WinHttpSendRequest(s->request,
857
- WINHTTP_NO_ADDITIONAL_HEADERS, 0,
858
- WINHTTP_NO_REQUEST_DATA, 0,
859
- len, 0)) {
860
- return -1;
831
+ int attempts;
832
+ bool success;
833
+
834
+ if (len > DWORD_MAX) {
835
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
836
+ return -1;
837
+ }
838
+
839
+ for (attempts = 0; attempts < 5; attempts++) {
840
+ if (ignore_length) {
841
+ success = WinHttpSendRequest(s->request,
842
+ WINHTTP_NO_ADDITIONAL_HEADERS, 0,
843
+ WINHTTP_NO_REQUEST_DATA, 0,
844
+ WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH, 0);
845
+ } else {
846
+ success = WinHttpSendRequest(s->request,
847
+ WINHTTP_NO_ADDITIONAL_HEADERS, 0,
848
+ WINHTTP_NO_REQUEST_DATA, 0,
849
+ (DWORD)len, 0);
861
850
  }
851
+
852
+ if (success || GetLastError() != (DWORD)SEC_E_BUFFER_TOO_SMALL)
853
+ break;
862
854
  }
863
855
 
864
- return 0;
856
+ return success ? 0 : -1;
865
857
  }
866
858
 
867
859
  static int send_request(winhttp_stream *s, size_t len, int ignore_length)
@@ -869,10 +861,10 @@ static int send_request(winhttp_stream *s, size_t len, int ignore_length)
869
861
  int request_failed = 0, cert_valid = 1, error = 0;
870
862
  DWORD ignore_flags;
871
863
 
872
- giterr_clear();
864
+ git_error_clear();
873
865
  if ((error = do_send_request(s, len, ignore_length)) < 0) {
874
866
  if (GetLastError() != ERROR_WINHTTP_SECURE_FAILURE) {
875
- giterr_set(GITERR_OS, "failed to send request");
867
+ git_error_set(GIT_ERROR_OS, "failed to send request");
876
868
  return -1;
877
869
  }
878
870
 
@@ -880,10 +872,10 @@ static int send_request(winhttp_stream *s, size_t len, int ignore_length)
880
872
  cert_valid = 0;
881
873
  }
882
874
 
883
- giterr_clear();
875
+ git_error_clear();
884
876
  if ((error = certificate_check(s, cert_valid)) < 0) {
885
- if (!giterr_last())
886
- giterr_set(GITERR_OS, "user cancelled certificate check");
877
+ if (!git_error_last())
878
+ git_error_set(GIT_ERROR_OS, "user cancelled certificate check");
887
879
 
888
880
  return error;
889
881
  }
@@ -895,16 +887,69 @@ static int send_request(winhttp_stream *s, size_t len, int ignore_length)
895
887
  ignore_flags = no_check_cert_flags;
896
888
 
897
889
  if (!WinHttpSetOption(s->request, WINHTTP_OPTION_SECURITY_FLAGS, &ignore_flags, sizeof(ignore_flags))) {
898
- giterr_set(GITERR_OS, "failed to set security options");
890
+ git_error_set(GIT_ERROR_OS, "failed to set security options");
899
891
  return -1;
900
892
  }
901
893
 
902
894
  if ((error = do_send_request(s, len, ignore_length)) < 0)
903
- giterr_set(GITERR_OS, "failed to send request with unchecked certificate");
895
+ git_error_set(GIT_ERROR_OS, "failed to send request with unchecked certificate");
904
896
 
905
897
  return error;
906
898
  }
907
899
 
900
+ static int acquire_credentials(
901
+ HINTERNET request,
902
+ winhttp_server *server,
903
+ const char *url_str,
904
+ git_cred_acquire_cb cred_cb,
905
+ void *cred_cb_payload)
906
+ {
907
+ int allowed_types;
908
+ int error = 1;
909
+
910
+ if (parse_unauthorized_response(&allowed_types, &server->auth_mechanisms, request) < 0)
911
+ return -1;
912
+
913
+ if (allowed_types) {
914
+ git_cred_free(server->cred);
915
+ server->cred = NULL;
916
+
917
+ /* Start with URL-specified credentials, if there were any. */
918
+ if (!server->url_cred_presented && server->url.username && server->url.password) {
919
+ error = acquire_url_cred(&server->cred, allowed_types, server->url.username, server->url.password);
920
+ server->url_cred_presented = 1;
921
+
922
+ if (error < 0)
923
+ return error;
924
+ }
925
+
926
+ /* Next use the user-defined callback, if there is one. */
927
+ if (error > 0 && cred_cb) {
928
+ error = cred_cb(&server->cred, url_str, server->url.username, allowed_types, cred_cb_payload);
929
+
930
+ /* Treat GIT_PASSTHROUGH as though git_cred_acquire_cb isn't set */
931
+ if (error == GIT_PASSTHROUGH)
932
+ error = 1;
933
+ else if (error < 0)
934
+ return error;
935
+ }
936
+
937
+ /* Finally, invoke the fallback default credential lookup. */
938
+ if (error > 0) {
939
+ error = acquire_fallback_cred(&server->cred, url_str, allowed_types);
940
+
941
+ if (error < 0)
942
+ return error;
943
+ }
944
+ }
945
+
946
+ /*
947
+ * No error occurred but we could not find appropriate credentials.
948
+ * This behaves like a pass-through.
949
+ */
950
+ return error;
951
+ }
952
+
908
953
  static int winhttp_stream_read(
909
954
  git_smart_subtransport_stream *stream,
910
955
  char *buffer,
@@ -919,8 +964,8 @@ static int winhttp_stream_read(
919
964
 
920
965
  replay:
921
966
  /* Enforce a reasonable cap on the number of replays */
922
- if (++replay_count >= 7) {
923
- giterr_set(GITERR_NET, "too many redirects or authentication replays");
967
+ if (replay_count++ >= GIT_HTTP_REPLAY_MAX) {
968
+ git_error_set(GIT_ERROR_NET, "too many redirects or authentication replays");
924
969
  return -1;
925
970
  }
926
971
 
@@ -955,7 +1000,7 @@ replay:
955
1000
  if (!WinHttpWriteData(s->request,
956
1001
  "0\r\n\r\n", 5,
957
1002
  &bytes_written)) {
958
- giterr_set(GITERR_OS, "failed to write final chunk");
1003
+ git_error_set(GIT_ERROR_OS, "failed to write final chunk");
959
1004
  return -1;
960
1005
  }
961
1006
  }
@@ -966,11 +1011,12 @@ replay:
966
1011
  if (INVALID_SET_FILE_POINTER == SetFilePointer(s->post_body,
967
1012
  0, 0, FILE_BEGIN) &&
968
1013
  NO_ERROR != GetLastError()) {
969
- giterr_set(GITERR_OS, "failed to reset file pointer");
1014
+ git_error_set(GIT_ERROR_OS, "failed to reset file pointer");
970
1015
  return -1;
971
1016
  }
972
1017
 
973
1018
  buffer = git__malloc(CACHED_POST_BODY_BUF_SIZE);
1019
+ GIT_ERROR_CHECK_ALLOC(buffer);
974
1020
 
975
1021
  while (len > 0) {
976
1022
  DWORD bytes_written;
@@ -980,14 +1026,14 @@ replay:
980
1026
  &bytes_read, NULL) ||
981
1027
  !bytes_read) {
982
1028
  git__free(buffer);
983
- giterr_set(GITERR_OS, "failed to read from temp file");
1029
+ git_error_set(GIT_ERROR_OS, "failed to read from temp file");
984
1030
  return -1;
985
1031
  }
986
1032
 
987
1033
  if (!WinHttpWriteData(s->request, buffer,
988
1034
  bytes_read, &bytes_written)) {
989
1035
  git__free(buffer);
990
- giterr_set(GITERR_OS, "failed to write data");
1036
+ git_error_set(GIT_ERROR_OS, "failed to write data");
991
1037
  return -1;
992
1038
  }
993
1039
 
@@ -1003,7 +1049,7 @@ replay:
1003
1049
  }
1004
1050
 
1005
1051
  if (!WinHttpReceiveResponse(s->request, 0)) {
1006
- giterr_set(GITERR_OS, "failed to receive response");
1052
+ git_error_set(GIT_ERROR_OS, "failed to receive response");
1007
1053
  return -1;
1008
1054
  }
1009
1055
 
@@ -1015,7 +1061,7 @@ replay:
1015
1061
  WINHTTP_HEADER_NAME_BY_INDEX,
1016
1062
  &status_code, &status_code_length,
1017
1063
  WINHTTP_NO_HEADER_INDEX)) {
1018
- giterr_set(GITERR_OS, "failed to retrieve status code");
1064
+ git_error_set(GIT_ERROR_OS, "failed to retrieve status code");
1019
1065
  return -1;
1020
1066
  }
1021
1067
 
@@ -1029,7 +1075,8 @@ replay:
1029
1075
  HTTP_STATUS_REDIRECT == status_code ||
1030
1076
  (HTTP_STATUS_REDIRECT_METHOD == status_code &&
1031
1077
  get_verb == s->verb) ||
1032
- HTTP_STATUS_REDIRECT_KEEP_VERB == status_code)) {
1078
+ HTTP_STATUS_REDIRECT_KEEP_VERB == status_code ||
1079
+ HTTP_STATUS_PERMANENT_REDIRECT == status_code)) {
1033
1080
 
1034
1081
  /* Check for Windows 7. This workaround is only necessary on
1035
1082
  * Windows Vista and earlier. Windows 7 is version 6.1. */
@@ -1045,12 +1092,12 @@ replay:
1045
1092
  &location_length,
1046
1093
  WINHTTP_NO_HEADER_INDEX) ||
1047
1094
  GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
1048
- giterr_set(GITERR_OS, "failed to read Location header");
1095
+ git_error_set(GIT_ERROR_OS, "failed to read Location header");
1049
1096
  return -1;
1050
1097
  }
1051
1098
 
1052
1099
  location = git__malloc(location_length);
1053
- GITERR_CHECK_ALLOC(location);
1100
+ GIT_ERROR_CHECK_ALLOC(location);
1054
1101
 
1055
1102
  if (!WinHttpQueryHeaders(s->request,
1056
1103
  WINHTTP_QUERY_LOCATION,
@@ -1058,14 +1105,14 @@ replay:
1058
1105
  location,
1059
1106
  &location_length,
1060
1107
  WINHTTP_NO_HEADER_INDEX)) {
1061
- giterr_set(GITERR_OS, "failed to read Location header");
1108
+ git_error_set(GIT_ERROR_OS, "failed to read Location header");
1062
1109
  git__free(location);
1063
1110
  return -1;
1064
1111
  }
1065
1112
 
1066
1113
  /* Convert the Location header to UTF-8 */
1067
1114
  if (git__utf16_to_8_alloc(&location8, location) < 0) {
1068
- giterr_set(GITERR_OS, "failed to convert Location header to UTF-8");
1115
+ git_error_set(GIT_ERROR_OS, "failed to convert Location header to UTF-8");
1069
1116
  git__free(location);
1070
1117
  return -1;
1071
1118
  }
@@ -1077,7 +1124,7 @@ replay:
1077
1124
 
1078
1125
  if (!git__prefixcmp_icase(location8, prefix_https)) {
1079
1126
  /* Upgrade to secure connection; disconnect and start over */
1080
- if (gitno_connection_data_from_url(&t->connection_data, location8, s->service_url) < 0) {
1127
+ if (gitno_connection_data_handle_redirect(&t->server.url, location8, s->service_url) < 0) {
1081
1128
  git__free(location8);
1082
1129
  return -1;
1083
1130
  }
@@ -1092,72 +1139,39 @@ replay:
1092
1139
  goto replay;
1093
1140
  }
1094
1141
 
1095
- /* Handle proxy authentication failures */
1096
- if (status_code == HTTP_STATUS_PROXY_AUTH_REQ) {
1097
- int allowed_types;
1098
-
1099
- if (parse_unauthorized_response(s->request, &allowed_types, &t->auth_mechanisms) < 0)
1100
- return -1;
1101
-
1102
- /* TODO: extract the username from the url, no payload? */
1103
- if (t->owner->proxy.credentials) {
1104
- int cred_error = 1;
1105
- cred_error = t->owner->proxy.credentials(&t->proxy_cred, t->owner->proxy.url, NULL, allowed_types, t->owner->proxy.payload);
1106
-
1107
- if (cred_error < 0)
1108
- return cred_error;
1109
- }
1110
-
1111
- winhttp_stream_close(s);
1112
- goto replay;
1113
- }
1114
-
1115
1142
  /* Handle authentication failures */
1116
- if (HTTP_STATUS_DENIED == status_code && get_verb == s->verb) {
1117
- int allowed_types;
1118
-
1119
- if (parse_unauthorized_response(s->request, &allowed_types, &t->auth_mechanisms) < 0)
1120
- return -1;
1121
-
1122
- if (allowed_types) {
1123
- int cred_error = 1;
1124
-
1125
- git_cred_free(t->cred);
1126
- t->cred = NULL;
1127
- /* Start with the user-supplied credential callback, if present */
1128
- if (t->owner->cred_acquire_cb) {
1129
- cred_error = t->owner->cred_acquire_cb(&t->cred, t->owner->url,
1130
- t->connection_data.user, allowed_types, t->owner->cred_acquire_payload);
1131
-
1132
- /* Treat GIT_PASSTHROUGH as though git_cred_acquire_cb isn't set */
1133
- if (cred_error == GIT_PASSTHROUGH)
1134
- cred_error = 1;
1135
- else if (cred_error < 0)
1136
- return cred_error;
1137
- }
1138
-
1139
- /* Invoke the fallback credentials acquisition callback if necessary */
1140
- if (cred_error > 0) {
1141
- cred_error = fallback_cred_acquire_cb(&t->cred, t->owner->url,
1142
- t->connection_data.user, allowed_types, NULL);
1143
-
1144
- if (cred_error < 0)
1145
- return cred_error;
1146
- }
1147
-
1148
- if (!cred_error) {
1149
- assert(t->cred);
1150
-
1151
- winhttp_stream_close(s);
1152
-
1153
- /* Successfully acquired a credential */
1154
- goto replay;
1155
- }
1143
+ if (status_code == HTTP_STATUS_DENIED) {
1144
+ int error = acquire_credentials(s->request,
1145
+ &t->server,
1146
+ t->owner->url,
1147
+ t->owner->cred_acquire_cb,
1148
+ t->owner->cred_acquire_payload);
1149
+
1150
+ if (error < 0) {
1151
+ return error;
1152
+ } else if (!error) {
1153
+ assert(t->server.cred);
1154
+ winhttp_stream_close(s);
1155
+ goto replay;
1156
+ }
1157
+ } else if (status_code == HTTP_STATUS_PROXY_AUTH_REQ) {
1158
+ int error = acquire_credentials(s->request,
1159
+ &t->proxy,
1160
+ t->owner->proxy.url,
1161
+ t->owner->proxy.credentials,
1162
+ t->owner->proxy.payload);
1163
+
1164
+ if (error < 0) {
1165
+ return error;
1166
+ } else if (!error) {
1167
+ assert(t->proxy.cred);
1168
+ winhttp_stream_close(s);
1169
+ goto replay;
1156
1170
  }
1157
1171
  }
1158
1172
 
1159
1173
  if (HTTP_STATUS_OK != status_code) {
1160
- giterr_set(GITERR_NET, "request failed with status code: %d", status_code);
1174
+ git_error_set(GIT_ERROR_NET, "request failed with status code: %lu", status_code);
1161
1175
  return -1;
1162
1176
  }
1163
1177
 
@@ -1168,7 +1182,7 @@ replay:
1168
1182
  p_snprintf(expected_content_type_8, MAX_CONTENT_TYPE_LEN, "application/x-git-%s-advertisement", s->service);
1169
1183
 
1170
1184
  if (git__utf8_to_16(expected_content_type, MAX_CONTENT_TYPE_LEN, expected_content_type_8) < 0) {
1171
- giterr_set(GITERR_OS, "failed to convert expected content-type to wide characters");
1185
+ git_error_set(GIT_ERROR_OS, "failed to convert expected content-type to wide characters");
1172
1186
  return -1;
1173
1187
  }
1174
1188
 
@@ -1179,12 +1193,12 @@ replay:
1179
1193
  WINHTTP_HEADER_NAME_BY_INDEX,
1180
1194
  &content_type, &content_type_length,
1181
1195
  WINHTTP_NO_HEADER_INDEX)) {
1182
- giterr_set(GITERR_OS, "failed to retrieve response content-type");
1196
+ git_error_set(GIT_ERROR_OS, "failed to retrieve response content-type");
1183
1197
  return -1;
1184
1198
  }
1185
1199
 
1186
1200
  if (wcscmp(expected_content_type, content_type)) {
1187
- giterr_set(GITERR_NET, "received unexpected content-type");
1201
+ git_error_set(GIT_ERROR_NET, "received unexpected content-type");
1188
1202
  return -1;
1189
1203
  }
1190
1204
 
@@ -1196,7 +1210,7 @@ replay:
1196
1210
  (DWORD)buf_size,
1197
1211
  &dw_bytes_read))
1198
1212
  {
1199
- giterr_set(GITERR_OS, "failed to read data");
1213
+ git_error_set(GIT_ERROR_OS, "failed to read data");
1200
1214
  return -1;
1201
1215
  }
1202
1216
 
@@ -1219,7 +1233,7 @@ static int winhttp_stream_write_single(
1219
1233
 
1220
1234
  /* This implementation of write permits only a single call. */
1221
1235
  if (s->sent_request) {
1222
- giterr_set(GITERR_NET, "subtransport configured for only one write");
1236
+ git_error_set(GIT_ERROR_NET, "subtransport configured for only one write");
1223
1237
  return -1;
1224
1238
  }
1225
1239
 
@@ -1232,7 +1246,7 @@ static int winhttp_stream_write_single(
1232
1246
  (LPCVOID)buffer,
1233
1247
  (DWORD)len,
1234
1248
  &bytes_written)) {
1235
- giterr_set(GITERR_OS, "failed to write data");
1249
+ git_error_set(GIT_ERROR_OS, "failed to write data");
1236
1250
  return -1;
1237
1251
  }
1238
1252
 
@@ -1250,12 +1264,12 @@ static int put_uuid_string(LPWSTR buffer, size_t buffer_len_cch)
1250
1264
  if (RPC_S_OK != status &&
1251
1265
  RPC_S_UUID_LOCAL_ONLY != status &&
1252
1266
  RPC_S_UUID_NO_ADDRESS != status) {
1253
- giterr_set(GITERR_NET, "unable to generate name for temp file");
1267
+ git_error_set(GIT_ERROR_NET, "unable to generate name for temp file");
1254
1268
  return -1;
1255
1269
  }
1256
1270
 
1257
1271
  if (buffer_len_cch < UUID_LENGTH_CCH + 1) {
1258
- giterr_set(GITERR_NET, "buffer too small for name of temp file");
1272
+ git_error_set(GIT_ERROR_NET, "buffer too small for name of temp file");
1259
1273
  return -1;
1260
1274
  }
1261
1275
 
@@ -1270,7 +1284,7 @@ static int put_uuid_string(LPWSTR buffer, size_t buffer_len_cch)
1270
1284
  uuid.Data4[4], uuid.Data4[5], uuid.Data4[6], uuid.Data4[7]);
1271
1285
 
1272
1286
  if (result < UUID_LENGTH_CCH) {
1273
- giterr_set(GITERR_OS, "unable to generate name for temp file");
1287
+ git_error_set(GIT_ERROR_OS, "unable to generate name for temp file");
1274
1288
  return -1;
1275
1289
  }
1276
1290
 
@@ -1282,7 +1296,7 @@ static int get_temp_file(LPWSTR buffer, DWORD buffer_len_cch)
1282
1296
  size_t len;
1283
1297
 
1284
1298
  if (!GetTempPathW(buffer_len_cch, buffer)) {
1285
- giterr_set(GITERR_OS, "failed to get temp path");
1299
+ git_error_set(GIT_ERROR_OS, "failed to get temp path");
1286
1300
  return -1;
1287
1301
  }
1288
1302
 
@@ -1325,13 +1339,13 @@ static int winhttp_stream_write_buffered(
1325
1339
 
1326
1340
  if (INVALID_HANDLE_VALUE == s->post_body) {
1327
1341
  s->post_body = NULL;
1328
- giterr_set(GITERR_OS, "failed to create temporary file");
1342
+ git_error_set(GIT_ERROR_OS, "failed to create temporary file");
1329
1343
  return -1;
1330
1344
  }
1331
1345
  }
1332
1346
 
1333
1347
  if (!WriteFile(s->post_body, buffer, (DWORD)len, &bytes_written, NULL)) {
1334
- giterr_set(GITERR_OS, "failed to write to temporary file");
1348
+ git_error_set(GIT_ERROR_OS, "failed to write to temporary file");
1335
1349
  return -1;
1336
1350
  }
1337
1351
 
@@ -1358,7 +1372,7 @@ static int winhttp_stream_write_chunked(
1358
1372
  if (!WinHttpAddRequestHeaders(s->request,
1359
1373
  transfer_encoding, (ULONG) -1L,
1360
1374
  WINHTTP_ADDREQ_FLAG_ADD)) {
1361
- giterr_set(GITERR_OS, "failed to add a header to the request");
1375
+ git_error_set(GIT_ERROR_OS, "failed to add a header to the request");
1362
1376
  return -1;
1363
1377
  }
1364
1378
 
@@ -1385,8 +1399,10 @@ static int winhttp_stream_write_chunked(
1385
1399
  /* Append as much to the buffer as we can */
1386
1400
  int count = (int)min(CACHED_POST_BODY_BUF_SIZE - s->chunk_buffer_len, len);
1387
1401
 
1388
- if (!s->chunk_buffer)
1402
+ if (!s->chunk_buffer) {
1389
1403
  s->chunk_buffer = git__malloc(CACHED_POST_BODY_BUF_SIZE);
1404
+ GIT_ERROR_CHECK_ALLOC(s->chunk_buffer);
1405
+ }
1390
1406
 
1391
1407
  memcpy(s->chunk_buffer + s->chunk_buffer_len, buffer, count);
1392
1408
  s->chunk_buffer_len += count;
@@ -1427,7 +1443,7 @@ static int winhttp_stream_alloc(winhttp_subtransport *t, winhttp_stream **stream
1427
1443
  return -1;
1428
1444
 
1429
1445
  s = git__calloc(1, sizeof(winhttp_stream));
1430
- GITERR_CHECK_ALLOC(s);
1446
+ GIT_ERROR_CHECK_ALLOC(s);
1431
1447
 
1432
1448
  s->parent.subtransport = &t->parent;
1433
1449
  s->parent.read = winhttp_stream_read;
@@ -1511,7 +1527,7 @@ static int winhttp_action(
1511
1527
  int ret = -1;
1512
1528
 
1513
1529
  if (!t->connection)
1514
- if ((ret = gitno_connection_data_from_url(&t->connection_data, url, NULL)) < 0 ||
1530
+ if ((ret = git_net_url_parse(&t->server.url, url)) < 0 ||
1515
1531
  (ret = winhttp_connect(t)) < 0)
1516
1532
  return ret;
1517
1533
 
@@ -1553,24 +1569,17 @@ static int winhttp_close(git_smart_subtransport *subtransport)
1553
1569
  {
1554
1570
  winhttp_subtransport *t = (winhttp_subtransport *)subtransport;
1555
1571
 
1556
- gitno_connection_data_free_ptrs(&t->connection_data);
1557
- memset(&t->connection_data, 0x0, sizeof(gitno_connection_data));
1558
- gitno_connection_data_free_ptrs(&t->proxy_connection_data);
1559
- memset(&t->proxy_connection_data, 0x0, sizeof(gitno_connection_data));
1560
-
1561
- if (t->cred) {
1562
- t->cred->free(t->cred);
1563
- t->cred = NULL;
1564
- }
1572
+ git_net_url_dispose(&t->server.url);
1573
+ git_net_url_dispose(&t->proxy.url);
1565
1574
 
1566
- if (t->proxy_cred) {
1567
- t->proxy_cred->free(t->proxy_cred);
1568
- t->proxy_cred = NULL;
1575
+ if (t->server.cred) {
1576
+ t->server.cred->free(t->server.cred);
1577
+ t->server.cred = NULL;
1569
1578
  }
1570
1579
 
1571
- if (t->url_cred) {
1572
- t->url_cred->free(t->url_cred);
1573
- t->url_cred = NULL;
1580
+ if (t->proxy.cred) {
1581
+ t->proxy.cred->free(t->proxy.cred);
1582
+ t->proxy.cred = NULL;
1574
1583
  }
1575
1584
 
1576
1585
  return winhttp_close_connection(t);
@@ -1595,7 +1604,7 @@ int git_smart_subtransport_http(git_smart_subtransport **out, git_transport *own
1595
1604
  return -1;
1596
1605
 
1597
1606
  t = git__calloc(1, sizeof(winhttp_subtransport));
1598
- GITERR_CHECK_ALLOC(t);
1607
+ GIT_ERROR_CHECK_ALLOC(t);
1599
1608
 
1600
1609
  t->owner = (transport_smart *)owner;
1601
1610
  t->parent.action = winhttp_action;