1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 13:47:46 +00:00

Everywhere: Debug macros instead of constexpr.

This was done with the following script:

    find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/dbgln<debug_([a-z_]+)>/dbgln<\U\1_DEBUG>/' {} \;

    find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/if constexpr \(debug_([a-z0-9_]+)/if constexpr \(\U\1_DEBUG/' {} \;
This commit is contained in:
asynts 2021-01-23 23:59:27 +01:00 committed by Andreas Kling
parent bb483f7ef4
commit 8465683dcf
98 changed files with 414 additions and 972 deletions

View file

@ -112,7 +112,7 @@ ssize_t TLSv12::handle_hello(ReadonlyBytes buffer, WritePacketStage& write_packe
return (i8)Error::NoCommonCipher;
}
m_context.cipher = cipher;
dbgln<debug_tls>("Cipher: {}", (u16)cipher);
dbgln<TLS_DEBUG>("Cipher: {}", (u16)cipher);
// The handshake hash function is _always_ SHA256
m_context.handshake_hash.initialize(Crypto::Hash::HashKind::SHA256);
@ -146,7 +146,7 @@ ssize_t TLSv12::handle_hello(ReadonlyBytes buffer, WritePacketStage& write_packe
u16 extension_length = AK::convert_between_host_and_network_endian(*(const u16*)buffer.offset_pointer(res));
res += 2;
dbgln<debug_tls>("extension {} with length {}", (u16)extension_type, extension_length);
dbgln<TLS_DEBUG>("extension {} with length {}", (u16)extension_type, extension_length);
if (extension_length) {
if (buffer.size() - res < extension_length) {
@ -218,12 +218,12 @@ ssize_t TLSv12::handle_finished(ReadonlyBytes buffer, WritePacketStage& write_pa
u32 size = buffer[0] * 0x10000 + buffer[1] * 0x100 + buffer[2];
if (size < 12) {
dbgln<debug_tls>("finished packet smaller than minimum size: {}", size);
dbgln<TLS_DEBUG>("finished packet smaller than minimum size: {}", size);
return (i8)Error::BrokenPacket;
}
if (size < buffer.size() - index) {
dbgln<debug_tls>("not enough data after length: {} > {}", size, buffer.size() - index);
dbgln<TLS_DEBUG>("not enough data after length: {} > {}", size, buffer.size() - index);
return (i8)Error::NeedMoreData;
}
@ -324,7 +324,7 @@ ssize_t TLSv12::handle_payload(ReadonlyBytes vbuffer)
auto type = buffer[0];
auto write_packets { WritePacketStage::Initial };
size_t payload_size = buffer[1] * 0x10000 + buffer[2] * 0x100 + buffer[3] + 3;
dbgln<debug_tls>("payload size: {} buffer length: {}", payload_size, buffer_length);
dbgln<TLS_DEBUG>("payload size: {} buffer length: {}", payload_size, buffer_length);
if (payload_size + 1 > buffer_length)
return (i8)Error::NeedMoreData;

View file

@ -39,12 +39,12 @@ void TLSv12::write_packet(ByteBuffer& packet)
m_context.tls_buffer.append(packet.data(), packet.size());
if (m_context.connection_status > ConnectionStatus::Disconnected) {
if (!m_has_scheduled_write_flush) {
dbgln<debug_tls>("Scheduling write of {}", m_context.tls_buffer.size());
dbgln<TLS_DEBUG>("Scheduling write of {}", m_context.tls_buffer.size());
deferred_invoke([this](auto&) { write_into_socket(); });
m_has_scheduled_write_flush = true;
} else {
// multiple packet are available, let's flush some out
dbgln<debug_tls>("Flushing scheduled write of {}", m_context.tls_buffer.size());
dbgln<TLS_DEBUG>("Flushing scheduled write of {}", m_context.tls_buffer.size());
write_into_socket();
// the deferred invoke is still in place
m_has_scheduled_write_flush = true;
@ -216,7 +216,7 @@ ByteBuffer TLSv12::hmac_message(const ReadonlyBytes& buf, const Optional<Readonl
auto digest = hmac.digest();
auto mac = ByteBuffer::copy(digest.immutable_data(), digest.data_length());
if constexpr (debug_tls) {
if constexpr (TLS_DEBUG) {
dbgln("HMAC of the block for sequence number {}", sequence_number);
print_buffer(mac);
}
@ -230,7 +230,7 @@ ssize_t TLSv12::handle_message(ReadonlyBytes buffer)
size_t header_size = res;
ssize_t payload_res = 0;
dbgln<debug_tls>("buffer size: {}", buffer.size());
dbgln<TLS_DEBUG>("buffer size: {}", buffer.size());
if (buffer.size() < 5) {
return (i8)Error::NeedMoreData;
@ -241,7 +241,7 @@ ssize_t TLSv12::handle_message(ReadonlyBytes buffer)
// FIXME: Read the version and verify it
if constexpr (debug_tls) {
if constexpr (TLS_DEBUG) {
auto version = (Version) * (const u16*)buffer.offset_pointer(buffer_position);
dbgln("type={}, version={}", (u8)type, (u16)version);
}
@ -249,21 +249,21 @@ ssize_t TLSv12::handle_message(ReadonlyBytes buffer)
buffer_position += 2;
auto length = AK::convert_between_host_and_network_endian(*(const u16*)buffer.offset_pointer(buffer_position));
dbgln<debug_tls>("record length: {} at offset: {}", length, buffer_position);
dbgln<TLS_DEBUG>("record length: {} at offset: {}", length, buffer_position);
buffer_position += 2;
if (buffer_position + length > buffer.size()) {
dbgln<debug_tls>("record length more than what we have: {}", buffer.size());
dbgln<TLS_DEBUG>("record length more than what we have: {}", buffer.size());
return (i8)Error::NeedMoreData;
}
dbgln<debug_tls>("message type: {}, length: {}", (u8)type, length);
dbgln<TLS_DEBUG>("message type: {}, length: {}", (u8)type, length);
auto plain = buffer.slice(buffer_position, buffer.size() - buffer_position);
ByteBuffer decrypted;
if (m_context.cipher_spec_set && type != MessageType::ChangeCipher) {
if constexpr (debug_tls) {
if constexpr (TLS_DEBUG) {
dbgln("Encrypted: ");
print_buffer(buffer.slice(header_size, length));
}
@ -389,7 +389,7 @@ ssize_t TLSv12::handle_message(ReadonlyBytes buffer)
auto packet = build_alert(true, (u8)AlertDescription::UnexpectedMessage);
write_packet(packet);
} else {
dbgln<debug_tls>("application data message of size {}", plain.size());
dbgln<TLS_DEBUG>("application data message of size {}", plain.size());
m_context.application_buffer.append(plain.data(), plain.size());
}
@ -414,9 +414,9 @@ ssize_t TLSv12::handle_message(ReadonlyBytes buffer)
}
break;
case MessageType::Alert:
dbgln<debug_tls>("alert message of length {}", length);
dbgln<TLS_DEBUG>("alert message of length {}", length);
if (length >= 2) {
if constexpr (debug_tls)
if constexpr (TLS_DEBUG)
print_buffer(plain);
auto level = plain[0];

View file

@ -174,7 +174,7 @@ void TLSv12::read_from_socket()
void TLSv12::write_into_socket()
{
dbgln<debug_tls>("Flushing cached records: {} established? {}", m_context.tls_buffer.size(), is_established());
dbgln<TLS_DEBUG>("Flushing cached records: {} established? {}", m_context.tls_buffer.size(), is_established());
m_has_scheduled_write_flush = false;
if (!check_connection_state(false))
@ -199,7 +199,7 @@ bool TLSv12::check_connection_state(bool read)
m_context.connection_finished = true;
}
if (m_context.critical_error) {
dbgln<debug_tls>("CRITICAL ERROR {} :(", m_context.critical_error);
dbgln<TLS_DEBUG>("CRITICAL ERROR {} :(", m_context.critical_error);
if (on_tls_error)
on_tls_error((AlertDescription)m_context.critical_error);
@ -211,7 +211,7 @@ bool TLSv12::check_connection_state(bool read)
on_tls_finished();
}
if (m_context.tls_buffer.size()) {
dbgln<debug_tls>("connection closed without finishing data transfer, {} bytes still in buffer and {} bytes in application buffer",
dbgln<TLS_DEBUG>("connection closed without finishing data transfer, {} bytes still in buffer and {} bytes in application buffer",
m_context.tls_buffer.size(),
m_context.application_buffer.size());
} else {
@ -247,7 +247,7 @@ bool TLSv12::flush()
}
if (m_context.send_retries++ == 10) {
// drop the records, we can't send
dbgln<debug_tls>("Dropping {} bytes worth of TLS records as max retries has been reached", write_buffer().size());
dbgln<TLS_DEBUG>("Dropping {} bytes worth of TLS records as max retries has been reached", write_buffer().size());
write_buffer().clear();
m_context.send_retries = 0;
}

View file

@ -406,7 +406,7 @@ static ssize_t _parse_asn1(const Context& context, Certificate& cert, const u8*
hash.initialize(Crypto::Hash::HashKind::SHA512);
break;
default:
dbgln<debug_tls>("Unsupported hash mode {}", (u32)cert.key_algorithm);
dbgln<TLS_DEBUG>("Unsupported hash mode {}", (u32)cert.key_algorithm);
// fallback to md5, it will fail later
hash.initialize(Crypto::Hash::HashKind::MD5);
break;
@ -436,7 +436,7 @@ Optional<Certificate> TLSv12::parse_asn1(ReadonlyBytes buffer, bool) const
_parse_asn1(m_context, cert, buffer.data(), buffer.size(), 1, fields, nullptr, 0, nullptr, nullptr);
dbgln<debug_tls>("Certificate issued for {} by {}", cert.subject, cert.issuer_subject);
dbgln<TLS_DEBUG>("Certificate issued for {} by {}", cert.subject, cert.issuer_subject);
return cert;
}
@ -454,7 +454,7 @@ ssize_t TLSv12::handle_certificate(ReadonlyBytes buffer)
u32 certificate_total_length = buffer[0] * 0x10000 + buffer[1] * 0x100 + buffer[2];
dbgln<debug_tls>("total length: {}", certificate_total_length);
dbgln<TLS_DEBUG>("total length: {}", certificate_total_length);
if (certificate_total_length <= 4)
return 3 * certificate_total_length;
@ -549,7 +549,7 @@ void TLSv12::consume(ReadonlyBytes record)
return;
}
dbgln<debug_tls>("Consuming {} bytes", record.size());
dbgln<TLS_DEBUG>("Consuming {} bytes", record.size());
m_context.message_buffer.append(record.data(), record.size());
@ -559,17 +559,17 @@ void TLSv12::consume(ReadonlyBytes record)
size_t size_offset { 3 }; // read the common record header
size_t header_size { 5 };
dbgln<debug_tls>("message buffer length {}", buffer_length);
dbgln<TLS_DEBUG>("message buffer length {}", buffer_length);
while (buffer_length >= 5) {
auto length = AK::convert_between_host_and_network_endian(*(u16*)m_context.message_buffer.offset_pointer(index + size_offset)) + header_size;
if (length > buffer_length) {
dbgln<debug_tls>("Need more data: {} > {}", length, buffer_length);
dbgln<TLS_DEBUG>("Need more data: {} > {}", length, buffer_length);
break;
}
auto consumed = handle_message(m_context.message_buffer.bytes().slice(index, length));
if constexpr (debug_tls) {
if constexpr (TLS_DEBUG) {
if (consumed > 0)
dbgln("consumed {} bytes", consumed);
else