quickjs-tart

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

lib1576.c (3025B)


      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 char t1576_testdata[] = "request indicates that the client, which made";
     29 
     30 static size_t t1576_read_cb(char *ptr, size_t size, size_t nmemb, void *stream)
     31 {
     32   size_t amount = nmemb * size; /* Total bytes curl wants */
     33   if(amount < strlen(t1576_testdata)) {
     34     return strlen(t1576_testdata);
     35   }
     36   (void)stream;
     37   memcpy(ptr, t1576_testdata, strlen(t1576_testdata));
     38   return strlen(t1576_testdata);
     39 }
     40 
     41 static int t1576_seek_callback(void *ptr, curl_off_t offset, int origin)
     42 {
     43   (void)ptr;
     44   (void)offset;
     45   if(origin != SEEK_SET)
     46     return CURL_SEEKFUNC_FAIL;
     47   return CURL_SEEKFUNC_OK;
     48 }
     49 
     50 static CURLcode test_lib1576(char *URL)
     51 {
     52   CURLcode res;
     53   CURL *curl;
     54   struct curl_slist *pHeaderList = NULL;
     55 
     56   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
     57     curl_mfprintf(stderr, "curl_global_init() failed\n");
     58     return TEST_ERR_MAJOR_BAD;
     59   }
     60 
     61   curl = curl_easy_init();
     62   if(!curl) {
     63     curl_mfprintf(stderr, "curl_easy_init() failed\n");
     64     curl_global_cleanup();
     65     return TEST_ERR_MAJOR_BAD;
     66   }
     67 
     68   test_setopt(curl, CURLOPT_HEADER, 1L);
     69   test_setopt(curl, CURLOPT_VERBOSE, 1L);
     70   test_setopt(curl, CURLOPT_URL, URL);
     71   test_setopt(curl, CURLOPT_UPLOAD, 1L);
     72   test_setopt(curl, CURLOPT_READFUNCTION, t1576_read_cb);
     73   test_setopt(curl, CURLOPT_SEEKFUNCTION, t1576_seek_callback);
     74   test_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(t1576_testdata));
     75 
     76   test_setopt(curl, CURLOPT_CUSTOMREQUEST, "CURL");
     77   if(testnum == 1578 || testnum == 1580) {
     78     test_setopt(curl, CURLOPT_FOLLOWLOCATION, CURLFOLLOW_FIRSTONLY);
     79   }
     80   else {
     81     test_setopt(curl, CURLOPT_FOLLOWLOCATION, CURLFOLLOW_OBEYCODE);
     82   }
     83   /* Remove "Expect: 100-continue" */
     84   pHeaderList = curl_slist_append(pHeaderList, "Expect:");
     85 
     86   curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pHeaderList);
     87   res = curl_easy_perform(curl);
     88 
     89 test_cleanup:
     90   curl_easy_cleanup(curl);
     91   curl_global_cleanup();
     92   curl_slist_free_all(pHeaderList);
     93 
     94   return res;
     95 }