Changeset 74023 in vbox for trunk/src/VBox/Runtime/common/rest
- Timestamp:
- Sep 2, 2018 1:43:59 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 124770
- Location:
- trunk/src/VBox/Runtime/common/rest
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/rest/RTCRestArrayBase.cpp
r74008 r74023 245 245 246 246 247 RTCRestObjectBase::kTypeClass RTCRestArrayBase::typeClass(void) const 248 { 249 return kTypeClass_Array; 250 } 251 252 253 const char *RTCRestArrayBase::typeName(void) const 254 { 255 return "RTCRestArray<ElementType>"; 256 } 257 258 247 259 248 260 /********************************************************************************************************************************* -
trunk/src/VBox/Runtime/common/rest/RTCRestClientRequestBase.cpp
r74020 r74023 146 146 else 147 147 { 148 AssertFailedReturn(VERR_NOT_IMPLEMENTED); 148 /* 149 * Enumerate array and add 'name=element' for each element in it. 150 */ 151 AssertReturn(a_papQueryParamObjs[i]->typeClass() == RTCRestObjectBase::kTypeClass_Array, 152 VERR_REST_INTERAL_ERROR_2); 153 RTCRestArrayBase const *pArray = (RTCRestArrayBase const *)a_papQueryParamObjs[i]; 154 for (size_t i = 0; i < pArray->size(); i++) 155 { 156 RTCRestObjectBase const *pObj = pArray->atBase(i); 157 int rc = pObj->toString(&strTmpVal, a_paQueryParams[i].fFlags & ~RTCRestObjectBase::kCollectionFormat_Mask); 158 AssertRCReturn(rc, rc); 159 160 rc = a_pStrQuery->appendPrintfNoThrow("%c%RMpq=%RMpq", chSep, a_paQueryParams[i].pszName, strTmpVal.c_str()); 161 AssertRCReturn(rc, rc); 162 163 chSep = '&'; 164 } 149 165 } 150 166 } … … 170 186 ("Required header parameter '%s' is not set!\n", a_paHeaderParams[i].pszName)); 171 187 172 int rc = a_papHeaderParamObjs[i]->toString(&strTmpVal, a_paHeaderParams[i].fFlags); 173 AssertRCReturn(rc, rc); 174 175 rc = RTHttpAppendHeader(a_hHttp, a_paHeaderParams[i].pszName, strTmpVal.c_str(), 0); 176 AssertRCReturn(rc, rc); 188 if (!a_paHeaderParams[i].fMapCollection) 189 { 190 int rc = a_papHeaderParamObjs[i]->toString(&strTmpVal, a_paHeaderParams[i].fFlags); 191 AssertRCReturn(rc, rc); 192 193 rc = RTHttpAppendHeader(a_hHttp, a_paHeaderParams[i].pszName, strTmpVal.c_str(), 0); 194 AssertRCReturn(rc, rc); 195 } 196 else if (!a_papHeaderParamObjs[i]->isNull()) 197 { 198 /* 199 * Enumerate the map and produce a series of head fields on the form: 200 * (a_paHeaderParams[i].pszName + key): value.toString() 201 */ 202 AssertReturn(a_papHeaderParamObjs[i]->typeClass() == RTCRestObjectBase::kTypeClass_StringMap, 203 VERR_REST_INTERAL_ERROR_1); 204 RTCRestStringMapBase const *pMap = (RTCRestStringMapBase const *)a_papHeaderParamObjs[i]; 205 const size_t cchName = strlen(a_paHeaderParams[i].pszName); 206 RTCString strTmpName; 207 for (RTCRestStringMapBase::ConstIterator it = pMap->begin(); it != pMap->end(); ++it) 208 { 209 int rc = strTmpName.assignNoThrow(a_paHeaderParams[i].pszName, cchName); 210 AssertRCReturn(rc, rc); 211 rc = strTmpName.appendNoThrow(it.getKey()); 212 AssertRCReturn(rc, rc); 213 214 rc = it.getValue()->toString(&strTmpVal, a_paHeaderParams[i].fFlags); 215 AssertRCReturn(rc, rc); 216 217 rc = RTHttpAppendHeader(a_hHttp, strTmpName.c_str(), strTmpVal.c_str(), 0); 218 AssertRCReturn(rc, rc); 219 } 220 } 221 else 222 Assert(!a_paHeaderParams[i].fRequired); 177 223 } 178 224 } -
trunk/src/VBox/Runtime/common/rest/RTCRestClientResponseBase.cpp
r74009 r74023 231 231 { 232 232 size_t const cchThisName = a_paFieldDescs[i].cchName; 233 if ( !(a_paFieldDescs[i].fFlags & kHdrField_MapCollection) 234 ? cchThisName == cchName 235 && RTStrNICmpAscii(a_pchData, a_paFieldDescs[i].pszName, cchThisName) == 0 236 : cchThisName <= cchName 237 && RTStrNICmpAscii(a_pchData, a_paFieldDescs[i].pszName, cchThisName - 1) == 0) 233 if ( (!(a_paFieldDescs[i].fFlags & kHdrField_MapCollection) ? cchThisName == cchName : cchThisName < cchName) 234 && RTStrNICmpAscii(a_pchData, a_paFieldDescs[i].pszName, cchThisName) == 0) 238 235 { 239 236 /* Get and clean the value. */ 240 int rc = VINF_SUCCESS;241 237 if (!fHaveValue) 242 238 { 243 rc = strValue.assignNoThrow(&a_pchData[offValue], cchValue);239 int rc = strValue.assignNoThrow(&a_pchData[offValue], cchValue); 244 240 if (RT_SUCCESS(rc)) 245 241 { … … 257 253 * Create field to deserialize. 258 254 */ 259 RTCRestObjectBase *pObj = NULL; 260 if (!(a_paFieldDescs[i].fFlags & (kHdrField_MapCollection | kHdrField_ArrayCollection))) 255 RTCRestStringMapBase *pMap = NULL; 256 RTCRestObjectBase *pObj = NULL; 257 if (!(a_paFieldDescs[i].fFlags & kHdrField_MapCollection)) 261 258 { 262 259 /* Only once. */ … … 269 266 { 270 267 addError(VERR_NO_MEMORY, "out of memory"); 271 continue;268 break; 272 269 } 273 270 } … … 280 277 else 281 278 { 282 Assert(a_paFieldDescs[i].pszName[cchThisName - 1] == '*'); 283 AssertMsgFailed(("impl field collections")); 284 continue; 279 /* Make sure we've got a map to work with. */ 280 if (!*a_pappFieldValues[i]) 281 *a_pappFieldValues[i] = pObj = a_paFieldDescs[i].pfnCreateInstance(); 282 else 283 pObj = *a_pappFieldValues[i]; 284 AssertBreak(pObj->typeClass() == RTCRestObjectBase::kTypeClass_StringMap); 285 pMap = (RTCRestStringMapBase *)pObj; 286 287 /* Insert the header field name (sans prefix) into the map. We then use the 288 new value object for the deserialization of the header field value below. */ 289 int rc = pMap->putNewValue(&pObj, &a_pchData[cchThisName], cchName - cchThisName); 290 if (RT_SUCCESS(rc)) 291 { /* likely */ } 292 else if (rc == VERR_ALREADY_EXISTS) 293 { 294 addError(VERR_REST_RESPONSE_REPEAT_HEADER_FIELD, "Already saw header field '%s'", a_paFieldDescs[i].pszName); 295 continue; 296 } 297 else 298 { 299 addError(rc, "out of memory"); 300 break; 301 } 285 302 } 286 303 … … 289 306 */ 290 307 RTERRINFOSTATIC ErrInfo; 291 rc = pObj->fromString(strValue, a_paFieldDescs[i].pszName, RTErrInfoInitStatic(&ErrInfo),292 a_paFieldDescs[i].fFlags & RTCRestObjectBase::kCollectionFormat_Mask);308 int rc = pObj->fromString(strValue, a_paFieldDescs[i].pszName, RTErrInfoInitStatic(&ErrInfo), 309 a_paFieldDescs[i].fFlags & RTCRestObjectBase::kCollectionFormat_Mask); 293 310 if (RT_SUCCESS(rc)) 294 311 { /* likely */ } … … 405 422 if (RT_SUCCESS(rc)) 406 423 { 407 PrimaryJsonCursorForBody PrimaryCursor(hValue, a_pDst-> getType(), this); /* note: consumes hValue */424 PrimaryJsonCursorForBody PrimaryCursor(hValue, a_pDst->typeName(), this); /* note: consumes hValue */ 408 425 a_pDst->deserializeFromJson(PrimaryCursor.m_Cursor); 409 426 } 410 427 else if (RTErrInfoIsSet(&ErrInfo.Core)) 411 428 addError(rc, "Error %Rrc parsing server response as JSON (type %s): %s", 412 rc, a_pDst-> getType(), ErrInfo.Core.pszMsg);429 rc, a_pDst->typeName(), ErrInfo.Core.pszMsg); 413 430 else 414 addError(rc, "Error %Rrc parsing server response as JSON (type %s)", rc, a_pDst-> getType());431 addError(rc, "Error %Rrc parsing server response as JSON (type %s)", rc, a_pDst->typeName()); 415 432 } 416 433 else if (rc == VERR_INVALID_UTF8_ENCODING) 417 434 addError(VERR_REST_RESPONSE_INVALID_UTF8_ENCODING, "Invalid UTF-8 body encoding (object type %s; Content-Type: %s)", 418 a_pDst-> getType(), m_strContentType.c_str());435 a_pDst->typeName(), m_strContentType.c_str()); 419 436 else if (rc == VERR_BUFFER_UNDERFLOW) 420 437 addError(VERR_REST_RESPONSE_EMBEDDED_ZERO_CHAR, "Embedded zero character in response (object type %s; Content-Type: %s)", 421 a_pDst-> getType(), m_strContentType.c_str());438 a_pDst->typeName(), m_strContentType.c_str()); 422 439 else 423 440 addError(rc, "Unexpected body validation error (object type %s; Content-Type: %s): %Rrc", 424 a_pDst-> getType(), m_strContentType.c_str(), rc);441 a_pDst->typeName(), m_strContentType.c_str(), rc); 425 442 } 426 443 else 427 444 addError(VERR_REST_RESPONSE_CONTENT_TYPE_NOT_SUPPORTED, "Unsupported content type for '%s': %s", 428 a_pDst-> getType(), m_strContentType.c_str());429 } 430 445 a_pDst->typeName(), m_strContentType.c_str()); 446 } 447 -
trunk/src/VBox/Runtime/common/rest/RTCRestStringMapBase.cpp
r74008 r74023 204 204 205 205 206 RTCRestObjectBase::kTypeClass RTCRestStringMapBase::typeClass(void) const 207 { 208 return kTypeClass_StringMap; 209 } 210 211 212 const char *RTCRestStringMapBase::typeName(void) const 213 { 214 return "RTCRestStringMap<ValueType>"; 215 } 216 217 206 218 /********************************************************************************************************************************* 207 219 * Generic map methods * … … 269 281 { 270 282 return remove(a_rStrKey.c_str()); 283 } 284 285 286 int RTCRestStringMapBase::putNewValue(RTCRestObjectBase **a_ppValue, const char *a_pszKey, size_t a_cchKey /*= RTSTR_MAX*/, 287 bool a_fReplace /*= false*/) 288 { 289 RTCRestObjectBase *pValue = createValue(); 290 if (pValue) 291 { 292 int rc = putWorker(a_pszKey, pValue, a_fReplace, a_cchKey); 293 if (RT_SUCCESS(rc)) 294 *a_ppValue = pValue; 295 else 296 { 297 delete pValue; 298 *a_ppValue = NULL; 299 } 300 return rc; 301 } 302 *a_ppValue = NULL; 303 return VERR_NO_MEMORY; 304 } 305 306 307 int RTCRestStringMapBase::putNewValue(RTCRestObjectBase **a_ppValue, RTCString const &a_rStrKey, bool a_fReplace /*= false*/) 308 { 309 return putNewValue(a_ppValue, a_rStrKey.c_str(), a_rStrKey.length(), a_fReplace); 271 310 } 272 311 … … 301 340 302 341 303 int RTCRestStringMapBase::putWorker(const char *a_pszKey, RTCRestObjectBase *a_pValue, bool a_fReplace) 342 int RTCRestStringMapBase::putWorker(const char *a_pszKey, RTCRestObjectBase *a_pValue, bool a_fReplace, 343 size_t a_cchKey /*= RTSTR_MAX*/) 304 344 { 305 345 int rc; … … 307 347 if (pEntry) 308 348 { 309 rc = pEntry->strKey.assignNoThrow(a_pszKey );349 rc = pEntry->strKey.assignNoThrow(a_pszKey, a_cchKey); 310 350 if (RT_SUCCESS(rc)) 311 351 { … … 347 387 348 388 349 int RTCRestStringMapBase::putCopyWorker(const char *a_pszKey, RTCRestObjectBase const &a_rValue, bool a_fReplace) 389 int RTCRestStringMapBase::putCopyWorker(const char *a_pszKey, RTCRestObjectBase const &a_rValue, bool a_fReplace, 390 size_t a_cchKey /*= RTSTR_MAX*/) 350 391 { 351 392 int rc; … … 353 394 if (pValueCopy) 354 395 { 355 rc = putWorker(a_pszKey, pValueCopy, a_fReplace );396 rc = putWorker(a_pszKey, pValueCopy, a_fReplace, a_cchKey); 356 397 if (RT_SUCCESS(rc)) 357 398 { /* likely */ } -
trunk/src/VBox/Runtime/common/rest/rest-primary-object-types.cpp
r74013 r74023 118 118 119 119 120 RTCRestObjectBase::kTypeClass RTCRestObjectBase::typeClass() const 121 { 122 return kTypeClass_Object; 123 } 124 125 120 126 /********************************************************************************************************************************* 121 127 * RTCRestBool implementation * … … 277 283 278 284 279 const char *RTCRestBool::getType() 285 RTCRestObjectBase::kTypeClass RTCRestBool::typeClass() const 286 { 287 return kTypeClass_Bool; 288 } 289 290 291 const char *RTCRestBool::typeName() const 280 292 { 281 293 return "bool"; … … 434 446 435 447 436 const char *RTCRestInt64::getType() 448 RTCRestObjectBase::kTypeClass RTCRestInt64::typeClass() const 449 { 450 return kTypeClass_Int64; 451 } 452 453 454 const char *RTCRestInt64::typeName() const 437 455 { 438 456 return "int64_t"; … … 597 615 598 616 599 const char *RTCRestInt32::getType() 617 RTCRestObjectBase::kTypeClass RTCRestInt32::typeClass() const 618 { 619 return kTypeClass_Int32; 620 } 621 622 623 const char *RTCRestInt32::typeName() const 600 624 { 601 625 return "int32_t"; … … 760 784 761 785 762 const char *RTCRestInt16::getType() 786 RTCRestObjectBase::kTypeClass RTCRestInt16::typeClass() const 787 { 788 return kTypeClass_Int16; 789 } 790 791 792 const char *RTCRestInt16::typeName() const 763 793 { 764 794 return "int16_t"; … … 920 950 921 951 922 const char *RTCRestDouble::getType() 952 RTCRestObjectBase::kTypeClass RTCRestDouble::typeClass() const 953 { 954 return kTypeClass_Double; 955 } 956 957 958 const char *RTCRestDouble::typeName() const 923 959 { 924 960 return "double"; … … 1071 1107 1072 1108 1073 const char *RTCRestString::getType() 1109 RTCRestObjectBase::kTypeClass RTCRestString::typeClass() const 1110 { 1111 return kTypeClass_String; 1112 } 1113 1114 1115 const char *RTCRestString::typeName() const 1074 1116 { 1075 1117 return "RTCString";
Note:
See TracChangeset
for help on using the changeset viewer.