Code

sysdb: Do an attempt to reconnect on all user input.
[sysdb.git] / src / tools / sysdb / input.h
index 4632b4f40c3b5150560363d43538caf0f7fd26c8..0aeabf8b7b653197f98ffa0678d13b769e0c21e2 100644 (file)
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "client/sock.h"
 #include "utils/strbuf.h"
 
 #ifndef SYSDB_INPUT_H
 #define SYSDB_INPUT_H 1
 
 typedef struct {
-       sdb_strbuf_t *buf;
+       sdb_client_t *client;
+       const char *user;
 
+       sdb_strbuf_t *input;
        size_t tokenizer_pos;
+       size_t query_len;
+
+       bool interactive;
+       bool eof;
 } sdb_input_t;
 
-#define SDB_INPUT_INIT { NULL, 0 }
+#define SDB_INPUT_INIT { NULL, NULL, NULL, 0, 0, 1, 0 }
+
+/*
+ * sysdb_input:
+ * Input object to be used by the 'sysdb' command line tool.
+ */
+extern sdb_input_t *sysdb_input;
+
+/*
+ * sdb_input_init:
+ * Initialize the input handler.
+ */
+int
+sdb_input_init(sdb_input_t *input);
+
+/*
+ * sdb_input_mainloop:
+ * Wait for and handle all user and server input until end-of-file is read
+ * from the user (on the standard input channel).
+ *
+ * Returns:
+ *  - 0 on success
+ *  - a negative value else
+ */
+int
+sdb_input_mainloop(void);
 
 /*
  * sdb_input_readline:
@@ -50,15 +82,23 @@ typedef struct {
  *  - A negative value in case of an error.
  */
 ssize_t
-sdb_input_readline(sdb_input_t *input, char *buf,
-               int *n_chars, size_t max_chars);
+sdb_input_readline(char *buf, size_t *n_chars, size_t max_chars);
 
 /*
- * scanner
+ * sdb_input_exec_query:
+ * Execute the query currently stored in the input buffer. Waits for the
+ * server's reply and prints errors or returned data to standard output.
  */
+int
+sdb_input_exec_query(void);
 
-void
-sdb_input_set(sdb_input_t *new_input);
+/*
+ * sdb_input_reconnect:
+ * Let the client reconnect to the server using the settings stored in
+ * sysdb_input.
+ */
+int
+sdb_input_reconnect(void);
 
 #endif /* SYSDB_INPUT_H */