summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 233d70f)
raw | patch | inline | side by side (parent: 233d70f)
author | Sebastian Harl <sh@tokkee.org> | |
Mon, 26 Sep 2016 08:07:26 +0000 (10:07 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Mon, 26 Sep 2016 08:07:26 +0000 (10:07 +0200) |
This is a work-around to fix integration tests (which expect the entire
output on one line). A better solution will rely on configurable output
formats.
Also, disable interactive mode when using -c <cmd> options. It's not
interactive after all :-)
output on one line). A better solution will rely on configurable output
formats.
Also, disable interactive mode when using -c <cmd> options. It's not
interactive after all :-)
index 4de2b44e4fc79245027a22c5c2932bd82b46f742..dd8b2980c7ca6efb784bd7c6e8a889618d207596 100644 (file)
#include <string.h>
static void
-ok_printer(sdb_strbuf_t *buf)
+ok_printer(sdb_input_t __attribute__((unused)) *input, sdb_strbuf_t *buf)
{
const char *msg = sdb_strbuf_string(buf);
if (msg && *msg)
} /* ok_printer */
static void
-log_printer(sdb_strbuf_t *buf)
+log_printer(sdb_input_t __attribute__((unused)) *input, sdb_strbuf_t *buf)
{
uint32_t prio = 0;
} /* log_printer */
static void
-data_printer(sdb_strbuf_t *buf)
+data_printer(sdb_input_t __attribute__((unused)) *input, sdb_strbuf_t *buf)
{
size_t len = sdb_strbuf_len(buf);
/* At the moment, we don't care about the result type. We simply print the
* result without further parsing it. */
sdb_strbuf_skip(buf, 0, sizeof(uint32_t));
- if (sdb_json_print(buf))
+ if (sdb_json_print(input, buf))
sdb_log(SDB_LOG_ERR, "Failed to print result");
printf("\n");
} /* data_printer */
static struct {
int status;
- void (*printer)(sdb_strbuf_t *);
+ void (*printer)(sdb_input_t *, sdb_strbuf_t *);
} response_printers[] = {
{ SDB_CONNECTION_OK, ok_printer },
{ SDB_CONNECTION_LOG, log_printer },
*/
int
-sdb_command_print_reply(sdb_client_t *client)
+sdb_command_print_reply(sdb_input_t *input)
{
sdb_strbuf_t *recv_buf;
const char *result;
if (! recv_buf)
return -1;
- if (sdb_client_recv(client, &rcode, recv_buf) < 0)
+ if (sdb_client_recv(input->client, &rcode, recv_buf) < 0)
rcode = UINT32_MAX;
- if (sdb_client_eof(client)) {
+ if (sdb_client_eof(input->client)) {
sdb_strbuf_destroy(recv_buf);
return -1;
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(response_printers); ++i) {
if (status == response_printers[i].status) {
- response_printers[i].printer(recv_buf);
+ response_printers[i].printer(input, recv_buf);
sdb_strbuf_destroy(recv_buf);
return status;
}
/* The server may send back log messages but will eventually reply to the
* query, which is either DATA or ERROR. */
while (42) {
- int status = sdb_command_print_reply(input->client);
+ int status = sdb_command_print_reply(input);
if (status < 0) {
sdb_log(SDB_LOG_ERR, "Failed to read reply from server");
break;
index 04ad5e156a7cd87992a9c8691adc2414eb4fe013..b2e5fa7ccc7363ea6efd51a091c06fb1c3caaac7 100644 (file)
* - a positive value if the server returned an error
*/
int
-sdb_command_print_reply(sdb_client_t *client);
+sdb_command_print_reply(sdb_input_t *input);
/*
* sdb_command_exec:
index f0f86ea2a9bff1e264013bf39c3ab31758919c63..2a2d1707101404169febb67d0ac643aaa98ec649 100644 (file)
--- a/src/tools/sysdb/input.c
+++ b/src/tools/sysdb/input.c
/* some response / error message from the server pending */
/* XXX: clear current line */
printf("\n");
- sdb_command_print_reply(sysdb_input->client);
+ sdb_command_print_reply(sysdb_input);
if (sdb_client_eof(sysdb_input->client)) {
rl_callback_handler_remove();
diff --git a/src/tools/sysdb/json.c b/src/tools/sysdb/json.c
index 703b22e8ef1ed5087ab6af48000d14054657a32f..1792cdac9b3f53eacb9c0b8ef238426a5e465b3b 100644 (file)
--- a/src/tools/sysdb/json.c
+++ b/src/tools/sysdb/json.c
*/
int
-sdb_json_print(sdb_strbuf_t *buf)
+sdb_json_print(sdb_input_t *input, sdb_strbuf_t *buf)
{
#ifdef HAVE_LIBYAJL
const unsigned char *json;
int ret = 0;
+ if (!input->interactive) {
+ /* no formatting */
+ printf("%s\n", sdb_strbuf_string(buf));
+ return 0;
+ }
+
gen = yajl_gen_alloc(/* alloc_funcs */ NULL);
if (! gen)
return -1;
diff --git a/src/tools/sysdb/json.h b/src/tools/sysdb/json.h
index 9fc1a70d3fb49fc42272e66ef4d2b7379ed0dd3b..08def61f726e361b94bf028b8098722740196066 100644 (file)
--- a/src/tools/sysdb/json.h
+++ b/src/tools/sysdb/json.h
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "tools/sysdb/input.h"
+
#include "utils/strbuf.h"
#ifndef SYSDB_JSON_H
* printed to the standard output channel.
*/
int
-sdb_json_print(sdb_strbuf_t *buf);
+sdb_json_print(sdb_input_t *input, sdb_strbuf_t *buf);
#endif /* SYSDB_JSON_H */
diff --git a/src/tools/sysdb/main.c b/src/tools/sysdb/main.c
index f502027f04353e115dd427cdd429816569a16116..b45ef878873b1b0dc943dbe38efa0555d6d042d2 100644 (file)
--- a/src/tools/sysdb/main.c
+++ b/src/tools/sysdb/main.c
} /* exit_version */
static int
-execute_commands(sdb_client_t *client, sdb_llist_t *commands)
+execute_commands(sdb_input_t *input, sdb_llist_t *commands)
{
sdb_llist_iter_t *iter;
int status = 0;
while (sdb_llist_iter_has_next(iter)) {
sdb_object_t *obj = sdb_llist_iter_get_next(iter);
- if (sdb_client_send(client, SDB_CONNECTION_QUERY,
+ if (sdb_client_send(input->client, SDB_CONNECTION_QUERY,
(uint32_t)strlen(obj->name), obj->name) <= 0) {
sdb_log(SDB_LOG_ERR, "Failed to send command '%s' to server",
obj->name);
* but eventually see the reply to the query, which is either DATA or
* ERROR. */
while (42) {
- status = sdb_command_print_reply(client);
+ status = sdb_command_print_reply(input);
if (status < 0) {
sdb_log(SDB_LOG_ERR, "Failed to read reply from server");
break;
sdb_input_reset(&input);
exit(1);
}
+ input.input = sdb_strbuf_create(2048);
+ sdb_input_init(&input);
+
canonicalize_ssl_options();
if (sdb_client_set_ssl_options(input.client, &ssl_options)) {
sdb_log(SDB_LOG_ERR, "Failed to apply SSL options");
}
if (commands) {
- int status = execute_commands(input.client, commands);
+ int status;
+ input.interactive = 0;
+ status = execute_commands(&input, commands);
sdb_llist_destroy(commands);
sdb_input_reset(&input);
if ((status != SDB_CONNECTION_OK) && (status != SDB_CONNECTION_DATA))
}
}
- input.input = sdb_strbuf_create(2048);
- sdb_input_init(&input);
sdb_input_mainloop();
sdb_client_shutdown(input.client, SHUT_WR);
while (! sdb_client_eof(input.client)) {
/* wait for remaining data to arrive */
- sdb_command_print_reply(input.client);
+ sdb_command_print_reply(&input);
}
if (hist_file[0] != '\0') {