static void esif_ws_http_process_get_or_post ( char *buffer, int fd, ssize_t ret ) { char *blankCharPtr0 = NULL; char *blankCharPtr1 = NULL; char *questMarkCharPtr = NULL; char resource[100]; char *fileName; char *method; char *fileType = NULL; int result = 0; #ifdef ESIF_ATTR_OS_WINDOWS char *str; #endif if (!strncmp(buffer, "GET ", 4)) { method = "GET"; } else { method = "POST"; } blankCharPtr0 = strchr(buffer, ' '); blankCharPtr0++; blankCharPtr1 = strchr(blankCharPtr0, ' '); questMarkCharPtr = strchr(blankCharPtr0, '?'); /* special case */ if (questMarkCharPtr && questMarkCharPtr < blankCharPtr1) { // resource = (char *)esif_ccb_malloc(questMarkCharPtr - blankCharPtr0 ); if (!strcmp(method, "GET")) { esif_ccb_memcpy(resource, buffer + 4, questMarkCharPtr - blankCharPtr0); } else { esif_ccb_memcpy(resource, buffer + 5, questMarkCharPtr - blankCharPtr0); } resource[questMarkCharPtr - blankCharPtr0] = 0; } else { // resource = (char *)esif_ccb_malloc(blankCharPtr1 - blankCharPtr0); if (!strcmp(method, "GET")) { esif_ccb_memcpy(resource, buffer + 4, blankCharPtr1 - blankCharPtr0); } else { esif_ccb_memcpy(resource, buffer + 5, blankCharPtr1 - blankCharPtr0); } resource[blankCharPtr1 - blankCharPtr0] = 0; } printf("resource b4: %s\n", resource); if (resource[1] == '\0') { printf("empty resource: %s\n", resource); result = esif_ws_http_server_static_pages(buffer, "index.html", fd, ret, "text/html"); if (result > 0) { esif_ws_http_send_error_code(fd, result); } return; } fileName = &resource[1]; // resource++; #ifdef ESIF_ATTR_OS_WINDOWS do { str = strchr(resource, '/'); if (str) { str[0] = '\\'; } } while (str != NULL); // printf("str: %s\n", str); #endif fileType = esif_ws_http_get_file_type(fileName); if (NULL != fileType) { result = esif_ws_http_server_static_pages(buffer, fileName, fd, ret, fileType); if (result > 0) { esif_ws_http_send_error_code(fd, result); } } else { printf("File type is not valid\n"); } esif_ws_http_send_error_code(fd, result); result = result; }
static void esif_ws_http_process_request ( ClientRecordPtr connection, char *buffer, ssize_t ret ) { char *blankCharPtr0 = NULL; char *blankCharPtr1 = NULL; char *questMarkCharPtr = NULL; char resource[100]={0}; char *fileName=NULL; char *method=NULL; char *fileType = NULL; int result = 0; #ifdef ESIF_ATTR_OS_WINDOWS char *str=NULL; #endif if (!strncmp(buffer, "GET ", 4)) { method = "GET"; } else { method = "POST"; } blankCharPtr0 = strchr(buffer, ' '); blankCharPtr0++; blankCharPtr1 = strchr(blankCharPtr0, ' '); questMarkCharPtr = strchr(blankCharPtr0, '?'); /* special case */ if (questMarkCharPtr && questMarkCharPtr < blankCharPtr1) { // resource = (char *)esif_ccb_malloc(questMarkCharPtr - blankCharPtr0 ); if (!strcmp(method, "GET")) { esif_ccb_memcpy(resource, buffer + 4, questMarkCharPtr - blankCharPtr0); } else { esif_ccb_memcpy(resource, buffer + 5, questMarkCharPtr - blankCharPtr0); } resource[questMarkCharPtr - blankCharPtr0] = 0; } else { // resource = (char *)esif_ccb_malloc(blankCharPtr1 - blankCharPtr0); if (!strcmp(method, "GET")) { esif_ccb_memcpy(resource, buffer + 4, blankCharPtr1 - blankCharPtr0); } else { esif_ccb_memcpy(resource, buffer + 5, blankCharPtr1 - blankCharPtr0); } resource[blankCharPtr1 - blankCharPtr0] = 0; } ESIF_TRACE_DEBUG("resource b4: %s\n", resource); if (resource[1] == '\0') { ESIF_TRACE_DEBUG("empty resource: %s\n", resource); result = esif_ws_http_process_static_pages(connection, buffer, "index.html", ret, "text/html"); if (result > 0) { esif_ws_http_send_error_code(connection, result); } return; } fileName = &resource[1]; // resource++; #ifdef ESIF_ATTR_OS_WINDOWS do { str = strchr(resource, '/'); if (str) { str[0] = '\\'; } } while (str != NULL); // ESIF_TRACE_DEBUG("str: %s\n", str); #endif fileType = esif_ws_http_get_file_type(fileName); if (NULL == fileType) { fileType = UNKNOWN_MIME_TYPE; } result = esif_ws_http_process_static_pages(connection, buffer, fileName, ret, fileType); if (result > 0) { esif_ws_http_send_error_code(connection, result); } }