- if (n > 0 && newline[-1] == '\r') {
- newline--;
- }
- *newline = '\0';
-
- process_command(conn, command);
-
- ofpbuf_pull(&conn->in, n);
- if (!conn->in.size) {
- ofpbuf_clear(&conn->in);
+ params = json_array(request->params);
+ command = shash_find_data(&commands, request->method);
+ if (!command) {
+ error = xasprintf("\"%s\" is not a valid command", request->method);
+ } else if (params->n < command->min_args) {
+ error = xasprintf("\"%s\" command requires at least %d arguments",
+ request->method, command->min_args);
+ } else if (params->n > command->max_args) {
+ error = xasprintf("\"%s\" command takes at most %d arguments",
+ request->method, command->max_args);
+ } else {
+ struct svec argv = SVEC_EMPTY_INITIALIZER;
+ int i;
+
+ svec_add(&argv, request->method);
+ for (i = 0; i < params->n; i++) {
+ if (params->elems[i]->type != JSON_STRING) {
+ error = xasprintf("\"%s\" command has non-string argument",
+ request->method);
+ break;