X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ovsdb%2Fjsonrpc-server.c;h=e398464730a8defeb1b71b74ea39447d555ad076;hb=4787d6d7df196ff7463517423dfbdfd41bdceffe;hp=936dd1db37263325b527b55c88769b129ae09049;hpb=23935e8bcb5be3e82ed2fb16333fdbea36eedfcd;p=openvswitch diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c index 936dd1db..e3984647 100644 --- a/ovsdb/jsonrpc-server.c +++ b/ovsdb/jsonrpc-server.c @@ -346,6 +346,48 @@ ovsdb_jsonrpc_session_close_all(struct ovsdb_jsonrpc_remote *remote) } } +static const char * +get_db_name(const struct ovsdb_jsonrpc_session *s) +{ + return s->remote->server->db->schema->name; +} + +static struct jsonrpc_msg * +ovsdb_jsonrpc_check_db_name(const struct ovsdb_jsonrpc_session *s, + const struct jsonrpc_msg *request) +{ + struct json_array *params; + const char *want_db_name; + const char *have_db_name; + struct ovsdb_error *error; + struct jsonrpc_msg *reply; + + params = json_array(request->params); + if (!params->n || params->elems[0]->type != JSON_STRING) { + error = ovsdb_syntax_error( + request->params, NULL, + "%s request params must begin with ", request->method); + goto error; + } + + want_db_name = params->elems[0]->u.string; + have_db_name = get_db_name(s); + if (strcmp(want_db_name, have_db_name)) { + error = ovsdb_syntax_error( + request->params, "unknown database", + "%s request specifies unknown database %s", + request->method, want_db_name); + goto error; + } + + return NULL; + +error: + reply = jsonrpc_create_reply(ovsdb_error_to_json(error), request->id); + ovsdb_error_destroy(error); + return reply; +} + static struct jsonrpc_msg * execute_transaction(struct ovsdb_jsonrpc_session *s, struct jsonrpc_msg *request) @@ -364,16 +406,30 @@ ovsdb_jsonrpc_session_got_request(struct ovsdb_jsonrpc_session *s, struct jsonrpc_msg *reply; if (!strcmp(request->method, "transact")) { - reply = execute_transaction(s, request); + reply = ovsdb_jsonrpc_check_db_name(s, request); + if (!reply) { + reply = execute_transaction(s, request); + } } else if (!strcmp(request->method, "monitor")) { - reply = jsonrpc_create_reply( - ovsdb_jsonrpc_monitor_create(s, request->params), request->id); + reply = ovsdb_jsonrpc_check_db_name(s, request); + if (!reply) { + reply = jsonrpc_create_reply( + ovsdb_jsonrpc_monitor_create(s, request->params), request->id); + } } else if (!strcmp(request->method, "monitor_cancel")) { reply = ovsdb_jsonrpc_monitor_cancel(s, json_array(request->params), request->id); } else if (!strcmp(request->method, "get_schema")) { + reply = ovsdb_jsonrpc_check_db_name(s, request); + if (!reply) { + reply = jsonrpc_create_reply( + ovsdb_schema_to_json(s->remote->server->db->schema), + request->id); + } + } else if (!strcmp(request->method, "list_dbs")) { reply = jsonrpc_create_reply( - ovsdb_schema_to_json(s->remote->server->db->schema), request->id); + json_array_create_1(json_string_create(get_db_name(s))), + request->id); } else if (!strcmp(request->method, "echo")) { reply = jsonrpc_create_reply(json_clone(request->params), request->id); } else { @@ -589,12 +645,12 @@ ovsdb_jsonrpc_monitor_create(struct ovsdb_jsonrpc_session *s, struct shash_node *node; struct json *json; - if (json_array(params)->n != 2) { + if (json_array(params)->n != 3) { error = ovsdb_syntax_error(params, NULL, "invalid parameters"); goto error; } - monitor_id = params->u.array.elems[0]; - monitor_requests = params->u.array.elems[1]; + monitor_id = params->u.array.elems[1]; + monitor_requests = params->u.array.elems[2]; if (monitor_requests->type != JSON_OBJECT) { error = ovsdb_syntax_error(monitor_requests, NULL, "monitor-requests must be object"); @@ -859,7 +915,8 @@ ovsdb_jsonrpc_monitor_init_aux(struct ovsdb_jsonrpc_monitor_aux *aux, static struct ovsdb_error * ovsdb_jsonrpc_monitor_commit(struct ovsdb_replica *replica, - const struct ovsdb_txn *txn, bool durable UNUSED) + const struct ovsdb_txn *txn, + bool durable OVS_UNUSED) { struct ovsdb_jsonrpc_monitor *m = ovsdb_jsonrpc_monitor_cast(replica); struct ovsdb_jsonrpc_monitor_aux aux;