lib1514.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2014, 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  * Make sure libcurl does not send a `Content-Length: -1` header when HTTP POST
00024  * size is unknown.
00025  */
00026 
00027 #include "test.h"
00028 
00029 #include "memdebug.h"
00030 
00031 static char data[]="dummy";
00032 
00033 struct WriteThis {
00034   char *readptr;
00035   size_t sizeleft;
00036 };
00037 
00038 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
00039 {
00040   struct WriteThis *pooh = (struct WriteThis *)userp;
00041 
00042   if(size*nmemb < 1)
00043     return 0;
00044 
00045   if(pooh->sizeleft) {
00046     *(char *)ptr = pooh->readptr[0]; /* copy one single byte */
00047     pooh->readptr++;                 /* advance pointer */
00048     pooh->sizeleft--;                /* less data left */
00049     return 1;                        /* we return 1 byte at a time! */
00050   }
00051 
00052   return 0;                         /* no more data left to deliver */
00053 }
00054 
00055 int test(char *URL)
00056 {
00057   CURL *curl;
00058   CURLcode result = CURLE_OK;
00059   int res = 0;
00060   struct WriteThis pooh = { data, sizeof(data)-1 };
00061 
00062   global_init(CURL_GLOBAL_ALL);
00063 
00064   easy_init(curl);
00065 
00066   easy_setopt(curl, CURLOPT_URL, URL);
00067   easy_setopt(curl, CURLOPT_POST, 1L);
00068   /* Purposely omit to set CURLOPT_POSTFIELDSIZE */
00069   easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
00070   easy_setopt(curl, CURLOPT_READDATA, &pooh);
00071 
00072   result = curl_easy_perform(curl);
00073 
00074 test_cleanup:
00075 
00076   curl_easy_cleanup(curl);
00077   curl_global_cleanup();
00078 
00079   return (int)result;
00080 }


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