Skip to content

Commit 4a3ee11

Browse files
committed
Infrastructure for ssl support
1 parent 8ce889b commit 4a3ee11

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

lib.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ fn main() {
6868
#[feature(macro_rules, struct_variant, globs)];
6969

7070
extern mod extra;
71+
extern mod ssl = "github.com/sfackler/rust-ssl";
7172

7273
use extra::container::Deque;
7374
use extra::ringbuf::RingBuf;
7475
use extra::url::{UserInfo, Url};
76+
use ssl::SslStream;
7577
use std::cell::Cell;
7678
use std::hashmap::HashMap;
7779
use std::rt::io::{Writer, io_error, Decorator};
@@ -379,8 +381,38 @@ fn open_socket(host: &str, port: Port)
379381
Err(SocketError)
380382
}
381383

384+
enum InternalStream {
385+
Normal(TcpStream),
386+
Ssl(SslStream<TcpStream>)
387+
}
388+
389+
impl Reader for InternalStream {
390+
fn read(&mut self, buf: &mut [u8]) -> Option<uint> {
391+
match *self {
392+
Normal(ref mut s) => s.read(buf),
393+
Ssl(ref mut s) => s.read(buf)
394+
}
395+
}
396+
397+
fn eof(&mut self) -> bool {
398+
match *self {
399+
Normal(ref mut s) => s.eof(),
400+
Ssl(ref mut s) => s.eof()
401+
}
402+
}
403+
}
404+
405+
impl Writer for InternalStream {
406+
fn write(&mut self, buf: &[u8]) {
407+
match *self {
408+
Normal(ref mut s) => s.write(buf),
409+
Ssl(ref mut s) => s.write(buf)
410+
}
411+
}
412+
}
413+
382414
struct InnerPostgresConnection {
383-
stream: BufferedStream<TcpStream>,
415+
stream: BufferedStream<InternalStream>,
384416
next_stmt_id: int,
385417
notice_handler: ~PostgresNoticeHandler,
386418
notifications: RingBuf<PostgresNotification>,
@@ -426,7 +458,7 @@ impl InnerPostgresConnection {
426458
};
427459

428460
let mut conn = InnerPostgresConnection {
429-
stream: BufferedStream::new(stream),
461+
stream: BufferedStream::new(Normal(stream)),
430462
next_stmt_id: 0,
431463
notice_handler: ~DefaultNoticeHandler as ~PostgresNoticeHandler,
432464
notifications: RingBuf::new(),
@@ -1286,7 +1318,6 @@ impl RowIndex for int {
12861318
}
12871319

12881320
impl<'self> RowIndex for &'self str {
1289-
#[inline]
12901321
fn idx(&self, stmt: &NormalPostgresStatement) -> uint {
12911322
for (i, desc) in stmt.result_descriptions().iter().enumerate() {
12921323
if desc.name.as_slice() == *self {

test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#[feature(struct_variant, macro_rules, globs)];
22

33
extern mod extra;
4+
extern mod ssl = "github.com/sfackler/rust-ssl";
45

56
use extra::comm::DuplexStream;
67
use extra::future::Future;

0 commit comments

Comments
 (0)