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

FlipSocial - v0.6.2

- added bearer auth
- FlipperHTTP edit by Will-JL
jblanked 1 год назад
Родитель
Сommit
66517d129f

+ 2 - 0
alloc/flip_social_alloc.c

@@ -520,6 +520,8 @@ FlipSocialApp *flip_social_app_alloc()
             app->wifi_ssid_logged_out_temp_buffer[app->wifi_ssid_logged_in_temp_buffer_size - 1] = '\0';
             app->wifi_ssid_logged_out_temp_buffer[app->wifi_ssid_logged_in_temp_buffer_size - 1] = '\0';
         }
         }
 
 
+        auth_headers_alloc();
+
         // set variable item text (ommit the passwords)
         // set variable item text (ommit the passwords)
         variable_item_set_current_value_text(app->variable_item_logged_in_wifi_settings_ssid, app->wifi_ssid_logged_in);
         variable_item_set_current_value_text(app->variable_item_logged_in_wifi_settings_ssid, app->wifi_ssid_logged_in);
         variable_item_set_current_value_text(app->variable_item_logged_out_wifi_settings_ssid, app->wifi_ssid_logged_out);
         variable_item_set_current_value_text(app->variable_item_logged_out_wifi_settings_ssid, app->wifi_ssid_logged_out);

+ 34 - 24
draw/flip_social_draw.c

@@ -155,12 +155,24 @@ 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 = furi_pubsub_subscribe(app_instance->input_event_queue, on_input, NULL);
         app_instance->input_event = 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);
@@ -184,17 +196,20 @@ void flip_social_callback_draw_compose(Canvas *canvas, void *model)
         // 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(command, sizeof(command), "{\"username\":\"%s\",\"content\":\"%s\"}",
             snprintf(command, sizeof(command), "{\"username\":\"%s\",\"content\":\"%s\"}",
                      app_instance->login_username_logged_in, selected_message);
                      app_instance->login_username_logged_in, 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;
@@ -209,24 +224,13 @@ 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);
@@ -411,6 +415,7 @@ void flip_social_callback_draw_feed(Canvas *canvas, void *model)
         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 = furi_pubsub_subscribe(app_instance->input_event_queue, on_input, NULL);
         app_instance->input_event = furi_pubsub_subscribe(app_instance->input_event_queue, on_input, NULL);
+        auth_headers_alloc();
     }
     }
 
 
     // handle action
     // handle action
@@ -460,7 +465,7 @@ void flip_social_callback_draw_feed(Canvas *canvas, void *model)
         }
         }
         char payload[256];
         char payload[256];
         snprintf(payload, sizeof(payload), "{\"username\":\"%s\",\"post_id\":\"%u\"}", app_instance->login_username_logged_in, flip_social_feed->ids[flip_social_feed->index]);
         snprintf(payload, sizeof(payload), "{\"username\":\"%s\",\"post_id\":\"%u\"}", app_instance->login_username_logged_in, flip_social_feed->ids[flip_social_feed->index]);
-        flipper_http_post_request_with_headers("https://www.flipsocial.net/api/feed/flip/", "{\"Content-Type\":\"application/json\"}", payload);
+        flipper_http_post_request_with_headers("https://www.flipsocial.net/api/feed/flip/", auth_headers, payload);
         flip_social_canvas_draw_message(canvas, flip_social_feed->usernames[flip_social_feed->index], flip_social_feed->messages[flip_social_feed->index], flip_social_feed->is_flipped[flip_social_feed->index], flip_social_feed->index > 0, flip_social_feed->index < flip_social_feed->count - 1, flip_social_feed->flips[flip_social_feed->index]);
         flip_social_canvas_draw_message(canvas, flip_social_feed->usernames[flip_social_feed->index], flip_social_feed->messages[flip_social_feed->index], flip_social_feed->is_flipped[flip_social_feed->index], flip_social_feed->index > 0, flip_social_feed->index < flip_social_feed->count - 1, flip_social_feed->flips[flip_social_feed->index]);
         action = ActionNone;
         action = ActionNone;
         break;
         break;
@@ -522,7 +527,7 @@ void flip_social_callback_draw_login(Canvas *canvas, void *model)
 
 
         char buffer[256];
         char buffer[256];
         snprintf(buffer, sizeof(buffer), "{\"username\":\"%s\",\"password\":\"%s\"}", app_instance->login_username_logged_out, app_instance->login_password_logged_out);
         snprintf(buffer, sizeof(buffer), "{\"username\":\"%s\",\"password\":\"%s\"}", app_instance->login_username_logged_out, app_instance->login_password_logged_out);
-        flip_social_login_success = flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/login/", "{\"Content-Type\":\"application/json\"}", buffer);
+        flip_social_login_success = flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/login/", buffer, buffer);
         if (flip_social_login_success)
         if (flip_social_login_success)
         {
         {
             fhttp.state = RECEIVING;
             fhttp.state = RECEIVING;
@@ -687,6 +692,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(app_instance->wifi_ssid_logged_out, app_instance->wifi_password_logged_out, app_instance->login_username_logged_out, app_instance->login_username_logged_in, app_instance->login_password_logged_out, app_instance->change_password_logged_in, app_instance->is_logged_in);
                 save_settings(app_instance->wifi_ssid_logged_out, app_instance->wifi_password_logged_out, app_instance->login_username_logged_out, app_instance->login_username_logged_in, app_instance->login_password_logged_out, app_instance->change_password_logged_in, app_instance->is_logged_in);
 
 
@@ -768,6 +776,7 @@ void flip_social_callback_draw_explore(Canvas *canvas, void *model)
         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 = furi_pubsub_subscribe(app_instance->input_event_queue, on_input, NULL);
         app_instance->input_event = furi_pubsub_subscribe(app_instance->input_event_queue, on_input, NULL);
+        auth_headers_alloc();
     }
     }
     flip_social_canvas_draw_explore(canvas, flip_social_explore->usernames[flip_social_explore->index], last_explore_response);
     flip_social_canvas_draw_explore(canvas, flip_social_explore->usernames[flip_social_explore->index], last_explore_response);
 
 
@@ -778,7 +787,7 @@ void flip_social_callback_draw_explore(Canvas *canvas, void *model)
         // add friend
         // add friend
         char add_payload[128];
         char add_payload[128];
         snprintf(add_payload, sizeof(add_payload), "{\"username\":\"%s\",\"friend\":\"%s\"}", app_instance->login_username_logged_in, flip_social_explore->usernames[flip_social_explore->index]);
         snprintf(add_payload, sizeof(add_payload), "{\"username\":\"%s\",\"friend\":\"%s\"}", app_instance->login_username_logged_in, flip_social_explore->usernames[flip_social_explore->index]);
-        flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/add-friend/", "{\"Content-Type\":\"application/json\"}", add_payload);
+        flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/add-friend/", auth_headers, add_payload);
         canvas_clear(canvas);
         canvas_clear(canvas);
         flip_social_canvas_draw_explore(canvas, flip_social_explore->usernames[flip_social_explore->index], "Added!");
         flip_social_canvas_draw_explore(canvas, flip_social_explore->usernames[flip_social_explore->index], "Added!");
         action = ActionNone;
         action = ActionNone;
@@ -787,7 +796,7 @@ void flip_social_callback_draw_explore(Canvas *canvas, void *model)
         // remove friend
         // remove friend
         char remove_payload[128];
         char remove_payload[128];
         snprintf(remove_payload, sizeof(remove_payload), "{\"username\":\"%s\",\"friend\":\"%s\"}", app_instance->login_username_logged_in, flip_social_explore->usernames[flip_social_explore->index]);
         snprintf(remove_payload, sizeof(remove_payload), "{\"username\":\"%s\",\"friend\":\"%s\"}", app_instance->login_username_logged_in, flip_social_explore->usernames[flip_social_explore->index]);
-        flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/remove-friend/", "{\"Content-Type\":\"application/json\"}", remove_payload);
+        flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/remove-friend/", auth_headers, remove_payload);
         canvas_clear(canvas);
         canvas_clear(canvas);
         flip_social_canvas_draw_explore(canvas, flip_social_explore->usernames[flip_social_explore->index], "Removed!");
         flip_social_canvas_draw_explore(canvas, flip_social_explore->usernames[flip_social_explore->index], "Removed!");
         action = ActionNone;
         action = ActionNone;
@@ -833,6 +842,7 @@ void flip_social_callback_draw_friends(Canvas *canvas, void *model)
         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 = furi_pubsub_subscribe(app_instance->input_event_queue, on_input, NULL);
         app_instance->input_event = furi_pubsub_subscribe(app_instance->input_event_queue, on_input, NULL);
+        auth_headers_alloc();
     }
     }
     flip_social_canvas_draw_explore(canvas, flip_social_friends->usernames[flip_social_friends->index], last_explore_response);
     flip_social_canvas_draw_explore(canvas, flip_social_friends->usernames[flip_social_friends->index], last_explore_response);
 
 
@@ -843,7 +853,7 @@ void flip_social_callback_draw_friends(Canvas *canvas, void *model)
         // add friend
         // add friend
         char add_payload[128];
         char add_payload[128];
         snprintf(add_payload, sizeof(add_payload), "{\"username\":\"%s\",\"friend\":\"%s\"}", app_instance->login_username_logged_in, flip_social_friends->usernames[flip_social_friends->index]);
         snprintf(add_payload, sizeof(add_payload), "{\"username\":\"%s\",\"friend\":\"%s\"}", app_instance->login_username_logged_in, flip_social_friends->usernames[flip_social_friends->index]);
-        if (flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/add-friend/", "{\"Content-Type\":\"application/json\"}", add_payload))
+        if (flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/add-friend/", auth_headers, add_payload))
         {
         {
             canvas_clear(canvas);
             canvas_clear(canvas);
             flip_social_canvas_draw_explore(canvas, flip_social_friends->usernames[flip_social_friends->index], "Added!");
             flip_social_canvas_draw_explore(canvas, flip_social_friends->usernames[flip_social_friends->index], "Added!");
@@ -862,7 +872,7 @@ void flip_social_callback_draw_friends(Canvas *canvas, void *model)
         // remove friend
         // remove friend
         char remove_payload[128];
         char remove_payload[128];
         snprintf(remove_payload, sizeof(remove_payload), "{\"username\":\"%s\",\"friend\":\"%s\"}", app_instance->login_username_logged_in, flip_social_friends->usernames[flip_social_friends->index]);
         snprintf(remove_payload, sizeof(remove_payload), "{\"username\":\"%s\",\"friend\":\"%s\"}", app_instance->login_username_logged_in, flip_social_friends->usernames[flip_social_friends->index]);
-        if (flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/remove-friend/", "{\"Content-Type\":\"application/json\"}", remove_payload))
+        if (flipper_http_post_request_with_headers("https://www.flipsocial.net/api/user/remove-friend/", auth_headers, remove_payload))
         {
         {
             canvas_clear(canvas);
             canvas_clear(canvas);
             flip_social_canvas_draw_explore(canvas, flip_social_friends->usernames[flip_social_friends->index], "Removed!");
             flip_social_canvas_draw_explore(canvas, flip_social_friends->usernames[flip_social_friends->index], "Removed!");

+ 2 - 5
explore/flip_social_explore.c

@@ -50,11 +50,8 @@ 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;

+ 9 - 6
feed/flip_social_feed.c

@@ -111,24 +111,27 @@ 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");
-    snprintf(command, 128, "https://www.flipsocial.net/api/feed/40/%s/extended/", app_instance->login_username_logged_out);
-    bool success = flipper_http_get_request_with_headers(command, headers);
-    free(headers);
-    if (!success)
+    auth_headers_alloc();
+    char command[96];
+    snprintf(command, 96, "https://www.flipsocial.net/api/feed/40/%s/extended/", app_instance->login_username_logged_out);
+    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;

+ 27 - 0
flip_social.c

@@ -18,6 +18,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.
@@ -284,6 +286,10 @@ void flip_social_app_free(FlipSocialApp *app)
         free(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);
@@ -294,4 +300,25 @@ void flip_social_app_free(FlipSocialApp *app)
     // Free the app structure
     // Free the app structure
     if (app_instance)
     if (app_instance)
         free(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.h

@@ -293,5 +293,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

+ 80 - 53
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(
@@ -147,14 +148,15 @@ 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)
         if (events & WorkerEvtStop)
+        {
             break;
             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
@@ -210,45 +212,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
@@ -473,14 +436,14 @@ 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)
+    if (send_length > 512)
     { // Ensure buffer size is sufficient
     { // 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
 
 
@@ -496,7 +459,7 @@ bool flipper_http_send_data(const char *data)
     furi_hal_serial_tx(fhttp.serial_handle, (const uint8_t *)send_buffer, send_length);
     furi_hal_serial_tx(fhttp.serial_handle, (const uint8_t *)send_buffer, send_length);
 
 
     // Uncomment below line to log the data sent over UART
     // Uncomment below line to log the data sent over UART
-    // FURI_LOG_I("FlipperHTTP", "Sent data over UART: %s", send_buffer);
+    FURI_LOG_I("FlipperHTTP", "Sent data over UART: %s", send_buffer);
     fhttp.state = IDLE;
     fhttp.state = IDLE;
     return true;
     return true;
 }
 }
@@ -799,7 +762,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))
     {
     {
@@ -835,7 +798,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))
@@ -871,7 +834,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))
@@ -913,7 +876,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),
@@ -956,7 +919,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),
@@ -1111,7 +1074,7 @@ void flipper_http_rx_callback(const char *line, void *context)
     }
     }
 
 
     // Uncomment below line to log the data received over UART
     // Uncomment below line to log the data received over UART
-    // FURI_LOG_I(HTTP_TAG, "Received UART line: %s", line);
+    FURI_LOG_I(HTTP_TAG, "Received UART line: %s", line);
 
 
     // Check if we've started receiving data from a GET request
     // Check if we've started receiving data from a GET request
     if (fhttp.started_receiving_get)
     if (fhttp.started_receiving_get)
@@ -1128,8 +1091,39 @@ 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;
         }
         }
 
 
@@ -1167,8 +1161,39 @@ 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;
         }
         }
 
 
@@ -1291,6 +1316,7 @@ 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;
+        file_buffer_len = 0;
         return;
         return;
     }
     }
     else if (strstr(line, "[POST/SUCCESS]") != NULL)
     else if (strstr(line, "[POST/SUCCESS]") != NULL)
@@ -1301,6 +1327,7 @@ 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;
+        file_buffer_len = 0;
         return;
         return;
     }
     }
     else if (strstr(line, "[PUT/SUCCESS]") != NULL)
     else if (strstr(line, "[PUT/SUCCESS]") != NULL)

+ 1 - 0
flipper_http/flipper_http.h

@@ -82,6 +82,7 @@ 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
friends/flip_social_friends.c

@@ -47,13 +47,12 @@ 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(url, 100, "https://www.flipsocial.net/api/user/friends/%s/", app_instance->login_username_logged_in);
     snprintf(url, 100, "https://www.flipsocial.net/api/user/friends/%s/", 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;

+ 4 - 8
messages/flip_social_messages.c

@@ -151,11 +151,9 @@ 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(command, 128, "https://www.flipsocial.net/api/messages/%s/get/list/", app_instance->login_username_logged_out);
     snprintf(command, 128, "https://www.flipsocial.net/api/messages/%s/get/list/", 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;
@@ -180,11 +178,9 @@ 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(command, 128, "https://www.flipsocial.net/api/messages/%s/get/%s/", app_instance->login_username_logged_out, flip_social_message_users->usernames[flip_social_message_users->index]);
     snprintf(command, 128, "https://www.flipsocial.net/api/messages/%s/get/%s/", app_instance->login_username_logged_out, 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;