Skip to content

Commit

Permalink
Merge pull request #24 from jblanked/dev_1.0
Browse files Browse the repository at this point in the history
Updated to ensure the flip_social data folder is created when saving
  • Loading branch information
jblanked authored Jan 14, 2025
2 parents b9aee23 + 6242c05 commit 9432080
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 6 deletions.
2 changes: 1 addition & 1 deletion application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 3 additions & 0 deletions assets/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion flip_social.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion flip_storage/flip_social_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
19 changes: 18 additions & 1 deletion jsmn/jsmn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 18 additions & 1 deletion jsmn/jsmn_furi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions jsmn/jsmn_h.c
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
5 changes: 4 additions & 1 deletion jsmn/jsmn_h.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 9432080

Please sign in to comment.