Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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;
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 int test(char *URL)
00046 {
00047 CURL *curl = NULL;
00048 CURLcode res = CURLE_FAILED_INIT;
00049
00050 struct curl_slist *hhl = NULL, *phl = NULL, *tmp = NULL;
00051
00052 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00053 fprintf(stderr, "curl_global_init() failed\n");
00054 return TEST_ERR_MAJOR_BAD;
00055 }
00056
00057 curl = curl_easy_init();
00058 if(!curl) {
00059 fprintf(stderr, "curl_easy_init() failed\n");
00060 curl_global_cleanup();
00061 return TEST_ERR_MAJOR_BAD;
00062 }
00063
00064 hhl = curl_slist_append(hhl, "User-Agent: Http Agent");
00065 phl = curl_slist_append(phl, "User-Agent: Proxy Agent");
00066 if(!hhl || !phl) {
00067 goto test_cleanup;
00068 }
00069 tmp = curl_slist_append(phl, "Expect:");
00070 if(!tmp) {
00071 goto test_cleanup;
00072 }
00073 phl = 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_PROXYHEADER, phl);
00079 test_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_SEPARATE);
00080 test_setopt(curl, CURLOPT_POST, 0L);
00081 test_setopt(curl, CURLOPT_UPLOAD, 1L);
00082 test_setopt(curl, CURLOPT_VERBOSE, 1L);
00083 test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
00084 test_setopt(curl, CURLOPT_HEADER, 1L);
00085 test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
00086 test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
00087 test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
00088 test_setopt(curl, CURLOPT_INFILESIZE, strlen(data));
00089
00090 res = curl_easy_perform(curl);
00091
00092 test_cleanup:
00093
00094 curl_easy_cleanup(curl);
00095
00096 curl_slist_free_all(hhl);
00097
00098 curl_slist_free_all(phl);
00099
00100 curl_global_cleanup();
00101
00102 return (int)res;
00103 }
00104