Changeset 57577 in vbox for trunk/src/VBox/Runtime/common/misc
- Timestamp:
- Aug 28, 2015 6:57:36 PM (10 years ago)
- svn:sync-xref-src-repo-rev:
- 102405
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/http.cpp
r57516 r57577 41 41 42 42 #include <curl/curl.h> 43 #include <openssl/ssl.h>44 43 #include "internal/magics.h" 45 44 … … 69 68 typedef struct RTHTTPMEMCHUNK 70 69 { 71 uint8_t *pu8Mem;72 size_t cb;70 uint8_t *pu8Mem; 71 size_t cb; 73 72 } RTHTTPMEMCHUNK; 74 73 typedef RTHTTPMEMCHUNK *PRTHTTPMEMCHUNK; … … 122 121 } 123 122 123 124 124 RTR3DECL(void) RTHttpDestroy(RTHTTP hHttp) 125 125 { … … 147 147 curl_global_cleanup(); 148 148 } 149 149 150 150 151 static DECLCALLBACK(size_t) rtHttpWriteData(void *pvBuf, size_t cb, size_t n, void *pvUser) … … 163 164 } 164 165 165 static DECLCALLBACK(int) rtHttpProgress(void *pData, double DlTotal, double DlNow, 166 166 167 static DECLCALLBACK(int) rtHttpProgress(void *pData, double DlTotal, double DlNow, double UlTotal, double UlNow) 167 168 { 168 169 PRTHTTPINTERNAL pHttpInt = (PRTHTTPINTERNAL)pData; … … 172 173 } 173 174 175 174 176 RTR3DECL(int) RTHttpAbort(RTHTTP hHttp) 175 177 { … … 181 183 return VINF_SUCCESS; 182 184 } 185 183 186 184 187 RTR3DECL(int) RTHttpGetRedirLocation(RTHTTP hHttp, char **ppszRedirLocation) … … 193 196 return VINF_SUCCESS; 194 197 } 198 195 199 196 200 RTR3DECL(int) RTHttpUseSystemProxySettings(RTHTTP hHttp) … … 229 233 } 230 234 235 231 236 RTR3DECL(int) RTHttpSetProxy(RTHTTP hHttp, const char *pcszProxy, uint32_t uPort, 232 237 const char *pcszProxyUser, const char *pcszProxyPwd) … … 260 265 return VINF_SUCCESS; 261 266 } 267 262 268 263 269 RTR3DECL(int) RTHttpSetHeaders(RTHTTP hHttp, size_t cHeaders, const char * const *papszHeaders) … … 286 292 } 287 293 288 RTR3DECL(int) RTHttpCertDigest(RTHTTP hHttp, char *pcszCert, size_t cbCert,289 uint8_t **pabSha1, size_t *pcbSha1,290 uint8_t **pabSha512, size_t *pcbSha512)291 {292 int rc = VINF_SUCCESS;293 294 BIO *cert = BIO_new_mem_buf(pcszCert, (int)cbCert);295 if (cert)296 {297 X509 *crt = NULL;298 if (PEM_read_bio_X509(cert, &crt, NULL, NULL))299 {300 unsigned cb;301 unsigned char md[EVP_MAX_MD_SIZE];302 303 int rc1 = X509_digest(crt, EVP_sha1(), md, &cb);304 if (rc1 > 0)305 {306 *pabSha1 = (uint8_t*)RTMemAlloc(cb);307 if (*pabSha1)308 {309 memcpy(*pabSha1, md, cb);310 *pcbSha1 = cb;311 312 rc1 = X509_digest(crt, EVP_sha512(), md, &cb);313 if (rc1 > 0)314 {315 *pabSha512 = (uint8_t*)RTMemAlloc(cb);316 if (*pabSha512)317 {318 memcpy(*pabSha512, md, cb);319 *pcbSha512 = cb;320 }321 else322 rc = VERR_NO_MEMORY;323 }324 else325 rc = VERR_HTTP_CACERT_WRONG_FORMAT;326 327 if (RT_FAILURE(rc))328 RTMemFree(*pabSha1);329 }330 else331 rc = VERR_NO_MEMORY;332 }333 else334 rc = VERR_HTTP_CACERT_WRONG_FORMAT;335 X509_free(crt);336 }337 else338 rc = VERR_HTTP_CACERT_WRONG_FORMAT;339 BIO_free(cert);340 }341 else342 rc = VERR_INTERNAL_ERROR;343 344 return rc;345 }346 294 347 295 RTR3DECL(int) RTHttpSetCAFile(RTHTTP hHttp, const char *pcszCAFile) … … 449 397 } 450 398 399 400 /** 401 * Internal worker that performs a HTTP GET. 402 * 403 * @returns IPRT status code. 404 * @param hHttp The HTTP instance. 405 * @param pcszUrl The URL. 406 * @param ppvResponse Where to return the pointer to the allocated 407 * response data (RTMemFree). There will always be 408 * an zero terminator char after the response, that 409 * is not part of the size returned via @a pcb. 410 * @param pcb The size of the response data. 411 */ 451 412 RTR3DECL(int) rtHttpGet(RTHTTP hHttp, const char *pcszUrl, uint8_t **ppvResponse, size_t *pcb) 452 413 { … … 476 437 } 477 438 478 RTHTTPMEMCHUNK chunk = { NULL, 0 };439 RTHTTPMEMCHUNK Chunk = { NULL, 0 }; 479 440 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_WRITEFUNCTION, &rtHttpWriteData); 480 441 if (CURL_FAILED(rcCurl)) 481 442 return VERR_INTERNAL_ERROR; 482 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_WRITEDATA, (void *)&chunk);443 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_WRITEDATA, (void *)&Chunk); 483 444 if (CURL_FAILED(rcCurl)) 484 445 return VERR_INTERNAL_ERROR; … … 486 447 if (CURL_FAILED(rcCurl)) 487 448 return VERR_INTERNAL_ERROR; 488 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_PROGRESSDATA, (void *)pHttpInt);449 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_PROGRESSDATA, (void *)pHttpInt); 489 450 if (CURL_FAILED(rcCurl)) 490 451 return VERR_INTERNAL_ERROR; … … 497 458 498 459 rcCurl = curl_easy_perform(pHttpInt->pCurl); 460 499 461 int rc = rtHttpGetCalcStatus(pHttpInt, rcCurl); 500 *ppvResponse = chunk.pu8Mem; 501 *pcb = chunk.cb; 462 if (RT_SUCCESS(rc)) 463 { 464 *ppvResponse = Chunk.pu8Mem; 465 *pcb = Chunk.cb; 466 } 467 else 468 { 469 if (Chunk.pu8Mem) 470 RTMemFree(Chunk.pu8Mem); 471 *ppvResponse = NULL; 472 *pcb = 0; 473 } 502 474 503 475 return rc; … … 505 477 506 478 507 RTR3DECL(int) RTHttpGetText(RTHTTP hHttp, const char *pcszUrl, char **ppsz Response)479 RTR3DECL(int) RTHttpGetText(RTHTTP hHttp, const char *pcszUrl, char **ppszNotUtf8) 508 480 { 509 481 uint8_t *pv; 510 size_t cb;482 size_t cb; 511 483 int rc = rtHttpGet(hHttp, pcszUrl, &pv, &cb); 512 *ppszResponse = (char*)pv; 484 if (RT_SUCCESS(rc)) 485 { 486 if (pv) /* paranoia */ 487 *ppszNotUtf8 = (char *)pv; 488 else 489 *ppszNotUtf8 = (char *)RTMemDup("", 1); 490 } 491 else 492 *ppszNotUtf8 = NULL; 513 493 return rc; 514 494 } 515 495 516 496 497 RTR3DECL(void) RTHttpFreeResponseText(char *pszNotUtf8) 498 { 499 RTMemFree(pszNotUtf8); 500 } 501 502 517 503 RTR3DECL(int) RTHttpGetBinary(RTHTTP hHttp, const char *pcszUrl, void **ppvResponse, size_t *pcb) 518 504 { 519 return rtHttpGet(hHttp, pcszUrl, (uint8_t**)ppvResponse, pcb); 505 return rtHttpGet(hHttp, pcszUrl, (uint8_t **)ppvResponse, pcb); 506 } 507 508 509 RTR3DECL(void) RTHttpFreeResponse(void *pvResponse) 510 { 511 RTMemFree(pvResponse); 520 512 } 521 513 … … 570 562 if (CURL_FAILED(rcCurl)) 571 563 return VERR_INTERNAL_ERROR; 572 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_PROGRESSDATA, (void *)pHttpInt);564 rcCurl = curl_easy_setopt(pHttpInt->pCurl, CURLOPT_PROGRESSDATA, (void *)pHttpInt); 573 565 if (CURL_FAILED(rcCurl)) 574 566 return VERR_INTERNAL_ERROR;
Note:
See TracChangeset
for help on using the changeset viewer.