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