1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:18:11 +00:00

LibCore: Remove all remaining C prefix references

LibCore's GZip is also moved into the Core namespace with this change.
This commit is contained in:
Shannon Booth 2020-03-07 11:37:51 +13:00 committed by Andreas Kling
parent 4a271430f8
commit 57f1c919df
17 changed files with 42 additions and 34 deletions

View file

@ -31,7 +31,7 @@ The service is advised to set this flag using [`fcntl`(2)](../man2/fcntl.md) and
unset `SOCKET_TAKEOVER` from the environment in order not to confuse its unset `SOCKET_TAKEOVER` from the environment in order not to confuse its
children. children.
LibCore provides `CLocalServer::take_over_from_system_server()` method that LibCore provides `Core::LocalServer::take_over_from_system_server()` method that
performs the service side of the socket takeover automatically. performs the service side of the socket takeover automatically.
If a service is configured as *lazy*, SystemServer will actually listen on the If a service is configured as *lazy*, SystemServer will actually listen on the

View file

@ -31,7 +31,9 @@
#include <limits.h> #include <limits.h>
#include <stddef.h> #include <stddef.h>
bool CGzip::is_compressed(const ByteBuffer& data) namespace Core {
bool Gzip::is_compressed(const ByteBuffer& data)
{ {
return data.size() > 2 && data[0] == 0x1F && data[1] == 0x8b; return data.size() > 2 && data[0] == 0x1F && data[1] == 0x8b;
} }
@ -102,7 +104,7 @@ static Optional<ByteBuffer> get_gzip_payload(const ByteBuffer& data)
return data.slice(current, new_size); return data.slice(current, new_size);
} }
Optional<ByteBuffer> CGzip::decompress(const ByteBuffer& data) Optional<ByteBuffer> Gzip::decompress(const ByteBuffer& data)
{ {
ASSERT(is_compressed(data)); ASSERT(is_compressed(data));
@ -145,3 +147,5 @@ Optional<ByteBuffer> CGzip::decompress(const ByteBuffer& data)
return destination; return destination;
} }
}

View file

@ -28,8 +28,12 @@
#include <AK/Optional.h> #include <AK/Optional.h>
#include <AK/String.h> #include <AK/String.h>
class CGzip { namespace Core {
class Gzip {
public: public:
static bool is_compressed(const ByteBuffer& data); static bool is_compressed(const ByteBuffer& data);
static Optional<ByteBuffer> decompress(const ByteBuffer& data); static Optional<ByteBuffer> decompress(const ByteBuffer& data);
}; };
}

View file

@ -38,26 +38,26 @@ namespace Core {
static ByteBuffer handle_content_encoding(const ByteBuffer& buf, const String& content_encoding) static ByteBuffer handle_content_encoding(const ByteBuffer& buf, const String& content_encoding)
{ {
#ifdef CHTTPJOB_DEBUG #ifdef CHTTPJOB_DEBUG
dbg() << "CHttpJob::handle_content_encoding: buf has content_encoding = " << content_encoding; dbg() << "HttpJob::handle_content_encoding: buf has content_encoding = " << content_encoding;
#endif #endif
if (content_encoding == "gzip") { if (content_encoding == "gzip") {
if (!CGzip::is_compressed(buf)) { if (!Gzip::is_compressed(buf)) {
dbg() << "CHttpJob::handle_content_encoding: buf is not gzip compressed!"; dbg() << "HttpJob::handle_content_encoding: buf is not gzip compressed!";
} }
#ifdef CHTTPJOB_DEBUG #ifdef CHTTPJOB_DEBUG
dbg() << "CHttpJob::handle_content_encoding: buf is gzip compressed!"; dbg() << "HttpJob::handle_content_encoding: buf is gzip compressed!";
#endif #endif
auto uncompressed = CGzip::decompress(buf); auto uncompressed = Gzip::decompress(buf);
if (!uncompressed.has_value()) { if (!uncompressed.has_value()) {
dbg() << "CHttpJob::handle_content_encoding: Gzip::decompress() failed. Returning original buffer."; dbg() << "HttpJob::handle_content_encoding: Gzip::decompress() failed. Returning original buffer.";
return buf; return buf;
} }
#ifdef CHTTPJOB_DEBUG #ifdef CHTTPJOB_DEBUG
dbg() << "CHttpJob::handle_content_encoding: Gzip::decompress() successful.\n" dbg() << "HttpJob::handle_content_encoding: Gzip::decompress() successful.\n"
<< " Input size = " << buf.size() << "\n" << " Input size = " << buf.size() << "\n"
<< " Output size = " << uncompressed.value().size(); << " Output size = " << uncompressed.value().size();
#endif #endif
@ -81,7 +81,7 @@ void HttpJob::on_socket_connected()
{ {
auto raw_request = m_request.to_raw_request(); auto raw_request = m_request.to_raw_request();
#if 0 #if 0
dbg() << "CHttpJob: raw_request:"; dbg() << "HttpJob: raw_request:";
dbg() << String::copy(raw_request).characters(); dbg() << String::copy(raw_request).characters();
#endif #endif
@ -97,18 +97,18 @@ void HttpJob::on_socket_connected()
return; return;
auto line = m_socket->read_line(PAGE_SIZE); auto line = m_socket->read_line(PAGE_SIZE);
if (line.is_null()) { if (line.is_null()) {
fprintf(stderr, "CHttpJob: Expected HTTP status\n"); fprintf(stderr, "HttpJob: Expected HTTP status\n");
return deferred_invoke([this](auto&) { did_fail(NetworkJob::Error::TransmissionFailed); }); return deferred_invoke([this](auto&) { did_fail(NetworkJob::Error::TransmissionFailed); });
} }
auto parts = String::copy(line, Chomp).split(' '); auto parts = String::copy(line, Chomp).split(' ');
if (parts.size() < 3) { if (parts.size() < 3) {
fprintf(stderr, "CHttpJob: Expected 3-part HTTP status, got '%s'\n", line.data()); fprintf(stderr, "HttpJob: Expected 3-part HTTP status, got '%s'\n", line.data());
return deferred_invoke([this](auto&) { did_fail(NetworkJob::Error::ProtocolFailed); }); return deferred_invoke([this](auto&) { did_fail(NetworkJob::Error::ProtocolFailed); });
} }
bool ok; bool ok;
m_code = parts[1].to_uint(ok); m_code = parts[1].to_uint(ok);
if (!ok) { if (!ok) {
fprintf(stderr, "CHttpJob: Expected numeric HTTP status\n"); fprintf(stderr, "HttpJob: Expected numeric HTTP status\n");
return deferred_invoke([this](auto&) { did_fail(NetworkJob::Error::ProtocolFailed); }); return deferred_invoke([this](auto&) { did_fail(NetworkJob::Error::ProtocolFailed); });
} }
m_state = State::InHeaders; m_state = State::InHeaders;
@ -119,7 +119,7 @@ void HttpJob::on_socket_connected()
return; return;
auto line = m_socket->read_line(PAGE_SIZE); auto line = m_socket->read_line(PAGE_SIZE);
if (line.is_null()) { if (line.is_null()) {
fprintf(stderr, "CHttpJob: Expected HTTP header\n"); fprintf(stderr, "HttpJob: Expected HTTP header\n");
return did_fail(NetworkJob::Error::ProtocolFailed); return did_fail(NetworkJob::Error::ProtocolFailed);
} }
auto chomped_line = String::copy(line, Chomp); auto chomped_line = String::copy(line, Chomp);
@ -129,18 +129,18 @@ void HttpJob::on_socket_connected()
} }
auto parts = chomped_line.split(':'); auto parts = chomped_line.split(':');
if (parts.is_empty()) { if (parts.is_empty()) {
fprintf(stderr, "CHttpJob: Expected HTTP header with key/value\n"); fprintf(stderr, "HttpJob: Expected HTTP header with key/value\n");
return deferred_invoke([this](auto&) { did_fail(NetworkJob::Error::ProtocolFailed); }); return deferred_invoke([this](auto&) { did_fail(NetworkJob::Error::ProtocolFailed); });
} }
auto name = parts[0]; auto name = parts[0];
if (chomped_line.length() < name.length() + 2) { if (chomped_line.length() < name.length() + 2) {
fprintf(stderr, "CHttpJob: Malformed HTTP header: '%s' (%zu)\n", chomped_line.characters(), chomped_line.length()); fprintf(stderr, "HttpJob: Malformed HTTP header: '%s' (%zu)\n", chomped_line.characters(), chomped_line.length());
return deferred_invoke([this](auto&) { did_fail(NetworkJob::Error::ProtocolFailed); }); return deferred_invoke([this](auto&) { did_fail(NetworkJob::Error::ProtocolFailed); });
} }
auto value = chomped_line.substring(name.length() + 2, chomped_line.length() - name.length() - 2); auto value = chomped_line.substring(name.length() + 2, chomped_line.length() - name.length() - 2);
m_headers.set(name, value); m_headers.set(name, value);
#ifdef CHTTPJOB_DEBUG #ifdef CHTTPJOB_DEBUG
dbg() << "CHttpJob: [" << name << "] = '" << value << "'"; dbg() << "HttpJob: [" << name << "] = '" << value << "'";
#endif #endif
return; return;
} }
@ -192,7 +192,7 @@ void HttpJob::start()
m_socket = TCPSocket::construct(this); m_socket = TCPSocket::construct(this);
m_socket->on_connected = [this] { m_socket->on_connected = [this] {
#ifdef CHTTPJOB_DEBUG #ifdef CHTTPJOB_DEBUG
dbg() << "CHttpJob: on_connected callback"; dbg() << "HttpJob: on_connected callback";
#endif #endif
on_socket_connected(); on_socket_connected();
}; };

View file

@ -104,7 +104,7 @@ ByteBuffer IODevice::read(size_t max_size)
bool IODevice::can_read_from_fd() const bool IODevice::can_read_from_fd() const
{ {
// FIXME: Can we somehow remove this once CSocket is implemented using non-blocking sockets? // FIXME: Can we somehow remove this once Core::Socket is implemented using non-blocking sockets?
fd_set rfds; fd_set rfds;
FD_ZERO(&rfds); FD_ZERO(&rfds);
FD_SET(m_fd, &rfds); FD_SET(m_fd, &rfds);

View file

@ -37,7 +37,7 @@ namespace Core {
LocalSocket::LocalSocket(int fd, Object* parent) LocalSocket::LocalSocket(int fd, Object* parent)
: Socket(Socket::Type::Local, parent) : Socket(Socket::Type::Local, parent)
{ {
// NOTE: This constructor is used by CLocalServer::accept(), so the socket is already connected. // NOTE: This constructor is used by LocalServer::accept(), so the socket is already connected.
m_connected = true; m_connected = true;
set_fd(fd); set_fd(fd);
set_mode(IODevice::ReadWrite); set_mode(IODevice::ReadWrite);

View file

@ -40,7 +40,7 @@ HashMap<pid_t, Core::ProcessStatistics> ProcessStatisticsReader::get_all()
{ {
auto file = Core::File::construct("/proc/all"); auto file = Core::File::construct("/proc/all");
if (!file->open(Core::IODevice::ReadOnly)) { if (!file->open(Core::IODevice::ReadOnly)) {
fprintf(stderr, "CProcessStatisticsReader: Failed to open /proc/all: %s\n", file->error_string()); fprintf(stderr, "ProcessStatisticsReader: Failed to open /proc/all: %s\n", file->error_string());
return {}; return {};
} }

View file

@ -77,7 +77,7 @@ public:
case Type::Local: case Type::Local:
return m_local_address; return m_local_address;
default: default:
return "[CSocketAddress]"; return "[SocketAddress]";
} }
} }

View file

@ -33,7 +33,7 @@ namespace Core {
TCPSocket::TCPSocket(int fd, Object* parent) TCPSocket::TCPSocket(int fd, Object* parent)
: Socket(Socket::Type::TCP, parent) : Socket(Socket::Type::TCP, parent)
{ {
// NOTE: This constructor is used by CTCPServer::accept(), so the socket is already connected. // NOTE: This constructor is used by TCPServer::accept(), so the socket is already connected.
m_connected = true; m_connected = true;
set_fd(fd); set_fd(fd);
set_mode(IODevice::ReadWrite); set_mode(IODevice::ReadWrite);

View file

@ -33,7 +33,7 @@ namespace Core {
UdpSocket::UdpSocket(int fd, Object* parent) UdpSocket::UdpSocket(int fd, Object* parent)
: Socket(Socket::Type::UDP, parent) : Socket(Socket::Type::UDP, parent)
{ {
// NOTE: This constructor is used by CUdpServer::accept(), so the socket is already connected. // NOTE: This constructor is used by UdpServer::accept(), so the socket is already connected.
m_connected = true; m_connected = true;
set_fd(fd); set_fd(fd);
set_mode(IODevice::ReadWrite); set_mode(IODevice::ReadWrite);

View file

@ -69,7 +69,7 @@ int Application::exec()
{ {
int exit_code = m_event_loop->exec(); int exit_code = m_event_loop->exec();
// NOTE: Maybe it would be cool to return instead of exit()? // NOTE: Maybe it would be cool to return instead of exit()?
// This would require cleaning up all the CObjects on the heap. // This would require cleaning up all the Core::Objects on the heap.
exit(exit_code); exit(exit_code);
return exit_code; return exit_code;
} }

View file

@ -95,7 +95,7 @@ void FileSystemModel::Node::traverse_if_needed(const FileSystemModel& model)
auto full_path = this->full_path(model); auto full_path = this->full_path(model);
Core::DirIterator di(full_path, Core::DirIterator::SkipDots); Core::DirIterator di(full_path, Core::DirIterator::SkipDots);
if (di.has_error()) { if (di.has_error()) {
fprintf(stderr, "CDirIterator: %s\n", di.error_string()); fprintf(stderr, "DirIterator: %s\n", di.error_string());
return; return;
} }

View file

@ -45,7 +45,7 @@ GFontDatabase::GFontDatabase()
{ {
Core::DirIterator di("/res/fonts", Core::DirIterator::SkipDots); Core::DirIterator di("/res/fonts", Core::DirIterator::SkipDots);
if (di.has_error()) { if (di.has_error()) {
fprintf(stderr, "CDirIterator: %s\n", di.error_string()); fprintf(stderr, "DirIterator: %s\n", di.error_string());
exit(1); exit(1);
} }
while (di.has_next()) { while (di.has_next()) {

View file

@ -176,7 +176,7 @@ bool copy_directory(String src_path, String dst_path)
} }
Core::DirIterator di(src_path, Core::DirIterator::SkipDots); Core::DirIterator di(src_path, Core::DirIterator::SkipDots);
if (di.has_error()) { if (di.has_error()) {
fprintf(stderr, "cp: CDirIterator: %s\n", di.error_string()); fprintf(stderr, "cp: DirIterator: %s\n", di.error_string());
return false; return false;
} }
while (di.has_next()) { while (di.has_next()) {

View file

@ -44,7 +44,7 @@ static int handle_show_all()
{ {
Core::DirIterator di("/res/wallpapers", Core::DirIterator::SkipDots); Core::DirIterator di("/res/wallpapers", Core::DirIterator::SkipDots);
if (di.has_error()) { if (di.has_error()) {
fprintf(stderr, "CDirIterator: %s\n", di.error_string()); fprintf(stderr, "DirIterator: %s\n", di.error_string());
return 1; return 1;
} }

View file

@ -78,7 +78,7 @@ static int handle_show_all()
{ {
Core::DirIterator di("/proc/sys", Core::DirIterator::SkipDots); Core::DirIterator di("/proc/sys", Core::DirIterator::SkipDots);
if (di.has_error()) { if (di.has_error()) {
fprintf(stderr, "CDirIterator: %s\n", di.error_string()); fprintf(stderr, "DirIterator: %s\n", di.error_string());
return 1; return 1;
} }

View file

@ -75,7 +75,7 @@ off_t find_seek_pos(Core::File& file, int wanted_lines)
off_t end = pos; off_t end = pos;
int lines = 0; int lines = 0;
// FIXME: Reading char-by-char is only OK if CIODevice's read buffer // FIXME: Reading char-by-char is only OK if IODevice's read buffer
// is smart enough to not read char-by-char. Fix it there, or fix it here :) // is smart enough to not read char-by-char. Fix it there, or fix it here :)
for (; pos >= 0; pos--) { for (; pos >= 0; pos--) {
file.seek(pos); file.seek(pos);