mpd: Update auth filter and convert audio_output and connection
This commit is contained in:
parent
1dc35c2bf7
commit
a2ae51ff65
@ -37,6 +37,7 @@ class MpdDispatcher(object):
|
|||||||
response = []
|
response = []
|
||||||
filter_chain = [
|
filter_chain = [
|
||||||
self._catch_mpd_ack_errors_filter,
|
self._catch_mpd_ack_errors_filter,
|
||||||
|
# TODO: tokenize filter
|
||||||
self._authenticate_filter,
|
self._authenticate_filter,
|
||||||
self._command_list_filter,
|
self._command_list_filter,
|
||||||
self._idle_filter,
|
self._idle_filter,
|
||||||
@ -88,9 +89,17 @@ class MpdDispatcher(object):
|
|||||||
return self._call_next_filter(request, response, filter_chain)
|
return self._call_next_filter(request, response, filter_chain)
|
||||||
else:
|
else:
|
||||||
command_name = request.split(' ')[0]
|
command_name = request.split(' ')[0]
|
||||||
|
command = protocol.commands.handlers.get(command_name)
|
||||||
|
if command:
|
||||||
|
if command.auth_required:
|
||||||
|
raise exceptions.MpdPermissionError(command=command_name)
|
||||||
|
else:
|
||||||
|
return self._call_next_filter(
|
||||||
|
request, response, filter_chain)
|
||||||
|
|
||||||
|
# TODO: remove
|
||||||
command_names_not_requiring_auth = [
|
command_names_not_requiring_auth = [
|
||||||
command.name for command in protocol.mpd_commands
|
c.name for c in protocol.mpd_commands if not c.auth_required]
|
||||||
if not command.auth_required]
|
|
||||||
if command_name in command_names_not_requiring_auth:
|
if command_name in command_names_not_requiring_auth:
|
||||||
return self._call_next_filter(request, response, filter_chain)
|
return self._call_next_filter(request, response, filter_chain)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from mopidy.mpd.exceptions import MpdNoExistError
|
from mopidy.mpd import exceptions, protocol
|
||||||
from mopidy.mpd.protocol import handle_request
|
|
||||||
|
|
||||||
|
|
||||||
@handle_request(r'disableoutput\ "(?P<outputid>\d+)"$')
|
@protocol.commands.add('disableoutput', outputid=protocol.UINT)
|
||||||
def disableoutput(context, outputid):
|
def disableoutput(context, outputid):
|
||||||
"""
|
"""
|
||||||
*musicpd.org, audio output section:*
|
*musicpd.org, audio output section:*
|
||||||
@ -13,13 +12,13 @@ def disableoutput(context, outputid):
|
|||||||
|
|
||||||
Turns an output off.
|
Turns an output off.
|
||||||
"""
|
"""
|
||||||
if int(outputid) == 0:
|
if outputid == 0:
|
||||||
context.core.playback.set_mute(False)
|
context.core.playback.set_mute(False)
|
||||||
else:
|
else:
|
||||||
raise MpdNoExistError('No such audio output')
|
raise exceptions.MpdNoExistError('No such audio output')
|
||||||
|
|
||||||
|
|
||||||
@handle_request(r'enableoutput\ "(?P<outputid>\d+)"$')
|
@protocol.commands.add('enableoutput', outputid=protocol.UINT)
|
||||||
def enableoutput(context, outputid):
|
def enableoutput(context, outputid):
|
||||||
"""
|
"""
|
||||||
*musicpd.org, audio output section:*
|
*musicpd.org, audio output section:*
|
||||||
@ -28,13 +27,13 @@ def enableoutput(context, outputid):
|
|||||||
|
|
||||||
Turns an output on.
|
Turns an output on.
|
||||||
"""
|
"""
|
||||||
if int(outputid) == 0:
|
if outputid == 0:
|
||||||
context.core.playback.set_mute(True)
|
context.core.playback.set_mute(True)
|
||||||
else:
|
else:
|
||||||
raise MpdNoExistError('No such audio output')
|
raise exceptions.MpdNoExistError('No such audio output')
|
||||||
|
|
||||||
|
|
||||||
@handle_request(r'outputs$')
|
@protocol.commands.add('outputs')
|
||||||
def outputs(context):
|
def outputs(context):
|
||||||
"""
|
"""
|
||||||
*musicpd.org, audio output section:*
|
*musicpd.org, audio output section:*
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from mopidy.mpd.protocol import handle_request
|
from mopidy.mpd import exceptions, protocol
|
||||||
from mopidy.mpd.exceptions import (
|
|
||||||
MpdPasswordError, MpdPermissionError)
|
|
||||||
|
|
||||||
|
|
||||||
@handle_request(r'close$', auth_required=False)
|
@protocol.commands.add('close', auth_required=False)
|
||||||
def close(context):
|
def close(context):
|
||||||
"""
|
"""
|
||||||
*musicpd.org, connection section:*
|
*musicpd.org, connection section:*
|
||||||
@ -17,7 +15,7 @@ def close(context):
|
|||||||
context.session.close()
|
context.session.close()
|
||||||
|
|
||||||
|
|
||||||
@handle_request(r'kill$')
|
@protocol.commands.add('kill')
|
||||||
def kill(context):
|
def kill(context):
|
||||||
"""
|
"""
|
||||||
*musicpd.org, connection section:*
|
*musicpd.org, connection section:*
|
||||||
@ -26,10 +24,10 @@ def kill(context):
|
|||||||
|
|
||||||
Kills MPD.
|
Kills MPD.
|
||||||
"""
|
"""
|
||||||
raise MpdPermissionError(command='kill')
|
raise exceptions.MpdPermissionError(command='kill')
|
||||||
|
|
||||||
|
|
||||||
@handle_request(r'password\ "(?P<password>[^"]+)"$', auth_required=False)
|
@protocol.commands.add('password', auth_required=False)
|
||||||
def password(context, password):
|
def password(context, password):
|
||||||
"""
|
"""
|
||||||
*musicpd.org, connection section:*
|
*musicpd.org, connection section:*
|
||||||
@ -42,10 +40,10 @@ def password(context, password):
|
|||||||
if password == context.config['mpd']['password']:
|
if password == context.config['mpd']['password']:
|
||||||
context.dispatcher.authenticated = True
|
context.dispatcher.authenticated = True
|
||||||
else:
|
else:
|
||||||
raise MpdPasswordError('incorrect password')
|
raise exceptions.MpdPasswordError('incorrect password')
|
||||||
|
|
||||||
|
|
||||||
@handle_request(r'ping$', auth_required=False)
|
@protocol.commands.add('ping', auth_required=False)
|
||||||
def ping(context):
|
def ping(context):
|
||||||
"""
|
"""
|
||||||
*musicpd.org, connection section:*
|
*musicpd.org, connection section:*
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user