diff --git a/server/libs/dnser.rb b/server/libs/dnser.rb index 0af84aea..ee57d27d 100644 --- a/server/libs/dnser.rb +++ b/server/libs/dnser.rb @@ -837,13 +837,13 @@ def initialize(host, port, cache=false) # This method returns immediately, but spawns a background thread. The thread # will recveive and parse DNS packets, create a transaction, and pass it to # the caller's block. - def on_request() + def on_request(&block) @thread = Thread.new() do |t| begin loop do data = @s.recvfrom(65536) - - begin + + begin # Data is an array where the first element is the actual data, and the second is the host/port request = DNSer::Packet.parse(data[0]) @@ -869,7 +869,7 @@ def on_request() if(!transaction.sent) begin - proc.call(transaction) + block.call(transaction) rescue StandardError => e puts("Caught an error: #{e}") puts(e.backtrace()) @@ -912,7 +912,7 @@ def wait() # Send out a query, asynchronously. This immediately returns, then, when the # query is finished, the callback block is called with a DNSer::Packet that # represents the response (or nil, if there was a timeout). - def DNSer.query(hostname, params = {}) + def DNSer.query(hostname, params = {}, &block) server = params[:server] || "8.8.8.8" port = params[:port] || 53 type = params[:type] || DNSer::Packet::TYPE_A @@ -930,10 +930,10 @@ def DNSer.query(hostname, params = {}) timeout(timeout) do response = s.recv(65536) - proc.call(DNSer::Packet.parse(response)) + block.call(DNSer::Packet.parse(response)) end rescue Timeout::Error - proc.call(nil) + block.call(nil) rescue Exception => e puts("There was an exception sending a query for #{hostname} to #{server}:#{port}: #{e}") ensure diff --git a/server/libs/settings.rb b/server/libs/settings.rb index 64882382..7fb5dafe 100644 --- a/server/libs/settings.rb +++ b/server/libs/settings.rb @@ -157,13 +157,13 @@ def each_setting() # Create a new setting, or replace an old one. This must be done before a # setting is used. - def create(name, type, default_value, docs) + def create(name, type, default_value, docs, &block) name = name.to_s() @settings[name] = @settings[name] || {} @settings[name][:type] = type - @settings[name][:watcher] = proc + @settings[name][:watcher] = block @settings[name][:docs] = docs @settings[name][:default] = @@mutators[type].call(default_value.to_s()) diff --git a/server/libs/swindow.rb b/server/libs/swindow.rb index 3095a48a..9292c924 100644 --- a/server/libs/swindow.rb +++ b/server/libs/swindow.rb @@ -60,14 +60,14 @@ class SWindow # This function will trap the TSTP signal (suspend, ctrl-z) and, if possible, # activate the parent window. - def SWindow._catch_suspend() + def SWindow._catch_suspend(&block) orig_suspend = Signal.trap("TSTP") do if(@@active) @@active.deactivate() end end - proc.call() + block.call() Signal.trap("TSTP", orig_suspend) end @@ -182,8 +182,8 @@ def children() # Set the on_input callback - the function that will be called when input is # received. Very important! - def on_input() - @callback = proc + def on_input(&block) + @callback = block end def with(params = {}) diff --git a/server/tunnel_drivers/driver_dns.rb b/server/tunnel_drivers/driver_dns.rb index f4e778e6..96023603 100644 --- a/server/tunnel_drivers/driver_dns.rb +++ b/server/tunnel_drivers/driver_dns.rb @@ -313,7 +313,7 @@ def initialize(parent_window, host, port, domains, cache) end # Get the response - response = proc.call(name, max_length) + response = yield(name, max_length) if(response.length > max_length) raise(DnscatException, "The handler returned too much data! This shouldn't happen, please report. (max = #{max_length}, returned = #{response.length}")