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