lib510.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 const char *post[]={
00027   "one",
00028   "two",
00029   "three",
00030   "and a final longer crap: four",
00031   NULL
00032 };
00033 
00034 
00035 struct WriteThis {
00036   int counter;
00037 };
00038 
00039 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
00040 {
00041   struct WriteThis *pooh = (struct WriteThis *)userp;
00042   const char *data;
00043 
00044   if(size*nmemb < 1)
00045     return 0;
00046 
00047   data = post[pooh->counter];
00048 
00049   if(data) {
00050     size_t len = strlen(data);
00051     memcpy(ptr, data, len);
00052     pooh->counter++; /* advance pointer */
00053     return len;
00054   }
00055   return 0;                         /* no more data left to deliver */
00056 }
00057 
00058 int test(char *URL)
00059 {
00060   CURL *curl;
00061   CURLcode res=CURLE_OK;
00062   struct curl_slist *slist = NULL;
00063   struct WriteThis pooh;
00064   pooh.counter = 0;
00065 
00066   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00067     fprintf(stderr, "curl_global_init() failed\n");
00068     return TEST_ERR_MAJOR_BAD;
00069   }
00070 
00071   curl = curl_easy_init();
00072   if(!curl) {
00073     fprintf(stderr, "curl_easy_init() failed\n");
00074     curl_global_cleanup();
00075     return TEST_ERR_MAJOR_BAD;
00076   }
00077 
00078   slist = curl_slist_append(slist, "Transfer-Encoding: chunked");
00079   if(slist == NULL) {
00080     fprintf(stderr, "curl_slist_append() failed\n");
00081     curl_easy_cleanup(curl);
00082     curl_global_cleanup();
00083     return TEST_ERR_MAJOR_BAD;
00084   }
00085 
00086   /* First set the URL that is about to receive our POST. */
00087   test_setopt(curl, CURLOPT_URL, URL);
00088 
00089   /* Now specify we want to POST data */
00090   test_setopt(curl, CURLOPT_POST, 1L);
00091 
00092 #ifdef CURL_DOES_CONVERSIONS
00093   /* Convert the POST data to ASCII */
00094   test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
00095 #endif
00096 
00097   /* we want to use our own read function */
00098   test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
00099 
00100   /* pointer to pass to our read function */
00101   test_setopt(curl, CURLOPT_READDATA, &pooh);
00102 
00103   /* get verbose debug output please */
00104   test_setopt(curl, CURLOPT_VERBOSE, 1L);
00105 
00106   /* include headers in the output */
00107   test_setopt(curl, CURLOPT_HEADER, 1L);
00108 
00109   /* enforce chunked transfer by setting the header */
00110   test_setopt(curl, CURLOPT_HTTPHEADER, slist);
00111 
00112 #ifdef LIB565
00113   test_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_DIGEST);
00114   test_setopt(curl, CURLOPT_USERPWD, "foo:bar");
00115 #endif
00116 
00117   /* Perform the request, res will get the return code */
00118   res = curl_easy_perform(curl);
00119 
00120 test_cleanup:
00121 
00122   /* clean up the headers list */
00123   if(slist)
00124     curl_slist_free_all(slist);
00125 
00126   /* always cleanup */
00127   curl_easy_cleanup(curl);
00128   curl_global_cleanup();
00129 
00130   return res;
00131 }


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