1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: lib547.c,v 1.1.1.1 2008-09-23 16:32:06 hoffman Exp $
12 * argv3 = proxyuser:password
17 #define UPLOADTHIS "this is the blurb we want to upload\n"
20 static size_t readcallback(void *ptr
,
25 int *counter
= (int *)clientp
;
28 /* only do this once and then require a clearing of this */
29 fprintf(stderr
, "READ ALREADY DONE!\n");
32 (*counter
)++; /* bump */
34 if(size
* nmemb
> strlen(UPLOADTHIS
)) {
35 fprintf(stderr
, "READ!\n");
36 strcpy(ptr
, UPLOADTHIS
);
37 return strlen(UPLOADTHIS
);
39 fprintf(stderr
, "READ NOT FINE!\n");
42 static curlioerr
ioctlcallback(CURL
*handle
,
46 int *counter
= (int *)clientp
;
47 (void)handle
; /* unused */
48 if(cmd
== CURLIOCMD_RESTARTREAD
) {
49 fprintf(stderr
, "REWIND!\n");
50 *counter
= 0; /* clear counter to make the read callback restart */
67 if (curl_global_init(CURL_GLOBAL_ALL
) != CURLE_OK
) {
68 fprintf(stderr
, "curl_global_init() failed\n");
69 return TEST_ERR_MAJOR_BAD
;
72 if ((curl
= curl_easy_init()) == NULL
) {
73 fprintf(stderr
, "curl_easy_init() failed\n");
74 curl_global_cleanup();
75 return TEST_ERR_MAJOR_BAD
;
78 curl_easy_setopt(curl
, CURLOPT_URL
, URL
);
79 curl_easy_setopt(curl
, CURLOPT_VERBOSE
, 1L);
80 curl_easy_setopt(curl
, CURLOPT_HEADER
, 1L);
82 /* set the data to POST with a mere pointer to a zero-terminated string */
83 curl_easy_setopt(curl
, CURLOPT_POSTFIELDS
, UPLOADTHIS
);
85 /* 547 style, which means reading the POST data from a callback */
86 curl_easy_setopt(curl
, CURLOPT_IOCTLFUNCTION
, ioctlcallback
);
87 curl_easy_setopt(curl
, CURLOPT_IOCTLDATA
, &counter
);
88 curl_easy_setopt(curl
, CURLOPT_READFUNCTION
, readcallback
);
89 curl_easy_setopt(curl
, CURLOPT_READDATA
, &counter
);
90 /* We CANNOT do the POST fine without setting the size (or choose chunked)! */
91 curl_easy_setopt(curl
, CURLOPT_POSTFIELDSIZE
, (long)strlen(UPLOADTHIS
));
93 curl_easy_setopt(curl
, CURLOPT_POST
, 1L);
94 curl_easy_setopt(curl
, CURLOPT_PROXY
, libtest_arg2
);
95 curl_easy_setopt(curl
, CURLOPT_PROXYUSERPWD
, libtest_arg3
);
96 curl_easy_setopt(curl
, CURLOPT_PROXYAUTH
,
97 (long) (CURLAUTH_NTLM
| CURLAUTH_DIGEST
| CURLAUTH_BASIC
) );
99 res
= curl_easy_perform(curl
);
101 curl_easy_cleanup(curl
);
102 curl_global_cleanup();