Skip to content

Commit c35d928

Browse files
committed
libunbound resolver: changing preferences no longer needs a restart
1 parent ff740d5 commit c35d928

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

Diff for: CHANGELOG.txt

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Authentication-Results header: continue verification if there is no DKIM result in the ARH header
66
- Authentication-Results header: fixed bug if ARH header exists, but no message authentication was done
77
- libunbound resolver: no longer blocks the UI of Thunderbird
8+
- libunbound resolver: changing preferences no longer needs a restart
89

910
1.3.6 [2015-09-13]
1011
------------------

Diff for: modules/libunbound.jsm

+47-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Wrapper for the libunbound DNS library. The actual work is done in the
55
* ChromeWorker libunboundWorker.jsm.
66
*
7-
* Version: 2.0.0pre1 (22 January 2016)
7+
* Version: 2.0.0pre2 (22 January 2016)
88
*
99
* Copyright (c) 2013-2016 Philippe Lieser
1010
*
@@ -188,6 +188,21 @@ let libunbound = {
188188
function init() {
189189
"use strict";
190190

191+
load();
192+
update_ctx();
193+
194+
// Register to receive notifications of preference changes
195+
prefs.addObserver("", prefObserver, false);
196+
197+
log.debug("initialized");
198+
}
199+
200+
/**
201+
* load library
202+
*/
203+
function load() {
204+
"use strict";
205+
191206
let path;
192207
if (prefs.getBoolPref("libunbound.path.relToProfileDir")) {
193208
path = OS.Path.join(OS.Constants.Path.profileDir,
@@ -201,10 +216,6 @@ function init() {
201216
method: "load",
202217
path: path,
203218
});
204-
205-
update_ctx();
206-
207-
log.debug("initialized");
208219
}
209220

210221
/**
@@ -314,6 +325,37 @@ libunboundWorker.onmessage = function(msg) {
314325
}
315326
};
316327

328+
var prefObserver = {
329+
/*
330+
* gets called called whenever an event occurs on the preference
331+
*/
332+
observe: function Verifier_observe(subject, topic, data) {
333+
"use strict";
334+
335+
// subject is the nsIPrefBranch we're observing (after appropriate QI)
336+
// data is the name of the pref that's been changed (relative to aSubject)
337+
338+
if (topic !== "nsPref:changed") {
339+
return;
340+
}
341+
342+
switch(data) {
343+
case "libunbound.path.relToProfileDir":
344+
case "libunbound.path":
345+
load();
346+
update_ctx();
347+
break;
348+
case "libunbound.conf":
349+
case "libunbound.debuglevel":
350+
case "getNameserversFromOS":
351+
case "nameserver":
352+
case "dnssec.trustAnchor":
353+
update_ctx();
354+
break;
355+
}
356+
},
357+
};
358+
317359
libunbound.Constants = Constants;
318360

319361
init();

Diff for: modules/libunboundWorker.jsm

+10-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* A ChromeWorker wrapper for the libunbound DNS library.
55
* Currently only the TXT resource record is completely supported.
66
*
7-
* Version: 1.0.0pre1 (22 January 2016)
7+
* Version: 1.0.0pre2 (22 January 2016)
88
*
99
* Copyright (c) 2016 Philippe Lieser
1010
*
@@ -249,6 +249,15 @@ function resolve(name, rrtype=Constants.RR_TYPE_A) {
249249
function load(path) {
250250
"use strict";
251251

252+
// if library was already loaded, do a cleanup first before reloading it
253+
if (lib) {
254+
// delete old context
255+
ub_ctx_delete(ctx);
256+
ctx = ctypes.voidptr_t();
257+
// close library
258+
lib.close();
259+
lib = null;
260+
}
252261
lib = ctypes.open(path);
253262

254263
ub_ctx = new ctypes.StructType("ub_ctx");

0 commit comments

Comments
 (0)