Home | History | Annotate | Line # | Download | only in internal
      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 
     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     uint64_t override_process_id;
     38     const char *override_impl_name;
     39 } QLOG_TRACE_INFO;
     40 
     41 QLOG *ossl_qlog_new(const QLOG_TRACE_INFO *info);
     42 QLOG *ossl_qlog_new_from_env(const QLOG_TRACE_INFO *info);
     43 
     44 void ossl_qlog_free(QLOG *qlog);
     45 
     46 /* Configuration */
     47 int ossl_qlog_set_event_type_enabled(QLOG *qlog, uint32_t event_type,
     48     int enable);
     49 int ossl_qlog_set_filter(QLOG *qlog, const char *filter);
     50 
     51 int ossl_qlog_set_sink_bio(QLOG *qlog, BIO *bio);
     52 #ifndef OPENSSL_NO_STDIO
     53 int ossl_qlog_set_sink_file(QLOG *qlog, FILE *file, int close_flag);
     54 #endif
     55 int ossl_qlog_set_sink_filename(QLOG *qlog, const char *filename);
     56 
     57 /* Operations */
     58 int ossl_qlog_flush(QLOG *qlog);
     59 
     60 /* Queries */
     61 int ossl_qlog_enabled(QLOG *qlog, uint32_t event_type);
     62 
     63 /* Grouping Functions */
     64 int ossl_qlog_event_try_begin(QLOG *qlog, uint32_t event_type,
     65     const char *event_cat, const char *event_name,
     66     const char *event_combined_name);
     67 void ossl_qlog_event_end(QLOG *qlog);
     68 
     69 void ossl_qlog_group_begin(QLOG *qlog, const char *name);
     70 void ossl_qlog_group_end(QLOG *qlog);
     71 
     72 void ossl_qlog_array_begin(QLOG *qlog, const char *name);
     73 void ossl_qlog_array_end(QLOG *qlog);
     74 
     75 void ossl_qlog_override_time(QLOG *qlog, OSSL_TIME event_time);
     76 
     77 /* Grouping Macros */
     78 #define QLOG_EVENT_BEGIN(qlog, cat, name)                             \
     79     {                                                                 \
     80         QLOG *qlog_instance = (qlog);                                 \
     81         uint32_t qlog_event_type = QLOG_EVENT_TYPE_##cat##_##name;    \
     82                                                                       \
     83         if (ossl_qlog_event_try_begin(qlog_instance, qlog_event_type, \
     84                 #cat, #name, #cat ":" #name)) {
     85 
     86 #define QLOG_EVENT_END()                \
     87     ossl_qlog_event_end(qlog_instance); \
     88     }                                   \
     89     }
     90 
     91 #define QLOG_BEGIN(name) \
     92     {                    \
     93         ossl_qlog_group_begin(qlog_instance, (name));
     94 
     95 #define QLOG_END()                      \
     96     ossl_qlog_group_end(qlog_instance); \
     97     }
     98 
     99 #define QLOG_BEGIN_ARRAY(name) \
    100     {                          \
    101         ossl_qlog_array_begin(qlog_instance, (name));
    102 
    103 #define QLOG_END_ARRAY()                \
    104     ossl_qlog_array_end(qlog_instance); \
    105     }
    106 
    107 /* Field Functions */
    108 void ossl_qlog_str(QLOG *qlog, const char *name, const char *value);
    109 void ossl_qlog_str_len(QLOG *qlog, const char *name,
    110     const char *value, size_t value_len);
    111 void ossl_qlog_u64(QLOG *qlog, const char *name, uint64_t value);
    112 void ossl_qlog_i64(QLOG *qlog, const char *name, int64_t value);
    113 void ossl_qlog_bool(QLOG *qlog, const char *name, int value);
    114 void ossl_qlog_bin(QLOG *qlog, const char *name,
    115     const void *value, size_t value_len);
    116 
    117 /* Field Macros */
    118 #define QLOG_STR(name, value) ossl_qlog_str(qlog_instance, (name), (value))
    119 #define QLOG_STR_LEN(name, value, value_len) \
    120     ossl_qlog_str_len(qlog_instance, (name), (value), (value_len))
    121 #define QLOG_I64(name, value) ossl_qlog_i64(qlog_instance, (name), (value))
    122 #define QLOG_U64(name, value) ossl_qlog_u64(qlog_instance, (name), (value))
    123 #define QLOG_F64(name, value) ossl_qlog_f64(qlog_instance, (name), (value))
    124 #define QLOG_BOOL(name, value) ossl_qlog_bool(qlog_instance, (name), (value))
    125 #define QLOG_BIN(name, value, value_len) \
    126     ossl_qlog_bin(qlog_instance, (name), (value), (value_len))
    127 #define QLOG_CID(name, value) QLOG_BIN((name), (value)->id, (value)->id_len)
    128 
    129 #endif
    130 
    131 #endif
    132