]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_ssl_gnutls.cpp
WebSocket: use one WebSocket message per IRC message.
[user/henk/code/inspircd.git] / src / modules / extra / m_ssl_gnutls.cpp
index 2d278c967b8b03d3cf605567a424c5c112706125..f5711cbd740faf28e7fb55ca2e36662e0f11c2d0 100644 (file)
 #if defined __clang__
 # pragma clang diagnostic ignored "-Wc++11-extensions"
 #elif defined __GNUC__
-# if __GNUC__ < 6
-#  pragma GCC diagnostic ignored "-pedantic"
+# if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8))
+#  pragma GCC diagnostic ignored "-Wpedantic"
 # else
-#  pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+#  pragma GCC diagnostic ignored "-pedantic"
 # endif
 #endif
 
+// Fix warnings about using std::auto_ptr on C++11 or newer.
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
 #include <gnutls/gnutls.h>
 #include <gnutls/x509.h>
 
 #define GNUTLS_NEW_PRIO_API
 #endif
 
-#if (!INSPIRCD_GNUTLS_HAS_VERSION(2, 0, 0))
-typedef gnutls_certificate_credentials_t gnutls_certificate_credentials;
-typedef gnutls_dh_params_t gnutls_dh_params;
-#endif
-
 enum issl_status { ISSL_NONE, ISSL_HANDSHAKING, ISSL_HANDSHAKEN };
 
 #if INSPIRCD_GNUTLS_HAS_VERSION(2, 12, 0)
@@ -112,10 +110,10 @@ typedef gnutls_connection_end_t inspircd_gnutls_session_init_flags_t;
 
 static Module* thismod;
 
-class RandGen : public HandlerBase2<void, char*, size_t>
+class RandGen
 {
  public:
-       void Call(char* buffer, size_t len) CXX11_OVERRIDE
+       static void Call(char* buffer, size_t len)
        {
 #ifdef GNUTLS_HAS_RND
                gnutls_rnd(GNUTLS_RND_RANDOM, buffer, len);
@@ -189,12 +187,12 @@ namespace GnuTLS
                                throw Exception("Unknown hash type " + hashname);
                        gnutls_hash_deinit(is_digest, NULL);
 #else
-                       if (hashname == "md5")
+                       if (stdalgo::string::equalsci(hashname, "md5"))
                                hash = GNUTLS_DIG_MD5;
-                       else if (hashname == "sha1")
+                       else if (stdalgo::string::equalsci(hashname, "sha1"))
                                hash = GNUTLS_DIG_SHA1;
 #ifdef INSPIRCD_GNUTLS_ENABLE_SHA256_FINGERPRINT
-                       else if (hashname == "sha256")
+                       else if (stdalgo::string::equalsci(hashname, "sha256"))
                                hash = GNUTLS_DIG_SHA256;
 #endif
                        else
@@ -655,7 +653,7 @@ namespace GnuTLS
                                , keystr(ReadFile(tag->getString("keyfile", "key.pem")))
                                , dh(DHParams::Import(ReadFile(tag->getString("dhfile", "dhparams.pem"))))
                                , priostr(GetPrioStr(profilename, tag))
-                               , mindh(tag->getInt("mindhbits", 1024))
+                               , mindh(tag->getUInt("mindhbits", 1024))
                                , hashstr(tag->getString("hash", "md5"))
                                , requestclientcert(tag->getBool("requestclientcert", true))
                        {
@@ -672,9 +670,9 @@ namespace GnuTLS
 
 #ifdef INSPIRCD_GNUTLS_HAS_CORK
                                // If cork support is available outrecsize represents the (rough) max amount of data we give GnuTLS while corked
-                               outrecsize = tag->getInt("outrecsize", 2048, 512);
+                               outrecsize = tag->getUInt("outrecsize", 2048, 512);
 #else
-                               outrecsize = tag->getInt("outrecsize", 2048, 512, 16384);
+                               outrecsize = tag->getUInt("outrecsize", 2048, 512, 16384);
 #endif
                        }
                };
@@ -1272,7 +1270,6 @@ class ModuleSSLGnuTLS : public Module
 
        // First member of the class, gets constructed first and destructed last
        GnuTLS::Init libinit;
-       RandGen randhandler;
        ProfileList profiles;
 
        void ReadProfiles()
@@ -1304,7 +1301,7 @@ class ModuleSSLGnuTLS : public Module
                for (ConfigIter i = tags.first; i != tags.second; ++i)
                {
                        ConfigTag* tag = i->second;
-                       if (tag->getString("provider") != "gnutls")
+                       if (!stdalgo::string::equalsci(tag->getString("provider"), "gnutls"))
                                continue;
 
                        std::string name = tag->getString("name");
@@ -1352,7 +1349,7 @@ class ModuleSSLGnuTLS : public Module
        {
                ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "GnuTLS lib version %s module was compiled for " GNUTLS_VERSION, gnutls_check_version(NULL));
                ReadProfiles();
-               ServerInstance->GenRandom = &randhandler;
+               ServerInstance->GenRandom = RandGen::Call;
        }
 
        void OnModuleRehash(User* user, const std::string &param) CXX11_OVERRIDE
@@ -1372,7 +1369,7 @@ class ModuleSSLGnuTLS : public Module
 
        ~ModuleSSLGnuTLS()
        {
-               ServerInstance->GenRandom = &ServerInstance->HandleGenRandom;
+               ServerInstance->GenRandom = &InspIRCd::DefaultGenRandom;
        }
 
        void OnCleanup(ExtensionItem::ExtensibleType type, Extensible* item) CXX11_OVERRIDE