Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a2f85fb6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Replace StringAppendF() with fmt::format_to"

parents 52cf009b 46dfd585
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -67,7 +67,6 @@

using aidl::android::net::IDnsResolver;
using aidl::android::net::ResolverOptionsParcel;
using android::base::StringAppendF;
using android::net::DnsQueryEvent;
using android::net::DnsStats;
using android::net::Experiments;
@@ -1121,11 +1120,9 @@ void _resolv_cache_query_failed(unsigned netid, const void* query, int querylen,
}

static void cache_dump_mru_locked(Cache* cache) {
    std::string buf;

    StringAppendF(&buf, "MRU LIST (%2d): ", cache->num_entries);
    std::string buf = fmt::format("MRU LIST ({:2d}): ", cache->num_entries);
    for (Entry* e = cache->mru_list.mru_next; e != &cache->mru_list; e = e->mru_next) {
        StringAppendF(&buf, " %d", e->id);
        fmt::format_to(std::back_inserter(buf), " {}", e->id);
    }

    LOG(INFO) << __func__ << ": " << buf;
+41 −40
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@
#define RESOLV_ALLOW_VERBOSE_LOGGING 0
#endif

using android::base::StringAppendF;
using fmt::format_to;

struct res_sym {
    int number;            /* Identifying number, like T_MX */
@@ -142,30 +142,31 @@ static void do_section(ns_msg* handle, ns_sect section) {
    int buflen = 2048;
    ns_rr rr;
    std::string s;

    auto out = std::back_inserter(s);
    /*
     * Print answer records.
     */
    for (;;) {
        if (ns_parserr(handle, section, rrnum, &rr)) {
            if (errno != ENODEV) StringAppendF(&s, "ns_parserr: %s", strerror(errno));
            if (errno != ENODEV) format_to(out, "ns_parserr: {}", strerror(errno));

            LOG(VERBOSE) << s;
            return;
        }
        if (rrnum == 0) {
            int opcode = ns_msg_getflag(*handle, ns_f_opcode);
            StringAppendF(&s, ";; %s SECTION:\n", p_section(section, opcode));
            format_to(out, ";; {} SECTION:\n", p_section(section, opcode));
        }
        if (section == ns_s_qd)
            StringAppendF(&s, ";;\t%s, type = %s, class = %s\n", ns_rr_name(rr),
            format_to(out, ";;\t{}, type = {}, class = {}\n", ns_rr_name(rr),
                      p_type(ns_rr_type(rr)), p_class(ns_rr_class(rr)));
        else if (section == ns_s_ar && ns_rr_type(rr) == ns_t_opt) {
            size_t rdatalen;
            uint16_t optcode, optlen;

            rdatalen = ns_rr_rdlen(rr);
            StringAppendF(&s, "; EDNS: version: %" PRIu32 ", udp=%u, flags=%" PRIu32 "\n",
                          (rr.ttl >> 16) & 0xff, ns_rr_class(rr), rr.ttl & 0xffff);
            format_to(out, "; EDNS: version: {}, udp={}, flags={}\n", (rr.ttl >> 16) & 0xff,
                      ns_rr_class(rr), rr.ttl & 0xffff);
            const uint8_t* cp = ns_rr_rdata(rr);
            while (rdatalen <= ns_rr_rdlen(rr) && rdatalen >= 4) {
                int i;
@@ -174,33 +175,33 @@ static void do_section(ns_msg* handle, ns_sect section) {
                GETSHORT(optlen, cp);

                if (optcode == NS_OPT_NSID) {
                    StringAppendF(&s, "; NSID: ");
                    format_to(out, "; NSID: ");
                    if (optlen == 0) {
                        StringAppendF(&s, "; NSID\n");
                        format_to(out, "; NSID\n");
                    } else {
                        StringAppendF(&s, "; NSID: ");
                        format_to(out, "; NSID: ");
                        for (i = 0; i < optlen; i++) {
                            StringAppendF(&s, "%02x ", cp[i]);
                            format_to(out, "{:02x} ", cp[i]);
                        }
                        StringAppendF(&s, " (");
                        format_to(out, " (");
                        for (i = 0; i < optlen; i++) {
                            StringAppendF(&s, "%c", isprint(cp[i]) ? cp[i] : '.');
                            format_to(out, "{} ", isprint(cp[i]) ? cp[i] : '.');
                        }
                        StringAppendF(&s, ")\n");
                        format_to(out, ")\n");
                    }
                } else {
                    if (optlen == 0) {
                        StringAppendF(&s, "; OPT=%u\n", optcode);
                        format_to(out, "; OPT={}\n", optcode);
                    } else {
                        StringAppendF(&s, "; OPT=%u: ", optcode);
                        format_to(out, "; OPT={}: ", optcode);
                        for (i = 0; i < optlen; i++) {
                            StringAppendF(&s, "%02x ", cp[i]);
                            format_to(out, "{:02x} ", cp[i]);
                        }
                        StringAppendF(&s, " (");
                        format_to(out, " (");
                        for (i = 0; i < optlen; i++) {
                            StringAppendF(&s, "%c", isprint(cp[i]) ? cp[i] : '.');
                            format_to(out, "{}", isprint(cp[i]) ? cp[i] : '.');
                        }
                        StringAppendF(&s, ")\n");
                        format_to(out, ")\n");
                    }
                }
                rdatalen -= 4 + optlen;
@@ -215,16 +216,16 @@ static void do_section(ns_msg* handle, ns_sect section) {
                        buflen += 1024;
                        continue;
                    } else {
                        StringAppendF(&s, "buflen over 131072");
                        format_to(out, "buflen over 131072");
                        PLOG(VERBOSE) << s;
                        return;
                    }
                }
                StringAppendF(&s, "ns_sprintrr failed");
                format_to(out, "ns_sprintrr failed");
                PLOG(VERBOSE) << s;
                return;
            }
            StringAppendF(&s, ";; %s\n", buf.get());
            format_to(out, ";; {}\n", buf.get());
        }
        rrnum++;
    }
@@ -269,22 +270,22 @@ void res_pquery(std::span<const uint8_t> msg) {
    /*
     * Print header fields.
     */
    std::string s;
    StringAppendF(&s, ";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n", _res_opcodes[opcode],
                  p_rcode((int)rcode), id);
    StringAppendF(&s, ";; flags:");
    if (ns_msg_getflag(handle, ns_f_qr)) StringAppendF(&s, " qr");
    if (ns_msg_getflag(handle, ns_f_aa)) StringAppendF(&s, " aa");
    if (ns_msg_getflag(handle, ns_f_tc)) StringAppendF(&s, " tc");
    if (ns_msg_getflag(handle, ns_f_rd)) StringAppendF(&s, " rd");
    if (ns_msg_getflag(handle, ns_f_ra)) StringAppendF(&s, " ra");
    if (ns_msg_getflag(handle, ns_f_z)) StringAppendF(&s, " ??");
    if (ns_msg_getflag(handle, ns_f_ad)) StringAppendF(&s, " ad");
    if (ns_msg_getflag(handle, ns_f_cd)) StringAppendF(&s, " cd");
    StringAppendF(&s, "; %s: %d", p_section(ns_s_qd, (int)opcode), qdcount);
    StringAppendF(&s, ", %s: %d", p_section(ns_s_an, (int)opcode), ancount);
    StringAppendF(&s, ", %s: %d", p_section(ns_s_ns, (int)opcode), nscount);
    StringAppendF(&s, ", %s: %d", p_section(ns_s_ar, (int)opcode), arcount);
    std::string s = fmt::format(";; ->>HEADER<<- opcode: {}, status: {}, id: {}\n",
                                _res_opcodes[opcode], p_rcode((int)rcode), id);
    auto out = std::back_inserter(s);
    format_to(out, ";; flags:");
    if (ns_msg_getflag(handle, ns_f_qr)) format_to(out, " qr");
    if (ns_msg_getflag(handle, ns_f_aa)) format_to(out, " aa");
    if (ns_msg_getflag(handle, ns_f_tc)) format_to(out, " tc");
    if (ns_msg_getflag(handle, ns_f_rd)) format_to(out, " rd");
    if (ns_msg_getflag(handle, ns_f_ra)) format_to(out, " ra");
    if (ns_msg_getflag(handle, ns_f_z)) format_to(out, " ??");
    if (ns_msg_getflag(handle, ns_f_ad)) format_to(out, " ad");
    if (ns_msg_getflag(handle, ns_f_cd)) format_to(out, " cd");
    format_to(out, "; {}: {}", p_section(ns_s_qd, (int)opcode), qdcount);
    format_to(out, ", {}: {}", p_section(ns_s_an, (int)opcode), ancount);
    format_to(out, ", {}: {}", p_section(ns_s_ns, (int)opcode), nscount);
    format_to(out, ", {}: {}", p_section(ns_s_ar, (int)opcode), arcount);

    LOG(VERBOSE) << s;