lib553.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 
00023 /* This test case and code is based on the bug recipe Joe Malicki provided for
00024  * bug report #1871269, fixed on Jan 14 2008 before the 7.18.0 release.
00025  */
00026 
00027 #include "test.h"
00028 
00029 #include "memdebug.h"
00030 
00031 #define POSTLEN 40960
00032 
00033 static size_t myreadfunc(void *ptr, size_t size, size_t nmemb, void *stream)
00034 {
00035   static size_t total=POSTLEN;
00036   static char buf[1024];
00037   (void)stream;
00038 
00039   memset(buf, 'A', sizeof(buf));
00040 
00041   size *= nmemb;
00042   if(size > total)
00043     size = total;
00044 
00045   if(size > sizeof(buf))
00046     size = sizeof(buf);
00047 
00048   memcpy(ptr, buf, size);
00049   total -= size;
00050   return size;
00051 }
00052 
00053 #define NUM_HEADERS 8
00054 #define SIZE_HEADERS 5000
00055 
00056 static char buf[SIZE_HEADERS + 100];
00057 
00058 int test(char *URL)
00059 {
00060   CURL *curl;
00061   CURLcode res = CURLE_FAILED_INIT;
00062   int i;
00063   struct curl_slist *headerlist=NULL, *hl;
00064 
00065   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00066     fprintf(stderr, "curl_global_init() failed\n");
00067     return TEST_ERR_MAJOR_BAD;
00068   }
00069 
00070   curl = curl_easy_init();
00071   if(!curl) {
00072     fprintf(stderr, "curl_easy_init() failed\n");
00073     curl_global_cleanup();
00074     return TEST_ERR_MAJOR_BAD;
00075   }
00076 
00077   for(i = 0; i < NUM_HEADERS; i++) {
00078     int len = snprintf(buf, sizeof(buf), "Header%d: ", i);
00079     memset(&buf[len], 'A', SIZE_HEADERS);
00080     buf[len + SIZE_HEADERS]=0; /* zero terminate */
00081     hl = curl_slist_append(headerlist,  buf);
00082     if(!hl)
00083       goto test_cleanup;
00084     headerlist = hl;
00085   }
00086 
00087   hl = curl_slist_append(headerlist, "Expect: ");
00088   if(!hl)
00089     goto test_cleanup;
00090   headerlist = hl;
00091 
00092   test_setopt(curl, CURLOPT_URL, URL);
00093   test_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
00094   test_setopt(curl, CURLOPT_POST, 1L);
00095 #ifdef CURL_DOES_CONVERSIONS
00096   /* Convert the POST data to ASCII */
00097   test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
00098 #endif
00099   test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)POSTLEN);
00100   test_setopt(curl, CURLOPT_VERBOSE, 1L);
00101   test_setopt(curl, CURLOPT_HEADER, 1L);
00102   test_setopt(curl, CURLOPT_READFUNCTION, myreadfunc);
00103 
00104   res = curl_easy_perform(curl);
00105 
00106 test_cleanup:
00107 
00108   curl_easy_cleanup(curl);
00109 
00110   curl_slist_free_all(headerlist);
00111 
00112   curl_global_cleanup();
00113 
00114   return (int)res;
00115 }


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