Changeset 87044 in vbox for trunk/src/VBox
- Timestamp:
- Dec 4, 2020 5:42:55 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/http-server.cpp
r87042 r87044 768 768 769 769 rc = rtHttpServerSendResponseEx(pClient, RTHTTPSTATUS_OK, &HdrLst); 770 771 RTHttpHeaderListDestroy(HdrLst); 772 773 if (rc == VERR_BROKEN_PIPE) /* Could happen on fast reloads. */ 774 break; 770 775 AssertRCReturn(rc, rc); 771 772 RTHttpHeaderListDestroy(HdrLst);773 776 774 777 size_t cbToRead = fsObj.cbObject; … … 1053 1056 * Needs to be free'd via rtHttpServerReqFree(). 1054 1057 */ 1055 static int rtHttpServerParseRequest(PRTHTTPSERVERCLIENT pClient, c har *pszReq, size_t cbReq,1058 static int rtHttpServerParseRequest(PRTHTTPSERVERCLIENT pClient, const char *pszReq, size_t cbReq, 1056 1059 PRTHTTPSERVERREQ *ppReq) 1057 1060 { … … 1064 1067 AssertReturn(RTStrIsValidEncoding(pszReq), VERR_INVALID_PARAMETER); 1065 1068 1066 char **ppapsz Strings= NULL;1067 size_t c Strings= 0;1068 int rc = RTStrSplit(pszReq, cbReq, RTHTTPSERVER_HTTP11_EOL_STR, &ppapsz Strings, &cStrings);1069 char **ppapszReq = NULL; 1070 size_t cReq = 0; 1071 int rc = RTStrSplit(pszReq, cbReq, RTHTTPSERVER_HTTP11_EOL_STR, &ppapszReq, &cReq); 1069 1072 if (RT_FAILURE(rc)) 1070 1073 return rc; 1071 1074 1072 if (!c Strings)1075 if (!cReq) 1073 1076 return VERR_INVALID_PARAMETER; 1074 1077 1075 /** Advances pszReq to the next string in the current line. 1076 ** @todo Can we do better here? */ 1077 #define REQ_GET_NEXT_STRING \ 1078 pszReq = psz; \ 1079 while (psz && !RT_C_IS_SPACE(*psz)) \ 1080 psz++; \ 1081 if (psz) \ 1082 { \ 1083 *psz = '\0'; \ 1084 psz++; \ 1085 } \ 1086 else /* Be strict for now. */ \ 1087 AssertFailedBreakStmt(rc = VERR_INVALID_PARAMETER); 1078 #ifdef LOG_ENABLED 1079 for (size_t i = 0; i < cReq; i++) 1080 LogFlowFunc(("%s\n", ppapszReq[i])); 1081 #endif 1088 1082 1089 1083 PRTHTTPSERVERREQ pReq = NULL; 1090 1084 1091 for (;;) /* To use break. */ 1092 { 1093 /* Start with the first line. */ 1094 char *psz = ppapszStrings[0]; 1095 AssertPtrBreakStmt(psz, rc = VERR_INVALID_PARAMETER); 1096 1097 /* A tiny bit of sanitation. */ 1098 RTStrStrip(psz); 1099 1085 char **ppapszFirstLine = NULL; 1086 size_t cFirstLine = 0; 1087 rc = RTStrSplit(ppapszReq[0], strlen(ppapszReq[0]), " ", &ppapszFirstLine, &cFirstLine); 1088 if (RT_SUCCESS(rc)) 1089 { 1090 if (cFirstLine < 3) /* At leat the method, path and version has to be present. */ 1091 rc = VERR_INVALID_PARAMETER; 1092 } 1093 1094 while (RT_SUCCESS(rc)) /* To use break. */ 1095 { 1100 1096 pReq = rtHttpServerReqAlloc(); 1101 1097 AssertPtrBreakStmt(pReq, rc = VERR_NO_MEMORY); 1102 1103 REQ_GET_NEXT_STRING1104 1098 1105 1099 /* 1106 1100 * Parse method to use. Method names are case sensitive. 1107 1101 */ 1108 if (!RTStrCmp(pszReq, "GET")) pReq->enmMethod = RTHTTPMETHOD_GET; 1109 else if (!RTStrCmp(pszReq, "HEAD")) pReq->enmMethod = RTHTTPMETHOD_HEAD; 1102 const char *pszMethod = ppapszFirstLine[0]; 1103 if (!RTStrCmp(pszMethod, "GET")) pReq->enmMethod = RTHTTPMETHOD_GET; 1104 else if (!RTStrCmp(pszMethod, "HEAD")) pReq->enmMethod = RTHTTPMETHOD_HEAD; 1110 1105 #ifdef IPRT_HTTP_WITH_WEBDAV 1111 else if (!RTStrCmp(psz Req, "OPTIONS")) pReq->enmMethod = RTHTTPMETHOD_OPTIONS;1112 else if (!RTStrCmp(psz Req, "PROPFIND")) pReq->enmMethod = RTHTTPMETHOD_PROPFIND;1106 else if (!RTStrCmp(pszMethod, "OPTIONS")) pReq->enmMethod = RTHTTPMETHOD_OPTIONS; 1107 else if (!RTStrCmp(pszMethod, "PROPFIND")) pReq->enmMethod = RTHTTPMETHOD_PROPFIND; 1113 1108 #endif 1114 1109 else … … 1118 1113 } 1119 1114 1120 REQ_GET_NEXT_STRING 1121 1115 /* 1116 * Parse requested path. 1117 */ 1122 1118 /** @todo Do URL unescaping here. */ 1123 1124 if (!rtHttpServerPathIsValid(psz Req, false /* fIsAbsolute */))1119 const char *pszPath = ppapszFirstLine[1]; 1120 if (!rtHttpServerPathIsValid(pszPath, false /* fIsAbsolute */)) 1125 1121 { 1126 1122 rc = VERR_PATH_NOT_FOUND; … … 1128 1124 } 1129 1125 1130 pReq->pszUrl = RTStrDup(pszReq); 1131 1132 REQ_GET_NEXT_STRING 1133 1134 /* We're picky heree: Only HTTP 1.1 is supported by now. */ 1135 if (RTStrCmp(pszReq, RTHTTPVER_1_1_STR)) /** @todo Use RTStrVersionCompare. Later. */ 1126 pReq->pszUrl = RTStrDup(pszPath); 1127 1128 /* 1129 * Parse HTTP version to use. 1130 * We're picky heree: Only HTTP 1.1 is supported by now. 1131 */ 1132 const char *pszVer = ppapszFirstLine[2]; 1133 if (RTStrCmp(pszVer, RTHTTPVER_1_1_STR)) /** @todo Use RTStrVersionCompare. Later. */ 1136 1134 { 1137 1135 rc = VERR_NOT_SUPPORTED; … … 1144 1142 * Process headers, if any. 1145 1143 */ 1146 if (c Strings> 1)1147 { 1148 rc = rtHttpServerParseHeaders(pReq->hHdrLst, c Strings - 1, &ppapszStrings[1]);1144 if (cReq > 1) 1145 { 1146 rc = rtHttpServerParseHeaders(pReq->hHdrLst, cReq - 1, &ppapszReq[1]); 1149 1147 if (RT_SUCCESS(rc)) 1150 1148 { … … 1159 1157 * Cleanup. 1160 1158 */ 1161 for (size_t i = 0; i < cStrings; i++) 1162 RTStrFree(ppapszStrings[i]); 1163 RTMemFree(ppapszStrings); 1159 1160 for (size_t i = 0; i < cFirstLine; i++) 1161 RTStrFree(ppapszFirstLine[i]); 1162 RTMemFree(ppapszFirstLine); 1163 1164 for (size_t i = 0; i < cReq; i++) 1165 RTStrFree(ppapszReq[i]); 1166 RTMemFree(ppapszReq); 1164 1167 1165 1168 if (RT_FAILURE(rc))
Note:
See TracChangeset
for help on using the changeset viewer.