diff options
author | Maximilian Krambach <[email protected]> | 2018-05-28 14:52:50 +0000 |
---|---|---|
committer | Maximilian Krambach <[email protected]> | 2018-05-28 14:52:50 +0000 |
commit | d4adbf453d39659eee378b2be1d7125315d76083 (patch) | |
tree | f560b50bacf8b64a019326c2cf4c72b43457adc8 /lang/js/src/Connection.js | |
parent | js: implement Key handling (1) (diff) | |
download | gpgme-d4adbf453d39659eee378b2be1d7125315d76083.tar.gz gpgme-d4adbf453d39659eee378b2be1d7125315d76083.zip |
js: Treat a connection as a gpgme Context
--
* After an operation a connection should be disconnected again.
The "end of operation" is now assumed to be either an error as
answer, or a message not including a "more"
* GPGME, GPGME_Key, GPGME_Keyring don't require a connection
anymore
* Message.js: The Message.post() method will open a connection as
required
Diffstat (limited to 'lang/js/src/Connection.js')
-rw-r--r-- | lang/js/src/Connection.js | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lang/js/src/Connection.js b/lang/js/src/Connection.js index 3b442622..3480d811 100644 --- a/lang/js/src/Connection.js +++ b/lang/js/src/Connection.js @@ -102,9 +102,11 @@ export class Connection{ } if (!message || !message instanceof GPGME_Message){ + this.disconnect(); return Promise.reject(gpgme_error('PARAM_WRONG'), message); } if (message.isComplete !== true){ + this.disconnect(); return Promise.reject(gpgme_error('MSG_INCOMPLETE')); } let me = this; @@ -113,25 +115,27 @@ export class Connection{ let listener = function(msg) { if (!msg){ me._connection.onMessage.removeListener(listener) + me._connection.disconnect(); reject(gpgme_error('CONN_EMPTY_GPG_ANSWER')); } else if (msg.type === "error"){ me._connection.onMessage.removeListener(listener); + me._connection.disconnect(); reject(gpgme_error('GNUPG_ERROR', msg.msg)); } else { let answer_result = answer.add(msg); if (answer_result !== true){ me._connection.onMessage.removeListener(listener); + me._connection.disconnect(); reject(answer_result); - } - if (msg.more === true){ + } else if (msg.more === true){ me._connection.postMessage({'op': 'getmore'}); } else { me._connection.onMessage.removeListener(listener) + me._connection.disconnect(); resolve(answer.message); } } }; - me._connection.onMessage.addListener(listener); if (permittedOperations[message.operation].pinentry){ return me._connection.postMessage(message.message); @@ -140,12 +144,14 @@ export class Connection{ me._connection.postMessage(message.message), function(resolve, reject){ setTimeout(function(){ + me._connection.disconnect(); reject(gpgme_error('CONN_TIMEOUT')); }, 5000); }]).then(function(result){ - return result; + return result; }, function(reject){ if(!reject instanceof Error) { + me._connection.disconnect(); return gpgme_error('GNUPG_ERROR', reject); } else { return reject; |