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 "testutil.h"
00025 #include "warnless.h"
00026 #include "memdebug.h"
00027
00028
00029
00030
00031 #define USERNAME "user@example.com"
00032 #define PASSWORD "123qwerty"
00033 #define RECIPIENT "<1507-recipient@example.com>"
00034 #define MAILFROM "<1507-realuser@example.com>"
00035
00036 #define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
00037
00038 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
00039 {
00040 (void)ptr;
00041 (void)size;
00042 (void)nmemb;
00043 (void)userp;
00044 return CURL_READFUNC_ABORT;
00045 }
00046
00047 static struct timeval tvnow(void)
00048 {
00049
00050
00051
00052 struct timeval now;
00053 now.tv_sec = (long)time(NULL);
00054 now.tv_usec = 0;
00055 return now;
00056 }
00057
00058 static long tvdiff(struct timeval newer, struct timeval older)
00059 {
00060 return (newer.tv_sec-older.tv_sec)*1000+
00061 (newer.tv_usec-older.tv_usec)/1000;
00062 }
00063
00064 int test(char *URL)
00065 {
00066 int res = 0;
00067 CURL *curl = NULL;
00068 CURLM *mcurl = NULL;
00069 int still_running = 1;
00070 struct timeval mp_start;
00071 struct curl_slist *rcpt_list = NULL;
00072
00073 curl_global_init(CURL_GLOBAL_DEFAULT);
00074
00075 easy_init(curl);
00076
00077 multi_init(mcurl);
00078
00079 rcpt_list = curl_slist_append(rcpt_list, RECIPIENT);
00080
00081
00082
00083
00084 curl_easy_setopt(curl, CURLOPT_URL, URL);
00085 #if 0
00086 curl_easy_setopt(curl, CURLOPT_USERNAME, USERNAME);
00087 curl_easy_setopt(curl, CURLOPT_PASSWORD, PASSWORD);
00088 #endif
00089 curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
00090 curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
00091 curl_easy_setopt(curl, CURLOPT_MAIL_FROM, MAILFROM);
00092 curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, rcpt_list);
00093 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
00094 multi_add_handle(mcurl, curl);
00095
00096 mp_start = tvnow();
00097
00098
00099 curl_multi_perform(mcurl, &still_running);
00100
00101 while(still_running) {
00102 struct timeval timeout;
00103 int rc;
00104
00105 fd_set fdread;
00106 fd_set fdwrite;
00107 fd_set fdexcep;
00108 int maxfd = -1;
00109
00110 long curl_timeo = -1;
00111
00112 FD_ZERO(&fdread);
00113 FD_ZERO(&fdwrite);
00114 FD_ZERO(&fdexcep);
00115
00116
00117 timeout.tv_sec = 1;
00118 timeout.tv_usec = 0;
00119
00120 curl_multi_timeout(mcurl, &curl_timeo);
00121 if(curl_timeo >= 0) {
00122 timeout.tv_sec = curl_timeo / 1000;
00123 if(timeout.tv_sec > 1)
00124 timeout.tv_sec = 1;
00125 else
00126 timeout.tv_usec = (curl_timeo % 1000) * 1000;
00127 }
00128
00129
00130 curl_multi_fdset(mcurl, &fdread, &fdwrite, &fdexcep, &maxfd);
00131
00132
00133
00134
00135
00136
00137
00138 rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
00139
00140 if(tvdiff(tvnow(), mp_start) > MULTI_PERFORM_HANG_TIMEOUT) {
00141 fprintf(stderr, "ABORTING TEST, since it seems "
00142 "that it would have run forever.\n");
00143 break;
00144 }
00145
00146 switch(rc) {
00147 case -1:
00148
00149 break;
00150 case 0:
00151 default:
00152 curl_multi_perform(mcurl, &still_running);
00153 break;
00154 }
00155 }
00156
00157 test_cleanup:
00158
00159 curl_slist_free_all(rcpt_list);
00160 curl_multi_remove_handle(mcurl, curl);
00161 curl_multi_cleanup(mcurl);
00162 curl_easy_cleanup(curl);
00163 curl_global_cleanup();
00164
00165 return res;
00166 }
00167
00168