quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

lib513.c (2470B)


      1 /***************************************************************************
      2  *                                  _   _ ____  _
      3  *  Project                     ___| | | |  _ \| |
      4  *                             / __| | | | |_) | |
      5  *                            | (__| |_| |  _ <| |___
      6  *                             \___|\___/|_| \_\_____|
      7  *
      8  * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
      9  *
     10  * This software is licensed as described in the file COPYING, which
     11  * you should have received as part of this distribution. The terms
     12  * are also available at https://curl.se/docs/copyright.html.
     13  *
     14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
     15  * copies of the Software, and permit persons to whom the Software is
     16  * furnished to do so, under the terms of the COPYING file.
     17  *
     18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
     19  * KIND, either express or implied.
     20  *
     21  * SPDX-License-Identifier: curl
     22  *
     23  ***************************************************************************/
     24 #include "first.h"
     25 
     26 #include "memdebug.h"
     27 
     28 static size_t t513_read_cb(char *ptr, size_t size, size_t nmemb, void *userp)
     29 {
     30   (void)ptr;
     31   (void)size;
     32   (void)nmemb;
     33   (void)userp;
     34   return CURL_READFUNC_ABORT;
     35 }
     36 
     37 static CURLcode test_lib513(char *URL)
     38 {
     39   CURL *curl;
     40   CURLcode res = CURLE_OK;
     41 
     42   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
     43     curl_mfprintf(stderr, "curl_global_init() failed\n");
     44     return TEST_ERR_MAJOR_BAD;
     45   }
     46 
     47   curl = curl_easy_init();
     48   if(!curl) {
     49     curl_mfprintf(stderr, "curl_easy_init() failed\n");
     50     curl_global_cleanup();
     51     return TEST_ERR_MAJOR_BAD;
     52   }
     53 
     54   /* First set the URL that is about to receive our POST. */
     55   test_setopt(curl, CURLOPT_URL, URL);
     56 
     57   /* Now specify we want to POST data */
     58   test_setopt(curl, CURLOPT_POST, 1L);
     59 
     60   /* Set the expected POST size */
     61   test_setopt(curl, CURLOPT_POSTFIELDSIZE, 1L);
     62 
     63   /* we want to use our own read function */
     64   test_setopt(curl, CURLOPT_READFUNCTION, t513_read_cb);
     65 
     66   /* pointer to pass to our read function */
     67   test_setopt(curl, CURLOPT_READDATA, NULL);
     68 
     69   /* get verbose debug output please */
     70   test_setopt(curl, CURLOPT_VERBOSE, 1L);
     71 
     72   /* include headers in the output */
     73   test_setopt(curl, CURLOPT_HEADER, 1L);
     74 
     75   /* Perform the request, res will get the return code */
     76   res = curl_easy_perform(curl);
     77 
     78 test_cleanup:
     79 
     80   /* always cleanup */
     81   curl_easy_cleanup(curl);
     82   curl_global_cleanup();
     83 
     84   return res;
     85 }