lib578.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "test.h"
00023 
00024 #include "memdebug.h"
00025 
00026 /* The size of data should be kept below MAX_INITIAL_POST_SIZE! */
00027 static char data[]="this is a short string.\n";
00028 
00029 static size_t data_size = sizeof(data) / sizeof(char);
00030 
00031 static int progress_callback(void *clientp, double dltotal, double dlnow,
00032                              double ultotal, double ulnow)
00033 {
00034   FILE *moo = fopen(libtest_arg2, "wb");
00035 
00036   (void)clientp; /* UNUSED */
00037   (void)dltotal; /* UNUSED */
00038   (void)dlnow; /* UNUSED */
00039 
00040   if(moo) {
00041     if((size_t)ultotal == data_size && (size_t)ulnow == data_size)
00042       fprintf(moo, "PASSED, UL data matched data size\n");
00043     else
00044       fprintf(moo, "Progress callback called with UL %f out of %f\n",
00045               ulnow, ultotal);
00046     fclose(moo);
00047   }
00048   return 0;
00049 }
00050 
00051 int test(char *URL)
00052 {
00053   CURL *curl;
00054   CURLcode res=CURLE_OK;
00055 
00056   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00057     fprintf(stderr, "curl_global_init() failed\n");
00058     return TEST_ERR_MAJOR_BAD;
00059   }
00060 
00061   curl = curl_easy_init();
00062   if(!curl) {
00063     fprintf(stderr, "curl_easy_init() failed\n");
00064     curl_global_cleanup();
00065     return TEST_ERR_MAJOR_BAD;
00066   }
00067 
00068   /* First set the URL that is about to receive our POST. */
00069   test_setopt(curl, CURLOPT_URL, URL);
00070 
00071   /* Now specify we want to POST data */
00072   test_setopt(curl, CURLOPT_POST, 1L);
00073 
00074 #ifdef CURL_DOES_CONVERSIONS
00075   /* Convert the POST data to ASCII */
00076   test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
00077 #endif
00078 
00079   /* Set the expected POST size */
00080   test_setopt(curl, CURLOPT_POSTFIELDSIZE, data_size);
00081   test_setopt(curl, CURLOPT_POSTFIELDS, data);
00082 
00083   /* we want to use our own progress function */
00084   test_setopt(curl, CURLOPT_NOPROGRESS, 0L);
00085   test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
00086 
00087   /* pointer to pass to our read function */
00088 
00089   /* get verbose debug output please */
00090   test_setopt(curl, CURLOPT_VERBOSE, 1L);
00091 
00092   /* include headers in the output */
00093   test_setopt(curl, CURLOPT_HEADER, 1L);
00094 
00095   /* Perform the request, res will get the return code */
00096   res = curl_easy_perform(curl);
00097 
00098 test_cleanup:
00099 
00100   /* always cleanup */
00101   curl_easy_cleanup(curl);
00102   curl_global_cleanup();
00103 
00104   return res;
00105 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05