lib556.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "test.h"
00023 
00024 #include "warnless.h"
00025 #include "memdebug.h"
00026 
00027 /* For Windows, mainly (may be moved in a config file?) */
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     /* we are connected, now get a HTTP document the raw way */
00063     const char *request =
00064 #ifdef CURL_DOES_CONVERSIONS
00065       /* ASCII representation with escape sequences for non-ASCII platforms */
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       /* we assume that sending always work */
00080 
00081       do {
00082         /* busy-read like crazy */
00083         res = curl_easy_recv(curl, buf, sizeof(buf), &iolen);
00084 
00085 #ifdef TPF
00086         sleep(1); /* avoid ctl-10 dump */
00087 #endif
00088 
00089         if(iolen) {
00090           /* send received stuff to stdout */
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 


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05