Exemplo n.º 1
0
/*
 * this function is to avoid logging too much or non-ascii data received.
 */
static char *make_logbuf(belle_sip_log_level level, const char *buffer, size_t size){
	char *logbuf;
	char truncate_msg[128]={0};
	int limit=7000; /*big message when many ice candidates*/

	if (!belle_sip_log_level_enabled(level)){
		return belle_sip_malloc0(1);
	}
	limit=find_non_printable(buffer,MIN(size,limit));
	if (limit==0){
		snprintf(truncate_msg,sizeof(truncate_msg)-1,"... (binary data)");
	} else if (size>limit){
		snprintf(truncate_msg,sizeof(truncate_msg)-1,"... (first %i bytes shown)",limit);
		size=limit;
	}

	if (truncate_msg[0]!=0){
		size+=sizeof(truncate_msg);
	}

	logbuf=belle_sip_malloc(size+1);
	strncpy(logbuf,buffer,limit);
	if (truncate_msg[0]!=0){
		strncpy(logbuf+limit,truncate_msg,sizeof(truncate_msg));
	}
	logbuf[size]='\0';
	return logbuf;
}
Exemplo n.º 2
0
/**
 * Clears all non-printable characters, convert them to space.
 * Returns NULL if nothing needs to be cleared.
 */
static char *
clear_non_printable(const char *p, size_t length)
{
	const char *first = find_non_printable(p, length);
	char *dest;

	if (first == NULL)
		return NULL;

	dest = g_strndup(p, length);

	for (size_t i = first - p; i < length; ++i)
		if (char_is_non_printable(dest[i]))
			dest[i] = ' ';

	return dest;
}