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 #include "test.h"
00023
00024 #include "memdebug.h"
00025
00026 static const char *post[]={
00027 "one",
00028 "two",
00029 "three",
00030 "and a final longer crap: four",
00031 NULL
00032 };
00033
00034
00035 struct WriteThis {
00036 int counter;
00037 };
00038
00039 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
00040 {
00041 struct WriteThis *pooh = (struct WriteThis *)userp;
00042 const char *data;
00043
00044 if(size*nmemb < 1)
00045 return 0;
00046
00047 data = post[pooh->counter];
00048
00049 if(data) {
00050 size_t len = strlen(data);
00051 memcpy(ptr, data, len);
00052 pooh->counter++;
00053 return len;
00054 }
00055 return 0;
00056 }
00057
00058 int test(char *URL)
00059 {
00060 CURL *curl;
00061 CURLcode res=CURLE_OK;
00062 struct curl_slist *slist = NULL;
00063 struct WriteThis pooh;
00064 pooh.counter = 0;
00065
00066 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00067 fprintf(stderr, "curl_global_init() failed\n");
00068 return TEST_ERR_MAJOR_BAD;
00069 }
00070
00071 curl = curl_easy_init();
00072 if(!curl) {
00073 fprintf(stderr, "curl_easy_init() failed\n");
00074 curl_global_cleanup();
00075 return TEST_ERR_MAJOR_BAD;
00076 }
00077
00078 slist = curl_slist_append(slist, "Transfer-Encoding: chunked");
00079 if(slist == NULL) {
00080 fprintf(stderr, "curl_slist_append() failed\n");
00081 curl_easy_cleanup(curl);
00082 curl_global_cleanup();
00083 return TEST_ERR_MAJOR_BAD;
00084 }
00085
00086
00087 test_setopt(curl, CURLOPT_URL, URL);
00088
00089
00090 test_setopt(curl, CURLOPT_POST, 1L);
00091
00092 #ifdef CURL_DOES_CONVERSIONS
00093
00094 test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
00095 #endif
00096
00097
00098 test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
00099
00100
00101 test_setopt(curl, CURLOPT_READDATA, &pooh);
00102
00103
00104 test_setopt(curl, CURLOPT_VERBOSE, 1L);
00105
00106
00107 test_setopt(curl, CURLOPT_HEADER, 1L);
00108
00109
00110 test_setopt(curl, CURLOPT_HTTPHEADER, slist);
00111
00112 #ifdef LIB565
00113 test_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_DIGEST);
00114 test_setopt(curl, CURLOPT_USERPWD, "foo:bar");
00115 #endif
00116
00117
00118 res = curl_easy_perform(curl);
00119
00120 test_cleanup:
00121
00122
00123 if(slist)
00124 curl_slist_free_all(slist);
00125
00126
00127 curl_easy_cleanup(curl);
00128 curl_global_cleanup();
00129
00130 return res;
00131 }