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 * const 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 int progress_callback(void *clientp, double dltotal, double dlnow,
00040 double ultotal, double ulnow)
00041 {
00042 FILE *moo;
00043 static int prev_ultotal = -1;
00044 static int prev_ulnow = -1;
00045 (void)clientp;
00046 (void)dltotal;
00047 (void)dlnow;
00048
00049
00050
00051
00052
00053 if((prev_ultotal != (int)ultotal) ||
00054 (prev_ulnow != (int)ulnow)) {
00055
00056 moo = fopen(libtest_arg2, "ab");
00057 if(moo) {
00058 fprintf(moo, "Progress callback called with UL %d out of %d\n",
00059 (int)ulnow, (int)ultotal);
00060 fclose(moo);
00061 }
00062 prev_ulnow = (int) ulnow;
00063 prev_ultotal = (int) ultotal;
00064 }
00065 return 0;
00066 }
00067
00068 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
00069 {
00070 struct WriteThis *pooh = (struct WriteThis *)userp;
00071 const char *data;
00072
00073 if(size*nmemb < 1)
00074 return 0;
00075
00076 data = post[pooh->counter];
00077
00078 if(data) {
00079 size_t len = strlen(data);
00080 memcpy(ptr, data, len);
00081 pooh->counter++;
00082 return len;
00083 }
00084 return 0;
00085 }
00086
00087 int test(char *URL)
00088 {
00089 CURL *curl;
00090 CURLcode res=CURLE_OK;
00091 struct curl_slist *slist = NULL;
00092 struct WriteThis pooh;
00093 pooh.counter = 0;
00094
00095 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00096 fprintf(stderr, "curl_global_init() failed\n");
00097 return TEST_ERR_MAJOR_BAD;
00098 }
00099
00100 curl = curl_easy_init();
00101 if(!curl) {
00102 fprintf(stderr, "curl_easy_init() failed\n");
00103 curl_global_cleanup();
00104 return TEST_ERR_MAJOR_BAD;
00105 }
00106
00107 slist = curl_slist_append(slist, "Transfer-Encoding: chunked");
00108 if(slist == NULL) {
00109 fprintf(stderr, "curl_slist_append() failed\n");
00110 curl_easy_cleanup(curl);
00111 curl_global_cleanup();
00112 return TEST_ERR_MAJOR_BAD;
00113 }
00114
00115
00116 test_setopt(curl, CURLOPT_URL, URL);
00117
00118
00119 test_setopt(curl, CURLOPT_POST, 1L);
00120
00121 #ifdef CURL_DOES_CONVERSIONS
00122
00123 test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
00124 #endif
00125
00126
00127 test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
00128
00129
00130 test_setopt(curl, CURLOPT_READDATA, &pooh);
00131
00132
00133 test_setopt(curl, CURLOPT_VERBOSE, 1L);
00134
00135
00136 test_setopt(curl, CURLOPT_HEADER, 1L);
00137
00138
00139 test_setopt(curl, CURLOPT_HTTPHEADER, slist);
00140
00141 test_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_DIGEST);
00142 test_setopt(curl, CURLOPT_USERPWD, "foo:bar");
00143
00144
00145 test_setopt(curl, CURLOPT_NOPROGRESS, 0L);
00146 test_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
00147
00148
00149 res = curl_easy_perform(curl);
00150
00151 test_cleanup:
00152
00153
00154 if(slist)
00155 curl_slist_free_all(slist);
00156
00157
00158 curl_easy_cleanup(curl);
00159 curl_global_cleanup();
00160
00161 return res;
00162 }