Ver Fonte

UTF8_BOM

balbekova há 7 anos atrás
pai
commit
61cb527aa1
1 ficheiros alterados com 6 adições e 4 exclusões
  1. 6 4
      modules/HTTP_Server/http_server.c

+ 6 - 4
modules/HTTP_Server/http_server.c

@@ -93,6 +93,8 @@ static const char Content_Length[17] =
 {0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x4c, 0x65, 0x6e, 0x67,0x74, 0x68, 0x3a, 0x20, };
 
 const char HTTP_200_OK[] = "HTTP/1.1 200 OK\r\n\r\n";
+/* utf-8 marker to support MS Excel */
+const char UTF8_BOM[] = {0xEF, 0xBB, 0xBF, 0x00};
 
 unsigned long log_ptr = 0;
 unsigned long log_size = 0;
@@ -1068,8 +1070,8 @@ int HTTP_HistoryPage(char *bufIn, char *bufOut, uint16_t lenBufIn, uint16_t *len
         // Send log as raw data
         log_ptr = 0;
 
-        log_size = History_GetTotalSTRCount() * STRING_SIZE_HISTORY;
-        sprintf(bufOut, "HTTP/1.1 200 OK\r\nContent-Length:%lu\r\n\r\n", log_size);
+        log_size = History_GetTotalSTRCount() * STRING_SIZE_HISTORY + sizeof(UTF8_BOM)-1;
+        sprintf(bufOut, "HTTP/1.1 200 OK\r\nContent-Length:%lu\r\n\r\n%s", log_size, UTF8_BOM);
 
         *lenBufOut = strlen(bufOut);
 
@@ -1122,8 +1124,8 @@ int HTTP_UpsHistoryPage(char *bufIn, char *bufOut, uint16_t lenBufIn, uint16_t *
         // Send log as raw data
         log_ptr = 0;
 
-        log_size = LOG_GetTotalSTRCount() * STRING_SIZE;
-        sprintf(bufOut, "HTTP/1.1 200 OK\r\nContent-Length:%lu\r\n\r\n", log_size);
+        log_size = LOG_GetTotalSTRCount() * STRING_SIZE + sizeof(UTF8_BOM)-1;
+        sprintf(bufOut, "HTTP/1.1 200 OK\r\nContent-Length:%lu\r\n\r\n%s", log_size, UTF8_BOM);
 
         *lenBufOut = strlen(bufOut);