VirtualBox

Changeset 73699 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Aug 15, 2018 8:26:03 PM (6 years ago)
Author:
vboxsync
Message:

http-curl.cpp: add a few thin wrappers for some curl options.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/generic/http-curl.cpp

    r73334 r73699  
    293293    curl_global_cleanup();
    294294    return rc;
     295}
     296
     297
     298RTR3DECL(int) RTHttpReset(RTHTTP hHttp)
     299{
     300    if (hHttp == NIL_RTHTTP)
     301        return VERR_INVALID_HANDLE;
     302
     303    PRTHTTPINTERNAL pThis = hHttp;
     304    RTHTTP_VALID_RETURN(pThis);
     305
     306    AssertReturn(!pThis->fBusy, VERR_WRONG_ORDER);
     307
     308    /* This resets options, but keeps open connections, cookies, etc. */
     309    curl_easy_reset(pThis->pCurl);
     310    return VINF_SUCCESS;
    295311}
    296312
     
    25692585    return VINF_SUCCESS;
    25702586}
     2587
     2588
     2589
     2590RTR3DECL(int) RTHttpSetReadCallback(RTHTTP hHttp, PRTHTTPREADCALLBACK pfnRead, void *pvUser)
     2591{
     2592    CURLcode rcCurl;
     2593
     2594    PRTHTTPINTERNAL pThis = hHttp;
     2595    RTHTTP_VALID_RETURN(pThis);
     2596
     2597    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_READFUNCTION, pfnRead);
     2598    if (rcCurl != CURLE_OK)
     2599        return VERR_HTTP_CURL_ERROR;
     2600
     2601    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_READDATA, pvUser);
     2602    if (rcCurl != CURLE_OK)
     2603        return VERR_HTTP_CURL_ERROR;
     2604
     2605    return VINF_SUCCESS;   
     2606}
     2607
     2608
     2609RTR3DECL(int) RTHttpSetWriteCallback(RTHTTP hHttp, PRTHTTPWRITECALLBACK pfnWrite, void *pvUser)
     2610{
     2611    CURLcode rcCurl;
     2612
     2613    PRTHTTPINTERNAL pThis = hHttp;
     2614    RTHTTP_VALID_RETURN(pThis);
     2615
     2616    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_WRITEFUNCTION, pfnWrite);
     2617    if (rcCurl != CURLE_OK)
     2618        return VERR_HTTP_CURL_ERROR;
     2619
     2620    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_WRITEDATA, pvUser);
     2621    if (rcCurl != CURLE_OK)
     2622        return VERR_HTTP_CURL_ERROR;
     2623
     2624    return VINF_SUCCESS;   
     2625}
     2626
     2627
     2628RTR3DECL(int) RTHttpSetWriteHeaderCallback(RTHTTP hHttp, PRTHTTPWRITECALLBACK pfnWrite, void *pvUser)
     2629{
     2630    CURLcode rcCurl;
     2631
     2632    PRTHTTPINTERNAL pThis = hHttp;
     2633    RTHTTP_VALID_RETURN(pThis);
     2634
     2635    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_HEADERFUNCTION, pfnWrite);
     2636    if (rcCurl != CURLE_OK)
     2637        return VERR_HTTP_CURL_ERROR;
     2638
     2639    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_HEADERDATA, pvUser);
     2640    if (rcCurl != CURLE_OK)
     2641        return VERR_HTTP_CURL_ERROR;
     2642
     2643    return VINF_SUCCESS;   
     2644}
     2645
     2646
     2647RTR3DECL(int) RTHttpRawSetUrl(RTHTTP hHttp, const char *pszUrl)
     2648{
     2649    CURLcode rcCurl;
     2650
     2651    PRTHTTPINTERNAL pThis = hHttp;
     2652    RTHTTP_VALID_RETURN(pThis);
     2653
     2654    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_URL, pszUrl);
     2655    if (rcCurl != CURLE_OK)
     2656        return VERR_HTTP_CURL_ERROR;
     2657
     2658    return VINF_SUCCESS;
     2659}
     2660
     2661
     2662RTR3DECL(int) RTHttpRawSetGet(RTHTTP hHttp)
     2663{
     2664    CURLcode rcCurl;
     2665
     2666    PRTHTTPINTERNAL pThis = hHttp;
     2667    RTHTTP_VALID_RETURN(pThis);
     2668
     2669    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_HTTPGET, 1L);
     2670    if (rcCurl != CURLE_OK)
     2671        return VERR_HTTP_CURL_ERROR;
     2672
     2673    return VINF_SUCCESS;
     2674}
     2675
     2676
     2677RTR3DECL(int) RTHttpRawSetHead(RTHTTP hHttp)
     2678{
     2679    CURLcode rcCurl;
     2680
     2681    PRTHTTPINTERNAL pThis = hHttp;
     2682    RTHTTP_VALID_RETURN(pThis);
     2683
     2684    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_HTTPGET, 1L);
     2685    if (rcCurl != CURLE_OK)
     2686        return VERR_HTTP_CURL_ERROR;
     2687
     2688    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_NOBODY, 1L);
     2689    if (rcCurl != CURLE_OK)
     2690        return VERR_HTTP_CURL_ERROR;
     2691
     2692    return VINF_SUCCESS;
     2693}
     2694
     2695
     2696RTR3DECL(int) RTHttpRawSetPost(RTHTTP hHttp)
     2697{
     2698    CURLcode rcCurl;
     2699
     2700    PRTHTTPINTERNAL pThis = hHttp;
     2701    RTHTTP_VALID_RETURN(pThis);
     2702
     2703    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_POST, 1L);
     2704    if (rcCurl != CURLE_OK)
     2705        return VERR_HTTP_CURL_ERROR;
     2706
     2707    return VINF_SUCCESS;
     2708}
     2709
     2710
     2711RTR3DECL(int) RTHttpRawSetPut(RTHTTP hHttp)
     2712{
     2713    CURLcode rcCurl;
     2714
     2715    PRTHTTPINTERNAL pThis = hHttp;
     2716    RTHTTP_VALID_RETURN(pThis);
     2717
     2718    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_PUT, 1L);
     2719    if (rcCurl != CURLE_OK)
     2720        return VERR_HTTP_CURL_ERROR;
     2721
     2722    return VINF_SUCCESS;
     2723}
     2724
     2725
     2726RTR3DECL(int) RTHttpRawSetDelete(RTHTTP hHttp)
     2727{
     2728    /* curl doesn't provide an option for this */
     2729    return RTHttpRawSetCustomRequest(hHttp, "DELETE");
     2730}
     2731
     2732
     2733RTR3DECL(int) RTHttpRawSetCustomRequest(RTHTTP hHttp, const char *pszVerb)
     2734{
     2735    CURLcode rcCurl;
     2736
     2737    PRTHTTPINTERNAL pThis = hHttp;
     2738    RTHTTP_VALID_RETURN(pThis);
     2739
     2740    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_CUSTOMREQUEST, pszVerb);
     2741    if (rcCurl != CURLE_OK)
     2742        return VERR_HTTP_CURL_ERROR;
     2743
     2744    return VINF_SUCCESS;
     2745}
     2746
     2747
     2748RTR3DECL(int) RTHttpRawSetPostFields(RTHTTP hHttp, const void *pv, size_t cb)
     2749{
     2750    CURLcode rcCurl;
     2751
     2752    PRTHTTPINTERNAL pThis = hHttp;
     2753    RTHTTP_VALID_RETURN(pThis);
     2754
     2755    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_POSTFIELDSIZE, cb);
     2756    if (rcCurl != CURLE_OK)
     2757        return VERR_HTTP_CURL_ERROR;
     2758
     2759    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_POSTFIELDS, pv);
     2760    if (rcCurl != CURLE_OK)
     2761        return VERR_HTTP_CURL_ERROR;
     2762
     2763    return VINF_SUCCESS;
     2764}
     2765
     2766RTR3DECL(int) RTHttpRawSetInfileSize(RTHTTP hHttp, RTFOFF cb)
     2767{
     2768    CURLcode rcCurl;
     2769
     2770    PRTHTTPINTERNAL pThis = hHttp;
     2771    RTHTTP_VALID_RETURN(pThis);
     2772
     2773    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_INFILESIZE_LARGE, cb);
     2774    if (rcCurl != CURLE_OK)
     2775        return VERR_HTTP_CURL_ERROR;
     2776
     2777    return VINF_SUCCESS;
     2778}
     2779
     2780
     2781RTR3DECL(int) RTHttpRawSetVerbose(RTHTTP hHttp, bool fValue)
     2782{
     2783    CURLcode rcCurl;
     2784
     2785    PRTHTTPINTERNAL pThis = hHttp;
     2786    RTHTTP_VALID_RETURN(pThis);
     2787
     2788    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_VERBOSE, fValue ? 1L : 0L);
     2789    if (rcCurl != CURLE_OK)
     2790        return VERR_HTTP_CURL_ERROR;
     2791
     2792    return VINF_SUCCESS;
     2793}
     2794
     2795
     2796RTR3DECL(int) RTHttpRawSetTimeout(RTHTTP hHttp, long sec)
     2797{
     2798    CURLcode rcCurl;
     2799
     2800    PRTHTTPINTERNAL pThis = hHttp;
     2801    RTHTTP_VALID_RETURN(pThis);
     2802
     2803    rcCurl = curl_easy_setopt(pThis->pCurl, CURLOPT_TIMEOUT, sec);
     2804    if (rcCurl != CURLE_OK)
     2805        return VERR_HTTP_CURL_ERROR;
     2806
     2807    return VINF_SUCCESS;
     2808}
     2809
     2810
     2811RTR3DECL(int) RTHttpRawPerform(RTHTTP hHttp)
     2812{
     2813    CURLcode rcCurl;
     2814
     2815    PRTHTTPINTERNAL pThis = hHttp;
     2816    RTHTTP_VALID_RETURN(pThis);
     2817
     2818    rcCurl = curl_easy_perform(pThis->pCurl);
     2819    if (rcCurl != CURLE_OK)
     2820        return VERR_HTTP_CURL_ERROR;
     2821
     2822    return VINF_SUCCESS;
     2823}
     2824
     2825
     2826RTR3DECL(int) RTHttpRawGetResponseCode(RTHTTP hHttp, long *plCode)
     2827{
     2828    CURLcode rcCurl;
     2829
     2830    PRTHTTPINTERNAL pThis = hHttp;
     2831    RTHTTP_VALID_RETURN(pThis);
     2832    AssertPtrReturn(plCode, VERR_INVALID_PARAMETER);
     2833
     2834    rcCurl = curl_easy_getinfo(pThis->pCurl, CURLINFO_RESPONSE_CODE, plCode);
     2835    if (rcCurl != CURLE_OK)
     2836        return VERR_HTTP_CURL_ERROR;
     2837
     2838    return VINF_SUCCESS;
     2839}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette