@@ -3,24 +3,25 @@ use std::rt::io::{Decorator, Reader, Writer};
33use std:: rt:: io:: extensions:: { ReaderUtil , ReaderByteConversions ,
44 WriterByteConversions } ;
55use std:: rt:: io:: mem:: { MemWriter , MemReader } ;
6- use std:: hashmap:: HashMap ;
76use std:: sys;
87use std:: vec;
98
109pub static PROTOCOL_VERSION : i32 = 0x0003_0000 ;
1110
1211#[ deriving( ToStr ) ]
1312pub enum BackendMessage {
13+ AuthenticationCleartextPassword ,
14+ AuthenticationMD5Password ( ~[ u8 ] ) ,
1415 AuthenticationOk ,
1516 BackendKeyData ( i32 , i32 ) ,
1617 BindComplete ,
1718 CloseComplete ,
1819 CommandComplete ( ~str ) ,
1920 DataRow ( ~[ Option < ~[ u8 ] > ] ) ,
2021 EmptyQueryResponse ,
21- ErrorResponse ( HashMap < u8 , ~str > ) ,
22+ ErrorResponse ( ~ [ ( u8 , ~str ) ] ) ,
2223 NoData ,
23- NoticeResponse ( HashMap < u8 , ~str > ) ,
24+ NoticeResponse ( ~ [ ( u8 , ~str ) ] ) ,
2425 ParameterDescription ( ~[ i32 ] ) ,
2526 ParameterStatus ( ~str , ~str ) ,
2627 ParseComplete ,
@@ -48,8 +49,9 @@ pub enum FrontendMessage<'self> {
4849 Execute ( & ' self str , i32 ) ,
4950 /// name, query, parameter types
5051 Parse ( & ' self str , & ' self str , & ' self [ i32 ] ) ,
52+ PasswordMessage ( & ' self str ) ,
5153 Query ( & ' self str ) ,
52- StartupMessage ( HashMap < & ' self str , & ' self str > ) ,
54+ StartupMessage ( & ' self [ ( ~ str , ~ str ) ] ) ,
5355 Sync ,
5456 Terminate
5557}
@@ -128,15 +130,19 @@ impl<W: Writer> WriteMessage for W {
128130 buf. write_be_i32_ ( * ty) ;
129131 }
130132 }
133+ PasswordMessage ( password) => {
134+ ident = Some ( 'p' ) ;
135+ buf. write_string ( password) ;
136+ }
131137 Query ( query) => {
132138 ident = Some ( 'Q' ) ;
133139 buf. write_string ( query) ;
134140 }
135141 StartupMessage ( ref params) => {
136142 buf. write_be_i32_ ( PROTOCOL_VERSION ) ;
137- for ( k , v) in params. iter ( ) {
138- buf. write_string ( * k ) ;
139- buf. write_string ( * v ) ;
143+ for & ( ref k , ref v) in params. iter ( ) {
144+ buf. write_string ( k . as_slice ( ) ) ;
145+ buf. write_string ( v . as_slice ( ) ) ;
140146 }
141147 buf. write_u8_ ( 0 ) ;
142148 }
@@ -199,11 +205,11 @@ impl<R: Reader> ReadMessage for R {
199205 '3' => CloseComplete ,
200206 'C' => CommandComplete ( buf. read_string ( ) ) ,
201207 'D' => read_data_row ( & mut buf) ,
202- 'E' => ErrorResponse ( read_hash ( & mut buf) ) ,
208+ 'E' => ErrorResponse ( read_fields ( & mut buf) ) ,
203209 'I' => EmptyQueryResponse ,
204210 'K' => BackendKeyData ( buf. read_be_i32_ ( ) , buf. read_be_i32_ ( ) ) ,
205211 'n' => NoData ,
206- 'N' => NoticeResponse ( read_hash ( & mut buf) ) ,
212+ 'N' => NoticeResponse ( read_fields ( & mut buf) ) ,
207213 'R' => read_auth_message ( & mut buf) ,
208214 'S' => ParameterStatus ( buf. read_string ( ) , buf. read_string ( ) ) ,
209215 't' => read_parameter_description ( & mut buf) ,
@@ -217,15 +223,15 @@ impl<R: Reader> ReadMessage for R {
217223 }
218224}
219225
220- fn read_hash ( buf : & mut MemReader ) -> HashMap < u8 , ~str > {
221- let mut fields = HashMap :: new ( ) ;
226+ fn read_fields ( buf : & mut MemReader ) -> ~ [ ( u8 , ~str ) ] {
227+ let mut fields = ~ [ ] ;
222228 loop {
223229 let ty = buf. read_u8_ ( ) ;
224230 if ty == 0 {
225231 break ;
226232 }
227233
228- fields. insert ( ty, buf. read_string ( ) ) ;
234+ fields. push ( ( ty, buf. read_string ( ) ) ) ;
229235 }
230236
231237 fields
@@ -249,6 +255,8 @@ fn read_data_row(buf: &mut MemReader) -> BackendMessage {
249255fn read_auth_message ( buf : & mut MemReader ) -> BackendMessage {
250256 match buf. read_be_i32_ ( ) {
251257 0 => AuthenticationOk ,
258+ 3 => AuthenticationCleartextPassword ,
259+ 5 => AuthenticationMD5Password ( buf. read_bytes ( 4 ) ) ,
252260 val => fail ! ( "Unknown Authentication identifier `%?`" , val)
253261 }
254262}
0 commit comments