@ -316,7 +316,7 @@ cleanup:
// be chained together)
// be chained together)
// 4) execute_command handles all state internally while config_command has
// 4) execute_command handles all state internally while config_command has
// some state handled outside (notably the block mode, in read_config)
// some state handled outside (notably the block mode, in read_config)
struct cmd_results * config_command ( char * exec ) {
struct cmd_results * config_command ( char * exec , char * * new_block ) {
struct cmd_results * results = NULL ;
struct cmd_results * results = NULL ;
int argc ;
int argc ;
char * * argv = split_args ( exec , & argc ) ;
char * * argv = split_args ( exec , & argc ) ;
@ -329,9 +329,8 @@ struct cmd_results *config_command(char *exec) {
// Check for the start of a block
// Check for the start of a block
if ( argc > 1 & & strcmp ( argv [ argc - 1 ] , " { " ) = = 0 ) {
if ( argc > 1 & & strcmp ( argv [ argc - 1 ] , " { " ) = = 0 ) {
char * block = join_args ( argv , argc - 1 ) ;
* new_block = join_args ( argv , argc - 1 ) ;
results = cmd_results_new ( CMD_BLOCK , block , NULL ) ;
results = cmd_results_new ( CMD_BLOCK , NULL , NULL ) ;
free ( block ) ;
goto cleanup ;
goto cleanup ;
}
}
@ -509,11 +508,7 @@ struct cmd_results *cmd_results_new(enum cmd_status status,
return NULL ;
return NULL ;
}
}
results - > status = status ;
results - > status = status ;
if ( input ) {
// NOTE: `input` argument is unused, remove
results - > input = strdup ( input ) ; // input is the command name
} else {
results - > input = NULL ;
}
if ( format ) {
if ( format ) {
char * error = malloc ( 256 ) ;
char * error = malloc ( 256 ) ;
va_list args ;
va_list args ;
@ -530,9 +525,6 @@ struct cmd_results *cmd_results_new(enum cmd_status status,
}
}
void free_cmd_results ( struct cmd_results * results ) {
void free_cmd_results ( struct cmd_results * results ) {
if ( results - > input ) {
free ( results - > input ) ;
}
if ( results - > error ) {
if ( results - > error ) {
free ( results - > error ) ;
free ( results - > error ) ;
}
}
@ -552,10 +544,6 @@ char *cmd_results_to_json(list_t *res_list) {
json_object_object_add (
json_object_object_add (
root , " error " , json_object_new_string ( results - > error ) ) ;
root , " error " , json_object_new_string ( results - > error ) ) ;
}
}
if ( results - > input ) {
json_object_object_add (
root , " input " , json_object_new_string ( results - > input ) ) ;
}
json_object_array_add ( result_array , root ) ;
json_object_array_add ( result_array , root ) ;
}
}
const char * json = json_object_to_json_string ( result_array ) ;
const char * json = json_object_to_json_string ( result_array ) ;