1/*************************************************************************** 2 * _ _ ____ _ 3 * Project ___| | | | _ \| | 4 * / __| | | | |_) | | 5 * | (__| |_| | _ <| |___ 6 * \___|\___/|_| \_\_____| 7 * 8 * Copyright (C) 1998 - 2011, 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 http://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/* argv1 = URL 23 * argv2 = proxy 24 * argv3 = proxyuser:password 25 */ 26 27#include "test.h" 28 29#include "memdebug.h" 30 31#ifdef CURL_DOES_CONVERSIONS 32 /* ASCII representation with escape sequences for non-ASCII platforms */ 33# define UPLOADTHIS "\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x62" \ 34 "\x6c\x75\x72\x62\x20\x77\x65\x20\x77\x61\x6e\x74\x20" \ 35 "\x74\x6f\x20\x75\x70\x6c\x6f\x61\x64\x0a" 36#else 37# define UPLOADTHIS "this is the blurb we want to upload\n" 38#endif 39 40#ifndef LIB548 41static size_t readcallback(void *ptr, 42 size_t size, 43 size_t nmemb, 44 void *clientp) 45{ 46 int *counter = (int *)clientp; 47 48 if(*counter) { 49 /* only do this once and then require a clearing of this */ 50 fprintf(stderr, "READ ALREADY DONE!\n"); 51 return 0; 52 } 53 (*counter)++; /* bump */ 54 55 if(size * nmemb > strlen(UPLOADTHIS)) { 56 fprintf(stderr, "READ!\n"); 57 strcpy(ptr, UPLOADTHIS); 58 return strlen(UPLOADTHIS); 59 } 60 fprintf(stderr, "READ NOT FINE!\n"); 61 return 0; 62} 63static curlioerr ioctlcallback(CURL *handle, 64 int cmd, 65 void *clientp) 66{ 67 int *counter = (int *)clientp; 68 (void)handle; /* unused */ 69 if(cmd == CURLIOCMD_RESTARTREAD) { 70 fprintf(stderr, "REWIND!\n"); 71 *counter = 0; /* clear counter to make the read callback restart */ 72 } 73 return CURLIOE_OK; 74} 75 76 77 78#endif 79 80int test(char *URL) 81{ 82 CURLcode res; 83 CURL *curl; 84#ifndef LIB548 85 int counter=0; 86#endif 87 88 if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { 89 fprintf(stderr, "curl_global_init() failed\n"); 90 return TEST_ERR_MAJOR_BAD; 91 } 92 93 if ((curl = curl_easy_init()) == NULL) { 94 fprintf(stderr, "curl_easy_init() failed\n"); 95 curl_global_cleanup(); 96 return TEST_ERR_MAJOR_BAD; 97 } 98 99 test_setopt(curl, CURLOPT_URL, URL); 100 test_setopt(curl, CURLOPT_VERBOSE, 1L); 101 test_setopt(curl, CURLOPT_HEADER, 1L); 102#ifdef LIB548 103 /* set the data to POST with a mere pointer to a zero-terminated string */ 104 test_setopt(curl, CURLOPT_POSTFIELDS, UPLOADTHIS); 105#else 106 /* 547 style, which means reading the POST data from a callback */ 107 test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback); 108 test_setopt(curl, CURLOPT_IOCTLDATA, &counter); 109 test_setopt(curl, CURLOPT_READFUNCTION, readcallback); 110 test_setopt(curl, CURLOPT_READDATA, &counter); 111 /* We CANNOT do the POST fine without setting the size (or choose chunked)! */ 112 test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(UPLOADTHIS)); 113#endif 114 test_setopt(curl, CURLOPT_POST, 1L); 115 test_setopt(curl, CURLOPT_PROXY, libtest_arg2); 116 test_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3); 117 test_setopt(curl, CURLOPT_PROXYAUTH, 118 (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) ); 119 120 res = curl_easy_perform(curl); 121 122test_cleanup: 123 124 curl_easy_cleanup(curl); 125 curl_global_cleanup(); 126 127 return (int)res; 128} 129 130