Ver código fonte

Merge flip_social from https://github.com/jblanked/FlipSocial

Willy-JL 1 ano atrás
pai
commit
0ea58eb96e

+ 1 - 1
flip_social/application.fam

@@ -9,6 +9,6 @@ App(
     fap_icon_assets="assets",
     fap_author="JBlanked",
     fap_weburl="https://github.com/jblanked/FlipSocial",
-    fap_version="1.0.2",
+    fap_version="1.0.3",
     fap_description="Social media platform for the Flipper Zero.",
 )

+ 3 - 0
flip_social/assets/CHANGELOG.md

@@ -1,3 +1,6 @@
+## 1.0.3
+- Updated to ensure the flip_social data folder is created when saving settings.
+
 ## 1.0.2
 - Fixed the Feed Type and Notifications toggles, in the User Settings, to work as intended. 
 - Added flip status to each feed post.

+ 1 - 1
flip_social/flip_social.h

@@ -10,7 +10,7 @@
 #include <font/font.h>
 
 #define TAG "FlipSocial"
-#define VERSION_TAG TAG " v1.0.2"
+#define VERSION_TAG TAG " v1.0.3"
 
 #define MAX_PRE_SAVED_MESSAGES 20 // Maximum number of pre-saved messages
 #define MAX_MESSAGE_LENGTH 100    // Maximum length of a message in the feed

+ 5 - 1
flip_social/flip_storage/flip_social_storage.c

@@ -389,6 +389,8 @@ bool flip_social_save_post(const char *post_id, const char *json_feed_data)
 
     // Create the directory for saving the feed
     char directory_path[128];
+    snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social");
+    storage_common_mkdir(storage, directory_path);
     snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/feed");
     storage_common_mkdir(storage, directory_path);
 
@@ -427,11 +429,13 @@ bool save_char(
     }
     // Create the directory for saving settings
     char directory_path[256];
-    snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/data");
+    snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social");
 
     // Create the directory
     Storage *storage = furi_record_open(RECORD_STORAGE);
     storage_common_mkdir(storage, directory_path);
+    snprintf(directory_path, sizeof(directory_path), STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/data");
+    storage_common_mkdir(storage, directory_path);
 
     // Open the settings file
     File *file = storage_file_alloc(storage);

+ 18 - 1
flip_social/jsmn/jsmn.c

@@ -454,6 +454,11 @@ char *get_json_value(char *key, const char *json_data)
         jsmn_parser parser;
         jsmn_init(&parser);
         uint32_t max_tokens = json_token_count(json_data);
+        if (!jsmn_memory_check(max_tokens))
+        {
+            FURI_LOG_E("JSMM.H", "Insufficient memory for JSON tokens.");
+            return NULL;
+        }
         // Allocate tokens array on the heap
         jsmntok_t *tokens = malloc(sizeof(jsmntok_t) * max_tokens);
         if (tokens == NULL)
@@ -572,6 +577,12 @@ char *get_json_array_value(char *key, uint32_t index, const char *json_data)
         return NULL;
     }
     uint32_t max_tokens = json_token_count(array_str);
+    if (!jsmn_memory_check(max_tokens))
+    {
+        FURI_LOG_E("JSMM.H", "Insufficient memory for JSON tokens.");
+        free(array_str);
+        return NULL;
+    }
 
     jsmn_parser parser;
     jsmn_init(&parser);
@@ -602,7 +613,7 @@ char *get_json_array_value(char *key, uint32_t index, const char *json_data)
 
     if (index >= (uint32_t)tokens[0].size)
     {
-        FURI_LOG_E("JSMM.H", "Index %lu out of bounds for array with size %u.", index, tokens[0].size);
+        // FURI_LOG_E("JSMM.H", "Index %lu out of bounds for array with size %u.", index, tokens[0].size);
         free(tokens);
         free(array_str);
         return NULL;
@@ -654,6 +665,12 @@ char **get_json_array_values(char *key, char *json_data, int *num_values)
         return NULL;
     }
     uint32_t max_tokens = json_token_count(array_str);
+    if (!jsmn_memory_check(max_tokens))
+    {
+        FURI_LOG_E("JSMM.H", "Insufficient memory for JSON tokens.");
+        free(array_str);
+        return NULL;
+    }
     // Initialize the JSON parser
     jsmn_parser parser;
     jsmn_init(&parser);

+ 18 - 1
flip_social/jsmn/jsmn_furi.c

@@ -481,6 +481,11 @@ FuriString *get_json_value_furi(const char *key, const FuriString *json_data)
         return NULL;
     }
     uint32_t max_tokens = json_token_count_furi(json_data);
+    if (!jsmn_memory_check(max_tokens))
+    {
+        FURI_LOG_E("JSMM.H", "Insufficient memory for JSON tokens.");
+        return NULL;
+    }
     // Create a temporary FuriString from key
     FuriString *key_str = furi_string_alloc();
     furi_string_cat_str(key_str, key);
@@ -546,6 +551,12 @@ FuriString *get_json_array_value_furi(const char *key, uint32_t index, const Fur
         return NULL;
     }
     uint32_t max_tokens = json_token_count_furi(array_str);
+    if (!jsmn_memory_check(max_tokens))
+    {
+        FURI_LOG_E("JSMM.H", "Insufficient memory for JSON tokens.");
+        furi_string_free(array_str);
+        return NULL;
+    }
     jsmn_parser parser;
     jsmn_init_furi(&parser);
 
@@ -576,7 +587,7 @@ FuriString *get_json_array_value_furi(const char *key, uint32_t index, const Fur
 
     if (index >= (uint32_t)tokens[0].size)
     {
-        FURI_LOG_E("JSMM.H", "Index %lu out of bounds for array with size %u.", index, tokens[0].size);
+        // FURI_LOG_E("JSMM.H", "Index %lu out of bounds for array with size %u.", index, tokens[0].size);
         free(tokens);
         furi_string_free(array_str);
         return NULL;
@@ -622,6 +633,12 @@ FuriString **get_json_array_values_furi(const char *key, const FuriString *json_
     }
 
     uint32_t max_tokens = json_token_count_furi(array_str);
+    if (!jsmn_memory_check(max_tokens))
+    {
+        FURI_LOG_E("JSMM.H", "Insufficient memory for JSON tokens.");
+        furi_string_free(array_str);
+        return NULL;
+    }
     jsmn_parser parser;
     jsmn_init_furi(&parser);
 

+ 1 - 0
flip_social/jsmn/jsmn_h.c

@@ -12,3 +12,4 @@ FuriString *char_to_furi_string(const char *str)
     }
     return furi_str;
 }
+bool jsmn_memory_check(size_t heap_size) { return memmgr_get_free_heap() > (heap_size + 1024); }

+ 4 - 1
flip_social/jsmn/jsmn_h.h

@@ -50,4 +50,7 @@ typedef struct
     FuriString *value;
 } FuriJSON;
 
-FuriString *char_to_furi_string(const char *str);
+FuriString *char_to_furi_string(const char *str);
+
+// check memory
+bool jsmn_memory_check(size_t heap_size);