1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 14:57:34 +00:00

AK+Everywhere: Rename String to DeprecatedString

We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
This commit is contained in:
Linus Groh 2022-12-04 18:02:33 +00:00 committed by Andreas Kling
parent f74251606d
commit 6e19ab2bbc
2006 changed files with 11635 additions and 11636 deletions

View file

@ -26,7 +26,7 @@ void ConnectionFromClient::die()
s_connections.remove(client_id());
}
Messages::LookupServer::LookupNameResponse ConnectionFromClient::lookup_name(String const& name)
Messages::LookupServer::LookupNameResponse ConnectionFromClient::lookup_name(DeprecatedString const& name)
{
auto maybe_answers = LookupServer::the().lookup(name, RecordType::A);
if (maybe_answers.is_error()) {
@ -35,19 +35,19 @@ Messages::LookupServer::LookupNameResponse ConnectionFromClient::lookup_name(Str
}
auto answers = maybe_answers.release_value();
Vector<String> addresses;
Vector<DeprecatedString> addresses;
for (auto& answer : answers) {
addresses.append(answer.record_data());
}
return { 0, move(addresses) };
}
Messages::LookupServer::LookupAddressResponse ConnectionFromClient::lookup_address(String const& address)
Messages::LookupServer::LookupAddressResponse ConnectionFromClient::lookup_address(DeprecatedString const& address)
{
if (address.length() != 4)
return { 1, String() };
return { 1, DeprecatedString() };
IPv4Address ip_address { (u8 const*)address.characters() };
auto name = String::formatted("{}.{}.{}.{}.in-addr.arpa",
auto name = DeprecatedString::formatted("{}.{}.{}.{}.in-addr.arpa",
ip_address[3],
ip_address[2],
ip_address[1],
@ -56,12 +56,12 @@ Messages::LookupServer::LookupAddressResponse ConnectionFromClient::lookup_addre
auto maybe_answers = LookupServer::the().lookup(name, RecordType::PTR);
if (maybe_answers.is_error()) {
dbgln("LookupServer: Failed to lookup PTR record: {}", maybe_answers.error());
return { 1, String() };
return { 1, DeprecatedString() };
}
auto answers = maybe_answers.release_value();
if (answers.is_empty())
return { 1, String() };
return { 1, DeprecatedString() };
return { 0, answers[0].record_data() };
}
}

View file

@ -25,8 +25,8 @@ public:
private:
explicit ConnectionFromClient(NonnullOwnPtr<Core::Stream::LocalSocket>, int client_id);
virtual Messages::LookupServer::LookupNameResponse lookup_name(String const&) override;
virtual Messages::LookupServer::LookupAddressResponse lookup_address(String const&) override;
virtual Messages::LookupServer::LookupNameResponse lookup_name(DeprecatedString const&) override;
virtual Messages::LookupServer::LookupAddressResponse lookup_address(DeprecatedString const&) override;
};
}

View file

@ -7,9 +7,9 @@
#include "LookupServer.h"
#include "ConnectionFromClient.h"
#include <AK/Debug.h>
#include <AK/DeprecatedString.h>
#include <AK/HashMap.h>
#include <AK/Random.h>
#include <AK/String.h>
#include <AK/StringBuilder.h>
#include <LibCore/ConfigFile.h>
#include <LibCore/File.h>
@ -78,7 +78,7 @@ LookupServer::LookupServer()
void LookupServer::load_etc_hosts()
{
m_etc_hosts.clear();
auto add_answer = [this](Name const& name, RecordType record_type, String data) {
auto add_answer = [this](Name const& name, RecordType record_type, DeprecatedString data) {
m_etc_hosts.ensure(name).empend(name, record_type, RecordClass::IN, s_static_ttl, move(data), false);
};
@ -115,7 +115,7 @@ void LookupServer::load_etc_hosts()
auto raw_addr = maybe_address->to_in_addr_t();
Name name { fields[1] };
add_answer(name, RecordType::A, String { (char const*)&raw_addr, sizeof(raw_addr) });
add_answer(name, RecordType::A, DeprecatedString { (char const*)&raw_addr, sizeof(raw_addr) });
StringBuilder builder;
builder.append(maybe_address->to_string_reversed());
@ -124,7 +124,7 @@ void LookupServer::load_etc_hosts()
}
}
static String get_hostname()
static DeprecatedString get_hostname()
{
char buffer[_POSIX_HOST_NAME_MAX];
VERIFY(gethostname(buffer, sizeof(buffer)) == 0);
@ -163,7 +163,7 @@ ErrorOr<Vector<Answer>> LookupServer::lookup(Name const& name, RecordType record
if (record_type == RecordType::A && get_hostname() == name) {
IPv4Address address = { 127, 0, 0, 1 };
auto raw_address = address.to_in_addr_t();
Answer answer { name, RecordType::A, RecordClass::IN, s_static_ttl, String { (char const*)&raw_address, sizeof(raw_address) }, false };
Answer answer { name, RecordType::A, RecordClass::IN, s_static_ttl, DeprecatedString { (char const*)&raw_address, sizeof(raw_address) }, false };
answers.append(move(answer));
return answers;
}
@ -224,7 +224,7 @@ ErrorOr<Vector<Answer>> LookupServer::lookup(Name const& name, RecordType record
return answers;
}
ErrorOr<Vector<Answer>> LookupServer::lookup(Name const& name, String const& nameserver, bool& did_get_response, RecordType record_type, ShouldRandomizeCase should_randomize_case)
ErrorOr<Vector<Answer>> LookupServer::lookup(Name const& name, DeprecatedString const& nameserver, bool& did_get_response, RecordType record_type, ShouldRandomizeCase should_randomize_case)
{
Packet request;
request.set_is_query();

View file

@ -32,12 +32,12 @@ private:
void load_etc_hosts();
void put_in_cache(Answer const&);
ErrorOr<Vector<Answer>> lookup(Name const& hostname, String const& nameserver, bool& did_get_response, RecordType record_type, ShouldRandomizeCase = ShouldRandomizeCase::Yes);
ErrorOr<Vector<Answer>> lookup(Name const& hostname, DeprecatedString const& nameserver, bool& did_get_response, RecordType record_type, ShouldRandomizeCase = ShouldRandomizeCase::Yes);
OwnPtr<IPC::MultiServer<ConnectionFromClient>> m_server;
RefPtr<DNSServer> m_dns_server;
RefPtr<MulticastDNS> m_mdns;
Vector<String> m_nameservers;
Vector<DeprecatedString> m_nameservers;
RefPtr<Core::FileWatcher> m_file_watcher;
HashMap<Name, Vector<Answer>, Name::Traits> m_etc_hosts;
HashMap<Name, Vector<Answer>, Name::Traits> m_lookup_cache;

View file

@ -2,6 +2,6 @@
endpoint LookupServer
{
// Keep these definitions synchronized with gethostbyname and gethostbyaddr in netdb.cpp
lookup_name(String name) => (int code, Vector<String> addresses)
lookup_address(String address) => (int code, String name)
lookup_name(DeprecatedString name) => (int code, Vector<DeprecatedString> addresses)
lookup_address(DeprecatedString address) => (int code, DeprecatedString name)
}

View file

@ -5,11 +5,11 @@
*/
#include "MulticastDNS.h"
#include <AK/DeprecatedString.h>
#include <AK/IPv4Address.h>
#include <AK/JsonArray.h>
#include <AK/JsonObject.h>
#include <AK/JsonValue.h>
#include <AK/String.h>
#include <LibCore/File.h>
#include <limits.h>
#include <poll.h>
@ -26,7 +26,7 @@ MulticastDNS::MulticastDNS(Object* parent)
if (gethostname(buffer, sizeof(buffer)) < 0) {
perror("gethostname");
} else {
m_hostname = String::formatted("{}.local", buffer);
m_hostname = DeprecatedString::formatted("{}.local", buffer);
}
u8 zero = 0;
@ -93,7 +93,7 @@ void MulticastDNS::announce()
RecordType::A,
RecordClass::IN,
120,
String { (char const*)&raw_addr, sizeof(raw_addr) },
DeprecatedString { (char const*)&raw_addr, sizeof(raw_addr) },
true,
};
response.add_answer(answer);