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
00046 int test(char *URL)
00047 {
00048 CURL *curl = NULL;
00049 CURLcode res = CURLE_FAILED_INIT;
00050
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 }