Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
380f73c1
Commit
380f73c1
authored
Apr 03, 2019
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client/Process: convert functions to Client methods
parent
9f79d034
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
41 deletions
+41
-41
Client.hxx
src/client/Client.hxx
+7
-1
ClientInternal.hxx
src/client/ClientInternal.hxx
+0
-4
ClientProcess.cxx
src/client/ClientProcess.cxx
+33
-35
ClientRead.cxx
src/client/ClientRead.cxx
+1
-1
No files found.
src/client/Client.hxx
View file @
380f73c1
/*
/*
* Copyright 2003-201
8
The Music Player Daemon Project
* Copyright 2003-201
9
The Music Player Daemon Project
* http://www.musicpd.org
* http://www.musicpd.org
*
*
* This program is free software; you can redistribute it and/or modify
* This program is free software; you can redistribute it and/or modify
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
#define MPD_CLIENT_H
#define MPD_CLIENT_H
#include "ClientMessage.hxx"
#include "ClientMessage.hxx"
#include "command/CommandResult.hxx"
#include "command/CommandListBuilder.hxx"
#include "command/CommandListBuilder.hxx"
#include "tag/Mask.hxx"
#include "tag/Mask.hxx"
#include "event/FullyBufferedSocket.hxx"
#include "event/FullyBufferedSocket.hxx"
...
@@ -226,6 +227,11 @@ public:
...
@@ -226,6 +227,11 @@ public:
const
Storage
*
GetStorage
()
const
noexcept
;
const
Storage
*
GetStorage
()
const
noexcept
;
private
:
private
:
CommandResult
ProcessCommandList
(
bool
list_ok
,
std
::
list
<
std
::
string
>
&&
list
)
noexcept
;
CommandResult
ProcessLine
(
char
*
line
)
noexcept
;
/* virtual methods from class BufferedSocket */
/* virtual methods from class BufferedSocket */
InputResult
OnSocketInput
(
void
*
data
,
size_t
length
)
noexcept
override
;
InputResult
OnSocketInput
(
void
*
data
,
size_t
length
)
noexcept
override
;
void
OnSocketError
(
std
::
exception_ptr
ep
)
noexcept
override
;
void
OnSocketError
(
std
::
exception_ptr
ep
)
noexcept
override
;
...
...
src/client/ClientInternal.hxx
View file @
380f73c1
...
@@ -21,7 +21,6 @@
...
@@ -21,7 +21,6 @@
#define MPD_CLIENT_INTERNAL_HXX
#define MPD_CLIENT_INTERNAL_HXX
#include "Client.hxx"
#include "Client.hxx"
#include "command/CommandResult.hxx"
#include <chrono>
#include <chrono>
...
@@ -34,7 +33,4 @@ extern std::chrono::steady_clock::duration client_timeout;
...
@@ -34,7 +33,4 @@ extern std::chrono::steady_clock::duration client_timeout;
extern
size_t
client_max_command_list_size
;
extern
size_t
client_max_command_list_size
;
extern
size_t
client_max_output_buffer_size
;
extern
size_t
client_max_output_buffer_size
;
CommandResult
client_process_line
(
Client
&
client
,
char
*
line
)
noexcept
;
#endif
#endif
src/client/ClientProcess.cxx
View file @
380f73c1
/*
/*
* Copyright 2003-201
8
The Music Player Daemon Project
* Copyright 2003-201
9
The Music Player Daemon Project
* http://www.musicpd.org
* http://www.musicpd.org
*
*
* This program is free software; you can redistribute it and/or modify
* This program is free software; you can redistribute it and/or modify
...
@@ -28,38 +28,38 @@
...
@@ -28,38 +28,38 @@
#define CLIENT_LIST_OK_MODE_BEGIN "command_list_ok_begin"
#define CLIENT_LIST_OK_MODE_BEGIN "command_list_ok_begin"
#define CLIENT_LIST_MODE_END "command_list_end"
#define CLIENT_LIST_MODE_END "command_list_end"
static
CommandResult
inline
CommandResult
client_process_command_list
(
Client
&
client
,
bool
list_ok
,
Client
::
ProcessCommandList
(
bool
list_ok
,
std
::
list
<
std
::
string
>
&&
list
)
noexcept
std
::
list
<
std
::
string
>
&&
list
)
noexcept
{
{
CommandResult
ret
=
CommandResult
::
OK
;
CommandResult
ret
=
CommandResult
::
OK
;
unsigned
n
um
=
0
;
unsigned
n
=
0
;
for
(
auto
&&
i
:
list
)
{
for
(
auto
&&
i
:
list
)
{
char
*
cmd
=
&*
i
.
begin
();
char
*
cmd
=
&*
i
.
begin
();
FormatDebug
(
client_domain
,
"process command
\"
%s
\"
"
,
cmd
);
FormatDebug
(
client_domain
,
"process command
\"
%s
\"
"
,
cmd
);
ret
=
command_process
(
client
,
num
++
,
cmd
);
ret
=
command_process
(
*
this
,
n
++
,
cmd
);
FormatDebug
(
client_domain
,
"command returned %i"
,
int
(
ret
));
FormatDebug
(
client_domain
,
"command returned %i"
,
int
(
ret
));
if
(
ret
!=
CommandResult
::
OK
||
client
.
IsExpired
())
if
(
ret
!=
CommandResult
::
OK
||
IsExpired
())
break
;
break
;
else
if
(
list_ok
)
else
if
(
list_ok
)
client
.
Write
(
"list_OK
\n
"
);
Write
(
"list_OK
\n
"
);
}
}
return
ret
;
return
ret
;
}
}
CommandResult
CommandResult
client_process_line
(
Client
&
client
,
char
*
line
)
noexcept
Client
::
ProcessLine
(
char
*
line
)
noexcept
{
{
CommandResult
ret
;
CommandResult
ret
;
if
(
StringIsEqual
(
line
,
"noidle"
))
{
if
(
StringIsEqual
(
line
,
"noidle"
))
{
if
(
client
.
idle_waiting
)
{
if
(
idle_waiting
)
{
/* send empty idle response and leave idle mode */
/* send empty idle response and leave idle mode */
client
.
idle_waiting
=
false
;
idle_waiting
=
false
;
command_success
(
client
);
command_success
(
*
this
);
}
}
/* do nothing if the client wasn't idling: the client
/* do nothing if the client wasn't idling: the client
...
@@ -67,44 +67,43 @@ client_process_line(Client &client, char *line) noexcept
...
@@ -67,44 +67,43 @@ client_process_line(Client &client, char *line) noexcept
client_idle_notify(), which he can now evaluate */
client_idle_notify(), which he can now evaluate */
return
CommandResult
::
OK
;
return
CommandResult
::
OK
;
}
else
if
(
client
.
idle_waiting
)
{
}
else
if
(
idle_waiting
)
{
/* during idle mode, clients must not send anything
/* during idle mode, clients must not send anything
except "noidle" */
except "noidle" */
FormatWarning
(
client_domain
,
FormatWarning
(
client_domain
,
"[%u] command
\"
%s
\"
during idle"
,
"[%u] command
\"
%s
\"
during idle"
,
client
.
num
,
line
);
num
,
line
);
return
CommandResult
::
CLOSE
;
return
CommandResult
::
CLOSE
;
}
}
if
(
c
lient
.
c
md_list
.
IsActive
())
{
if
(
cmd_list
.
IsActive
())
{
if
(
StringIsEqual
(
line
,
CLIENT_LIST_MODE_END
))
{
if
(
StringIsEqual
(
line
,
CLIENT_LIST_MODE_END
))
{
FormatDebug
(
client_domain
,
FormatDebug
(
client_domain
,
"[%u] process command list"
,
"[%u] process command list"
,
client
.
num
);
num
);
auto
&&
cmd_list
=
client
.
cmd_list
.
Commit
();
auto
&&
list
=
cmd_list
.
Commit
();
ret
=
client_process_command_list
(
client
,
ret
=
ProcessCommandList
(
cmd_list
.
IsOKMode
(),
client
.
cmd_list
.
IsOKMode
(),
std
::
move
(
list
));
std
::
move
(
cmd_list
));
FormatDebug
(
client_domain
,
FormatDebug
(
client_domain
,
"[%u] process command "
"[%u] process command "
"list returned %i"
,
client
.
num
,
int
(
ret
));
"list returned %i"
,
num
,
int
(
ret
));
if
(
ret
==
CommandResult
::
CLOSE
||
if
(
ret
==
CommandResult
::
CLOSE
||
client
.
IsExpired
())
IsExpired
())
return
CommandResult
::
CLOSE
;
return
CommandResult
::
CLOSE
;
if
(
ret
==
CommandResult
::
OK
)
if
(
ret
==
CommandResult
::
OK
)
command_success
(
client
);
command_success
(
*
this
);
c
lient
.
c
md_list
.
Reset
();
cmd_list
.
Reset
();
}
else
{
}
else
{
if
(
!
c
lient
.
c
md_list
.
Add
(
line
))
{
if
(
!
cmd_list
.
Add
(
line
))
{
FormatWarning
(
client_domain
,
FormatWarning
(
client_domain
,
"[%u] command list size "
"[%u] command list size "
"is larger than the max (%lu)"
,
"is larger than the max (%lu)"
,
client
.
num
,
num
,
(
unsigned
long
)
client_max_command_list_size
);
(
unsigned
long
)
client_max_command_list_size
);
return
CommandResult
::
CLOSE
;
return
CommandResult
::
CLOSE
;
}
}
...
@@ -113,10 +112,10 @@ client_process_line(Client &client, char *line) noexcept
...
@@ -113,10 +112,10 @@ client_process_line(Client &client, char *line) noexcept
}
}
}
else
{
}
else
{
if
(
StringIsEqual
(
line
,
CLIENT_LIST_MODE_BEGIN
))
{
if
(
StringIsEqual
(
line
,
CLIENT_LIST_MODE_BEGIN
))
{
c
lient
.
c
md_list
.
Begin
(
false
);
cmd_list
.
Begin
(
false
);
ret
=
CommandResult
::
OK
;
ret
=
CommandResult
::
OK
;
}
else
if
(
StringIsEqual
(
line
,
CLIENT_LIST_OK_MODE_BEGIN
))
{
}
else
if
(
StringIsEqual
(
line
,
CLIENT_LIST_OK_MODE_BEGIN
))
{
c
lient
.
c
md_list
.
Begin
(
true
);
cmd_list
.
Begin
(
true
);
ret
=
CommandResult
::
OK
;
ret
=
CommandResult
::
OK
;
}
else
if
(
IsUpperAlphaASCII
(
*
line
))
{
}
else
if
(
IsUpperAlphaASCII
(
*
line
))
{
/* no valid MPD command begins with an upper
/* no valid MPD command begins with an upper
...
@@ -124,23 +123,22 @@ client_process_line(Client &client, char *line) noexcept
...
@@ -124,23 +123,22 @@ client_process_line(Client &client, char *line) noexcept
HTTP request */
HTTP request */
FormatWarning
(
client_domain
,
FormatWarning
(
client_domain
,
"[%u] malformed command
\"
%s
\"
"
,
"[%u] malformed command
\"
%s
\"
"
,
client
.
num
,
line
);
num
,
line
);
ret
=
CommandResult
::
CLOSE
;
ret
=
CommandResult
::
CLOSE
;
}
else
{
}
else
{
FormatDebug
(
client_domain
,
FormatDebug
(
client_domain
,
"[%u] process command
\"
%s
\"
"
,
"[%u] process command
\"
%s
\"
"
,
client
.
num
,
line
);
num
,
line
);
ret
=
command_process
(
client
,
0
,
line
);
ret
=
command_process
(
*
this
,
0
,
line
);
FormatDebug
(
client_domain
,
FormatDebug
(
client_domain
,
"[%u] command returned %i"
,
"[%u] command returned %i"
,
client
.
num
,
int
(
ret
));
num
,
int
(
ret
));
if
(
ret
==
CommandResult
::
CLOSE
||
if
(
ret
==
CommandResult
::
CLOSE
||
IsExpired
())
client
.
IsExpired
())
return
CommandResult
::
CLOSE
;
return
CommandResult
::
CLOSE
;
if
(
ret
==
CommandResult
::
OK
)
if
(
ret
==
CommandResult
::
OK
)
command_success
(
client
);
command_success
(
*
this
);
}
}
}
}
...
...
src/client/ClientRead.cxx
View file @
380f73c1
...
@@ -43,7 +43,7 @@ Client::OnSocketInput(void *data, size_t length) noexcept
...
@@ -43,7 +43,7 @@ Client::OnSocketInput(void *data, size_t length) noexcept
/* terminate the string at the end of the line */
/* terminate the string at the end of the line */
*
end
=
0
;
*
end
=
0
;
CommandResult
result
=
client_process_line
(
*
this
,
p
);
CommandResult
result
=
ProcessLine
(
p
);
switch
(
result
)
{
switch
(
result
)
{
case
CommandResult
:
:
OK
:
case
CommandResult
:
:
OK
:
case
CommandResult
:
:
IDLE
:
case
CommandResult
:
:
IDLE
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment