diesel/mysql/connection/
url.rs

1extern crate percent_encoding;
2extern crate url;
3
4use self::percent_encoding::percent_decode;
5use self::url::{Host, Url};
6use std::collections::HashMap;
7use std::ffi::{CStr, CString};
8
9use crate::result::{ConnectionError, ConnectionResult};
10
11use mysqlclient_sys::mysql_ssl_mode;
12
13pub struct CapabilityFlags(<CapabilityFlags as
    ::bitflags::__private::PublicFlags>::Internal);
#[automatically_derived]
impl ::core::clone::Clone for CapabilityFlags {
    #[inline]
    fn clone(&self) -> CapabilityFlags {
        let _:
                ::core::clone::AssertParamIsClone<<CapabilityFlags as
                ::bitflags::__private::PublicFlags>::Internal>;
        *self
    }
}
#[automatically_derived]
impl ::core::marker::Copy for CapabilityFlags { }
impl CapabilityFlags {
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_LONG_PASSWORD: Self = Self::from_bits_retain(0x00000001);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_FOUND_ROWS: Self = Self::from_bits_retain(0x00000002);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_LONG_FLAG: Self = Self::from_bits_retain(0x00000004);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_CONNECT_WITH_DB: Self =
        Self::from_bits_retain(0x00000008);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_NO_SCHEMA: Self = Self::from_bits_retain(0x00000010);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_COMPRESS: Self = Self::from_bits_retain(0x00000020);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_ODBC: Self = Self::from_bits_retain(0x00000040);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_LOCAL_FILES: Self = Self::from_bits_retain(0x00000080);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_IGNORE_SPACE: Self = Self::from_bits_retain(0x00000100);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_PROTOCOL_41: Self = Self::from_bits_retain(0x00000200);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_INTERACTIVE: Self = Self::from_bits_retain(0x00000400);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_SSL: Self = Self::from_bits_retain(0x00000800);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_IGNORE_SIGPIPE: Self =
        Self::from_bits_retain(0x00001000);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_TRANSACTIONS: Self = Self::from_bits_retain(0x00002000);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_RESERVED: Self = Self::from_bits_retain(0x00004000);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_SECURE_CONNECTION: Self =
        Self::from_bits_retain(0x00008000);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_MULTI_STATEMENTS: Self =
        Self::from_bits_retain(0x00010000);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_MULTI_RESULTS: Self = Self::from_bits_retain(0x00020000);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_PS_MULTI_RESULTS: Self =
        Self::from_bits_retain(0x00040000);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_PLUGIN_AUTH: Self = Self::from_bits_retain(0x00080000);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_CONNECT_ATTRS: Self = Self::from_bits_retain(0x00100000);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA: Self =
        Self::from_bits_retain(0x00200000);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS: Self =
        Self::from_bits_retain(0x00400000);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_SESSION_TRACK: Self = Self::from_bits_retain(0x00800000);
    #[allow(deprecated, non_upper_case_globals,)]
    pub const CLIENT_DEPRECATE_EOF: Self = Self::from_bits_retain(0x01000000);
}
impl ::bitflags::Flags for CapabilityFlags {
    const FLAGS: &'static [::bitflags::Flag<CapabilityFlags>] =
        &[{

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_LONG_PASSWORD",
                            CapabilityFlags::CLIENT_LONG_PASSWORD)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_FOUND_ROWS",
                            CapabilityFlags::CLIENT_FOUND_ROWS)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_LONG_FLAG",
                            CapabilityFlags::CLIENT_LONG_FLAG)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_CONNECT_WITH_DB",
                            CapabilityFlags::CLIENT_CONNECT_WITH_DB)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_NO_SCHEMA",
                            CapabilityFlags::CLIENT_NO_SCHEMA)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_COMPRESS",
                            CapabilityFlags::CLIENT_COMPRESS)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_ODBC",
                            CapabilityFlags::CLIENT_ODBC)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_LOCAL_FILES",
                            CapabilityFlags::CLIENT_LOCAL_FILES)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_IGNORE_SPACE",
                            CapabilityFlags::CLIENT_IGNORE_SPACE)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_PROTOCOL_41",
                            CapabilityFlags::CLIENT_PROTOCOL_41)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_INTERACTIVE",
                            CapabilityFlags::CLIENT_INTERACTIVE)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_SSL",
                            CapabilityFlags::CLIENT_SSL)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_IGNORE_SIGPIPE",
                            CapabilityFlags::CLIENT_IGNORE_SIGPIPE)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_TRANSACTIONS",
                            CapabilityFlags::CLIENT_TRANSACTIONS)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_RESERVED",
                            CapabilityFlags::CLIENT_RESERVED)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_SECURE_CONNECTION",
                            CapabilityFlags::CLIENT_SECURE_CONNECTION)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_MULTI_STATEMENTS",
                            CapabilityFlags::CLIENT_MULTI_STATEMENTS)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_MULTI_RESULTS",
                            CapabilityFlags::CLIENT_MULTI_RESULTS)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_PS_MULTI_RESULTS",
                            CapabilityFlags::CLIENT_PS_MULTI_RESULTS)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_PLUGIN_AUTH",
                            CapabilityFlags::CLIENT_PLUGIN_AUTH)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_CONNECT_ATTRS",
                            CapabilityFlags::CLIENT_CONNECT_ATTRS)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA",
                            CapabilityFlags::CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS",
                            CapabilityFlags::CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_SESSION_TRACK",
                            CapabilityFlags::CLIENT_SESSION_TRACK)
                    },
                    {

                        #[allow(deprecated, non_upper_case_globals,)]
                        ::bitflags::Flag::new("CLIENT_DEPRECATE_EOF",
                            CapabilityFlags::CLIENT_DEPRECATE_EOF)
                    }];
    type Bits = u32;
    fn bits(&self) -> u32 { CapabilityFlags::bits(self) }
    fn from_bits_retain(bits: u32) -> CapabilityFlags {
        CapabilityFlags::from_bits_retain(bits)
    }
}
#[allow(dead_code, deprecated, unused_doc_comments, unused_attributes,
unused_mut, unused_imports, non_upper_case_globals, clippy ::
assign_op_pattern, clippy :: indexing_slicing, clippy :: same_name_method,
clippy :: iter_without_into_iter,)]
const _: () =
    {
        #[repr(transparent)]
        pub struct InternalBitFlags(u32);
        #[automatically_derived]
        impl ::core::clone::Clone for InternalBitFlags {
            #[inline]
            fn clone(&self) -> InternalBitFlags {
                let _: ::core::clone::AssertParamIsClone<u32>;
                *self
            }
        }
        #[automatically_derived]
        impl ::core::marker::Copy for InternalBitFlags { }
        #[automatically_derived]
        impl ::core::marker::StructuralPartialEq for InternalBitFlags { }
        #[automatically_derived]
        impl ::core::cmp::PartialEq for InternalBitFlags {
            #[inline]
            fn eq(&self, other: &InternalBitFlags) -> bool {
                self.0 == other.0
            }
        }
        #[automatically_derived]
        impl ::core::cmp::Eq for InternalBitFlags {
            #[inline]
            #[doc(hidden)]
            #[coverage(off)]
            fn assert_receiver_is_total_eq(&self) -> () {
                let _: ::core::cmp::AssertParamIsEq<u32>;
            }
        }
        #[automatically_derived]
        impl ::core::cmp::PartialOrd for InternalBitFlags {
            #[inline]
            fn partial_cmp(&self, other: &InternalBitFlags)
                -> ::core::option::Option<::core::cmp::Ordering> {
                ::core::cmp::PartialOrd::partial_cmp(&self.0, &other.0)
            }
        }
        #[automatically_derived]
        impl ::core::cmp::Ord for InternalBitFlags {
            #[inline]
            fn cmp(&self, other: &InternalBitFlags) -> ::core::cmp::Ordering {
                ::core::cmp::Ord::cmp(&self.0, &other.0)
            }
        }
        #[automatically_derived]
        impl ::core::hash::Hash for InternalBitFlags {
            #[inline]
            fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
                ::core::hash::Hash::hash(&self.0, state)
            }
        }
        impl ::bitflags::__private::PublicFlags for CapabilityFlags {
            type Primitive = u32;
            type Internal = InternalBitFlags;
        }
        impl ::bitflags::__private::core::default::Default for
            InternalBitFlags {
            #[inline]
            fn default() -> Self { InternalBitFlags::empty() }
        }
        impl ::bitflags::__private::core::fmt::Debug for InternalBitFlags {
            fn fmt(&self,
                f: &mut ::bitflags::__private::core::fmt::Formatter<'_>)
                -> ::bitflags::__private::core::fmt::Result {
                if self.is_empty() {
                    f.write_fmt(format_args!("{0:#x}",
                            <u32 as ::bitflags::Bits>::EMPTY))
                } else {
                    ::bitflags::__private::core::fmt::Display::fmt(self, f)
                }
            }
        }
        impl ::bitflags::__private::core::fmt::Display for InternalBitFlags {
            fn fmt(&self,
                f: &mut ::bitflags::__private::core::fmt::Formatter<'_>)
                -> ::bitflags::__private::core::fmt::Result {
                ::bitflags::parser::to_writer(&CapabilityFlags(*self), f)
            }
        }
        impl ::bitflags::__private::core::str::FromStr for InternalBitFlags {
            type Err = ::bitflags::parser::ParseError;
            fn from_str(s: &str)
                ->
                    ::bitflags::__private::core::result::Result<Self,
                    Self::Err> {
                ::bitflags::parser::from_str::<CapabilityFlags>(s).map(|flags|
                        flags.0)
            }
        }
        impl ::bitflags::__private::core::convert::AsRef<u32> for
            InternalBitFlags {
            fn as_ref(&self) -> &u32 { &self.0 }
        }
        impl ::bitflags::__private::core::convert::From<u32> for
            InternalBitFlags {
            fn from(bits: u32) -> Self { Self::from_bits_retain(bits) }
        }
        #[allow(dead_code, deprecated, unused_attributes)]
        impl InternalBitFlags {
            /// Get a flags value with all bits unset.
            #[inline]
            pub const fn empty() -> Self {
                Self(<u32 as ::bitflags::Bits>::EMPTY)
            }
            /// Get a flags value with all known bits set.
            #[inline]
            pub const fn all() -> Self {
                let mut truncated = <u32 as ::bitflags::Bits>::EMPTY;
                let mut i = 0;
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                {
                    {
                        let flag =
                            <CapabilityFlags as
                                            ::bitflags::Flags>::FLAGS[i].value().bits();
                        truncated = truncated | flag;
                        i += 1;
                    }
                };
                let _ = i;
                Self(truncated)
            }
            /// Get the underlying bits value.
            ///
            /// The returned value is exactly the bits set in this flags value.
            #[inline]
            pub const fn bits(&self) -> u32 { self.0 }
            /// Convert from a bits value.
            ///
            /// This method will return `None` if any unknown bits are set.
            #[inline]
            pub const fn from_bits(bits: u32)
                -> ::bitflags::__private::core::option::Option<Self> {
                let truncated = Self::from_bits_truncate(bits).0;
                if truncated == bits {
                    ::bitflags::__private::core::option::Option::Some(Self(bits))
                } else { ::bitflags::__private::core::option::Option::None }
            }
            /// Convert from a bits value, unsetting any unknown bits.
            #[inline]
            pub const fn from_bits_truncate(bits: u32) -> Self {
                Self(bits & Self::all().0)
            }
            /// Convert from a bits value exactly.
            #[inline]
            pub const fn from_bits_retain(bits: u32) -> Self { Self(bits) }
            /// Get a flags value with the bits of a flag with the given name set.
            ///
            /// This method will return `None` if `name` is empty or doesn't
            /// correspond to any named flag.
            #[inline]
            pub fn from_name(name: &str)
                -> ::bitflags::__private::core::option::Option<Self> {
                {
                    if name == "CLIENT_LONG_PASSWORD" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_LONG_PASSWORD.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_FOUND_ROWS" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_FOUND_ROWS.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_LONG_FLAG" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_LONG_FLAG.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_CONNECT_WITH_DB" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_CONNECT_WITH_DB.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_NO_SCHEMA" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_NO_SCHEMA.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_COMPRESS" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_COMPRESS.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_ODBC" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_ODBC.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_LOCAL_FILES" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_LOCAL_FILES.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_IGNORE_SPACE" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_IGNORE_SPACE.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_PROTOCOL_41" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_PROTOCOL_41.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_INTERACTIVE" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_INTERACTIVE.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_SSL" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_SSL.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_IGNORE_SIGPIPE" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_IGNORE_SIGPIPE.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_TRANSACTIONS" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_TRANSACTIONS.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_RESERVED" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_RESERVED.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_SECURE_CONNECTION" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_SECURE_CONNECTION.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_MULTI_STATEMENTS" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_MULTI_STATEMENTS.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_MULTI_RESULTS" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_MULTI_RESULTS.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_PS_MULTI_RESULTS" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_PS_MULTI_RESULTS.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_PLUGIN_AUTH" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_PLUGIN_AUTH.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_CONNECT_ATTRS" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_CONNECT_ATTRS.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_SESSION_TRACK" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_SESSION_TRACK.bits()));
                    }
                };
                ;
                {
                    if name == "CLIENT_DEPRECATE_EOF" {
                        return ::bitflags::__private::core::option::Option::Some(Self(CapabilityFlags::CLIENT_DEPRECATE_EOF.bits()));
                    }
                };
                ;
                let _ = name;
                ::bitflags::__private::core::option::Option::None
            }
            /// Whether all bits in this flags value are unset.
            #[inline]
            pub const fn is_empty(&self) -> bool {
                self.0 == <u32 as ::bitflags::Bits>::EMPTY
            }
            /// Whether all known bits in this flags value are set.
            #[inline]
            pub const fn is_all(&self) -> bool {
                Self::all().0 | self.0 == self.0
            }
            /// Whether any set bits in a source flags value are also set in a target flags value.
            #[inline]
            pub const fn intersects(&self, other: Self) -> bool {
                self.0 & other.0 != <u32 as ::bitflags::Bits>::EMPTY
            }
            /// Whether all set bits in a source flags value are also set in a target flags value.
            #[inline]
            pub const fn contains(&self, other: Self) -> bool {
                self.0 & other.0 == other.0
            }
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            pub fn insert(&mut self, other: Self) {
                *self = Self(self.0).union(other);
            }
            /// The intersection of a source flags value with the complement of a target flags
            /// value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `remove` won't truncate `other`, but the `!` operator will.
            #[inline]
            pub fn remove(&mut self, other: Self) {
                *self = Self(self.0).difference(other);
            }
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            pub fn toggle(&mut self, other: Self) {
                *self = Self(self.0).symmetric_difference(other);
            }
            /// Call `insert` when `value` is `true` or `remove` when `value` is `false`.
            #[inline]
            pub fn set(&mut self, other: Self, value: bool) {
                if value { self.insert(other); } else { self.remove(other); }
            }
            /// The bitwise and (`&`) of the bits in two flags values.
            #[inline]
            #[must_use]
            pub const fn intersection(self, other: Self) -> Self {
                Self(self.0 & other.0)
            }
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            #[must_use]
            pub const fn union(self, other: Self) -> Self {
                Self(self.0 | other.0)
            }
            /// The intersection of a source flags value with the complement of a target flags
            /// value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `difference` won't truncate `other`, but the `!` operator will.
            #[inline]
            #[must_use]
            pub const fn difference(self, other: Self) -> Self {
                Self(self.0 & !other.0)
            }
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            #[must_use]
            pub const fn symmetric_difference(self, other: Self) -> Self {
                Self(self.0 ^ other.0)
            }
            /// The bitwise negation (`!`) of the bits in a flags value, truncating the result.
            #[inline]
            #[must_use]
            pub const fn complement(self) -> Self {
                Self::from_bits_truncate(!self.0)
            }
        }
        impl ::bitflags::__private::core::fmt::Binary for InternalBitFlags {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::Binary::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::fmt::Octal for InternalBitFlags {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::Octal::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::fmt::LowerHex for InternalBitFlags {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::LowerHex::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::fmt::UpperHex for InternalBitFlags {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::UpperHex::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::ops::BitOr for InternalBitFlags {
            type Output = Self;
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            fn bitor(self, other: InternalBitFlags) -> Self {
                self.union(other)
            }
        }
        impl ::bitflags::__private::core::ops::BitOrAssign for
            InternalBitFlags {
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            fn bitor_assign(&mut self, other: Self) { self.insert(other); }
        }
        impl ::bitflags::__private::core::ops::BitXor for InternalBitFlags {
            type Output = Self;
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            fn bitxor(self, other: Self) -> Self {
                self.symmetric_difference(other)
            }
        }
        impl ::bitflags::__private::core::ops::BitXorAssign for
            InternalBitFlags {
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            fn bitxor_assign(&mut self, other: Self) { self.toggle(other); }
        }
        impl ::bitflags::__private::core::ops::BitAnd for InternalBitFlags {
            type Output = Self;
            /// The bitwise and (`&`) of the bits in two flags values.
            #[inline]
            fn bitand(self, other: Self) -> Self { self.intersection(other) }
        }
        impl ::bitflags::__private::core::ops::BitAndAssign for
            InternalBitFlags {
            /// The bitwise and (`&`) of the bits in two flags values.
            #[inline]
            fn bitand_assign(&mut self, other: Self) {
                *self =
                    Self::from_bits_retain(self.bits()).intersection(other);
            }
        }
        impl ::bitflags::__private::core::ops::Sub for InternalBitFlags {
            type Output = Self;
            /// The intersection of a source flags value with the complement of a target flags value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `difference` won't truncate `other`, but the `!` operator will.
            #[inline]
            fn sub(self, other: Self) -> Self { self.difference(other) }
        }
        impl ::bitflags::__private::core::ops::SubAssign for InternalBitFlags
            {
            /// The intersection of a source flags value with the complement of a target flags value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `difference` won't truncate `other`, but the `!` operator will.
            #[inline]
            fn sub_assign(&mut self, other: Self) { self.remove(other); }
        }
        impl ::bitflags::__private::core::ops::Not for InternalBitFlags {
            type Output = Self;
            /// The bitwise negation (`!`) of the bits in a flags value, truncating the result.
            #[inline]
            fn not(self) -> Self { self.complement() }
        }
        impl ::bitflags::__private::core::iter::Extend<InternalBitFlags> for
            InternalBitFlags {
            /// The bitwise or (`|`) of the bits in each flags value.
            fn extend<T: ::bitflags::__private::core::iter::IntoIterator<Item
                = Self>>(&mut self, iterator: T) {
                for item in iterator { self.insert(item) }
            }
        }
        impl ::bitflags::__private::core::iter::FromIterator<InternalBitFlags>
            for InternalBitFlags {
            /// The bitwise or (`|`) of the bits in each flags value.
            fn from_iter<T: ::bitflags::__private::core::iter::IntoIterator<Item
                = Self>>(iterator: T) -> Self {
                use ::bitflags::__private::core::iter::Extend;
                let mut result = Self::empty();
                result.extend(iterator);
                result
            }
        }
        impl InternalBitFlags {
            /// Yield a set of contained flags values.
            ///
            /// Each yielded flags value will correspond to a defined named flag. Any unknown bits
            /// will be yielded together as a final flags value.
            #[inline]
            pub const fn iter(&self)
                -> ::bitflags::iter::Iter<CapabilityFlags> {
                ::bitflags::iter::Iter::__private_const_new(<CapabilityFlags
                        as ::bitflags::Flags>::FLAGS,
                    CapabilityFlags::from_bits_retain(self.bits()),
                    CapabilityFlags::from_bits_retain(self.bits()))
            }
            /// Yield a set of contained named flags values.
            ///
            /// This method is like [`iter`](#method.iter), except only yields bits in contained named flags.
            /// Any unknown bits, or bits not corresponding to a contained flag will not be yielded.
            #[inline]
            pub const fn iter_names(&self)
                -> ::bitflags::iter::IterNames<CapabilityFlags> {
                ::bitflags::iter::IterNames::__private_const_new(<CapabilityFlags
                        as ::bitflags::Flags>::FLAGS,
                    CapabilityFlags::from_bits_retain(self.bits()),
                    CapabilityFlags::from_bits_retain(self.bits()))
            }
        }
        impl ::bitflags::__private::core::iter::IntoIterator for
            InternalBitFlags {
            type Item = CapabilityFlags;
            type IntoIter = ::bitflags::iter::Iter<CapabilityFlags>;
            fn into_iter(self) -> Self::IntoIter { self.iter() }
        }
        impl InternalBitFlags {
            /// Returns a mutable reference to the raw value of the flags currently stored.
            #[inline]
            pub fn bits_mut(&mut self) -> &mut u32 { &mut self.0 }
        }
        #[allow(dead_code, deprecated, unused_attributes)]
        impl CapabilityFlags {
            /// Get a flags value with all bits unset.
            #[inline]
            pub const fn empty() -> Self { Self(InternalBitFlags::empty()) }
            /// Get a flags value with all known bits set.
            #[inline]
            pub const fn all() -> Self { Self(InternalBitFlags::all()) }
            /// Get the underlying bits value.
            ///
            /// The returned value is exactly the bits set in this flags value.
            #[inline]
            pub const fn bits(&self) -> u32 { self.0.bits() }
            /// Convert from a bits value.
            ///
            /// This method will return `None` if any unknown bits are set.
            #[inline]
            pub const fn from_bits(bits: u32)
                -> ::bitflags::__private::core::option::Option<Self> {
                match InternalBitFlags::from_bits(bits) {
                    ::bitflags::__private::core::option::Option::Some(bits) =>
                        ::bitflags::__private::core::option::Option::Some(Self(bits)),
                    ::bitflags::__private::core::option::Option::None =>
                        ::bitflags::__private::core::option::Option::None,
                }
            }
            /// Convert from a bits value, unsetting any unknown bits.
            #[inline]
            pub const fn from_bits_truncate(bits: u32) -> Self {
                Self(InternalBitFlags::from_bits_truncate(bits))
            }
            /// Convert from a bits value exactly.
            #[inline]
            pub const fn from_bits_retain(bits: u32) -> Self {
                Self(InternalBitFlags::from_bits_retain(bits))
            }
            /// Get a flags value with the bits of a flag with the given name set.
            ///
            /// This method will return `None` if `name` is empty or doesn't
            /// correspond to any named flag.
            #[inline]
            pub fn from_name(name: &str)
                -> ::bitflags::__private::core::option::Option<Self> {
                match InternalBitFlags::from_name(name) {
                    ::bitflags::__private::core::option::Option::Some(bits) =>
                        ::bitflags::__private::core::option::Option::Some(Self(bits)),
                    ::bitflags::__private::core::option::Option::None =>
                        ::bitflags::__private::core::option::Option::None,
                }
            }
            /// Whether all bits in this flags value are unset.
            #[inline]
            pub const fn is_empty(&self) -> bool { self.0.is_empty() }
            /// Whether all known bits in this flags value are set.
            #[inline]
            pub const fn is_all(&self) -> bool { self.0.is_all() }
            /// Whether any set bits in a source flags value are also set in a target flags value.
            #[inline]
            pub const fn intersects(&self, other: Self) -> bool {
                self.0.intersects(other.0)
            }
            /// Whether all set bits in a source flags value are also set in a target flags value.
            #[inline]
            pub const fn contains(&self, other: Self) -> bool {
                self.0.contains(other.0)
            }
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            pub fn insert(&mut self, other: Self) { self.0.insert(other.0) }
            /// The intersection of a source flags value with the complement of a target flags
            /// value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `remove` won't truncate `other`, but the `!` operator will.
            #[inline]
            pub fn remove(&mut self, other: Self) { self.0.remove(other.0) }
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            pub fn toggle(&mut self, other: Self) { self.0.toggle(other.0) }
            /// Call `insert` when `value` is `true` or `remove` when `value` is `false`.
            #[inline]
            pub fn set(&mut self, other: Self, value: bool) {
                self.0.set(other.0, value)
            }
            /// The bitwise and (`&`) of the bits in two flags values.
            #[inline]
            #[must_use]
            pub const fn intersection(self, other: Self) -> Self {
                Self(self.0.intersection(other.0))
            }
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            #[must_use]
            pub const fn union(self, other: Self) -> Self {
                Self(self.0.union(other.0))
            }
            /// The intersection of a source flags value with the complement of a target flags
            /// value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `difference` won't truncate `other`, but the `!` operator will.
            #[inline]
            #[must_use]
            pub const fn difference(self, other: Self) -> Self {
                Self(self.0.difference(other.0))
            }
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            #[must_use]
            pub const fn symmetric_difference(self, other: Self) -> Self {
                Self(self.0.symmetric_difference(other.0))
            }
            /// The bitwise negation (`!`) of the bits in a flags value, truncating the result.
            #[inline]
            #[must_use]
            pub const fn complement(self) -> Self {
                Self(self.0.complement())
            }
        }
        impl ::bitflags::__private::core::fmt::Binary for CapabilityFlags {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::Binary::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::fmt::Octal for CapabilityFlags {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::Octal::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::fmt::LowerHex for CapabilityFlags {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::LowerHex::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::fmt::UpperHex for CapabilityFlags {
            fn fmt(&self, f: &mut ::bitflags::__private::core::fmt::Formatter)
                -> ::bitflags::__private::core::fmt::Result {
                let inner = self.0;
                ::bitflags::__private::core::fmt::UpperHex::fmt(&inner, f)
            }
        }
        impl ::bitflags::__private::core::ops::BitOr for CapabilityFlags {
            type Output = Self;
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            fn bitor(self, other: CapabilityFlags) -> Self {
                self.union(other)
            }
        }
        impl ::bitflags::__private::core::ops::BitOrAssign for CapabilityFlags
            {
            /// The bitwise or (`|`) of the bits in two flags values.
            #[inline]
            fn bitor_assign(&mut self, other: Self) { self.insert(other); }
        }
        impl ::bitflags::__private::core::ops::BitXor for CapabilityFlags {
            type Output = Self;
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            fn bitxor(self, other: Self) -> Self {
                self.symmetric_difference(other)
            }
        }
        impl ::bitflags::__private::core::ops::BitXorAssign for
            CapabilityFlags {
            /// The bitwise exclusive-or (`^`) of the bits in two flags values.
            #[inline]
            fn bitxor_assign(&mut self, other: Self) { self.toggle(other); }
        }
        impl ::bitflags::__private::core::ops::BitAnd for CapabilityFlags {
            type Output = Self;
            /// The bitwise and (`&`) of the bits in two flags values.
            #[inline]
            fn bitand(self, other: Self) -> Self { self.intersection(other) }
        }
        impl ::bitflags::__private::core::ops::BitAndAssign for
            CapabilityFlags {
            /// The bitwise and (`&`) of the bits in two flags values.
            #[inline]
            fn bitand_assign(&mut self, other: Self) {
                *self =
                    Self::from_bits_retain(self.bits()).intersection(other);
            }
        }
        impl ::bitflags::__private::core::ops::Sub for CapabilityFlags {
            type Output = Self;
            /// The intersection of a source flags value with the complement of a target flags value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `difference` won't truncate `other`, but the `!` operator will.
            #[inline]
            fn sub(self, other: Self) -> Self { self.difference(other) }
        }
        impl ::bitflags::__private::core::ops::SubAssign for CapabilityFlags {
            /// The intersection of a source flags value with the complement of a target flags value (`&!`).
            ///
            /// This method is not equivalent to `self & !other` when `other` has unknown bits set.
            /// `difference` won't truncate `other`, but the `!` operator will.
            #[inline]
            fn sub_assign(&mut self, other: Self) { self.remove(other); }
        }
        impl ::bitflags::__private::core::ops::Not for CapabilityFlags {
            type Output = Self;
            /// The bitwise negation (`!`) of the bits in a flags value, truncating the result.
            #[inline]
            fn not(self) -> Self { self.complement() }
        }
        impl ::bitflags::__private::core::iter::Extend<CapabilityFlags> for
            CapabilityFlags {
            /// The bitwise or (`|`) of the bits in each flags value.
            fn extend<T: ::bitflags::__private::core::iter::IntoIterator<Item
                = Self>>(&mut self, iterator: T) {
                for item in iterator { self.insert(item) }
            }
        }
        impl ::bitflags::__private::core::iter::FromIterator<CapabilityFlags>
            for CapabilityFlags {
            /// The bitwise or (`|`) of the bits in each flags value.
            fn from_iter<T: ::bitflags::__private::core::iter::IntoIterator<Item
                = Self>>(iterator: T) -> Self {
                use ::bitflags::__private::core::iter::Extend;
                let mut result = Self::empty();
                result.extend(iterator);
                result
            }
        }
        impl CapabilityFlags {
            /// Yield a set of contained flags values.
            ///
            /// Each yielded flags value will correspond to a defined named flag. Any unknown bits
            /// will be yielded together as a final flags value.
            #[inline]
            pub const fn iter(&self)
                -> ::bitflags::iter::Iter<CapabilityFlags> {
                ::bitflags::iter::Iter::__private_const_new(<CapabilityFlags
                        as ::bitflags::Flags>::FLAGS,
                    CapabilityFlags::from_bits_retain(self.bits()),
                    CapabilityFlags::from_bits_retain(self.bits()))
            }
            /// Yield a set of contained named flags values.
            ///
            /// This method is like [`iter`](#method.iter), except only yields bits in contained named flags.
            /// Any unknown bits, or bits not corresponding to a contained flag will not be yielded.
            #[inline]
            pub const fn iter_names(&self)
                -> ::bitflags::iter::IterNames<CapabilityFlags> {
                ::bitflags::iter::IterNames::__private_const_new(<CapabilityFlags
                        as ::bitflags::Flags>::FLAGS,
                    CapabilityFlags::from_bits_retain(self.bits()),
                    CapabilityFlags::from_bits_retain(self.bits()))
            }
        }
        impl ::bitflags::__private::core::iter::IntoIterator for
            CapabilityFlags {
            type Item = CapabilityFlags;
            type IntoIter = ::bitflags::iter::Iter<CapabilityFlags>;
            fn into_iter(self) -> Self::IntoIter { self.iter() }
        }
    };bitflags::bitflags! {
14    #[derive(Clone, Copy)]
15    pub struct CapabilityFlags: u32 {
16        const CLIENT_LONG_PASSWORD = 0x00000001;
17        const CLIENT_FOUND_ROWS = 0x00000002;
18        const CLIENT_LONG_FLAG = 0x00000004;
19        const CLIENT_CONNECT_WITH_DB = 0x00000008;
20        const CLIENT_NO_SCHEMA = 0x00000010;
21        const CLIENT_COMPRESS = 0x00000020;
22        const CLIENT_ODBC = 0x00000040;
23        const CLIENT_LOCAL_FILES = 0x00000080;
24        const CLIENT_IGNORE_SPACE = 0x00000100;
25        const CLIENT_PROTOCOL_41 = 0x00000200;
26        const CLIENT_INTERACTIVE = 0x00000400;
27        const CLIENT_SSL = 0x00000800;
28        const CLIENT_IGNORE_SIGPIPE = 0x00001000;
29        const CLIENT_TRANSACTIONS = 0x00002000;
30        const CLIENT_RESERVED = 0x00004000;
31        const CLIENT_SECURE_CONNECTION = 0x00008000;
32        const CLIENT_MULTI_STATEMENTS = 0x00010000;
33        const CLIENT_MULTI_RESULTS = 0x00020000;
34        const CLIENT_PS_MULTI_RESULTS = 0x00040000;
35        const CLIENT_PLUGIN_AUTH = 0x00080000;
36        const CLIENT_CONNECT_ATTRS = 0x00100000;
37        const CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA = 0x00200000;
38        const CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS = 0x00400000;
39        const CLIENT_SESSION_TRACK = 0x00800000;
40        const CLIENT_DEPRECATE_EOF = 0x01000000;
41    }
42}
43
44pub(super) struct ConnectionOptions {
45    host: Option<CString>,
46    user: CString,
47    password: Option<CString>,
48    database: Option<CString>,
49    port: Option<u16>,
50    unix_socket: Option<CString>,
51    client_flags: CapabilityFlags,
52    ssl_mode: Option<mysql_ssl_mode>,
53    ssl_ca: Option<CString>,
54    ssl_cert: Option<CString>,
55    ssl_key: Option<CString>,
56}
57
58impl ConnectionOptions {
59    pub(super) fn parse(database_url: &str) -> ConnectionResult<Self> {
60        let url = match Url::parse(database_url) {
61            Ok(url) => url,
62            Err(_) => return Err(connection_url_error()),
63        };
64
65        if url.scheme() != "mysql" {
66            return Err(connection_url_error());
67        }
68
69        if url.path_segments().map(Iterator::count).unwrap_or(0) > 1 {
70            return Err(connection_url_error());
71        }
72
73        let query_pairs = url.query_pairs().into_owned().collect::<HashMap<_, _>>();
74        if query_pairs.contains_key("database") {
75            return Err(connection_url_error());
76        }
77
78        let unix_socket = match query_pairs.get("unix_socket") {
79            Some(v) => Some(CString::new(v.as_bytes())?),
80            _ => None,
81        };
82
83        let ssl_ca = match query_pairs.get("ssl_ca") {
84            Some(v) => Some(CString::new(v.as_bytes())?),
85            _ => None,
86        };
87
88        let ssl_cert = match query_pairs.get("ssl_cert") {
89            Some(v) => Some(CString::new(v.as_bytes())?),
90            _ => None,
91        };
92
93        let ssl_key = match query_pairs.get("ssl_key") {
94            Some(v) => Some(CString::new(v.as_bytes())?),
95            _ => None,
96        };
97
98        let ssl_mode = match query_pairs.get("ssl_mode") {
99            Some(v) => {
100                let ssl_mode = match v.to_lowercase().as_str() {
101                    "disabled" => mysql_ssl_mode::SSL_MODE_DISABLED,
102                    "preferred" => mysql_ssl_mode::SSL_MODE_PREFERRED,
103                    "required" => mysql_ssl_mode::SSL_MODE_REQUIRED,
104                    "verify_ca" => mysql_ssl_mode::SSL_MODE_VERIFY_CA,
105                    "verify_identity" => mysql_ssl_mode::SSL_MODE_VERIFY_IDENTITY,
106                    _ => {
107                        let msg = "unknown ssl_mode";
108                        return Err(ConnectionError::InvalidConnectionUrl(msg.into()));
109                    }
110                };
111                Some(ssl_mode)
112            }
113            _ => None,
114        };
115
116        let host = match url.host() {
117            Some(Host::Ipv6(host)) => Some(CString::new(host.to_string())?),
118            Some(host) if host.to_string() == "localhost" && unix_socket.is_some() => None,
119            Some(host) => Some(CString::new(host.to_string())?),
120            None => None,
121        };
122        let user = decode_into_cstring(url.username())?;
123        let password = match url.password() {
124            Some(password) => Some(decode_into_cstring(password)?),
125            None => None,
126        };
127
128        let database = match url.path_segments().and_then(|mut iter| iter.next()) {
129            Some("") | None => None,
130            Some(segment) => Some(CString::new(segment.as_bytes())?),
131        };
132
133        // this is not present in the database_url, using a default value
134        let client_flags = CapabilityFlags::CLIENT_FOUND_ROWS;
135
136        Ok(ConnectionOptions {
137            host,
138            user,
139            password,
140            database,
141            port: url.port(),
142            client_flags,
143            ssl_mode,
144            unix_socket,
145            ssl_ca,
146            ssl_cert,
147            ssl_key,
148        })
149    }
150
151    pub(super) fn host(&self) -> Option<&CStr> {
152        self.host.as_deref()
153    }
154
155    pub(super) fn user(&self) -> &CStr {
156        &self.user
157    }
158
159    pub(super) fn password(&self) -> Option<&CStr> {
160        self.password.as_deref()
161    }
162
163    pub(super) fn database(&self) -> Option<&CStr> {
164        self.database.as_deref()
165    }
166
167    pub(super) fn port(&self) -> Option<u16> {
168        self.port
169    }
170
171    pub(super) fn unix_socket(&self) -> Option<&CStr> {
172        self.unix_socket.as_deref()
173    }
174
175    pub(super) fn ssl_ca(&self) -> Option<&CStr> {
176        self.ssl_ca.as_deref()
177    }
178
179    pub(super) fn ssl_cert(&self) -> Option<&CStr> {
180        self.ssl_cert.as_deref()
181    }
182
183    pub(super) fn ssl_key(&self) -> Option<&CStr> {
184        self.ssl_key.as_deref()
185    }
186
187    pub(super) fn client_flags(&self) -> CapabilityFlags {
188        self.client_flags
189    }
190
191    pub(super) fn ssl_mode(&self) -> Option<mysql_ssl_mode> {
192        self.ssl_mode
193    }
194}
195
196fn decode_into_cstring(s: &str) -> ConnectionResult<CString> {
197    let decoded = percent_decode(s.as_bytes())
198        .decode_utf8()
199        .map_err(|_| connection_url_error())?;
200    CString::new(decoded.as_bytes()).map_err(Into::into)
201}
202
203fn connection_url_error() -> ConnectionError {
204    let msg = "MySQL connection URLs must be in the form \
205               `mysql://[[user]:[password]@]host[:port][/database][?unix_socket=socket-path]`";
206    ConnectionError::InvalidConnectionUrl(msg.into())
207}
208
209#[cfg(test)]
210mod tests {
211    use super::*;
212
213    #[diesel_test_helper::test]
214    fn urls_with_schemes_other_than_mysql_are_errors() {
215        assert!(ConnectionOptions::parse("postgres://localhost").is_err());
216        assert!(ConnectionOptions::parse("http://localhost").is_err());
217        assert!(ConnectionOptions::parse("file:///tmp/mysql.sock").is_err());
218        assert!(ConnectionOptions::parse("socket:///tmp/mysql.sock").is_err());
219        assert!(ConnectionOptions::parse("mysql://localhost?database=somedb").is_err());
220        assert!(ConnectionOptions::parse("mysql://localhost").is_ok());
221    }
222
223    #[diesel_test_helper::test]
224    fn urls_must_have_zero_or_one_path_segments() {
225        assert!(ConnectionOptions::parse("mysql://localhost/foo/bar").is_err());
226        assert!(ConnectionOptions::parse("mysql://localhost/foo").is_ok());
227    }
228
229    #[diesel_test_helper::test]
230    fn first_path_segment_is_treated_as_database() {
231        let foo_cstr = CString::new("foo").unwrap();
232        let bar_cstr = CString::new("bar").unwrap();
233        assert_eq!(
234            Some(&*foo_cstr),
235            ConnectionOptions::parse("mysql://localhost/foo")
236                .unwrap()
237                .database()
238        );
239        assert_eq!(
240            Some(&*bar_cstr),
241            ConnectionOptions::parse("mysql://localhost/bar")
242                .unwrap()
243                .database()
244        );
245        assert_eq!(
246            None,
247            ConnectionOptions::parse("mysql://localhost")
248                .unwrap()
249                .database()
250        );
251    }
252
253    #[diesel_test_helper::test]
254    fn userinfo_should_be_percent_decode() {
255        use self::percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS};
256        const USERINFO_ENCODE_SET: &AsciiSet = &CONTROLS
257            .add(b' ')
258            .add(b'"')
259            .add(b'<')
260            .add(b'>')
261            .add(b'`')
262            .add(b'#')
263            .add(b'?')
264            .add(b'{')
265            .add(b'}')
266            .add(b'/')
267            .add(b':')
268            .add(b';')
269            .add(b'=')
270            .add(b'@')
271            .add(b'[')
272            .add(b'\\')
273            .add(b']')
274            .add(b'^')
275            .add(b'|');
276
277        let username = "x#gfuL?4Zuj{n73m}eeJt0";
278        let encoded_username = utf8_percent_encode(username, USERINFO_ENCODE_SET);
279
280        let password = "x/gfuL?4Zuj{n73m}eeJt1";
281        let encoded_password = utf8_percent_encode(password, USERINFO_ENCODE_SET);
282
283        let db_url = format!("mysql://{encoded_username}:{encoded_password}@localhost/bar",);
284        let db_url = Url::parse(&db_url).unwrap();
285
286        let conn_opts = ConnectionOptions::parse(db_url.as_str()).unwrap();
287        let username = CString::new(username.as_bytes()).unwrap();
288        let password = CString::new(password.as_bytes()).unwrap();
289        assert_eq!(username, conn_opts.user);
290        assert_eq!(password, conn_opts.password.unwrap());
291    }
292
293    #[diesel_test_helper::test]
294    fn ipv6_host_not_wrapped_in_brackets() {
295        let host1 = CString::new("::1").unwrap();
296        let host2 = CString::new("2001:db8:85a3::8a2e:370:7334").unwrap();
297
298        assert_eq!(
299            Some(&*host1),
300            ConnectionOptions::parse("mysql://[::1]").unwrap().host()
301        );
302        assert_eq!(
303            Some(&*host2),
304            ConnectionOptions::parse("mysql://[2001:db8:85a3::8a2e:370:7334]")
305                .unwrap()
306                .host()
307        );
308    }
309
310    #[diesel_test_helper::test]
311    fn unix_socket_tests() {
312        let unix_socket = "/var/run/mysqld.sock";
313        let username = "foo";
314        let password = "bar";
315        let db_url = format!("mysql://{username}:{password}@localhost?unix_socket={unix_socket}",);
316        let conn_opts = ConnectionOptions::parse(db_url.as_str()).unwrap();
317        let cstring = |s| CString::new(s).unwrap();
318        assert_eq!(None, conn_opts.host);
319        assert_eq!(None, conn_opts.port);
320        assert_eq!(cstring(username), conn_opts.user);
321        assert_eq!(cstring(password), conn_opts.password.unwrap());
322        assert_eq!(
323            CString::new(unix_socket).unwrap(),
324            conn_opts.unix_socket.unwrap()
325        );
326    }
327
328    #[diesel_test_helper::test]
329    fn ssl_ca_tests() {
330        let ssl_ca = "/etc/ssl/certs/ca-certificates.crt";
331        let username = "foo";
332        let password = "bar";
333        let db_url = format!("mysql://{username}:{password}@localhost?ssl_ca={ssl_ca}",);
334        let conn_opts = ConnectionOptions::parse(db_url.as_str()).unwrap();
335        let cstring = |s| CString::new(s).unwrap();
336        assert_eq!(Some(cstring("localhost")), conn_opts.host);
337        assert_eq!(None, conn_opts.port);
338        assert_eq!(cstring(username), conn_opts.user);
339        assert_eq!(cstring(password), conn_opts.password.unwrap());
340        assert_eq!(CString::new(ssl_ca).unwrap(), conn_opts.ssl_ca.unwrap());
341
342        let url_with_unix_str_and_ssl_ca = format!(
343        "mysql://{username}:{password}@localhost?unix_socket=/var/run/mysqld.sock&ssl_ca={ssl_ca}"
344    );
345
346        let conn_opts2 = ConnectionOptions::parse(url_with_unix_str_and_ssl_ca.as_str()).unwrap();
347        assert_eq!(None, conn_opts2.host);
348        assert_eq!(None, conn_opts2.port);
349        assert_eq!(CString::new(ssl_ca).unwrap(), conn_opts2.ssl_ca.unwrap());
350    }
351
352    #[diesel_test_helper::test]
353    fn ssl_cert_tests() {
354        let ssl_cert = "/etc/ssl/certs/client-cert.crt";
355        let username = "foo";
356        let password = "bar";
357        let db_url = format!("mysql://{username}:{password}@localhost?ssl_cert={ssl_cert}");
358        let conn_opts = ConnectionOptions::parse(db_url.as_str()).unwrap();
359        let cstring = |s| CString::new(s).unwrap();
360        assert_eq!(Some(cstring("localhost")), conn_opts.host);
361        assert_eq!(None, conn_opts.port);
362        assert_eq!(cstring(username), conn_opts.user);
363        assert_eq!(cstring(password), conn_opts.password.unwrap());
364        assert_eq!(CString::new(ssl_cert).unwrap(), conn_opts.ssl_cert.unwrap());
365
366        let url_with_unix_str_and_ssl_cert = format!(
367        "mysql://{username}:{password}@localhost?unix_socket=/var/run/mysqld.sock&ssl_cert={ssl_cert}"
368    );
369
370        let conn_opts2 = ConnectionOptions::parse(url_with_unix_str_and_ssl_cert.as_str()).unwrap();
371        assert_eq!(None, conn_opts2.host);
372        assert_eq!(None, conn_opts2.port);
373        assert_eq!(
374            CString::new(ssl_cert).unwrap(),
375            conn_opts2.ssl_cert.unwrap()
376        );
377    }
378
379    #[diesel_test_helper::test]
380    fn ssl_key_tests() {
381        let ssl_key = "/etc/ssl/certs/client-key.crt";
382        let username = "foo";
383        let password = "bar";
384        let db_url = format!("mysql://{username}:{password}@localhost?ssl_key={ssl_key}");
385        let conn_opts = ConnectionOptions::parse(db_url.as_str()).unwrap();
386        let cstring = |s| CString::new(s).unwrap();
387        assert_eq!(Some(cstring("localhost")), conn_opts.host);
388        assert_eq!(None, conn_opts.port);
389        assert_eq!(cstring(username), conn_opts.user);
390        assert_eq!(cstring(password), conn_opts.password.unwrap());
391        assert_eq!(CString::new(ssl_key).unwrap(), conn_opts.ssl_key.unwrap());
392
393        let url_with_unix_str_and_ssl_key = format!(
394        "mysql://{username}:{password}@localhost?unix_socket=/var/run/mysqld.sock&ssl_key={ssl_key}"
395    );
396
397        let conn_opts2 = ConnectionOptions::parse(url_with_unix_str_and_ssl_key.as_str()).unwrap();
398        assert_eq!(None, conn_opts2.host);
399        assert_eq!(None, conn_opts2.port);
400        assert_eq!(CString::new(ssl_key).unwrap(), conn_opts2.ssl_key.unwrap());
401    }
402
403    #[diesel_test_helper::test]
404    fn ssl_mode() {
405        let ssl_mode = |url| ConnectionOptions::parse(url).unwrap().ssl_mode();
406        assert_eq!(ssl_mode("mysql://localhost"), None);
407        assert_eq!(
408            ssl_mode("mysql://localhost?ssl_mode=disabled"),
409            Some(mysql_ssl_mode::SSL_MODE_DISABLED)
410        );
411        assert_eq!(
412            ssl_mode("mysql://localhost?ssl_mode=PREFERRED"),
413            Some(mysql_ssl_mode::SSL_MODE_PREFERRED)
414        );
415        assert_eq!(
416            ssl_mode("mysql://localhost?ssl_mode=required"),
417            Some(mysql_ssl_mode::SSL_MODE_REQUIRED)
418        );
419        assert_eq!(
420            ssl_mode("mysql://localhost?ssl_mode=VERIFY_CA"),
421            Some(mysql_ssl_mode::SSL_MODE_VERIFY_CA)
422        );
423        assert_eq!(
424            ssl_mode("mysql://localhost?ssl_mode=verify_identity"),
425            Some(mysql_ssl_mode::SSL_MODE_VERIFY_IDENTITY)
426        );
427    }
428}