qlog.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef OSSL_QLOG_H
  10. # define OSSL_QLOG_H
  11. # include <openssl/ssl.h>
  12. # include "internal/quic_types.h"
  13. # include "internal/time.h"
  14. typedef struct qlog_st QLOG;
  15. # ifndef OPENSSL_NO_QLOG
  16. enum {
  17. QLOG_EVENT_TYPE_NONE,
  18. # define QLOG_EVENT(cat, name) QLOG_EVENT_TYPE_##cat##_##name,
  19. # include "internal/qlog_events.h"
  20. # undef QLOG_EVENT
  21. QLOG_EVENT_TYPE_NUM
  22. };
  23. typedef struct qlog_trace_info_st {
  24. QUIC_CONN_ID odcid;
  25. const char *title, *description, *group_id;
  26. int is_server;
  27. OSSL_TIME (*now_cb)(void *arg);
  28. void *now_cb_arg;
  29. uint64_t override_process_id;
  30. const char *override_impl_name;
  31. } QLOG_TRACE_INFO;
  32. QLOG *ossl_qlog_new(const QLOG_TRACE_INFO *info);
  33. QLOG *ossl_qlog_new_from_env(const QLOG_TRACE_INFO *info);
  34. void ossl_qlog_free(QLOG *qlog);
  35. /* Configuration */
  36. int ossl_qlog_set_event_type_enabled(QLOG *qlog, uint32_t event_type,
  37. int enable);
  38. int ossl_qlog_set_filter(QLOG *qlog, const char *filter);
  39. int ossl_qlog_set_sink_bio(QLOG *qlog, BIO *bio);
  40. # ifndef OPENSSL_NO_STDIO
  41. int ossl_qlog_set_sink_file(QLOG *qlog, FILE *file, int close_flag);
  42. # endif
  43. int ossl_qlog_set_sink_filename(QLOG *qlog, const char *filename);
  44. /* Operations */
  45. int ossl_qlog_flush(QLOG *qlog);
  46. /* Queries */
  47. int ossl_qlog_enabled(QLOG *qlog, uint32_t event_type);
  48. /* Grouping Functions */
  49. int ossl_qlog_event_try_begin(QLOG *qlog, uint32_t event_type,
  50. const char *event_cat, const char *event_name,
  51. const char *event_combined_name);
  52. void ossl_qlog_event_end(QLOG *qlog);
  53. void ossl_qlog_group_begin(QLOG *qlog, const char *name);
  54. void ossl_qlog_group_end(QLOG *qlog);
  55. void ossl_qlog_array_begin(QLOG *qlog, const char *name);
  56. void ossl_qlog_array_end(QLOG *qlog);
  57. void ossl_qlog_override_time(QLOG *qlog, OSSL_TIME event_time);
  58. /* Grouping Macros */
  59. # define QLOG_EVENT_BEGIN(qlog, cat, name) \
  60. { \
  61. QLOG *qlog_instance = (qlog); \
  62. uint32_t qlog_event_type = QLOG_EVENT_TYPE_##cat##_##name; \
  63. \
  64. if (ossl_qlog_event_try_begin(qlog_instance, qlog_event_type, \
  65. #cat, #name, #cat ":" #name)) {
  66. # define QLOG_EVENT_END() \
  67. ossl_qlog_event_end(qlog_instance); \
  68. } \
  69. }
  70. # define QLOG_BEGIN(name) \
  71. { \
  72. ossl_qlog_group_begin(qlog_instance, (name));
  73. # define QLOG_END() \
  74. ossl_qlog_group_end(qlog_instance); \
  75. }
  76. # define QLOG_BEGIN_ARRAY(name) \
  77. { \
  78. ossl_qlog_array_begin(qlog_instance, (name));
  79. # define QLOG_END_ARRAY() \
  80. ossl_qlog_array_end(qlog_instance); \
  81. }
  82. /* Field Functions */
  83. void ossl_qlog_str(QLOG *qlog, const char *name, const char *value);
  84. void ossl_qlog_str_len(QLOG *qlog, const char *name,
  85. const char *value, size_t value_len);
  86. void ossl_qlog_u64(QLOG *qlog, const char *name, uint64_t value);
  87. void ossl_qlog_i64(QLOG *qlog, const char *name, int64_t value);
  88. void ossl_qlog_bool(QLOG *qlog, const char *name, int value);
  89. void ossl_qlog_bin(QLOG *qlog, const char *name,
  90. const void *value, size_t value_len);
  91. /* Field Macros */
  92. # define QLOG_STR(name, value) ossl_qlog_str(qlog_instance, (name), (value))
  93. # define QLOG_STR_LEN(name, value, value_len) \
  94. ossl_qlog_str_len(qlog_instance, (name), (value), (value_len))
  95. # define QLOG_I64(name, value) ossl_qlog_i64(qlog_instance, (name), (value))
  96. # define QLOG_U64(name, value) ossl_qlog_u64(qlog_instance, (name), (value))
  97. # define QLOG_F64(name, value) ossl_qlog_f64(qlog_instance, (name), (value))
  98. # define QLOG_BOOL(name, value) ossl_qlog_bool(qlog_instance, (name), (value))
  99. # define QLOG_BIN(name, value, value_len) \
  100. ossl_qlog_bin(qlog_instance, (name), (value), (value_len))
  101. # define QLOG_CID(name, value) QLOG_BIN((name), (value)->id, (value)->id_len)
  102. # endif
  103. #endif