lib556.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at https://curl.haxx.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  ***************************************************************************/
22 #include "test.h"
23 
24 #include "warnless.h"
25 #include "memdebug.h"
26 
27 /* For Windows, mainly (may be moved in a config file?) */
28 #ifndef STDIN_FILENO
29  #define STDIN_FILENO 0
30 #endif
31 #ifndef STDOUT_FILENO
32  #define STDOUT_FILENO 1
33 #endif
34 #ifndef STDERR_FILENO
35  #define STDERR_FILENO 2
36 #endif
37 
38 int test(char *URL)
39 {
40  CURLcode res;
41  CURL *curl;
42 
44  fprintf(stderr, "curl_global_init() failed\n");
45  return TEST_ERR_MAJOR_BAD;
46  }
47 
48  curl = curl_easy_init();
49  if(!curl) {
50  fprintf(stderr, "curl_easy_init() failed\n");
52  return TEST_ERR_MAJOR_BAD;
53  }
54 
55  test_setopt(curl, CURLOPT_URL, URL);
56  test_setopt(curl, CURLOPT_CONNECT_ONLY, 1L);
57  test_setopt(curl, CURLOPT_VERBOSE, 1L);
58 
59  res = curl_easy_perform(curl);
60 
61  if(!res) {
62  /* we are connected, now get a HTTP document the raw way */
63  const char *request =
64 #ifdef CURL_DOES_CONVERSIONS
65  /* ASCII representation with escape sequences for non-ASCII platforms */
66  "\x47\x45\x54\x20\x2f\x35\x35\x36\x20\x48\x54\x54\x50\x2f\x31\x2e"
67  "\x32\x0d\x0a\x48\x6f\x73\x74\x3a\x20\x6e\x69\x6e\x6a\x61\x0d\x0a"
68  "\x0d\x0a";
69 #else
70  "GET /556 HTTP/1.2\r\n"
71  "Host: ninja\r\n\r\n";
72 #endif
73  size_t iolen;
74  char buf[1024];
75 
76  res = curl_easy_send(curl, request, strlen(request), &iolen);
77 
78  if(!res) {
79  /* we assume that sending always work */
80 
81  do {
82  /* busy-read like crazy */
83  res = curl_easy_recv(curl, buf, sizeof(buf), &iolen);
84 
85 #ifdef TPF
86  sleep(1); /* avoid ctl-10 dump */
87 #endif
88 
89  if(iolen) {
90  /* send received stuff to stdout */
91  if(!write(STDOUT_FILENO, buf, iolen))
92  break;
93  }
94 
95  } while((res == CURLE_OK && iolen != 0) || (res == CURLE_AGAIN));
96  }
97 
98  if(res != CURLE_OK || iolen != 0)
99  return TEST_ERR_FAILURE;
100  }
101 
102 test_cleanup:
103 
104  curl_easy_cleanup(curl);
106 
107  return (int)res;
108 }
109 
#define test_setopt(A, B, C)
Definition: test.h:47
#define TEST_ERR_FAILURE
Definition: test.h:92
CURL_EXTERN CURLcode curl_easy_send(CURL *curl, const void *buffer, size_t buflen, size_t *n)
CURL_EXTERN CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen, size_t *n)
CURLcode
Definition: curl.h:454
static int res
#define STDOUT_FILENO
Definition: lib556.c:32
#define TEST_ERR_MAJOR_BAD
Definition: test.h:85
CURL_EXTERN CURL * curl_easy_init(void)
Definition: easy.c:343
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
Definition: curl.h:455
int test(char *URL)
Definition: lib556.c:38
CURL_EXTERN CURLcode curl_global_init(long flags)
curl_global_init() globally initializes curl given a bitwise set of the different features of what to...
Definition: easy.c:271
char buf[3]
Definition: unit1398.c:32
void CURL
Definition: curl.h:102
#define fprintf
Definition: curl_printf.h:41
CURL_EXTERN void curl_global_cleanup(void)
curl_global_cleanup() globally cleanups curl, uses the value of "init_flags" to determine what needs ...
Definition: easy.c:312
#define CURL_GLOBAL_ALL
Definition: curl.h:2519
static CURL * curl
Definition: sessioninfo.c:35
CURL_EXTERN CURLcode curl_easy_perform(CURL *curl)


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:15