+/* Print CMP log messages (i.e., diagnostic info) via the log cb of the ctx */
+int ossl_cmp_print_log(OSSL_CMP_severity level, const OSSL_CMP_CTX *ctx,
+ const char *func, const char *file, int line,
+ const char *level_str, const char *format, ...)
+{
+ va_list args;
+ char hugebuf[1024 * 2];
+ int res = 0;
+
+ if (ctx == NULL || ctx->log_cb == NULL)
+ return 1; /* silently drop message */
+
+ if (level > ctx->log_verbosity) /* excludes the case level is unknown */
+ return 1; /* suppress output since severity is not sufficient */
+
+ if (format == NULL)
+ return 0;
+
+ va_start(args, format);
+
+ if (func == NULL)
+ func = "(unset function name)";
+ if (file == NULL)
+ file = "(unset file name)";
+ if (level_str == NULL)
+ level_str = "(unset level string)";
+
+#ifndef OPENSSL_NO_TRACE
+ if (OSSL_TRACE_ENABLED(CMP)) {
+ OSSL_TRACE_BEGIN(CMP) {
+ int printed =
+ BIO_snprintf(hugebuf, sizeof(hugebuf),
+ "%s:%s:%d:" OSSL_CMP_LOG_PREFIX "%s: ",
+ func, file, line, level_str);
+ if (printed > 0 && (size_t)printed < sizeof(hugebuf)) {
+ if (BIO_vsnprintf(hugebuf + printed,
+ sizeof(hugebuf) - printed, format, args) > 0)
+ res = BIO_puts(trc_out, hugebuf) > 0;
+ }
+ } OSSL_TRACE_END(CMP);
+ }
+#else /* compensate for disabled trace API */
+ {
+ if (BIO_vsnprintf(hugebuf, sizeof(hugebuf), format, args) > 0)
+ res = ctx->log_cb(func, file, line, level, hugebuf);
+ }
+#endif
+ va_end(args);
+ return res;
+}
+
+/* Set a callback function for error reporting and logging messages */
+int OSSL_CMP_CTX_set_log_cb(OSSL_CMP_CTX *ctx, OSSL_CMP_log_cb_t cb)