curl_trc.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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. #include "curl_setup.h"
  25. #include <curl/curl.h>
  26. #include "curl_trc.h"
  27. #include "urldata.h"
  28. #include "easyif.h"
  29. #include "cfilters.h"
  30. #include "multiif.h"
  31. #include "cf-socket.h"
  32. #include "connect.h"
  33. #include "doh.h"
  34. #include "http2.h"
  35. #include "http_proxy.h"
  36. #include "cf-h1-proxy.h"
  37. #include "cf-h2-proxy.h"
  38. #include "cf-haproxy.h"
  39. #include "cf-https-connect.h"
  40. #include "cf-ip-happy.h"
  41. #include "socks.h"
  42. #include "curlx/strparse.h"
  43. #include "vtls/vtls.h"
  44. #include "vquic/vquic.h"
  45. /* The last 3 #include files should be in this order */
  46. #include "curl_printf.h"
  47. #include "curl_memory.h"
  48. #include "memdebug.h"
  49. static void trc_write(struct Curl_easy *data, curl_infotype type,
  50. const char *ptr, size_t size)
  51. {
  52. if(data->set.verbose) {
  53. if(data->set.fdebug) {
  54. bool inCallback = Curl_is_in_callback(data);
  55. Curl_set_in_callback(data, TRUE);
  56. (void)(*data->set.fdebug)(data, type, CURL_UNCONST(ptr), size,
  57. data->set.debugdata);
  58. Curl_set_in_callback(data, inCallback);
  59. }
  60. else {
  61. static const char s_infotype[CURLINFO_END][3] = {
  62. "* ", "< ", "> ", "{ ", "} ", "{ ", "} " };
  63. switch(type) {
  64. case CURLINFO_TEXT:
  65. case CURLINFO_HEADER_OUT:
  66. case CURLINFO_HEADER_IN:
  67. fwrite(s_infotype[type], 2, 1, data->set.err);
  68. fwrite(ptr, size, 1, data->set.err);
  69. break;
  70. default: /* nada */
  71. break;
  72. }
  73. }
  74. }
  75. }
  76. /* max length we trace before ending in '...' */
  77. #define TRC_LINE_MAX 2048
  78. #define CURL_TRC_FMT_IDSC "[x-%" CURL_FORMAT_CURL_OFF_T "] "
  79. #define CURL_TRC_FMT_IDSD "[%" CURL_FORMAT_CURL_OFF_T "-x] "
  80. #define CURL_TRC_FMT_IDSDC "[%" CURL_FORMAT_CURL_OFF_T "-%" \
  81. CURL_FORMAT_CURL_OFF_T "] "
  82. static struct curl_trc_feat Curl_trc_feat_ids = {
  83. "LIB-IDS",
  84. CURL_LOG_LVL_NONE,
  85. };
  86. #define CURL_TRC_IDS(data) \
  87. (Curl_trc_is_verbose(data) && \
  88. Curl_trc_feat_ids.log_level >= CURL_LOG_LVL_INFO)
  89. static size_t trc_print_ids(struct Curl_easy *data, char *buf, size_t maxlen)
  90. {
  91. curl_off_t cid = data->conn ?
  92. data->conn->connection_id : data->state.recent_conn_id;
  93. if(data->id >= 0) {
  94. if(cid >= 0)
  95. return msnprintf(buf, maxlen, CURL_TRC_FMT_IDSDC, data->id, cid);
  96. else
  97. return msnprintf(buf, maxlen, CURL_TRC_FMT_IDSD, data->id);
  98. }
  99. else if(cid >= 0)
  100. return msnprintf(buf, maxlen, CURL_TRC_FMT_IDSC, cid);
  101. else {
  102. return msnprintf(buf, maxlen, "[x-x] ");
  103. }
  104. }
  105. static size_t trc_end_buf(char *buf, size_t len, size_t maxlen, bool addnl)
  106. {
  107. /* make sure we end the trace line in `buf` properly. It needs
  108. * to end with a terminating '\0' or '\n\0' */
  109. if(len >= (maxlen - (addnl ? 2 : 1))) {
  110. len = maxlen - 5;
  111. buf[len++] = '.';
  112. buf[len++] = '.';
  113. buf[len++] = '.';
  114. buf[len++] = '\n';
  115. }
  116. else if(addnl)
  117. buf[len++] = '\n';
  118. buf[len] = '\0';
  119. return len;
  120. }
  121. void Curl_debug(struct Curl_easy *data, curl_infotype type,
  122. const char *ptr, size_t size)
  123. {
  124. if(data->set.verbose) {
  125. static const char s_infotype[CURLINFO_END][3] = {
  126. "* ", "< ", "> ", "{ ", "} ", "{ ", "} " };
  127. char buf[TRC_LINE_MAX];
  128. size_t len;
  129. if(data->set.fdebug) {
  130. bool inCallback = Curl_is_in_callback(data);
  131. if(CURL_TRC_IDS(data) && (size < TRC_LINE_MAX)) {
  132. len = trc_print_ids(data, buf, TRC_LINE_MAX);
  133. len += msnprintf(buf + len, TRC_LINE_MAX - len, "%.*s",
  134. (int)size, ptr);
  135. len = trc_end_buf(buf, len, TRC_LINE_MAX, FALSE);
  136. Curl_set_in_callback(data, TRUE);
  137. (void)(*data->set.fdebug)(data, type, buf, len, data->set.debugdata);
  138. Curl_set_in_callback(data, inCallback);
  139. }
  140. else {
  141. Curl_set_in_callback(data, TRUE);
  142. (void)(*data->set.fdebug)(data, type, CURL_UNCONST(ptr),
  143. size, data->set.debugdata);
  144. Curl_set_in_callback(data, inCallback);
  145. }
  146. }
  147. else {
  148. switch(type) {
  149. case CURLINFO_TEXT:
  150. case CURLINFO_HEADER_OUT:
  151. case CURLINFO_HEADER_IN:
  152. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  153. if(CURL_TRC_IDS(data)) {
  154. len = trc_print_ids(data, buf, TRC_LINE_MAX);
  155. fwrite(buf, len, 1, data->set.err);
  156. }
  157. #endif
  158. fwrite(s_infotype[type], 2, 1, data->set.err);
  159. fwrite(ptr, size, 1, data->set.err);
  160. break;
  161. default: /* nada */
  162. break;
  163. }
  164. }
  165. }
  166. }
  167. /* Curl_failf() is for messages stating why we failed.
  168. * The message SHALL NOT include any LF or CR.
  169. */
  170. void Curl_failf(struct Curl_easy *data, const char *fmt, ...)
  171. {
  172. DEBUGASSERT(!strchr(fmt, '\n'));
  173. if(data->set.verbose || data->set.errorbuffer) {
  174. va_list ap;
  175. size_t len;
  176. char error[CURL_ERROR_SIZE + 2];
  177. va_start(ap, fmt);
  178. len = mvsnprintf(error, CURL_ERROR_SIZE, fmt, ap);
  179. if(data->set.errorbuffer && !data->state.errorbuf) {
  180. strcpy(data->set.errorbuffer, error);
  181. data->state.errorbuf = TRUE; /* wrote error string */
  182. }
  183. error[len++] = '\n';
  184. error[len] = '\0';
  185. trc_write(data, CURLINFO_TEXT, error, len);
  186. va_end(ap);
  187. }
  188. }
  189. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  190. static void trc_infof(struct Curl_easy *data,
  191. struct curl_trc_feat *feat,
  192. const char *opt_id, int opt_id_idx,
  193. const char * const fmt, va_list ap) CURL_PRINTF(5, 0);
  194. static void trc_infof(struct Curl_easy *data,
  195. struct curl_trc_feat *feat,
  196. const char *opt_id, int opt_id_idx,
  197. const char * const fmt, va_list ap)
  198. {
  199. size_t len = 0;
  200. char buf[TRC_LINE_MAX];
  201. if(CURL_TRC_IDS(data))
  202. len += trc_print_ids(data, buf + len, TRC_LINE_MAX - len);
  203. if(feat)
  204. len += msnprintf(buf + len, TRC_LINE_MAX - len, "[%s] ", feat->name);
  205. if(opt_id) {
  206. if(opt_id_idx > 0)
  207. len += msnprintf(buf + len, TRC_LINE_MAX - len, "[%s-%d] ",
  208. opt_id, opt_id_idx);
  209. else
  210. len += msnprintf(buf + len, TRC_LINE_MAX - len, "[%s] ", opt_id);
  211. }
  212. len += mvsnprintf(buf + len, TRC_LINE_MAX - len, fmt, ap);
  213. len = trc_end_buf(buf, len, TRC_LINE_MAX, TRUE);
  214. trc_write(data, CURLINFO_TEXT, buf, len);
  215. }
  216. void Curl_infof(struct Curl_easy *data, const char *fmt, ...)
  217. {
  218. DEBUGASSERT(!strchr(fmt, '\n'));
  219. if(Curl_trc_is_verbose(data)) {
  220. va_list ap;
  221. va_start(ap, fmt);
  222. trc_infof(data, data->state.feat, NULL, 0, fmt, ap);
  223. va_end(ap);
  224. }
  225. }
  226. void Curl_trc_cf_infof(struct Curl_easy *data, const struct Curl_cfilter *cf,
  227. const char *fmt, ...)
  228. {
  229. DEBUGASSERT(cf);
  230. if(Curl_trc_cf_is_verbose(cf, data)) {
  231. va_list ap;
  232. va_start(ap, fmt);
  233. trc_infof(data, data->state.feat, cf->cft->name, cf->sockindex, fmt, ap);
  234. va_end(ap);
  235. }
  236. }
  237. struct curl_trc_feat Curl_trc_feat_multi = {
  238. "MULTI",
  239. CURL_LOG_LVL_NONE,
  240. };
  241. struct curl_trc_feat Curl_trc_feat_read = {
  242. "READ",
  243. CURL_LOG_LVL_NONE,
  244. };
  245. struct curl_trc_feat Curl_trc_feat_write = {
  246. "WRITE",
  247. CURL_LOG_LVL_NONE,
  248. };
  249. struct curl_trc_feat Curl_trc_feat_dns = {
  250. "DNS",
  251. CURL_LOG_LVL_NONE,
  252. };
  253. static const char * const Curl_trc_timer_names[]={
  254. "100_TIMEOUT",
  255. "ASYNC_NAME",
  256. "CONNECTTIMEOUT",
  257. "DNS_PER_NAME",
  258. "DNS_PER_NAME2",
  259. "HAPPY_EYEBALLS_DNS",
  260. "HAPPY_EYEBALLS",
  261. "MULTI_PENDING",
  262. "SPEEDCHECK",
  263. "TIMEOUT",
  264. "TOOFAST",
  265. "QUIC",
  266. "FTP_ACCEPT",
  267. "ALPN_EYEBALLS",
  268. "SHUTDOWN",
  269. };
  270. const char *Curl_trc_timer_name(int tid)
  271. {
  272. if((tid >= 0) && ((size_t)tid < CURL_ARRAYSIZE(Curl_trc_timer_names)))
  273. return Curl_trc_timer_names[(size_t)tid];
  274. return "UNKNOWN?";
  275. }
  276. void Curl_trc_multi_timeouts(struct Curl_easy *data)
  277. {
  278. struct Curl_llist_node *e = Curl_llist_head(&data->state.timeoutlist);
  279. if(e) {
  280. struct curltime now = curlx_now();
  281. while(e) {
  282. struct time_node *n = Curl_node_elem(e);
  283. e = Curl_node_next(e);
  284. CURL_TRC_M(data, "[TIMEOUT] %s expires in %" FMT_TIMEDIFF_T "ns",
  285. CURL_TIMER_NAME(n->eid),
  286. curlx_timediff_us(n->time, now));
  287. }
  288. }
  289. }
  290. static const char * const Curl_trc_mstate_names[]={
  291. "INIT",
  292. "PENDING",
  293. "SETUP",
  294. "CONNECT",
  295. "RESOLVING",
  296. "CONNECTING",
  297. "TUNNELING",
  298. "PROTOCONNECT",
  299. "PROTOCONNECTING",
  300. "DO",
  301. "DOING",
  302. "DOING_MORE",
  303. "DID",
  304. "PERFORMING",
  305. "RATELIMITING",
  306. "DONE",
  307. "COMPLETED",
  308. "MSGSENT",
  309. };
  310. const char *Curl_trc_mstate_name(int state)
  311. {
  312. if((state >= 0) && ((size_t)state < CURL_ARRAYSIZE(Curl_trc_mstate_names)))
  313. return Curl_trc_mstate_names[(size_t)state];
  314. return "?";
  315. }
  316. void Curl_trc_multi(struct Curl_easy *data, const char *fmt, ...)
  317. {
  318. DEBUGASSERT(!strchr(fmt, '\n'));
  319. if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_multi)) {
  320. const char *sname = (data->id >= 0) ?
  321. Curl_trc_mstate_name(data->mstate) : NULL;
  322. va_list ap;
  323. va_start(ap, fmt);
  324. trc_infof(data, &Curl_trc_feat_multi, sname, 0, fmt, ap);
  325. va_end(ap);
  326. }
  327. }
  328. void Curl_trc_read(struct Curl_easy *data, const char *fmt, ...)
  329. {
  330. DEBUGASSERT(!strchr(fmt, '\n'));
  331. if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_read)) {
  332. va_list ap;
  333. va_start(ap, fmt);
  334. trc_infof(data, &Curl_trc_feat_read, NULL, 0, fmt, ap);
  335. va_end(ap);
  336. }
  337. }
  338. void Curl_trc_write(struct Curl_easy *data, const char *fmt, ...)
  339. {
  340. DEBUGASSERT(!strchr(fmt, '\n'));
  341. if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_write)) {
  342. va_list ap;
  343. va_start(ap, fmt);
  344. trc_infof(data, &Curl_trc_feat_write, NULL, 0, fmt, ap);
  345. va_end(ap);
  346. }
  347. }
  348. void Curl_trc_dns(struct Curl_easy *data, const char *fmt, ...)
  349. {
  350. DEBUGASSERT(!strchr(fmt, '\n'));
  351. if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_dns)) {
  352. va_list ap;
  353. va_start(ap, fmt);
  354. trc_infof(data, &Curl_trc_feat_dns, NULL, 0, fmt, ap);
  355. va_end(ap);
  356. }
  357. }
  358. #ifndef CURL_DISABLE_FTP
  359. struct curl_trc_feat Curl_trc_feat_ftp = {
  360. "FTP",
  361. CURL_LOG_LVL_NONE,
  362. };
  363. void Curl_trc_ftp(struct Curl_easy *data, const char *fmt, ...)
  364. {
  365. DEBUGASSERT(!strchr(fmt, '\n'));
  366. if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ftp)) {
  367. va_list ap;
  368. va_start(ap, fmt);
  369. trc_infof(data, &Curl_trc_feat_ftp, NULL, 0, fmt, ap);
  370. va_end(ap);
  371. }
  372. }
  373. #endif /* !CURL_DISABLE_FTP */
  374. #ifndef CURL_DISABLE_SMTP
  375. struct curl_trc_feat Curl_trc_feat_smtp = {
  376. "SMTP",
  377. CURL_LOG_LVL_NONE,
  378. };
  379. void Curl_trc_smtp(struct Curl_easy *data, const char *fmt, ...)
  380. {
  381. DEBUGASSERT(!strchr(fmt, '\n'));
  382. if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_smtp)) {
  383. va_list ap;
  384. va_start(ap, fmt);
  385. trc_infof(data, &Curl_trc_feat_smtp, NULL, 0, fmt, ap);
  386. va_end(ap);
  387. }
  388. }
  389. #endif /* !CURL_DISABLE_SMTP */
  390. #ifdef USE_SSL
  391. struct curl_trc_feat Curl_trc_feat_ssls = {
  392. "SSLS",
  393. CURL_LOG_LVL_NONE,
  394. };
  395. void Curl_trc_ssls(struct Curl_easy *data, const char *fmt, ...)
  396. {
  397. DEBUGASSERT(!strchr(fmt, '\n'));
  398. if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ssls)) {
  399. va_list ap;
  400. va_start(ap, fmt);
  401. trc_infof(data, &Curl_trc_feat_ssls, NULL, 0, fmt, ap);
  402. va_end(ap);
  403. }
  404. }
  405. #endif /* USE_SSL */
  406. #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
  407. struct curl_trc_feat Curl_trc_feat_ws = {
  408. "WS",
  409. CURL_LOG_LVL_NONE,
  410. };
  411. void Curl_trc_ws(struct Curl_easy *data, const char *fmt, ...)
  412. {
  413. DEBUGASSERT(!strchr(fmt, '\n'));
  414. if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ws)) {
  415. va_list ap;
  416. va_start(ap, fmt);
  417. trc_infof(data, &Curl_trc_feat_ws, NULL, 0, fmt, ap);
  418. va_end(ap);
  419. }
  420. }
  421. #endif /* !CURL_DISABLE_WEBSOCKETS && !CURL_DISABLE_HTTP */
  422. #define TRC_CT_NONE (0)
  423. #define TRC_CT_PROTOCOL (1<<(0))
  424. #define TRC_CT_NETWORK (1<<(1))
  425. #define TRC_CT_PROXY (1<<(2))
  426. #define TRC_CT_INTERNALS (1<<(3))
  427. struct trc_feat_def {
  428. struct curl_trc_feat *feat;
  429. unsigned int category;
  430. };
  431. static struct trc_feat_def trc_feats[] = {
  432. { &Curl_trc_feat_ids, TRC_CT_INTERNALS },
  433. { &Curl_trc_feat_multi, TRC_CT_NETWORK },
  434. { &Curl_trc_feat_read, TRC_CT_NONE },
  435. { &Curl_trc_feat_write, TRC_CT_NONE },
  436. { &Curl_trc_feat_dns, TRC_CT_NETWORK },
  437. #ifndef CURL_DISABLE_FTP
  438. { &Curl_trc_feat_ftp, TRC_CT_PROTOCOL },
  439. #endif
  440. #ifndef CURL_DISABLE_DOH
  441. #endif
  442. #ifndef CURL_DISABLE_SMTP
  443. { &Curl_trc_feat_smtp, TRC_CT_PROTOCOL },
  444. #endif
  445. #ifdef USE_SSL
  446. { &Curl_trc_feat_ssls, TRC_CT_NETWORK },
  447. #endif
  448. #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
  449. { &Curl_trc_feat_ws, TRC_CT_PROTOCOL },
  450. #endif
  451. };
  452. struct trc_cft_def {
  453. struct Curl_cftype *cft;
  454. unsigned int category;
  455. };
  456. static struct trc_cft_def trc_cfts[] = {
  457. { &Curl_cft_tcp, TRC_CT_NETWORK },
  458. { &Curl_cft_udp, TRC_CT_NETWORK },
  459. { &Curl_cft_unix, TRC_CT_NETWORK },
  460. { &Curl_cft_tcp_accept, TRC_CT_NETWORK },
  461. { &Curl_cft_ip_happy, TRC_CT_NETWORK },
  462. { &Curl_cft_setup, TRC_CT_PROTOCOL },
  463. #if !defined(CURL_DISABLE_HTTP) && defined(USE_NGHTTP2)
  464. { &Curl_cft_nghttp2, TRC_CT_PROTOCOL },
  465. #endif
  466. #ifdef USE_SSL
  467. { &Curl_cft_ssl, TRC_CT_NETWORK },
  468. #ifndef CURL_DISABLE_PROXY
  469. { &Curl_cft_ssl_proxy, TRC_CT_PROXY },
  470. #endif
  471. #endif
  472. #ifndef CURL_DISABLE_PROXY
  473. #ifndef CURL_DISABLE_HTTP
  474. { &Curl_cft_h1_proxy, TRC_CT_PROXY },
  475. #ifdef USE_NGHTTP2
  476. { &Curl_cft_h2_proxy, TRC_CT_PROXY },
  477. #endif
  478. { &Curl_cft_http_proxy, TRC_CT_PROXY },
  479. #endif /* !CURL_DISABLE_HTTP */
  480. { &Curl_cft_haproxy, TRC_CT_PROXY },
  481. { &Curl_cft_socks_proxy, TRC_CT_PROXY },
  482. #endif /* !CURL_DISABLE_PROXY */
  483. #if !defined(CURL_DISABLE_HTTP) && defined(USE_HTTP3)
  484. { &Curl_cft_http3, TRC_CT_PROTOCOL },
  485. #endif
  486. #ifndef CURL_DISABLE_HTTP
  487. { &Curl_cft_http_connect, TRC_CT_PROTOCOL },
  488. #endif
  489. };
  490. static void trc_apply_level_by_name(struct Curl_str *token, int lvl)
  491. {
  492. size_t i;
  493. for(i = 0; i < CURL_ARRAYSIZE(trc_cfts); ++i) {
  494. if(curlx_str_casecompare(token, trc_cfts[i].cft->name)) {
  495. trc_cfts[i].cft->log_level = lvl;
  496. break;
  497. }
  498. }
  499. for(i = 0; i < CURL_ARRAYSIZE(trc_feats); ++i) {
  500. if(curlx_str_casecompare(token, trc_feats[i].feat->name)) {
  501. trc_feats[i].feat->log_level = lvl;
  502. break;
  503. }
  504. }
  505. }
  506. static void trc_apply_level_by_category(int category, int lvl)
  507. {
  508. size_t i;
  509. for(i = 0; i < CURL_ARRAYSIZE(trc_cfts); ++i) {
  510. if(!category || (trc_cfts[i].category & category))
  511. trc_cfts[i].cft->log_level = lvl;
  512. }
  513. for(i = 0; i < CURL_ARRAYSIZE(trc_feats); ++i) {
  514. if(!category || (trc_feats[i].category & category))
  515. trc_feats[i].feat->log_level = lvl;
  516. }
  517. }
  518. static CURLcode trc_opt(const char *config)
  519. {
  520. struct Curl_str out;
  521. while(!curlx_str_until(&config, &out, 32, ',')) {
  522. int lvl = CURL_LOG_LVL_INFO;
  523. const char *token = curlx_str(&out);
  524. if(*token == '-') {
  525. lvl = CURL_LOG_LVL_NONE;
  526. curlx_str_nudge(&out, 1);
  527. }
  528. else if(*token == '+')
  529. curlx_str_nudge(&out, 1);
  530. if(curlx_str_casecompare(&out, "all"))
  531. trc_apply_level_by_category(TRC_CT_NONE, lvl);
  532. else if(curlx_str_casecompare(&out, "protocol"))
  533. trc_apply_level_by_category(TRC_CT_PROTOCOL, lvl);
  534. else if(curlx_str_casecompare(&out, "network"))
  535. trc_apply_level_by_category(TRC_CT_NETWORK, lvl);
  536. else if(curlx_str_casecompare(&out, "proxy"))
  537. trc_apply_level_by_category(TRC_CT_PROXY, lvl);
  538. else if(curlx_str_casecompare(&out, "doh")) {
  539. struct Curl_str dns = { "dns", 3 };
  540. trc_apply_level_by_name(&dns, lvl);
  541. }
  542. else
  543. trc_apply_level_by_name(&out, lvl);
  544. if(curlx_str_single(&config, ','))
  545. break;
  546. }
  547. return CURLE_OK;
  548. }
  549. CURLcode Curl_trc_opt(const char *config)
  550. {
  551. CURLcode result = config ? trc_opt(config) : CURLE_OK;
  552. #ifdef DEBUGBUILD
  553. /* CURL_DEBUG can override anything */
  554. if(!result) {
  555. const char *dbg_config = getenv("CURL_DEBUG");
  556. if(dbg_config)
  557. result = trc_opt(dbg_config);
  558. }
  559. #endif /* DEBUGBUILD */
  560. return result;
  561. }
  562. CURLcode Curl_trc_init(void)
  563. {
  564. #ifdef DEBUGBUILD
  565. return Curl_trc_opt(NULL);
  566. #else
  567. return CURLE_OK;
  568. #endif
  569. }
  570. #else /* CURL_DISABLE_VERBOSE_STRINGS */
  571. CURLcode Curl_trc_init(void)
  572. {
  573. return CURLE_OK;
  574. }
  575. void Curl_infof(struct Curl_easy *data, const char *fmt, ...)
  576. {
  577. (void)data; (void)fmt;
  578. }
  579. void Curl_trc_cf_infof(struct Curl_easy *data, const struct Curl_cfilter *cf,
  580. const char *fmt, ...)
  581. {
  582. (void)data; (void)cf; (void)fmt;
  583. }
  584. struct curl_trc_feat;
  585. void Curl_trc_multi(struct Curl_easy *data, const char *fmt, ...)
  586. {
  587. (void)data; (void)fmt;
  588. }
  589. void Curl_trc_write(struct Curl_easy *data, const char *fmt, ...)
  590. {
  591. (void)data; (void)fmt;
  592. }
  593. void Curl_trc_dns(struct Curl_easy *data, const char *fmt, ...)
  594. {
  595. (void)data; (void)fmt;
  596. }
  597. void Curl_trc_read(struct Curl_easy *data, const char *fmt, ...)
  598. {
  599. (void)data; (void)fmt;
  600. }
  601. #ifndef CURL_DISABLE_FTP
  602. void Curl_trc_ftp(struct Curl_easy *data, const char *fmt, ...)
  603. {
  604. (void)data; (void)fmt;
  605. }
  606. #endif
  607. #ifndef CURL_DISABLE_SMTP
  608. void Curl_trc_smtp(struct Curl_easy *data, const char *fmt, ...)
  609. {
  610. (void)data; (void)fmt;
  611. }
  612. #endif
  613. #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
  614. void Curl_trc_ws(struct Curl_easy *data, const char *fmt, ...)
  615. {
  616. (void)data; (void)fmt;
  617. }
  618. #endif
  619. #ifdef USE_SSL
  620. void Curl_trc_ssls(struct Curl_easy *data, const char *fmt, ...)
  621. {
  622. (void)data;
  623. (void)fmt;
  624. }
  625. #endif
  626. #endif /* !CURL_DISABLE_VERBOSE_STRINGS */