Code

frontend, sysdbd: Let all TCP connections use SSL.
[sysdb.git] / src / tools / sysdb / command.c
index 78deb717520be48a95d37808b8b3830e32ec73db..440ba41e3b13832574ff0ca42472315023cd7f07 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
+static void
+ok_printer(sdb_strbuf_t *buf)
+{
+       const char *msg = sdb_strbuf_string(buf);
+       if (msg && *msg)
+               printf("%s\n", msg);
+       else
+               printf("OK\n");
+} /* ok_printer */
+
 static void
 log_printer(sdb_strbuf_t *buf)
 {
-       uint32_t prio = sdb_proto_unmarshal_int(SDB_STRBUF_STR(buf));
+       uint32_t prio = 0;
 
-       if (prio == UINT32_MAX) {
+       if (sdb_proto_unmarshal_int32(SDB_STRBUF_STR(buf), &prio) < 0) {
                sdb_log(SDB_LOG_WARNING, "Received a LOG message with invalid "
                                "or missing priority");
                prio = (uint32_t)SDB_LOG_ERR;
@@ -86,6 +96,7 @@ static struct {
        int status;
        void (*printer)(sdb_strbuf_t *);
 } response_printers[] = {
+       { SDB_CONNECTION_OK,   ok_printer },
        { SDB_CONNECTION_LOG,  log_printer },
        { SDB_CONNECTION_DATA, data_printer },
 };
@@ -195,7 +206,8 @@ sdb_command_exec(sdb_input_t *input)
                        break;
                }
 
-               if ((status == SDB_CONNECTION_DATA)
+               if ((status == SDB_CONNECTION_OK)
+                               || (status == SDB_CONNECTION_DATA)
                                || (status == SDB_CONNECTION_ERROR))
                        break;
        }