Changeset 87042 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Dec 4, 2020 12:10:36 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 141732
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/http-server.cpp
r87041 r87042 328 328 329 329 /** 330 * Initializes a HTTP body. 331 * 332 * @param pBody Body to initialize. 333 * @param cbSize Size of body (in bytes) to allocate. Optional and can be 0. 334 */ 335 static int rtHttpServerBodyInit(PRTHTTPBODY pBody, size_t cbSize) 336 { 337 if (cbSize) 338 { 339 pBody->pvBody = RTMemAlloc(cbSize); 340 AssertPtrReturn(pBody->pvBody, VERR_NO_MEMORY); 341 pBody->cbBodyAlloc = cbSize; 342 } 343 else 344 { 345 pBody->pvBody = NULL; 346 pBody->cbBodyAlloc = 0; 347 } 348 349 pBody->cbBodyUsed = 0; 350 pBody->offBody = 0; 351 352 return VINF_SUCCESS; 353 } 354 355 /** 356 * Destroys a HTTP body. 357 * 358 * @param pBody Body to destroy. 359 */ 360 static void rtHttpServerBodyDestroy(PRTHTTPBODY pBody) 361 { 362 if (!pBody) 363 return; 364 365 if (pBody->pvBody) 366 { 367 Assert(pBody->cbBodyAlloc); 368 369 RTMemFree(pBody->pvBody); 370 pBody->pvBody = NULL; 371 } 372 373 pBody->cbBodyAlloc = 0; 374 pBody->cbBodyUsed = 0; 375 pBody->offBody = 0; 376 } 377 378 /** 330 379 * Allocates and initializes a new client request. 331 380 * … … 341 390 AssertRC(rc2); 342 391 392 rc2 = rtHttpServerBodyInit(&pReq->Body, 0 /* cbSize */); 393 AssertRC(rc2); 394 343 395 return pReq; 344 396 } … … 356 408 RTHttpHeaderListDestroy(pReq->hHdrLst); 357 409 358 RTMemFree(pReq->pvBody); 359 pReq->pvBody = NULL; 410 rtHttpServerBodyDestroy(&pReq->Body); 360 411 361 412 RTMemFree(pReq); … … 376 427 AssertRCReturn(rc, rc); 377 428 378 if (cbBody) 379 { 380 pResp->pvBody = RTMemAlloc(cbBody); 381 AssertPtrReturn(pResp->pvBody, VERR_NO_MEMORY); 382 pResp->cbBodyAlloc = cbBody; 383 } 384 else 385 { 386 pResp->cbBodyAlloc = 0; 387 } 388 389 pResp->cbBodyUsed = 0; 429 rc = rtHttpServerBodyInit(&pResp->Body, cbBody); 390 430 391 431 return rc; … … 417 457 RTHttpHeaderListDestroy(pResp->hHdrLst); 418 458 419 if (pResp->pvBody) 420 { 421 Assert(pResp->cbBodyAlloc); 422 423 RTMemFree(pResp->pvBody); 424 pResp->pvBody = NULL; 425 } 426 427 pResp->cbBodyAlloc = 0; 428 pResp->cbBodyUsed = 0; 459 rtHttpServerBodyDestroy(&pResp->Body); 429 460 } 430 461 -
trunk/src/VBox/Runtime/tools/RTHttpServer.cpp
r87037 r87042 328 328 * !!! HACK ALERT !!! 329 329 ** @todo Build up and use a real XML DOM here. Works with Gnome / Gvfs-compatible apps though. 330 * !!! HACK ALERT !!! 330 331 */ 331 332 ssize_t cch = RTStrPrintf(pszBuf, cbBuf, … … 354 355 return rc; 355 356 } 357 358 static int writeHeaderDAV(PRTHTTPSERVERREQ pReq, PRTFSOBJINFO pObjInfo, char *pszBuf, size_t cbBuf, size_t *pcbWritten) 359 { 360 /** 361 * !!! HACK ALERT !!! 362 ** @todo Build up and use a real XML DOM here. Works with Gnome / Gvfs-compatible apps though. 363 * !!! HACK ALERT !!! 364 */ 365 366 size_t cbWritten = 0; 367 368 ssize_t cch = RTStrPrintf2(pszBuf, cbBuf - cbWritten, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"); 369 AssertReturn(cch, VERR_BUFFER_UNDERFLOW); 370 pszBuf += cch; 371 cbWritten += cch; 372 373 cch = RTStrPrintf2(pszBuf, cbBuf - cbWritten, "<d:multistatus xmlns:d=\"DAV:\">\r\n"); 374 AssertReturn(cch, VERR_BUFFER_UNDERFLOW); 375 pszBuf += cch; 376 cbWritten += cch; 377 378 int rc = dirEntryWriteDAV(pszBuf, cbBuf - cbWritten, pReq->pszUrl, pObjInfo, (size_t *)&cch); 379 AssertRC(rc); 380 pszBuf += cch; 381 cbWritten += cch; 382 383 *pcbWritten += cbWritten; 384 385 return rc; 386 } 387 388 static int writeFooterDAV(PRTHTTPSERVERREQ pReq, char *pszBuf, size_t cbBuf, size_t *pcbWritten) 389 { 390 RT_NOREF(pReq, pcbWritten); 391 392 /** 393 * !!! HACK ALERT !!! 394 ** @todo Build up and use a real XML DOM here. Works with Gnome / Gvfs-compatible apps though. 395 * !!! HACK ALERT !!! 396 */ 397 ssize_t cch = RTStrPrintf2(pszBuf, cbBuf, "</d:multistatus>"); 398 AssertReturn(cch, VERR_BUFFER_UNDERFLOW); 399 RT_NOREF(cch); 400 401 return VINF_SUCCESS; 402 } 356 403 #endif /* IPRT_HTTP_WITH_WEBDAV */ 357 404 … … 477 524 PRTHTTPSERVERRESP pResp = &pThis->Resp; 478 525 479 const size_t cbToCopy = RT_MIN(cbBuf, pResp-> cbBodyUsed);480 memcpy(pvBuf, pResp->pvBody, cbToCopy);481 Assert(pResp-> cbBodyUsed >= cbToCopy);482 pResp-> cbBodyUsed -= cbToCopy;526 const size_t cbToCopy = RT_MIN(cbBuf, pResp->Body.cbBodyUsed - pResp->Body.offBody); 527 memcpy(pvBuf, (uint8_t *)pResp->Body.pvBody + pResp->Body.offBody, cbToCopy); 528 Assert(pResp->Body.cbBodyUsed >= cbToCopy); 529 pResp->Body.offBody += cbToCopy; 483 530 484 531 *pcbRead = cbToCopy; … … 545 592 if (RTFS_IS_DIRECTORY(objInfo.Attr.fMode)) 546 593 { 547 PRTHTTPSERVERRESP pResp = &pThis->Resp; 594 PRTHTTPSERVERRESP pResp = &pThis->Resp; /* Only one request a time for now. */ 548 595 549 596 RTVFSDIR hVfsDir; … … 554 601 RTHttpServerResponseInitEx(pResp, _64K); /** @todo Make this more dynamic. */ 555 602 556 char *pszBody = (char *)pResp-> pvBody;557 size_t cbBodyLeft = pResp-> cbBodyAlloc;603 char *pszBody = (char *)pResp->Body.pvBody; 604 size_t cbBodyLeft = pResp->Body.cbBodyAlloc; 558 605 559 606 /* … … 573 620 else if (pReq->enmMethod == RTHTTPMETHOD_PROPFIND) 574 621 { 575 ssize_t cch = RTStrPrintf2(pszBody, cbBodyLeft, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"); 576 Assert(cch); 577 pszBody += cch; 578 cbBodyLeft -= cch; 579 580 cch = RTStrPrintf2(pszBody, cbBodyLeft, "<d:multistatus xmlns:d=\"DAV:\">\r\n"); 581 Assert(cch); 582 pszBody += cch; 583 cbBodyLeft -= cch; 584 585 rc = dirEntryWriteDAV(pszBody, cbBodyLeft, "/", &objInfo, (size_t *)&cch); 586 AssertRC(rc); 587 pszBody += cch; 588 cbBodyLeft -= cch; 622 size_t cbWritten = 0; 623 rc = writeHeaderDAV(pReq, &objInfo, pszBody, cbBodyLeft, &cbWritten); 624 if (RT_SUCCESS(rc)) 625 { 626 Assert(cbBodyLeft >= cbWritten); 627 cbBodyLeft -= cbWritten; 628 } 629 589 630 } 590 631 #endif /* IPRT_HTTP_WITH_WEBDAV */ … … 596 637 while (RT_SUCCESS(rc = dirRead(hVfsDir, &pszEntry, &fsObjInfo))) 597 638 { 639 LogFlowFunc(("Entry '%s'\n", pszEntry)); 640 598 641 size_t cbWritten = 0; 599 642 rc = dirEntryWrite(pReq->enmMethod, pszBody, cbBodyLeft, pszEntry, &fsObjInfo, &cbWritten); 600 643 if (rc == VERR_BUFFER_OVERFLOW) 601 644 { 602 pResp-> cbBodyAlloc += _4K; /** @todo Improve this. */603 pResp-> pvBody = RTMemRealloc(pResp->pvBody, pResp->cbBodyAlloc);604 AssertPtrBreakStmt(pResp-> pvBody, rc = VERR_NO_MEMORY);605 606 pszBody = (char *)pResp-> pvBody;645 pResp->Body.cbBodyAlloc += _4K; /** @todo Improve this. */ 646 pResp->Body.pvBody = RTMemRealloc(pResp->Body.pvBody, pResp->Body.cbBodyAlloc); 647 AssertPtrBreakStmt(pResp->Body.pvBody, rc = VERR_NO_MEMORY); 648 649 pszBody = (char *)pResp->Body.pvBody; 607 650 cbBodyLeft += _4K; /** @todo Ditto. */ 608 651 … … 642 685 else if (pReq->enmMethod == RTHTTPMETHOD_PROPFIND) 643 686 { 644 /** 645 * !!! HACK ALERT !!! 646 ** @todo Build up and use a real XML DOM here. Works with Gnome / Gvfs-compatible apps though. 647 */ 648 ssize_t cch = RTStrPrintf2(pszBody, cbBodyLeft, "</d:multistatus>\r\n"); 649 Assert(cch); 650 RT_NOREF(cch); 687 rc = writeFooterDAV(pReq, pszBody, cbBodyLeft, NULL); 651 688 } 652 689 #endif /* IPRT_HTTP_WITH_WEBDAV */ 653 690 654 pResp-> cbBodyUsed = strlen((char *)pResp->pvBody);655 656 pObjInfo->cbObject = pResp-> cbBodyUsed;691 pResp->Body.cbBodyUsed = strlen((char *)pResp->Body.pvBody); 692 693 pObjInfo->cbObject = pResp->Body.cbBodyUsed; 657 694 } 658 695 }
Note:
See TracChangeset
for help on using the changeset viewer.