balbekova преди 7 години
родител
ревизия
0b4c2f366f
променени са 1 файла, в които са добавени 27 реда и са изтрити 4 реда
  1. 27 4
      modules/HTTP_Server/http_server.c

+ 27 - 4
modules/HTTP_Server/http_server.c

@@ -48,7 +48,7 @@ static void HTTP_ForceUserLogout(uint8_t user_id);
 void LogoutTimerCallback(TimerHandle_t pxTimer);
 void LoginTimerCallback(TimerHandle_t pxTimer);
 int HTTP_ChangeUserPwd(char *bufIn, char *bufOut, uint16_t lenBufIn, uint16_t *lenBufOut);
-void send_file(char *filename, char *pnonmatch,  struct fs_file *file);
+char* send_file(char *filename, char *pnonmatch,  struct fs_file *file, uint16_t *Len);
 static uint32_t Parse_Header(char *data, uint32_t len, const char *field, uint32_t flen, char *value);
 bool GetFileName(char *inStr, char *fileName, uint8_t *fileNameLen);
 
@@ -1988,7 +1988,7 @@ char* AuthenticatedTrueRoutine(uint16_t* sendLen)
     char *DataOffset;
     char *ptr;
     
-    if (strncmp(receiveBuf, "GET /main.css", 13) == 0) // +
+  /*  if (strncmp(receiveBuf, "GET /main.css", 13) == 0) // +
     {
         fs_open("/main.css", &file);
         *sendLen = file.len;
@@ -2050,7 +2050,7 @@ char* AuthenticatedTrueRoutine(uint16_t* sendLen)
         *sendLen = file.len;
         return file.data;
     }
-    else if (strncmp(receiveBuf, "GET /getJson.cgi", 16) == 0) // +
+    else*/ if (strncmp(receiveBuf, "GET /getJson.cgi", 16) == 0) // +
     {
         HTTP_GetParamsPage1(sendBuf);
         *sendLen = strlen(sendBuf);
@@ -2361,6 +2361,25 @@ char* AuthenticatedTrueRoutine(uint16_t* sendLen)
         HTTP_Prodate(receiveBuf, sendBuf, receivedBufLen, sendLen);
         return sendBuf;
     }
+    /* Check common GET request */
+	  else if (strncmp(receiveBuf, "GET", 3) == 0) {
+		  char filename[MAX_FILENAME_LEN];
+		  char nonmatch[MAX_ETAG_LEN];
+		  char *pnonmatch = NULL;
+		  uint8_t len;
+
+		  if (GetFileName(receiveBuf, filename, &len)) {
+			  HTTP_UpdateUserLoginTime(user_id);
+
+			  /* Parce If-Non_Match value */
+			  uint8_t nonmatch_len = Parse_Header(receiveBuf, receivedBufLen, If_None_Match, 15, nonmatch);
+			  if (nonmatch_len < MAX_ETAG_LEN && nonmatch_len > 0) {
+				  DBG printf("If_None_Match: %s\r\n", nonmatch);
+				  pnonmatch = nonmatch;
+			  }
+			  return send_file(filename, pnonmatch, &file, sendLen);
+		  }
+	  }
     else
     {
         HTTP_UpdateUserLoginTime(user_id);
@@ -2507,7 +2526,7 @@ void HTTP_SendLog(void)
   * @param  file: pointer to a fs_file struct
   * @retval
   */
-void send_file(char *filename, char *pnonmatch,  struct fs_file *file)
+char* send_file(char *filename, char *pnonmatch,  struct fs_file *file, uint16_t *Len)
 {
     int res = 0;
     char etag[MAX_ETAG_LEN];
@@ -2533,6 +2552,8 @@ void send_file(char *filename, char *pnonmatch,  struct fs_file *file)
         /* Send 304 code */
         sprintf(sendBuf, HTTP_304_NOT_MODIFIED);
         DBG printf(sendBuf);
+        *Len = strlen(sendBuf);
+        return sendBuf;
         //hs->file = sendBuf;
         //hs->left = strlen(sendBuf);
     }
@@ -2541,6 +2562,8 @@ void send_file(char *filename, char *pnonmatch,  struct fs_file *file)
         //DBG printf("%s\r\n\r\n", filename);
         //hs->file = file->data;
         //hs->left = file->len;
+    	*Len = file->len;
+    	return file->data;
     }
 
     //send_data(pcb, hs);