Browse Source

[http_server]fix load log (lock_buf)

balbekova 5 năm trước cách đây
mục cha
commit
4ce3cb3da5
1 tập tin đã thay đổi với 35 bổ sung19 xóa
  1. 35 19
      modules/HTTP_Server/http_server.c

+ 35 - 19
modules/HTTP_Server/http_server.c

@@ -160,28 +160,30 @@ typedef struct {
 
 web_func_handler_t process_web_funcs[] = {
 #ifdef HTTP_AUTH_ENABLE
-    { "POST /login.cgi",            15,   COMMON_ANSWER,        ALL_ACCESS,   HTTP_LoginPage },
-    { "GET /logout.cgi",            15,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_LogoutPage },
-    { "GET /changepwd.cgi",         18,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_ChangeUserPwd },
+    { "POST /login.cgi",                15,   COMMON_ANSWER,        ALL_ACCESS,   HTTP_LoginPage },
+    { "GET /logout.cgi",                15,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_LogoutPage },
+    { "GET /changepwd.cgi",             18,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_ChangeUserPwd },
 #endif
-    { "GET /getJson.cgi",           16,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_GetParamsPage },
-    { "GET /settings.cgi",          17,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_GetSettingsPage },
-    { "POST /settings.cgi",         18,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_SetSettingsPage },
+    { "GET /getJson.cgi",               16,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_GetParamsPage },
+    { "GET /settings.cgi",              17,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_GetSettingsPage },
+    { "POST /settings.cgi",             18,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_SetSettingsPage },
 #ifdef NOTIFICATION_CONTROL_ENABLE
-    { "GET /snmp.cgi",              13,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_SnmpParam },
+    { "GET /snmp.cgi",                  13,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_SnmpParam },
 #endif
-    { "GET /info.cgi",              13,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_GetInfo },
-    { "POST /info.cgi",             14,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_SetInfoPage },
-    { "GET /history.cgi",           16,   HISTORY_ANSWER,       TIME_ACCESS,  HTTP_HistoryPage },
-    { "GET /ups_history.cgi",       19,   UPS_HISTORY_ANSWER,   TIME_ACCESS,  HTTP_UpsHistoryPage },
-    { "GET /reset.cgi",             14,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_Reset },
-    { "GET /bat_test.cgi",          17,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_UPSTest },
-    { "GET /ups_power.cgi",         18,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_UPSshutdown },
-    { "GET /reboot.cgi",            15,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_Reboot },
-    { "GET /confirm.cgi",           16,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_Confirm },
-    { "GET /fw_update.cgi",         18,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_ConfirmBootPwd },
-    { "GET",                        3,    COMMON_ANSWER,        ALL_ACCESS,   HTTP_GetRequest },
-    { "",                           0,    COMMON_ANSWER,        ALL_ACCESS,   HTTP_NoFound },
+    { "GET /info.cgi",                  13,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_GetInfo },
+    { "POST /info.cgi",                 14,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_SetInfoPage },
+    { "GET /history.cgi?page=all",      25,   HISTORY_ANSWER,       TIME_ACCESS,  HTTP_HistoryPage },
+    { "GET /history.cgi",               16,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_HistoryPage },
+    { "GET /ups_history.cgi?page=all",  29,   UPS_HISTORY_ANSWER,   TIME_ACCESS,  HTTP_UpsHistoryPage },
+    { "GET /ups_history.cgi",           20,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_UpsHistoryPage },
+    { "GET /reset.cgi",                 14,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_Reset },
+    { "GET /bat_test.cgi",              17,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_UPSTest },
+    { "GET /ups_power.cgi",             18,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_UPSshutdown },
+    { "GET /reboot.cgi",                15,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_Reboot },
+    { "GET /confirm.cgi",               16,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_Confirm },
+    { "GET /fw_update.cgi",             18,   COMMON_ANSWER,        TIME_ACCESS,  HTTP_ConfirmBootPwd },
+    { "GET",                            3,    COMMON_ANSWER,        ALL_ACCESS,   HTTP_GetRequest },
+    { "",                               0,    COMMON_ANSWER,        ALL_ACCESS,   HTTP_NoFound },
     { "", 0, 0, 0, NULL }
 };
 
@@ -419,6 +421,12 @@ static err_t http_sent_history(void *arg, struct tcp_pcb *pcb, u16_t len)
     if (hs->left > 0) {
         send_data(pcb, hs);
     } else {
+        /* Release previously used send buffer to use 
+        * separate file transfer buffer (logFileBuf) */
+        if (hs->locked != 0) {
+            unlock_buf(hs->locked);
+        }
+
         memset(logFileBuf, 0, FILE_BUF_MAX_LEN);
         if (log_ptr + FILE_BUF_MAX_LEN <= log_size) {
             nbytes = History_GetData(log_ptr, logFileBuf, FILE_BUF_MAX_LEN, start);
@@ -465,6 +473,12 @@ static err_t http_sent_log(void *arg, struct tcp_pcb *pcb, u16_t len)
     if (hs->left > 0) {
         send_data(pcb, hs);
     } else {
+        /* Release previously used send buffer to use 
+        * separate file transfer buffer (logFileBuf) */
+        if (hs->locked != 0) {
+            unlock_buf(hs->locked);
+        }
+
         memset(logFileBuf, 0, FILE_BUF_MAX_LEN);
         if (log_ptr + FILE_BUF_MAX_LEN_LOG <= log_size) {
             nbytes = LOG_GetData(log_ptr, logFileBuf, FILE_BUF_MAX_LEN_LOG, start);
@@ -635,6 +649,8 @@ static err_t http_accept(void *arg, struct tcp_pcb *pcb, err_t err)
     /* Initialize the structure. */
     hs->file = NULL;
     hs->left = 0;
+    hs->reqnum = 0;
+    hs->locked = NULL;
 
     /* Tell TCP that this is the structure we wish to be passed for our
        callbacks. */