1 /*****************************************************************************
3 * Project ___| | | | _ \| |
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.
15 * argv3 = proxyuser:password
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
,
30 int *counter
= (int *)clientp
;
33 /* only do this once and then require a clearing of this */
34 fprintf(stderr
, "READ ALREADY DONE!\n");
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");
47 static curlioerr
ioctlcallback(CURL
*handle
,
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 */
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
;
117 mp_start
= tutil_tvnow();
120 res
= (int)curl_multi_perform(m
, &running
);
121 if (tutil_tvdiff(tutil_tvnow(), mp_start
) >
122 MULTI_PERFORM_HANG_TIMEOUT
) {
127 fprintf(stderr
, "nothing left running.\n");
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();