Debian Codegraph @

src/connection/establish.rs

raw symbols SCIP
1 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::HashMaprust-analyzer cargo hashbrown 0.15.5 map/HashMap#;
2
3 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::commonrust-analyzer cargo sqlx-core 0.8.3 common/::StatementCacherust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/StatementCache#;
4 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::connectionrust-analyzer cargo sqlx-postgres 0.8.3 connection/::{saslrust-analyzer cargo sqlx-postgres 0.8.3 connection/sasl/, streamrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/::PgStreamrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream#};
5 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::errorrust-analyzer cargo sqlx-postgres 0.8.3 error/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#;
6 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::iorust-analyzer cargo sqlx-postgres 0.8.3 io/::StatementIdrust-analyzer cargo sqlx-postgres 0.8.3 io/StatementId#;
7 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::messagerust-analyzer cargo sqlx-postgres 0.8.3 message/::{
8 Authenticationrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/Authentication#, BackendKeyDatarust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/BackendKeyData#, BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#, Passwordrust-analyzer cargo sqlx-postgres 0.8.3 message/password/Password#, ReadyForQueryrust-analyzer cargo sqlx-postgres 0.8.3 message/ready_for_query/ReadyForQuery#, Startuprust-analyzer cargo sqlx-postgres 0.8.3 message/startup/Startup#,
9 };
10 use craterust-analyzer cargo sqlx-postgres 0.8.3 crate/::{PgConnectOptionsrust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#, PgConnectionrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnection#};
11
12 use superrust-analyzer cargo sqlx-postgres 0.8.3 connection/::PgConnectionInnerrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnectionInner#;
13
14 // https://www.postgresql.org/docs/current/protocol-flow.html#id-1.10.5.7.3
15 // https://www.postgresql.org/docs/current/protocol-flow.html#id-1.10.5.7.11
16
17 impl PgConnectionrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnection# {
18 pub(craterust-analyzer cargo sqlx-postgres 0.8.3 crate/) async fn establishrust-analyzer cargo sqlx-postgres 0.8.3 connection/establish/impl#[PgConnection]establish().(options: &PgConnectOptionsrust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-postgres 0.8.3 connection/establish/impl#[PgConnection], Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> {
19 // Upgrade to TLS if we were asked to and the server supports it
20 let mut stream = PgStreamrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/PgStream#::connectrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream]connect().(options).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
21
22 // To begin a session, a frontend opens a connection to the server
23 // and sends a startup message.
24
25 let mut params = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
26 // Sets the display format for date and time values,
27 // as well as the rules for interpreting ambiguous date input values.
28 ("DateStyle", "ISO, MDY"),
29 // Sets the client-side encoding (character set).
30 // <https://www.postgresql.org/docs/devel/multibyte.html#MULTIBYTE-CHARSET-SUPPORTED>
31 ("client_encoding", "UTF8"),
32 // Sets the time zone for displaying and interpreting time stamps.
33 ("TimeZone", "UTC"),
34 ];
35
36 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref extra_float_digits) = options.extra_float_digitsrust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#extra_float_digits. {
37 params.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(("extra_float_digits", extra_float_digits));
38 }
39
40 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref application_name) = options.application_namerust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#application_name. {
41 params.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(("application_name", application_name));
42 }
43
44 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref options) = options.optionsrust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#options. {
45 params.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(("options", options));
46 }
47
48 stream.writerust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]write().(Startuprust-analyzer cargo sqlx-postgres 0.8.3 message/startup/Startup# {
49 usernamerust-analyzer cargo sqlx-postgres 0.8.3 message/startup/Startup#username.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&options.usernamerust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#username.),
50 databaserust-analyzer cargo sqlx-postgres 0.8.3 message/startup/Startup#database.: options.databaserust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#database..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().(),
51 paramsrust-analyzer cargo sqlx-postgres 0.8.3 message/startup/Startup#params.: &params,
52 })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
53
54 stream.flushrust-analyzer cargo sqlx-core 0.8.3 net/socket/buffered/impl#[`BufferedSocket<S>`]flush().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
55
56 // The server then uses this information and the contents of
57 // its configuration files (such as pg_hba.conf) to determine whether the connection is
58 // provisionally acceptable, and what additional
59 // authentication is required (if any).
60
61 let mut process_id = 0;
62 let mut secret_key = 0;
63 let transaction_status;
64
65 loop {
66 let message = stream.recvrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream]recv().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
67 match message.formatrust-analyzer cargo sqlx-postgres 0.8.3 message/ReceivedMessage#format. {
68 BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#::Authenticationrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#Authentication# => match message.decoderust-analyzer cargo sqlx-postgres 0.8.3 message/impl#[ReceivedMessage]decode().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
69 Authenticationrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/Authentication#::Okrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/Authentication#Ok# => {
70 // the authentication exchange is successfully completed
71 // do nothing; no more information is required to continue
72 }
73
74 Authenticationrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/Authentication#::CleartextPasswordrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/Authentication#CleartextPassword# => {
75 // The frontend must now send a [PasswordMessage] containing the
76 // password in clear-text form.
77
78 stream
79 .sendrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream]send().(Passwordrust-analyzer cargo sqlx-postgres 0.8.3 message/password/Password#::Cleartextrust-analyzer cargo sqlx-postgres 0.8.3 message/password/Password#Cleartext#(
80 options.passwordrust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#password..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().().unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().(),
81 ))
82 .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
83 }
84
85 Authenticationrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/Authentication#::Md5Passwordrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/Authentication#Md5Password#(body) => {
86 // The frontend must now send a [PasswordMessage] containing the
87 // password (with user name) encrypted via MD5, then encrypted again
88 // using the 4-byte random salt specified in the
89 // [AuthenticationMD5Password] message.
90
91 stream
92 .sendrust-analyzer cargo sqlx-postgres 0.8.3 connection/stream/impl#[PgStream]send().(Passwordrust-analyzer cargo sqlx-postgres 0.8.3 message/password/Password#::Md5rust-analyzer cargo sqlx-postgres 0.8.3 message/password/Password#Md5# {
93 usernamerust-analyzer cargo sqlx-postgres 0.8.3 message/password/Password#Md5#username.: &options.usernamerust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#username.,
94 passwordrust-analyzer cargo sqlx-postgres 0.8.3 message/password/Password#Md5#password.: options.passwordrust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#password..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().().unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().(),
95 saltrust-analyzer cargo sqlx-postgres 0.8.3 message/password/Password#Md5#salt.: body.saltrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/AuthenticationMd5Password#salt.,
96 })
97 .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
98 }
99
100 Authenticationrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/Authentication#::Saslrust-analyzer cargo sqlx-postgres 0.8.3 message/authentication/Authentication#Sasl#(body) => {
101 saslrust-analyzer cargo sqlx-postgres 0.8.3 connection/sasl/::authenticaterust-analyzer cargo sqlx-postgres 0.8.3 connection/sasl/authenticate().(&mut stream, options, body).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
102 }
103
104 method => {
105 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err_protocolrust-analyzer cargo sqlx-core 0.8.3 error/err_protocol!!(
106 "unsupported authentication method: {:?}",
107 method
108 ));
109 }
110 },
111
112 BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#::BackendKeyDatarust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#BackendKeyData# => {
113 // provides secret-key data that the frontend must save if it wants to be
114 // able to issue cancel requests later
115
116 let data: BackendKeyDatarust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/BackendKeyData# = message.decoderust-analyzer cargo sqlx-postgres 0.8.3 message/impl#[ReceivedMessage]decode().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
117
118 process_id = data.process_idrust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/BackendKeyData#process_id.;
119 secret_key = data.secret_keyrust-analyzer cargo sqlx-postgres 0.8.3 message/backend_key_data/BackendKeyData#secret_key.;
120 }
121
122 BackendMessageFormatrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#::ReadyForQueryrust-analyzer cargo sqlx-postgres 0.8.3 message/BackendMessageFormat#ReadyForQuery# => {
123 // start-up is completed. The frontend can now issue commands
124 transaction_status = message.decoderust-analyzer cargo sqlx-postgres 0.8.3 message/impl#[ReceivedMessage]decode().::<ReadyForQueryrust-analyzer cargo sqlx-postgres 0.8.3 message/ready_for_query/ReadyForQuery#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..transaction_statusrust-analyzer cargo sqlx-postgres 0.8.3 message/ready_for_query/ReadyForQuery#transaction_status.;
125
126 break;
127 }
128
129 _ => {
130 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err_protocolrust-analyzer cargo sqlx-core 0.8.3 error/err_protocol!!(
131 "establish: unexpected message: {:?}",
132 message.formatrust-analyzer cargo sqlx-postgres 0.8.3 message/ReceivedMessage#format.
133 ))
134 }
135 }
136 }
137
138 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(PgConnectionrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnection# {
139 innerrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnection#inner.: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(PgConnectionInnerrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnectionInner# {
140 streamrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnectionInner#stream.,
141 process_idrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnectionInner#process_id.,
142 secret_keyrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnectionInner#secret_key.,
143 transaction_statusrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnectionInner#transaction_status.,
144 transaction_depthrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnectionInner#transaction_depth.: 0,
145 pending_ready_for_query_countrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnectionInner#pending_ready_for_query_count.: 0,
146 next_statement_idrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnectionInner#next_statement_id.: StatementIdrust-analyzer cargo sqlx-postgres 0.8.3 io/StatementId#::NAMED_STARTrust-analyzer cargo sqlx-postgres 0.8.3 io/impl#[StatementId]NAMED_START.,
147 cache_statementrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnectionInner#cache_statement.: StatementCacherust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/StatementCache#::newrust-analyzer cargo sqlx-core 0.8.3 common/statement_cache/impl#[`StatementCache<T>`]new().(options.statement_cache_capacityrust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#statement_cache_capacity.),
148 cache_type_oidrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnectionInner#cache_type_oid.: HashMaprust-analyzer cargo hashbrown 0.15.5 map/HashMap#::newrust-analyzer cargo hashbrown 0.15.5 map/impl#[`HashMap<K, V>`]new().(),
149 cache_type_inforust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnectionInner#cache_type_info.: HashMaprust-analyzer cargo hashbrown 0.15.5 map/HashMap#::newrust-analyzer cargo hashbrown 0.15.5 map/impl#[`HashMap<K, V>`]new().(),
150 cache_elem_type_to_arrayrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnectionInner#cache_elem_type_to_array.: HashMaprust-analyzer cargo hashbrown 0.15.5 map/HashMap#::newrust-analyzer cargo hashbrown 0.15.5 map/impl#[`HashMap<K, V>`]new().(),
151 log_settingsrust-analyzer cargo sqlx-postgres 0.8.3 connection/PgConnectionInner#log_settings.: options.log_settingsrust-analyzer cargo sqlx-postgres 0.8.3 options/PgConnectOptions#log_settings..clonerust-analyzer cargo sqlx-core 0.8.3 connection/impl#[LogSettings][Clone]clone().(),
152 }),
153 })
154 }
155 }