- command = NULL;
- status = parse_string(&buffer, &command);
- if (status != 0) {
- print_to_socket(fh, "-1 Cannot parse command.\n");
- free_everything_and_return(-1);
- }
- assert(command != NULL);
-
- if (strcasecmp("LISTVAL", command) != 0) {
- print_to_socket(fh, "-1 Unexpected command: `%s'.\n", command);
- free_everything_and_return(-1);
- }
-
- if (*buffer != 0) {
- print_to_socket(fh, "-1 Garbage after end of command: %s\n", buffer);
- free_everything_and_return(-1);
+ if ((status = cmd_parse(buffer, &cmd, NULL, &err)) != CMD_OK)
+ return status;
+ if (cmd.type != CMD_LISTVAL) {
+ cmd_error(CMD_UNKNOWN_COMMAND, &err, "Unexpected command: `%s'.",
+ CMD_TO_STRING(cmd.type));
+ free_everything_and_return(CMD_UNKNOWN_COMMAND);