diff options
author | Hugo Landau <hlandau@openssl.org> | 2023-09-12 12:21:44 +0100 |
---|---|---|
committer | Hugo Landau <hlandau@openssl.org> | 2024-02-02 11:49:34 +0000 |
commit | b3706fd7e23c59e0f2e737ec29a5df77e585d878 (patch) | |
tree | 49d95bd4df136d880512562b57986b4f67a8d203 /ssl | |
parent | 0f4f9902cceacd9739c0eceae6f1926545ad8e42 (diff) | |
download | openssl-b3706fd7e23c59e0f2e737ec29a5df77e585d878.tar.gz |
QLOG: JSON Encoder: Rename JSON_ENC
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22037)
Diffstat (limited to 'ssl')
-rw-r--r-- | ssl/quic/json_enc.c | 100 | ||||
-rw-r--r-- | ssl/quic/qlog.c | 19 |
2 files changed, 59 insertions, 60 deletions
diff --git a/ssl/quic/json_enc.c b/ssl/quic/json_enc.c index 80dfdb0265..a95244f499 100644 --- a/ssl/quic/json_enc.c +++ b/ssl/quic/json_enc.c @@ -105,11 +105,11 @@ static int wbuf_flush(struct json_write_buf *wbuf) } /* - * JSON_ENC: Stack Management - * ========================== + * OSSL_JSON_ENC: Stack Management + * =============================== */ -static int json_ensure_stack_size(JSON_ENC *json, size_t num_bytes) +static int json_ensure_stack_size(OSSL_JSON_ENC *json, size_t num_bytes) { unsigned char *stack; @@ -133,7 +133,7 @@ static int json_ensure_stack_size(JSON_ENC *json, size_t num_bytes) } /* Push one bit onto the stack. Returns 0 on allocation failure. */ -static int json_push(JSON_ENC *json, unsigned int v) +static int json_push(OSSL_JSON_ENC *json, unsigned int v) { if (v > 1) return 0; @@ -166,7 +166,7 @@ static int json_push(JSON_ENC *json, unsigned int v) * Pop a bit from the stack. Returns 0 if stack is empty. Use json_peek() to get * the value before calling this. */ -static int json_pop(JSON_ENC *json) +static int json_pop(OSSL_JSON_ENC *json) { if (json->stack_end_byte == 0 && json->stack_end_bit == 0) return 0; @@ -184,7 +184,7 @@ static int json_pop(JSON_ENC *json) /* * Returns the bit on the top of the stack, or -1 if the stack is empty. */ -static int json_peek(JSON_ENC *json) +static int json_peek(OSSL_JSON_ENC *json) { size_t obyte, obit; @@ -204,8 +204,8 @@ static int json_peek(JSON_ENC *json) } /* - * JSON_ENC: Initialisation - * ======================== + * OSSL_JSON_ENC: Initialisation + * ============================= */ enum { @@ -214,22 +214,22 @@ enum { STATE_PRE_COMMA }; -static ossl_inline int in_ijson(const JSON_ENC *json) +static ossl_inline int in_ijson(const OSSL_JSON_ENC *json) { - return (json->flags & JSON_FLAG_IJSON) != 0; + return (json->flags & OSSL_JSON_FLAG_IJSON) != 0; } -static ossl_inline int in_seq(const JSON_ENC *json) +static ossl_inline int in_seq(const OSSL_JSON_ENC *json) { - return (json->flags & JSON_FLAG_SEQ) != 0; + return (json->flags & OSSL_JSON_FLAG_SEQ) != 0; } -static ossl_inline int in_pretty(const JSON_ENC *json) +static ossl_inline int in_pretty(const OSSL_JSON_ENC *json) { - return (json->flags & JSON_FLAG_PRETTY) != 0; + return (json->flags & OSSL_JSON_FLAG_PRETTY) != 0; } -int ossl_json_init(JSON_ENC *json, BIO *bio, uint32_t flags) +int ossl_json_init(OSSL_JSON_ENC *json, BIO *bio, uint32_t flags) { memset(json, 0, sizeof(*json)); json->flags = flags; @@ -241,7 +241,7 @@ int ossl_json_init(JSON_ENC *json, BIO *bio, uint32_t flags) return ossl_json_reset(json); } -void ossl_json_cleanup(JSON_ENC *json) +void ossl_json_cleanup(OSSL_JSON_ENC *json) { wbuf_cleanup(&json->wbuf); @@ -251,7 +251,7 @@ void ossl_json_cleanup(JSON_ENC *json) json->stack = NULL; } -int ossl_json_flush_cleanup(JSON_ENC *json) +int ossl_json_flush_cleanup(OSSL_JSON_ENC *json) { int ok = ossl_json_flush(json); @@ -259,7 +259,7 @@ int ossl_json_flush_cleanup(JSON_ENC *json) return ok; } -int ossl_json_reset(JSON_ENC *json) +int ossl_json_reset(OSSL_JSON_ENC *json) { wbuf_clean(&json->wbuf); json->stack_end_byte = 0; @@ -268,18 +268,18 @@ int ossl_json_reset(JSON_ENC *json) return 1; } -int ossl_json_flush(JSON_ENC *json) +int ossl_json_flush(OSSL_JSON_ENC *json) { return wbuf_flush(&json->wbuf); } -int ossl_json_set_sink(JSON_ENC *json, BIO *bio) +int ossl_json_set_sink(OSSL_JSON_ENC *json, BIO *bio) { wbuf_set_bio(&json->wbuf, bio); return 1; } -int ossl_json_in_error(JSON_ENC *json) +int ossl_json_in_error(OSSL_JSON_ENC *json) { return json->error; } @@ -289,20 +289,20 @@ int ossl_json_in_error(JSON_ENC *json) * ================== */ -static void json_write_qstring(JSON_ENC *json, const char *str); -static void json_indent(JSON_ENC *json); +static void json_write_qstring(OSSL_JSON_ENC *json, const char *str); +static void json_indent(OSSL_JSON_ENC *json); -static ossl_inline int json_in_error(const JSON_ENC *json) +static ossl_inline int json_in_error(const OSSL_JSON_ENC *json) { return json->error; } -static void json_raise_error(JSON_ENC *json) +static void json_raise_error(OSSL_JSON_ENC *json) { json->error = 1; } -static void json_undefer(JSON_ENC *json) +static void json_undefer(OSSL_JSON_ENC *json) { if (!json->defer_indent) return; @@ -310,7 +310,7 @@ static void json_undefer(JSON_ENC *json) json_indent(json); } -static void json_write_char(JSON_ENC *json, char ch) +static void json_write_char(OSSL_JSON_ENC *json, char ch) { if (json_in_error(json)) return; @@ -320,7 +320,7 @@ static void json_write_char(JSON_ENC *json, char ch) json_raise_error(json); } -static void json_write_str(JSON_ENC *json, const char *s) +static void json_write_str(OSSL_JSON_ENC *json, const char *s) { if (json_in_error(json)) return; @@ -330,7 +330,7 @@ static void json_write_str(JSON_ENC *json, const char *s) json_raise_error(json); } -static void json_indent(JSON_ENC *json) +static void json_indent(OSSL_JSON_ENC *json) { size_t i, depth; @@ -346,7 +346,7 @@ static void json_indent(JSON_ENC *json) json_write_str(json, " "); } -static int json_pre_item(JSON_ENC *json) +static int json_pre_item(OSSL_JSON_ENC *json) { int s; @@ -388,7 +388,7 @@ static int json_pre_item(JSON_ENC *json) return 1; } -static void json_post_item(JSON_ENC *json) +static void json_post_item(OSSL_JSON_ENC *json) { int s = json_peek(json); @@ -403,7 +403,7 @@ static void json_post_item(JSON_ENC *json) * * type: 0=object, 1=array. */ -static void composite_begin(JSON_ENC *json, int type, char ch) +static void composite_begin(OSSL_JSON_ENC *json, int type, char ch) { if (!json_pre_item(json) || !json_push(json, type)) @@ -418,7 +418,7 @@ static void composite_begin(JSON_ENC *json, int type, char ch) * * type: 0=object, 1=array. Errors on mismatch. */ -static void composite_end(JSON_ENC *json, int type, char ch) +static void composite_end(OSSL_JSON_ENC *json, int type, char ch) { int was_defer = json->defer_indent; @@ -446,27 +446,27 @@ static void composite_end(JSON_ENC *json, int type, char ch) } /* Begin a new JSON object. */ -void ossl_json_object_begin(JSON_ENC *json) +void ossl_json_object_begin(OSSL_JSON_ENC *json) { composite_begin(json, 0, '{'); json->state = STATE_PRE_KEY; } /* End a JSON obejct. Must be matched with a call to ossl_json_object_begin(). */ -void ossl_json_object_end(JSON_ENC *json) +void ossl_json_object_end(OSSL_JSON_ENC *json) { composite_end(json, 0, '}'); } /* Begin a new JSON array. */ -void ossl_json_array_begin(JSON_ENC *json) +void ossl_json_array_begin(OSSL_JSON_ENC *json) { composite_begin(json, 1, '['); json->state = STATE_PRE_ITEM; } /* End a JSON array. Must be matched with a call to ossl_json_array_end(). */ -void ossl_json_array_end(JSON_ENC *json) +void ossl_json_array_end(OSSL_JSON_ENC *json) { composite_end(json, 1, ']'); } @@ -475,7 +475,7 @@ void ossl_json_array_end(JSON_ENC *json) * Encode a JSON key within an object. Pass a zero-terminated string, which can * be freed immediately following the call to this function. */ -void ossl_json_key(JSON_ENC *json, const char *key) +void ossl_json_key(OSSL_JSON_ENC *json, const char *key) { if (json_in_error(json)) return; @@ -509,7 +509,7 @@ void ossl_json_key(JSON_ENC *json, const char *key) } /* Encode a JSON 'null' value. */ -void ossl_json_null(JSON_ENC *json) +void ossl_json_null(OSSL_JSON_ENC *json) { if (!json_pre_item(json)) return; @@ -518,7 +518,7 @@ void ossl_json_null(JSON_ENC *json) json_post_item(json); } -void ossl_json_bool(JSON_ENC *json, int v) +void ossl_json_bool(OSSL_JSON_ENC *json, int v) { if (!json_pre_item(json)) return; @@ -530,7 +530,7 @@ void ossl_json_bool(JSON_ENC *json, int v) #define POW_53 (((int64_t)1) << 53) /* Encode a JSON integer from a uint64_t. */ -static void json_u64(JSON_ENC *json, uint64_t v, int noquote) +static void json_u64(OSSL_JSON_ENC *json, uint64_t v, int noquote) { char buf[22], *p = buf + sizeof(buf) - 1; int quote = !noquote && in_ijson(json) && v > (uint64_t)(POW_53 - 1); @@ -555,13 +555,13 @@ static void json_u64(JSON_ENC *json, uint64_t v, int noquote) json_post_item(json); } -void ossl_json_u64(JSON_ENC *json, uint64_t v) +void ossl_json_u64(OSSL_JSON_ENC *json, uint64_t v) { json_u64(json, v, 0); } /* Encode a JSON integer from an int64_t. */ -void ossl_json_i64(JSON_ENC *json, int64_t value) +void ossl_json_i64(OSSL_JSON_ENC *json, int64_t value) { uint64_t uv; int quote; @@ -592,7 +592,7 @@ void ossl_json_i64(JSON_ENC *json, int64_t value) } /* Encode a JSON number from a 64-bit floating point value. */ -void ossl_json_f64(JSON_ENC *json, double value) +void ossl_json_f64(OSSL_JSON_ENC *json, double value) { char buf[32]; @@ -619,7 +619,7 @@ static ossl_inline int hex_digit(int v) } static ossl_inline void -json_write_qstring_inner(JSON_ENC *json, const char *str, size_t str_len, +json_write_qstring_inner(OSSL_JSON_ENC *json, const char *str, size_t str_len, int nul_term) { char c, *o, obuf[7]; @@ -668,18 +668,18 @@ json_write_qstring_inner(JSON_ENC *json, const char *str, size_t str_len, } static void -json_write_qstring(JSON_ENC *json, const char *str) +json_write_qstring(OSSL_JSON_ENC *json, const char *str) { json_write_qstring_inner(json, str, 0, 1); } static void -json_write_qstring_len(JSON_ENC *json, const char *str, size_t str_len) +json_write_qstring_len(OSSL_JSON_ENC *json, const char *str, size_t str_len) { json_write_qstring_inner(json, str, str_len, 0); } -void ossl_json_str(JSON_ENC *json, const char *str) +void ossl_json_str(OSSL_JSON_ENC *json, const char *str) { if (!json_pre_item(json)) return; @@ -688,7 +688,7 @@ void ossl_json_str(JSON_ENC *json, const char *str) json_post_item(json); } -void ossl_json_str_len(JSON_ENC *json, const char *str, size_t str_len) +void ossl_json_str_len(OSSL_JSON_ENC *json, const char *str, size_t str_len) { if (!json_pre_item(json)) return; @@ -701,7 +701,7 @@ void ossl_json_str_len(JSON_ENC *json, const char *str, size_t str_len) * Encode binary data as a lowercase hex string. data_len is the data length in * bytes. */ -void ossl_json_str_hex(JSON_ENC *json, const void *data, size_t data_len) +void ossl_json_str_hex(OSSL_JSON_ENC *json, const void *data, size_t data_len) { const unsigned char *b = data, *end = b + data_len; unsigned char c; diff --git a/ssl/quic/qlog.c b/ssl/quic/qlog.c index 33ed4e0986..7815f2af39 100644 --- a/ssl/quic/qlog.c +++ b/ssl/quic/qlog.c @@ -30,18 +30,16 @@ static ossl_unused ossl_inline void bit_set(size_t *p, uint32_t bit_no, int enab p[bit_no / BITS_PER_WORD] &= mask; } -/* TODO abort */ - struct qlog_st { QLOG_TRACE_INFO info; - BIO *bio; - size_t enabled[NUM_ENABLED_W]; - uint32_t event_type; - const char *event_cat, *event_name, *event_combined_name; - OSSL_TIME event_time, prev_event_time; - JSON_ENC json; - int header_done, first_event_done; + BIO *bio; + size_t enabled[NUM_ENABLED_W]; + uint32_t event_type; + const char *event_cat, *event_name, *event_combined_name; + OSSL_TIME event_time, prev_event_time; + OSSL_JSON_ENC json; + int header_done, first_event_done; }; static OSSL_TIME default_now(void *arg) @@ -78,7 +76,8 @@ QLOG *ossl_qlog_new(const QLOG_TRACE_INFO *info) && (qlog->info.group_id = OPENSSL_strdup(info->group_id)) == NULL) goto err; - if (!ossl_json_init(&qlog->json, NULL, JSON_FLAG_IJSON | JSON_FLAG_SEQ)) + if (!ossl_json_init(&qlog->json, NULL, + OSSL_JSON_FLAG_IJSON | OSSL_JSON_FLAG_SEQ)) goto err; if (qlog->info.now_cb == NULL) |