xref: /curl/tests/libtest/lib1555.c (revision 25cbc2f7)
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 /*
25  * Verify that some API functions are locked from being called inside callback
26  */
27 
28 #include "test.h"
29 
30 #include "memdebug.h"
31 
32 static CURL *curl;
33 
progressCallback(void * arg,double dltotal,double dlnow,double ultotal,double ulnow)34 static int progressCallback(void *arg,
35                             double dltotal,
36                             double dlnow,
37                             double ultotal,
38                             double ulnow)
39 {
40   CURLcode res = CURLE_OK;
41   char buffer[256];
42   size_t n = 0;
43   (void)arg;
44   (void)dltotal;
45   (void)dlnow;
46   (void)ultotal;
47   (void)ulnow;
48   res = curl_easy_recv(curl, buffer, 256, &n);
49   printf("curl_easy_recv returned %d\n", res);
50   res = curl_easy_send(curl, buffer, n, &n);
51   printf("curl_easy_send returned %d\n", res);
52 
53   return 1;
54 }
55 
test(char * URL)56 CURLcode test(char *URL)
57 {
58   CURLcode res = CURLE_OK;
59 
60   global_init(CURL_GLOBAL_ALL);
61 
62   easy_init(curl);
63 
64   easy_setopt(curl, CURLOPT_URL, URL);
65   easy_setopt(curl, CURLOPT_TIMEOUT, (long)7);
66   easy_setopt(curl, CURLOPT_NOSIGNAL, (long)1);
67   CURL_IGNORE_DEPRECATION(
68     easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progressCallback);
69     easy_setopt(curl, CURLOPT_PROGRESSDATA, NULL);
70   )
71   easy_setopt(curl, CURLOPT_NOPROGRESS, (long)0);
72 
73   res = curl_easy_perform(curl);
74 
75 test_cleanup:
76 
77   /* undocumented cleanup sequence - type UA */
78 
79   curl_easy_cleanup(curl);
80   curl_global_cleanup();
81 
82   return res;
83 }
84