lib508.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 
00037   if(size*nmemb < 1)
00038     return 0;
00039 
00040   if(pooh->sizeleft) {
00041     *(char *)ptr = pooh->readptr[0]; /* copy one single byte */
00042     pooh->readptr++;                 /* advance pointer */
00043     pooh->sizeleft--;                /* less data left */
00044     return 1;                        /* we return 1 byte at a time! */
00045   }
00046 
00047   return 0;                         /* no more data left to deliver */
00048 }
00049 
00050 int test(char *URL)
00051 {
00052   CURL *curl;
00053   CURLcode res=CURLE_OK;
00054 
00055   struct WriteThis pooh;
00056 
00057   pooh.readptr = data;
00058   pooh.sizeleft = strlen(data);
00059 
00060   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00061     fprintf(stderr, "curl_global_init() failed\n");
00062     return TEST_ERR_MAJOR_BAD;
00063   }
00064 
00065   curl = curl_easy_init();
00066   if(!curl) {
00067     fprintf(stderr, "curl_easy_init() failed\n");
00068     curl_global_cleanup();
00069     return TEST_ERR_MAJOR_BAD;
00070   }
00071 
00072   /* First set the URL that is about to receive our POST. */
00073   test_setopt(curl, CURLOPT_URL, URL);
00074 
00075   /* Now specify we want to POST data */
00076   test_setopt(curl, CURLOPT_POST, 1L);
00077 
00078 #ifdef CURL_DOES_CONVERSIONS
00079   /* Convert the POST data to ASCII */
00080   test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
00081 #endif
00082 
00083   /* Set the expected POST size */
00084   test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)pooh.sizeleft);
00085 
00086   /* we want to use our own read function */
00087   test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
00088 
00089   /* pointer to pass to our read function */
00090   test_setopt(curl, CURLOPT_READDATA, &pooh);
00091 
00092   /* get verbose debug output please */
00093   test_setopt(curl, CURLOPT_VERBOSE, 1L);
00094 
00095   /* include headers in the output */
00096   test_setopt(curl, CURLOPT_HEADER, 1L);
00097 
00098   /* Perform the request, res will get the return code */
00099   res = curl_easy_perform(curl);
00100 
00101 test_cleanup:
00102 
00103   /* always cleanup */
00104   curl_easy_cleanup(curl);
00105   curl_global_cleanup();
00106 
00107   return res;
00108 }


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