Просмотр исходного кода

converted strcat to furi_string_cat() to allow compilation on officia… (#10) (#15)

* converted strcat to furi_string_cat() to allow compilation on official firmware

* convert furistring to cstr before uart

* utilize furi string functions for logs

* convert output data to FuriString

---------

Co-authored-by: Steven Boger <sboger@users.noreply.github.com>
Co-authored-by: Steven Boger <stevenb@marketleader.com>
bigbrodude6119 2 лет назад
Родитель
Сommit
51eaaa95b9

+ 3 - 3
evil_portal_app.c

@@ -31,7 +31,7 @@ Evil_PortalApp *evil_portal_app_alloc() {
   app->sent_reset = false;
   app->sent_reset = false;
   app->has_command_queue = false;  
   app->has_command_queue = false;  
   app->command_index = 0;
   app->command_index = 0;
-  app->portal_logs = malloc(5000);
+  app->portal_logs = furi_string_alloc();
 
 
   app->gui = furi_record_open(RECORD_GUI);
   app->gui = furi_record_open(RECORD_GUI);
 
 
@@ -73,9 +73,9 @@ Evil_PortalApp *evil_portal_app_alloc() {
 void evil_portal_app_free(Evil_PortalApp *app) {  
 void evil_portal_app_free(Evil_PortalApp *app) {  
 
 
   // save latest logs
   // save latest logs
-  if (strlen(app->portal_logs) > 0) {
+  if (furi_string_utf8_length(app->portal_logs) > 0) {
     write_logs(app->portal_logs);
     write_logs(app->portal_logs);
-    free(app->portal_logs);
+    furi_string_free(app->portal_logs);
   }
   }
 
 
   // Send reset event to dev board
   // Send reset event to dev board

+ 1 - 1
evil_portal_app_i.h

@@ -25,7 +25,7 @@ struct Evil_PortalApp {
   ViewDispatcher *view_dispatcher;
   ViewDispatcher *view_dispatcher;
   SceneManager *scene_manager;
   SceneManager *scene_manager;
 
 
-  char* portal_logs;
+  FuriString* portal_logs;
   const char *command_queue[1];
   const char *command_queue[1];
   int command_index;
   int command_index;
   bool has_command_queue;
   bool has_command_queue;

+ 12 - 14
evil_portal_uart.c

@@ -57,13 +57,13 @@ static int32_t uart_worker(void *context) {
                   strncmp(SET_AP_CMD,
                   strncmp(SET_AP_CMD,
                           uart->app->command_queue[uart->app->command_index],
                           uart->app->command_queue[uart->app->command_index],
                           strlen(SET_AP_CMD))) {
                           strlen(SET_AP_CMD))) {
-                char *out_data =
-                    malloc((size_t)(strlen((char *)uart->app->ap_name) +
-                                    strlen("setap=")));
-                strcat(out_data, "setap=");
-                strcat(out_data, (char *)uart->app->ap_name);
+                FuriString *out_data = furi_string_alloc();
 
 
-                evil_portal_uart_tx((uint8_t *)(out_data), strlen(out_data));
+                furi_string_cat(out_data, "setap=");
+                furi_string_cat(out_data, (char *)uart->app->ap_name);
+
+                evil_portal_uart_tx((uint8_t *)(furi_string_get_cstr(out_data)),
+                                    strlen(furi_string_get_cstr(out_data)));
                 evil_portal_uart_tx((uint8_t *)("\n"), 1);
                 evil_portal_uart_tx((uint8_t *)("\n"), 1);
 
 
                 uart->app->sent_ap = true;
                 uart->app->sent_ap = true;
@@ -79,24 +79,22 @@ static int32_t uart_worker(void *context) {
           }
           }
 
 
           if (uart->app->sent_reset == false) {
           if (uart->app->sent_reset == false) {
-            strcat(uart->app->portal_logs, (char *)uart->rx_buf);
+            furi_string_cat(uart->app->portal_logs, (char *)uart->rx_buf);
           }
           }
 
 
-          if (strlen(uart->app->portal_logs) > 4000) {
+          if (furi_string_utf8_length(uart->app->portal_logs) > 4000) {
             write_logs(uart->app->portal_logs);
             write_logs(uart->app->portal_logs);
-            free(uart->app->portal_logs);
-            strcpy(uart->app->portal_logs, "");
+            furi_string_reset(uart->app->portal_logs);
           }
           }
         } else {          
         } else {          
           uart->rx_buf[len] = '\0';
           uart->rx_buf[len] = '\0';
           if (uart->app->sent_reset == false) {
           if (uart->app->sent_reset == false) {
-            strcat(uart->app->portal_logs, (char *)uart->rx_buf);
+            furi_string_cat(uart->app->portal_logs, (char *)uart->rx_buf);
           }
           }
 
 
-          if (strlen(uart->app->portal_logs) > 4000) {
+          if (furi_string_utf8_length(uart->app->portal_logs) > 4000) {
             write_logs(uart->app->portal_logs);
             write_logs(uart->app->portal_logs);
-            free(uart->app->portal_logs);
-            strcpy(uart->app->portal_logs, "");
+            furi_string_reset(uart->app->portal_logs);
           }
           }
         }
         }
       } 
       } 

+ 2 - 4
helpers/evil_portal_storage.c

@@ -97,7 +97,7 @@ char *sequential_file_resolve_path(Storage *storage, const char *dir,
   return strdup(file_path);
   return strdup(file_path);
 }
 }
 
 
-void write_logs(char *portal_logs) {
+void write_logs(FuriString *portal_logs) {
   Storage *storage = evil_portal_open_storage();
   Storage *storage = evil_portal_open_storage();
 
 
   if (!storage_file_exists(storage, EVIL_PORTAL_LOG_SAVE_PATH)) {
   if (!storage_file_exists(storage, EVIL_PORTAL_LOG_SAVE_PATH)) {
@@ -110,11 +110,9 @@ void write_logs(char *portal_logs) {
   File *file = storage_file_alloc(storage);
   File *file = storage_file_alloc(storage);
 
 
   if (storage_file_open(file, seq_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
   if (storage_file_open(file, seq_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
-    storage_file_write(file, portal_logs, strlen(portal_logs));
+    storage_file_write(file, furi_string_get_cstr(portal_logs), furi_string_utf8_length(portal_logs));
   }
   }
   storage_file_close(file);
   storage_file_close(file);
   storage_file_free(file);
   storage_file_free(file);
   evil_portal_close_storage();
   evil_portal_close_storage();
-
-  portal_logs = "";
 }
 }

+ 1 - 1
helpers/evil_portal_storage.h

@@ -12,6 +12,6 @@
 
 
 void evil_portal_read_index_html(void *context);
 void evil_portal_read_index_html(void *context);
 void evil_portal_read_ap_name(void *context);
 void evil_portal_read_ap_name(void *context);
-void write_logs(char* portal_logs);
+void write_logs(FuriString* portal_logs);
 char *sequential_file_resolve_path(Storage *storage, const char *dir,
 char *sequential_file_resolve_path(Storage *storage, const char *dir,
                                    const char *prefix, const char *extension);
                                    const char *prefix, const char *extension);

+ 7 - 8
scenes/evil_portal_scene_console_output.c

@@ -57,8 +57,7 @@ void evil_portal_scene_console_output_on_enter(void *context) {
       furi_string_cat_str(app->text_box_store, help_msg);
       furi_string_cat_str(app->text_box_store, help_msg);
       app->text_box_store_strlen += strlen(help_msg);
       app->text_box_store_strlen += strlen(help_msg);
       write_logs(app->portal_logs);
       write_logs(app->portal_logs);
-      free(app->portal_logs);
-      strcpy(app->portal_logs, "");
+      furi_string_reset(app->portal_logs);
       if (app->show_stopscan_tip) {
       if (app->show_stopscan_tip) {
         const char *msg = "Press BACK to return\n";
         const char *msg = "Press BACK to return\n";
         furi_string_cat_str(app->text_box_store, msg);
         furi_string_cat_str(app->text_box_store, msg);
@@ -105,12 +104,12 @@ void evil_portal_scene_console_output_on_enter(void *context) {
         strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
         strncmp(SET_HTML_CMD, app->selected_tx_string, strlen(SET_HTML_CMD))) {
       evil_portal_read_index_html(context);
       evil_portal_read_index_html(context);
 
 
-      char *data = malloc(
-          (size_t)(strlen((char *)app->index_html) + strlen("sethtml=")));
-      strcat(data, "sethtml=");
-      strcat(data, (char *)app->index_html);
+      FuriString *data = furi_string_alloc();
+      furi_string_cat(data, "sethtml=");
+      furi_string_cat(data, (char *)app->index_html);
 
 
-      evil_portal_uart_tx((uint8_t *)(data), strlen(data));
+      evil_portal_uart_tx((uint8_t *)(furi_string_get_cstr(data)),
+                          strlen(furi_string_get_cstr(data)));
       evil_portal_uart_tx((uint8_t *)("\n"), 1);
       evil_portal_uart_tx((uint8_t *)("\n"), 1);
 
 
       app->sent_html = true;
       app->sent_html = true;
@@ -155,4 +154,4 @@ void evil_portal_scene_console_output_on_exit(void *context) {
 
 
   // Unregister rx callback
   // Unregister rx callback
   evil_portal_uart_set_handle_rx_data_cb(app->uart, NULL);
   evil_portal_uart_set_handle_rx_data_cb(app->uart, NULL);
-}
+}