hangups-rs

Rust version of hangups (WIP) Currently Login not possible
git clone git://archive.git.mtrnord.blog/Nordgedanken/hangups-rs.git
Log | Files | Refs | README | LICENSE

commit 93fc1576b017bb6e9c3ed7b409741ecac3540919
parent 98c3d0806d18f62b690cfaeaa8e4c44aebedf93e
Author: MTRNord <mtrnord1@gmail.com>
Date:   Sat, 22 Apr 2017 20:12:46 +0200

nearly fix all hyper issues

Diffstat:
Mlog.txt | 141-------------------------------------------------------------------------------
Msrc/hangups/mod.rs | 19+++++++------------
Msrc/lib.rs | 31++++++++-----------------------
3 files changed, 15 insertions(+), 176 deletions(-)

diff --git a/log.txt b/log.txt @@ -1,142 +1 @@ - Updating registry `https://github.com/rust-lang/crates.io-index` - Updating git repository `https://github.com/hyperium/hyper` - Downloading futures v0.1.13 - Downloading sha1 v0.2.0 - Downloading rand v0.3.15 - Downloading regex v0.2.1 - Downloading tokio-core v0.1.6 - Downloading jconfig v0.1.0 - Downloading rustc-serialize v0.3.23 - Downloading url v1.4.0 - Downloading protobuf v1.2.2 - Downloading libc v0.2.21 - Downloading aho-corasick v0.6.3 - Downloading regex-syntax v0.4.0 - Downloading memchr v1.0.1 - Downloading thread_local v0.3.3 - Downloading utf8-ranges v1.0.0 - Downloading unreachable v0.1.1 - Downloading void v1.0.2 - Downloading bytes v0.4.2 - Downloading tokio-io v0.1.1 - Downloading mio v0.6.6 - Downloading scoped-tls v0.1.0 - Downloading iovec v0.1.0 - Downloading log v0.3.7 - Downloading slab v0.3.0 - Downloading byteorder v1.0.0 - Downloading net2 v0.2.27 - Downloading lazycell v0.4.0 - Downloading cfg-if v0.1.0 - Downloading traitobject v0.0.3 - Downloading quick-error v1.1.0 - Downloading unicase v1.4.0 - Downloading rustc_version v0.1.7 - Downloading semver v0.1.20 - Downloading httparse v1.2.1 - Downloading base64 v0.4.1 - Downloading time v0.1.36 - Downloading mime v0.2.3 - Downloading language-tags v0.2.2 - Downloading tokio-service v0.1.0 - Downloading tokio-proto v0.1.1 - Downloading futures-cpupool v0.1.5 - Downloading matches v0.1.4 - Downloading idna v0.1.1 - Downloading unicode-bidi v0.2.5 - Downloading unicode-normalization v0.1.4 - Downloading smallvec v0.2.1 - Downloading take v0.1.0 - Downloading num_cpus v1.3.0 - Downloading thread-id v3.0.0 - Compiling lazycell v0.4.0 - Compiling byteorder v1.0.0 - Compiling base64 v0.4.1 - Compiling slab v0.3.0 - Compiling take v0.1.0 - Compiling futures v0.1.13 - Compiling iovec v0.1.0 - Compiling bytes v0.4.2 - Compiling cfg-if v0.1.0 - Compiling smallvec v0.2.1 - Compiling tokio-service v0.1.0 - Compiling tokio-io v0.1.1 - Compiling scoped-tls v0.1.0 - Compiling net2 v0.2.27 - Compiling mio v0.6.6 - Compiling tokio-core v0.1.6 - Compiling tokio-proto v0.1.1 - Compiling futures-cpupool v0.1.5 - Compiling hyper v0.11.0-a.0 (https://github.com/hyperium/hyper#736a342e) Compiling hangups v0.0.1 (file:///source) -error[E0382]: use of moved value: `core` - --> src/lib.rs:257:9 - | -233 | let req_raw = client.get(auth_uri).and_then(|res| { - | ----- value moved (into closure) here -... -257 | core.run(req).unwrap(); - | ^^^^ value used here after move - | - = note: move occurs because `core` has type `tokio_core::reactor::Core`, which does not implement the `Copy` trait - -error: cannot borrow immutable borrowed content as mutable - --> src/lib.rs:247:115 - | -247 | do_auth_step(&mut core, &client, email_uri, &res, &body.as_str(), client_email, client_email, &mut headers); - | ^^^^^^^^^^^^ cannot borrow as mutable - -error[E0505]: cannot move out of `res` because it is borrowed - --> src/lib.rs:240:18 - | -236 | &res.headers() - | --- borrow of `res` occurs here -... -240 | &res.body().for_each(|chunk| { - | ^^^ move out of `res` occurs here - -error[E0382]: use of moved value: `core` - --> src/lib.rs:247:39 - | -246 | let core_raw = core; - | -------- value moved here -247 | do_auth_step(&mut core, &client, email_uri, &res, &body.as_str(), client_email, client_email, &mut headers); - | ^^^^ value used here after move - | - = note: move occurs because `core` has type `tokio_core::reactor::Core`, which does not implement the `Copy` trait - -error[E0382]: use of moved value: `res` - --> src/lib.rs:247:66 - | -240 | &res.body().for_each(|chunk| { - | --- value moved here -... -247 | do_auth_step(&mut core, &client, email_uri, &res, &body.as_str(), client_email, client_email, &mut headers); - | ^^^ value used here after move - | - = note: move occurs because `res` has type `hyper::client::Response`, which does not implement the `Copy` trait - -error[E0382]: use of moved value: `client_email` - --> src/lib.rs:247:101 - | -247 | do_auth_step(&mut core, &client, email_uri, &res, &body.as_str(), client_email, client_email, &mut headers); - | ------------ ^^^^^^^^^^^^ value used here after move - | | - | value moved here - | - = note: move occurs because `client_email` has type `std::string::String`, which does not implement the `Copy` trait - -error[E0505]: cannot move out of `body` because it is borrowed - --> src/hangups/mod.rs:125:12 - | -109 | let post_req = client.request(fresh_request).map_err(|_| ()).and_then(|res| { - | ----- borrow of `body` occurs here -... -125 | Ok(body) - | ^^^^ move out of `body` occurs here - -error: aborting due to 7 previous errors - -error: Could not compile `hangups`. - -To learn more, run the command again with --verbose. diff --git a/src/hangups/mod.rs b/src/hangups/mod.rs @@ -79,6 +79,9 @@ pub mod hangups { use tokio_core::reactor::Core; use std::str::FromStr; use futures::{Future, Stream}; + use std::cell::RefCell; + use std::rc::Rc; + let mut core = Core::new().unwrap(); let handle = core.handle(); @@ -105,20 +108,12 @@ pub mod hangups { } let mut body = String::new(); - let mut post = { - let post_req = client.request(fresh_request).map_err(|_| ()).and_then(|res| { - res.body().for_each(|chunk| { - let body_chunk = String::from_utf8(chunk.to_vec()).unwrap(); - body.push_str(body_chunk.as_str()); - Ok(()) - }); - Ok(()) - }) - .map(|_| { + let mut post = client.request(fresh_request) + .map(|res| { + let body = res.body(); println!("\n\nDone."); + body }); - post_req - }; core.run(post).unwrap(); diff --git a/src/lib.rs b/src/lib.rs @@ -15,7 +15,7 @@ pub mod auth { use hyper::client::{Response, HttpConnector}; use tokio_core::reactor::Core; use hyper::header::Headers; - fn do_auth_step(mut core: &mut Core, client: &Client<HttpConnector, Body>, url: Uri, resp: &Response, resp_body: &str, email: String, password: String, mut resp_headers_raw: &mut Headers) { + fn do_auth_step(client: &Client<HttpConnector, Body>, url: Uri, resp: &Response, resp_body: &str, email: String, password: String, mut resp_headers_raw: &Headers) { use hyper::header::{Headers, SetCookie, UserAgent}; use hyper::client::Request; use hyper::{Method, Uri}; @@ -25,7 +25,9 @@ pub mod auth { use std::str::FromStr; use futures::Future; use futures::Stream; + use tokio_core::reactor::Core; + let mut core = Core::new().unwrap(); header! { (ContentType, "content-type") => [String] } header! { (GAPS, "GAPS") => [String] } header! { (GALX, "GALX") => [String] } @@ -229,30 +231,13 @@ pub mod auth { println!("You typed: {}", client_passwd); // Login Step1 - let req = { - let req_raw = client.get(auth_uri).and_then(|res| { - println!("Response: {}", &res.status()); - let mut headers = { - &res.headers() - }; - let mut body = String::new(); - - &res.body().for_each(|chunk| { - let body_chunk = String::from_utf8(chunk.to_vec()).unwrap(); - body.push_str(body_chunk.as_str()); + let req = client.get(auth_uri).and_then(move |res| { + do_auth_step(&client, email_uri, &res, &format!("{:?}", &res.body()).as_str(), client_email, client_passwd, &res.headers()); Ok(()) + }) + .map(|_| { + println!("\n\nDone."); }); - { - let core_raw = core; - do_auth_step(&mut core, &client, email_uri, &res, &body.as_str(), client_email, client_email, &mut headers); - } - Ok(()) - }) - .map(|_| { - println!("\n\nDone."); - }); - req_raw - }; core.run(req).unwrap(); }