From 7b14fd7212b2e5f053b1f00dbc4b35d953c84f40 Mon Sep 17 00:00:00 2001 From: mwalker33 Date: Mon, 6 Apr 2020 16:20:57 +1000 Subject: [PATCH] Code Clean --- client/emv/emvjson.c | 1 + client/fileutils.c | 9 ++++----- client/proxmark3.c | 7 +++---- client/settings.c | 14 ++++++-------- client/settings.h | 14 ++++++++++---- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/client/emv/emvjson.c b/client/emv/emvjson.c index 9b86b38ca..968b51d51 100644 --- a/client/emv/emvjson.c +++ b/client/emv/emvjson.c @@ -97,6 +97,7 @@ int JsonSaveStr(json_t *root, const char *path, const char *value) { int JsonSaveBoolean(json_t *root, const char *path, bool value) { return JsonSaveJsonObject(root, path, json_boolean(value)); } + int JsonSaveBufAsHexCompact(json_t *elm, const char *path, uint8_t *data, size_t datalen) { char *msg = sprint_hex_inrow(data, datalen); if (msg && strlen(msg) && msg[strlen(msg) - 1] == ' ') diff --git a/client/fileutils.c b/client/fileutils.c index 5ce1f3a6a..50d3ca9d6 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -38,6 +38,8 @@ // this define is needed for scandir/alphasort to work #define _GNU_SOURCE #include "fileutils.h" +#include "settings.h" + #include #include @@ -52,9 +54,6 @@ #define PATH_MAX_LENGTH 200 -extern void JsonLoadSettingsCallback (json_t *root); -extern void JsonSaveSettingsCallback (json_t *root); - struct wave_info_t { char signature[4]; uint32_t filesize; @@ -429,7 +428,7 @@ int saveFileJSON(const char *preferredName, JSONFileType ftype, uint8_t *data, s } break; case jsfSettings: - JsonSaveSettingsCallback (root); + settings_save_callback (root); break; default: break; @@ -870,7 +869,7 @@ int loadFileJSON(const char *preferredName, void *data, size_t maxdatalen, size_ *datalen = sptr; } if (!strcmp(ctype,"settings")) { - JsonLoadSettingsCallback (root); + settings_load_callback (root); } PrintAndLogEx(SUCCESS, "loaded from JSON file " _YELLOW_("%s"), fileName); out: diff --git a/client/proxmark3.c b/client/proxmark3.c index 504ae93e5..168b5b960 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -558,7 +558,6 @@ int main(int argc, char *argv[]) { /* initialize history */ using_history(); - #ifdef RL_STATE_READCMD rl_extend_line_buffer(1024); @@ -583,9 +582,9 @@ int main(int argc, char *argv[]) { set_my_executable_path(); set_my_user_directory(); - // Settings - settingsLoad (); - settingsSave (); + // Settings Load and Test + settings_load (); + settings_save (); printf ("Ver : %s\n",mySettings.version); // End Settings diff --git a/client/settings.c b/client/settings.c index a3571c566..976121eed 100644 --- a/client/settings.c +++ b/client/settings.c @@ -43,10 +43,8 @@ #include "comms.h" #include "emv/emvjson.h" -// settings_t mySettings; - // Load all settings into memory (struct) -void settingsLoad (void) +int settings_load (void) { // loadFileJson wants these, so pass in place holder values, though not used // in settings load; @@ -79,17 +77,17 @@ void settingsLoad (void) printf (" window_hsize (int) : [%d]\n",mySettings.window_hsize); printf (" window_wsize (int) : [%d]\n",mySettings.window_wsize); + return PM3_SUCCESS; } // Save all settings from memory (struct) to file -int settingsSave (void) +int settings_save (void) { // Note sure if backup has value ? char backupFilename[500]; - // if (mySettings.loaded) snprintf (backupFilename,sizeof(backupFilename),"%s.bak",settingsFilename); - + if (fileExists (backupFilename)) { if (remove (backupFilename) != 0) { PrintAndLogEx (FAILED, "Error - could not delete old settings backup file \"%s\"",backupFilename); @@ -115,7 +113,7 @@ int settingsSave (void) return PM3_SUCCESS; } -void JsonSaveSettingsCallback (json_t *root) +void settings_save_callback (json_t *root) { // extern settings_t mySettings; @@ -141,7 +139,7 @@ void JsonSaveSettingsCallback (json_t *root) JsonSaveInt (root,"window.wsize",mySettings.window_wsize); } -void JsonLoadSettingsCallback (json_t *root) +void settings_load_callback (json_t *root) { // extern settings_t mySettings; json_error_t up_error = {0}; diff --git a/client/settings.h b/client/settings.h index f0093c207..799af7caa 100644 --- a/client/settings.h +++ b/client/settings.h @@ -8,10 +8,13 @@ //----------------------------------------------------------------------------- // Settings Functions //----------------------------------------------------------------------------- +#ifndef settings_h +#define settings_h #include "fileutils.h" #define settingsFilename "settings.json" + typedef struct { bool loaded; char version[20]; @@ -23,10 +26,13 @@ typedef struct { int window_wsize; } settings_t; +// Settings struct so as to be available to other modules by including settings.h settings_t mySettings; -void settingsLoad (void); -int settingsSave (void); +int settings_load (void); +int settings_save (void); -void JsonSaveCallback ( json_t *root); -void JsonLoadCallback ( json_t *root); +void settings_save_callback (json_t *root); +void settings_load_callback (json_t *root); + +#endif