lib1527.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Vijay Panghal, <vpanghal@maginatics.com>, 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 /*
00024  * This unit test PUT http data over proxy. Same  http header will be generated
00025  * for server and proxy
00026  */
00027 
00028 #include "test.h"
00029 
00030 #include "memdebug.h"
00031 
00032 static char data [] = "Hello Cloud!\n";
00033 
00034 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
00035 {
00036   size_t  amount = nmemb * size; /* Total bytes curl wants */
00037   if(amount < strlen(data)) {
00038     return strlen(data);
00039   }
00040   (void)stream;
00041   memcpy(ptr, data, strlen(data));
00042   return strlen(data);
00043 }
00044 
00045 
00046 int test(char *URL)
00047 {
00048   CURL *curl = NULL;
00049   CURLcode res = CURLE_FAILED_INIT;
00050   /* http header list*/
00051   struct curl_slist *hhl = NULL, *tmp = NULL;
00052 
00053   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00054     fprintf(stderr, "curl_global_init() failed\n");
00055     return TEST_ERR_MAJOR_BAD;
00056   }
00057 
00058   curl = curl_easy_init();
00059   if(!curl) {
00060     fprintf(stderr, "curl_easy_init() failed\n");
00061     curl_global_cleanup();
00062     return TEST_ERR_MAJOR_BAD;
00063   }
00064 
00065   hhl = curl_slist_append(hhl, "User-Agent: Http Agent");
00066   if(!hhl) {
00067     goto test_cleanup;
00068   }
00069   tmp = curl_slist_append(hhl, "Expect: 100-continue");
00070   if(!tmp) {
00071     goto test_cleanup;
00072   }
00073   hhl = tmp;
00074 
00075   test_setopt(curl, CURLOPT_URL, URL);
00076   test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
00077   test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
00078   test_setopt(curl, CURLOPT_POST, 0L);
00079   test_setopt(curl, CURLOPT_UPLOAD, 1L);
00080   test_setopt(curl, CURLOPT_VERBOSE, 1L);
00081   test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
00082   test_setopt(curl, CURLOPT_HEADER, 1L);
00083   test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
00084   test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
00085   test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
00086   test_setopt(curl, CURLOPT_INFILESIZE, strlen(data));
00087   test_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_UNIFIED);
00088 
00089   res = curl_easy_perform(curl);
00090 
00091 test_cleanup:
00092 
00093   curl_easy_cleanup(curl);
00094 
00095   curl_slist_free_all(hhl);
00096 
00097   curl_global_cleanup();
00098 
00099   return (int)res;
00100 }


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