Переглянути джерело

Закончил портирование старой версии веба

TelenkovDmitry 7 роки тому
батько
коміт
c8bc44b9a0
3 змінених файлів з 112 додано та 22 видалено
  1. 108 22
      modules/HTTP_Server/http_server.c
  2. 3 0
      modules/HTTP_Server/http_server.h
  3. 1 0
      user/init_task.c

+ 108 - 22
modules/HTTP_Server/http_server.c

@@ -2223,7 +2223,7 @@ void ssl_server(void *pvParameters)
         //printf("\n\r <= Read from client :");
         do
         {
-            len = sizeof(buf) - 1;
+            receivedBufLen = RECIVE_BUF_MAX_LEN - 1;
             memset(receiveBuf, 0, RECIVE_BUF_MAX_LEN);
 
             // Read decrypted application data 
@@ -2245,12 +2245,12 @@ void ssl_server(void *pvParameters)
                 break;
 
                 default:
-                    printf("\n\r ssl_read returned %d\n", ret);
+                    //printf("\n\r ssl_read returned %d\n", ret);
                 break;
                 }
                 break;
             }
-            len = ret;
+            receivedBufLen = ret;
             // Display the length of read data 
             //printf("\n\r Successfully read %d bytes from client \n\r",len);
         }while(0);
@@ -2387,7 +2387,7 @@ void ssl_server(void *pvParameters)
                 }
                 else 
                 {
-                    printf("Too long POST request!\r\n");
+                    //printf("Too long POST request!\r\n");
                     /* Ignore request */
                     post_data_count = 0;
                     log_post_reqn = 0;
@@ -2538,18 +2538,16 @@ void ssl_server(void *pvParameters)
 
                 if (res == SEND_REQUIRED_FILE)
                 {
-                    hs->file = sendBuf;
-                    hs->left = sendBufLoadLen;
-                    send_data(pcb, hs);
-                    tcp_sent(pcb, http_sent_history);
-                    tcp_err(pcb, http_sent_log_err);
+                    ssl_sendframes(&ssl, sendBuf, sendBufLoadLen);
+                    
+                    //send_data(pcb, hs);
+                    //tcp_sent(pcb, http_sent_history);
+                    HTTP_SendHistory();
+                    //tcp_err(pcb, http_sent_log_err);
                 }
                 else if (res == SEND_REQUIRED_YES) 
                 {
-                    hs->file = sendBuf;
-                    hs->left = sendBufLoadLen;
-                    send_data(pcb, hs);
-                    tcp_sent(pcb, http_sent);
+                    ssl_sendframes(&ssl, sendBuf, sendBufLoadLen);
                 }
             }
             else if (strncmp(receiveBuf, "GET /ups_history.cgi", 19) == 0)
@@ -2560,18 +2558,16 @@ void ssl_server(void *pvParameters)
 
                 if (res == SEND_REQUIRED_FILE)
                 {
-                    hs->file = sendBuf;
-                    hs->left = sendBufLoadLen;
-                    send_data(pcb, hs);
-                    tcp_sent(pcb, http_sent_log);
-                    tcp_err(pcb, http_sent_log_err);
+                    ssl_sendframes(&ssl, sendBuf, sendBufLoadLen);
+                    
+                    //send_data(pcb, hs);
+                    //tcp_sent(pcb, http_sent_log);
+                    HTTP_SendLog();
+                    //tcp_err(pcb, http_sent_log_err);
                 }
                 else if (res == SEND_REQUIRED_YES) 
                 {
-                    hs->file = sendBuf;
-                    hs->left = sendBufLoadLen;
-                    send_data(pcb, hs);
-                    tcp_sent(pcb, http_sent);
+                    ssl_sendframes(&ssl, sendBuf, sendBufLoadLen);
                 }
             }
             /* Тест  АКБ ИБП */
@@ -2881,3 +2877,93 @@ int RandVal(void* arg)
 {
   return (int)GetRandomNumber();
 }
+
+/**
+  * @brief Send callback for log file transfer (messages as is, not ordered)
+  */
+void HTTP_SendHistory(void)
+{
+    uint32_t nbytes = 0;
+    static bool start = true;
+
+    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);
+    }
+    else if (log_ptr < log_size) {
+        nbytes = History_GetData(log_ptr, logFileBuf, (log_size - log_ptr), start);
+    }
+    else {
+        nbytes = 0;
+    }
+    log_ptr += nbytes;
+
+    start = false;
+    
+    if (nbytes == 0) {
+        // File transfer finished. 
+        start = true;
+        // Clear file transfer in progress flag 
+        fLogTransInprog = false;
+        return;
+    }
+
+    ssl_sendframes(&ssl, logFileBuf, nbytes);
+    HTTP_SendHistory();
+}
+
+
+/**
+  * @brief Sent callback for log file transfer (messages as is, not ordered)
+  */
+void HTTP_SendLog(void)
+{
+    uint32_t nbytes = 0;
+    static bool start = true;
+
+	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);
+    }
+    else if (log_ptr < log_size) {
+        nbytes = LOG_GetData(log_ptr, logFileBuf, (log_size - log_ptr), start);
+    }
+    else {
+        nbytes = 0;
+    }
+    log_ptr += nbytes;
+
+    start = false;
+    if (nbytes == 0) {
+        // File transfer finished. 
+        start = true;
+        // Clear file transfer in progress flag 
+        fLogTransInprog = false;
+        return;
+    }
+
+    ssl_sendframes(&ssl, logFileBuf, nbytes);
+    HTTP_SendLog();
+  
+    return;
+}
+
+/**
+  * @brief  Initialize the HTTPS server (start its thread) 
+  */
+void HTTPS_Init()
+{
+	char buf[MAX_WEB_COOKIE_LEN];
+	uint8_t user_id;
+    
+    for (user_id = 0; user_id < MAX_WEB_USERS; user_id++) {
+        // Flush user cookie by random value 
+        sprintf(buf, "%X", (unsigned int)GetRandomNumber());
+        HTTP_SetUserCookie(buf, user_id);
+
+        // Create user logout timers 
+        users[user_id].LogoutTimer =
+             xTimerCreate("LogoutTmr", WEB_LOGOUT_TIME, pdFALSE, ( void * ) user_id, LogoutTimerCallback);
+    }
+}

+ 3 - 0
modules/HTTP_Server/http_server.h

@@ -148,6 +148,9 @@ void ssl_server(void *pvParameters);
 void ssl_DynPage(ssl_context *ssl);
 void ssl_sendframes(ssl_context *ssl, char *data, int datalen);
 int RandVal(void* arg);
+void HTTP_SendHistory(void);
+void HTTP_SendLog(void);
+void HTTPS_Init();
 
 #ifdef __cplusplus
 }

+ 1 - 0
user/init_task.c

@@ -138,6 +138,7 @@ void InitTask(void *params)
   
 #ifdef WEB_SERVER_ENABLE
   //HTTP_Init();
+  HTTPS_Init();
 #define SSL_TASK_PRIO   ( configMAX_PRIORITIES - 3 )
   xTaskCreate(ssl_server, "SSL", 10*configMINIMAL_STACK_SIZE, NULL, SSL_TASK_PRIO, NULL); 
 #endif