From 015af82f22944d116031ddc1056bba562b39f0af Mon Sep 17 00:00:00 2001 From: Tomasz Sidoruk Date: Fri, 22 Apr 2022 01:08:54 +0200 Subject: [PATCH] ok --- Cargo.lock | 1804 ++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 17 + src/main.rs | 1026 ++++++++++++++++++++++++++++ src/main1.rs | 55 ++ 4 files changed, 2902 insertions(+) create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs create mode 100644 src/main1.rs diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..9a0fe39 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1804 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "aho-corasick" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +dependencies = [ + "memchr", +] + +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "bcrypt" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe4fef31efb0f76133ae8e3576a88e58edb7cfc5584c81c758c349ba46b43fc" +dependencies = [ + "base64", + "blowfish", + "getrandom", + "zeroize", +] + +[[package]] +name = "bigdecimal" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aaf33151a6429fe9211d1b276eafdf70cdff28b071e76c0b0e1503221ea3744" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", +] + +[[package]] +name = "bindgen" +version = "0.59.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bd2a9a458e8f4304c52c43ebb0cfbd520289f8379a52e329a38afda99bf8eb8" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitvec" +version = "0.22.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5237f00a8c86130a0cc317830e558b966dd7850d48a953d998c813f01a41b527" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "block-buffer" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +dependencies = [ + "generic-array", +] + +[[package]] +name = "blowfish" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e412e2cd0f2b2d93e02543ceae7917b3c70331573df19ee046bcbc35e45e87d7" +dependencies = [ + "byteorder", + "cipher", +] + +[[package]] +name = "bufstream" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40e38929add23cdf8a366df9b0e088953150724bcbe5fc330b0d8eb3b328eec8" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" + +[[package]] +name = "cc" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cipher" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1873270f8f7942c191139cb8a40fd228da6c3fd2fc376d7e92d47aa14aeb59e" +dependencies = [ + "crypto-common", + "inout", +] + +[[package]] +name = "clang-sys" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cc00842eed744b858222c4c9faf7243aafc6d33f92f96935263ef4d8a41ce21" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "cmake" +version = "0.1.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8ad8cef104ac57b68b89df3208164d228503abbdce70f6880ffa3d970e7443a" +dependencies = [ + "cc", +] + +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + +[[package]] +name = "cpufeatures" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae5588f6b3c3cb05239e90bd110f257254aecd01e4635400391aeae07497845" +dependencies = [ + "cfg-if", + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-epoch", + "crossbeam-queue", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "lazy_static", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-queue" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f25d8400f4a7a5778f0e4e52384a48cbd9b5c495d110786187fc750075277a2" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" +dependencies = [ + "cfg-if", + "lazy_static", +] + +[[package]] +name = "crypto-common" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "derive_utils" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "532b4c15dccee12c7044f1fcad956e98410860b22231e44a3b827464797ca7bf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "digest" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "fastrand" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" +dependencies = [ + "instant", +] + +[[package]] +name = "flate2" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e6988e897c1c9c485f43b47a529cef42fde0547f9d8d41a7062518f1d8fc53f" +dependencies = [ + "cfg-if", + "crc32fast", + "libc", + "libz-sys", + "miniz_oxide", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding", +] + +[[package]] +name = "frunk" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cd67cf7d54b7e72d0ea76f3985c3747d74aee43e0218ad993b7903ba7a5395e" +dependencies = [ + "frunk_core", + "frunk_derives", + "frunk_proc_macros", +] + +[[package]] +name = "frunk_core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1246cf43ec80bf8b2505b5c360b8fb999c97dabd17dbb604d85558d5cbc25482" + +[[package]] +name = "frunk_derives" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dbc4f084ec5a3f031d24ccedeb87ab2c3189a2f33b8d070889073837d5ea09e" +dependencies = [ + "frunk_proc_macro_helpers", + "quote", + "syn", +] + +[[package]] +name = "frunk_proc_macro_helpers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99f11257f106c6753f5ffcb8e601fb39c390a088017aaa55b70c526bff15f63e" +dependencies = [ + "frunk_core", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "frunk_proc_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a078bd8459eccbb85e0b007b8f756585762a72a9efc53f359b371c3b6351dbcc" +dependencies = [ + "frunk_core", + "frunk_proc_macros_impl", + "proc-macro-hack", +] + +[[package]] +name = "frunk_proc_macros_impl" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ffba99f0fa4f57e42f57388fbb9a0ca863bc2b4261f3c5570fed579d5df6c32" +dependencies = [ + "frunk_core", + "frunk_proc_macro_helpers", + "proc-macro-hack", + "quote", + "syn", +] + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + +[[package]] +name = "funty" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1847abb9cb65d566acd5942e94aea9c8f547ad02c98e1649326fc0e8910b8b1e" + +[[package]] +name = "futures-channel" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" + +[[package]] +name = "futures-sink" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" + +[[package]] +name = "futures-task" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" + +[[package]] +name = "futures-util" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + +[[package]] +name = "generic-array" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.10.2+wasi-snapshot-preview1", +] + +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + +[[package]] +name = "h2" +version = "0.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62eeb471aa3e3c9197aa4bfeabfe02982f6dc96f750486c0bb0009ac58b26d2b" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +dependencies = [ + "ahash", +] + +[[package]] +name = "hello_world" +version = "0.1.0" +dependencies = [ + "bcrypt", + "hyper", + "mysql", + "rand 0.3.23", + "serde", + "serde_derive", + "serde_json", + "tokio", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "http" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31f4c6746584866f0feabcc69893c5b51beef3831656a968ed7ae254cdc4fd03" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9100414882e15fb7feccb4897e5f0ff0ff1ca7d1a86a23208ada4d7a18e6c6c4" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + +[[package]] +name = "hyper" +version = "0.14.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "043f0e083e9901b6cc658a77d1eb86f4fc650bbb977a4337dd63192826aa85dd" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "generic-array", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "io-enum" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03e3306b0f260aad2872563eb0d5d1a59f2420fad270a661dce59a01e92d806b" +dependencies = [ + "autocfg", + "derive_utils", + "quote", + "syn", +] + +[[package]] +name = "itoa" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "lexical" +version = "6.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccd3e434c16f0164124ade12dcdee324fcc3dafb1cad0c7f1d8c2451a1aa6886" +dependencies = [ + "lexical-core", +] + +[[package]] +name = "lexical-core" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92912c4af2e7d9075be3e5e3122c4d7263855fa6cce34fbece4dd08e5884624d" +dependencies = [ + "lexical-parse-float", + "lexical-parse-integer", + "lexical-util", + "lexical-write-float", + "lexical-write-integer", +] + +[[package]] +name = "lexical-parse-float" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f518eed87c3be6debe6d26b855c97358d8a11bf05acec137e5f53080f5ad2dd8" +dependencies = [ + "lexical-parse-integer", + "lexical-util", + "static_assertions", +] + +[[package]] +name = "lexical-parse-integer" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc852ec67c6538bbb2b9911116a385b24510e879a69ab516e6a151b15a79168" +dependencies = [ + "lexical-util", + "static_assertions", +] + +[[package]] +name = "lexical-util" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c72a9d52c5c4e62fa2cdc2cb6c694a39ae1382d9c2a17a466f18e272a0930eb1" +dependencies = [ + "static_assertions", +] + +[[package]] +name = "lexical-write-float" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a89ec1d062e481210c309b672f73a0567b7855f21e7d2fae636df44d12e97f9" +dependencies = [ + "lexical-util", + "lexical-write-integer", + "static_assertions", +] + +[[package]] +name = "lexical-write-integer" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "094060bd2a7c2ff3a16d5304a6ae82727cb3cc9d1c70f813cc73f744c319337e" +dependencies = [ + "lexical-util", + "static_assertions", +] + +[[package]] +name = "libc" +version = "0.2.121" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" + +[[package]] +name = "libloading" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" +dependencies = [ + "cfg-if", + "winapi", +] + +[[package]] +name = "libz-sys" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f35facd4a5673cb5a48822be2be1d4236c1c99cb4113cab7061ac720d5bf859" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "lock_api" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "lru" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb87f3080f6d1d69e8c564c0fcfde1d7aa8cc451ce40cae89479111f03bc0eb" +dependencies = [ + "hashbrown", +] + +[[package]] +name = "matches" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" + +[[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "miniz_oxide" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +dependencies = [ + "adler", + "autocfg", +] + +[[package]] +name = "mio" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52da4364ffb0e4fe33a9841a98a3f3014fb964045ce4f7a45a398243c8d6b0c9" +dependencies = [ + "libc", + "log", + "miow", + "ntapi", + "wasi 0.11.0+wasi-snapshot-preview1", + "winapi", +] + +[[package]] +name = "miow" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" +dependencies = [ + "winapi", +] + +[[package]] +name = "mysql" +version = "22.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e6f8658d54e3c294d94a741a5f414c21431f56f253b5dc2e2582941d834b3a9" +dependencies = [ + "bufstream", + "bytes", + "crossbeam", + "flate2", + "io-enum", + "libc", + "lru", + "mysql_common", + "named_pipe", + "native-tls", + "nix", + "once_cell", + "pem", + "percent-encoding", + "serde", + "serde_json", + "socket2", + "twox-hash", + "url", +] + +[[package]] +name = "mysql_common" +version = "0.28.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4140827f2d12750de1e8755442577e4292a835f26ff2f659f0a380d1d71020b0" +dependencies = [ + "base64", + "bigdecimal", + "bindgen", + "bitflags", + "bitvec", + "byteorder", + "bytes", + "cc", + "cmake", + "crc32fast", + "flate2", + "frunk", + "lazy_static", + "lexical", + "num-bigint", + "num-traits", + "rand 0.8.5", + "regex", + "rust_decimal", + "saturating", + "serde", + "serde_json", + "sha-1", + "sha2", + "smallvec", + "subprocess", + "thiserror", + "time", + "uuid", +] + +[[package]] +name = "named_pipe" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad9c443cce91fc3e12f017290db75dde490d685cdaaf508d7159d7cf41f0eb2b" +dependencies = [ + "winapi", +] + +[[package]] +name = "native-tls" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48ba9f7719b5a0f42f338907614285fb5fd70e53858141f69898a1fb7203b24d" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "nix" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6" +dependencies = [ + "bitflags", + "cc", + "cfg-if", + "libc", + "memoffset", +] + +[[package]] +name = "nom" +version = "7.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "ntapi" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" +dependencies = [ + "winapi", +] + +[[package]] +name = "num-bigint" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "num_threads" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aba1801fb138d8e85e11d0fc70baf4fe1cdfffda7c6cd34a854905df588e5ed0" +dependencies = [ + "libc", +] + +[[package]] +name = "once_cell" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" + +[[package]] +name = "openssl" +version = "0.10.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7ae222234c30df141154f159066c5093ff73b63204dcda7121eb082fc56a95" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-sys", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e46109c383602735fa0a2e48dd2b7c892b048e1bf69e5c3b1d804b7d9c203cb" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28141e0cc4143da2443301914478dc976a61ffdb3f043058310c70df2fed8954" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-sys", +] + +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "pem" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9a3b09a20e374558580a4914d3b7d89bd61b954a5a5e1dcbea98753addb1947" +dependencies = [ + "base64", +] + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "pin-project-lite" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" + +[[package]] +name = "ppv-lite86" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" + +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + +[[package]] +name = "proc-macro2" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4af2ec4714533fcdf07e886f17025ace8b997b9ce51204ee69b6da831c3da57" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb" + +[[package]] +name = "rand" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" +dependencies = [ + "libc", + "rand 0.4.6", +] + +[[package]] +name = "rand" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" +dependencies = [ + "fuchsia-cprng", + "libc", + "rand_core 0.3.1", + "rdrand", + "winapi", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core 0.6.3", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.3", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "redox_syscall" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8380fe0152551244f0747b1bf41737e0f8a74f97a14ccefd1148187271634f3c" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "rust_decimal" +version = "1.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d37baa70cf8662d2ba1c1868c5983dda16ef32b105cce41fb5c47e72936a90b3" +dependencies = [ + "arrayvec", + "num-traits", + "serde", +] + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "ryu" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" + +[[package]] +name = "saturating" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ece8e78b2f38ec51c51f5d475df0a7187ba5111b2a28bdc761ee05b075d40a71" + +[[package]] +name = "schannel" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" +dependencies = [ + "lazy_static", + "winapi", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "security-framework" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "serde" +version = "1.0.136" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" + +[[package]] +name = "serde_derive" +version = "1.0.136" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha-1" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "shlex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" + +[[package]] +name = "signal-hook-registry" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" + +[[package]] +name = "smallvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" + +[[package]] +name = "socket2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "subprocess" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "055cf3ebc2981ad8f0a5a17ef6652f652d87831f79fddcba2ac57bcb9a0aa407" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "syn" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea297be220d52398dcc07ce15a209fce436d361735ac1db700cab3b6cdfb9f54" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "tempfile" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +dependencies = [ + "cfg-if", + "fastrand", + "libc", + "redox_syscall", + "remove_dir_all", + "winapi", +] + +[[package]] +name = "thiserror" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "time" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "004cbc98f30fa233c61a38bc77e96a9106e65c88f2d3bef182ae952027e5753d" +dependencies = [ + "libc", + "num_threads", +] + +[[package]] +name = "tinyvec" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "tokio" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" +dependencies = [ + "bytes", + "libc", + "memchr", + "mio", + "num_cpus", + "once_cell", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "winapi", +] + +[[package]] +name = "tokio-macros" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-util" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e99e1983e5d376cd8eb4b66604d2e99e79f5bd988c3055891dcd8c9e2604cc0" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "log", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" + +[[package]] +name = "tracing" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a1bdf54a7c28a2bbf701e1d2233f6c77f473486b94bee4f9678da5a148dca7f" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa31669fa42c09c34d94d8165dd2012e8ff3c66aca50f3bb226b68f216f2706c" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + +[[package]] +name = "twox-hash" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ee73e6e4924fe940354b8d4d98cad5231175d615cd855b758adc658c0aac6a0" +dependencies = [ + "cfg-if", + "rand 0.8.5", + "static_assertions", +] + +[[package]] +name = "typenum" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" + +[[package]] +name = "unicode-bidi" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f" + +[[package]] +name = "unicode-normalization" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "url" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", +] + +[[package]] +name = "uuid" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3df6e476185f92a12c072be4a189a0210dcdcf512a1891d6dff9edb874deadc6" +dependencies = [ + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_msvc" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5" + +[[package]] +name = "windows_i686_gnu" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615" + +[[package]] +name = "windows_i686_msvc" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316" + +[[package]] +name = "wyz" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "129e027ad65ce1453680623c3fb5163cbf7107bfe1aa32257e7d0e63f9ced188" +dependencies = [ + "tap", +] + +[[package]] +name = "zeroize" +version = "1.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb5728b8afd3f280a869ce1d4c554ffaed35f45c231fc41bfbd0381bef50317" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..854afdf --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "hello_world" +version = "0.1.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +hyper = { version = "*", features = ["full"] } +tokio = { version = "*", features = ["full"] } +mysql = "*" +serde_json = "*" +serde = "*" +serde_derive = "*" +bcrypt = "0.12" +rand = "0.3.0" + diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..2e08fb8 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,1026 @@ +use std::collections::HashMap; +use serde_derive::{Serialize, Deserialize}; +use mysql::*; +use mysql::prelude::*; +use std::convert::Infallible; +use std::net::SocketAddr; +use hyper::{Body, Client, Method, Request, Response, Server, StatusCode}; +use hyper::service::{make_service_fn, service_fn}; +use bcrypt::{DEFAULT_COST, hash, verify}; +use rand::{OsRng, Rng}; + +#[derive(Serialize, Deserialize)] +struct User { + id: i32, + name: String, + surname: String, + role: String, + login: String, + phone: String, + mail: String, +} + +#[derive(Serialize, Deserialize)] +struct Registration { + id: i32, + userid: String, + tournamentid: String, + paymenttype: String, + paymentstatus: String, + approval: String, +} + +#[derive(Serialize, Deserialize)] +struct Usera { + id: i32, + name: String, + surname: String, + role: String, + login: String, + phone: String, + mail: String, + deleted: i32, +} + +#[derive(Serialize, Deserialize)] +struct tournament { + id: i32, + name: String, + typeOfLadder: String, + pointsForTournament: i32, + places: i32, + roles: String, + creator: i32, + approved: i32, +} + +#[derive(Serialize, Deserialize)] +struct tournamenta { + id: i32, + name: String, + typeOfLadder: String, + pointsForTournament: i32, + places: i32, + roles: String, + creator: i32, + approved: i32, + deleted: i32, +} + +thread_local!(static POOL: Pool = Pool::new(Opts::from_url("mysql://inz:*****!@10.1.6.101:3306/inz").unwrap()).unwrap()); + +async fn hello_world(req: Request) -> Result> { + let mut response = Response::new(Body::empty()); + match (req.method(), req.uri().path()) { + (&Method::POST, "/registrations/approve") => { + if req.headers().contains_key("Authorization") { + let mut tmp = req.headers().get("Authorization").unwrap().to_str().unwrap().split(" "); + let aa = tmp.next().unwrap(); + if aa != "Bearer" { + *response.status_mut() = StatusCode::UNAUTHORIZED; + return Ok(response); + } + let token = tmp.next().unwrap().to_string(); + let byte_stream = hyper::body::to_bytes(req).await.unwrap(); + let s: HashMap = serde_json::from_slice(&byte_stream).unwrap(); + if !s.contains_key("id"){ + *response.body_mut() = "{\"error\":\"id required\"}".into(); + return Ok(response); + } + POOL.with(|poola| { + let mut con = poola.get_conn().unwrap(); + let mut result = con.exec_iter("Select id,role from users where (role = '2' OR role = '3')AND id =(SELECT user FROM `inz`.`sessions` where token = ? and expire > NOW());", (&token, )).unwrap(); + let mut it = result.iter().unwrap(); + let mut row = it.next(); + if row.is_none() { + *response.status_mut() = StatusCode::FORBIDDEN; + return; + } + let urow = row.unwrap().unwrap(); + let id: i32 = urow.get(0).unwrap(); + let role: String = urow.get(1).unwrap(); + if (role == "2") { + let mut conn1 = poola.get_conn().unwrap(); + let mut result1 = conn1.exec_iter("Select userid from registrations where id = ?", (&s.get("id"), )).unwrap(); + let mut it1 = result1.iter().unwrap(); + let mut row1 = it1.next(); + let urow1 = row1.unwrap().unwrap(); + let userid: String = urow1.get(0).unwrap(); + if userid != id.to_string() { + return; + } + poola.get_conn().unwrap().exec_drop("Update registrations set approval ='1' where id = ?", (&s.get("id"), )).unwrap(); + } else { + poola.get_conn().unwrap().exec_drop("Update registrations set approval ='1' where id = ?", (&s.get("id"), )).unwrap(); + } + }); + } else { + *response.status_mut() = StatusCode::UNAUTHORIZED; + } + } + (&Method::GET, "/registrations") => { + if req.headers().contains_key("Authorization") { + let query: &str = req.uri().query().unwrap(); + let mut splited = query.split("="); + let id = splited.next().unwrap(); + let val = splited.next().unwrap(); + if id != "id" { + *response.body_mut() = "{\"error\":\"id required\"}".into(); + return Ok(response); + } + + let mut tmp = req.headers().get("Authorization").unwrap().to_str().unwrap().split(" "); + let aa = tmp.next().unwrap(); + if aa != "Bearer" { + *response.status_mut() = StatusCode::UNAUTHORIZED; + return Ok(response); + } + let token = tmp.next().unwrap().to_string(); + POOL.with(|poola| { + let mut con = poola.get_conn().unwrap(); + let mut result = con.exec_iter("Select id,role from users where id =(SELECT user FROM `inz`.`sessions` where token = ? and expire > NOW());", (&token, )).unwrap(); + let mut it = result.iter().unwrap(); + let mut row = it.next(); + if row.is_none() { + *response.status_mut() = StatusCode::FORBIDDEN; + return; + } + + let urow = row.unwrap().unwrap(); + let id: i32 = urow.get(0).unwrap(); + let role: String = urow.get(1).unwrap(); + if (role == "1") { + let res = poola.get_conn().unwrap() + .exec_map( + "SELECT `registrations`.`id`,`registrations`.`userid`,`registrations`.`tournamentid`,`registrations`.`paymenttype`,`registrations`.`paymentstatus`,`registrations`.`approval`FROM `inz`.`registrations` where tournamentid= ? and userid=?;", (&val, id), + |(id, userid, tournamentid, paymenttype, paymentstatus, approval)| { + Registration { id, userid, tournamentid, paymenttype, paymentstatus, approval } + }, + ); + *response.body_mut() = serde_json::to_string(&res.unwrap()).unwrap().into(); + } else { + if (role == "2") { + let mut conn1 = poola.get_conn().unwrap(); + let mut result1 = conn1.exec_iter("Select userid from registrations where id = ?", (&val, )).unwrap(); + let mut it1 = result1.iter().unwrap(); + let mut row1 = it1.next(); + let urow1 = row1.unwrap().unwrap(); + let userid: String = urow1.get(0).unwrap(); + if userid != id.to_string() { + let res = poola.get_conn().unwrap() + .exec_map( + "SELECT `registrations`.`id`,`registrations`.`userid`,`registrations`.`tournamentid`,`registrations`.`paymenttype`,`registrations`.`paymentstatus`,`registrations`.`approval`FROM `inz`.`registrations` where tournamentid= ? and userid=?;", (&val, id), + |(id, userid, tournamentid, paymenttype, paymentstatus, approval)| { + Registration { id, userid, tournamentid, paymenttype, paymentstatus, approval } + }, + ); + *response.body_mut() = serde_json::to_string(&res.unwrap()).unwrap().into(); + return; + } + + + let res = poola.get_conn().unwrap() + .exec_map( + "SELECT `registrations`.`id`,`registrations`.`userid`,`registrations`.`tournamentid`,`registrations`.`paymenttype`,`registrations`.`paymentstatus`,`registrations`.`approval`FROM `inz`.`registrations` where tournamentid= ?;", (&val, ), + |(id, userid, tournamentid, paymenttype, paymentstatus, approval)| { + Registration { id, userid, tournamentid, paymenttype, paymentstatus, approval } + }, + ); + *response.body_mut() = serde_json::to_string(&res.unwrap()).unwrap().into(); + } else { + let res = poola.get_conn().unwrap() + .exec_map( + "SELECT `registrations`.`id`,`registrations`.`userid`,`registrations`.`tournamentid`,`registrations`.`paymenttype`,`registrations`.`paymentstatus`,`registrations`.`approval`FROM `inz`.`registrations` where tournamentid= ?;", (&val, ), + |(id, userid, tournamentid, paymenttype, paymentstatus, approval)| { + Registration { id, userid, tournamentid, paymenttype, paymentstatus, approval } + }, + ); + *response.body_mut() = serde_json::to_string(&res.unwrap()).unwrap().into(); + } + } + }); + } else { + *response.status_mut() = StatusCode::UNAUTHORIZED; + } + } + (&Method::POST, "/admin/user") => { + if req.headers().contains_key("Authorization") { + let mut tmp = req.headers().get("Authorization").unwrap().to_str().unwrap().split(" "); + let aa = tmp.next().unwrap(); + if aa != "Bearer" { + *response.status_mut() = StatusCode::UNAUTHORIZED; + return Ok(response); + } + let token = tmp.next().unwrap().to_string(); + let byte_stream = hyper::body::to_bytes(req).await.unwrap(); + let s: HashMap = serde_json::from_slice(&byte_stream).unwrap(); + let mut row: Option> = None; + POOL.with(|poola| { + let mut con = poola.get_conn().unwrap(); + let mut result = con.exec_iter("Select id from users where role ='3' and id =(SELECT user FROM `inz`.`sessions` where token = ? and expire > NOW());", (&token, )).unwrap(); + let mut it = result.iter().unwrap(); + row = it.next(); + if row.is_none() { + *response.status_mut() = StatusCode::FORBIDDEN; + return; + } + if !s.contains_key("id") { + *response.body_mut() = Body::from("{\"error\":\"id is required\"}"); + return; + } + let idi = s.get("id").unwrap(); + if s.contains_key("name") { + poola.get_conn().unwrap().exec_drop("Update users set name =? where id = ?", (s.get("name"), idi)).unwrap(); + } + if s.contains_key("surname") { + poola.get_conn().unwrap().exec_drop("Update users set surname =? where id = ?", (s.get("surname"), idi)).unwrap(); + } + if s.contains_key("password") { + poola.get_conn().unwrap().exec_drop("Update users set password =? where id = ?", (hash(s.get("password").unwrap().to_string(), DEFAULT_COST - 6).unwrap(), idi)).unwrap(); + } + if s.contains_key("mail") { + poola.get_conn().unwrap().exec_drop("Update users set mail =? where id = ?", (s.get("mail"), idi)).unwrap(); + } + if s.contains_key("phone") { + poola.get_conn().unwrap().exec_drop("Update users set phone =? where id = ?", (s.get("phone"), idi)).unwrap(); + } + if s.contains_key("role") { + poola.get_conn().unwrap().exec_drop("Update users set role =? where id = ?", (s.get("role"), idi)).unwrap(); + } + }); + } else { + *response.status_mut() = StatusCode::UNAUTHORIZED; + } + } + (&Method::DELETE, "/admin/user") => { + if req.headers().contains_key("Authorization") { + let mut tmp = req.headers().get("Authorization").unwrap().to_str().unwrap().split(" "); + let aa = tmp.next().unwrap(); + if aa != "Bearer" { + *response.status_mut() = StatusCode::UNAUTHORIZED; + return Ok(response); + } + let token = tmp.next().unwrap().to_string(); + let byte_stream = hyper::body::to_bytes(req).await.unwrap(); + let s: HashMap = serde_json::from_slice(&byte_stream).unwrap(); + let mut row: Option> = None; + POOL.with(|poola| { + let mut con = poola.get_conn().unwrap(); + let mut result = con.exec_iter("Select id from users where role ='3' and id =(SELECT user FROM `inz`.`sessions` where token = ? and expire > NOW());", (&token, )).unwrap(); + let mut it = result.iter().unwrap(); + row = it.next(); + if row.is_none() { + *response.status_mut() = StatusCode::FORBIDDEN; + return; + } + if !s.contains_key("id") { + *response.body_mut() = Body::from("{\"error\":\"id is required\"}"); + return; + } + poola.get_conn().unwrap().exec_drop("Update users set deleted =1 where id = ?", (&s.contains_key("id"), )).unwrap(); + }); + } else { + *response.status_mut() = StatusCode::UNAUTHORIZED; + } + } + (&Method::GET, "/admin/users") => { + if req.headers().contains_key("Authorization") { + let mut tmp = req.headers().get("Authorization").unwrap().to_str().unwrap().split(" "); + let aa = tmp.next().unwrap(); + if aa != "Bearer" { + *response.status_mut() = StatusCode::UNAUTHORIZED; + return Ok(response); + } + let token = tmp.next().unwrap().to_string(); + let mut row: Option> = None; + POOL.with(|poola| { + let mut con = poola.get_conn().unwrap(); + let mut result = con.exec_iter("Select id from users where role ='3' and id =(SELECT user FROM `inz`.`sessions` where token = ? and expire > NOW());", (&token, )).unwrap(); + let mut it = result.iter().unwrap(); + row = it.next(); + if row.is_none() { + *response.status_mut() = StatusCode::FORBIDDEN; + return; + } + let res = poola.get_conn().unwrap() + .query_map( + "SELECT `id`, `name`, `surname`, `role`, `login`, `mail`, `phone`,`deleted` from users ", + |(id, name, surname, role, login, mail, phone, deleted)| { + Usera { id, name, surname, role, login, mail, phone, deleted } + }, + ); + *response.body_mut() = serde_json::to_string(&res.unwrap()).unwrap().into(); + }); + } else { + *response.status_mut() = StatusCode::UNAUTHORIZED; + } + } + (&Method::DELETE, "/admin/tournament") => { + if req.headers().contains_key("Authorization") { + let mut tmp = req.headers().get("Authorization").unwrap().to_str().unwrap().split(" "); + let aa = tmp.next().unwrap(); + if aa != "Bearer" { + *response.status_mut() = StatusCode::UNAUTHORIZED; + return Ok(response); + } + let token = tmp.next().unwrap().to_string(); + let byte_stream = hyper::body::to_bytes(req).await.unwrap(); + let s: HashMap = serde_json::from_slice(&byte_stream).unwrap(); + let mut row: Option> = None; + POOL.with(|poola| { + let mut con = poola.get_conn().unwrap(); + let mut result = con.exec_iter("Select id from users where role ='3' and id =(SELECT user FROM `inz`.`sessions` where token = ? and expire > NOW());", (&token, )).unwrap(); + let mut it = result.iter().unwrap(); + row = it.next(); + if row.is_none() { + *response.status_mut() = StatusCode::FORBIDDEN; + return; + } + if !s.contains_key("id") { + *response.body_mut() = Body::from("{\"error\":\"id is required\"}"); + return; + } + poola.get_conn().unwrap().exec_drop("Update tournaments set deleted =1 where id = ?", (&s.get("id"), )).unwrap(); + }); + } else { + *response.status_mut() = StatusCode::UNAUTHORIZED; + } + } + (&Method::POST, "/admin/tournament") => { + if req.headers().contains_key("Authorization") { + let mut tmp = req.headers().get("Authorization").unwrap().to_str().unwrap().split(" "); + let aa = tmp.next().unwrap(); + if aa != "Bearer" { + *response.status_mut() = StatusCode::UNAUTHORIZED; + return Ok(response); + } + let token = tmp.next().unwrap().to_string(); + let byte_stream = hyper::body::to_bytes(req).await.unwrap(); + let s: HashMap = serde_json::from_slice(&byte_stream).unwrap(); + let mut row: Option> = None; + POOL.with(|poola| { + let mut con = poola.get_conn().unwrap(); + let mut result = con.exec_iter("Select id from users where role ='3' and id =(SELECT user FROM `inz`.`sessions` where token = ? and expire > NOW());", (&token, )).unwrap(); + let mut it = result.iter().unwrap(); + row = it.next(); + if row.is_none() { + *response.status_mut() = StatusCode::FORBIDDEN; + return; + } + if !s.contains_key("id") { + *response.body_mut() = Body::from("{\"error\":\"id is required\"}"); + return; + } + if s.contains_key("name") { + poola.get_conn().unwrap().exec_drop("Update tournaments set name =? where id = ?", (s.get("name"), &s.get("id"))).unwrap(); + } + if s.contains_key("typeOfLadder") { + poola.get_conn().unwrap().exec_drop("Update tournaments set typeOfLadder =? where id = ?", (s.get("typeOfLadder"), &s.get("id"))).unwrap(); + } + if s.contains_key("pointsForTournament") { + poola.get_conn().unwrap().exec_drop("Update tournaments set pointsForTournament =? where id = ?", (s.get("pointsForTournament"), &s.get("id"))).unwrap(); + } + if s.contains_key("places") { + poola.get_conn().unwrap().exec_drop("Update tournaments set places =? where id = ?", (s.get("places"), &s.get("id"))).unwrap(); + } + if s.contains_key("roles") { + poola.get_conn().unwrap().exec_drop("Update tournaments set roles =? where id = ?", (s.get("roles"), &s.get("id"))).unwrap(); + } + }); + } else { + *response.status_mut() = StatusCode::UNAUTHORIZED; + } + } + (&Method::GET, "/admin/tournaments") => { + if req.headers().contains_key("Authorization") { + let mut tmp = req.headers().get("Authorization").unwrap().to_str().unwrap().split(" "); + let aa = tmp.next().unwrap(); + if aa != "Bearer" { + *response.status_mut() = StatusCode::UNAUTHORIZED; + return Ok(response); + } + let token = tmp.next().unwrap().to_string(); + let mut row: Option> = None; + POOL.with(|poola| { + let mut con = poola.get_conn().unwrap(); + let mut result = con.exec_iter("Select id from users where role ='3' and id =(SELECT user FROM `inz`.`sessions` where token = ? and expire > NOW());", (&token, )).unwrap(); + let mut it = result.iter().unwrap(); + row = it.next(); + if row.is_none() { + *response.status_mut() = StatusCode::FORBIDDEN; + return; + } + let res = poola.get_conn().unwrap() + .query_map( + "SELECT id, name, typeOfLadder, pointsForTournament, places, roles, creator,approved,deleted from tournaments ", + |(id, name, type_of_ladder, points_for_tournament, places, roles, creator, approved, deleted)| { + tournamenta { id, name, typeOfLadder: type_of_ladder, places, roles, creator, pointsForTournament: points_for_tournament, approved, deleted } + }, + ); + *response.body_mut() = serde_json::to_string(&res.unwrap()).unwrap().into(); + }); + } else { + *response.status_mut() = StatusCode::UNAUTHORIZED; + } + } + (&Method::POST, "/admin/approveTurnament") => { + if req.headers().contains_key("Authorization") { + let mut tmp = req.headers().get("Authorization").unwrap().to_str().unwrap().split(" "); + let aa = tmp.next().unwrap(); + if aa != "Bearer" { + *response.status_mut() = StatusCode::UNAUTHORIZED; + return Ok(response); + } + let token = tmp.next().unwrap().to_string(); + let byte_stream = hyper::body::to_bytes(req).await.unwrap(); + let s: HashMap = serde_json::from_slice(&byte_stream).unwrap(); + let mut row: Option> = None; + let mut row2: Option> = None; + if s.contains_key("id") { + POOL.with(|poola| { + let mut con = poola.get_conn().unwrap(); + let mut result = con.exec_iter("Select id from users where role ='3' and id =(SELECT user FROM `inz`.`sessions` where token = ? and expire > NOW());", (&token, )).unwrap(); + let mut it = result.iter().unwrap(); + row = it.next(); + let mut con2 = poola.get_conn().unwrap(); + let mut result2 = con2.exec_iter("Select approved from tournaments where id =?;", (&s.get("id").unwrap(), )).unwrap(); + let mut it2 = result2.iter().unwrap(); + row2 = it2.next(); + }); + if row.is_none() { + *response.status_mut() = StatusCode::FORBIDDEN; + return Ok(response); + } + let urow2 = row2.unwrap().unwrap(); + let approved: i32 = urow2.get(0).unwrap(); + if (approved == 1) { + POOL.with(|poola| { + poola.get_conn().unwrap().exec_drop("Update tournaments set approved =2 where id = ?", (s.get("id").unwrap(), )).unwrap(); + }); + } else { + *response.status_mut() = StatusCode::BAD_REQUEST; + return Ok(response); + } + } else { + *response.body_mut() = "{\"error\":\"missing id\"}".into(); + } + } else { + *response.status_mut() = StatusCode::UNAUTHORIZED; + } + } + (&Method::POST, "/registration/payedUsingCash") => { + if req.headers().contains_key("Authorization") { + let mut tmp = req.headers().get("Authorization").unwrap().to_str().unwrap().split(" "); + let aa = tmp.next().unwrap(); + if aa != "Bearer" { + *response.status_mut() = StatusCode::UNAUTHORIZED; + return Ok(response); + } + let token = tmp.next().unwrap().to_string(); + let byte_stream = hyper::body::to_bytes(req).await.unwrap(); + let s: HashMap = serde_json::from_slice(&byte_stream).unwrap(); + if !s.contains_key("id") { + *response.body_mut() = "{\"error\":\"id required\"}".into(); + return Ok(response); + } + + let mut row: Option> = None; + let mut row2: Option> = None; + let mut row3: Option> = None; + POOL.with(|poola| { + let mut con = poola.get_conn().unwrap(); + let mut result = con.exec_iter("Select id, role from users where (role='2' or role='3' )and id =(SELECT user FROM `inz`.`sessions` where token = ? and expire > NOW());", (&token, )).unwrap(); + let mut it = result.iter().unwrap(); + row = it.next(); + let mut con2 = poola.get_conn().unwrap(); + let mut result2 = con2.exec_iter("Select paymenttype,tournamentid from registrations where id =?;", (&s.get("id"), )).unwrap(); + let mut it2 = result2.iter().unwrap(); + row2 = it2.next(); + }); + if row.is_none() { + *response.status_mut() = StatusCode::FORBIDDEN; + return Ok(response); + } + if row2.is_none() { + *response.status_mut() = StatusCode::NOT_FOUND; + return Ok(response); + } + let urow = row.unwrap().unwrap(); + let urow2 = row2.unwrap().unwrap(); + let id: i32 = urow.get(0).unwrap(); + let role: String = urow.get(1).unwrap(); + let paymenttype: String = urow2.get(0).unwrap(); + let tournamentid: String = urow2.get(1).unwrap(); + if (role == "2") { + POOL.with(|poola| { + let mut con3 = poola.get_conn().unwrap(); + let mut result3 = con3.exec_iter("Select creator from tournaments where id = ?;", (&tournamentid, )).unwrap(); + let mut it3 = result3.iter().unwrap(); + row3 = it3.next(); + }); + let urow3 = row3.unwrap().unwrap(); + let creator: String = urow3.get(0).unwrap(); + if creator != id.to_string() { + *response.status_mut() = StatusCode::NOT_FOUND; + return Ok(response); + } + } + if paymenttype == "cash" { + POOL.with(|poola| { + poola.get_conn().unwrap().exec_drop("Update registrations set paymentstatus ='DONE' where id = ?", (&s.get("id"), )).unwrap(); + }); + } else { + *response.status_mut() = StatusCode::BAD_REQUEST; + return Ok(response); + } + } else { + *response.status_mut() = StatusCode::UNAUTHORIZED; + } + } + (&Method::GET, "/registration/paymentstatus") => { + if req.headers().contains_key("Authorization") { + let query: &str = req.uri().query().unwrap(); + let mut splited = query.split("="); + let id = splited.next().unwrap(); + let val = splited.next().unwrap(); + if id != "id" { + *response.body_mut() = "{\"error\":\"id required\"}".into(); + return Ok(response); + } + let mut tmp = req.headers().get("Authorization").unwrap().to_str().unwrap().split(" "); + let aa = tmp.next().unwrap(); + if aa != "Bearer" { + *response.status_mut() = StatusCode::UNAUTHORIZED; + return Ok(response); + } + let token = tmp.next().unwrap().to_string(); + let mut row: Option> = None; + let mut row2: Option> = None; + POOL.with(|poola| { + let mut con = poola.get_conn().unwrap(); + let mut result = con.exec_iter("Select id, role from users where id =(SELECT user FROM `inz`.`sessions` where token = ? and expire > NOW());", (&token, )).unwrap(); + let mut it = result.iter().unwrap(); + row = it.next(); + if row.is_none() { + *response.status_mut() = StatusCode::FORBIDDEN; + return; + } + let mut con2 = poola.get_conn().unwrap(); + let mut result2 = con2.exec_iter("Select paymentstatus, paymentreference, userid, paymenttype from registrations where id =?;", (&val, )).unwrap(); + let mut it2 = result2.iter().unwrap(); + row2 = it2.next(); + }); + if row2.is_none() { + *response.status_mut() = StatusCode::NOT_FOUND; + return Ok(response); + } + let urow = row.unwrap().unwrap(); + let urow2 = row2.unwrap().unwrap(); + let id: i32 = urow.get(0).unwrap(); + let role: String = urow.get(1).unwrap(); + let paymentstatus: String = urow2.get(0).unwrap(); + let paymentreference: String = urow2.get(1).unwrap(); + let userid: String = urow2.get(2).unwrap(); + let paymenttype: String = urow2.get(3).unwrap(); + if role == "1" || role == "2" { + if userid != id.to_string() { + *response.status_mut() = StatusCode::NOT_FOUND; + return Ok(response); + } + } + if paymentstatus == "PENDING" && paymenttype != "cash" { + if paymenttype == "btc" { + let client = Client::new(); + let req = Request::builder() + .method(Method::GET) + .uri("http://10.1.6.101:8082/api/v1/stores/*****/invoices/".to_owned() + &paymentreference) + .header("content-type", "application/json") + .header("Authorization", "token ******").body(Body::empty()).unwrap(); + let resp = client.request(req).await.unwrap(); + let parsed: serde_json::Value = serde_json::from_slice(hyper::body::to_bytes(resp.into_body()).await.unwrap().as_ref()).unwrap(); + let stat: String = parsed.get("status").unwrap().as_str().unwrap().into(); + if stat == "New" { + *response.body_mut() = Body::from("{\"status\":\"PENDING\"}"); + } else { + if stat == "Settled" { + *response.body_mut() = Body::from("{\"status\":\"DONE\"}"); + POOL.with(|poola| { + poola.get_conn().unwrap().exec_drop("Update registrations set paymentstatus ='DONE' where id = ?", (val, )).unwrap(); + }); + } else { + if stat == "Processing" { + *response.body_mut() = Body::from("{\"status\":\"PROCESSING\"}"); + } else { + if stat == "Expired" { + *response.body_mut() = Body::from("{\"status\":\"EXPIRED\"}"); + POOL.with(|poola| { + poola.get_conn().unwrap().exec_drop("Update registrations set paymentstatus ='EXPIRED' where id = ?", (val, )).unwrap(); + }); + } else { + *response.body_mut() = Body::from("{\"status\":\"".to_owned() + &stat + "\"}"); + POOL.with(|poola| { + poola.get_conn().unwrap().exec_drop("Update registrations set paymentstatus ='?' where id = ?", (stat, val)).unwrap(); + }); + } + } + } + } + } + } else { + *response.body_mut() = Body::from("{\"status\":\"".to_owned() + &paymentstatus + "\"}"); + } + } else { + *response.status_mut() = StatusCode::UNAUTHORIZED; + } + } + (&Method::PUT, "/registration") => { + if req.headers().contains_key("Authorization") { + let mut tmp = req.headers().get("Authorization").unwrap().to_str().unwrap().split(" "); + let aa = tmp.next().unwrap(); + if aa != "Bearer" { + *response.status_mut() = StatusCode::UNAUTHORIZED; + return Ok(response); + } + let token = tmp.next().unwrap().to_string(); + let byte_stream = hyper::body::to_bytes(req).await.unwrap(); + let s: HashMap = serde_json::from_slice(&byte_stream).unwrap(); + let mut row: Option> = None; + POOL.with(|poola| { + let mut con = poola.get_conn().unwrap(); + + let mut result = con.exec_iter("Select id from users where id =(SELECT user FROM `inz`.`sessions` where token = ? and expire > NOW());", (&token, )).unwrap(); + let mut it = result.iter().unwrap(); + row = it.next(); + }); + if row.is_none() { + *response.status_mut() = StatusCode::FORBIDDEN; + return Ok(response); + } + let urow = row.unwrap().unwrap(); + let id: i32 = urow.get(0).unwrap(); + if s.contains_key("tournament") && s.contains_key("paymentmethod") { + let tournament = s.get("tournament").unwrap().to_string(); + let paymentmethod = s.get("paymentmethod").unwrap().to_string(); + if paymentmethod == "btc" { + let client = Client::new(); + let req = Request::builder() + .method(Method::POST) + .uri("http://10.1.6.101:8082/api/v1/stores/****/invoices") + .header("content-type", "application/json") + .header("Authorization", "token *****") + .body(Body::from("{\"metadata\": {\"orderId\": \"id123\"},\"checkout\": {\"speedPolicy\": \"LowMediumSpeed\",\"redirectURL\":\"https://www.google.com\"},\"amount\": \"1.00\",\"currency\": \"PLN\"}")).unwrap(); + let resp = client.request(req).await.unwrap(); + let parsed: serde_json::Value = serde_json::from_slice(hyper::body::to_bytes(resp.into_body()).await.unwrap().as_ref()).unwrap(); + POOL.with(|poola| { + let tmp: String = parsed.get("id").unwrap().as_str().unwrap().into(); + let nid: String = poola.get_conn().unwrap().exec_iter("INSERT INTO `inz`.`registrations`(`userid`,`tournamentid`,`paymenttype`,`paymentstatus`,`approval`,`paymentreference`)VALUES(?,?,'btc','PENDING',0,?);", (id, tournament, &tmp)).unwrap().last_insert_id().unwrap().to_string(); + let mut checkout: String = parsed.get("checkoutLink").unwrap().as_str().unwrap().into(); + checkout = checkout.replace("http://10.1.6.101:8082/", "https://btcpay.dragonmaster.pl/"); + *response.body_mut() = Body::from("{\"id\":\"".to_owned() + &nid + "\",\"url\":\"" + &*checkout + "\"}"); + }); + } else { + if paymentmethod == "cash" { + POOL.with(|poola| { + let nid = "{\"id\":".to_owned() + &poola.get_conn().unwrap().exec_iter("INSERT INTO `inz`.`registrations`(`userid`,`tournamentid`,`paymenttype`,`paymentstatus`,`approval`,`paymentreference`)VALUES(?,?,'cash','PENDING',0,'N/A');", (id, tournament)).unwrap().last_insert_id().unwrap().to_string() + "\"}"; + *response.body_mut() = nid.into(); + }); + } else { + *response.body_mut() = "{\"error\":\"bad payment method\"}".into(); + } + } + } else { + *response.body_mut() = "{\"error\":\"not all fields\"}".into(); + } + } else { + *response.status_mut() = StatusCode::UNAUTHORIZED; + } + } + (&Method::POST, "/tournament") => { + if req.headers().contains_key("Authorization") { + let mut tmp = req.headers().get("Authorization").unwrap().to_str().unwrap().split(" "); + let aa = tmp.next().unwrap(); + if aa != "Bearer" { + *response.status_mut() = StatusCode::UNAUTHORIZED; + return Ok(response); + } + let token = tmp.next().unwrap().to_string(); + let byte_stream = hyper::body::to_bytes(req).await.unwrap(); + let s: HashMap = serde_json::from_slice(&byte_stream).unwrap(); + POOL.with(|poola| { + let mut con = poola.get_conn().unwrap(); + let mut result = con.exec_iter("Select role, id from users where id =(SELECT user FROM `inz`.`sessions` where token = ? and expire > NOW());", (&token, )).unwrap(); + let mut it = result.iter().unwrap(); + let row = it.next(); + if row.is_none() { + *response.status_mut() = StatusCode::FORBIDDEN; + return; + } + let urow = row.unwrap().unwrap(); + let role: String = urow.get(0).unwrap(); + let id: i32 = urow.get(1).unwrap(); + if role == "1" { + *response.status_mut() = StatusCode::FORBIDDEN; + return; + } + if s.contains_key("id") { + let tid = s.get("id").unwrap().to_string(); + if role != "3" { + let creator: i32 = poola.get_conn().unwrap().exec_first("Select creator from tournaments where id = ?", (&tid, )).unwrap().unwrap(); + if creator != id { + *response.status_mut() = StatusCode::FORBIDDEN; + return; + } + } + if s.contains_key("name") { + poola.get_conn().unwrap().exec_drop("Update tournaments set name =? where id = ? and deleted =0", (s.get("name"), &tid)).unwrap(); + } + if s.contains_key("typeOfLadder") { + poola.get_conn().unwrap().exec_drop("Update tournaments set typeOfLadder =? where id = ? and deleted =0", (s.get("typeOfLadder"), &tid)).unwrap(); + } + if s.contains_key("pointsForTournament") { + poola.get_conn().unwrap().exec_drop("Update tournaments set pointsForTournament =? where id = ? and deleted =0", (s.get("pointsForTournament"), &tid)).unwrap(); + } + if s.contains_key("places") { + poola.get_conn().unwrap().exec_drop("Update tournaments set places =? where id = ? and deleted =0", (s.get("places"), &tid)).unwrap(); + } + if s.contains_key("roles") { + poola.get_conn().unwrap().exec_drop("Update tournaments set roles =? where id = ? and deleted =0", (s.get("roles"), &tid)).unwrap(); + } + *response.body_mut() = "{}".into(); + } else { + *response.body_mut() = "{\"error\":\"not all fields\"}".into(); + } + }); + } else { + *response.status_mut() = StatusCode::UNAUTHORIZED; + } + } + (&Method::DELETE, "/tournament") => { + if req.headers().contains_key("Authorization") { + let mut tmp = req.headers().get("Authorization").unwrap().to_str().unwrap().split(" "); + let aa = tmp.next().unwrap(); + if aa != "Bearer" { + *response.status_mut() = StatusCode::UNAUTHORIZED; + return Ok(response); + } + let token = tmp.next().unwrap().to_string(); + let byte_stream = hyper::body::to_bytes(req).await.unwrap(); + let s: HashMap = serde_json::from_slice(&byte_stream).unwrap(); + POOL.with(|poola| { + let mut con = poola.get_conn().unwrap(); + + let mut result = con.exec_iter("Select role, id from users where id =(SELECT user FROM `inz`.`sessions` where token = ? and expire > NOW());", (&token, )).unwrap(); + let mut it = result.iter().unwrap(); + let row = it.next(); + if row.is_none() { + *response.status_mut() = StatusCode::FORBIDDEN; + return; + } + let urow = row.unwrap().unwrap(); + let role: String = urow.get(0).unwrap(); + let id: i32 = urow.get(1).unwrap(); + if role == "1" { + *response.status_mut() = StatusCode::FORBIDDEN; + return; + } + if s.contains_key("id") { + let tid = s.get("id").unwrap().to_string(); + if role != "3" { + let creator: i32 = poola.get_conn().unwrap().exec_first("Select creator from tournaments where id = ?", (&tid, )).unwrap().unwrap(); + if creator != id { + *response.status_mut() = StatusCode::FORBIDDEN; + return; + } + } + poola.get_conn().unwrap().exec_drop("Update tournaments set deleted =1 where id = ?", (tid, )).unwrap(); + *response.body_mut() = "{}".into(); + } else { + *response.body_mut() = "{\"error\":\"not all fields\"}".into(); + } + }); + } else { + *response.status_mut() = StatusCode::UNAUTHORIZED; + } + } + (&Method::GET, "/tournaments") => { + POOL.with(|poola| { + let res = poola.get_conn().unwrap() + .query_map( + "SELECT id, name, typeOfLadder, pointsForTournament, places, roles, creator,approved from tournaments where deleted =0", + |(id, name, type_of_ladder, points_for_tournament, places, roles, creator, approved)| { + tournament { id, name, typeOfLadder: type_of_ladder, places, roles, creator, pointsForTournament: points_for_tournament, approved } + }, + ); + *response.body_mut() = serde_json::to_string(&res.unwrap()).unwrap().into(); + }); + } + (&Method::PUT, "/tournament") => { + if req.headers().contains_key("Authorization") { + let mut tmp = req.headers().get("Authorization").unwrap().to_str().unwrap().split(" "); + let aa = tmp.next().unwrap(); + if aa != "Bearer" { + *response.status_mut() = StatusCode::UNAUTHORIZED; + return Ok(response); + } + let token = tmp.next().unwrap().to_string(); + let byte_stream = hyper::body::to_bytes(req).await.unwrap(); + let s: HashMap = serde_json::from_slice(&byte_stream).unwrap(); + POOL.with(|poola| { + let mut con = poola.get_conn().unwrap(); + + let mut result = con.exec_iter("Select role, id from users where id =(SELECT user FROM `inz`.`sessions` where token = ? and expire > NOW());", (&token, )).unwrap(); + let mut it = result.iter().unwrap(); + let row = it.next(); + if row.is_none() { + *response.status_mut() = StatusCode::FORBIDDEN; + return; + } + let urow = row.unwrap().unwrap(); + let role: String = urow.get(0).unwrap(); + let id: i32 = urow.get(1).unwrap(); + if role == "1" { + *response.status_mut() = StatusCode::FORBIDDEN; + return; + } + if s.contains_key("name") && s.contains_key("typeOfLadder") && s.contains_key("pointsForTournament") && s.contains_key("places") && s.contains_key("roles") && s.contains_key("ranked") { + let name = s.get("name").unwrap().to_string(); + let type_of_ladder = s.get("typeOfLadder").unwrap().to_string(); + let points_for_tournament = s.get("pointsForTournament").unwrap().to_string(); + let places = s.get("places").unwrap().to_string(); + let roles = s.get("roles").unwrap().to_string(); + let mut ranked = s.get("ranked").unwrap().to_string(); + if ranked != "0" && ranked != "1" { + ranked = String::from("0"); + } + let str = "{\"id\":".to_owned() + &poola.get_conn().unwrap().exec_iter("INSERT INTO `inz`.`tournaments`(`name`,`typeOfLadder`,`pointsForTournament`,`places`,`roles`,`creator`,`deleted`,`approved`) VALUES (?,?,?,?,?,?,0,?);", (name, type_of_ladder, points_for_tournament, places, roles, id, ranked)).unwrap().last_insert_id().unwrap().to_string() + "}"; + *response.body_mut() = str.into(); + } else { + *response.body_mut() = "{\"error\":\"not all fields\"}".into(); + } + }); + } else { + *response.status_mut() = StatusCode::UNAUTHORIZED; + } + } + (&Method::POST, "/user") => { + let headers = (&req).headers(); + let mut tmp = headers.get("Authorization").unwrap().to_str().unwrap().split(" "); + let aa = tmp.next().unwrap(); + if aa != "Bearer" { + *response.status_mut() = StatusCode::UNAUTHORIZED; + return Ok(response); + } + let token = tmp.next().unwrap().to_string(); + if req.headers().contains_key("Authorization") { + let byte_stream = hyper::body::to_bytes(req).await.unwrap(); + let s: HashMap = serde_json::from_slice(&byte_stream).unwrap(); + POOL.with(|poola| { + let mut con = poola.get_conn().unwrap(); + let mut result = con.exec_iter("Select id from users where id =(SELECT user FROM `inz`.`sessions` where token = ? and expire > NOW());", (token, )).unwrap(); + let mut it = result.iter().unwrap(); + let row = it.next(); + if row.is_none() { + *response.status_mut() = StatusCode::FORBIDDEN; + return; + } + let urow = row.unwrap().unwrap(); + let idi: i32 = urow.get(0).unwrap(); + if s.contains_key("name") { + poola.get_conn().unwrap().exec_drop("Update users set name =? where id = ?", (s.get("name"), idi)).unwrap(); + } + if s.contains_key("surname") { + poola.get_conn().unwrap().exec_drop("Update users set surname =? where id = ?", (s.get("surname"), idi)).unwrap(); + } + if s.contains_key("password") { + poola.get_conn().unwrap().exec_drop("Update users set password =? where id = ?", (hash(s.get("password").unwrap().to_string(), DEFAULT_COST - 6).unwrap(), idi)).unwrap(); + } + if s.contains_key("mail") { + poola.get_conn().unwrap().exec_drop("Update users set mail =? where id = ?", (s.get("mail"), idi)).unwrap(); + } + if s.contains_key("phone") { + poola.get_conn().unwrap().exec_drop("Update users set phone =? where id = ?", (s.get("phone "), idi)).unwrap(); + } + }); + } else { + *response.status_mut() = StatusCode::UNAUTHORIZED; + } + } + (&Method::GET, "/user") => { + if req.headers().contains_key("Authorization") { + POOL.with(|poola| { + let mut con = poola.get_conn().unwrap(); + let mut tmp = req.headers().get("Authorization").unwrap().to_str().unwrap().split(" "); + let aa = tmp.next().unwrap(); + if aa != "Bearer" { + *response.status_mut() = StatusCode::UNAUTHORIZED; + return; + } + let token = tmp.next().unwrap(); + let mut result = con.exec_iter("Select * from users where id =(SELECT user FROM `inz`.`sessions` where token = ? and expire > NOW());", (&token, )).unwrap(); + let mut it = result.iter().unwrap(); + let row = it.next(); + if row.is_none() { + *response.status_mut() = StatusCode::FORBIDDEN; + return; + } + let urow = row.unwrap().unwrap(); + let a = User { id: urow.get(0).unwrap(), name: urow.get(1).unwrap(), surname: urow.get(2).unwrap(), role: urow.get(3).unwrap(), login: urow.get(4).unwrap(), phone: urow.get(7).unwrap(), mail: urow.get(6).unwrap() }; + + *response.body_mut() = serde_json::to_string(&a).unwrap().into(); + }); + } else { + *response.status_mut() = StatusCode::UNAUTHORIZED; + } + } + (&Method::PUT, "/user/create") => { + let byte_stream = hyper::body::to_bytes(req).await.unwrap(); + let s: HashMap = serde_json::from_slice(&byte_stream).unwrap(); + if s.contains_key("username") && s.contains_key("name") && s.contains_key("surname") && s.contains_key("password") && s.contains_key("role") && s.contains_key("mail") && s.contains_key("phone") { + let username = s.get("username").unwrap().to_string(); + let name = s.get("name").unwrap().to_string(); + let surname = s.get("surname").unwrap().to_string(); + let password = hash(s.get("password").unwrap().to_string(), DEFAULT_COST - 6).unwrap(); + let role = s.get("role").unwrap().to_string(); + let mail = s.get("mail").unwrap().to_string(); + let phone = s.get("phone").unwrap().to_string(); + if role == "1" || role == "2" { + POOL.with(|poola| { + let mut con = poola.get_conn().unwrap() ; + let mut a = con.exec_iter("select `login` from users where login = ?", (&username,)).unwrap(); + let it = a.iter().unwrap().next(); + if(it.is_none()) { + poola.get_conn().unwrap().exec_drop("INSERT INTO `inz`.`users`(`name`,`surname`,`role`,`login`,`password`,`mail`,`phone`,`deleted`)VALUES (?,?,?,?,?,?,?,0);", (name, surname, role, username, password, mail, phone)).unwrap(); + } + }); + *response.body_mut() = "{}".into(); + } else { + *response.body_mut() = "{\"error\":\"bad role\"}".into(); + } + } else { + *response.body_mut() = "{\"error\":\"not all fields\"}".into(); + } + } + (&Method::POST, "/user/login") => { + let byte_stream = hyper::body::to_bytes(req).await.unwrap(); + let s: HashMap = serde_json::from_slice(&byte_stream).unwrap(); + if s.contains_key("username") && s.contains_key("password") { + let username = s.get("username").unwrap().to_string(); + let password = s.get("password").unwrap().to_string(); + *response.body_mut() = POOL.with(|poola| { + let mut con = poola.get_conn().unwrap(); + let mut result = con.exec_iter("SELECT * FROM `inz`.`users` where login = ? and `deleted`=0;", (&username, )).unwrap(); + let mut it = result.iter().unwrap(); + let row = it.next(); + if !row.is_none() { + let urow = row.unwrap().unwrap(); + let pas: String = urow.get(5).unwrap(); + let id: i32 = urow.get(0).unwrap(); + if verify(&password, &pas).unwrap() { + let mut rand: OsRng = OsRng::new().expect("Error opening random number generator"); + if !it.next().is_none() { + return Body::from("{\"error\":\"wrong username or password\"}"); + } + const CHARSET: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\ + abcdefghijklmnopqrstuvwxyz\ + 0123456789"; + const PASSWORD_LEN: usize = 80; + let password: String = (0..PASSWORD_LEN) + .map(|_| { + let idx = rand.gen_range(0, CHARSET.len()); + CHARSET[idx] as char + }) + .collect(); + poola.get_conn().unwrap().exec_drop("DELETE FROM `inz`.`sessions`WHERE user = ?;", (id, )).unwrap(); + poola.get_conn().unwrap().exec_drop("INSERT INTO `inz`.`sessions`(`user`,`token`,`expire`)VALUES (?,?,DATE_ADD(NOW(), INTERVAL 30 MINUTE));", (id, &password)).unwrap(); + return Body::from("{\"token\":\"".to_owned() + &password + "\"}"); + } else { + return Body::from("{\"error\":\"wrong username or password\"}"); + } + } else { + hash("asd", DEFAULT_COST - 6).unwrap(); + return Body::from("{\"error\":\"wrong username or password\"}"); + } + }); + } else { + *response.body_mut() = "{\"error\":\"not all fields\"}".into(); + } + } + + _ => { + *response.status_mut() = StatusCode::NOT_FOUND; + } + }; + Ok(response) +} + +#[tokio::main] +async fn main() { + let addr = SocketAddr::from(([0, 0, 0, 0], 1000)); + let make_svc = make_service_fn(|_conn| async { + Ok::<_, Infallible>(service_fn(hello_world)) + }); + let server = Server::bind(&addr).serve(make_svc); + if let Err(e) = server.await { + eprintln!("server error: {}", e); + } +} diff --git a/src/main1.rs b/src/main1.rs new file mode 100644 index 0000000..db48c7a --- /dev/null +++ b/src/main1.rs @@ -0,0 +1,55 @@ +use serde_derive::{Serialize, Deserialize}; +use mysql::*; +use mysql::prelude::*; +use std::convert::Infallible; +use std::net::SocketAddr; +use hyper::{Body, Request, Response, Server}; +use hyper::service::{make_service_fn, service_fn}; +#[derive(Serialize, Deserialize)] +struct dane { + id:i32, + data:String +} + +fn getJson() -> Vec { + let url = "mysql://inz:HaLzqw68CbabS8Smz3Vx!@localhost:3306/inz"; + +let opts = Opts::from_url(url).unwrap(); +let pool = Pool::new(opts).unwrap(); +let mut conn = pool.get_conn().unwrap(); +let res = conn + .query_map( + "SELECT id, data from dane", + |(id,data)| { + dane { id,data } + }, + ); + return res.unwrap(); +} +async fn hello_world(_req: Request) -> Result> { + let path :String = _req.uri().path().to_string(); + if path != "/mysql"{ +return Ok(Response::new(path.into())); +}else{ + return Ok(Response::new(serde_json::to_string(&getJson()).unwrap().into())) + } +} +#[tokio::main] +async fn main() { + let addr = SocketAddr::from(([0, 0, 0, 0], 1000)); + + // A `Service` is needed for every connection, so this + // creates one from our `hello_world` function. + let make_svc = make_service_fn(|_conn| async { + // service_fn converts our function into a `Service` + Ok::<_, Infallible>(service_fn(hello_world)) + }); + + let server = Server::bind(&addr).serve(make_svc); + + // Run this server for... forever! + if let Err(e) = server.await { + eprintln!("server error: {}", e); + } + +}