rugged 0.27.10 → 0.27.10.1

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