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 char data[]="this is what we post to the silly web server\n";
00027
00028 struct WriteThis {
00029 char *readptr;
00030 size_t sizeleft;
00031 };
00032
00033 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
00034 {
00035 struct WriteThis *pooh = (struct WriteThis *)userp;
00036 size_t tocopy = size * nmemb;
00037
00038
00039
00040 wait_ms(1000);
00041
00042 if(tocopy < 1 || !pooh->sizeleft)
00043 return 0;
00044
00045 if(pooh->sizeleft < tocopy)
00046 tocopy = pooh->sizeleft;
00047
00048 memcpy(ptr, pooh->readptr, tocopy);
00049 pooh->readptr += tocopy;
00050 pooh->sizeleft -= tocopy;
00051 return tocopy;
00052 }
00053
00054 int test(char *URL)
00055 {
00056 CURL *curl;
00057 CURLcode res=CURLE_OK;
00058
00059 struct WriteThis pooh;
00060
00061 pooh.readptr = data;
00062 pooh.sizeleft = strlen(data);
00063
00064 if(curl_global_init(CURL_GLOBAL_ALL)) {
00065 fprintf(stderr, "curl_global_init() failed\n");
00066 return TEST_ERR_MAJOR_BAD;
00067 }
00068
00069 curl = curl_easy_init();
00070 if(!curl) {
00071 fprintf(stderr, "curl_easy_init() failed\n");
00072 curl_global_cleanup();
00073 return TEST_ERR_MAJOR_BAD;
00074 }
00075
00076
00077 test_setopt(curl, CURLOPT_URL, URL);
00078
00079
00080 test_setopt(curl, CURLOPT_POST, 1L);
00081
00082 #ifdef CURL_DOES_CONVERSIONS
00083
00084 test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
00085 #endif
00086
00087
00088 test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)pooh.sizeleft);
00089
00090
00091 test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
00092
00093
00094 test_setopt(curl, CURLOPT_READDATA, &pooh);
00095
00096
00097 test_setopt(curl, CURLOPT_VERBOSE, 1L);
00098
00099
00100 test_setopt(curl, CURLOPT_HEADER, 1L);
00101
00102
00103
00104
00105
00106
00107 res = curl_easy_perform(curl);
00108
00109 test_cleanup:
00110
00111
00112 curl_easy_cleanup(curl);
00113 curl_global_cleanup();
00114
00115 return res;
00116 }