• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2020, 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  * This test case is based on the sample code provided by Saqib Ali
24  * https://curl.haxx.se/mail/lib-2011-03/0066.html
25  */
26 
27 #include "test.h"
28 
29 #include <sys/stat.h>
30 
31 #include "memdebug.h"
32 
test(char * URL)33 int test(char *URL)
34 {
35   int stillRunning;
36   CURLM *multiHandle = NULL;
37   CURL *curl = NULL;
38   CURLcode res = CURLE_OK;
39   CURLMcode mres;
40 
41   global_init(CURL_GLOBAL_ALL);
42 
43   multi_init(multiHandle);
44 
45   easy_init(curl);
46 
47   easy_setopt(curl, CURLOPT_USERPWD, libtest_arg2);
48   easy_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE, "curl_client_key.pub");
49   easy_setopt(curl, CURLOPT_SSH_PRIVATE_KEYFILE, "curl_client_key");
50 
51   easy_setopt(curl, CURLOPT_UPLOAD, 1L);
52   easy_setopt(curl, CURLOPT_VERBOSE, 1L);
53 
54   easy_setopt(curl, CURLOPT_URL, URL);
55   easy_setopt(curl, CURLOPT_INFILESIZE, (long)5);
56 
57   multi_add_handle(multiHandle, curl);
58 
59   /* this tests if removing an easy handle immediately after multi
60      perform has been called succeeds or not. */
61 
62   fprintf(stderr, "curl_multi_perform()...\n");
63 
64   multi_perform(multiHandle, &stillRunning);
65 
66   fprintf(stderr, "curl_multi_perform() succeeded\n");
67 
68   fprintf(stderr, "curl_multi_remove_handle()...\n");
69   mres = curl_multi_remove_handle(multiHandle, curl);
70   if(mres) {
71     fprintf(stderr, "curl_multi_remove_handle() failed, "
72             "with code %d\n", (int)mres);
73     res = TEST_ERR_MULTI;
74   }
75   else
76     fprintf(stderr, "curl_multi_remove_handle() succeeded\n");
77 
78 test_cleanup:
79 
80   /* undocumented cleanup sequence - type UB */
81 
82   curl_easy_cleanup(curl);
83   curl_multi_cleanup(multiHandle);
84   curl_global_cleanup();
85 
86   return (int)res;
87 }
88