<commit_before>/****************************************************************************
 *
 * Copyright 2016 Samsung Electronics All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.
 *
 ****************************************************************************/

/*
 *  Debugging routines
 *
 *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
 *  SPDX-License-Identifier: Apache-2.0
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may
 *  not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *  This file is part of mbed TLS (https://tls.mbed.org)
 */

#include "mbedtls/config.h"

#if defined(MBEDTLS_DEBUG_C)

#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdlib.h>
#define mbedtls_calloc      calloc
#define mbedtls_free        free
#define mbedtls_time_t      time_t
#define mbedtls_snprintf    snprintf
#endif

#include "mbedtls/debug.h"

#include <stdarg.h>
#include <stdio.h>
#include <string.h>

#if (defined(__ARMCC_VERSION) || defined(_MSC_VER)) && \
	!defined(inline) && !defined(__cplusplus)
#define inline __inline
#endif

#define DEBUG_BUF_SIZE      512

static int debug_threshold = 0;

void mbedtls_debug_set_threshold(int threshold)
{
	debug_threshold = threshold;
}

/*
 * All calls to f_dbg must be made via this function
 */
static inline void debug_send_line(const mbedtls_ssl_context *ssl, int level, const char *file, int line, const char *str)
{
	/*
	 * If in a threaded environment, we need a thread identifier.
	 * Since there is no portable way to get one, use the address of the ssl
	 * context instead, as it shouldn't be shared between threads.
	 */
#if 0							/* For TinyAra */
#if defined(MBEDTLS_THREADING_C)
	char idstr[20 + DEBUG_BUF_SIZE];	/* 0x + 16 nibbles + ': ' */
	mbedtls_snprintf(idstr, sizeof(idstr), "%p: %s", ssl, str);
	ssl->conf->f_dbg(ssl->conf->p_dbg, level, file, line, idstr);
#else
	ssl->conf->f_dbg(ssl->conf->p_dbg, level, file, line, str);
#endif
#else
	printf("%s(%d) : %s", file, line, str);
#endif
}

void mbedtls_debug_print_msg(const mbedtls_ssl_context *ssl, int level, const char *file, int line, const char *format, ...)
{
	va_list argp;
	char str[DEBUG_BUF_SIZE];
	int ret;

	if (NULL == ssl || NULL == ssl->conf || NULL == ssl->conf->f_dbg || level > debug_threshold) {
		return;
	}

	va_start(argp, format);
#if defined(_WIN32)
#if defined(_TRUNCATE)
	ret = _vsnprintf_s(str, DEBUG_BUF_SIZE, _TRUNCATE, format, argp);
#else
	ret = _vsnprintf(str, DEBUG_BUF_SIZE, format, argp);
	if (ret < 0 || (size_t)ret == DEBUG_BUF_SIZE) {
		str[DEBUG_BUF_SIZE - 1] = '\0';
		ret = -1;
	}
#endif
#else
	ret = vsnprintf(str, DEBUG_BUF_SIZE, format, argp);
#endif<commit_msg>Enable debugging function call in mbedtls<commit_after>/****************************************************************************
 *
 * Copyright 2016 Samsung Electronics All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.
 *
 ****************************************************************************/

/*
 *  Debugging routines
 *
 *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
 *  SPDX-License-Identifier: Apache-2.0
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may
 *  not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *  This file is part of mbed TLS (https://tls.mbed.org)
 */

#include "mbedtls/config.h"

#if defined(MBEDTLS_DEBUG_C)

#if defined(MBEDTLS_PLATFORM_C)
#include "mbedtls/platform.h"
#else
#include <stdlib.h>
#define mbedtls_calloc      calloc
#define mbedtls_free        free
#define mbedtls_time_t      time_t
#define mbedtls_snprintf    snprintf
#endif

#include "mbedtls/debug.h"

#include <stdarg.h>
#include <stdio.h>
#include <string.h>

#if (defined(__ARMCC_VERSION) || defined(_MSC_VER)) && \
	!defined(inline) && !defined(__cplusplus)
#define inline __inline
#endif

#define DEBUG_BUF_SIZE      512

static int debug_threshold = 0;

void mbedtls_debug_set_threshold(int threshold)
{
	debug_threshold = threshold;
}

/*
 * All calls to f_dbg must be made via this function
 */
static inline void debug_send_line(const mbedtls_ssl_context *ssl, int level, const char *file, int line, const char *str)
{
	/*
	 * If in a threaded environment, we need a thread identifier.
	 * Since there is no portable way to get one, use the address of the ssl
	 * context instead, as it shouldn't be shared between threads.
	 */
#if defined(MBEDTLS_THREADING_C)
	char idstr[20 + DEBUG_BUF_SIZE];	/* 0x + 16 nibbles + ': ' */
	mbedtls_snprintf(idstr, sizeof(idstr), "%p: %s", ssl, str);
	ssl->conf->f_dbg(ssl->conf->p_dbg, level, file, line, idstr);
#else
	ssl->conf->f_dbg(ssl->conf->p_dbg, level, file, line, str);
#endif
}

void mbedtls_debug_print_msg(const mbedtls_ssl_context *ssl, int level, const char *file, int line, const char *format, ...)
{
	va_list argp;
	char str[DEBUG_BUF_SIZE];
	int ret;

	if (NULL == ssl || NULL == ssl->conf || NULL == ssl->conf->f_dbg || level > debug_threshold) {
		return;
	}

	va_start(argp, format);
#if defined(_WIN32)
#if defined(_TRUNCATE)
	ret = _vsnprintf_s(str, DEBUG_BUF_SIZE, _TRUNCATE, format, argp);
#else
	ret = _vsnprintf(str, DEBUG_BUF_SIZE, format, argp);
	if (ret < 0 || (size_t)ret == DEBUG_BUF_SIZE) {
		str[DEBUG_BUF_SIZE - 1] = '\0';
		ret = -1;
	}
#endif
#else
	ret = vsnprintf(str, DEBUG_BUF_SIZE, format, argp);
#endif
{'fraction_non_alphanumeric': 0.1477961432506887, 'fraction_numerical': 0.010330578512396695, 'mean_word_length': 4.335047759000735, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 35, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3481101', 'n_tokens_mistral': 2402, 'n_tokens_neox': 2293, 'n_words': 793}