1 /*************************************************************************** 2 * _ _ ____ _ 3 * Project ___| | | | _ \| | 4 * / __| | | | |_) | | 5 * | (__| |_| | _ <| |___ 6 * \___|\___/|_| \_\_____| 7 * 8 * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel (at) 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 #include "test.h" 23 24 #include "memdebug.h" 25 26 static int progress_callback(void *clientp, double dltotal, 27 double dlnow, double ultotal, double ulnow) 28 { 29 (void)clientp; 30 (void)ulnow; 31 (void)ultotal; 32 33 if((dltotal > 0.0) && (dlnow > dltotal)) { 34 /* this should not happen with test case 599 */ 35 printf("%.0f > %.0f !!\n", dltotal, dlnow); 36 return -1; 37 } 38 39 return 0; 40 } 41 42 int test(char *URL) 43 { 44 CURL *curl; 45 CURLcode res=CURLE_OK; 46 double content_length = 0.0; 47 48 if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { 49 fprintf(stderr, "curl_global_init() failed\n"); 50 return TEST_ERR_MAJOR_BAD; 51 } 52 53 if ((curl = curl_easy_init()) == NULL) { 54 fprintf(stderr, "curl_easy_init() failed\n"); 55 curl_global_cleanup(); 56 return TEST_ERR_MAJOR_BAD; 57 } 58 59 /* First set the URL that is about to receive our POST. */ 60 test_setopt(curl, CURLOPT_URL, URL); 61 62 /* we want to use our own progress function */ 63 test_setopt(curl, CURLOPT_NOPROGRESS, 0L); 64 test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback); 65 66 /* get verbose debug output please */ 67 test_setopt(curl, CURLOPT_VERBOSE, 1L); 68 69 /* follow redirects */ 70 test_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); 71 72 /* include headers in the output */ 73 test_setopt(curl, CURLOPT_HEADER, 1L); 74 75 /* Perform the request, res will get the return code */ 76 res = curl_easy_perform(curl); 77 78 if (!res) { 79 FILE *moo; 80 res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, 81 &content_length); 82 moo = fopen(libtest_arg2, "wb"); 83 if (moo) { 84 fprintf(moo, "CL: %.0f\n", content_length); 85 fclose(moo); 86 } 87 } 88 89 test_cleanup: 90 91 /* always cleanup */ 92 curl_easy_cleanup(curl); 93 curl_global_cleanup(); 94 95 return res; 96 } 97