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
38e9205d
Commit
38e9205d
authored
Jul 19, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
command: use the tokenizer library
parent
16ff44ad
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
4 deletions
+50
-4
command.c
src/command.c
+50
-4
No files found.
src/command.c
View file @
38e9205d
...
@@ -32,7 +32,7 @@
...
@@ -32,7 +32,7 @@
#include "volume.h"
#include "volume.h"
#include "stats.h"
#include "stats.h"
#include "permission.h"
#include "permission.h"
#include "
buffer2array
.h"
#include "
tokenizer
.h"
#include "stored_playlist.h"
#include "stored_playlist.h"
#include "ack.h"
#include "ack.h"
#include "output_command.h"
#include "output_command.h"
...
@@ -1878,15 +1878,61 @@ command_checked_lookup(struct client *client, unsigned permission,
...
@@ -1878,15 +1878,61 @@ command_checked_lookup(struct client *client, unsigned permission,
}
}
enum
command_return
enum
command_return
command_process
(
struct
client
*
client
,
char
*
commandString
)
command_process
(
struct
client
*
client
,
char
*
line
)
{
{
GError
*
error
=
NULL
;
int
argc
;
int
argc
;
char
*
argv
[
COMMAND_ARGV_MAX
]
=
{
NULL
};
char
*
argv
[
COMMAND_ARGV_MAX
]
=
{
NULL
};
const
struct
command
*
cmd
;
const
struct
command
*
cmd
;
enum
command_return
ret
=
COMMAND_RETURN_ERROR
;
enum
command_return
ret
=
COMMAND_RETURN_ERROR
;
if
(
!
(
argc
=
buffer2array
(
commandString
,
argv
,
COMMAND_ARGV_MAX
)))
/* get the command name (first word on the line) */
return
COMMAND_RETURN_OK
;
argv
[
0
]
=
tokenizer_next_word
(
&
line
,
&
error
);
if
(
argv
[
0
]
==
NULL
)
{
current_command
=
""
;
if
(
*
line
==
0
)
command_error
(
client
,
ACK_ERROR_UNKNOWN
,
"No command given"
);
else
{
command_error
(
client
,
ACK_ERROR_UNKNOWN
,
"%s"
,
error
->
message
);
g_error_free
(
error
);
}
current_command
=
NULL
;
return
COMMAND_RETURN_ERROR
;
}
argc
=
1
;
/* now parse the arguments (quoted or unquoted) */
while
(
argc
<
(
int
)
G_N_ELEMENTS
(
argv
)
&&
(
argv
[
argc
]
=
tokenizer_next_word_or_string
(
&
line
,
&
error
))
!=
NULL
)
++
argc
;
/* some error checks; we have to set current_command because
command_error() expects it to be set */
current_command
=
argv
[
0
];
if
(
argc
>=
(
int
)
G_N_ELEMENTS
(
argv
))
{
command_error
(
client
,
ACK_ERROR_ARG
,
"Too many arguments"
);
current_command
=
NULL
;
return
COMMAND_RETURN_ERROR
;
}
if
(
*
line
!=
0
)
{
command_error
(
client
,
ACK_ERROR_ARG
,
"%s"
,
error
->
message
);
current_command
=
NULL
;
g_error_free
(
error
);
return
COMMAND_RETURN_ERROR
;
}
/* look up and invoke the command handler */
cmd
=
command_checked_lookup
(
client
,
client_get_permission
(
client
),
cmd
=
command_checked_lookup
(
client
,
client_get_permission
(
client
),
argc
,
argv
);
argc
,
argv
);
...
...
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