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
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;
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
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 }