Sfoglia il codice sorgente

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

Willy-JL 1 anno fa
parent
commit
f9af643689

+ 6 - 2
flip_social/README.md

@@ -6,7 +6,7 @@ The highlight of this app is customizable pre-saves, which, as explained below,
 FlipSocial uses the FlipperHTTP flash for the WiFi Devboard, first introduced in the WebCrawler app: https://github.com/jblanked/WebCrawler-FlipperZero/tree/main/assets/FlipperHTTP
 FlipSocial uses the FlipperHTTP flash for the WiFi Devboard, first introduced in the WebCrawler app: https://github.com/jblanked/WebCrawler-FlipperZero/tree/main/assets/FlipperHTTP
 
 
 ## Requirements
 ## Requirements
-- WiFi Dev Board or Raspberry Pi Pico W for Flipper Zero with FlipperHTTP Flash: https://github.com/jblanked/FlipperHTTP
+- WiFi Developer Board or Raspberry Pi Pico W with FlipperHTTP Flash: https://github.com/jblanked/FlipperHTTP
 - WiFi Access Point
 - WiFi Access Point
 
 
 
 
@@ -88,4 +88,8 @@ This is a big project, and I welcome all contributors, especially developers int
 - **Solution 3:** Ensure your WiFi Devboard is plugged in, then restart your Flipper device.
 - **Solution 3:** Ensure your WiFi Devboard is plugged in, then restart your Flipper device.
 
 
 5. Out of memory when starting the app or after visiting the feed and post views back-to-back.
 5. Out of memory when starting the app or after visiting the feed and post views back-to-back.
-- **Solution:** Restart your Flipper device.
+- **Solution:** Restart your Flipper device.
+
+6. I can no longer access my Direct Messages.
+- **Solution 1:** Uppdate the app to version 0.6.3 (or higher)
+- **Solution 2:** Click the logout button then login again.

+ 2 - 0
flip_social/alloc/flip_social_alloc.c

@@ -918,6 +918,8 @@ FlipSocialApp* flip_social_app_alloc() {
                 '\0';
                 '\0';
         }
         }
 
 
+        auth_headers_alloc();
+
         // set variable item text (ommit the passwords)
         // set variable item text (ommit the passwords)
         variable_item_set_current_value_text(
         variable_item_set_current_value_text(
             app->variable_item_logged_in_wifi_settings_ssid, app->wifi_ssid_logged_in);
             app->variable_item_logged_in_wifi_settings_ssid, app->wifi_ssid_logged_in);

+ 1 - 1
flip_social/application.fam

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

+ 6 - 2
flip_social/assets/README.md

@@ -6,7 +6,7 @@ The highlight of this app is customizable pre-saves, which, as explained below,
 FlipSocial uses the FlipperHTTP flash for the WiFi Devboard, first introduced in the WebCrawler app: https://github.com/jblanked/WebCrawler-FlipperZero/tree/main/assets/FlipperHTTP
 FlipSocial uses the FlipperHTTP flash for the WiFi Devboard, first introduced in the WebCrawler app: https://github.com/jblanked/WebCrawler-FlipperZero/tree/main/assets/FlipperHTTP
 
 
 ## Requirements
 ## Requirements
-- WiFi Dev Board or Raspberry Pi Pico W for Flipper Zero with FlipperHTTP Flash: https://github.com/jblanked/FlipperHTTP
+- WiFi Developer Board or Raspberry Pi Pico W with FlipperHTTP Flash: https://github.com/jblanked/FlipperHTTP
 - WiFi Access Point
 - WiFi Access Point
 
 
 
 
@@ -88,4 +88,8 @@ This is a big project, and I welcome all contributors, especially developers int
 - **Solution 3:** Ensure your WiFi Devboard is plugged in, then restart your Flipper device.
 - **Solution 3:** Ensure your WiFi Devboard is plugged in, then restart your Flipper device.
 
 
 5. Out of memory when starting the app or after visiting the feed and post views back-to-back.
 5. Out of memory when starting the app or after visiting the feed and post views back-to-back.
-- **Solution:** Restart your Flipper device.
+- **Solution:** Restart your Flipper device.
+
+6. I can no longer access my Direct Messages.
+- **Solution 1:** Uppdate the app to version 0.6.3 (or higher)
+- **Solution 2:** Click the logout button then login again.

+ 8 - 12
flip_social/callback/flip_social_callback.c

@@ -967,6 +967,7 @@ void flip_social_logged_in_profile_change_password_updated(void* context) {
     }
     }
 
 
     // send post request to change password
     // send post request to change password
+    auth_headers_alloc();
     char payload[256];
     char payload[256];
     snprintf(
     snprintf(
         payload,
         payload,
@@ -975,15 +976,12 @@ void flip_social_logged_in_profile_change_password_updated(void* context) {
         app->login_username_logged_out,
         app->login_username_logged_out,
         old_password,
         old_password,
         app->change_password_logged_in);
         app->change_password_logged_in);
-    char* headers = jsmn("Content-Type", "application/json");
     if(!flipper_http_post_request_with_headers(
     if(!flipper_http_post_request_with_headers(
-           "https://www.flipsocial.net/api/user/change-password/", headers, payload)) {
+           "https://www.flipsocial.net/api/user/change-password/", auth_headers, payload)) {
         FURI_LOG_E(TAG, "Failed to send post request to change password");
         FURI_LOG_E(TAG, "Failed to send post request to change password");
         FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
         FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
-        free(headers);
         return;
         return;
     }
     }
-    free(headers);
     // Save the settings
     // Save the settings
     save_settings(
     save_settings(
         app_instance->wifi_ssid_logged_out,
         app_instance->wifi_ssid_logged_out,
@@ -1098,6 +1096,7 @@ void flip_social_logged_in_messages_user_choice_message_updated(void* context) {
         '\0';
         '\0';
 
 
     // send post request to send message
     // send post request to send message
+    auth_headers_alloc();
     char url[128];
     char url[128];
     char payload[256];
     char payload[256];
     snprintf(
     snprintf(
@@ -1111,17 +1110,15 @@ void flip_social_logged_in_messages_user_choice_message_updated(void* context) {
         "{\"receiver\":\"%s\",\"content\":\"%s\"}",
         "{\"receiver\":\"%s\",\"content\":\"%s\"}",
         flip_social_explore->usernames[flip_social_explore->index],
         flip_social_explore->usernames[flip_social_explore->index],
         app->message_user_choice_logged_in);
         app->message_user_choice_logged_in);
-    char* headers = jsmn("Content-Type", "application/json");
 
 
-    if(flipper_http_post_request_with_headers(url, headers, payload)) // start the async request
+    if(flipper_http_post_request_with_headers(
+           url, auth_headers, payload)) // start the async request
     {
     {
         furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
         fhttp.state = RECEIVING;
-        free(headers);
     } else {
     } else {
         FURI_LOG_E(TAG, "Failed to send post request to send message");
         FURI_LOG_E(TAG, "Failed to send post request to send message");
         FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
         FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
-        free(headers);
         return;
         return;
     }
     }
     while(fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0) {
     while(fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0) {
@@ -1173,6 +1170,7 @@ void flip_social_logged_in_messages_new_message_updated(void* context) {
         '\0';
         '\0';
 
 
     // send post request to send message
     // send post request to send message
+    auth_headers_alloc();
     char url[128];
     char url[128];
     char payload[256];
     char payload[256];
     snprintf(
     snprintf(
@@ -1186,17 +1184,15 @@ void flip_social_logged_in_messages_new_message_updated(void* context) {
         "{\"receiver\":\"%s\",\"content\":\"%s\"}",
         "{\"receiver\":\"%s\",\"content\":\"%s\"}",
         flip_social_message_users->usernames[flip_social_message_users->index],
         flip_social_message_users->usernames[flip_social_message_users->index],
         app->messages_new_message_logged_in);
         app->messages_new_message_logged_in);
-    char* headers = jsmn("Content-Type", "application/json");
 
 
-    if(flipper_http_post_request_with_headers(url, headers, payload)) // start the async request
+    if(flipper_http_post_request_with_headers(
+           url, auth_headers, payload)) // start the async request
     {
     {
         furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         furi_timer_start(fhttp.get_timeout_timer, TIMEOUT_DURATION_TICKS);
         fhttp.state = RECEIVING;
         fhttp.state = RECEIVING;
-        free(headers);
     } else {
     } else {
         FURI_LOG_E(TAG, "Failed to send post request to send message");
         FURI_LOG_E(TAG, "Failed to send post request to send message");
         FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
         FURI_LOG_E(TAG, "Make sure the Flipper is connected to the Wifi Dev Board");
-        free(headers);
         return;
         return;
     }
     }
     while(fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0) {
     while(fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0) {

+ 30 - 34
flip_social/draw/flip_social_draw.c

@@ -132,12 +132,22 @@ void flip_social_callback_draw_compose(Canvas* canvas, void* model) {
         FURI_LOG_E(TAG, "FlipSocialApp is NULL");
         FURI_LOG_E(TAG, "FlipSocialApp is NULL");
         return;
         return;
     }
     }
+    if(!selected_message) {
+        FURI_LOG_E(TAG, "Selected message is NULL");
+        return;
+    }
+
+    if(strlen(selected_message) > MAX_MESSAGE_LENGTH) {
+        FURI_LOG_E(TAG, "Message is too long");
+        return;
+    }
 
 
     if(!flip_social_dialog_shown) {
     if(!flip_social_dialog_shown) {
         flip_social_dialog_shown = true;
         flip_social_dialog_shown = true;
         app_instance->input_event_queue = furi_record_open(RECORD_INPUT_EVENTS);
         app_instance->input_event_queue = furi_record_open(RECORD_INPUT_EVENTS);
         app_instance->input_event =
         app_instance->input_event =
             furi_pubsub_subscribe(app_instance->input_event_queue, on_input, NULL);
             furi_pubsub_subscribe(app_instance->input_event_queue, on_input, NULL);
+        auth_headers_alloc();
     }
     }
 
 
     draw_user_message(canvas, selected_message, 0, 2);
     draw_user_message(canvas, selected_message, 0, 2);
@@ -159,6 +169,10 @@ void flip_social_callback_draw_compose(Canvas* canvas, void* model) {
     case ActionNext:
     case ActionNext:
         // send selected_message
         // send selected_message
         if(selected_message && app_instance->login_username_logged_in) {
         if(selected_message && app_instance->login_username_logged_in) {
+            if(strlen(selected_message) > MAX_MESSAGE_LENGTH) {
+                FURI_LOG_E(TAG, "Message is too long");
+                return;
+            }
             // Send the selected_message
             // Send the selected_message
             char command[256];
             char command[256];
             snprintf(
             snprintf(
@@ -168,12 +182,8 @@ void flip_social_callback_draw_compose(Canvas* canvas, void* model) {
                 app_instance->login_username_logged_in,
                 app_instance->login_username_logged_in,
                 selected_message);
                 selected_message);
 
 
-            bool success = flipper_http_post_request_with_headers(
-                "https://www.flipsocial.net/api/feed/post/",
-                "{\"Content-Type\":\"application/json\"}",
-                command);
-
-            if(!success) {
+            if(!flipper_http_post_request_with_headers(
+                   "https://www.flipsocial.net/api/feed/post/", auth_headers, command)) {
                 FURI_LOG_E(TAG, "Failed to send HTTP request for feed");
                 FURI_LOG_E(TAG, "Failed to send HTTP request for feed");
                 fhttp.state = ISSUE;
                 fhttp.state = ISSUE;
                 return;
                 return;
@@ -185,23 +195,12 @@ void flip_social_callback_draw_compose(Canvas* canvas, void* model) {
             FURI_LOG_E(TAG, "Message or username is NULL");
             FURI_LOG_E(TAG, "Message or username is NULL");
             return;
             return;
         }
         }
-
-        int i = 0;
         while(fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0) {
         while(fhttp.state == RECEIVING && furi_timer_is_running(fhttp.get_timeout_timer) > 0) {
             // Wait for the feed to be received
             // Wait for the feed to be received
             furi_delay_ms(100);
             furi_delay_ms(100);
 
 
-            char dots_str[64] = "Receiving";
-
-            // Append dots to the string based on the value of i
-            int dot_count = i % 4;
-            int len = strlen(dots_str);
-            snprintf(dots_str + len, sizeof(dots_str) - len, "%.*s", dot_count, "....");
-
             // Draw the resulting string on the canvas
             // Draw the resulting string on the canvas
-            canvas_draw_str(canvas, 0, 30, dots_str);
-
-            i++;
+            canvas_draw_str(canvas, 0, 30, "Receiving..");
         }
         }
         flip_social_dialog_stop = true;
         flip_social_dialog_stop = true;
         furi_timer_stop(fhttp.get_timeout_timer);
         furi_timer_stop(fhttp.get_timeout_timer);
@@ -372,6 +371,7 @@ void flip_social_callback_draw_feed(Canvas* canvas, void* model) {
         app_instance->input_event_queue = furi_record_open(RECORD_INPUT_EVENTS);
         app_instance->input_event_queue = furi_record_open(RECORD_INPUT_EVENTS);
         app_instance->input_event =
         app_instance->input_event =
             furi_pubsub_subscribe(app_instance->input_event_queue, on_input, NULL);
             furi_pubsub_subscribe(app_instance->input_event_queue, on_input, NULL);
+        auth_headers_alloc();
     }
     }
 
 
     // handle action
     // handle action
@@ -442,9 +442,7 @@ void flip_social_callback_draw_feed(Canvas* canvas, void* model) {
             app_instance->login_username_logged_in,
             app_instance->login_username_logged_in,
             flip_social_feed->ids[flip_social_feed->index]);
             flip_social_feed->ids[flip_social_feed->index]);
         flipper_http_post_request_with_headers(
         flipper_http_post_request_with_headers(
-            "https://www.flipsocial.net/api/feed/flip/",
-            "{\"Content-Type\":\"application/json\"}",
-            payload);
+            "https://www.flipsocial.net/api/feed/flip/", auth_headers, payload);
         flip_social_canvas_draw_message(
         flip_social_canvas_draw_message(
             canvas,
             canvas,
             flip_social_feed->usernames[flip_social_feed->index],
             flip_social_feed->usernames[flip_social_feed->index],
@@ -513,10 +511,9 @@ void flip_social_callback_draw_login(Canvas* canvas, void* model) {
             "{\"username\":\"%s\",\"password\":\"%s\"}",
             "{\"username\":\"%s\",\"password\":\"%s\"}",
             app_instance->login_username_logged_out,
             app_instance->login_username_logged_out,
             app_instance->login_password_logged_out);
             app_instance->login_password_logged_out);
+        auth_headers_alloc();
         flip_social_login_success = flipper_http_post_request_with_headers(
         flip_social_login_success = flipper_http_post_request_with_headers(
-            "https://www.flipsocial.net/api/user/login/",
-            "{\"Content-Type\":\"application/json\"}",
-            buffer);
+            "https://www.flipsocial.net/api/user/login/", auth_headers, buffer);
         if(flip_social_login_success) {
         if(flip_social_login_success) {
             fhttp.state = RECEIVING;
             fhttp.state = RECEIVING;
             return;
             return;
@@ -679,6 +676,9 @@ void flip_social_callback_draw_register(Canvas* canvas, void* model) {
 
 
                 app_instance->is_logged_in = "true";
                 app_instance->is_logged_in = "true";
 
 
+                // update header credentials
+                auth_headers_alloc();
+
                 // save the credentials
                 // save the credentials
                 save_settings(
                 save_settings(
                     app_instance->wifi_ssid_logged_out,
                     app_instance->wifi_ssid_logged_out,
@@ -755,6 +755,7 @@ void flip_social_callback_draw_explore(Canvas* canvas, void* model) {
         app_instance->input_event_queue = furi_record_open(RECORD_INPUT_EVENTS);
         app_instance->input_event_queue = furi_record_open(RECORD_INPUT_EVENTS);
         app_instance->input_event =
         app_instance->input_event =
             furi_pubsub_subscribe(app_instance->input_event_queue, on_input, NULL);
             furi_pubsub_subscribe(app_instance->input_event_queue, on_input, NULL);
+        auth_headers_alloc();
     }
     }
     flip_social_canvas_draw_explore(
     flip_social_canvas_draw_explore(
         canvas, flip_social_explore->usernames[flip_social_explore->index], last_explore_response);
         canvas, flip_social_explore->usernames[flip_social_explore->index], last_explore_response);
@@ -771,9 +772,7 @@ void flip_social_callback_draw_explore(Canvas* canvas, void* model) {
             app_instance->login_username_logged_in,
             app_instance->login_username_logged_in,
             flip_social_explore->usernames[flip_social_explore->index]);
             flip_social_explore->usernames[flip_social_explore->index]);
         flipper_http_post_request_with_headers(
         flipper_http_post_request_with_headers(
-            "https://www.flipsocial.net/api/user/add-friend/",
-            "{\"Content-Type\":\"application/json\"}",
-            add_payload);
+            "https://www.flipsocial.net/api/user/add-friend/", auth_headers, add_payload);
         canvas_clear(canvas);
         canvas_clear(canvas);
         flip_social_canvas_draw_explore(
         flip_social_canvas_draw_explore(
             canvas, flip_social_explore->usernames[flip_social_explore->index], "Added!");
             canvas, flip_social_explore->usernames[flip_social_explore->index], "Added!");
@@ -789,9 +788,7 @@ void flip_social_callback_draw_explore(Canvas* canvas, void* model) {
             app_instance->login_username_logged_in,
             app_instance->login_username_logged_in,
             flip_social_explore->usernames[flip_social_explore->index]);
             flip_social_explore->usernames[flip_social_explore->index]);
         flipper_http_post_request_with_headers(
         flipper_http_post_request_with_headers(
-            "https://www.flipsocial.net/api/user/remove-friend/",
-            "{\"Content-Type\":\"application/json\"}",
-            remove_payload);
+            "https://www.flipsocial.net/api/user/remove-friend/", auth_headers, remove_payload);
         canvas_clear(canvas);
         canvas_clear(canvas);
         flip_social_canvas_draw_explore(
         flip_social_canvas_draw_explore(
             canvas, flip_social_explore->usernames[flip_social_explore->index], "Removed!");
             canvas, flip_social_explore->usernames[flip_social_explore->index], "Removed!");
@@ -834,6 +831,7 @@ void flip_social_callback_draw_friends(Canvas* canvas, void* model) {
         app_instance->input_event_queue = furi_record_open(RECORD_INPUT_EVENTS);
         app_instance->input_event_queue = furi_record_open(RECORD_INPUT_EVENTS);
         app_instance->input_event =
         app_instance->input_event =
             furi_pubsub_subscribe(app_instance->input_event_queue, on_input, NULL);
             furi_pubsub_subscribe(app_instance->input_event_queue, on_input, NULL);
+        auth_headers_alloc();
     }
     }
     flip_social_canvas_draw_explore(
     flip_social_canvas_draw_explore(
         canvas, flip_social_friends->usernames[flip_social_friends->index], last_explore_response);
         canvas, flip_social_friends->usernames[flip_social_friends->index], last_explore_response);
@@ -850,9 +848,7 @@ void flip_social_callback_draw_friends(Canvas* canvas, void* model) {
             app_instance->login_username_logged_in,
             app_instance->login_username_logged_in,
             flip_social_friends->usernames[flip_social_friends->index]);
             flip_social_friends->usernames[flip_social_friends->index]);
         if(flipper_http_post_request_with_headers(
         if(flipper_http_post_request_with_headers(
-               "https://www.flipsocial.net/api/user/add-friend/",
-               "{\"Content-Type\":\"application/json\"}",
-               add_payload)) {
+               "https://www.flipsocial.net/api/user/add-friend/", auth_headers, add_payload)) {
             canvas_clear(canvas);
             canvas_clear(canvas);
             flip_social_canvas_draw_explore(
             flip_social_canvas_draw_explore(
                 canvas, flip_social_friends->usernames[flip_social_friends->index], "Added!");
                 canvas, flip_social_friends->usernames[flip_social_friends->index], "Added!");
@@ -878,7 +874,7 @@ void flip_social_callback_draw_friends(Canvas* canvas, void* model) {
             flip_social_friends->usernames[flip_social_friends->index]);
             flip_social_friends->usernames[flip_social_friends->index]);
         if(flipper_http_post_request_with_headers(
         if(flipper_http_post_request_with_headers(
                "https://www.flipsocial.net/api/user/remove-friend/",
                "https://www.flipsocial.net/api/user/remove-friend/",
-               "{\"Content-Type\":\"application/json\"}",
+               auth_headers,
                remove_payload)) {
                remove_payload)) {
             canvas_clear(canvas);
             canvas_clear(canvas);
             flip_social_canvas_draw_explore(
             flip_social_canvas_draw_explore(

+ 3 - 6
flip_social/explore/flip_social_explore.c

@@ -40,12 +40,9 @@ bool flip_social_get_explore() {
         STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/users.txt");
         STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/users.txt");
 
 
     fhttp.save_received_data = true;
     fhttp.save_received_data = true;
-    char* headers = jsmn("Content-Type", "application/json");
-    // will return true unless the devboard is not connected
-    bool success = flipper_http_get_request_with_headers(
-        "https://www.flipsocial.net/api/user/users/", headers);
-    free(headers);
-    if(!success) {
+    auth_headers_alloc();
+    if(!flipper_http_get_request_with_headers(
+           "https://www.flipsocial.net/api/user/users/", auth_headers)) {
         FURI_LOG_E(TAG, "Failed to send HTTP request for explore");
         FURI_LOG_E(TAG, "Failed to send HTTP request for explore");
         fhttp.state = ISSUE;
         fhttp.state = ISSUE;
         return false;
         return false;

+ 8 - 6
flip_social/feed/flip_social_feed.c

@@ -92,27 +92,29 @@ void flip_social_free_feed() {
 }
 }
 
 
 bool flip_social_get_feed() {
 bool flip_social_get_feed() {
+    if(!app_instance) {
+        FURI_LOG_E(TAG, "FlipSocialApp is NULL");
+        return false;
+    }
     // Get the feed from the server
     // Get the feed from the server
     if(app_instance->login_username_logged_out == NULL) {
     if(app_instance->login_username_logged_out == NULL) {
         FURI_LOG_E(TAG, "Username is NULL");
         FURI_LOG_E(TAG, "Username is NULL");
         return false;
         return false;
     }
     }
-    char command[128];
     snprintf(
     snprintf(
         fhttp.file_path,
         fhttp.file_path,
         sizeof(fhttp.file_path),
         sizeof(fhttp.file_path),
         STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/feed.txt");
         STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/feed.txt");
 
 
     fhttp.save_received_data = true;
     fhttp.save_received_data = true;
-    char* headers = jsmn("Content-Type", "application/json");
+    auth_headers_alloc();
+    char command[96];
     snprintf(
     snprintf(
         command,
         command,
-        128,
+        96,
         "https://www.flipsocial.net/api/feed/40/%s/extended/",
         "https://www.flipsocial.net/api/feed/40/%s/extended/",
         app_instance->login_username_logged_out);
         app_instance->login_username_logged_out);
-    bool success = flipper_http_get_request_with_headers(command, headers);
-    free(headers);
-    if(!success) {
+    if(!flipper_http_get_request_with_headers(command, auth_headers)) {
         FURI_LOG_E(TAG, "Failed to send HTTP request for feed");
         FURI_LOG_E(TAG, "Failed to send HTTP request for feed");
         fhttp.state = ISSUE;
         fhttp.state = ISSUE;
         return false;
         return false;

+ 28 - 0
flip_social/flip_social.c

@@ -20,6 +20,8 @@ bool flip_social_send_message = false;
 char* last_explore_response = NULL;
 char* last_explore_response = NULL;
 char* selected_message = NULL;
 char* selected_message = NULL;
 
 
+char auth_headers[256] = {0};
+
 /**
 /**
  * @brief Function to free the resources used by FlipSocialApp.
  * @brief Function to free the resources used by FlipSocialApp.
  * @details Cleans up all allocated resources before exiting the application.
  * @details Cleans up all allocated resources before exiting the application.
@@ -241,6 +243,8 @@ void flip_social_app_free(FlipSocialApp* app) {
     if(app->message_user_choice_logged_in) free(app->message_user_choice_logged_in);
     if(app->message_user_choice_logged_in) free(app->message_user_choice_logged_in);
     if(app->message_user_choice_logged_in_temp_buffer)
     if(app->message_user_choice_logged_in_temp_buffer)
         free(app->message_user_choice_logged_in_temp_buffer);
         free(app->message_user_choice_logged_in_temp_buffer);
+    if(last_explore_response) free(last_explore_response);
+    if(selected_message) free(selected_message);
 
 
     if(app->input_event && app->input_event_queue)
     if(app->input_event && app->input_event_queue)
         furi_pubsub_unsubscribe(app->input_event_queue, app->input_event);
         furi_pubsub_unsubscribe(app->input_event_queue, app->input_event);
@@ -251,3 +255,27 @@ void flip_social_app_free(FlipSocialApp* app) {
     // Free the app structure
     // Free the app structure
     if(app_instance) free(app_instance);
     if(app_instance) free(app_instance);
 }
 }
+
+void auth_headers_alloc(void) {
+    if(!app_instance) {
+        return;
+    }
+
+    if(app_instance->login_username_logged_out && app_instance->login_password_logged_out) {
+        snprintf(
+            auth_headers,
+            sizeof(auth_headers),
+            "{\"Content-Type\":\"application/json\",\"username\":\"%s\",\"password\":\"%s\"}",
+            app_instance->login_username_logged_out,
+            app_instance->login_password_logged_out);
+    } else if(app_instance->login_username_logged_in && app_instance->change_password_logged_in) {
+        snprintf(
+            auth_headers,
+            sizeof(auth_headers),
+            "{\"Content-Type\":\"application/json\",\"username\":\"%s\",\"password\":\"%s\"}",
+            app_instance->login_username_logged_in,
+            app_instance->change_password_logged_in);
+    } else {
+        snprintf(auth_headers, sizeof(auth_headers), "{\"Content-Type\":\"application/json\"}");
+    }
+}

+ 2 - 0
flip_social/flip_social.h

@@ -325,5 +325,7 @@ extern bool flip_social_dialog_stop;
 extern bool flip_social_send_message;
 extern bool flip_social_send_message;
 extern char* last_explore_response;
 extern char* last_explore_response;
 extern char* selected_message;
 extern char* selected_message;
+extern char auth_headers[256];
 
 
+void auth_headers_alloc(void);
 #endif
 #endif

+ 87 - 44
flip_social/flipper_http/flipper_http.c

@@ -1,7 +1,8 @@
-#include <flipper_http/flipper_http.h>
+#include <flipper_http/flipper_http.h> // change this to where flipper_http.h is located
 FlipperHTTP fhttp;
 FlipperHTTP fhttp;
 char rx_line_buffer[RX_LINE_BUFFER_SIZE];
 char rx_line_buffer[RX_LINE_BUFFER_SIZE];
 uint8_t file_buffer[FILE_BUFFER_SIZE];
 uint8_t file_buffer[FILE_BUFFER_SIZE];
+size_t file_buffer_len = 0;
 // Function to append received data to file
 // Function to append received data to file
 // make sure to initialize the file path before calling this function
 // make sure to initialize the file path before calling this function
 bool flipper_http_append_to_file(
 bool flipper_http_append_to_file(
@@ -13,6 +14,15 @@ bool flipper_http_append_to_file(
     File* file = storage_file_alloc(storage);
     File* file = storage_file_alloc(storage);
 
 
     if(start_new_file) {
     if(start_new_file) {
+        // Delete the file if it already exists
+        if(storage_file_exists(storage, file_path)) {
+            if(!storage_simply_remove_recursive(storage, file_path)) {
+                FURI_LOG_E(HTTP_TAG, "Failed to delete file: %s", file_path);
+                storage_file_free(file);
+                furi_record_close(RECORD_STORAGE);
+                return false;
+            }
+        }
         // Open the file in write mode
         // Open the file in write mode
         if(!storage_file_open(file, file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
         if(!storage_file_open(file, file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
             FURI_LOG_E(HTTP_TAG, "Failed to open file for writing: %s", file_path);
             FURI_LOG_E(HTTP_TAG, "Failed to open file for writing: %s", file_path);
@@ -131,12 +141,13 @@ FuriString* flipper_http_load_from_file(char* file_path) {
 int32_t flipper_http_worker(void* context) {
 int32_t flipper_http_worker(void* context) {
     UNUSED(context);
     UNUSED(context);
     size_t rx_line_pos = 0;
     size_t rx_line_pos = 0;
-    static size_t file_buffer_len = 0;
 
 
     while(1) {
     while(1) {
         uint32_t events = furi_thread_flags_wait(
         uint32_t events = furi_thread_flags_wait(
             WorkerEvtStop | WorkerEvtRxDone, FuriFlagWaitAny, FuriWaitForever);
             WorkerEvtStop | WorkerEvtRxDone, FuriFlagWaitAny, FuriWaitForever);
-        if(events & WorkerEvtStop) break;
+        if(events & WorkerEvtStop) {
+            break;
+        }
         if(events & WorkerEvtRxDone) {
         if(events & WorkerEvtRxDone) {
             // Continuously read from the stream buffer until it's empty
             // Continuously read from the stream buffer until it's empty
             while(!furi_stream_buffer_is_empty(fhttp.flipper_http_stream)) {
             while(!furi_stream_buffer_is_empty(fhttp.flipper_http_stream)) {
@@ -156,10 +167,14 @@ int32_t flipper_http_worker(void* context) {
                     // Write to file if buffer is full
                     // Write to file if buffer is full
                     if(file_buffer_len >= FILE_BUFFER_SIZE) {
                     if(file_buffer_len >= FILE_BUFFER_SIZE) {
                         if(!flipper_http_append_to_file(
                         if(!flipper_http_append_to_file(
-                               file_buffer, file_buffer_len, false, fhttp.file_path)) {
+                               file_buffer,
+                               file_buffer_len,
+                               fhttp.just_started_bytes,
+                               fhttp.file_path)) {
                             FURI_LOG_E(HTTP_TAG, "Failed to append data to file");
                             FURI_LOG_E(HTTP_TAG, "Failed to append data to file");
                         }
                         }
                         file_buffer_len = 0;
                         file_buffer_len = 0;
+                        fhttp.just_started_bytes = false;
                     }
                     }
                 }
                 }
 
 
@@ -182,36 +197,6 @@ int32_t flipper_http_worker(void* context) {
         }
         }
     }
     }
 
 
-    if(fhttp.save_bytes) {
-        // Write the remaining data to the file
-        if(file_buffer_len > 0) {
-            if(!flipper_http_append_to_file(file_buffer, file_buffer_len, false, fhttp.file_path)) {
-                FURI_LOG_E(HTTP_TAG, "Failed to append remaining data to file");
-            }
-        }
-    }
-
-    // remove [POST/END] and/or [GET/END] from the file
-    if(fhttp.save_bytes) {
-        char* end = NULL;
-        if((end = strstr(fhttp.file_path, "[POST/END]")) != NULL) {
-            *end = '\0';
-        } else if((end = strstr(fhttp.file_path, "[GET/END]")) != NULL) {
-            *end = '\0';
-        }
-    }
-
-    // remove newline from the from the end of the file
-    if(fhttp.save_bytes) {
-        char* end = NULL;
-        if((end = strstr(fhttp.file_path, "\n")) != NULL) {
-            *end = '\0';
-        }
-    }
-
-    // Reset the file buffer length
-    file_buffer_len = 0;
-
     return 0;
     return 0;
 }
 }
 // Timer callback function
 // Timer callback function
@@ -418,13 +403,13 @@ bool flipper_http_send_data(const char* data) {
 
 
     // Create a buffer with data + '\n'
     // Create a buffer with data + '\n'
     size_t send_length = data_length + 1; // +1 for '\n'
     size_t send_length = data_length + 1; // +1 for '\n'
-    if(send_length > 256) { // Ensure buffer size is sufficient
+    if(send_length > 512) { // Ensure buffer size is sufficient
         FURI_LOG_E("FlipperHTTP", "Data too long to send over FHTTP.");
         FURI_LOG_E("FlipperHTTP", "Data too long to send over FHTTP.");
         return false;
         return false;
     }
     }
 
 
-    char send_buffer[257]; // 256 + 1 for safety
-    strncpy(send_buffer, data, 256);
+    char send_buffer[513]; // 512 + 1 for safety
+    strncpy(send_buffer, data, 512);
     send_buffer[data_length] = '\n'; // Append newline
     send_buffer[data_length] = '\n'; // Append newline
     send_buffer[data_length + 1] = '\0'; // Null-terminate
     send_buffer[data_length + 1] = '\0'; // Null-terminate
 
 
@@ -710,7 +695,7 @@ bool flipper_http_get_request(const char* url) {
     }
     }
 
 
     // Prepare GET request command
     // Prepare GET request command
-    char command[256];
+    char command[512];
     int ret = snprintf(command, sizeof(command), "[GET]%s", url);
     int ret = snprintf(command, sizeof(command), "[GET]%s", url);
     if(ret < 0 || ret >= (int)sizeof(command)) {
     if(ret < 0 || ret >= (int)sizeof(command)) {
         FURI_LOG_E("FlipperHTTP", "Failed to format GET request command.");
         FURI_LOG_E("FlipperHTTP", "Failed to format GET request command.");
@@ -742,7 +727,7 @@ bool flipper_http_get_request_with_headers(const char* url, const char* headers)
     }
     }
 
 
     // Prepare GET request command with headers
     // Prepare GET request command with headers
-    char command[256];
+    char command[512];
     int ret = snprintf(
     int ret = snprintf(
         command, sizeof(command), "[GET/HTTP]{\"url\":\"%s\",\"headers\":%s}", url, headers);
         command, sizeof(command), "[GET/HTTP]{\"url\":\"%s\",\"headers\":%s}", url, headers);
     if(ret < 0 || ret >= (int)sizeof(command)) {
     if(ret < 0 || ret >= (int)sizeof(command)) {
@@ -774,7 +759,7 @@ bool flipper_http_get_request_bytes(const char* url, const char* headers) {
     }
     }
 
 
     // Prepare GET request command with headers
     // Prepare GET request command with headers
-    char command[256];
+    char command[512];
     int ret = snprintf(
     int ret = snprintf(
         command, sizeof(command), "[GET/BYTES]{\"url\":\"%s\",\"headers\":%s}", url, headers);
         command, sizeof(command), "[GET/BYTES]{\"url\":\"%s\",\"headers\":%s}", url, headers);
     if(ret < 0 || ret >= (int)sizeof(command)) {
     if(ret < 0 || ret >= (int)sizeof(command)) {
@@ -812,7 +797,7 @@ bool flipper_http_post_request_with_headers(
     }
     }
 
 
     // Prepare POST request command with headers and data
     // Prepare POST request command with headers and data
-    char command[256];
+    char command[512];
     int ret = snprintf(
     int ret = snprintf(
         command,
         command,
         sizeof(command),
         sizeof(command),
@@ -851,7 +836,7 @@ bool flipper_http_post_request_bytes(const char* url, const char* headers, const
     }
     }
 
 
     // Prepare POST request command with headers and data
     // Prepare POST request command with headers and data
-    char command[256];
+    char command[512];
     int ret = snprintf(
     int ret = snprintf(
         command,
         command,
         sizeof(command),
         sizeof(command),
@@ -1006,8 +991,35 @@ void flipper_http_rx_callback(const char* line, void* context) {
             fhttp.just_started_get = false;
             fhttp.just_started_get = false;
             fhttp.state = IDLE;
             fhttp.state = IDLE;
             fhttp.save_bytes = false;
             fhttp.save_bytes = false;
-            fhttp.is_bytes_request = false;
             fhttp.save_received_data = false;
             fhttp.save_received_data = false;
+
+            if(fhttp.is_bytes_request) {
+                // Search for the binary marker `[GET/END]` in the file buffer
+                const char marker[] = "[GET/END]";
+                const size_t marker_len = sizeof(marker) - 1; // Exclude null terminator
+
+                for(size_t i = 0; i <= file_buffer_len - marker_len; i++) {
+                    // Check if the marker is found
+                    if(memcmp(&file_buffer[i], marker, marker_len) == 0) {
+                        // Remove the marker by shifting the remaining data left
+                        size_t remaining_len = file_buffer_len - (i + marker_len);
+                        memmove(&file_buffer[i], &file_buffer[i + marker_len], remaining_len);
+                        file_buffer_len -= marker_len;
+                        break;
+                    }
+                }
+
+                // If there is data left in the buffer, append it to the file
+                if(file_buffer_len > 0) {
+                    if(!flipper_http_append_to_file(
+                           file_buffer, file_buffer_len, false, fhttp.file_path)) {
+                        FURI_LOG_E(HTTP_TAG, "Failed to append data to file.");
+                    }
+                    file_buffer_len = 0;
+                }
+            }
+
+            fhttp.is_bytes_request = false;
             return;
             return;
         }
         }
 
 
@@ -1041,8 +1053,35 @@ void flipper_http_rx_callback(const char* line, void* context) {
             fhttp.just_started_post = false;
             fhttp.just_started_post = false;
             fhttp.state = IDLE;
             fhttp.state = IDLE;
             fhttp.save_bytes = false;
             fhttp.save_bytes = false;
-            fhttp.is_bytes_request = false;
             fhttp.save_received_data = false;
             fhttp.save_received_data = false;
+
+            if(fhttp.is_bytes_request) {
+                // Search for the binary marker `[POST/END]` in the file buffer
+                const char marker[] = "[POST/END]";
+                const size_t marker_len = sizeof(marker) - 1; // Exclude null terminator
+
+                for(size_t i = 0; i <= file_buffer_len - marker_len; i++) {
+                    // Check if the marker is found
+                    if(memcmp(&file_buffer[i], marker, marker_len) == 0) {
+                        // Remove the marker by shifting the remaining data left
+                        size_t remaining_len = file_buffer_len - (i + marker_len);
+                        memmove(&file_buffer[i], &file_buffer[i + marker_len], remaining_len);
+                        file_buffer_len -= marker_len;
+                        break;
+                    }
+                }
+
+                // If there is data left in the buffer, append it to the file
+                if(file_buffer_len > 0) {
+                    if(!flipper_http_append_to_file(
+                           file_buffer, file_buffer_len, false, fhttp.file_path)) {
+                        FURI_LOG_E(HTTP_TAG, "Failed to append data to file.");
+                    }
+                    file_buffer_len = 0;
+                }
+            }
+
+            fhttp.is_bytes_request = false;
             return;
             return;
         }
         }
 
 
@@ -1149,6 +1188,8 @@ void flipper_http_rx_callback(const char* line, void* context) {
         fhttp.state = RECEIVING;
         fhttp.state = RECEIVING;
         // for GET request, save data only if it's a bytes request
         // for GET request, save data only if it's a bytes request
         fhttp.save_bytes = fhttp.is_bytes_request;
         fhttp.save_bytes = fhttp.is_bytes_request;
+        fhttp.just_started_bytes = true;
+        file_buffer_len = 0;
         return;
         return;
     } else if(strstr(line, "[POST/SUCCESS]") != NULL) {
     } else if(strstr(line, "[POST/SUCCESS]") != NULL) {
         FURI_LOG_I(HTTP_TAG, "POST request succeeded.");
         FURI_LOG_I(HTTP_TAG, "POST request succeeded.");
@@ -1157,6 +1198,8 @@ void flipper_http_rx_callback(const char* line, void* context) {
         fhttp.state = RECEIVING;
         fhttp.state = RECEIVING;
         // for POST request, save data only if it's a bytes request
         // for POST request, save data only if it's a bytes request
         fhttp.save_bytes = fhttp.is_bytes_request;
         fhttp.save_bytes = fhttp.is_bytes_request;
+        fhttp.just_started_bytes = true;
+        file_buffer_len = 0;
         return;
         return;
     } else if(strstr(line, "[PUT/SUCCESS]") != NULL) {
     } else if(strstr(line, "[PUT/SUCCESS]") != NULL) {
         FURI_LOG_I(HTTP_TAG, "PUT request succeeded.");
         FURI_LOG_I(HTTP_TAG, "PUT request succeeded.");

+ 3 - 0
flip_social/flipper_http/flipper_http.h

@@ -74,12 +74,15 @@ typedef struct {
     bool is_bytes_request; // Flag to indicate if the request is for bytes
     bool is_bytes_request; // Flag to indicate if the request is for bytes
     bool save_bytes; // Flag to save the received data to a file
     bool save_bytes; // Flag to save the received data to a file
     bool save_received_data; // Flag to save the received data to a file
     bool save_received_data; // Flag to save the received data to a file
+
+    bool just_started_bytes; // Indicates if bytes data reception has just started
 } FlipperHTTP;
 } FlipperHTTP;
 
 
 extern FlipperHTTP fhttp;
 extern FlipperHTTP fhttp;
 // Global static array for the line buffer
 // Global static array for the line buffer
 extern char rx_line_buffer[RX_LINE_BUFFER_SIZE];
 extern char rx_line_buffer[RX_LINE_BUFFER_SIZE];
 extern uint8_t file_buffer[FILE_BUFFER_SIZE];
 extern uint8_t file_buffer[FILE_BUFFER_SIZE];
+extern size_t file_buffer_len;
 
 
 // fhttp.last_response holds the last received data from the UART
 // fhttp.last_response holds the last received data from the UART
 
 

+ 3 - 4
flip_social/friends/flip_social_friends.c

@@ -38,16 +38,15 @@ bool flip_social_get_friends() {
         STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/friends.txt");
         STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/friends.txt");
 
 
     fhttp.save_received_data = true;
     fhttp.save_received_data = true;
-    char* headers = jsmn("Content-Type", "application/json");
+    auth_headers_alloc();
     snprintf(
     snprintf(
         url,
         url,
         100,
         100,
         "https://www.flipsocial.net/api/user/friends/%s/",
         "https://www.flipsocial.net/api/user/friends/%s/",
         app_instance->login_username_logged_in);
         app_instance->login_username_logged_in);
-    bool success = flipper_http_get_request_with_headers(url, headers);
-    free(headers);
-    if(!success) {
+    if(!flipper_http_get_request_with_headers(url, auth_headers)) {
         FURI_LOG_E(TAG, "Failed to send HTTP request for friends");
         FURI_LOG_E(TAG, "Failed to send HTTP request for friends");
+        fhttp.state = ISSUE;
         return false;
         return false;
     }
     }
     fhttp.state = RECEIVING;
     fhttp.state = RECEIVING;

+ 9 - 8
flip_social/messages/flip_social_messages.c

@@ -135,15 +135,13 @@ bool flip_social_get_message_users() {
         STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/message_users.txt");
         STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/message_users.txt");
 
 
     fhttp.save_received_data = true;
     fhttp.save_received_data = true;
-    char* headers = jsmn("Content-Type", "application/json");
+    auth_headers_alloc();
     snprintf(
     snprintf(
         command,
         command,
         128,
         128,
         "https://www.flipsocial.net/api/messages/%s/get/list/",
         "https://www.flipsocial.net/api/messages/%s/get/list/",
         app_instance->login_username_logged_out);
         app_instance->login_username_logged_out);
-    bool success = flipper_http_get_request_with_headers(command, headers);
-    free(headers);
-    if(!success) {
+    if(!flipper_http_get_request_with_headers(command, auth_headers)) {
         FURI_LOG_E(TAG, "Failed to send HTTP request for messages");
         FURI_LOG_E(TAG, "Failed to send HTTP request for messages");
         fhttp.state = ISSUE;
         fhttp.state = ISSUE;
         return false;
         return false;
@@ -158,6 +156,11 @@ bool flip_social_get_messages_with_user() {
         FURI_LOG_E(TAG, "Username is NULL");
         FURI_LOG_E(TAG, "Username is NULL");
         return false;
         return false;
     }
     }
+    if(!flip_social_message_users->usernames[flip_social_message_users->index] ||
+       strlen(flip_social_message_users->usernames[flip_social_message_users->index]) == 0) {
+        FURI_LOG_E(TAG, "Username is NULL");
+        return false;
+    }
     char command[128];
     char command[128];
     snprintf(
     snprintf(
         fhttp.file_path,
         fhttp.file_path,
@@ -165,16 +168,14 @@ bool flip_social_get_messages_with_user() {
         STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/messages.txt");
         STORAGE_EXT_PATH_PREFIX "/apps_data/flip_social/messages.txt");
 
 
     fhttp.save_received_data = true;
     fhttp.save_received_data = true;
-    char* headers = jsmn("Content-Type", "application/json");
+    auth_headers_alloc();
     snprintf(
     snprintf(
         command,
         command,
         128,
         128,
         "https://www.flipsocial.net/api/messages/%s/get/%s/",
         "https://www.flipsocial.net/api/messages/%s/get/%s/",
         app_instance->login_username_logged_out,
         app_instance->login_username_logged_out,
         flip_social_message_users->usernames[flip_social_message_users->index]);
         flip_social_message_users->usernames[flip_social_message_users->index]);
-    bool success = flipper_http_get_request_with_headers(command, headers);
-    free(headers);
-    if(!success) {
+    if(!flipper_http_get_request_with_headers(command, auth_headers)) {
         FURI_LOG_E(TAG, "Failed to send HTTP request for messages");
         FURI_LOG_E(TAG, "Failed to send HTTP request for messages");
         fhttp.state = ISSUE;
         fhttp.state = ISSUE;
         return false;
         return false;