| @@ -2,6 +2,9 @@ use crate::{client::SetServiceResponse, Protocol, Service}; · 1 unmodified line |
| 2 | use bstr::BString; | 2 | use bstr::BString; |
| 3 | use std::{io, net::TcpStream}; | 3 | use std::{io, net::TcpStream}; |
| 4 | | 4 | |
| | 5 | pub mod message; |
| | 6 | pub(crate) mod recv; |
| | 7 | |
| 5 | pub struct Connection<R, W> { | 8 | pub struct Connection<R, W> { |
| 6 | write: W, | 9 | write: W, |
| 7 | line_reader: git_packetline::Reader<R>, | 10 | line_reader: git_packetline::Reader<R>, |
| @@ -10,67 +13,6 @@ pub struct Connection<R, W> { · 2 unmodified lines |
| 10 | protocol: Protocol, | 13 | protocol: Protocol, |
| 11 | } | 14 | } |
| 12 | | 15 | |
| 13 | impl<R, W> crate::client::Transport for Connection<R, W> | | |
| 14 | where | | |
| 15 | R: io::Read, | | |
| 16 | W: io::Write, | | |
| 17 | { | | |
| 18 | } | | |
| 19 | | | |
| 20 | pub mod message { | | |
| 21 | use crate::{Protocol, Service}; | | |
| 22 | use bstr::{BString, ByteVec}; | | |
| 23 | | | |
| 24 | pub fn connect( | | |
| 25 | service: Service, | | |
| 26 | version: Protocol, | | |
| 27 | path: &[u8], | | |
| 28 | virtual_host: Option<&(String, Option<u16>)>, | | |
| 29 | ) -> BString { | | |
| 30 | let mut out = bstr::BString::from(service.as_str()); | | |
| 31 | out.push(b' '); | | |
| 32 | out.extend_from_slice(&path); | | |
| 33 | out.push(0); | | |
| 34 | if let Some((host, port)) = virtual_host { | | |
| 35 | out.push_str("host="); | | |
| 36 | out.extend_from_slice(host.as_bytes()); | | |
| 37 | if let Some(port) = port { | | |
| 38 | out.push_byte(b':'); | | |
| 39 | out.push_str(&format!("{}", port)); | | |
| 40 | } | | |
| 41 | out.push(0); | | |
| 42 | } | | |
| 43 | if version != Protocol::V1 { | | |
| 44 | out.push(0); | | |
| 45 | out.push_str(format!("version={}", version as usize)); | | |
| 46 | out.push(0); | | |
| 47 | } | | |
| 48 | out | | |
| 49 | } | | |
| 50 | } | | |
| 51 | | | |
| 52 | pub(crate) mod recv { | | |
| 53 | use crate::client::Capabilities; | | |
| 54 | use std::io; | | |
| 55 | | | |
| 56 | pub fn capabilties_and_possibly_refs<'a, T: io::Read>( | | |
| 57 | rd: &'a mut git_packetline::Reader<T>, | | |
| 58 | ) -> Result<(Capabilities, Option<Box<dyn io::BufRead + 'a>>), crate::client::Error> { | | |
| 59 | rd.fail_on_err_lines(true); | | |
| 60 | let capabilities = rd | | |
| 61 | .peek_line() | | |
| 62 | .ok_or(crate::client::Error::ExpectedLine("capabilities or version"))???; | | |
| 63 | let (capabilities, delimiter_position) = Capabilities::from_bytes( | | |
| 64 | capabilities | | |
| 65 | .to_text() | | |
| 66 | .ok_or(crate::client::Error::ExpectedDataLine)? | | |
| 67 | .as_slice(), | | |
| 68 | )?; | | |
| 69 | rd.peek_buffer_replace_and_truncate(delimiter_position, b'\n'); | | |
| 70 | Ok((capabilities, Some(Box::new(rd.as_read())))) | | |
| 71 | } | | |
| 72 | } | | |
| 73 | | | |
| 74 | impl<R, W> crate::client::TransportSketch for Connection<R, W> | 16 | impl<R, W> crate::client::TransportSketch for Connection<R, W> |
| 75 | where | 17 | where |
| 76 | R: io::Read, | 18 | R: io::Read, |
| @@ -116,6 +58,13 @@ where · 39 unmodified lines |
| 116 | } | 58 | } |
| 117 | } | 59 | } |
| 118 | | 60 | |
| | 61 | impl<R, W> crate::client::Transport for Connection<R, W> |
| | 62 | where |
| | 63 | R: io::Read, |
| | 64 | W: io::Write, |
| | 65 | { |
| | 66 | } |
| | 67 | |
| 119 | use quick_error::quick_error; | 68 | use quick_error::quick_error; |
| 120 | quick_error! { | 69 | quick_error! { |
| 121 | #[derive(Debug)] | 70 | #[derive(Debug)] |