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 #ifdef CURL_DOES_CONVERSIONS
00032
00033 # define UPLOADTHIS "\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x62" \
00034 "\x6c\x75\x72\x62\x20\x77\x65\x20\x77\x61\x6e\x74\x20" \
00035 "\x74\x6f\x20\x75\x70\x6c\x6f\x61\x64\x0a"
00036 #else
00037 # define UPLOADTHIS "this is the blurb we want to upload\n"
00038 #endif
00039
00040 #ifndef LIB548
00041 static size_t readcallback(void *ptr,
00042 size_t size,
00043 size_t nmemb,
00044 void *clientp)
00045 {
00046 int *counter = (int *)clientp;
00047
00048 if(*counter) {
00049
00050 fprintf(stderr, "READ ALREADY DONE!\n");
00051 return 0;
00052 }
00053 (*counter)++;
00054
00055 if(size * nmemb > strlen(UPLOADTHIS)) {
00056 fprintf(stderr, "READ!\n");
00057 strcpy(ptr, UPLOADTHIS);
00058 return strlen(UPLOADTHIS);
00059 }
00060 fprintf(stderr, "READ NOT FINE!\n");
00061 return 0;
00062 }
00063 static curlioerr ioctlcallback(CURL *handle,
00064 int cmd,
00065 void *clientp)
00066 {
00067 int *counter = (int *)clientp;
00068 (void)handle;
00069 if(cmd == CURLIOCMD_RESTARTREAD) {
00070 fprintf(stderr, "REWIND!\n");
00071 *counter = 0;
00072 }
00073 return CURLIOE_OK;
00074 }
00075
00076
00077
00078 #endif
00079
00080 int test(char *URL)
00081 {
00082 CURLcode res;
00083 CURL *curl;
00084 #ifndef LIB548
00085 int counter=0;
00086 #endif
00087
00088 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00089 fprintf(stderr, "curl_global_init() failed\n");
00090 return TEST_ERR_MAJOR_BAD;
00091 }
00092
00093 curl = curl_easy_init();
00094 if(!curl) {
00095 fprintf(stderr, "curl_easy_init() failed\n");
00096 curl_global_cleanup();
00097 return TEST_ERR_MAJOR_BAD;
00098 }
00099
00100 test_setopt(curl, CURLOPT_URL, URL);
00101 test_setopt(curl, CURLOPT_VERBOSE, 1L);
00102 test_setopt(curl, CURLOPT_HEADER, 1L);
00103 #ifdef LIB548
00104
00105 test_setopt(curl, CURLOPT_POSTFIELDS, UPLOADTHIS);
00106 #else
00107
00108 test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
00109 test_setopt(curl, CURLOPT_IOCTLDATA, &counter);
00110 test_setopt(curl, CURLOPT_READFUNCTION, readcallback);
00111 test_setopt(curl, CURLOPT_READDATA, &counter);
00112
00113
00114 test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(UPLOADTHIS));
00115 #endif
00116 test_setopt(curl, CURLOPT_POST, 1L);
00117 test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
00118 test_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
00119 test_setopt(curl, CURLOPT_PROXYAUTH,
00120 (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
00121
00122 res = curl_easy_perform(curl);
00123
00124 test_cleanup:
00125
00126 curl_easy_cleanup(curl);
00127 curl_global_cleanup();
00128
00129 return (int)res;
00130 }
00131