.pragma library .import harbour.weechatrelay.connectionhandler 1.0 as CH .import harbour.weechatrelay.qsslcertificateinfo 1.0 as QSCI .import "storage.js" as S .import "debug.js" as D /* * © Mikko Ahlroth 2014 * WeeCRApp is open source software. For licensing information, please check * the LICENCE file. */ /* * This file contains the main UI logic in the handling of a relay connection. * It will create the necessary views and pass messages to them. */ // State variables var connected = false; var connection = null; // A Connection object var handler = null; // The underlying ConnectionHandler var ps = null; // The PageStack // Views var debugViewPage = null; var sslVerifyDialog = null; // Set initial variables before using any other functions function init(connectionHandler, pageStack) { handler = connectionHandler; ps = pageStack; } // Signal handlers for incoming data from connection function onDisplayDebugData(str) { debugViewPage.display(str); } function onConnected() { connected = true; debugViewPage.connected(); debug("Connected"); } function onDisconnected() { connected = false; debugViewPage.disconnected(); debug("Disconnected"); } function onSslError(errorStrings, issuerInfo, startDate, expiryDate, digest) { debug("SSL verification error when connecting"); sslVerifyDialog = ps.push("../pages/SslVerifyDialog.qml", { "errorList": errorStrings, "issuer": issuerInfo, "startDate": startDate, "expiryDate": expiryDate, "digest": digest }); } // Public API function connect(connObj) { debugViewPage = ps.replace("../pages/DebugView.qml"); debug("Connecting..."); var connType = (connObj.type === "ssl") ? CH.ConnectionHandler.SSL : CH.ConnectionHandler.NONE; // Use any stored certificates if ('cert' in connObj.options && 'digest' in connObj.options.cert && connObj.options.cert.digest.length > 0) { var qmlSpec = "import harbour.weechatrelay.qsslcertificateinfo 1.0; QSslCertificateInfo {}"; var info = Qt.createQmlObject(qmlSpec, handler, ''); info.effectiveDate = connObj.options.cert.effectiveDate; info.expiryDate = connObj.options.cert.expiryDate; info.digest = connObj.options.cert.digest; handler.acceptCertificate(info); } handler.connect(CH.ConnectionHandler.WEECHAT, connType, connObj.host, connObj.port, connObj.password); connection = new S.Connection(connObj); } function disconnect() { connected = false; handler.disconnect(); } function reconnect() { debug("Reconnecting..."); handler.reconnect(); } // Reconnect, accepting the previously failed certificate function reconnectWithFailed() { debug("Reconnecting..."); handler.reconnectWithFailed(); } // Store the failed certificate information so that it will be accepted automatically // on the next connection function storeFailedCertificate() { var cert = handler.getFailedCertificate(); var storedInfo = { effectiveDate: cert.effectiveDate, expiryDate: cert.expiryDate, digest: cert.digest }; connection.options['cert'] = storedInfo; S.storeConnection(S.connect(), connection); } function clearConnection() { connection = null; connected = false; handler.clearData(); } // Write a line to the debug view (will go to console if debug view isn't open) function debug(str) { if (debugViewPage !== null) { debugViewPage.display(str); } else { console.log(str); } } // Private API