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 "warnless.h"
00025 #include "memdebug.h"
00026
00027
00028 #ifndef STDIN_FILENO
00029 #define STDIN_FILENO 0
00030 #endif
00031 #ifndef STDOUT_FILENO
00032 #define STDOUT_FILENO 1
00033 #endif
00034 #ifndef STDERR_FILENO
00035 #define STDERR_FILENO 2
00036 #endif
00037
00038 int test(char *URL)
00039 {
00040 CURLcode res;
00041 CURL *curl;
00042
00043 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00044 fprintf(stderr, "curl_global_init() failed\n");
00045 return TEST_ERR_MAJOR_BAD;
00046 }
00047
00048 curl = curl_easy_init();
00049 if(!curl) {
00050 fprintf(stderr, "curl_easy_init() failed\n");
00051 curl_global_cleanup();
00052 return TEST_ERR_MAJOR_BAD;
00053 }
00054
00055 test_setopt(curl, CURLOPT_URL, URL);
00056 test_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
00057 test_setopt(curl, CURLOPT_VERBOSE, 1L);
00058
00059 res = curl_easy_perform(curl);
00060
00061 if(!res) {
00062
00063 const char *request =
00064 #ifdef CURL_DOES_CONVERSIONS
00065
00066 "\x47\x45\x54\x20\x2f\x35\x35\x36\x20\x48\x54\x54\x50\x2f\x31\x2e"
00067 "\x32\x0d\x0a\x48\x6f\x73\x74\x3a\x20\x6e\x69\x6e\x6a\x61\x0d\x0a"
00068 "\x0d\x0a";
00069 #else
00070 "GET /556 HTTP/1.2\r\n"
00071 "Host: ninja\r\n\r\n";
00072 #endif
00073 size_t iolen;
00074 char buf[1024];
00075
00076 res = curl_easy_send(curl, request, strlen(request), &iolen);
00077
00078 if(!res) {
00079
00080
00081 do {
00082
00083 res = curl_easy_recv(curl, buf, sizeof(buf), &iolen);
00084
00085 #ifdef TPF
00086 sleep(1);
00087 #endif
00088
00089 if(iolen) {
00090
00091 if(!write(STDOUT_FILENO, buf, iolen))
00092 break;
00093 }
00094
00095 } while((res == CURLE_OK && iolen != 0) || (res == CURLE_AGAIN));
00096 }
00097
00098 if(res != CURLE_OK || iolen != 0)
00099 return TEST_ERR_FAILURE;
00100 }
00101
00102 test_cleanup:
00103
00104 curl_easy_cleanup(curl);
00105 curl_global_cleanup();
00106
00107 return (int)res;
00108 }
00109