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