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 #include "test.h"
00028
00029 #include "memdebug.h"
00030
00031 static char data[]="dummy";
00032
00033 struct WriteThis {
00034 char *readptr;
00035 size_t sizeleft;
00036 };
00037
00038 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
00039 {
00040 struct WriteThis *pooh = (struct WriteThis *)userp;
00041
00042 if(size*nmemb < 1)
00043 return 0;
00044
00045 if(pooh->sizeleft) {
00046 *(char *)ptr = pooh->readptr[0];
00047 pooh->readptr++;
00048 pooh->sizeleft--;
00049 return 1;
00050 }
00051
00052 return 0;
00053 }
00054
00055 int test(char *URL)
00056 {
00057 CURL *curl;
00058 CURLcode result = CURLE_OK;
00059 int res = 0;
00060 struct WriteThis pooh = { data, sizeof(data)-1 };
00061
00062 global_init(CURL_GLOBAL_ALL);
00063
00064 easy_init(curl);
00065
00066 easy_setopt(curl, CURLOPT_URL, URL);
00067 easy_setopt(curl, CURLOPT_POST, 1L);
00068
00069 easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
00070 easy_setopt(curl, CURLOPT_READDATA, &pooh);
00071
00072 result = curl_easy_perform(curl);
00073
00074 test_cleanup:
00075
00076 curl_easy_cleanup(curl);
00077 curl_global_cleanup();
00078
00079 return (int)result;
00080 }