Code

frontend: Added the SERVER_VERSION command.
authorSebastian Harl <sh@tokkee.org>
Sun, 22 Feb 2015 15:46:30 +0000 (16:46 +0100)
committerSebastian Harl <sh@tokkee.org>
Sun, 22 Feb 2015 15:46:30 +0000 (16:46 +0100)
This command sends back the server version.

src/frontend/connection.c
src/include/frontend/connection.h
src/include/frontend/proto.h

index 64f2cb2000322dcb83557c932282e0125a797ca2..117c6ae18adab025f667fab709c3997b7b0618e6 100644 (file)
@@ -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 : */
 
index c4f2bc716a75de34b31e5160cecb12fcc6e19a5b..0397e508d2eeab6f5d0fc58a9d5dbadc4496ec27 100644 (file)
@@ -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
index 833762d76a3644a9237c19ccb9c29f9a26e36f51..ade3a7cb192eaa7fc1ccf0fa5c01c050723c69e8 100644 (file)
@@ -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) \