diff options
author | Martin Szulecki | 2013-09-26 22:39:04 +0200 |
---|---|---|
committer | Martin Szulecki | 2013-09-26 22:39:04 +0200 |
commit | 871ffcdcf06692fd306c8f63cd7796277c2b3d27 (patch) | |
tree | 6d1fc3f266af3a99b984ecc627c512f582113321 | |
parent | 6c329b7e20e7511e0be0445e6aeec46d588b2e4b (diff) | |
download | libirecovery-871ffcdcf06692fd306c8f63cd7796277c2b3d27.tar.gz libirecovery-871ffcdcf06692fd306c8f63cd7796277c2b3d27.tar.bz2 |
Make irecv_execute_script() use a script as argument instead of a filename
-rw-r--r-- | include/libirecovery.h | 2 | ||||
-rw-r--r-- | src/libirecovery.c | 20 |
2 files changed, 10 insertions, 12 deletions
diff --git a/include/libirecovery.h b/include/libirecovery.h index fbc0a8f..efa6ff2 100644 --- a/include/libirecovery.h +++ b/include/libirecovery.h @@ -205,7 +205,7 @@ irecv_error_t irecv_reset(irecv_client_t client); irecv_error_t irecv_close(irecv_client_t client); irecv_error_t irecv_receive(irecv_client_t client); irecv_error_t irecv_send_exploit(irecv_client_t client); -irecv_error_t irecv_execute_script(irecv_client_t client, const char* filename); +irecv_error_t irecv_execute_script(irecv_client_t client, const char* script); irecv_error_t irecv_set_configuration(irecv_client_t client, int configuration); irecv_error_t irecv_event_subscribe(irecv_client_t client, irecv_event_type type, irecv_event_cb_t callback, void *user_data); diff --git a/src/libirecovery.c b/src/libirecovery.c index 54af81d..87ec520 100644 --- a/src/libirecovery.c +++ b/src/libirecovery.c @@ -1271,33 +1271,31 @@ irecv_error_t irecv_send_exploit(irecv_client_t client) { return IRECV_E_SUCCESS; } -irecv_error_t irecv_execute_script(irecv_client_t client, const char* filename) { +irecv_error_t irecv_execute_script(irecv_client_t client, const char* script) { irecv_error_t error = IRECV_E_SUCCESS; if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; - char* file_data = NULL; - unsigned int file_size = 0; - if(irecv_read_file(filename, &file_data, &file_size) < 0) { - return IRECV_E_FILE_NOT_FOUND; - } - - char* line = strtok(file_data, "\n"); + char* body = strdup(script); + char* line = strtok(body, "\n"); while(line != NULL) { if(line[0] != '#') { error = irecv_send_command(client, line); if(error != IRECV_E_SUCCESS) { - return error; + break; } error = irecv_receive(client); if(error != IRECV_E_SUCCESS) { - return error; + break; } } line = strtok(NULL, "\n"); } - return IRECV_E_SUCCESS; + if (body) + free(body); + + return error; } irecv_error_t irecv_saveenv(irecv_client_t client) { |