Changeset 46050 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- May 14, 2013 8:41:11 AM (12 years ago)
- Location:
- trunk/src/VBox/Runtime/common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/dbg/dbgcfg.cpp
r46028 r46050 41 41 #include <iprt/env.h> 42 42 #include <iprt/file.h> 43 #include <iprt/http.h> 43 44 #include <iprt/list.h> 44 45 #include <iprt/log.h> … … 488 489 return VWRN_NOT_FOUND; 489 490 490 491 return VERR_NOT_IMPLEMENTED; 491 /* 492 * Create the path. 493 */ 494 const char *pszFilename = pSplitFn->apszComps[pSplitFn->cComps - 1]; 495 int rc = RTPathAppend(pszPath, RTPATH_MAX, pszFilename); 496 if (RT_FAILURE(rc)) 497 return rc; 498 if (!RTDirExists(pszPath)) 499 { 500 rc = RTDirCreate(pszPath, 0766, 0); 501 if (RT_FAILURE(rc)) 502 { 503 Log(("RTDirCreate(%s) -> %Rrc\n", pszPath, rc)); 504 } 505 } 506 507 rc = RTPathAppend(pszPath, RTPATH_MAX, pszCacheSubDir); 508 if (RT_FAILURE(rc)) 509 return rc; 510 if (!RTDirExists(pszPath)) 511 { 512 rc = RTDirCreate(pszPath, 0766, 0); 513 if (RT_FAILURE(rc)) 514 { 515 Log(("RTDirCreate(%s) -> %Rrc\n", pszPath, rc)); 516 } 517 } 518 519 /* Prepare the destination file name while we're here. */ 520 rc = RTPathAppend(pszPath, RTPATH_MAX, pszFilename); 521 if (RT_FAILURE(rc)) 522 return rc; 523 524 /* 525 * Download the file. 526 */ 527 RTHTTP hHttp; 528 rc = RTHttpCreate(&hHttp); 529 if (RT_FAILURE(rc)) 530 return rc; 531 532 static const char * const s_apszHeaders[] = 533 { 534 "User-Agent: Microsoft-Symbol-Server/6.6.0999.9", 535 "Cache-Control: no-cache", 536 }; 537 538 rc = RTHttpSetHeaders(hHttp, RT_ELEMENTS(s_apszHeaders), s_apszHeaders); 539 if (RT_SUCCESS(rc)) 540 { 541 char szUrl[_2K]; 542 RTStrPrintf(szUrl, sizeof(szUrl), "%s/%s/%s/%s", pszServer, pszFilename, pszCacheSubDir, pszFilename); 543 544 /** @todo Use some temporary file name and rename it after the operation. */ 545 rc = RTHttpGetFile(hHttp, szUrl, pszPath); 546 if (RT_FAILURE(rc)) 547 RTFileDelete(pszPath); 548 } 549 550 RTHttpDestroy(hHttp); 551 return rc; 492 552 } 493 553 … … 1334 1394 1335 1395 1336 RTDECL(int) RTDbgCfgCreate(PRTDBGCFG phDbgCfg, const char *pszEnvVarPrefix )1396 RTDECL(int) RTDbgCfgCreate(PRTDBGCFG phDbgCfg, const char *pszEnvVarPrefix, bool fNativePaths) 1337 1397 { 1338 1398 /* … … 1374 1434 * Read configurtion from the environment if requested to do so. 1375 1435 */ 1376 if (pszEnvVarPrefix) 1377 { 1378 static struct 1379 { 1380 RTDBGCFGPROP enmProp; 1381 const char *pszVar; 1382 } const s_aProps[] = 1383 { 1384 { RTDBGCFGPROP_FLAGS, "FLAGS" }, 1385 { RTDBGCFGPROP_PATH, "PATH" }, 1386 { RTDBGCFGPROP_SUFFIXES, "SUFFIXES" }, 1387 { RTDBGCFGPROP_SRC_PATH, "SRC_PATH" }, 1388 }; 1436 if (pszEnvVarPrefix || fNativePaths) 1437 { 1389 1438 const size_t cbEnvVar = 256; 1390 1439 const size_t cbEnvVal = 65536 - cbEnvVar; … … 1393 1442 { 1394 1443 char *pszEnvVal = pszEnvVar + cbEnvVar; 1395 for (unsigned i = 0; i < RT_ELEMENTS(s_aProps); i++) 1444 1445 if (pszEnvVarPrefix) 1396 1446 { 1397 size_t cchEnvVar = RTStrPrintf(pszEnvVar, cbEnvVar, "%s_%s", pszEnvVarPrefix, s_aProps[i].pszVar); 1398 if (cchEnvVar >= cbEnvVar - 1) 1447 static struct 1399 1448 { 1400 rc = VERR_BUFFER_OVERFLOW; 1401 break; 1449 RTDBGCFGPROP enmProp; 1450 const char *pszVar; 1451 } const s_aProps[] = 1452 { 1453 { RTDBGCFGPROP_FLAGS, "FLAGS" }, 1454 { RTDBGCFGPROP_PATH, "PATH" }, 1455 { RTDBGCFGPROP_SUFFIXES, "SUFFIXES" }, 1456 { RTDBGCFGPROP_SRC_PATH, "SRC_PATH" }, 1457 }; 1458 1459 for (unsigned i = 0; i < RT_ELEMENTS(s_aProps); i++) 1460 { 1461 size_t cchEnvVar = RTStrPrintf(pszEnvVar, cbEnvVar, "%s_%s", pszEnvVarPrefix, s_aProps[i].pszVar); 1462 if (cchEnvVar >= cbEnvVar - 1) 1463 { 1464 rc = VERR_BUFFER_OVERFLOW; 1465 break; 1466 } 1467 1468 rc = RTEnvGetEx(RTENV_DEFAULT, pszEnvVar, pszEnvVal, cbEnvVal, NULL); 1469 if (RT_SUCCESS(rc)) 1470 { 1471 rc = RTDbgCfgChangeString(pThis, s_aProps[i].enmProp, RTDBGCFGOP_SET, pszEnvVal); 1472 if (RT_FAILURE(rc)) 1473 break; 1474 } 1475 else if (rc != VERR_ENV_VAR_NOT_FOUND) 1476 break; 1477 else 1478 rc = VINF_SUCCESS; 1402 1479 } 1403 1404 rc = RTEnvGetEx(RTENV_DEFAULT, pszEnvVar, pszEnvVal, cbEnvVal, NULL);1405 if (RT_SUCCESS(rc))1406 {1407 rc = RTDbgCfgChangeString(pThis, s_aProps[i].enmProp, RTDBGCFGOP_SET, pszEnvVal);1408 if (RT_FAILURE(rc))1409 break;1410 }1411 else if (rc != VERR_ENV_VAR_NOT_FOUND)1412 break;1413 else1414 rc = VINF_SUCCESS;1415 1480 } 1416 1481 … … 1418 1483 * Pick up system specific search paths. 1419 1484 */ 1420 if (RT_SUCCESS(rc) )1485 if (RT_SUCCESS(rc) && fNativePaths) 1421 1486 { 1422 1487 struct -
trunk/src/VBox/Runtime/common/misc/http.cpp
r45632 r46050 204 204 } 205 205 206 RTR3DECL(int) RTHttpSetHeaders(RTHTTP hHttp, uint32_t cHeaders, const char *pcszHeaders[])206 RTR3DECL(int) RTHttpSetHeaders(RTHTTP hHttp, size_t cHeaders, const char * const *papszHeaders) 207 207 { 208 208 PRTHTTPINTERNAL pHttpInt = hHttp; … … 218 218 219 219 struct curl_slist *pHeaders = NULL; 220 for ( unsignedi = 0; i < cHeaders; i++)221 pHeaders = curl_slist_append(pHeaders, p cszHeaders[i]);220 for (size_t i = 0; i < cHeaders; i++) 221 pHeaders = curl_slist_append(pHeaders, papszHeaders[i]); 222 222 223 223 pHttpInt->pHeaders = pHeaders; … … 305 305 } 306 306 307 RTR3DECL(int) RTHttpGet(RTHTTP hHttp, const char *pcszUrl, char **ppszResponse) 308 { 309 PRTHTTPINTERNAL pHttpInt = hHttp; 310 RTHTTP_VALID_RETURN(pHttpInt); 311 312 pHttpInt->fAbort = false; 313 314 int rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_URL, pcszUrl); 315 if (CURL_FAILED(rcCurl)) 316 return VERR_INVALID_PARAMETER; 317 318 #if 0 319 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_VERBOSE, 1); 320 if (CURL_FAILED(rcCurl)) 321 return VERR_INVALID_PARAMETER; 322 #endif 323 324 const char *pcszCAFile = "/etc/ssl/certs/ca-certificates.crt"; 325 if (pHttpInt->pcszCAFile) 326 pcszCAFile = pHttpInt->pcszCAFile; 327 if (RTFileExists(pcszCAFile)) 328 { 329 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_CAINFO, pcszCAFile); 330 if (CURL_FAILED(rcCurl)) 331 return VERR_INTERNAL_ERROR; 332 } 333 334 RTHTTPMEMCHUNK chunk = { NULL, 0 }; 335 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_WRITEFUNCTION, &rtHttpWriteData); 336 if (CURL_FAILED(rcCurl)) 337 return VERR_INTERNAL_ERROR; 338 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_WRITEDATA, (void*)&chunk); 339 if (CURL_FAILED(rcCurl)) 340 return VERR_INTERNAL_ERROR; 341 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_PROGRESSFUNCTION, &rtHttpProgress); 342 if (CURL_FAILED(rcCurl)) 343 return VERR_INTERNAL_ERROR; 344 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_PROGRESSDATA, (void*)pHttpInt); 345 if (CURL_FAILED(rcCurl)) 346 return VERR_INTERNAL_ERROR; 347 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_NOPROGRESS, (long)0); 348 if (CURL_FAILED(rcCurl)) 349 return VERR_INTERNAL_ERROR; 350 351 rcCurl = curl_easy_perform(pHttpInt->pCurl); 307 308 /** 309 * Figures out the IPRT status code for a GET. 310 * 311 * @returns IPRT status code. 312 * @param pHttpInt HTTP instance. 313 * @param rcCurl What curl returned. 314 */ 315 static int rtHttpGetCalcStatus(PRTHTTPINTERNAL pHttpInt, int rcCurl) 316 { 352 317 int rc = VERR_INTERNAL_ERROR; 353 318 if (rcCurl == CURLE_OK) … … 408 373 } 409 374 375 return rc; 376 } 377 378 RTR3DECL(int) RTHttpGet(RTHTTP hHttp, const char *pcszUrl, char **ppszResponse) 379 { 380 PRTHTTPINTERNAL pHttpInt = hHttp; 381 RTHTTP_VALID_RETURN(pHttpInt); 382 383 pHttpInt->fAbort = false; 384 385 int rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_URL, pcszUrl); 386 if (CURL_FAILED(rcCurl)) 387 return VERR_INVALID_PARAMETER; 388 389 #if 0 390 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_VERBOSE, 1); 391 if (CURL_FAILED(rcCurl)) 392 return VERR_INVALID_PARAMETER; 393 #endif 394 395 const char *pcszCAFile = "/etc/ssl/certs/ca-certificates.crt"; 396 if (pHttpInt->pcszCAFile) 397 pcszCAFile = pHttpInt->pcszCAFile; 398 if (RTFileExists(pcszCAFile)) 399 { 400 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_CAINFO, pcszCAFile); 401 if (CURL_FAILED(rcCurl)) 402 return VERR_INTERNAL_ERROR; 403 } 404 405 RTHTTPMEMCHUNK chunk = { NULL, 0 }; 406 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_WRITEFUNCTION, &rtHttpWriteData); 407 if (CURL_FAILED(rcCurl)) 408 return VERR_INTERNAL_ERROR; 409 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_WRITEDATA, (void*)&chunk); 410 if (CURL_FAILED(rcCurl)) 411 return VERR_INTERNAL_ERROR; 412 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_PROGRESSFUNCTION, &rtHttpProgress); 413 if (CURL_FAILED(rcCurl)) 414 return VERR_INTERNAL_ERROR; 415 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_PROGRESSDATA, (void*)pHttpInt); 416 if (CURL_FAILED(rcCurl)) 417 return VERR_INTERNAL_ERROR; 418 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_NOPROGRESS, (long)0); 419 if (CURL_FAILED(rcCurl)) 420 return VERR_INTERNAL_ERROR; 421 422 rcCurl = curl_easy_perform(pHttpInt->pCurl); 423 int rc = rtHttpGetCalcStatus(pHttpInt, rcCurl); 410 424 *ppszResponse = chunk.pszMem; 411 425 412 426 return rc; 413 427 } 428 429 430 static size_t rtHttpWriteDataToFile(void *pvBuf, size_t cb, size_t n, void *pvUser) 431 { 432 size_t cbAll = cb * n; 433 RTFILE hFile = (RTFILE)(intptr_t)pvUser; 434 435 size_t cbWritten = 0; 436 int rc = RTFileWrite(hFile, pvBuf, cbAll, &cbWritten); 437 if (RT_SUCCESS(rc)) 438 return cbWritten; 439 return 0; 440 } 441 442 443 RTR3DECL(int) RTHttpGetFile(RTHTTP hHttp, const char *pszUrl, const char *pszDstFile) 444 { 445 PRTHTTPINTERNAL pHttpInt = hHttp; 446 RTHTTP_VALID_RETURN(pHttpInt); 447 448 /* 449 * Set up the request. 450 */ 451 pHttpInt->fAbort = false; 452 453 int rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_URL, pszUrl); 454 if (CURL_FAILED(rcCurl)) 455 return VERR_INVALID_PARAMETER; 456 457 #if 0 458 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_VERBOSE, 1); 459 if (CURL_FAILED(rcCurl)) 460 return VERR_INVALID_PARAMETER; 461 #endif 462 463 const char *pcszCAFile = "/etc/ssl/certs/ca-certificates.crt"; 464 if (pHttpInt->pcszCAFile) 465 pcszCAFile = pHttpInt->pcszCAFile; 466 if (RTFileExists(pcszCAFile)) 467 { 468 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_CAINFO, pcszCAFile); 469 if (CURL_FAILED(rcCurl)) 470 return VERR_INTERNAL_ERROR; 471 } 472 473 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_WRITEFUNCTION, &rtHttpWriteDataToFile); 474 if (CURL_FAILED(rcCurl)) 475 return VERR_INTERNAL_ERROR; 476 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_PROGRESSFUNCTION, &rtHttpProgress); 477 if (CURL_FAILED(rcCurl)) 478 return VERR_INTERNAL_ERROR; 479 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_PROGRESSDATA, (void*)pHttpInt); 480 if (CURL_FAILED(rcCurl)) 481 return VERR_INTERNAL_ERROR; 482 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_NOPROGRESS, (long)0); 483 if (CURL_FAILED(rcCurl)) 484 return VERR_INTERNAL_ERROR; 485 486 /* 487 * Open the output file. 488 */ 489 RTFILE hFile; 490 int rc = RTFileOpen(&hFile, pszDstFile, RTFILE_O_WRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_READWRITE); 491 if (RT_SUCCESS(rc)) 492 { 493 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_WRITEDATA, (void *)(uintptr_t)hFile); 494 if (!CURL_FAILED(rcCurl)) 495 { 496 /* 497 * Perform the request. 498 */ 499 rcCurl = curl_easy_perform(pHttpInt->pCurl); 500 rc = rtHttpGetCalcStatus(pHttpInt, rcCurl); 501 } 502 else 503 rc = VERR_INTERNAL_ERROR; 504 505 int rc2 = RTFileClose(hFile); 506 if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) 507 rc = rc2; 508 } 509 510 return rc; 511 } 512
Note:
See TracChangeset
for help on using the changeset viewer.