Skip to content

Commit

Permalink
Fix utf username.
Browse files Browse the repository at this point in the history
  • Loading branch information
PlusMinus0 committed May 11, 2020
1 parent e47ae83 commit 522dac8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 4 additions & 1 deletion connect/src/spirc.rs
Expand Up @@ -14,11 +14,13 @@ use crate::playback::mixer::Mixer;
use crate::playback::player::{Player, PlayerEvent, PlayerEventChannel};
use crate::protocol;
use crate::protocol::spirc::{DeviceState, Frame, MessageType, PlayStatus, State, TrackRef};

use librespot_core::config::ConnectConfig;
use librespot_core::mercury::MercuryError;
use librespot_core::session::Session;
use librespot_core::spotify_id::{SpotifyAudioType, SpotifyId, SpotifyIdError};
use librespot_core::util::SeqGenerator;
use librespot_core::util::url_encode;
use librespot_core::version;
use librespot_core::volume::Volume;

Expand Down Expand Up @@ -249,7 +251,8 @@ impl Spirc {
let ident = session.device_id().to_owned();

// Uri updated in response to issue #288
let uri = format!("hm://remote/user/{}/", session.username());
debug!("canonical_username: {}", url_encode(&session.username()));
let uri = format!("hm://remote/user/{}/", url_encode(&session.username()));

let subscription = session.mercury().subscribe(&uri as &str);
let subscription = subscription
Expand Down
4 changes: 3 additions & 1 deletion core/src/mercury/mod.rs
@@ -1,4 +1,5 @@
use crate::protocol;
use crate::util::url_encode;
use byteorder::{BigEndian, ByteOrder};
use bytes::Bytes;
use futures::sync::{mpsc, oneshot};
Expand Down Expand Up @@ -187,12 +188,13 @@ impl MercuryManager {
data.split_to(size).as_ref().to_owned()
}


fn complete_request(&self, cmd: u8, mut pending: MercuryPending) {
let header_data = pending.parts.remove(0);
let header: protocol::mercury::Header = protobuf::parse_from_bytes(&header_data).unwrap();

let response = MercuryResponse {
uri: header.get_uri().to_owned(),
uri: url_encode(header.get_uri()).to_owned(),
status_code: header.get_status_code(),
payload: pending.parts,
};
Expand Down
14 changes: 14 additions & 0 deletions core/src/util/mod.rs
Expand Up @@ -12,6 +12,20 @@ pub fn rand_vec<G: Rng>(rng: &mut G, size: usize) -> Vec<u8> {
.collect()
}

pub fn url_encode(inp: &str) -> String {
let mut encoded = String::new();

for c in inp.as_bytes().iter() {
match *c as char {
'A'..='Z' | 'a'..='z' | '0'..='9' | '-' | '_' | '.' | '~' | ':' | '/' => encoded.push(*c as char),
c => encoded.push_str(format!("%{:02X}", c as u32).as_str()),
};
}

encoded
}


pub fn powm(base: &BigUint, exp: &BigUint, modulus: &BigUint) -> BigUint {
let mut base = base.clone();
let mut exp = exp.clone();
Expand Down

0 comments on commit 522dac8

Please sign in to comment.