lib1517.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 static char data[]="this is what we post to the silly web server\n";
00027 
00028 struct WriteThis {
00029   char *readptr;
00030   size_t sizeleft;
00031 };
00032 
00033 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
00034 {
00035   struct WriteThis *pooh = (struct WriteThis *)userp;
00036   size_t tocopy = size * nmemb;
00037 
00038   /* Wait one second before return POST data          *
00039    * so libcurl will wait before sending request body */
00040   wait_ms(1000);
00041 
00042   if(tocopy < 1 || !pooh->sizeleft)
00043     return 0;
00044 
00045   if(pooh->sizeleft < tocopy)
00046     tocopy = pooh->sizeleft;
00047 
00048   memcpy(ptr, pooh->readptr, tocopy);/* copy requested data */
00049   pooh->readptr += tocopy;           /* advance pointer */
00050   pooh->sizeleft -= tocopy;          /* less data left */
00051   return tocopy;
00052 }
00053 
00054 int test(char *URL)
00055 {
00056   CURL *curl;
00057   CURLcode res=CURLE_OK;
00058 
00059   struct WriteThis pooh;
00060 
00061   pooh.readptr = data;
00062   pooh.sizeleft = strlen(data);
00063 
00064   if(curl_global_init(CURL_GLOBAL_ALL)) {
00065     fprintf(stderr, "curl_global_init() failed\n");
00066     return TEST_ERR_MAJOR_BAD;
00067   }
00068 
00069   curl = curl_easy_init();
00070   if(!curl) {
00071     fprintf(stderr, "curl_easy_init() failed\n");
00072     curl_global_cleanup();
00073     return TEST_ERR_MAJOR_BAD;
00074   }
00075 
00076   /* First set the URL that is about to receive our POST. */
00077   test_setopt(curl, CURLOPT_URL, URL);
00078 
00079   /* Now specify we want to POST data */
00080   test_setopt(curl, CURLOPT_POST, 1L);
00081 
00082 #ifdef CURL_DOES_CONVERSIONS
00083   /* Convert the POST data to ASCII */
00084   test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
00085 #endif
00086 
00087   /* Set the expected POST size */
00088   test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)pooh.sizeleft);
00089 
00090   /* we want to use our own read function */
00091   test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
00092 
00093   /* pointer to pass to our read function */
00094   test_setopt(curl, CURLOPT_READDATA, &pooh);
00095 
00096   /* get verbose debug output please */
00097   test_setopt(curl, CURLOPT_VERBOSE, 1L);
00098 
00099   /* include headers in the output */
00100   test_setopt(curl, CURLOPT_HEADER, 1L);
00101 
00102   /* detect HTTP error codes >= 400 */
00103   /* test_setopt(curl, CURLOPT_FAILONERROR, 1L); */
00104 
00105 
00106   /* Perform the request, res will get the return code */
00107   res = curl_easy_perform(curl);
00108 
00109 test_cleanup:
00110 
00111   /* always cleanup */
00112   curl_easy_cleanup(curl);
00113   curl_global_cleanup();
00114 
00115   return res;
00116 }


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