From 646c196ab19e80fbd91cc60ab9b006f997d8b666 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 16 Jul 2010 18:25:22 +0200 Subject: irecovery: Move getenv handling into precommand callback to fix getenv usage --- src/irecovery.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/irecovery.c b/src/irecovery.c index 415c20e..327527b 100644 --- a/src/irecovery.c +++ b/src/irecovery.c @@ -137,26 +137,21 @@ int received_cb(irecv_client_t client, const irecv_event_t* event) { } int precommand_cb(irecv_client_t client, const irecv_event_t* event) { - if (event->type == IRECV_PRECOMMAND) { - irecv_error_t error = 0; - if (event->data[0] == '/') { - parse_command(client, event->data, event->size); - return -1; - } - } - return 0; -} - -int postcommand_cb(irecv_client_t client, const irecv_event_t* event) { char* value = NULL; char* action = NULL; char* command = NULL; char* argument = NULL; irecv_error_t error = IRECV_E_SUCCESS; - if (event->type == IRECV_POSTCOMMAND) { + if (event->type == IRECV_PRECOMMAND) { + if (event->data[0] == '/') { + parse_command(client, event->data, event->size); + return -1; + } + command = strdup(event->data); action = strtok(command, " "); + if (!strcmp(action, "getenv")) { argument = strtok(NULL, " "); error = irecv_getenv(client, argument, &value); @@ -165,9 +160,23 @@ int postcommand_cb(irecv_client_t client, const irecv_event_t* event) { free(command); return error; } - printf("%s\n", value); - free(value); + if (value) { + printf("%s\n", value); + free(value); + } + return 1; } + } + return 0; +} + +int postcommand_cb(irecv_client_t client, const irecv_event_t* event) { + char* action = NULL; + char* command = NULL; + + if (event->type == IRECV_POSTCOMMAND) { + command = strdup(event->data); + action = strtok(command, " "); if (!strcmp(action, "reboot")) { quit = 1; -- cgit v1.1-32-gdbae