~singpolyma/biboumi

b1564e4ddc3e54ad78788a6f5643056d03a41678 — louiz’ 5 years ago 0b51e38
Fix a bunch of int to unsigned int conversion warnings
M src/main.cpp => src/main.cpp +1 -1
@@ 77,7 77,7 @@ static void setup_signals()
  sigfillset(&on_sigint.sa_mask);
  // we want to catch that signal only once.
  // Sending SIGINT again will "force" an exit
  on_sigint.sa_flags = SA_RESETHAND;
  on_sigint.sa_flags = 0 & SA_RESETHAND;
  sigaction(SIGINT, &on_sigint, nullptr);
  sigaction(SIGTERM, &on_sigint, nullptr);


M src/network/credentials_manager.cpp => src/network/credentials_manager.cpp +1 -2
@@ 21,9 21,8 @@ static const std::vector<std::string> default_cert_files = {
Botan::Certificate_Store_In_Memory BasicCredentialsManager::certificate_store;
bool BasicCredentialsManager::certs_loaded = false;

BasicCredentialsManager::BasicCredentialsManager(const TCPSocketHandler* const socket_handler):
BasicCredentialsManager::BasicCredentialsManager():
    Botan::Credentials_Manager(),
    socket_handler(socket_handler),
    trusted_fingerprint{}
{
  BasicCredentialsManager::load_certs();

M src/network/credentials_manager.hpp => src/network/credentials_manager.hpp +1 -2
@@ 25,7 25,7 @@ void check_tls_certificate(const std::vector<Botan::X509_Certificate>& certs,
class BasicCredentialsManager: public Botan::Credentials_Manager
{
public:
  BasicCredentialsManager(const TCPSocketHandler* const socket_handler);
  BasicCredentialsManager();

  BasicCredentialsManager(BasicCredentialsManager&&) = delete;
  BasicCredentialsManager(const BasicCredentialsManager&) = delete;


@@ 38,7 38,6 @@ public:
  const std::string& get_trusted_fingerprint() const;

private:
  const TCPSocketHandler* const socket_handler;

  static bool try_to_open_one_ca_bundle(const std::vector<std::string>& paths);
  static void load_certs();

M src/network/tcp_socket_handler.cpp => src/network/tcp_socket_handler.cpp +9 -7
@@ 50,7 50,7 @@ TCPSocketHandler::TCPSocketHandler(std::shared_ptr<Poller>& poller):
  SocketHandler(poller, -1),
  use_tls(false)
#ifdef BOTAN_FOUND
  ,credential_manager(this)
  ,credential_manager()
#endif
{}



@@ 84,10 84,11 @@ void TCPSocketHandler::plain_recv()
  if (recv_buf == nullptr)
    recv_buf = buf;

  const ssize_t size = this->do_recv(recv_buf, buf_size);
  const ssize_t ssize = this->do_recv(recv_buf, buf_size);

  if (size > 0)
  if (ssize > 0)
    {
      auto size = static_cast<std::size_t>(ssize);
      if (buf == recv_buf)
        {
          // data needs to be placed in the in_buf string, because no buffer


@@ 149,21 150,22 @@ void TCPSocketHandler::on_send()
    }
  else
    {
      auto size = static_cast<std::size_t>(res);
      // remove all the strings that were successfully sent.
      auto it = this->out_buf.begin();
      while (it != this->out_buf.end())
        {
          if (static_cast<size_t>(res) >= it->size())
          if (size >= it->size())
            {
              res -= it->size();
              size -= it->size();
              ++it;
            }
          else
            {
              // If one string has partially been sent, we use substr to
              // crop it
              if (res > 0)
                *it = it->substr(res, std::string::npos);
              if (size > 0)
                *it = it->substr(size, std::string::npos);
              break;
            }
        }

M src/utils/encoding.cpp => src/utils/encoding.cpp +13 -13
@@ 48,16 48,16 @@ namespace utils
        if (codepoint_size == 4)
          {
            if (!str[1] || !str[2] || !str[3]
                || ((str[1] & 0b11000000) != 0b10000000)
                || ((str[2] & 0b11000000) != 0b10000000)
                || ((str[3] & 0b11000000) != 0b10000000))
                || ((str[1] & 0b11000000u) != 0b10000000u)
                || ((str[2] & 0b11000000u) != 0b10000000u)
                || ((str[3] & 0b11000000u) != 0b10000000u))
              return false;
          }
        else if (codepoint_size == 3)
          {
            if (!str[1] || !str[2]
                || ((str[1] & 0b11000000) != 0b10000000)
                || ((str[2] & 0b11000000) != 0b10000000))
                || ((str[1] & 0b11000000u) != 0b10000000u)
                || ((str[2] & 0b11000000u) != 0b10000000u))
              return false;
          }
        else if (codepoint_size == 2)


@@ 81,7 81,7 @@ namespace utils
    // pointer where we write valid chars
    char* r = res.data();

    const char* str = original.c_str();
    const unsigned char* str = reinterpret_cast<const unsigned char*>(original.c_str());
    std::bitset<20> codepoint;

    while (*str)


@@ 89,10 89,10 @@ namespace utils
        // 4 bytes:  11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
        if ((str[0] & 0b11111000) == 0b11110000)
          {
            codepoint  = ((str[0] & 0b00000111) << 18);
            codepoint |= ((str[1] & 0b00111111) << 12);
            codepoint |= ((str[2] & 0b00111111) << 6 );
            codepoint |= ((str[3] & 0b00111111) << 0 );
            codepoint  = ((str[0] & 0b00000111u) << 18u);
            codepoint |= ((str[1] & 0b00111111u) << 12u);
            codepoint |= ((str[2] & 0b00111111u) << 6u );
            codepoint |= ((str[3] & 0b00111111u) << 0u );
            if (codepoint.to_ulong() <= 0x10FFFF)
              {
                ::memcpy(r, str, 4);


@@ 103,9 103,9 @@ namespace utils
        // 3 bytes:  1110xxx 10xxxxxx 10xxxxxx
        else if ((str[0] & 0b11110000) == 0b11100000)
          {
            codepoint  = ((str[0] & 0b00001111) << 12);
            codepoint |= ((str[1] & 0b00111111) << 6);
            codepoint |= ((str[2] & 0b00111111) << 0 );
            codepoint  = ((str[0] & 0b00001111u) << 12u);
            codepoint |= ((str[1] & 0b00111111u) << 6u);
            codepoint |= ((str[2] & 0b00111111u) << 0u );
            if (codepoint.to_ulong() <= 0xD7FF ||
                (codepoint.to_ulong() >= 0xE000 && codepoint.to_ulong() <= 0xFFFD))
              {

M src/xmpp/biboumi_component.cpp => src/xmpp/biboumi_component.cpp +1 -1
@@ 762,7 762,7 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza)
        if (limit < 0 || limit > 100)
          limit = 100;
        auto result = Database::get_muc_logs(from.bare(), iid.get_local(), iid.get_server(),
                                            limit,
                                            static_cast<std::size_t>(limit),
                                            start, end,
                                            reference_record_id, paging_order);
        bool complete = std::get<bool>(result);

M src/xmpp/jid.cpp => src/xmpp/jid.cpp +1 -1
@@ 106,7 106,7 @@ std::string jidprep(const std::string& original)
          --domain_end;
        if (domain_end != domain && special_chars.count(domain[0]))
          {
            std::memmove(domain, domain + 1, domain_end - domain + 1);
            std::memmove(domain, domain + 1, static_cast<std::size_t>(domain_end - domain) + 1);
            --domain_end;
          }
        // And if the final result is an empty string, return a dummy hostname

M src/xmpp/xmpp_parser.cpp => src/xmpp/xmpp_parser.cpp +1 -1
@@ 20,7 20,7 @@ static void end_element_handler(void* user_data, const XML_Char* name)

static void character_data_handler(void *user_data, const XML_Char *s, int len)
{
  static_cast<XmppParser*>(user_data)->char_data(s, len);
  static_cast<XmppParser*>(user_data)->char_data(s, static_cast<std::size_t>(len));
}

/**