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
@@ -12,11 +12,11 @@
12
12
  #include "git2.h"
13
13
  #include "auth.h"
14
14
 
15
- #if defined(GIT_GSSAPI) || defined(GIT_GSSFRAMEWORK)
15
+ #ifdef GIT_GSSAPI
16
16
 
17
17
  extern int git_http_auth_negotiate(
18
18
  git_http_auth_context **out,
19
- const git_net_url *url);
19
+ const gitno_connection_data *connection_data);
20
20
 
21
21
  #else
22
22
 
@@ -5,10 +5,10 @@
5
5
  * a Linking Exception. For full terms see the included COPYING file.
6
6
  */
7
7
 
8
- #include "common.h"
8
+ #include "cred.h"
9
9
 
10
- #include "git2/cred.h"
11
- #include "git2/sys/cred.h"
10
+ #include "git2.h"
11
+ #include "smart.h"
12
12
  #include "git2/cred_helpers.h"
13
13
 
14
14
  static int git_cred_ssh_key_type_new(
@@ -27,7 +27,7 @@ int git_cred_has_username(git_cred *cred)
27
27
  return 1;
28
28
  }
29
29
 
30
- const char *git_cred_get_username(git_cred *cred)
30
+ const char *git_cred__username(git_cred *cred)
31
31
  {
32
32
  switch (cred->credtype) {
33
33
  case GIT_CREDTYPE_USERNAME:
@@ -88,7 +88,7 @@ int git_cred_userpass_plaintext_new(
88
88
  assert(cred && username && password);
89
89
 
90
90
  c = git__malloc(sizeof(git_cred_userpass_plaintext));
91
- GIT_ERROR_CHECK_ALLOC(c);
91
+ GITERR_CHECK_ALLOC(c);
92
92
 
93
93
  c->parent.credtype = GIT_CREDTYPE_USERPASS_PLAINTEXT;
94
94
  c->parent.free = plaintext_free;
@@ -217,7 +217,7 @@ int git_cred_ssh_key_memory_new(
217
217
  GIT_UNUSED(privatekey);
218
218
  GIT_UNUSED(passphrase);
219
219
 
220
- git_error_set(GIT_ERROR_INVALID,
220
+ giterr_set(GITERR_INVALID,
221
221
  "this version of libgit2 was not built with ssh memory credentials.");
222
222
  return -1;
223
223
  #endif
@@ -236,25 +236,25 @@ static int git_cred_ssh_key_type_new(
236
236
  assert(username && cred && privatekey);
237
237
 
238
238
  c = git__calloc(1, sizeof(git_cred_ssh_key));
239
- GIT_ERROR_CHECK_ALLOC(c);
239
+ GITERR_CHECK_ALLOC(c);
240
240
 
241
241
  c->parent.credtype = credtype;
242
242
  c->parent.free = ssh_key_free;
243
243
 
244
244
  c->username = git__strdup(username);
245
- GIT_ERROR_CHECK_ALLOC(c->username);
245
+ GITERR_CHECK_ALLOC(c->username);
246
246
 
247
247
  c->privatekey = git__strdup(privatekey);
248
- GIT_ERROR_CHECK_ALLOC(c->privatekey);
248
+ GITERR_CHECK_ALLOC(c->privatekey);
249
249
 
250
250
  if (publickey) {
251
251
  c->publickey = git__strdup(publickey);
252
- GIT_ERROR_CHECK_ALLOC(c->publickey);
252
+ GITERR_CHECK_ALLOC(c->publickey);
253
253
  }
254
254
 
255
255
  if (passphrase) {
256
256
  c->passphrase = git__strdup(passphrase);
257
- GIT_ERROR_CHECK_ALLOC(c->passphrase);
257
+ GITERR_CHECK_ALLOC(c->passphrase);
258
258
  }
259
259
 
260
260
  *cred = &c->parent;
@@ -264,7 +264,7 @@ static int git_cred_ssh_key_type_new(
264
264
  int git_cred_ssh_interactive_new(
265
265
  git_cred **out,
266
266
  const char *username,
267
- git_cred_ssh_interactive_cb prompt_callback,
267
+ git_cred_ssh_interactive_callback prompt_callback,
268
268
  void *payload)
269
269
  {
270
270
  git_cred_ssh_interactive *c;
@@ -272,13 +272,13 @@ int git_cred_ssh_interactive_new(
272
272
  assert(out && username && prompt_callback);
273
273
 
274
274
  c = git__calloc(1, sizeof(git_cred_ssh_interactive));
275
- GIT_ERROR_CHECK_ALLOC(c);
275
+ GITERR_CHECK_ALLOC(c);
276
276
 
277
277
  c->parent.credtype = GIT_CREDTYPE_SSH_INTERACTIVE;
278
278
  c->parent.free = ssh_interactive_free;
279
279
 
280
280
  c->username = git__strdup(username);
281
- GIT_ERROR_CHECK_ALLOC(c->username);
281
+ GITERR_CHECK_ALLOC(c->username);
282
282
 
283
283
  c->prompt_callback = prompt_callback;
284
284
  c->payload = payload;
@@ -293,13 +293,13 @@ int git_cred_ssh_key_from_agent(git_cred **cred, const char *username) {
293
293
  assert(username && cred);
294
294
 
295
295
  c = git__calloc(1, sizeof(git_cred_ssh_key));
296
- GIT_ERROR_CHECK_ALLOC(c);
296
+ GITERR_CHECK_ALLOC(c);
297
297
 
298
298
  c->parent.credtype = GIT_CREDTYPE_SSH_KEY;
299
299
  c->parent.free = ssh_key_free;
300
300
 
301
301
  c->username = git__strdup(username);
302
- GIT_ERROR_CHECK_ALLOC(c->username);
302
+ GITERR_CHECK_ALLOC(c->username);
303
303
 
304
304
  c->privatekey = NULL;
305
305
 
@@ -312,7 +312,7 @@ int git_cred_ssh_custom_new(
312
312
  const char *username,
313
313
  const char *publickey,
314
314
  size_t publickey_len,
315
- git_cred_sign_cb sign_callback,
315
+ git_cred_sign_callback sign_callback,
316
316
  void *payload)
317
317
  {
318
318
  git_cred_ssh_custom *c;
@@ -320,17 +320,17 @@ int git_cred_ssh_custom_new(
320
320
  assert(username && cred);
321
321
 
322
322
  c = git__calloc(1, sizeof(git_cred_ssh_custom));
323
- GIT_ERROR_CHECK_ALLOC(c);
323
+ GITERR_CHECK_ALLOC(c);
324
324
 
325
325
  c->parent.credtype = GIT_CREDTYPE_SSH_CUSTOM;
326
326
  c->parent.free = ssh_custom_free;
327
327
 
328
328
  c->username = git__strdup(username);
329
- GIT_ERROR_CHECK_ALLOC(c->username);
329
+ GITERR_CHECK_ALLOC(c->username);
330
330
 
331
331
  if (publickey_len > 0) {
332
332
  c->publickey = git__malloc(publickey_len);
333
- GIT_ERROR_CHECK_ALLOC(c->publickey);
333
+ GITERR_CHECK_ALLOC(c->publickey);
334
334
 
335
335
  memcpy(c->publickey, publickey, publickey_len);
336
336
  }
@@ -350,7 +350,7 @@ int git_cred_default_new(git_cred **cred)
350
350
  assert(cred);
351
351
 
352
352
  c = git__calloc(1, sizeof(git_cred_default));
353
- GIT_ERROR_CHECK_ALLOC(c);
353
+ GITERR_CHECK_ALLOC(c);
354
354
 
355
355
  c->credtype = GIT_CREDTYPE_DEFAULT;
356
356
  c->free = default_free;
@@ -368,10 +368,10 @@ int git_cred_username_new(git_cred **cred, const char *username)
368
368
 
369
369
  len = strlen(username);
370
370
 
371
- GIT_ERROR_CHECK_ALLOC_ADD(&allocsize, sizeof(git_cred_username), len);
372
- GIT_ERROR_CHECK_ALLOC_ADD(&allocsize, allocsize, 1);
371
+ GITERR_CHECK_ALLOC_ADD(&allocsize, sizeof(git_cred_username), len);
372
+ GITERR_CHECK_ALLOC_ADD(&allocsize, allocsize, 1);
373
373
  c = git__malloc(allocsize);
374
- GIT_ERROR_CHECK_ALLOC(c);
374
+ GITERR_CHECK_ALLOC(c);
375
375
 
376
376
  c->parent.credtype = GIT_CREDTYPE_USERNAME;
377
377
  c->parent.free = username_free;
@@ -4,14 +4,13 @@
4
4
  * This file is part of libgit2, distributed under the GNU GPL v2 with
5
5
  * a Linking Exception. For full terms see the included COPYING file.
6
6
  */
7
-
8
- #ifndef INCLUDE_allocators_crtdbg_h
9
- #define INCLUDE_allocators_crtdbg_h
7
+ #ifndef INCLUDE_transports_cred_h__
8
+ #define INCLUDE_transports_cred_h__
10
9
 
11
10
  #include "common.h"
12
11
 
13
- #include "alloc.h"
12
+ #include "git2/transport.h"
14
13
 
15
- int git_win32_crtdbg_init_allocator(git_allocator *allocator);
14
+ const char *git_cred__username(git_cred *cred);
16
15
 
17
16
  #endif
@@ -47,7 +47,7 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url)
47
47
 
48
48
  delim = strchr(url, '/');
49
49
  if (delim == NULL) {
50
- git_error_set(GIT_ERROR_NET, "malformed URL");
50
+ giterr_set(GITERR_NET, "malformed URL");
51
51
  return -1;
52
52
  }
53
53
 
@@ -75,19 +75,19 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url)
75
75
 
76
76
  static int send_command(git_proto_stream *s)
77
77
  {
78
- git_buf request = GIT_BUF_INIT;
79
78
  int error;
79
+ git_buf request = GIT_BUF_INIT;
80
80
 
81
- if ((error = gen_proto(&request, s->cmd, s->url)) < 0)
82
- goto cleanup;
83
-
84
- if ((error = git_stream__write_full(s->io, request.ptr, request.size, 0)) < 0)
81
+ error = gen_proto(&request, s->cmd, s->url);
82
+ if (error < 0)
85
83
  goto cleanup;
86
84
 
87
- s->sent_command = 1;
85
+ error = git_stream_write(s->io, request.ptr, request.size, 0);
86
+ if (error >= 0)
87
+ s->sent_command = 1;
88
88
 
89
89
  cleanup:
90
- git_buf_dispose(&request);
90
+ git_buf_free(&request);
91
91
  return error;
92
92
  }
93
93
 
@@ -121,13 +121,13 @@ static int git_proto_stream_write(
121
121
  const char *buffer,
122
122
  size_t len)
123
123
  {
124
- git_proto_stream *s = (git_proto_stream *)stream;
125
124
  int error;
125
+ git_proto_stream *s = (git_proto_stream *)stream;
126
126
 
127
127
  if (!s->sent_command && (error = send_command(s)) < 0)
128
128
  return error;
129
129
 
130
- return git_stream__write_full(s->io, buffer, len, 0);
130
+ return git_stream_write(s->io, buffer, len, 0);
131
131
  }
132
132
 
133
133
  static void git_proto_stream_free(git_smart_subtransport_stream *stream)
@@ -163,7 +163,7 @@ static int git_proto_stream_alloc(
163
163
  return -1;
164
164
 
165
165
  s = git__calloc(1, sizeof(git_proto_stream));
166
- GIT_ERROR_CHECK_ALLOC(s);
166
+ GITERR_CHECK_ALLOC(s);
167
167
 
168
168
  s->parent.subtransport = &t->parent;
169
169
  s->parent.read = git_proto_stream_read;
@@ -181,7 +181,7 @@ static int git_proto_stream_alloc(
181
181
  if ((git_socket_stream_new(&s->io, host, port)) < 0)
182
182
  return -1;
183
183
 
184
- GIT_ERROR_CHECK_VERSION(s->io, GIT_STREAM_VERSION, "git_stream");
184
+ GITERR_CHECK_VERSION(s->io, GIT_STREAM_VERSION, "git_stream");
185
185
 
186
186
  *stream = &s->parent;
187
187
  return 0;
@@ -192,9 +192,8 @@ static int _git_uploadpack_ls(
192
192
  const char *url,
193
193
  git_smart_subtransport_stream **stream)
194
194
  {
195
- git_net_url urldata = GIT_NET_URL_INIT;
195
+ char *host=NULL, *port=NULL, *path=NULL, *user=NULL, *pass=NULL;
196
196
  const char *stream_url = url;
197
- const char *host, *port;
198
197
  git_proto_stream *s;
199
198
  int error;
200
199
 
@@ -203,15 +202,17 @@ static int _git_uploadpack_ls(
203
202
  if (!git__prefixcmp(url, prefix_git))
204
203
  stream_url += strlen(prefix_git);
205
204
 
206
- if ((error = git_net_url_parse(&urldata, url)) < 0)
205
+ if ((error = gitno_extract_url_parts(&host, &port, &path, &user, &pass, url, GIT_DEFAULT_PORT)) < 0)
207
206
  return error;
208
207
 
209
- host = urldata.host;
210
- port = urldata.port ? urldata.port : GIT_DEFAULT_PORT;
211
-
212
208
  error = git_proto_stream_alloc(t, stream_url, cmd_uploadpack, host, port, stream);
213
209
 
214
- git_net_url_dispose(&urldata);
210
+ git__free(host);
211
+ git__free(port);
212
+ git__free(path);
213
+ git__free(user);
214
+ git__free(pass);
215
+
215
216
 
216
217
  if (error < 0) {
217
218
  git_proto_stream_free(*stream);
@@ -241,7 +242,7 @@ static int _git_uploadpack(
241
242
  return 0;
242
243
  }
243
244
 
244
- git_error_set(GIT_ERROR_NET, "must call UPLOADPACK_LS before UPLOADPACK");
245
+ giterr_set(GITERR_NET, "must call UPLOADPACK_LS before UPLOADPACK");
245
246
  return -1;
246
247
  }
247
248
 
@@ -250,7 +251,7 @@ static int _git_receivepack_ls(
250
251
  const char *url,
251
252
  git_smart_subtransport_stream **stream)
252
253
  {
253
- git_net_url urldata = GIT_NET_URL_INIT;
254
+ char *host=NULL, *port=NULL, *path=NULL, *user=NULL, *pass=NULL;
254
255
  const char *stream_url = url;
255
256
  git_proto_stream *s;
256
257
  int error;
@@ -259,12 +260,16 @@ static int _git_receivepack_ls(
259
260
  if (!git__prefixcmp(url, prefix_git))
260
261
  stream_url += strlen(prefix_git);
261
262
 
262
- if ((error = git_net_url_parse(&urldata, url)) < 0)
263
+ if ((error = gitno_extract_url_parts(&host, &port, &path, &user, &pass, url, GIT_DEFAULT_PORT)) < 0)
263
264
  return error;
264
265
 
265
- error = git_proto_stream_alloc(t, stream_url, cmd_receivepack, urldata.host, urldata.port, stream);
266
+ error = git_proto_stream_alloc(t, stream_url, cmd_receivepack, host, port, stream);
266
267
 
267
- git_net_url_dispose(&urldata);
268
+ git__free(host);
269
+ git__free(port);
270
+ git__free(path);
271
+ git__free(user);
272
+ git__free(pass);
268
273
 
269
274
  if (error < 0) {
270
275
  git_proto_stream_free(*stream);
@@ -293,7 +298,7 @@ static int _git_receivepack(
293
298
  return 0;
294
299
  }
295
300
 
296
- git_error_set(GIT_ERROR_NET, "must call RECEIVEPACK_LS before RECEIVEPACK");
301
+ giterr_set(GITERR_NET, "must call RECEIVEPACK_LS before RECEIVEPACK");
297
302
  return -1;
298
303
  }
299
304
 
@@ -353,7 +358,7 @@ int git_smart_subtransport_git(git_smart_subtransport **out, git_transport *owne
353
358
  return -1;
354
359
 
355
360
  t = git__calloc(1, sizeof(git_subtransport));
356
- GIT_ERROR_CHECK_ALLOC(t);
361
+ GITERR_CHECK_ALLOC(t);
357
362
 
358
363
  t->owner = owner;
359
364
  t->parent.action = _git_action;
@@ -12,22 +12,19 @@
12
12
  #include "git2.h"
13
13
  #include "http_parser.h"
14
14
  #include "buffer.h"
15
- #include "net.h"
16
15
  #include "netops.h"
17
16
  #include "global.h"
18
17
  #include "remote.h"
19
- #include "git2/sys/cred.h"
20
18
  #include "smart.h"
21
19
  #include "auth.h"
22
20
  #include "http.h"
23
21
  #include "auth_negotiate.h"
24
- #include "auth_ntlm.h"
25
22
  #include "streams/tls.h"
26
23
  #include "streams/socket.h"
24
+ #include "streams/curl.h"
27
25
 
28
26
  git_http_auth_scheme auth_schemes[] = {
29
27
  { GIT_AUTHTYPE_NEGOTIATE, "Negotiate", GIT_CREDTYPE_DEFAULT, git_http_auth_negotiate },
30
- { GIT_AUTHTYPE_NTLM, "NTLM", GIT_CREDTYPE_USERPASS_PLAINTEXT, git_http_auth_ntlm },
31
28
  { GIT_AUTHTYPE_BASIC, "Basic", GIT_CREDTYPE_USERPASS_PLAINTEXT, git_http_auth_basic },
32
29
  };
33
30
 
@@ -40,12 +37,6 @@ static const char *receive_pack_service_url = "/git-receive-pack";
40
37
  static const char *get_verb = "GET";
41
38
  static const char *post_verb = "POST";
42
39
 
43
- #define AUTH_HEADER_SERVER "Authorization"
44
- #define AUTH_HEADER_PROXY "Proxy-Authorization"
45
-
46
- #define SERVER_TYPE_REMOTE "remote"
47
- #define SERVER_TYPE_PROXY "proxy"
48
-
49
40
  #define OWNING_SUBTRANSPORT(s) ((http_subtransport *)(s)->parent.subtransport)
50
41
 
51
42
  #define PARSE_ERROR_GENERIC -1
@@ -71,36 +62,17 @@ typedef struct {
71
62
  unsigned chunk_buffer_len;
72
63
  unsigned sent_request : 1,
73
64
  received_response : 1,
74
- chunked : 1;
65
+ chunked : 1,
66
+ redirect_count : 3;
75
67
  } http_stream;
76
68
 
77
- typedef struct {
78
- git_net_url url;
79
- git_stream *stream;
80
-
81
- git_http_authtype_t authtypes;
82
- git_credtype_t credtypes;
83
-
84
- git_cred *cred;
85
- unsigned url_cred_presented : 1,
86
- authenticated : 1;
87
-
88
- git_vector auth_challenges;
89
- git_http_auth_context *auth_context;
90
- } http_server;
91
-
92
69
  typedef struct {
93
70
  git_smart_subtransport parent;
94
71
  transport_smart *owner;
95
- git_stream *gitserver_stream;
72
+ git_stream *io;
73
+ gitno_connection_data connection_data;
96
74
  bool connected;
97
75
 
98
- http_server server;
99
-
100
- http_server proxy;
101
- char *proxy_url;
102
- git_proxy_options proxy_opts;
103
-
104
76
  /* Parser structures */
105
77
  http_parser parser;
106
78
  http_parser_settings settings;
@@ -109,15 +81,17 @@ typedef struct {
109
81
  git_buf parse_header_value;
110
82
  char parse_buffer_data[NETIO_BUFSIZE];
111
83
  char *content_type;
112
- char *content_length;
113
84
  char *location;
85
+ git_vector www_authenticate;
114
86
  enum last_cb last_cb;
115
87
  int parse_error;
116
88
  int error;
117
- unsigned request_count;
118
- unsigned parse_finished : 1,
119
- keepalive : 1,
120
- replay_count : 4;
89
+ unsigned parse_finished : 1;
90
+
91
+ /* Authentication */
92
+ git_cred *cred;
93
+ git_cred *url_cred;
94
+ git_vector auth_contexts;
121
95
  } http_subtransport;
122
96
 
123
97
  typedef struct {
@@ -130,50 +104,94 @@ typedef struct {
130
104
  size_t *bytes_read;
131
105
  } parser_context;
132
106
 
133
- static git_http_auth_scheme *scheme_for_challenge(
134
- const char *challenge,
135
- git_cred *cred)
107
+ static bool credtype_match(git_http_auth_scheme *scheme, void *data)
108
+ {
109
+ unsigned int credtype = *(unsigned int *)data;
110
+
111
+ return !!(scheme->credtypes & credtype);
112
+ }
113
+
114
+ static bool challenge_match(git_http_auth_scheme *scheme, void *data)
115
+ {
116
+ const char *scheme_name = scheme->name;
117
+ const char *challenge = (const char *)data;
118
+ size_t scheme_len;
119
+
120
+ scheme_len = strlen(scheme_name);
121
+ return (strncasecmp(challenge, scheme_name, scheme_len) == 0 &&
122
+ (challenge[scheme_len] == '\0' || challenge[scheme_len] == ' '));
123
+ }
124
+
125
+ static int auth_context_match(
126
+ git_http_auth_context **out,
127
+ http_subtransport *t,
128
+ bool (*scheme_match)(git_http_auth_scheme *scheme, void *data),
129
+ void *data)
136
130
  {
137
131
  git_http_auth_scheme *scheme = NULL;
132
+ git_http_auth_context *context = NULL, *c;
138
133
  size_t i;
139
134
 
135
+ *out = NULL;
136
+
140
137
  for (i = 0; i < ARRAY_SIZE(auth_schemes); i++) {
141
- const char *scheme_name = auth_schemes[i].name;
142
- const git_credtype_t scheme_types = auth_schemes[i].credtypes;
143
- size_t scheme_len;
138
+ if (scheme_match(&auth_schemes[i], data)) {
139
+ scheme = &auth_schemes[i];
140
+ break;
141
+ }
142
+ }
144
143
 
145
- scheme_len = strlen(scheme_name);
144
+ if (!scheme)
145
+ return 0;
146
146
 
147
- if ((!cred || (cred->credtype & scheme_types)) &&
148
- strncasecmp(challenge, scheme_name, scheme_len) == 0 &&
149
- (challenge[scheme_len] == '\0' || challenge[scheme_len] == ' ')) {
150
- scheme = &auth_schemes[i];
147
+ /* See if authentication has already started for this scheme */
148
+ git_vector_foreach(&t->auth_contexts, i, c) {
149
+ if (c->type == scheme->type) {
150
+ context = c;
151
151
  break;
152
152
  }
153
153
  }
154
154
 
155
- return scheme;
155
+ if (!context) {
156
+ if (scheme->init_context(&context, &t->connection_data) < 0)
157
+ return -1;
158
+ else if (!context)
159
+ return 0;
160
+ else if (git_vector_insert(&t->auth_contexts, context) < 0)
161
+ return -1;
162
+ }
163
+
164
+ *out = context;
165
+
166
+ return 0;
156
167
  }
157
168
 
158
- static int apply_credentials(
159
- git_buf *buf,
160
- http_server *server,
161
- const char *header_name)
169
+ static int apply_credentials(git_buf *buf, http_subtransport *t)
162
170
  {
163
- git_buf token = GIT_BUF_INIT;
164
- int error = 0;
171
+ git_cred *cred = t->cred;
172
+ git_http_auth_context *context;
173
+
174
+ /* Apply the credentials given to us in the URL */
175
+ if (!cred && t->connection_data.user && t->connection_data.pass) {
176
+ if (!t->url_cred &&
177
+ git_cred_userpass_plaintext_new(&t->url_cred,
178
+ t->connection_data.user, t->connection_data.pass) < 0)
179
+ return -1;
180
+
181
+ cred = t->url_cred;
182
+ }
165
183
 
166
- if (!server->auth_context)
167
- goto done;
184
+ if (!cred)
185
+ return 0;
168
186
 
169
- if ((error = server->auth_context->next_token(&token, server->auth_context, server->cred)) < 0)
170
- goto done;
187
+ /* Get or create a context for the best scheme for this cred type */
188
+ if (auth_context_match(&context, t, credtype_match, &cred->credtype) < 0)
189
+ return -1;
171
190
 
172
- error = git_buf_printf(buf, "%s: %s\r\n", header_name, token.ptr);
191
+ if (!context)
192
+ return 0;
173
193
 
174
- done:
175
- git_buf_dispose(&token);
176
- return error;
194
+ return context->next_token(buf, context, cred);
177
195
  }
178
196
 
179
197
  static int gen_request(
@@ -182,29 +200,15 @@ static int gen_request(
182
200
  size_t content_length)
183
201
  {
184
202
  http_subtransport *t = OWNING_SUBTRANSPORT(s);
185
- const char *path = t->server.url.path ? t->server.url.path : "/";
203
+ const char *path = t->connection_data.path ? t->connection_data.path : "/";
186
204
  size_t i;
187
205
 
188
- if (t->proxy_opts.type == GIT_PROXY_SPECIFIED)
189
- git_buf_printf(buf, "%s %s://%s:%s%s%s HTTP/1.1\r\n",
190
- s->verb,
191
- t->server.url.scheme,
192
- t->server.url.host,
193
- t->server.url.port,
194
- path, s->service_url);
195
- else
196
- git_buf_printf(buf, "%s %s%s HTTP/1.1\r\n",
197
- s->verb, path, s->service_url);
206
+ git_buf_printf(buf, "%s %s%s HTTP/1.1\r\n", s->verb, path, s->service_url);
198
207
 
199
208
  git_buf_puts(buf, "User-Agent: ");
200
209
  git_http__user_agent(buf);
201
210
  git_buf_puts(buf, "\r\n");
202
- git_buf_printf(buf, "Host: %s", t->server.url.host);
203
-
204
- if (!git_net_url_is_default_port(&t->server.url))
205
- git_buf_printf(buf, ":%s", t->server.url.port);
206
-
207
- git_buf_puts(buf, "\r\n");
211
+ git_buf_printf(buf, "Host: %s\r\n", t->connection_data.host);
208
212
 
209
213
  if (s->chunked || content_length > 0) {
210
214
  git_buf_printf(buf, "Accept: application/x-git-%s-result\r\n", s->service);
@@ -222,12 +226,8 @@ static int gen_request(
222
226
  git_buf_printf(buf, "%s\r\n", t->owner->custom_headers.strings[i]);
223
227
  }
224
228
 
225
- /* Apply proxy and server credentials to the request */
226
- if (t->proxy_opts.type != GIT_PROXY_NONE &&
227
- apply_credentials(buf, &t->proxy, AUTH_HEADER_PROXY) < 0)
228
- return -1;
229
-
230
- if (apply_credentials(buf, &t->server, AUTH_HEADER_SERVER) < 0)
229
+ /* Apply credentials to the request */
230
+ if (apply_credentials(buf, t) < 0)
231
231
  return -1;
232
232
 
233
233
  git_buf_puts(buf, "\r\n");
@@ -238,86 +238,29 @@ static int gen_request(
238
238
  return 0;
239
239
  }
240
240
 
241
- static int set_authentication_challenge(http_server *server)
242
- {
243
- const char *challenge;
244
-
245
- if (git_vector_length(&server->auth_challenges) > 1) {
246
- git_error_set(GIT_ERROR_NET, "received multiple authentication challenges");
247
- return -1;
248
- }
249
-
250
- challenge = git_vector_get(&server->auth_challenges, 0);
251
-
252
- if (server->auth_context->set_challenge)
253
- return server->auth_context->set_challenge(server->auth_context, challenge);
254
- else
255
- return 0;
256
- }
257
-
258
- static int set_authentication_types(http_server *server)
241
+ static int parse_authenticate_response(
242
+ git_vector *www_authenticate,
243
+ http_subtransport *t,
244
+ int *allowed_types)
259
245
  {
260
- git_http_auth_scheme *scheme;
246
+ git_http_auth_context *context;
261
247
  char *challenge;
262
248
  size_t i;
263
249
 
264
- git_vector_foreach(&server->auth_challenges, i, challenge) {
265
- if ((scheme = scheme_for_challenge(challenge, NULL)) != NULL) {
266
- server->authtypes |= scheme->type;
267
- server->credtypes |= scheme->credtypes;
268
- }
269
- }
270
-
271
- return 0;
272
- }
273
-
274
- static bool auth_context_complete(http_server *server)
275
- {
276
- /* If there's no is_complete function, we're always complete */
277
- if (!server->auth_context->is_complete)
278
- return true;
279
-
280
- if (server->auth_context->is_complete(server->auth_context))
281
- return true;
282
-
283
- return false;
284
- }
285
-
286
- static void free_auth_context(http_server *server)
287
- {
288
- if (!server->auth_context)
289
- return;
290
-
291
- if (server->auth_context->free)
292
- server->auth_context->free(server->auth_context);
293
-
294
- server->auth_context = NULL;
295
- }
250
+ git_vector_foreach(www_authenticate, i, challenge) {
251
+ if (auth_context_match(&context, t, challenge_match, challenge) < 0)
252
+ return -1;
253
+ else if (!context)
254
+ continue;
296
255
 
297
- static int parse_authenticate_response(http_server *server)
298
- {
299
- /*
300
- * If we think that we've completed authentication (ie, we've either
301
- * sent a basic credential or we've sent the NTLM/Negotiate response)
302
- * but we've got an authentication request from the server then our
303
- * last authentication did not succeed. Start over.
304
- */
305
- if (server->auth_context && auth_context_complete(server)) {
306
- free_auth_context(server);
256
+ if (context->set_challenge &&
257
+ context->set_challenge(context, challenge) < 0)
258
+ return -1;
307
259
 
308
- server->authenticated = 0;
260
+ *allowed_types |= context->credtypes;
309
261
  }
310
262
 
311
- /*
312
- * If we've begun authentication, give the challenge to the context.
313
- * Otherwise, set up the types to prepare credentials.
314
- */
315
- if (git_vector_length(&server->auth_challenges) == 0)
316
- return 0;
317
- else if (server->auth_context)
318
- return set_authentication_challenge(server);
319
- else
320
- return set_authentication_types(server);
263
+ return 0;
321
264
  }
322
265
 
323
266
  static int on_header_ready(http_subtransport *t)
@@ -326,45 +269,22 @@ static int on_header_ready(http_subtransport *t)
326
269
  git_buf *value = &t->parse_header_value;
327
270
 
328
271
  if (!strcasecmp("Content-Type", git_buf_cstr(name))) {
329
- if (t->content_type) {
330
- git_error_set(GIT_ERROR_NET, "multiple Content-Type headers");
331
- return -1;
332
- }
333
-
334
- t->content_type = git__strdup(git_buf_cstr(value));
335
- GIT_ERROR_CHECK_ALLOC(t->content_type);
336
- }
337
- else if (!strcasecmp("Content-Length", git_buf_cstr(name))) {
338
- if (t->content_length) {
339
- git_error_set(GIT_ERROR_NET, "multiple Content-Length headers");
340
- return -1;
272
+ if (!t->content_type) {
273
+ t->content_type = git__strdup(git_buf_cstr(value));
274
+ GITERR_CHECK_ALLOC(t->content_type);
341
275
  }
342
-
343
- t->content_length = git__strdup(git_buf_cstr(value));
344
- GIT_ERROR_CHECK_ALLOC(t->content_length);
345
- }
346
- else if (!strcasecmp("Proxy-Authenticate", git_buf_cstr(name))) {
347
- char *dup = git__strdup(git_buf_cstr(value));
348
- GIT_ERROR_CHECK_ALLOC(dup);
349
-
350
- if (git_vector_insert(&t->proxy.auth_challenges, dup) < 0)
351
- return -1;
352
276
  }
353
277
  else if (!strcasecmp("WWW-Authenticate", git_buf_cstr(name))) {
354
278
  char *dup = git__strdup(git_buf_cstr(value));
355
- GIT_ERROR_CHECK_ALLOC(dup);
279
+ GITERR_CHECK_ALLOC(dup);
356
280
 
357
- if (git_vector_insert(&t->server.auth_challenges, dup) < 0)
358
- return -1;
281
+ git_vector_insert(&t->www_authenticate, dup);
359
282
  }
360
283
  else if (!strcasecmp("Location", git_buf_cstr(name))) {
361
- if (t->location) {
362
- git_error_set(GIT_ERROR_NET, "multiple Location headers");
363
- return -1;
284
+ if (!t->location) {
285
+ t->location = git__strdup(git_buf_cstr(value));
286
+ GITERR_CHECK_ALLOC(t->location);
364
287
  }
365
-
366
- t->location = git__strdup(git_buf_cstr(value));
367
- GIT_ERROR_CHECK_ALLOC(t->location);
368
288
  }
369
289
 
370
290
  return 0;
@@ -408,204 +328,85 @@ static int on_header_value(http_parser *parser, const char *str, size_t len)
408
328
  return 0;
409
329
  }
410
330
 
411
- GIT_INLINE(void) free_cred(git_cred **cred)
412
- {
413
- if (*cred) {
414
- git_cred_free(*cred);
415
- (*cred) = NULL;
416
- }
417
- }
418
-
419
- static int apply_url_credentials(
420
- git_cred **cred,
421
- unsigned int allowed_types,
422
- const char *username,
423
- const char *password)
424
- {
425
- if (allowed_types & GIT_CREDTYPE_USERPASS_PLAINTEXT)
426
- return git_cred_userpass_plaintext_new(cred, username, password);
427
-
428
- if ((allowed_types & GIT_CREDTYPE_DEFAULT) && *username == '\0' && *password == '\0')
429
- return git_cred_default_new(cred);
430
-
431
- return GIT_PASSTHROUGH;
432
- }
433
-
434
- static int init_auth(http_server *server)
435
- {
436
- git_http_auth_scheme *s, *scheme = NULL;
437
- char *c, *challenge = NULL;
438
- size_t i;
439
- int error;
440
-
441
- git_vector_foreach(&server->auth_challenges, i, c) {
442
- s = scheme_for_challenge(c, server->cred);
443
-
444
- if (s && !!(s->credtypes & server->credtypes)) {
445
- scheme = s;
446
- challenge = c;
447
- break;
448
- }
449
- }
450
-
451
- if (!scheme) {
452
- git_error_set(GIT_ERROR_NET, "no authentication mechanism could be negotiated");
453
- return -1;
454
- }
455
-
456
- if ((error = scheme->init_context(&server->auth_context, &server->url)) == GIT_PASSTHROUGH)
457
- return 0;
458
- else if (error < 0)
459
- return error;
460
-
461
- if (server->auth_context->set_challenge &&
462
- (error = server->auth_context->set_challenge(server->auth_context, challenge)) < 0)
463
- return error;
464
-
465
- return 0;
466
- }
467
-
468
- static int on_auth_required(
469
- http_parser *parser,
470
- http_server *server,
471
- const char *url,
472
- const char *type,
473
- git_cred_acquire_cb callback,
474
- void *callback_payload)
475
- {
476
- parser_context *ctx = (parser_context *) parser->data;
477
- http_subtransport *t = ctx->t;
478
- int error = 1;
479
-
480
- if (parse_authenticate_response(server) < 0) {
481
- t->parse_error = PARSE_ERROR_GENERIC;
482
- return t->parse_error;
483
- }
484
-
485
- /* If we're in the middle of challenge/response auth, continue */
486
- if (parser->status_code == 407 || parser->status_code == 401) {
487
- if (server->auth_context && !auth_context_complete(server)) {
488
- t->parse_error = PARSE_ERROR_REPLAY;
489
- return 0;
490
- }
491
- }
492
-
493
- /* Enforce a reasonable cap on the number of replays */
494
- if (t->replay_count++ >= GIT_HTTP_REPLAY_MAX) {
495
- git_error_set(GIT_ERROR_NET, "too many redirects or authentication replays");
496
- return t->parse_error = PARSE_ERROR_GENERIC;
497
- }
498
-
499
- if (!server->credtypes) {
500
- git_error_set(GIT_ERROR_NET, "%s requested authentication but did not negotiate mechanisms", type);
501
- t->parse_error = PARSE_ERROR_GENERIC;
502
- return t->parse_error;
503
- }
504
-
505
- free_auth_context(server);
506
- free_cred(&server->cred);
507
-
508
- /* Start with URL-specified credentials, if there were any. */
509
- if (!server->url_cred_presented && server->url.username && server->url.password) {
510
- error = apply_url_credentials(&server->cred, server->credtypes, server->url.username, server->url.password);
511
- server->url_cred_presented = 1;
512
-
513
- if (error == GIT_PASSTHROUGH) {
514
- /* treat GIT_PASSTHROUGH as if callback isn't set */
515
- error = 1;
516
- }
517
- }
518
-
519
- if (error > 0 && callback) {
520
- error = callback(&server->cred, url, server->url.username, server->credtypes, callback_payload);
521
-
522
- if (error == GIT_PASSTHROUGH) {
523
- /* treat GIT_PASSTHROUGH as if callback isn't set */
524
- error = 1;
525
- }
526
- }
527
-
528
- if (error > 0) {
529
- git_error_set(GIT_ERROR_NET, "%s authentication required but no callback set",
530
- type);
531
- t->parse_error = PARSE_ERROR_GENERIC;
532
- return t->parse_error;
533
- } else if (error < 0) {
534
- t->error = error;
535
- t->parse_error = PARSE_ERROR_EXT;
536
- return t->parse_error;
537
- }
538
-
539
- assert(server->cred);
540
-
541
- if (!(server->cred->credtype & server->credtypes)) {
542
- git_error_set(GIT_ERROR_NET, "%s credential provider returned an invalid cred type", type);
543
- t->parse_error = PARSE_ERROR_GENERIC;
544
- return t->parse_error;
545
- }
546
-
547
- /* Successfully acquired a credential. Start an auth context. */
548
- if (init_auth(server) < 0) {
549
- t->parse_error = PARSE_ERROR_GENERIC;
550
- return t->parse_error;
551
- }
552
-
553
- t->parse_error = PARSE_ERROR_REPLAY;
554
- return 0;
555
- }
556
-
557
- static void on_auth_success(http_server *server)
558
- {
559
- server->url_cred_presented = 0;
560
- server->authenticated = 1;
561
- }
562
-
563
331
  static int on_headers_complete(http_parser *parser)
564
332
  {
565
333
  parser_context *ctx = (parser_context *) parser->data;
566
334
  http_subtransport *t = ctx->t;
567
335
  http_stream *s = ctx->s;
568
336
  git_buf buf = GIT_BUF_INIT;
337
+ int error = 0, no_callback = 0, allowed_auth_types = 0;
569
338
 
570
339
  /* Both parse_header_name and parse_header_value are populated
571
340
  * and ready for consumption. */
572
- if (t->last_cb == VALUE && on_header_ready(t) < 0)
573
- return t->parse_error = PARSE_ERROR_GENERIC;
341
+ if (VALUE == t->last_cb)
342
+ if (on_header_ready(t) < 0)
343
+ return t->parse_error = PARSE_ERROR_GENERIC;
574
344
 
575
- /* Check for a proxy authentication failure. */
576
- if (parser->status_code == 407 && get_verb == s->verb)
577
- return on_auth_required(
578
- parser,
579
- &t->proxy,
580
- t->proxy_opts.url,
581
- SERVER_TYPE_PROXY,
582
- t->proxy_opts.credentials,
583
- t->proxy_opts.payload);
584
- else
585
- on_auth_success(&t->proxy);
345
+ /* Capture authentication headers which may be a 401 (authentication
346
+ * is not complete) or a 200 (simply informing us that auth *is*
347
+ * complete.)
348
+ */
349
+ if (parse_authenticate_response(&t->www_authenticate, t,
350
+ &allowed_auth_types) < 0)
351
+ return t->parse_error = PARSE_ERROR_GENERIC;
586
352
 
587
353
  /* Check for an authentication failure. */
588
- if (parser->status_code == 401 && get_verb == s->verb)
589
- return on_auth_required(
590
- parser,
591
- &t->server,
592
- t->owner->url,
593
- SERVER_TYPE_REMOTE,
594
- t->owner->cred_acquire_cb,
595
- t->owner->cred_acquire_payload);
596
- else
597
- on_auth_success(&t->server);
354
+ if (parser->status_code == 401 && get_verb == s->verb) {
355
+ if (!t->owner->cred_acquire_cb) {
356
+ no_callback = 1;
357
+ } else {
358
+ if (allowed_auth_types) {
359
+ if (t->cred) {
360
+ t->cred->free(t->cred);
361
+ t->cred = NULL;
362
+ }
363
+
364
+ error = t->owner->cred_acquire_cb(&t->cred,
365
+ t->owner->url,
366
+ t->connection_data.user,
367
+ allowed_auth_types,
368
+ t->owner->cred_acquire_payload);
369
+
370
+ if (error == GIT_PASSTHROUGH) {
371
+ no_callback = 1;
372
+ } else if (error < 0) {
373
+ t->error = error;
374
+ return t->parse_error = PARSE_ERROR_EXT;
375
+ } else {
376
+ assert(t->cred);
377
+
378
+ if (!(t->cred->credtype & allowed_auth_types)) {
379
+ giterr_set(GITERR_NET, "credentials callback returned an invalid cred type");
380
+ return t->parse_error = PARSE_ERROR_GENERIC;
381
+ }
382
+
383
+ /* Successfully acquired a credential. */
384
+ t->parse_error = PARSE_ERROR_REPLAY;
385
+ return 0;
386
+ }
387
+ }
388
+ }
389
+
390
+ if (no_callback) {
391
+ giterr_set(GITERR_NET, "authentication required but no callback set");
392
+ return t->parse_error = PARSE_ERROR_GENERIC;
393
+ }
394
+ }
598
395
 
599
396
  /* Check for a redirect.
600
397
  * Right now we only permit a redirect to the same hostname. */
601
398
  if ((parser->status_code == 301 ||
602
399
  parser->status_code == 302 ||
603
400
  (parser->status_code == 303 && get_verb == s->verb) ||
604
- parser->status_code == 307 ||
605
- parser->status_code == 308) &&
401
+ parser->status_code == 307) &&
606
402
  t->location) {
607
403
 
608
- if (gitno_connection_data_handle_redirect(&t->server.url, t->location, s->service_url) < 0)
404
+ if (s->redirect_count >= 7) {
405
+ giterr_set(GITERR_NET, "too many redirects");
406
+ return t->parse_error = PARSE_ERROR_GENERIC;
407
+ }
408
+
409
+ if (gitno_connection_data_from_url(&t->connection_data, t->location, s->service_url) < 0)
609
410
  return t->parse_error = PARSE_ERROR_GENERIC;
610
411
 
611
412
  /* Set the redirect URL on the stream. This is a transfer of
@@ -617,13 +418,15 @@ static int on_headers_complete(http_parser *parser)
617
418
  t->location = NULL;
618
419
 
619
420
  t->connected = 0;
421
+ s->redirect_count++;
422
+
620
423
  t->parse_error = PARSE_ERROR_REPLAY;
621
424
  return 0;
622
425
  }
623
426
 
624
427
  /* Check for a 200 HTTP status code. */
625
428
  if (parser->status_code != 200) {
626
- git_error_set(GIT_ERROR_NET,
429
+ giterr_set(GITERR_NET,
627
430
  "unexpected HTTP status code: %d",
628
431
  parser->status_code);
629
432
  return t->parse_error = PARSE_ERROR_GENERIC;
@@ -631,7 +434,7 @@ static int on_headers_complete(http_parser *parser)
631
434
 
632
435
  /* The response must contain a Content-Type header. */
633
436
  if (!t->content_type) {
634
- git_error_set(GIT_ERROR_NET, "no Content-Type header in response");
437
+ giterr_set(GITERR_NET, "no Content-Type header in response");
635
438
  return t->parse_error = PARSE_ERROR_GENERIC;
636
439
  }
637
440
 
@@ -649,14 +452,14 @@ static int on_headers_complete(http_parser *parser)
649
452
  return t->parse_error = PARSE_ERROR_GENERIC;
650
453
 
651
454
  if (strcmp(t->content_type, git_buf_cstr(&buf))) {
652
- git_buf_dispose(&buf);
653
- git_error_set(GIT_ERROR_NET,
455
+ git_buf_free(&buf);
456
+ giterr_set(GITERR_NET,
654
457
  "invalid Content-Type: %s",
655
458
  t->content_type);
656
459
  return t->parse_error = PARSE_ERROR_GENERIC;
657
460
  }
658
461
 
659
- git_buf_dispose(&buf);
462
+ git_buf_free(&buf);
660
463
 
661
464
  return 0;
662
465
  }
@@ -667,7 +470,6 @@ static int on_message_complete(http_parser *parser)
667
470
  http_subtransport *t = ctx->t;
668
471
 
669
472
  t->parse_finished = 1;
670
- t->keepalive = http_should_keep_alive(parser);
671
473
 
672
474
  return 0;
673
475
  }
@@ -677,19 +479,22 @@ static int on_body_fill_buffer(http_parser *parser, const char *str, size_t len)
677
479
  parser_context *ctx = (parser_context *) parser->data;
678
480
  http_subtransport *t = ctx->t;
679
481
 
680
- /* If there's no buffer set, we're explicitly ignoring the body. */
681
- if (ctx->buffer) {
682
- if (ctx->buf_size < len) {
683
- git_error_set(GIT_ERROR_NET, "can't fit data in the buffer");
684
- return t->parse_error = PARSE_ERROR_GENERIC;
685
- }
482
+ /* If our goal is to replay the request (either an auth failure or
483
+ * a redirect) then don't bother buffering since we're ignoring the
484
+ * content anyway.
485
+ */
486
+ if (t->parse_error == PARSE_ERROR_REPLAY)
487
+ return 0;
686
488
 
687
- memcpy(ctx->buffer, str, len);
688
- ctx->buffer += len;
689
- ctx->buf_size -= len;
489
+ if (ctx->buf_size < len) {
490
+ giterr_set(GITERR_NET, "can't fit data in the buffer");
491
+ return t->parse_error = PARSE_ERROR_GENERIC;
690
492
  }
691
493
 
494
+ memcpy(ctx->buffer, str, len);
692
495
  *(ctx->bytes_read) += len;
496
+ ctx->buffer += len;
497
+ ctx->buf_size -= len;
693
498
 
694
499
  return 0;
695
500
  }
@@ -697,7 +502,7 @@ static int on_body_fill_buffer(http_parser *parser, const char *str, size_t len)
697
502
  static void clear_parser_state(http_subtransport *t)
698
503
  {
699
504
  http_parser_init(&t->parser, HTTP_RESPONSE);
700
- gitno_buffer_setup_fromstream(t->server.stream,
505
+ gitno_buffer_setup_fromstream(t->io,
701
506
  &t->parse_buffer,
702
507
  t->parse_buffer_data,
703
508
  sizeof(t->parse_buffer_data));
@@ -705,25 +510,20 @@ static void clear_parser_state(http_subtransport *t)
705
510
  t->last_cb = NONE;
706
511
  t->parse_error = 0;
707
512
  t->parse_finished = 0;
708
- t->keepalive = 0;
709
513
 
710
- git_buf_dispose(&t->parse_header_name);
514
+ git_buf_free(&t->parse_header_name);
711
515
  git_buf_init(&t->parse_header_name, 0);
712
516
 
713
- git_buf_dispose(&t->parse_header_value);
517
+ git_buf_free(&t->parse_header_value);
714
518
  git_buf_init(&t->parse_header_value, 0);
715
519
 
716
520
  git__free(t->content_type);
717
521
  t->content_type = NULL;
718
522
 
719
- git__free(t->content_length);
720
- t->content_length = NULL;
721
-
722
523
  git__free(t->location);
723
524
  t->location = NULL;
724
525
 
725
- git_vector_free_deep(&t->proxy.auth_challenges);
726
- git_vector_free_deep(&t->server.auth_challenges);
526
+ git_vector_free_deep(&t->www_authenticate);
727
527
  }
728
528
 
729
529
  static int write_chunk(git_stream *io, const char *buffer, size_t len)
@@ -736,424 +536,117 @@ static int write_chunk(git_stream *io, const char *buffer, size_t len)
736
536
  if (git_buf_oom(&buf))
737
537
  return -1;
738
538
 
739
- if (git_stream__write_full(io, buf.ptr, buf.size, 0) < 0) {
740
- git_buf_dispose(&buf);
539
+ if (git_stream_write(io, buf.ptr, buf.size, 0) < 0) {
540
+ git_buf_free(&buf);
741
541
  return -1;
742
542
  }
743
543
 
744
- git_buf_dispose(&buf);
544
+ git_buf_free(&buf);
745
545
 
746
546
  /* Chunk body */
747
- if (len > 0 && git_stream__write_full(io, buffer, len, 0) < 0)
547
+ if (len > 0 && git_stream_write(io, buffer, len, 0) < 0)
748
548
  return -1;
749
549
 
750
550
  /* Chunk footer */
751
- if (git_stream__write_full(io, "\r\n", 2, 0) < 0)
551
+ if (git_stream_write(io, "\r\n", 2, 0) < 0)
752
552
  return -1;
753
553
 
754
554
  return 0;
755
555
  }
756
556
 
757
- static int load_proxy_config(http_subtransport *t)
557
+ static int apply_proxy_config(http_subtransport *t)
758
558
  {
759
559
  int error;
560
+ git_proxy_t proxy_type;
760
561
 
761
- switch (t->owner->proxy.type) {
762
- case GIT_PROXY_NONE:
562
+ if (!git_stream_supports_proxy(t->io))
763
563
  return 0;
764
564
 
765
- case GIT_PROXY_AUTO:
766
- git__free(t->proxy_url);
767
- t->proxy_url = NULL;
768
-
769
- git_proxy_options_init(&t->proxy_opts, GIT_PROXY_OPTIONS_VERSION);
770
-
771
- if ((error = git_remote__get_http_proxy(t->owner->owner,
772
- !strcmp(t->server.url.scheme, "https"), &t->proxy_url)) < 0)
773
- return error;
774
-
775
- if (!t->proxy_url)
776
- return 0;
777
-
778
- t->proxy_opts.type = GIT_PROXY_SPECIFIED;
779
- t->proxy_opts.url = t->proxy_url;
780
- t->proxy_opts.credentials = t->owner->proxy.credentials;
781
- t->proxy_opts.certificate_check = t->owner->proxy.certificate_check;
782
- t->proxy_opts.payload = t->owner->proxy.payload;
783
- break;
565
+ proxy_type = t->owner->proxy.type;
784
566
 
785
- case GIT_PROXY_SPECIFIED:
786
- memcpy(&t->proxy_opts, &t->owner->proxy, sizeof(git_proxy_options));
787
- break;
788
-
789
- default:
790
- assert(0);
791
- return -1;
792
- }
793
-
794
- git_net_url_dispose(&t->proxy.url);
795
-
796
- return git_net_url_parse(&t->proxy.url, t->proxy_opts.url);
797
- }
798
-
799
- static int check_certificate(
800
- git_stream *stream,
801
- git_net_url *url,
802
- int is_valid,
803
- git_transport_certificate_check_cb cert_cb,
804
- void *cert_cb_payload)
805
- {
806
- git_cert *cert;
807
- git_error_state last_error = {0};
808
- int error;
809
-
810
- if ((error = git_stream_certificate(&cert, stream)) < 0)
811
- return error;
812
-
813
- git_error_state_capture(&last_error, GIT_ECERTIFICATE);
814
-
815
- error = cert_cb(cert, is_valid, url->host, cert_cb_payload);
816
-
817
- if (error == GIT_PASSTHROUGH && !is_valid)
818
- return git_error_state_restore(&last_error);
819
- else if (error == GIT_PASSTHROUGH)
820
- error = 0;
821
- else if (error && !git_error_last())
822
- git_error_set(GIT_ERROR_NET, "user rejected certificate for %s", url->host);
823
-
824
- git_error_state_free(&last_error);
825
- return error;
826
- }
567
+ if (proxy_type == GIT_PROXY_NONE)
568
+ return 0;
827
569
 
828
- static int stream_connect(
829
- git_stream *stream,
830
- git_net_url *url,
831
- git_transport_certificate_check_cb cert_cb,
832
- void *cb_payload)
833
- {
834
- int error;
570
+ if (proxy_type == GIT_PROXY_AUTO) {
571
+ char *url;
572
+ git_proxy_options opts = GIT_PROXY_OPTIONS_INIT;
835
573
 
836
- GIT_ERROR_CHECK_VERSION(stream, GIT_STREAM_VERSION, "git_stream");
574
+ if ((error = git_remote__get_http_proxy(t->owner->owner, !!t->connection_data.use_ssl, &url)) < 0)
575
+ return error;
837
576
 
838
- error = git_stream_connect(stream);
577
+ opts.credentials = t->owner->proxy.credentials;
578
+ opts.certificate_check = t->owner->proxy.certificate_check;
579
+ opts.payload = t->owner->proxy.payload;
580
+ opts.type = GIT_PROXY_SPECIFIED;
581
+ opts.url = url;
582
+ error = git_stream_set_proxy(t->io, &opts);
583
+ git__free(url);
839
584
 
840
- if (error && error != GIT_ECERTIFICATE)
841
585
  return error;
842
-
843
- if (git_stream_is_encrypted(stream) && cert_cb != NULL)
844
- error = check_certificate(stream, url, !error, cert_cb, cb_payload);
845
-
846
- return error;
847
- }
848
-
849
- static int gen_connect_req(git_buf *buf, http_subtransport *t)
850
- {
851
- git_buf_printf(buf, "CONNECT %s:%s HTTP/1.1\r\n",
852
- t->server.url.host, t->server.url.port);
853
-
854
- git_buf_puts(buf, "User-Agent: ");
855
- git_http__user_agent(buf);
856
- git_buf_puts(buf, "\r\n");
857
-
858
- git_buf_printf(buf, "Host: %s\r\n", t->proxy.url.host);
859
-
860
- if (apply_credentials(buf, &t->proxy, AUTH_HEADER_PROXY) < 0)
861
- return -1;
862
-
863
- git_buf_puts(buf, "\r\n");
864
-
865
- return git_buf_oom(buf) ? -1 : 0;
866
- }
867
-
868
- static int proxy_headers_complete(http_parser *parser)
869
- {
870
- parser_context *ctx = (parser_context *) parser->data;
871
- http_subtransport *t = ctx->t;
872
-
873
- /* Both parse_header_name and parse_header_value are populated
874
- * and ready for consumption. */
875
- if (t->last_cb == VALUE && on_header_ready(t) < 0)
876
- return t->parse_error = PARSE_ERROR_GENERIC;
877
-
878
- /*
879
- * Capture authentication headers for the proxy or final endpoint,
880
- * these may be 407/401 (authentication is not complete) or a 200
881
- * (informing us that auth has completed).
882
- */
883
- if (parse_authenticate_response(&t->proxy) < 0)
884
- return t->parse_error = PARSE_ERROR_GENERIC;
885
-
886
- /* If we're in the middle of challenge/response auth, continue */
887
- if (parser->status_code == 407) {
888
- if (t->proxy.auth_context && !auth_context_complete(&t->proxy)) {
889
- t->parse_error = PARSE_ERROR_REPLAY;
890
- return 0;
891
- }
892
- }
893
-
894
- /* Enforce a reasonable cap on the number of replays */
895
- if (t->replay_count++ >= GIT_HTTP_REPLAY_MAX) {
896
- git_error_set(GIT_ERROR_NET, "too many redirects or authentication replays");
897
- return t->parse_error = PARSE_ERROR_GENERIC;
898
- }
899
-
900
- /* Check for a proxy authentication failure. */
901
- if (parser->status_code == 407)
902
- return on_auth_required(
903
- parser,
904
- &t->proxy,
905
- t->proxy_opts.url,
906
- SERVER_TYPE_PROXY,
907
- t->proxy_opts.credentials,
908
- t->proxy_opts.payload);
909
-
910
- if (parser->status_code != 200) {
911
- git_error_set(GIT_ERROR_NET, "unexpected status code from proxy: %d",
912
- parser->status_code);
913
- return t->parse_error = PARSE_ERROR_GENERIC;
914
586
  }
915
587
 
916
- if (!t->content_length || strcmp(t->content_length, "0") == 0)
917
- t->parse_finished = 1;
918
-
919
- return 0;
588
+ return git_stream_set_proxy(t->io, &t->owner->proxy);
920
589
  }
921
590
 
922
- static int proxy_connect(
923
- git_stream **out, git_stream *proxy_stream, http_subtransport *t)
591
+ static int http_connect(http_subtransport *t)
924
592
  {
925
- git_buf request = GIT_BUF_INIT;
926
- static http_parser_settings proxy_parser_settings = {0};
927
- size_t bytes_read = 0, bytes_parsed;
928
- parser_context ctx;
929
- bool auth_replay;
930
593
  int error;
931
594
 
932
- /* Use the parser settings only to parser headers. */
933
- proxy_parser_settings.on_header_field = on_header_field;
934
- proxy_parser_settings.on_header_value = on_header_value;
935
- proxy_parser_settings.on_headers_complete = proxy_headers_complete;
936
- proxy_parser_settings.on_message_complete = on_message_complete;
937
-
938
- replay:
939
- clear_parser_state(t);
940
-
941
- auth_replay = false;
942
-
943
- gitno_buffer_setup_fromstream(proxy_stream,
944
- &t->parse_buffer,
945
- t->parse_buffer_data,
946
- sizeof(t->parse_buffer_data));
947
-
948
- if ((error = gen_connect_req(&request, t)) < 0)
949
- goto done;
950
-
951
- if ((error = git_stream__write_full(proxy_stream, request.ptr,
952
- request.size, 0)) < 0)
953
- goto done;
954
-
955
- git_buf_dispose(&request);
956
-
957
- while (!bytes_read && !t->parse_finished) {
958
- t->parse_buffer.offset = 0;
959
-
960
- if ((error = gitno_recv(&t->parse_buffer)) < 0) {
961
- goto done;
962
- } else if (error == 0 && t->request_count > 0) {
963
- /* Server closed a keep-alive socket; reconnect. */
964
- auth_replay = true;
965
- goto done;
966
- } else if (error == 0) {
967
- git_error_set(GIT_ERROR_NET, "unexpected disconnection from server");
968
- error = -1;
969
- goto done;
970
- }
971
-
972
- /*
973
- * This call to http_parser_execute will invoke the on_*
974
- * callbacks. Since we don't care about the body of the response,
975
- * we can set our buffer to NULL.
976
- */
977
- ctx.t = t;
978
- ctx.s = NULL;
979
- ctx.buffer = NULL;
980
- ctx.buf_size = 0;
981
- ctx.bytes_read = &bytes_read;
982
-
983
- /* Set the context, call the parser, then unset the context. */
984
- t->parser.data = &ctx;
985
-
986
- bytes_parsed = http_parser_execute(&t->parser,
987
- &proxy_parser_settings, t->parse_buffer.data, t->parse_buffer.offset);
988
-
989
- t->parser.data = NULL;
990
-
991
- /* Ensure that we didn't get a redirect; unsupported. */
992
- if (t->location) {
993
- git_error_set(GIT_ERROR_NET, "proxy server sent unsupported redirect during CONNECT");
994
- error = -1;
995
- goto done;
996
- }
997
-
998
- /* Replay the request with authentication headers. */
999
- if (PARSE_ERROR_REPLAY == t->parse_error) {
1000
- auth_replay = true;
1001
- } else if (t->parse_error < 0) {
1002
- error = t->parse_error == PARSE_ERROR_EXT ? PARSE_ERROR_EXT : -1;
1003
- goto done;
1004
- }
1005
-
1006
- if (bytes_parsed != t->parse_buffer.offset) {
1007
- git_error_set(GIT_ERROR_NET,
1008
- "HTTP parser error: %s",
1009
- http_errno_description((enum http_errno)t->parser.http_errno));
1010
- error = -1;
1011
- goto done;
1012
- }
1013
- }
1014
-
1015
- t->request_count++;
1016
-
1017
- if (auth_replay) {
1018
- if (t->keepalive && t->parse_finished)
1019
- goto replay;
595
+ if (t->connected &&
596
+ http_should_keep_alive(&t->parser) &&
597
+ t->parse_finished)
598
+ return 0;
1020
599
 
1021
- return PARSE_ERROR_REPLAY;
600
+ if (t->io) {
601
+ git_stream_close(t->io);
602
+ git_stream_free(t->io);
603
+ t->io = NULL;
604
+ t->connected = 0;
1022
605
  }
1023
606
 
1024
- if ((error = git_tls_stream_wrap(out, proxy_stream, t->server.url.host)) == 0)
1025
- error = stream_connect(*out, &t->server.url,
1026
- t->owner->certificate_check_cb,
1027
- t->owner->message_cb_payload);
1028
-
1029
- /*
1030
- * Since we've connected via a HTTPS proxy tunnel, we don't behave
1031
- * as if we have an HTTP proxy.
1032
- */
1033
- t->proxy_opts.type = GIT_PROXY_NONE;
1034
- t->replay_count = 0;
1035
- t->request_count = 0;
1036
-
1037
- done:
1038
- return error;
1039
- }
1040
-
1041
- static void reset_auth_connection(http_server *server)
1042
- {
1043
- /*
1044
- * If we've authenticated and we're doing "normal"
1045
- * authentication with a request affinity (Basic, Digest)
1046
- * then we want to _keep_ our context, since authentication
1047
- * survives even through non-keep-alive connections. If
1048
- * we've authenticated and we're doing connection-based
1049
- * authentication (NTLM, Negotiate) - indicated by the presence
1050
- * of an `is_complete` callback - then we need to restart
1051
- * authentication on a new connection.
1052
- */
1053
-
1054
- if (server->authenticated &&
1055
- server->auth_context &&
1056
- server->auth_context->connection_affinity) {
1057
- free_auth_context(server);
1058
-
1059
- server->url_cred_presented = 0;
1060
- server->authenticated = 0;
607
+ if (t->connection_data.use_ssl) {
608
+ error = git_tls_stream_new(&t->io, t->connection_data.host, t->connection_data.port);
609
+ } else {
610
+ #ifdef GIT_CURL
611
+ error = git_curl_stream_new(&t->io, t->connection_data.host, t->connection_data.port);
612
+ #else
613
+ error = git_socket_stream_new(&t->io, t->connection_data.host, t->connection_data.port);
614
+ #endif
1061
615
  }
1062
- }
1063
-
1064
- static int http_connect(http_subtransport *t)
1065
- {
1066
- git_net_url *url;
1067
- git_stream *proxy_stream = NULL, *stream = NULL;
1068
- git_transport_certificate_check_cb cert_cb;
1069
- void *cb_payload;
1070
- int error;
1071
-
1072
- auth_replay:
1073
- if (t->connected && t->keepalive && t->parse_finished)
1074
- return 0;
1075
616
 
1076
- if ((error = load_proxy_config(t)) < 0)
617
+ if (error < 0)
1077
618
  return error;
1078
619
 
1079
- if (t->server.stream) {
1080
- git_stream_close(t->server.stream);
1081
- git_stream_free(t->server.stream);
1082
- t->server.stream = NULL;
1083
- }
1084
-
1085
- if (t->proxy.stream) {
1086
- git_stream_close(t->proxy.stream);
1087
- git_stream_free(t->proxy.stream);
1088
- t->proxy.stream = NULL;
1089
- }
620
+ GITERR_CHECK_VERSION(t->io, GIT_STREAM_VERSION, "git_stream");
1090
621
 
1091
- reset_auth_connection(&t->server);
1092
- reset_auth_connection(&t->proxy);
622
+ apply_proxy_config(t);
1093
623
 
1094
- t->connected = 0;
1095
- t->keepalive = 0;
1096
- t->request_count = 0;
624
+ error = git_stream_connect(t->io);
1097
625
 
1098
- if (t->proxy_opts.type == GIT_PROXY_SPECIFIED) {
1099
- url = &t->proxy.url;
1100
- cert_cb = t->proxy_opts.certificate_check;
1101
- cb_payload = t->proxy_opts.payload;
1102
- } else {
1103
- url = &t->server.url;
1104
- cert_cb = t->owner->certificate_check_cb;
1105
- cb_payload = t->owner->message_cb_payload;
1106
- }
626
+ if ((!error || error == GIT_ECERTIFICATE) && t->owner->certificate_check_cb != NULL &&
627
+ git_stream_is_encrypted(t->io)) {
628
+ git_cert *cert;
629
+ int is_valid = (error == GIT_OK);
1107
630
 
1108
- if (strcmp(url->scheme, "https") == 0)
1109
- error = git_tls_stream_new(&stream, url->host, url->port);
1110
- else
1111
- error = git_socket_stream_new(&stream, url->host, url->port);
631
+ if ((error = git_stream_certificate(&cert, t->io)) < 0)
632
+ return error;
1112
633
 
1113
- if (error < 0)
1114
- goto on_error;
634
+ giterr_clear();
635
+ error = t->owner->certificate_check_cb(cert, is_valid, t->connection_data.host, t->owner->message_cb_payload);
1115
636
 
1116
- if ((error = stream_connect(stream, url, cert_cb, cb_payload)) < 0)
1117
- goto on_error;
637
+ if (error < 0) {
638
+ if (!giterr_last())
639
+ giterr_set(GITERR_NET, "user cancelled certificate check");
1118
640
 
1119
- /*
1120
- * At this point we have a connection to the remote server or to
1121
- * a proxy. If it's a proxy and the remote server is actually
1122
- * an HTTPS connection, then we need to build a CONNECT tunnel.
1123
- */
1124
- if (t->proxy_opts.type == GIT_PROXY_SPECIFIED &&
1125
- strcmp(t->server.url.scheme, "https") == 0) {
1126
- proxy_stream = stream;
1127
- stream = NULL;
1128
-
1129
- error = proxy_connect(&stream, proxy_stream, t);
1130
-
1131
- if (error == PARSE_ERROR_REPLAY) {
1132
- git_stream_close(proxy_stream);
1133
- git_stream_free(proxy_stream);
1134
- goto auth_replay;
1135
- } else if (error < 0) {
1136
- goto on_error;
641
+ return error;
1137
642
  }
1138
643
  }
1139
644
 
1140
- t->proxy.stream = proxy_stream;
1141
- t->server.stream = stream;
645
+ if (error < 0)
646
+ return error;
647
+
1142
648
  t->connected = 1;
1143
649
  return 0;
1144
-
1145
- on_error:
1146
- if (stream) {
1147
- git_stream_close(stream);
1148
- git_stream_free(stream);
1149
- }
1150
-
1151
- if (proxy_stream) {
1152
- git_stream_close(proxy_stream);
1153
- git_stream_free(proxy_stream);
1154
- }
1155
-
1156
- return error;
1157
650
  }
1158
651
 
1159
652
  static int http_stream_read(
@@ -1166,23 +659,26 @@ static int http_stream_read(
1166
659
  http_subtransport *t = OWNING_SUBTRANSPORT(s);
1167
660
  parser_context ctx;
1168
661
  size_t bytes_parsed;
1169
- git_buf request = GIT_BUF_INIT;
1170
- bool auth_replay;
1171
- int error = 0;
1172
662
 
1173
663
  replay:
1174
664
  *bytes_read = 0;
1175
- auth_replay = false;
1176
665
 
1177
666
  assert(t->connected);
1178
667
 
1179
668
  if (!s->sent_request) {
1180
- git_buf_clear(&request);
669
+ git_buf request = GIT_BUF_INIT;
670
+
1181
671
  clear_parser_state(t);
1182
672
 
1183
- if ((error = gen_request(&request, s, 0)) < 0 ||
1184
- (error = git_stream__write_full(t->server.stream, request.ptr, request.size, 0)) < 0)
1185
- goto done;
673
+ if (gen_request(&request, s, 0) < 0)
674
+ return -1;
675
+
676
+ if (git_stream_write(t->io, request.ptr, request.size, 0) < 0) {
677
+ git_buf_free(&request);
678
+ return -1;
679
+ }
680
+
681
+ git_buf_free(&request);
1186
682
 
1187
683
  s->sent_request = 1;
1188
684
  }
@@ -1192,17 +688,15 @@ replay:
1192
688
  assert(s->verb == post_verb);
1193
689
 
1194
690
  /* Flush, if necessary */
1195
- if (s->chunk_buffer_len > 0) {
1196
- if ((error = write_chunk(t->server.stream, s->chunk_buffer, s->chunk_buffer_len)) < 0)
1197
- goto done;
691
+ if (s->chunk_buffer_len > 0 &&
692
+ write_chunk(t->io, s->chunk_buffer, s->chunk_buffer_len) < 0)
693
+ return -1;
1198
694
 
1199
- s->chunk_buffer_len = 0;
1200
- }
695
+ s->chunk_buffer_len = 0;
1201
696
 
1202
697
  /* Write the final chunk. */
1203
- if ((error = git_stream__write_full(t->server.stream,
1204
- "0\r\n\r\n", 5, 0)) < 0)
1205
- goto done;
698
+ if (git_stream_write(t->io, "0\r\n\r\n", 5, 0) < 0)
699
+ return -1;
1206
700
  }
1207
701
 
1208
702
  s->received_response = 1;
@@ -1210,6 +704,7 @@ replay:
1210
704
 
1211
705
  while (!*bytes_read && !t->parse_finished) {
1212
706
  size_t data_offset;
707
+ int error;
1213
708
 
1214
709
  /*
1215
710
  * Make the parse_buffer think it's as full of data as
@@ -1219,37 +714,26 @@ replay:
1219
714
  * data_offset is the actual data offset from which we
1220
715
  * should tell the parser to start reading.
1221
716
  */
1222
- if (buf_size >= t->parse_buffer.len)
717
+ if (buf_size >= t->parse_buffer.len) {
1223
718
  t->parse_buffer.offset = 0;
1224
- else
719
+ } else {
1225
720
  t->parse_buffer.offset = t->parse_buffer.len - buf_size;
721
+ }
1226
722
 
1227
723
  data_offset = t->parse_buffer.offset;
1228
724
 
1229
- if ((error = gitno_recv(&t->parse_buffer)) < 0) {
1230
- goto done;
1231
- } else if (error == 0 && t->request_count > 0) {
1232
- /* Server closed a keep-alive socket; reconnect. */
1233
- auth_replay = true;
1234
- goto done;
1235
- } else if (error == 0) {
1236
- git_error_set(GIT_ERROR_NET, "unexpected disconnection from server");
1237
- error = -1;
1238
- goto done;
1239
- }
725
+ if (gitno_recv(&t->parse_buffer) < 0)
726
+ return -1;
1240
727
 
1241
- /*
1242
- * This call to http_parser_execute will result in invocations
1243
- * of the on_* family of callbacks, including on_body_fill_buffer
1244
- * which will write into the target buffer. Set up the buffer
1245
- * for it to write into _unless_ we got an auth failure; in
1246
- * that case we only care about the headers and don't need to
1247
- * bother copying the body.
1248
- */
728
+ /* This call to http_parser_execute will result in invocations of the
729
+ * on_* family of callbacks. The most interesting of these is
730
+ * on_body_fill_buffer, which is called when data is ready to be copied
731
+ * into the target buffer. We need to marshal the buffer, buf_size, and
732
+ * bytes_read parameters to this callback. */
1249
733
  ctx.t = t;
1250
734
  ctx.s = s;
1251
- ctx.buffer = auth_replay ? NULL : buffer;
1252
- ctx.buf_size = auth_replay ? 0 : buf_size;
735
+ ctx.buffer = buffer;
736
+ ctx.buf_size = buf_size;
1253
737
  ctx.bytes_read = bytes_read;
1254
738
 
1255
739
  /* Set the context, call the parser, then unset the context. */
@@ -1262,40 +746,33 @@ replay:
1262
746
 
1263
747
  t->parser.data = NULL;
1264
748
 
1265
- /* On a 401, read the rest of the response then retry. */
1266
- if (t->parse_error == PARSE_ERROR_REPLAY) {
1267
- auth_replay = true;
1268
- } else if (t->parse_error == PARSE_ERROR_EXT) {
1269
- error = t->error;
1270
- goto done;
1271
- } else if (t->parse_error < 0) {
1272
- error = -1;
1273
- goto done;
749
+ /* If there was a handled authentication failure, then parse_error
750
+ * will have signaled us that we should replay the request. */
751
+ if (PARSE_ERROR_REPLAY == t->parse_error) {
752
+ s->sent_request = 0;
753
+
754
+ if ((error = http_connect(t)) < 0)
755
+ return error;
756
+
757
+ goto replay;
758
+ }
759
+
760
+ if (t->parse_error == PARSE_ERROR_EXT) {
761
+ return t->error;
1274
762
  }
1275
763
 
764
+ if (t->parse_error < 0)
765
+ return -1;
766
+
1276
767
  if (bytes_parsed != t->parse_buffer.offset - data_offset) {
1277
- git_error_set(GIT_ERROR_NET,
768
+ giterr_set(GITERR_NET,
1278
769
  "HTTP parser error: %s",
1279
770
  http_errno_description((enum http_errno)t->parser.http_errno));
1280
- error = -1;
1281
- goto done;
771
+ return -1;
1282
772
  }
1283
773
  }
1284
774
 
1285
- t->request_count++;
1286
-
1287
- if (auth_replay) {
1288
- s->sent_request = 0;
1289
-
1290
- if ((error = http_connect(t)) < 0)
1291
- return error;
1292
-
1293
- goto replay;
1294
- }
1295
-
1296
- done:
1297
- git_buf_dispose(&request);
1298
- return error;
775
+ return 0;
1299
776
  }
1300
777
 
1301
778
  static int http_stream_write_chunked(
@@ -1303,7 +780,7 @@ static int http_stream_write_chunked(
1303
780
  const char *buffer,
1304
781
  size_t len)
1305
782
  {
1306
- http_stream *s = GIT_CONTAINER_OF(stream, http_stream, parent);
783
+ http_stream *s = (http_stream *)stream;
1307
784
  http_subtransport *t = OWNING_SUBTRANSPORT(s);
1308
785
 
1309
786
  assert(t->connected);
@@ -1317,13 +794,12 @@ static int http_stream_write_chunked(
1317
794
  if (gen_request(&request, s, 0) < 0)
1318
795
  return -1;
1319
796
 
1320
- if (git_stream__write_full(t->server.stream, request.ptr,
1321
- request.size, 0) < 0) {
1322
- git_buf_dispose(&request);
797
+ if (git_stream_write(t->io, request.ptr, request.size, 0) < 0) {
798
+ git_buf_free(&request);
1323
799
  return -1;
1324
800
  }
1325
801
 
1326
- git_buf_dispose(&request);
802
+ git_buf_free(&request);
1327
803
 
1328
804
  s->sent_request = 1;
1329
805
  }
@@ -1331,25 +807,22 @@ static int http_stream_write_chunked(
1331
807
  if (len > CHUNK_SIZE) {
1332
808
  /* Flush, if necessary */
1333
809
  if (s->chunk_buffer_len > 0) {
1334
- if (write_chunk(t->server.stream,
1335
- s->chunk_buffer, s->chunk_buffer_len) < 0)
810
+ if (write_chunk(t->io, s->chunk_buffer, s->chunk_buffer_len) < 0)
1336
811
  return -1;
1337
812
 
1338
813
  s->chunk_buffer_len = 0;
1339
814
  }
1340
815
 
1341
816
  /* Write chunk directly */
1342
- if (write_chunk(t->server.stream, buffer, len) < 0)
817
+ if (write_chunk(t->io, buffer, len) < 0)
1343
818
  return -1;
1344
819
  }
1345
820
  else {
1346
821
  /* Append as much to the buffer as we can */
1347
822
  int count = min(CHUNK_SIZE - s->chunk_buffer_len, len);
1348
823
 
1349
- if (!s->chunk_buffer) {
824
+ if (!s->chunk_buffer)
1350
825
  s->chunk_buffer = git__malloc(CHUNK_SIZE);
1351
- GIT_ERROR_CHECK_ALLOC(s->chunk_buffer);
1352
- }
1353
826
 
1354
827
  memcpy(s->chunk_buffer + s->chunk_buffer_len, buffer, count);
1355
828
  s->chunk_buffer_len += count;
@@ -1358,8 +831,7 @@ static int http_stream_write_chunked(
1358
831
 
1359
832
  /* Is the buffer full? If so, then flush */
1360
833
  if (CHUNK_SIZE == s->chunk_buffer_len) {
1361
- if (write_chunk(t->server.stream,
1362
- s->chunk_buffer, s->chunk_buffer_len) < 0)
834
+ if (write_chunk(t->io, s->chunk_buffer, s->chunk_buffer_len) < 0)
1363
835
  return -1;
1364
836
 
1365
837
  s->chunk_buffer_len = 0;
@@ -1379,14 +851,14 @@ static int http_stream_write_single(
1379
851
  const char *buffer,
1380
852
  size_t len)
1381
853
  {
1382
- http_stream *s = GIT_CONTAINER_OF(stream, http_stream, parent);
854
+ http_stream *s = (http_stream *)stream;
1383
855
  http_subtransport *t = OWNING_SUBTRANSPORT(s);
1384
856
  git_buf request = GIT_BUF_INIT;
1385
857
 
1386
858
  assert(t->connected);
1387
859
 
1388
860
  if (s->sent_request) {
1389
- git_error_set(GIT_ERROR_NET, "subtransport configured for only one write");
861
+ giterr_set(GITERR_NET, "subtransport configured for only one write");
1390
862
  return -1;
1391
863
  }
1392
864
 
@@ -1395,25 +867,25 @@ static int http_stream_write_single(
1395
867
  if (gen_request(&request, s, len) < 0)
1396
868
  return -1;
1397
869
 
1398
- if (git_stream__write_full(t->server.stream, request.ptr, request.size, 0) < 0)
870
+ if (git_stream_write(t->io, request.ptr, request.size, 0) < 0)
1399
871
  goto on_error;
1400
872
 
1401
- if (len && git_stream__write_full(t->server.stream, buffer, len, 0) < 0)
873
+ if (len && git_stream_write(t->io, buffer, len, 0) < 0)
1402
874
  goto on_error;
1403
875
 
1404
- git_buf_dispose(&request);
876
+ git_buf_free(&request);
1405
877
  s->sent_request = 1;
1406
878
 
1407
879
  return 0;
1408
880
 
1409
881
  on_error:
1410
- git_buf_dispose(&request);
882
+ git_buf_free(&request);
1411
883
  return -1;
1412
884
  }
1413
885
 
1414
886
  static void http_stream_free(git_smart_subtransport_stream *stream)
1415
887
  {
1416
- http_stream *s = GIT_CONTAINER_OF(stream, http_stream, parent);
888
+ http_stream *s = (http_stream *)stream;
1417
889
 
1418
890
  if (s->chunk_buffer)
1419
891
  git__free(s->chunk_buffer);
@@ -1433,7 +905,7 @@ static int http_stream_alloc(http_subtransport *t,
1433
905
  return -1;
1434
906
 
1435
907
  s = git__calloc(sizeof(http_stream), 1);
1436
- GIT_ERROR_CHECK_ALLOC(s);
908
+ GITERR_CHECK_ALLOC(s);
1437
909
 
1438
910
  s->parent.subtransport = &t->parent;
1439
911
  s->parent.read = http_stream_read;
@@ -1526,24 +998,16 @@ static int http_action(
1526
998
  const char *url,
1527
999
  git_smart_service_t action)
1528
1000
  {
1529
- http_subtransport *t = GIT_CONTAINER_OF(subtransport, http_subtransport, parent);
1001
+ http_subtransport *t = (http_subtransport *)subtransport;
1530
1002
  int ret;
1531
1003
 
1532
- assert(stream);
1004
+ if (!stream)
1005
+ return -1;
1533
1006
 
1534
- /*
1535
- * If we've seen a redirect then preserve the location that we've
1536
- * been given. This is important to continue authorization against
1537
- * the redirect target, not the user-given source; the endpoint may
1538
- * have redirected us from HTTP->HTTPS and is using an auth mechanism
1539
- * that would be insecure in plaintext (eg, HTTP Basic).
1540
- */
1541
- if ((!t->server.url.host || !t->server.url.port || !t->server.url.path) &&
1542
- (ret = git_net_url_parse(&t->server.url, url)) < 0)
1007
+ if ((!t->connection_data.host || !t->connection_data.port || !t->connection_data.path) &&
1008
+ (ret = gitno_connection_data_from_url(&t->connection_data, url, NULL)) < 0)
1543
1009
  return ret;
1544
1010
 
1545
- assert(t->server.url.host && t->server.url.port && t->server.url.path);
1546
-
1547
1011
  if ((ret = http_connect(t)) < 0)
1548
1012
  return ret;
1549
1013
 
@@ -1567,47 +1031,50 @@ static int http_action(
1567
1031
 
1568
1032
  static int http_close(git_smart_subtransport *subtransport)
1569
1033
  {
1570
- http_subtransport *t = GIT_CONTAINER_OF(subtransport, http_subtransport, parent);
1034
+ http_subtransport *t = (http_subtransport *) subtransport;
1035
+ git_http_auth_context *context;
1036
+ size_t i;
1571
1037
 
1572
1038
  clear_parser_state(t);
1573
1039
 
1574
1040
  t->connected = 0;
1575
1041
 
1576
- if (t->server.stream) {
1577
- git_stream_close(t->server.stream);
1578
- git_stream_free(t->server.stream);
1579
- t->server.stream = NULL;
1042
+ if (t->io) {
1043
+ git_stream_close(t->io);
1044
+ git_stream_free(t->io);
1045
+ t->io = NULL;
1580
1046
  }
1581
1047
 
1582
- if (t->proxy.stream) {
1583
- git_stream_close(t->proxy.stream);
1584
- git_stream_free(t->proxy.stream);
1585
- t->proxy.stream = NULL;
1048
+ if (t->cred) {
1049
+ t->cred->free(t->cred);
1050
+ t->cred = NULL;
1586
1051
  }
1587
1052
 
1588
- free_cred(&t->server.cred);
1589
- free_cred(&t->proxy.cred);
1590
-
1591
- free_auth_context(&t->server);
1592
- free_auth_context(&t->proxy);
1053
+ if (t->url_cred) {
1054
+ t->url_cred->free(t->url_cred);
1055
+ t->url_cred = NULL;
1056
+ }
1593
1057
 
1594
- t->server.url_cred_presented = false;
1595
- t->proxy.url_cred_presented = false;
1058
+ git_vector_foreach(&t->auth_contexts, i, context) {
1059
+ if (context->free)
1060
+ context->free(context);
1061
+ }
1596
1062
 
1597
- git_net_url_dispose(&t->server.url);
1598
- git_net_url_dispose(&t->proxy.url);
1063
+ git_vector_clear(&t->auth_contexts);
1599
1064
 
1600
- git__free(t->proxy_url);
1601
- t->proxy_url = NULL;
1065
+ gitno_connection_data_free_ptrs(&t->connection_data);
1066
+ memset(&t->connection_data, 0x0, sizeof(gitno_connection_data));
1602
1067
 
1603
1068
  return 0;
1604
1069
  }
1605
1070
 
1606
1071
  static void http_free(git_smart_subtransport *subtransport)
1607
1072
  {
1608
- http_subtransport *t = GIT_CONTAINER_OF(subtransport, http_subtransport, parent);
1073
+ http_subtransport *t = (http_subtransport *) subtransport;
1609
1074
 
1610
1075
  http_close(subtransport);
1076
+
1077
+ git_vector_free(&t->auth_contexts);
1611
1078
  git__free(t);
1612
1079
  }
1613
1080
 
@@ -1621,7 +1088,7 @@ int git_smart_subtransport_http(git_smart_subtransport **out, git_transport *own
1621
1088
  return -1;
1622
1089
 
1623
1090
  t = git__calloc(sizeof(http_subtransport), 1);
1624
- GIT_ERROR_CHECK_ALLOC(t);
1091
+ GITERR_CHECK_ALLOC(t);
1625
1092
 
1626
1093
  t->owner = (transport_smart *)owner;
1627
1094
  t->parent.action = http_action;