Bläddra i källkod

Merge branch 'master' into next

* master:
  Update bdlib
  Update for new bdlib API
  mdata()->begin(), data()->cbegin().
  Implicit conversion is fine here
  Simplify traversing the symbol table
  Simplify some Array handling
  Update bdlib
  Update bdlib
Bryan Drewery 7 år sedan
förälder
incheckning
e840212908

+ 1 - 1
lib/bdlib

@@ -1 +1 @@
-Subproject commit f52bbedef0db3b744730141c688335f1e143f6b6
+Subproject commit 145e14bf013b3c171483c660b60682167a09ff65

+ 9 - 6
src/adns.cc

@@ -1303,8 +1303,11 @@ void tell_dnsdebug(int idx)
 
 	for (int i = 0; i < ncache; i++) {
 		dprintf(idx, "cache(%d) %s expires in %ds\n", i, cache[i].query, (int) (cache[i].expiretime - now));
-		for (size_t n = 0; n < cache[i].answer->size(); n++)
-			dprintf(idx, "%zu: %s\n", n, bd::String((*(cache[i].answer))[n]).c_str());
+		size_t n = 0;
+		for (const auto& answer : *cache[i].answer) {
+			dprintf(idx, "%zu: %s\n", n, answer.c_str());
+			n++;
+		}
 	}
 }
 
@@ -1396,10 +1399,10 @@ bool valid_dns_id(int idx, int id)
 	return 0;
 }
 
-bd::String dns_find_ip(bd::Array<bd::String> ips, int af_type) {
-	for (size_t i = 0; i < ips.size(); ++i) {
-		if (is_dotted_ip(bd::String(ips[i]).c_str()) == af_type) {
-			return ips[i];
+bd::String dns_find_ip(const bd::Array<bd::String>& ips, int af_type) {
+	for (const auto& ip : ips) {
+		if (is_dotted_ip(ip.c_str()) == af_type) {
+			return ip;
 		}
 	}
 	return bd::String();

+ 3 - 2
src/adns.h

@@ -43,7 +43,8 @@ TXT             16 text strings
 #include <bdlib/src/String.h>
 #include <bdlib/src/Array.h>
 
-typedef void (*dns_callback_t)(int, void *client_data, const char *query, bd::Array<bd::String> answers);
+typedef void (*dns_callback_t)(int, void *client_data, const char *query,
+    const bd::Array<bd::String>& answers);
 
 int egg_dns_init(void);
 //int egg_dns_shutdown(void);
@@ -57,7 +58,7 @@ void tell_dnsdebug(int);
 void dns_cache_flush();
 bool valid_dns_id(int, int);
 int reverse_ip(const char *host, char *reverse);
-bd::String dns_find_ip(bd::Array<bd::String> ips, int af_type);
+bd::String dns_find_ip(const bd::Array<bd::String>& ips, int af_type);
 
 extern int		dns_sock, dns_idx;
 extern const char	*dns_ip;

+ 2 - 2
src/base64.cc

@@ -128,7 +128,7 @@ b64enc(const unsigned char *data, size_t len)
  */
 bd::String broken_base64Encode(const bd::String& string) {
   size_t len = string.length();
-  char *p = b64enc_bd((unsigned char*) string.data(), &len);
+  char *p = b64enc_bd((unsigned char*) string.cbegin(), &len);
   bd::String encoded(p, len);
   free(p);
   return encoded;
@@ -141,7 +141,7 @@ bd::String broken_base64Encode(const bd::String& string) {
  */
 bd::String broken_base64Decode(const bd::String& string) {
   size_t len = string.length();
-  char *p = b64dec_bd((unsigned char*) string.data(), &len);
+  char *p = b64dec_bd((unsigned char*) string.cbegin(), &len);
   bd::String decoded(p, len);
   free(p);
   return decoded;

+ 9 - 11
src/binary.cc

@@ -502,31 +502,29 @@ readcfg(const char *cfgfile, bool read_stdin)
 void writecfg() {
   const char salt1[] = SALT1;
   const char salt2[] = SALT2;
-  bd::Array<bd::String> owners(bd::String(settings.owners).split(","));
-  const bd::Array<bd::String> hubs(conf.hubs);
-  bd::Array<bd::String> hubInfo;
+  const auto& owners(bd::String(settings.owners).split(","));
 
   printf("PACKNAME %s\n", settings.packname);
   // Display the shellhash as salted-sha1 if it is not already
-  bd::String shellhash(settings.shellhash);
+  const bd::String shellhash(settings.shellhash);
   printf("BINARYPASS %s\n", (shellhash.length() == 40 || shellhash.length() == 47) ? shellhash.c_str() : salted_sha1(shellhash.c_str()));
   printf("DCCPREFIX %s\n", settings.dcc_prefix);
-  for (size_t i = 0; i < owners.length(); ++i) {
-    bd::Array<bd::String> ownerInfo(static_cast<bd::String>(owners[i]).split(" "));
+  for (const auto &ownerLine : owners) {
+    auto ownerInfo(ownerLine.split(" "));
     // Ensure the pass is salted-sha1
-    const size_t ownerPassLength = static_cast<bd::String>(ownerInfo[1]).length();
+    const size_t ownerPassLength = ownerInfo.at(1).length();
     if (ownerPassLength != 40 && ownerPassLength != 47) {
-      ownerInfo[1] = bd::String(salted_sha1(static_cast<bd::String>(ownerInfo[1]).c_str()));
+      ownerInfo[1] = bd::String(salted_sha1(ownerInfo.at(1).c_str()));
     }
     printf("OWNER %s\n", ownerInfo.join(" ").c_str());
   }
-  for (size_t i = 0; i < hubs.length(); ++i) {
-    hubInfo = static_cast<bd::String>(hubs[i]).split(' ');
+  for (auto hubLine : conf.hubs) {
+    auto hubInfo = hubLine.split(' ');
     // Trim away hublevel
     if (hubInfo.length() == 4) {
       hubInfo.resize(3);
     }
-    printf("HUB %s\n", static_cast<bd::String>(hubInfo.join(" ")).c_str());
+    printf("HUB %s\n", hubInfo.join(" ").c_str());
   }
   printf("SALT1 %s\n", salt1);
   printf("SALT2 %s\n", salt2);

+ 8 - 4
src/botnet.cc

@@ -994,7 +994,8 @@ int botunlink(int idx, const char *nick, const char *reason)
   return 0;
 }
 
-static void botlink_dns_callback(int, void *, const char *, bd::Array<bd::String>);
+static void botlink_dns_callback(int, void *, const char *,
+    const bd::Array<bd::String>&);
 static void botlink_real(int);
 
 /* Link to another bot
@@ -1094,7 +1095,8 @@ int botlink(char *linker, int idx, char *nick)
   return 0;
 }
 
-static void botlink_dns_callback(int id, void *client_data, const char *host, bd::Array<bd::String> ips)
+static void botlink_dns_callback(int id, void *client_data, const char *host,
+    const bd::Array<bd::String>& ips)
 {
   long data = (long) client_data;
   int i = (int) data;
@@ -1207,7 +1209,8 @@ static void failed_tandem_relay(int idx)
   return;
 }
 
-static void tandem_relay_dns_callback(int, void *, const char *, bd::Array<bd::String>);
+static void tandem_relay_dns_callback(int, void *, const char *,
+    const bd::Array<bd::String>&);
 
 /* Relay to another tandembot
  */
@@ -1271,7 +1274,8 @@ void tandem_relay(int idx, char *nick, int i)
   /* wait for async reply */
 }
 
-static void tandem_relay_dns_callback(int id, void *client_data, const char *host, bd::Array<bd::String> ips)
+static void tandem_relay_dns_callback(int id, void *client_data,
+    const char *host, const bd::Array<bd::String>& ips)
 {
   //64bit hacks
   long data = (long) client_data;

+ 7 - 7
src/chanprog.cc

@@ -386,15 +386,15 @@ void load_internal_users()
 
   /* hubs */
   for (size_t idx = 0; idx < conf.hubs.length(); ++idx) {
-    bd::Array<bd::String> params(static_cast<bd::String>(conf.hubs[idx]).split(' '));
-    const bd::String handle(params[0]);
-    const bd::String address(params[1]);
-    const in_port_t port = atoi(static_cast<bd::String>(params[2]).c_str());
-    const unsigned short hublevel = params.length() == 4 ? atoi(static_cast<bd::String>(params[3]).c_str()) : (idx + 1);
+    const auto& params(conf.hubs.at(idx).split(' '));
+    const auto& handle(params[0]);
+    const auto& address(params[1]);
+    const in_port_t port = atoi(params[2].c_str());
+    const unsigned short hublevel = params.length() == 4 ? atoi(params[3].c_str()) : (idx + 1);
 
-    if (!(u = get_user_by_handle(userlist, const_cast<char*>(handle.c_str())))) {
+    if (!(u = get_user_by_handle(userlist, handle.c_str()))) {
       userlist = adduser(userlist, handle.c_str(), "none", "-", USER_OP, 1);
-      u = get_user_by_handle(userlist, const_cast<char*>(handle.c_str()));
+      u = get_user_by_handle(userlist, handle.c_str());
     }
 
     simple_snprintf(tmp, sizeof(tmp), "%li [internal]", (long)now);

+ 10 - 9
src/cmds.cc

@@ -3371,7 +3371,7 @@ static void cmd_newleaf(int idx, char *par)
 
 static void cmd_newhub(int idx, char *par)
 {
-  bd::Array<bd::String> params(bd::String(par).split(' '));
+  const auto& params(bd::String(par).split(' '));
   if (!par[0] || params.length() < 3) {
     dprintf(idx, "Usage: newhub <handle> <address> <port> [hublevel]\n");
     return;
@@ -3384,7 +3384,7 @@ static void cmd_newhub(int idx, char *par)
   if (handle.length() > HANDLEN) {
     handle.resize(HANDLEN);
   }
-  if (get_user_by_handle(userlist, const_cast<char*>(handle.c_str()))) {
+  if (get_user_by_handle(userlist, handle.c_str())) {
     dprintf(idx, "Already got a %s hub\n", handle.c_str());
     return;
   } else if (strchr(BADHANDCHARS, handle[0]) != NULL) {
@@ -3392,13 +3392,13 @@ static void cmd_newhub(int idx, char *par)
     return;
   }
 
-  bd::String address(params[1]);
-  in_port_t port = atoi(static_cast<bd::String>(params[2]).c_str());
+  const auto& address(params[1]);
+  in_port_t port = atoi(params[2].c_str());
 
   unsigned short hublevel = 0;
   // Was a hublevel passed in?
   if (params.length() == 4) {
-    hublevel = atoi(static_cast<bd::String>(params[3]).c_str());
+    hublevel = atoi(params[3].c_str());
   } else {
     // Find next available hublevel
     for (struct userrec *u = userlist; u; u = u->next) {
@@ -3415,7 +3415,7 @@ static void cmd_newhub(int idx, char *par)
   char tmp[81] = "";
 
   userlist = adduser(userlist, handle.c_str(), "none", "-", USER_OP, 1);
-  u1 = get_user_by_handle(userlist, const_cast<char*>(handle.c_str()));
+  u1 = get_user_by_handle(userlist, handle.c_str());
   bi = (struct bot_addr *) calloc(1, sizeof(struct bot_addr));
   bi->uplink = (char *) calloc(1, 1);
   bi->address = strdup(address.c_str());
@@ -4310,7 +4310,8 @@ static void cmd_crontab(int idx, char *par) {
   }
 }
 
-static void my_dns_callback(int id, void *client_data, const char *host, bd::Array<bd::String> ips)
+static void my_dns_callback(int id, void *client_data, const char *host,
+    const bd::Array<bd::String>& ips)
 {
   //64bit hacks
   long data = (long) client_data;
@@ -4322,8 +4323,8 @@ static void my_dns_callback(int id, void *client_data, const char *host, bd::Arr
     return;
 
   if (ips.size())
-    for (size_t i = 0; i < ips.size(); ++i)
-      dprintf(idx, "Resolved %s using (%s) to: %s\n", host, dns_ip, bd::String(ips[i]).c_str());
+    for (const auto& ip : ips)
+      dprintf(idx, "Resolved %s using (%s) to: %s\n", host, dns_ip, ip.c_str());
   else
     dprintf(idx, "Failed to lookup via (%s): %s\n", dns_ip, host);
 

+ 14 - 12
src/conf.cc

@@ -707,16 +707,18 @@ readconf(const char *fname, int bits)
 
 char s1_9[3] = "",s1_5[3] = "",s1_1[3] = "";
 
-bool hubSort (bd::String hub1, bd::String hub2) {
-  bd::Array<bd::String> hub1params(static_cast<bd::String>(hub1).split(' '));
-  bd::Array<bd::String> hub2params(static_cast<bd::String>(hub2).split(' '));
+static bool
+__attribute__((pure))
+hubSort (const bd::String& hub1, const bd::String& hub2) {
+  const auto& hub1params(hub1.split(' '));
+  const auto& hub2params(hub2.split(' '));
 
   unsigned short hub1level = 99, hub2level = 99;
   if (hub1params.length() == 4) {
-    hub1level = atoi(static_cast<bd::String>(hub1params[3]).c_str());
+    hub1level = atoi(hub1params[3].c_str());
   }
   if (hub2params.length() == 4) {
-    hub2level = atoi(static_cast<bd::String>(hub2params[3]).c_str());
+    hub2level = atoi(hub2params[3].c_str());
   }
   return hub1level < hub2level;
 }
@@ -814,10 +816,10 @@ writeconf(char *filename, int fd, int bits)
     bd::Array<bd::String> sortedhubs(conf.hubs);
     std::sort(sortedhubs.begin(), sortedhubs.end(), hubSort);
 
-    for (size_t idx = 0; idx < sortedhubs.length(); ++idx) {
-      bd::Array<bd::String> hubparams(static_cast<bd::String>(sortedhubs[idx]).split(' '));
-      bd::String hubnick(hubparams[0]), address(hubparams[1]);
-      in_port_t port = atoi(static_cast<bd::String>(hubparams[2]).c_str());
+    for (const auto& hubLine : sortedhubs) {
+      const auto& hubparams(hubLine.split(' '));
+      const auto& hubnick(hubparams[0]), address(hubparams[1]);
+      const in_port_t port = atoi(hubparams[2].c_str());
       *stream << bd::String::printf(STR("! hub %s %s %d\n"), hubnick.c_str(), address.c_str(), port);
     }
     comment("");
@@ -1044,9 +1046,9 @@ void conf_update_hubs(struct userrec* list) {
   }
 
   conf.hubs.clear();
-  conf.hubs.Reserve(hubUsers.length());
-  for (size_t idx = 0; idx < hubUsers.length(); ++idx) {
-    struct userrec *u = get_user_by_handle(list, const_cast<char*>(static_cast<bd::String>(hubUsers[idx]).c_str()));
+  conf.hubs.reserve(hubUsers.length());
+  for (const auto& hubUser : hubUsers) {
+    struct userrec *u = get_user_by_handle(list, hubUser.c_str());
     struct bot_addr *bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u);
     conf.hubs << bd::String::printf("%s %s %d %d", u->handle, bi->address, bi->telnet_port, bi->hublevel);
   }

+ 2 - 2
src/crypto/aes_util.cc

@@ -45,7 +45,7 @@ bd::String encrypt_string_cbc(const bd::String& key, bd::String data, bd::String
   data.resize(data.length() + padding, padding);
 
   AES_set_encrypt_key((const unsigned char *) key.c_str(), CRYPT_KEYBITS, &e_key);
-  AES_cbc_encrypt((const unsigned char*)data.data(), (unsigned char*)data.mdata(), data.length(), &e_key, (unsigned char*)IV.mdata(), AES_ENCRYPT);
+  AES_cbc_encrypt((const unsigned char*)data.cbegin(), (unsigned char*)data.begin(), data.length(), &e_key, (unsigned char*)IV.begin(), AES_ENCRYPT);
   OPENSSL_cleanse(&e_key, sizeof(e_key));
 
   return data;
@@ -79,7 +79,7 @@ bd::String decrypt_string_cbc(const bd::String& key, bd::String data, bd::String
 
   data.resize(data.length() - (data.length() % CRYPT_BLOCKSIZE));
   AES_set_decrypt_key((const unsigned char *) key.c_str(), CRYPT_KEYBITS, &d_key);
-  AES_cbc_encrypt((const unsigned char*)data.data(), (unsigned char*)data.mdata(), data.length(), &d_key, (unsigned char*)IV.mdata(), AES_DECRYPT);
+  AES_cbc_encrypt((const unsigned char*)data.cbegin(), (unsigned char*)data.begin(), data.length(), &d_key, (unsigned char*)IV.begin(), AES_DECRYPT);
   OPENSSL_cleanse(&d_key, sizeof(d_key));
 
   // How much padding?

+ 4 - 4
src/crypto/bf_util.cc

@@ -57,10 +57,10 @@ bd::String egg_bf_encrypt(bd::String in, const bd::String& key)
     datalen += 8 - (datalen % 8);
     in.resize(datalen, 0);
   }
-  BF_set_key(&bf_e_key, key.length(), (unsigned char *)key.data());
+  BF_set_key(&bf_e_key, key.length(), (unsigned char *)key.cbegin());
   bf_data data;
   size_t part;
-  unsigned char *s = (unsigned char *)in.data();
+  unsigned char *s = (unsigned char *)in.cbegin();
   for (size_t i = 0; i < in.length(); i += 8) {
     data.lr.left = *s++ << 24;
     data.lr.left += *s++ << 16;
@@ -105,11 +105,11 @@ bd::String egg_bf_decrypt(bd::String in, const bd::String& key)
   if (cut_off > 0)
     in.resize(in.length() - cut_off);
 
-  BF_set_key(&bf_d_key, key.length(), (unsigned char *)key.data());
+  BF_set_key(&bf_d_key, key.length(), (unsigned char *)key.cbegin());
   bf_data data;
   int val;
   size_t part;
-  char *s = (char *)in.data();
+  char *s = (char *)in.cbegin();
   for (size_t i = 0; i < in.length(); i += 12) {
     data.lr.left = 0;
     data.lr.right = 0;

+ 6 - 6
src/crypto/dh_util.cc

@@ -106,13 +106,13 @@ void DH1080_gen(bd::String& privateKey, bd::String& publicKeyB64) {
   pub_key = dh->pub_key;
 #endif
   privateKey.resize(BN_num_bytes(priv_key), 0);
-  BN_bn2bin(priv_key, reinterpret_cast<unsigned char*>(privateKey.mdata()));
+  BN_bn2bin(priv_key, reinterpret_cast<unsigned char*>(privateKey.begin()));
 
   // Get public key
   bd::String publicKey;
-  // Resize as the mdata() modification won't update the internal length, but resize() will
+  // Resize as the begin() modification won't update the internal length, but resize() will
   publicKey.resize(static_cast<size_t>(BN_num_bytes(pub_key)));
-  BN_bn2bin(pub_key, reinterpret_cast<unsigned char*>(publicKey.mdata()));;
+  BN_bn2bin(pub_key, reinterpret_cast<unsigned char*>(publicKey.begin()));;
 
   // base64 encode
   publicKeyB64 = fishBase64Encode(publicKey);
@@ -136,7 +136,7 @@ bool DH1080_comp(const bd::String privateKey, const bd::String theirPublicKeyB64
 #endif
 
   // Setup my private key
-  b_myPrivkey = BN_bin2bn(reinterpret_cast<const unsigned char*>(privateKey.data()), privateKey.length(), NULL);
+  b_myPrivkey = BN_bin2bn(reinterpret_cast<const unsigned char*>(privateKey.cbegin()), privateKey.length(), NULL);
 #if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000L
   DH_set0_key(dh, NULL, b_myPrivkey);
 #else
@@ -145,7 +145,7 @@ bool DH1080_comp(const bd::String privateKey, const bd::String theirPublicKeyB64
 
   // Prep their public key
   bd::String theirPublicKey(fishBase64Decode(theirPublicKeyB64));
-  b_HisPubkey = BN_bin2bn(reinterpret_cast<const unsigned char*>(theirPublicKey.data()), theirPublicKey.length(), NULL);
+  b_HisPubkey = BN_bin2bn(reinterpret_cast<const unsigned char*>(theirPublicKey.cbegin()), theirPublicKey.length(), NULL);
 
   // Compute the Shared key
   char *key = (char *)calloc(1, DH_size(dh));
@@ -168,7 +168,7 @@ bool DH1080_comp(const bd::String privateKey, const bd::String theirPublicKeyB64
 
   SHA256_Init(&c);
   SHA256_Update(&c, key, len);
-  SHA256_Final(reinterpret_cast<unsigned char*>(SHA256Digest.mdata()), &c);
+  SHA256_Final(reinterpret_cast<unsigned char*>(SHA256Digest.begin()), &c);
   sharedKey = fishBase64Encode(SHA256Digest);
 
   free(key);

+ 14 - 10
src/dcc.cc

@@ -1403,8 +1403,10 @@ detect_telnet_flood(char *floodhost)
   return 0;
 }
 
-static void dcc_telnet_dns_callback(int, void *, const char *, bd::Array<bd::String>);
-static void dcc_telnet_dns_forward_callback(int, void *, const char *, bd::Array<bd::String>);
+static void dcc_telnet_dns_callback(int, void *, const char *,
+    const bd::Array<bd::String>&);
+static void dcc_telnet_dns_forward_callback(int, void *, const char *,
+    const bd::Array<bd::String>&);
 
 static void
 dcc_telnet(int idx, char *buf, int ii)
@@ -1499,7 +1501,8 @@ dcc_telnet(int idx, char *buf, int ii)
     dcc[i].dns_id = dns_id;
 }
 
-static void dcc_telnet_dns_callback(int id, void *client_data, const char *ip, bd::Array<bd::String> hosts)
+static void dcc_telnet_dns_callback(int id, void *client_data, const char *ip,
+    const bd::Array<bd::String>& hosts)
 {
   // 64bit hacks
   long data = (long) client_data;
@@ -1525,23 +1528,24 @@ static void dcc_telnet_dns_callback(int id, void *client_data, const char *ip, b
   //Clear the ip (still saved in dcc[i].addr)
   dcc[i].host[0] = 0;
   if (hosts.size()) {
-    strlcpy(dcc[i].host, bd::String(hosts[0]).c_str(), sizeof(dcc[i].host));
+    strlcpy(dcc[i].host, hosts[0].c_str(), sizeof(dcc[i].host));
 
     //Check forward; only check the protocol of which this connection is.
     //If they connected on V4, lookup A, if V6, lookup AAAA
     int dns_type = DNS_LOOKUP_A;
     if (is_dotted_ip(iptostr(htonl(dcc[i].addr))) == AF_INET6)//Is this even valid?
       dns_type = DNS_LOOKUP_AAAA;
-    int dns_id = egg_dns_lookup(bd::String(hosts[0]).c_str(), 20, dcc_telnet_dns_forward_callback, (void *) (long) i, dns_type);
+    int dns_id = egg_dns_lookup(hosts[0].c_str(), 20, dcc_telnet_dns_forward_callback, (void *) (long) i, dns_type);
     if (dns_id >= 0)
       dcc[i].dns_id = dns_id;
   } else {
-    bd::Array<bd::String> empty;
+    const bd::Array<bd::String> empty;
     dcc_telnet_dns_forward_callback(id, client_data, ip, empty);
   }
 }
 
-static void dcc_telnet_dns_forward_callback(int id, void *client_data, const char *host, bd::Array<bd::String> ips) {
+static void dcc_telnet_dns_forward_callback(int id, void *client_data,
+    const char *host, const bd::Array<bd::String>& ips) {
   // 64bit hacks
   long data = (long) client_data;
   int i = (int) data;
@@ -1565,10 +1569,10 @@ static void dcc_telnet_dns_forward_callback(int id, void *client_data, const cha
   }
 
   bool forward_matched = false;
-  bd::String look_for_ip(iptostr(htonl(dcc[i].addr)));
+  const auto& look_for_ip(iptostr(htonl(dcc[i].addr)));
   // Look for any match
-  for (size_t n = 0; n < ips.size(); ++n) {
-    if (ips[n] == look_for_ip) {
+  for (const auto& ip : ips) {
+    if (ip == look_for_ip) {
       forward_matched = true;
       break;
     }

+ 6 - 7
src/libcrypto.cc

@@ -101,13 +101,13 @@ int load_libcrypto() {
 
   sdprintf("Loading libcrypto");
 
-  bd::Array<bd::String> libs_list(bd::String("libcrypto.so." SHLIB_VERSION_NUMBER " libcrypto.so libcrypto.so.1.1 libcrypto.so.1.0.0 libcrypto.so.0.9.8 libcrypto.so.10 libcrypto.so.9 libcrypto.so.8 libcrypto.so.7 libcrypto.so.6").split(' '));
+  const auto& libs_list(bd::String("libcrypto.so." SHLIB_VERSION_NUMBER " libcrypto.so libcrypto.so.1.1 libcrypto.so.1.0.0 libcrypto.so.0.9.8 libcrypto.so.10 libcrypto.so.9 libcrypto.so.8 libcrypto.so.7 libcrypto.so.6").split(' '));
 
-  for (size_t i = 0; i < libs_list.length(); ++i) {
+  for (const auto& lib : libs_list) {
     dlerror(); // Clear Errors
-    libcrypto_handle = dlopen(bd::String(libs_list[i]).c_str(), RTLD_LAZY|RTLD_GLOBAL);
+    libcrypto_handle = dlopen(lib.c_str(), RTLD_LAZY|RTLD_GLOBAL);
     if (libcrypto_handle) {
-      sdprintf("Found libcrypto: %s", bd::String(libs_list[i]).c_str());
+      sdprintf("Found libcrypto: %s", lib.c_str());
       break;
     }
   }
@@ -127,9 +127,8 @@ int load_libcrypto() {
 int unload_libcrypto() {
   if (libcrypto_handle) {
     // Cleanup symbol table
-    for (size_t i = 0; i < my_symbols.length(); ++i) {
-      dl_symbol_table.remove(my_symbols[i]);
-      static_cast<bd::String>(my_symbols[i]).clear();
+    for (const auto& symbol : my_symbols) {
+      dl_symbol_table.remove(symbol);
     }
     my_symbols.clear();
 

+ 6 - 7
src/libssl.cc

@@ -82,13 +82,13 @@ int load_libssl() {
 
   sdprintf("Loading libssl");
 
-  bd::Array<bd::String> libs_list(bd::String("libssl.so." SHLIB_VERSION_NUMBER " libssl.so libssl.so.1.1 libssl.so.1.0.0 libssl.so.0.9.8 libssl.so.10 libssl.so.9 libssl.so.8 libssl.so.7 libssl.so.6").split(' '));
+  const auto& libs_list(bd::String("libssl.so." SHLIB_VERSION_NUMBER " libssl.so libssl.so.1.1 libssl.so.1.0.0 libssl.so.0.9.8 libssl.so.10 libssl.so.9 libssl.so.8 libssl.so.7 libssl.so.6").split(' '));
 
-  for (size_t i = 0; i < libs_list.length(); ++i) {
+  for (const auto& lib : libs_list) {
     dlerror(); // Clear Errors
-    libssl_handle = dlopen(bd::String(libs_list[i]).c_str(), RTLD_LAZY);
+    libssl_handle = dlopen(lib.c_str(), RTLD_LAZY);
     if (libssl_handle) {
-      sdprintf("Found libssl: %s", bd::String(libs_list[i]).c_str());
+      sdprintf("Found libssl: %s", lib.c_str());
       break;
     }
   }
@@ -108,9 +108,8 @@ int load_libssl() {
 int unload_libssl() {
   if (libssl_handle) {
     // Cleanup symbol table
-    for (size_t i = 0; i < my_symbols.length(); ++i) {
-      dl_symbol_table.remove(my_symbols[i]);
-      static_cast<bd::String>(my_symbols[i]).clear();
+    for (const auto& symbol : my_symbols) {
+      dl_symbol_table.remove(symbol);
     }
     my_symbols.clear();
 

+ 5 - 6
src/libtcl.cc

@@ -67,11 +67,11 @@ int load_libtcl() {
   }
 #endif
 
-  bd::Array<bd::String> libs_list(bd::String("libtcl.so libtcl83.so libtcl8.3.so libtcl84.so libtcl8.4.so libtcl85.so libtcl8.5.so libtcl86.so libtcl8.6.so").split(' '));
+  const auto& libs_list(bd::String("libtcl.so libtcl83.so libtcl8.3.so libtcl84.so libtcl8.4.so libtcl85.so libtcl8.5.so libtcl86.so libtcl8.6.so").split(' '));
 
-  for (size_t i = 0; i < libs_list.length(); ++i) {
+  for (const auto& lib : libs_list) {
     dlerror(); // Clear Errors
-    libtcl_handle = dlopen(bd::String(libs_list[i]).c_str(), RTLD_LAZY);
+    libtcl_handle = dlopen(lib.c_str(), RTLD_LAZY);
     if (libtcl_handle) break;
   }
   if (!libtcl_handle) {
@@ -127,9 +127,8 @@ int unload_libtcl() {
 #endif
 
     // Cleanup symbol table
-    for (size_t i = 0; i < my_symbols.length(); ++i) {
-      dl_symbol_table.remove(my_symbols[i]);
-      static_cast<bd::String>(my_symbols[i]).clear();
+    for (const auto& symbol : my_symbols) {
+      dl_symbol_table.remove(symbol);
     }
     my_symbols.clear();
 

+ 7 - 5
src/mod/irc.mod/chan.cc

@@ -44,7 +44,8 @@ typedef struct resolvstruct {
   bd::String* server;
 } resolv_member;
 
-static void resolv_member_callback(int id, void *client_data, const char *host, bd::Array<bd::String> ips)
+static void resolv_member_callback(int id, void *client_data, const char *host,
+    const bd::Array<bd::String>& ips)
 {
   resolv_member *r = (resolv_member *) client_data;
   struct chanset_t* chan = NULL;
@@ -68,7 +69,7 @@ static void resolv_member_callback(int id, void *client_data, const char *host,
       pe = strchr(m->userhost, '@');
       if (pe && !strcmp(pe + 1, r->host)) {
         strlcpy(user, m->userhost, pe - m->userhost + 1);
-        simple_snprintf(m->userip, sizeof(m->userip), "%s@%s", user, bd::String(ips[0]).c_str());
+        simple_snprintf(m->userip, sizeof(m->userip), "%s@%s", user, ips[0].c_str());
         simple_snprintf(m->fromip, sizeof(m->fromip), "%s!%s", m->nick, m->userip);
         if (!m->user) {
           m->user = get_user_by_host(m->fromip);
@@ -84,7 +85,7 @@ static void resolv_member_callback(int id, void *client_data, const char *host,
   }
 
   if (!matched_user && channel_rbl(chan))
-    resolve_to_rbl(chan, bd::String(ips[0]).c_str());
+    resolve_to_rbl(chan, ips[0].c_str());
 
   free(r->host);
   free(r->chan);
@@ -110,7 +111,8 @@ void resolve_to_member(struct chanset_t *chan, char *nick, char *host)
 }
 
 /* RBL */
-static void resolve_rbl_callback(int id, void *client_data, const char *host, bd::Array<bd::String> ips)
+static void resolve_rbl_callback(int id, void *client_data, const char *host,
+    const bd::Array<bd::String>& ips)
 {
   resolv_member *r = (resolv_member *) client_data;
   struct chanset_t* chan = NULL;
@@ -123,7 +125,7 @@ static void resolve_rbl_callback(int id, void *client_data, const char *host, bd
     return;
   }
 
-  sdprintf("RBL match for %s:%s: %s", chan->dname, r->host, bd::String(ips[0]).c_str());
+  sdprintf("RBL match for %s:%s: %s", chan->dname, r->host, ips[0].c_str());
 
   char s1[UHOSTLEN] = "";
   simple_snprintf(s1, sizeof(s1), "*!*@%s", r->host);

+ 2 - 2
src/mod/server.mod/server.cc

@@ -178,8 +178,8 @@ burst_mode_ok(const char *msg, size_t len) {
   const auto list(mode.split(' '));
   if (list.length() == 2) return 1;
   if (list.length() == 3) {
-    if (!strchr(CHANMETA, bd::String(list[1]).at(0))) return 1;
-    else if (bd::String(list[2]).at(0) == 'b') return 1;
+    if (!strchr(CHANMETA, list[1][0])) return 1;
+    else if (list[2][0] == 'b') return 1;
   }
   return 0;
 }

+ 4 - 2
src/mod/server.mod/servmsg.cc

@@ -2043,7 +2043,8 @@ static cmd_t my_raw_binds[] =
   {NULL,	NULL,	NULL,				NULL, 0}
 };
 
-static void server_dns_callback(int, void *, const char *, bd::Array<bd::String>);
+static void server_dns_callback(int, void *, const char *,
+    const bd::Array<bd::String>&);
 
 /* Hook up to a server
  */
@@ -2122,7 +2123,8 @@ static void connect_server(void)
   }
 }
 
-static void server_dns_callback(int id, void *client_data, const char *host, bd::Array<bd::String> ips)
+static void server_dns_callback(int id, void *client_data, const char *host,
+    const bd::Array<bd::String>& ips)
 {
   //64bit hacks
   long data = (long) client_data;

+ 3 - 3
src/net.cc

@@ -119,12 +119,12 @@ static int get_ip(char *hostname, union sockaddr_union *so, int dns_type)
   memset(so, 0, sizeof(union sockaddr_union));
   debug1("get_ip(%s)", hostname);
 
-  bd::Array<bd::String> hosts = dns_lookup_block(hostname, 10, dns_type);
+  const auto& hosts = dns_lookup_block(hostname, 10, dns_type);
   if (hosts.length() == 0)
     return -1;
 
   my_addr_t addr;
-  get_addr(bd::String(hosts[0]).c_str(), &addr);
+  get_addr(hosts[0].c_str(), &addr);
 
   if (addr.family == AF_INET) {
     so->sin.sin_family = AF_INET;
@@ -1244,7 +1244,7 @@ int sockgets(char *s, int *len)
   }
   /* Might be necessary to prepend stored-up data! */
   if (socklist[ret].inbuf != NULL) {
-    *(socklist[ret].inbuf) += bd::String(xx);
+    *(socklist[ret].inbuf) += xx;
     if (socklist[ret].inbuf->length() < (SGRAB + 2)) {
       strlcpy(xx, socklist[ret].inbuf->c_str(), sizeof(xx));
       delete socklist[ret].inbuf;

+ 1 - 1
src/response.cc

@@ -25,6 +25,6 @@ init_responses()
 const char *
 response(response_t type)
 {
-  return res_map[type].at(randint(res_map[type].size()));
+  return res_map[type][randint(res_map[type].size())];
 }
 /* vim: set sts=2 sw=2 ts=8 et: */