Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmcurl-7.19.0 / tests / libtest / lib555.c
blob091dbf12c412d11b786481d657675a71e5e7d9fa
1 /*****************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: lib555.c,v 1.1.1.1 2008-09-23 16:32:06 hoffman Exp $
10 * This test case is supposed to be identical to 547 except that this uses the
11 * multi interface and 547 is easy interface.
13 * argv1 = URL
14 * argv2 = proxy
15 * argv3 = proxyuser:password
18 #include "test.h"
19 #include "testutil.h"
21 #define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
23 #define UPLOADTHIS "this is the blurb we want to upload\n"
25 static size_t readcallback(void *ptr,
26 size_t size,
27 size_t nmemb,
28 void *clientp)
30 int *counter = (int *)clientp;
32 if(*counter) {
33 /* only do this once and then require a clearing of this */
34 fprintf(stderr, "READ ALREADY DONE!\n");
35 return 0;
37 (*counter)++; /* bump */
39 if(size * nmemb > strlen(UPLOADTHIS)) {
40 fprintf(stderr, "READ!\n");
41 strcpy(ptr, UPLOADTHIS);
42 return strlen(UPLOADTHIS);
44 fprintf(stderr, "READ NOT FINE!\n");
45 return 0;
47 static curlioerr ioctlcallback(CURL *handle,
48 int cmd,
49 void *clientp)
51 int *counter = (int *)clientp;
52 (void)handle; /* unused */
53 if(cmd == CURLIOCMD_RESTARTREAD) {
54 fprintf(stderr, "REWIND!\n");
55 *counter = 0; /* clear counter to make the read callback restart */
57 return CURLIOE_OK;
61 int test(char *URL)
63 int res;
64 CURL *curl;
65 int counter=0;
66 CURLM *m;
67 int running=1;
68 struct timeval mp_start;
69 char mp_timedout = FALSE;
71 if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
72 fprintf(stderr, "curl_global_init() failed\n");
73 return TEST_ERR_MAJOR_BAD;
76 if ((curl = curl_easy_init()) == NULL) {
77 fprintf(stderr, "curl_easy_init() failed\n");
78 curl_global_cleanup();
79 return TEST_ERR_MAJOR_BAD;
82 curl_easy_setopt(curl, CURLOPT_URL, URL);
83 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
84 curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
86 /* read the POST data from a callback */
87 curl_easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
88 curl_easy_setopt(curl, CURLOPT_IOCTLDATA, &counter);
89 curl_easy_setopt(curl, CURLOPT_READFUNCTION, readcallback);
90 curl_easy_setopt(curl, CURLOPT_READDATA, &counter);
91 /* We CANNOT do the POST fine without setting the size (or choose chunked)! */
92 curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(UPLOADTHIS));
94 curl_easy_setopt(curl, CURLOPT_POST, 1L);
95 curl_easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
96 curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
97 curl_easy_setopt(curl, CURLOPT_PROXYAUTH,
98 (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
100 if ((m = curl_multi_init()) == NULL) {
101 fprintf(stderr, "curl_multi_init() failed\n");
102 curl_easy_cleanup(curl);
103 curl_global_cleanup();
104 return TEST_ERR_MAJOR_BAD;
107 if ((res = (int)curl_multi_add_handle(m, curl)) != CURLM_OK) {
108 fprintf(stderr, "curl_multi_add_handle() failed, "
109 "with code %d\n", res);
110 curl_multi_cleanup(m);
111 curl_easy_cleanup(curl);
112 curl_global_cleanup();
113 return TEST_ERR_MAJOR_BAD;
116 mp_timedout = FALSE;
117 mp_start = tutil_tvnow();
119 while (running) {
120 res = (int)curl_multi_perform(m, &running);
121 if (tutil_tvdiff(tutil_tvnow(), mp_start) >
122 MULTI_PERFORM_HANG_TIMEOUT) {
123 mp_timedout = TRUE;
124 break;
126 if (running <= 0) {
127 fprintf(stderr, "nothing left running.\n");
128 break;
132 if (mp_timedout) {
133 if (mp_timedout) fprintf(stderr, "mp_timedout\n");
134 fprintf(stderr, "ABORTING TEST, since it seems "
135 "that it would have run forever.\n");
136 res = TEST_ERR_RUNS_FOREVER;
139 curl_multi_remove_handle(m, curl);
140 curl_easy_cleanup(curl);
141 curl_multi_cleanup(m);
143 curl_global_cleanup();
145 return res;