Compare commits
1 Commits
main
...
deduplicat
Author | SHA1 | Date | |
---|---|---|---|
e469a8eb3c |
src/commands
client_to_client
connection_settings
music_database
queue
reflection
stickers
stored_playlists
@ -34,8 +34,12 @@ impl Command for ReadMessages {
|
|||||||
let (ckey, cvalue) = channel_message_pair[0];
|
let (ckey, cvalue) = channel_message_pair[0];
|
||||||
let (mkey, mvalue) = channel_message_pair[1];
|
let (mkey, mvalue) = channel_message_pair[1];
|
||||||
|
|
||||||
debug_assert!(ckey == "channel");
|
if ckey != "channel" {
|
||||||
debug_assert!(mkey == "message");
|
return Err(ResponseParserError::UnexpectedProperty(ckey));
|
||||||
|
}
|
||||||
|
if mkey != "message" {
|
||||||
|
return Err(ResponseParserError::UnexpectedProperty(mkey));
|
||||||
|
}
|
||||||
|
|
||||||
let channel = expect_property_type!(Some(cvalue), "channel", Text).to_string();
|
let channel = expect_property_type!(Some(cvalue), "channel", Text).to_string();
|
||||||
let message = expect_property_type!(Some(mvalue), "message", Text).to_string();
|
let message = expect_property_type!(Some(mvalue), "message", Text).to_string();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::commands::{
|
use crate::commands::{
|
||||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
|
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||||
ResponseParserError,
|
expect_property_type,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct TagTypes;
|
pub struct TagTypes;
|
||||||
@ -24,16 +24,7 @@ impl Command for TagTypes {
|
|||||||
let mut tagtypes = Vec::with_capacity(parts.len());
|
let mut tagtypes = Vec::with_capacity(parts.len());
|
||||||
for (key, value) in parts.into_iter() {
|
for (key, value) in parts.into_iter() {
|
||||||
debug_assert_eq!(key, "tagtype");
|
debug_assert_eq!(key, "tagtype");
|
||||||
|
let tagtype = expect_property_type!(Some(value), "tagtype", Text).to_string();
|
||||||
let tagtype = match value {
|
|
||||||
GenericResponseValue::Text(name) => name.to_string(),
|
|
||||||
GenericResponseValue::Binary(_) => {
|
|
||||||
return Err(ResponseParserError::UnexpectedPropertyType(
|
|
||||||
"tagtype", "Binary",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
tagtypes.push(tagtype);
|
tagtypes.push(tagtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use crate::commands::{
|
use crate::commands::{
|
||||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||||
ResponseAttributes, ResponseParserError,
|
ResponseAttributes, ResponseParserError, expect_property_type,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct ReadComments;
|
pub struct ReadComments;
|
||||||
@ -30,10 +30,12 @@ impl Command for ReadComments {
|
|||||||
let parts: HashMap<_, _> = parts.into();
|
let parts: HashMap<_, _> = parts.into();
|
||||||
|
|
||||||
let comments = parts
|
let comments = parts
|
||||||
.iter()
|
.into_iter()
|
||||||
.map(|(k, v)| match v {
|
.map(|(k, v)| {
|
||||||
GenericResponseValue::Text(s) => Ok((k.to_string(), s.to_string())),
|
Ok((
|
||||||
GenericResponseValue::Binary(_) => Err(ResponseParserError::SyntaxError(1, k)),
|
k.to_string(),
|
||||||
|
expect_property_type!(Some(v), k, Text).to_string(),
|
||||||
|
))
|
||||||
})
|
})
|
||||||
.collect::<Result<HashMap<_, _>, ResponseParserError>>()?;
|
.collect::<Result<HashMap<_, _>, ResponseParserError>>()?;
|
||||||
|
|
||||||
|
@ -40,8 +40,15 @@ impl Command for AddId {
|
|||||||
) -> Result<Self::Response, ResponseParserError> {
|
) -> Result<Self::Response, ResponseParserError> {
|
||||||
let parts: Vec<_> = parts.into();
|
let parts: Vec<_> = parts.into();
|
||||||
let mut iter = parts.into_iter();
|
let mut iter = parts.into_iter();
|
||||||
|
|
||||||
let (key, id) = get_next_and_parse_property!(iter, Text);
|
let (key, id) = get_next_and_parse_property!(iter, Text);
|
||||||
debug_assert!(key == "Id");
|
|
||||||
|
if key != "Id" {
|
||||||
|
return Err(ResponseParserError::UnexpectedProperty(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
debug_assert!(iter.next().is_none());
|
||||||
|
|
||||||
Ok(AddIdResponse { id })
|
Ok(AddIdResponse { id })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::commands::{
|
use crate::commands::{
|
||||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
|
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||||
ResponseParserError,
|
expect_property_type,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Commands;
|
pub struct Commands;
|
||||||
@ -25,14 +25,7 @@ impl Command for Commands {
|
|||||||
if key != "command" {
|
if key != "command" {
|
||||||
return Err(ResponseParserError::UnexpectedProperty(key));
|
return Err(ResponseParserError::UnexpectedProperty(key));
|
||||||
}
|
}
|
||||||
let value = match value {
|
let value = expect_property_type!(Some(value), "command", Text);
|
||||||
GenericResponseValue::Text(value) => value,
|
|
||||||
GenericResponseValue::Binary(_) => {
|
|
||||||
return Err(ResponseParserError::UnexpectedPropertyType(
|
|
||||||
"handler", "Binary",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
result.push(value.to_string());
|
result.push(value.to_string());
|
||||||
}
|
}
|
||||||
Ok(result)
|
Ok(result)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::commands::{
|
use crate::commands::{
|
||||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
|
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||||
ResponseParserError,
|
expect_property_type,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct NotCommands;
|
pub struct NotCommands;
|
||||||
@ -25,14 +25,7 @@ impl Command for NotCommands {
|
|||||||
if key != "command" {
|
if key != "command" {
|
||||||
return Err(ResponseParserError::UnexpectedProperty(key));
|
return Err(ResponseParserError::UnexpectedProperty(key));
|
||||||
}
|
}
|
||||||
let value = match value {
|
let value = expect_property_type!(Some(value), "command", Text).to_string();
|
||||||
GenericResponseValue::Text(value) => value,
|
|
||||||
GenericResponseValue::Binary(_) => {
|
|
||||||
return Err(ResponseParserError::UnexpectedPropertyType(
|
|
||||||
"handler", "Binary",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
result.push(value.to_string());
|
result.push(value.to_string());
|
||||||
}
|
}
|
||||||
Ok(result)
|
Ok(result)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::commands::{
|
use crate::commands::{
|
||||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
|
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||||
ResponseParserError,
|
expect_property_type,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct UrlHandlers;
|
pub struct UrlHandlers;
|
||||||
@ -25,14 +25,7 @@ impl Command for UrlHandlers {
|
|||||||
if key != "handler" {
|
if key != "handler" {
|
||||||
return Err(ResponseParserError::UnexpectedProperty(key));
|
return Err(ResponseParserError::UnexpectedProperty(key));
|
||||||
}
|
}
|
||||||
let value = match value {
|
let value = expect_property_type!(Some(value), "handler", Text);
|
||||||
GenericResponseValue::Text(value) => value,
|
|
||||||
GenericResponseValue::Binary(_) => {
|
|
||||||
return Err(ResponseParserError::UnexpectedPropertyType(
|
|
||||||
"handler", "Binary",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
url_handlers.push(value.to_string());
|
url_handlers.push(value.to_string());
|
||||||
}
|
}
|
||||||
Ok(url_handlers)
|
Ok(url_handlers)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::commands::{
|
use crate::commands::{
|
||||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||||
ResponseAttributes, ResponseParserError,
|
ResponseParserError, expect_property_type,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct StickerFind;
|
pub struct StickerFind;
|
||||||
@ -84,21 +84,8 @@ impl Command for StickerFind {
|
|||||||
// TODO: debug assert that this is a valid sticker type
|
// TODO: debug assert that this is a valid sticker type
|
||||||
// debug_assert!(uri.0 == "");
|
// debug_assert!(uri.0 == "");
|
||||||
|
|
||||||
let uri = match uri.1 {
|
let uri = expect_property_type!(Some(uri.1), uri.0, Text).to_string();
|
||||||
GenericResponseValue::Text(s) => s.to_string(),
|
let sticker = expect_property_type!(Some(sticker.1), sticker.0, Text);
|
||||||
GenericResponseValue::Binary(_) => {
|
|
||||||
return Err(ResponseParserError::UnexpectedPropertyType(uri.0, "Binary"));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let sticker = match sticker.1 {
|
|
||||||
GenericResponseValue::Text(s) => s,
|
|
||||||
GenericResponseValue::Binary(_) => {
|
|
||||||
return Err(ResponseParserError::UnexpectedPropertyType(
|
|
||||||
"sticker", "Binary",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: This assumes the first = is the only one.
|
// TODO: This assumes the first = is the only one.
|
||||||
// See: https://github.com/MusicPlayerDaemon/MPD/issues/2166
|
// See: https://github.com/MusicPlayerDaemon/MPD/issues/2166
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::commands::{
|
use crate::commands::{
|
||||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||||
ResponseAttributes, ResponseParserError,
|
ResponseParserError, expect_property_type,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct StickerList;
|
pub struct StickerList;
|
||||||
@ -37,12 +37,7 @@ impl Command for StickerList {
|
|||||||
|
|
||||||
let result = parts
|
let result = parts
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(_, v)| match v {
|
.map(|(k, v)| Ok(expect_property_type!(Some(v), k, Text)))
|
||||||
GenericResponseValue::Text(value) => Ok(value),
|
|
||||||
GenericResponseValue::Binary(_) => Err(
|
|
||||||
ResponseParserError::UnexpectedPropertyType("sticker", "Binary"),
|
|
||||||
),
|
|
||||||
})
|
|
||||||
.collect::<Result<Vec<_>, ResponseParserError>>()?;
|
.collect::<Result<Vec<_>, ResponseParserError>>()?;
|
||||||
|
|
||||||
result
|
result
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::commands::{
|
use crate::commands::{
|
||||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
|
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||||
ResponseParserError,
|
expect_property_type,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct StickerNamesTypes;
|
pub struct StickerNamesTypes;
|
||||||
@ -34,23 +34,8 @@ impl Command for StickerNamesTypes {
|
|||||||
debug_assert!(name_key == "name");
|
debug_assert!(name_key == "name");
|
||||||
debug_assert!(type_key == "type");
|
debug_assert!(type_key == "type");
|
||||||
|
|
||||||
let name = match name_value {
|
let name = expect_property_type!(Some(name_value), name_key, Text).to_string();
|
||||||
GenericResponseValue::Text(s) => s.to_string(),
|
let sticker_type = expect_property_type!(Some(type_value), type_key, Text).to_string();
|
||||||
GenericResponseValue::Binary(_) => {
|
|
||||||
return Err(ResponseParserError::UnexpectedPropertyType(
|
|
||||||
"name", "Binary",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let sticker_type = match type_value {
|
|
||||||
GenericResponseValue::Text(s) => s.to_string(),
|
|
||||||
GenericResponseValue::Binary(_) => {
|
|
||||||
return Err(ResponseParserError::UnexpectedPropertyType(
|
|
||||||
"type", "Binary",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
result
|
result
|
||||||
.entry(name)
|
.entry(name)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
commands::{
|
commands::{
|
||||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||||
ResponseAttributes, ResponseParserError,
|
ResponseParserError, expect_property_type,
|
||||||
},
|
},
|
||||||
common::PlaylistName,
|
common::PlaylistName,
|
||||||
};
|
};
|
||||||
@ -37,17 +37,12 @@ impl Command for ListPlaylist {
|
|||||||
parts: ResponseAttributes<'_>,
|
parts: ResponseAttributes<'_>,
|
||||||
) -> Result<Self::Response, ResponseParserError> {
|
) -> Result<Self::Response, ResponseParserError> {
|
||||||
let parts: Vec<_> = parts.into();
|
let parts: Vec<_> = parts.into();
|
||||||
|
|
||||||
|
debug_assert!(parts.iter().all(|(k, _)| *k == "file"));
|
||||||
|
|
||||||
parts
|
parts
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(name, value)| {
|
.map(|(name, value)| Ok(expect_property_type!(Some(value), name, Text).to_string()))
|
||||||
debug_assert_eq!(name, "file");
|
|
||||||
match value {
|
|
||||||
GenericResponseValue::Text(value) => Ok(value.to_string()),
|
|
||||||
GenericResponseValue::Binary(_) => Err(
|
|
||||||
ResponseParserError::UnexpectedPropertyType("file", "Binary"),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user