]> git.ipfire.org Git - thirdparty/openssl.git/blob - include/internal/qlog.h
QLOG: Frontend: API Definition
[thirdparty/openssl.git] / include / internal / qlog.h
1 /*
2 * Copyright 2023 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
10 #ifndef OSSL_QLOG_H
11 # define OSSL_QLOG_H
12
13 # include <openssl/ssl.h>
14 # include "internal/quic_types.h"
15 # include "internal/time.h"
16
17 typedef struct qlog_st QLOG;
18
19 # ifndef OPENSSL_NO_QLOG
20
21 enum {
22 QLOG_EVENT_TYPE_NONE,
23
24 # define QLOG_EVENT(cat, name) QLOG_EVENT_TYPE_##cat##_##name,
25 # include "internal/qlog_events.h"
26 # undef QLOG_EVENT
27
28 QLOG_EVENT_TYPE_NUM
29 };
30
31 typedef struct qlog_trace_info_st {
32 QUIC_CONN_ID odcid;
33 const char *title, *description, *group_id;
34 int is_server;
35 OSSL_TIME (*now_cb)(void *arg);
36 void *now_cb_arg;
37 } QLOG_TRACE_INFO;
38
39 QLOG *ossl_qlog_new(const QLOG_TRACE_INFO *info);
40 QLOG *ossl_qlog_new_from_env(const QLOG_TRACE_INFO *info);
41
42 void ossl_qlog_free(QLOG *qlog);
43
44 /* Configuration */
45 int ossl_qlog_set_event_type_enabled(QLOG *qlog, uint32_t event_type,
46 int enable);
47 int ossl_qlog_set_filter(QLOG *qlog, const char *filter);
48
49 int ossl_qlog_set_sink_bio(QLOG *qlog, BIO *bio);
50 # ifndef OPENSSL_NO_STDIO
51 int ossl_qlog_set_sink_file(QLOG *qlog, FILE *file, int close_flag);
52 # endif
53 int ossl_qlog_set_sink_filename(QLOG *qlog, const char *filename);
54
55 /* Operations */
56 int ossl_qlog_flush(QLOG *qlog);
57
58 /* Queries */
59 int ossl_qlog_enabled(QLOG *qlog, uint32_t event_type);
60
61 /* Grouping Functions */
62 int ossl_qlog_event_try_begin(QLOG *qlog, uint32_t event_type,
63 const char *event_cat, const char *event_name,
64 const char *event_combined_name);
65 void ossl_qlog_event_end(QLOG *qlog);
66 void ossl_qlog_event_abort(QLOG *qlog);
67
68 void ossl_qlog_group_begin(QLOG *qlog, const char *name);
69 void ossl_qlog_group_end(QLOG *qlog);
70
71 void ossl_qlog_array_begin(QLOG *qlog, const char *name);
72 void ossl_qlog_array_end(QLOG *qlog);
73
74 void ossl_qlog_override_time(QLOG *qlog, OSSL_TIME event_time);
75
76 /* Grouping Macros */
77 # define QLOG_EVENT_BEGIN(qlog, cat, name) \
78 { \
79 QLOG *qlog_instance = (qlog); \
80 uint32_t qlog_event_type = QLOG_EVENT_TYPE_##cat##_##name; \
81 \
82 if (ossl_qlog_event_try_begin(qlog_instance, qlog_event_type, \
83 #cat, #name, #cat ":" #name)) {
84
85 # define QLOG_EVENT_END() \
86 ossl_qlog_event_end(qlog_instance); \
87 } \
88 }
89
90 # define QLOG_BEGIN(name) \
91 { \
92 ossl_qlog_group_begin(qlog_instance, (name));
93
94 # define QLOG_END() \
95 ossl_qlog_group_end(qlog_instance); \
96 }
97
98 # define QLOG_BEGIN_ARRAY(name) \
99 { \
100 ossl_qlog_array_begin(qlog_instance, (name));
101
102 # define QLOG_END_ARRAY() \
103 ossl_qlog_array_end(qlog_instance); \
104 }
105
106 # define QLOG_ABORT() ossl_qlog_event_abort(qlog_instance)
107
108 /* Field Functions */
109 void ossl_qlog_str(QLOG *qlog, const char *name, const char *value);
110 void ossl_qlog_str_len(QLOG *qlog, const char *name,
111 const char *value, size_t value_len);
112 void ossl_qlog_u64(QLOG *qlog, const char *name, uint64_t value);
113 void ossl_qlog_i64(QLOG *qlog, const char *name, int64_t value);
114 void ossl_qlog_bool(QLOG *qlog, const char *name, int value);
115 void ossl_qlog_bin(QLOG *qlog, const char *name,
116 const void *value, size_t value_len);
117
118 /* Field Macros */
119 # define QLOG_STR(name, value) ossl_qlog_str(qlog_instance, (name), (value))
120 # define QLOG_STR_LEN(name, value, value_len) \
121 ossl_qlog_str_len(qlog_instance, (name), (value), (value_len))
122 # define QLOG_I64(name, value) ossl_qlog_i64(qlog_instance, (name), (value))
123 # define QLOG_U64(name, value) ossl_qlog_u64(qlog_instance, (name), (value))
124 # define QLOG_F64(name, value) ossl_qlog_f64(qlog_instance, (name), (value))
125 # define QLOG_BOOL(name, value) ossl_qlog_bool(qlog_instance, (name), (value))
126 # define QLOG_BIN(name, value, value_len) \
127 ossl_qlog_bin(qlog_instance, (name), (value), (value_len))
128 # define QLOG_CID(name, value) QLOG_BIN((name), (value)->id, (value)->id_len)
129
130 # endif
131
132 #endif