From: Sebastian Harl Date: Sun, 22 Feb 2015 15:46:30 +0000 (+0100) Subject: frontend: Added the SERVER_VERSION command. X-Git-Tag: sysdb-0.8.0~170 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f813acbff144fa649d152838957c321894c1cbba;p=sysdb.git frontend: Added the SERVER_VERSION command. This command sends back the server version. --- diff --git a/src/frontend/connection.c b/src/frontend/connection.c index 64f2cb2..117c6ae 100644 --- a/src/frontend/connection.c +++ b/src/frontend/connection.c @@ -284,6 +284,7 @@ command_handle(sdb_conn_t *conn) status = sdb_connection_ping(conn); else if (conn->cmd == SDB_CONNECTION_STARTUP) status = sdb_fe_session_start(conn); + else if (conn->cmd == SDB_CONNECTION_QUERY) status = sdb_fe_query(conn); else if (conn->cmd == SDB_CONNECTION_FETCH) @@ -294,6 +295,10 @@ command_handle(sdb_conn_t *conn) status = sdb_fe_lookup(conn); else if (conn->cmd == SDB_CONNECTION_STORE) status = sdb_fe_store(conn); + + else if (conn->cmd == SDB_CONNECTION_SERVER_VERSION) + status = sdb_connection_server_version(conn); + else { sdb_log(SDB_LOG_WARNING, "frontend: Ignoring invalid command %#x", conn->cmd); @@ -532,5 +537,20 @@ sdb_connection_ping(sdb_conn_t *conn) return 0; } /* sdb_connection_ping */ +int +sdb_connection_server_version(sdb_conn_t *conn) +{ + char msg[sizeof(uint32_t) + strlen(SDB_VERSION_EXTRA) + 1]; + + if ((! conn) || (conn->cmd != SDB_CONNECTION_SERVER_VERSION)) + return -1; + + sdb_proto_marshal_int32(msg, sizeof(msg), (uint32_t)SDB_VERSION); + strncpy(msg + sizeof(uint32_t), SDB_VERSION_EXTRA, + sizeof(msg) - sizeof(uint32_t)); + sdb_connection_send(conn, SDB_CONNECTION_OK, (uint32_t)sizeof(msg), msg); + return 0; +} /* sdb_connection_server_version */ + /* vim: set tw=78 sw=4 ts=4 noexpandtab : */ diff --git a/src/include/frontend/connection.h b/src/include/frontend/connection.h index c4f2bc7..0397e50 100644 --- a/src/include/frontend/connection.h +++ b/src/include/frontend/connection.h @@ -135,6 +135,17 @@ sdb_connection_send(sdb_conn_t *conn, uint32_t code, int sdb_connection_ping(sdb_conn_t *conn); +/* + * sdb_connection_server_version: + * Send back the backend server version to the connected client. + * + * Returns: + * - 0 on success + * - a negative value else + */ +int +sdb_connection_server_version(sdb_conn_t *conn); + /* * sdb_fe_parse: * Parse the query text specified in 'query' of length 'len' and return a list diff --git a/src/include/frontend/proto.h b/src/include/frontend/proto.h index 833762d..ade3a7c 100644 --- a/src/include/frontend/proto.h +++ b/src/include/frontend/proto.h @@ -298,6 +298,25 @@ typedef enum { * A parsed expression. Only used internally. */ SDB_CONNECTION_EXPR, + + /* + * Server status queries. + */ + + /* + * SDB_CONNECTION_SERVER_VERSION: + * Retrieve the server version. The server replies with SDB_CONNECTION_OK + * on success and the server version as an unsigned 32-bit integer, + * optionally followed by a string describing extra version components. + * The integer server version is encoded as 100000 * major + 100 * minor + + * patch. + * + * 0 32 64 + * +---------------+---------------+ + * | SERVER_VERSION| 0 | + * +---------------+---------------+ + */ + SDB_CONNECTION_SERVER_VERSION = 1000, } sdb_conn_state_t; #define SDB_CONN_MSGTYPE_TO_STRING(t) \