VirtualBox

source: vbox/trunk/src/libs/curl-8.7.1/lib/curl_trc.c@ 107400

最後變更 在這個檔案從107400是 107400,由 vboxsync 提交於 8 週 前

bugref:

檔案大小: 6.8 KB
 
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <[email protected]>, 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.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 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24
25#include "curl_setup.h"
26
27#include <curl/curl.h>
28
29#include "curl_trc.h"
30#include "urldata.h"
31#include "easyif.h"
32#include "cfilters.h"
33#include "timeval.h"
34#include "multiif.h"
35#include "strcase.h"
36
37#include "cf-socket.h"
38#include "connect.h"
39#include "doh.h"
40#include "http2.h"
41#include "http_proxy.h"
42#include "cf-h1-proxy.h"
43#include "cf-h2-proxy.h"
44#include "cf-haproxy.h"
45#include "cf-https-connect.h"
46#include "socks.h"
47#include "strtok.h"
48#include "vtls/vtls.h"
49#include "vquic/vquic.h"
50
51/* The last 3 #include files should be in this order */
52#include "curl_printf.h"
53#include "curl_memory.h"
54#include "memdebug.h"
55
56
57void Curl_debug(struct Curl_easy *data, curl_infotype type,
58 char *ptr, size_t size)
59{
60 if(data->set.verbose) {
61 static const char s_infotype[CURLINFO_END][3] = {
62 "* ", "< ", "> ", "{ ", "} ", "{ ", "} " };
63 if(data->set.fdebug) {
64 bool inCallback = Curl_is_in_callback(data);
65 Curl_set_in_callback(data, true);
66 (void)(*data->set.fdebug)(data, type, ptr, size, data->set.debugdata);
67 Curl_set_in_callback(data, inCallback);
68 }
69 else {
70 switch(type) {
71 case CURLINFO_TEXT:
72 case CURLINFO_HEADER_OUT:
73 case CURLINFO_HEADER_IN:
74 case CURLINFO_DATA_IN: /* XXX: uwe */
75 case CURLINFO_DATA_OUT: /* XXX: uwe */
76 fwrite(s_infotype[type], 2, 1, data->set.err);
77 fwrite(ptr, size, 1, data->set.err);
78 break;
79 default: /* nada */
80 break;
81 }
82 }
83 }
84}
85
86
87/* Curl_failf() is for messages stating why we failed.
88 * The message SHALL NOT include any LF or CR.
89 */
90void Curl_failf(struct Curl_easy *data, const char *fmt, ...)
91{
92 DEBUGASSERT(!strchr(fmt, '\n'));
93 if(data->set.verbose || data->set.errorbuffer) {
94 va_list ap;
95 int len;
96 char error[CURL_ERROR_SIZE + 2];
97 va_start(ap, fmt);
98 len = mvsnprintf(error, CURL_ERROR_SIZE, fmt, ap);
99
100 if(data->set.errorbuffer && !data->state.errorbuf) {
101 strcpy(data->set.errorbuffer, error);
102 data->state.errorbuf = TRUE; /* wrote error string */
103 }
104 error[len++] = '\n';
105 error[len] = '\0';
106 Curl_debug(data, CURLINFO_TEXT, error, len);
107 va_end(ap);
108 }
109}
110
111#if !defined(CURL_DISABLE_VERBOSE_STRINGS)
112
113/* Curl_infof() is for info message along the way */
114#define MAXINFO 2048
115
116void Curl_infof(struct Curl_easy *data, const char *fmt, ...)
117{
118 DEBUGASSERT(!strchr(fmt, '\n'));
119 if(Curl_trc_is_verbose(data)) {
120 va_list ap;
121 int len = 0;
122 char buffer[MAXINFO + 2];
123 if(data->state.feat)
124 len = msnprintf(buffer, MAXINFO, "[%s] ", data->state.feat->name);
125 va_start(ap, fmt);
126 len += mvsnprintf(buffer + len, MAXINFO - len, fmt, ap);
127 va_end(ap);
128 buffer[len++] = '\n';
129 buffer[len] = '\0';
130 Curl_debug(data, CURLINFO_TEXT, buffer, len);
131 }
132}
133
134void Curl_trc_cf_infof(struct Curl_easy *data, struct Curl_cfilter *cf,
135 const char *fmt, ...)
136{
137 DEBUGASSERT(cf);
138 if(Curl_trc_cf_is_verbose(cf, data)) {
139 va_list ap;
140 int len = 0;
141 char buffer[MAXINFO + 2];
142 if(data->state.feat)
143 len += msnprintf(buffer + len, MAXINFO - len, "[%s] ",
144 data->state.feat->name);
145 if(cf->sockindex)
146 len += msnprintf(buffer + len, MAXINFO - len, "[%s-%d] ",
147 cf->cft->name, cf->sockindex);
148 else
149 len += msnprintf(buffer + len, MAXINFO - len, "[%s] ", cf->cft->name);
150 va_start(ap, fmt);
151 len += mvsnprintf(buffer + len, MAXINFO - len, fmt, ap);
152 va_end(ap);
153 buffer[len++] = '\n';
154 buffer[len] = '\0';
155 Curl_debug(data, CURLINFO_TEXT, buffer, len);
156 }
157}
158
159static struct curl_trc_feat *trc_feats[] = {
160#ifndef CURL_DISABLE_DOH
161 &Curl_doh_trc,
162#endif
163 NULL,
164};
165
166static struct Curl_cftype *cf_types[] = {
167 &Curl_cft_tcp,
168 &Curl_cft_udp,
169 &Curl_cft_unix,
170 &Curl_cft_tcp_accept,
171 &Curl_cft_happy_eyeballs,
172 &Curl_cft_setup,
173#ifdef USE_NGHTTP2
174 &Curl_cft_nghttp2,
175#endif
176#ifdef USE_SSL
177 &Curl_cft_ssl,
178#ifndef CURL_DISABLE_PROXY
179 &Curl_cft_ssl_proxy,
180#endif
181#endif
182#if !defined(CURL_DISABLE_PROXY)
183#if !defined(CURL_DISABLE_HTTP)
184 &Curl_cft_h1_proxy,
185#ifdef USE_NGHTTP2
186 &Curl_cft_h2_proxy,
187#endif
188 &Curl_cft_http_proxy,
189#endif /* !CURL_DISABLE_HTTP */
190 &Curl_cft_haproxy,
191 &Curl_cft_socks_proxy,
192#endif /* !CURL_DISABLE_PROXY */
193#ifdef ENABLE_QUIC
194 &Curl_cft_http3,
195#endif
196#if !defined(CURL_DISABLE_HTTP) && !defined(USE_HYPER)
197 &Curl_cft_http_connect,
198#endif
199 NULL,
200};
201
202CURLcode Curl_trc_opt(const char *config)
203{
204 char *token, *tok_buf, *tmp;
205 size_t i;
206 int lvl;
207
208 tmp = strdup(config);
209 if(!tmp)
210 return CURLE_OUT_OF_MEMORY;
211
212 token = strtok_r(tmp, ", ", &tok_buf);
213 while(token) {
214 switch(*token) {
215 case '-':
216 lvl = CURL_LOG_LVL_NONE;
217 ++token;
218 break;
219 case '+':
220 lvl = CURL_LOG_LVL_INFO;
221 ++token;
222 break;
223 default:
224 lvl = CURL_LOG_LVL_INFO;
225 break;
226 }
227 for(i = 0; cf_types[i]; ++i) {
228 if(strcasecompare(token, "all")) {
229 cf_types[i]->log_level = lvl;
230 }
231 else if(strcasecompare(token, cf_types[i]->name)) {
232 cf_types[i]->log_level = lvl;
233 break;
234 }
235 }
236 for(i = 0; trc_feats[i]; ++i) {
237 if(strcasecompare(token, "all")) {
238 trc_feats[i]->log_level = lvl;
239 }
240 else if(strcasecompare(token, trc_feats[i]->name)) {
241 trc_feats[i]->log_level = lvl;
242 break;
243 }
244 }
245 token = strtok_r(NULL, ", ", &tok_buf);
246 }
247 free(tmp);
248 return CURLE_OK;
249}
250
251CURLcode Curl_trc_init(void)
252{
253#ifdef DEBUGBUILD
254 /* WIP: we use the auto-init from an env var only in DEBUG builds for
255 * convenience. */
256 const char *config = getenv("CURL_DEBUG");
257 if(config) {
258 return Curl_trc_opt(config);
259 }
260#endif /* DEBUGBUILD */
261 return CURLE_OK;
262}
263#else /* defined(CURL_DISABLE_VERBOSE_STRINGS) */
264
265CURLcode Curl_trc_init(void)
266{
267 return CURLE_OK;
268}
269
270#endif /* !defined(CURL_DISABLE_VERBOSE_STRINGS) */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette