lib1525.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  * Copyright (C) 2014, Vijay Panghal, <vpanghal@maginatics.com>, et al.
00010  *
00011  * This software is licensed as described in the file COPYING, which
00012  * you should have received as part of this distribution. The terms
00013  * are also available at https://curl.haxx.se/docs/copyright.html.
00014  *
00015  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00016  * copies of the Software, and permit persons to whom the Software is
00017  * furnished to do so, under the terms of the COPYING file.
00018  *
00019  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00020  * KIND, either express or implied.
00021  *
00022  ***************************************************************************/
00023 
00024 /*
00025  * This unit test PUT http data over proxy. Proxy header will be different
00026  * from server http header
00027  */
00028 
00029 #include "test.h"
00030 
00031 #include "memdebug.h"
00032 
00033 static char data [] = "Hello Cloud!\n";
00034 
00035 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
00036 {
00037   size_t  amount = nmemb * size; /* Total bytes curl wants */
00038   if(amount < strlen(data)) {
00039     return strlen(data);
00040   }
00041   (void)stream;
00042   memcpy(ptr, data, strlen(data));
00043   return strlen(data);
00044 }
00045 
00046 
00047 int test(char *URL)
00048 {
00049   CURL *curl = NULL;
00050   CURLcode res = CURLE_FAILED_INIT;
00051   /* http and proxy header list*/
00052   struct curl_slist *hhl = NULL;
00053 
00054   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00055     fprintf(stderr, "curl_global_init() failed\n");
00056     return TEST_ERR_MAJOR_BAD;
00057   }
00058 
00059   curl = curl_easy_init();
00060   if(!curl) {
00061     fprintf(stderr, "curl_easy_init() failed\n");
00062     curl_global_cleanup();
00063     return TEST_ERR_MAJOR_BAD;
00064   }
00065 
00066   hhl = curl_slist_append(hhl, "User-Agent: Http Agent");
00067 
00068   if(!hhl) {
00069     goto test_cleanup;
00070   }
00071 
00072   test_setopt(curl, CURLOPT_URL, URL);
00073   test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
00074   test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
00075   test_setopt(curl, CURLOPT_PROXYHEADER, hhl);
00076   test_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_UNIFIED);
00077   test_setopt(curl, CURLOPT_POST, 0L);
00078   test_setopt(curl, CURLOPT_UPLOAD, 1L);
00079   test_setopt(curl, CURLOPT_VERBOSE, 1L);
00080   test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
00081   test_setopt(curl, CURLOPT_HEADER, 1L);
00082   test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
00083   test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
00084   test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
00085   test_setopt(curl, CURLOPT_INFILESIZE, strlen(data));
00086 
00087   res = curl_easy_perform(curl);
00088 
00089 test_cleanup:
00090 
00091   curl_easy_cleanup(curl);
00092 
00093   curl_slist_free_all(hhl);
00094 
00095   curl_global_cleanup();
00096 
00097   return (int)res;
00098 }


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