Class: Riddl::Server
- Inherits:
-
Object
- Object
- Riddl::Server
- Defined in:
- lib/ruby/riddl/server.rb
Defined Under Namespace
Classes: Execution
Constant Summary collapse
- OPTS =
}}}
{ :host => 'localhost', :port => 9292, :secure => false, :mode => :debug, :verbose => false, :http_only => false, :basepath => File.(File.dirname($0)), :pidfile => File.basename($0,'.rb') + '.pid', :conffile => File.basename($0,'.rb') + '.conf', :runtime_options => [], :cmdl_parsing => true, :cmdl_operation => 'start' }
Instance Attribute Summary collapse
-
#riddl_log ⇒ Object
readonly
}}}.
-
#riddl_method ⇒ Object
readonly
}}}.
-
#riddl_pinfo ⇒ Object
readonly
}}}.
-
#riddl_status ⇒ Object
readonly
}}}.
Instance Method Summary collapse
-
#__call ⇒ Object
}}}.
-
#__http_call(env) ⇒ Object
}}}.
-
#__xmpp_call(env, raw) ⇒ Object
}}}.
-
#accessible_description(ad) ⇒ Object
}}}.
-
#at_exit(&blk) ⇒ Object
}}}.
-
#call(env) ⇒ Object
{{{.
-
#cross_site_xhr(csxhr) ⇒ Object
}}}.
-
#declaration_path ⇒ Object
}}}.
-
#declaration_resource ⇒ Object
}}}.
- #delete(min = '*') ⇒ Object
- #get(min = '*') ⇒ Object
-
#initialize(riddl, opts = {}, &blk) ⇒ Server
constructor
{{{.
-
#interface(name, &block) ⇒ Object
}}}.
-
#logger(lgr) ⇒ Object
}}}.
-
#loop! ⇒ Object
{{{.
-
#matching_path ⇒ Object
{{{.
-
#method(what) ⇒ Object
}}}.
-
#on(resource, &block) ⇒ Object
}}}.
-
#post(min = '*') ⇒ Object
}}}.
-
#process_out(pout) ⇒ Object
}}}.
- #put(min = '*') ⇒ Object
- #resource(rname = nil) ⇒ Object
-
#run(what, *args) ⇒ Object
}}}.
-
#use(blk, *args) ⇒ Object
}}}.
- #websocket ⇒ Object
-
#xmpp(jid, pass) ⇒ Object
}}}.
Constructor Details
#initialize(riddl, opts = {}, &blk) ⇒ Server
{{{
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/ruby/riddl/server.rb', line 195 def initialize(riddl,opts={},&blk)# {{{ @riddl_opts = {} @riddl_opts = OPTS.merge(opts) if File.exists?(@riddl_opts[:basepath] + '/' + @riddl_opts[:conffile]) @riddl_opts.merge!(Psych::load_file(@riddl_opts[:basepath] + '/' + @riddl_opts[:conffile])) end ######################################################################################################################## # parse arguments ######################################################################################################################## if @riddl_opts[:cmdl_parsing] @riddl_opts[:cmdl_operation] = "start" ARGV. { |opt| opt.summary_indent = ' ' * 4 opt. = "Usage:\n#{opt.summary_indent}ruby server.rb [options] start|stop|restart|info" + (@riddl_opts[:runtime_options].length > 0 ? '|' : '') + @riddl_opts[:runtime_options].map{|ro| ro[0]}.join('|') + "\n" opt.on("Options:") opt.on("--port [PORT]", "-p [PORT]", "Specify http port.") do |p| @riddl_opts[:port] = p.to_i @riddl_opts[:pidfile] = @riddl_opts[:pidfile].gsub(/\.pid/,'') + '-' + @riddl_opts[:port].to_s + '.pid' end opt.on("--http-only", "-s", "Only http, no other protocols.") { @riddl_opts[:http_only] = true } opt.on("--verbose", "-v", "Do not daemonize. Write ouput to console.") { @riddl_opts[:verbose] = true } opt.on("--help", "-h", "This text.") { puts opt; exit } opt.separator(opt.summary_indent + "start|stop|restart|info".ljust(opt.summary_width+1) + "Do operation start, stop, restart or get information.") @riddl_opts[:runtime_options].each do |ro| opt.separator(opt.summary_indent + ro[0].ljust(opt.summary_width+1) + ro[1]) end opt.parse! } unless (%w{start stop restart info} + @riddl_opts[:runtime_options].map{|ro| ro[0] }).include?(ARGV[0]) puts ARGV. exit end @riddl_opts[:cmdl_operation] = ARGV[0] end ######################################################################################################################## @riddl_opts[:url] = (@riddl_opts[:secure] ? 'https://' : 'http://') + @riddl_opts[:host] + ':' + @riddl_opts[:port].to_s @riddl_logger = nil @riddl_process_out = true @riddl_cross_site_xhr = false @accessible_description = false @riddl_description_string = '' @riddl_paths = [] @riddl_at_exit = nil @riddl_interfaces = {} instance_exec(@riddl_opts,&blk) if block_given? @riddl = Riddl::Wrapper.new(riddl,@accessible_description) if @riddl.description? raise SpecificationError, 'RIDDL description does not conform to specification' unless @riddl.validate! @riddl_description_string = @riddl.description.xml elsif @riddl.declaration? raise SpecificationError, 'RIDDL declaration does not conform to specification' unless @riddl.validate! @riddl_description_string = @riddl.declaration.description_xml else raise SpecificationError, 'Not a RIDDL file' end @riddl.load_necessary_handlers! @riddl_paths = @riddl.paths end |
Instance Attribute Details
#riddl_log ⇒ Object (readonly)
}}}
193 194 195 |
# File 'lib/ruby/riddl/server.rb', line 193 def riddl_log @riddl_log end |
#riddl_method ⇒ Object (readonly)
}}}
193 194 195 |
# File 'lib/ruby/riddl/server.rb', line 193 def riddl_method @riddl_method end |
#riddl_pinfo ⇒ Object (readonly)
}}}
193 194 195 |
# File 'lib/ruby/riddl/server.rb', line 193 def riddl_pinfo @riddl_pinfo end |
#riddl_status ⇒ Object (readonly)
}}}
193 194 195 |
# File 'lib/ruby/riddl/server.rb', line 193 def riddl_status @riddl_status end |
Instance Method Details
#__call ⇒ Object
}}}
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/ruby/riddl/server.rb', line 269 def __call #{{{ @riddl_message = @riddl.(@riddl_matching_path[0],@riddl_method,@riddl_parameters,@riddl_headers) if @riddl_message.nil? if @riddl_info[:env].has_key?('HTTP_ORIGIN') && @riddl_cross_site_xhr && @riddl_method == 'options' @riddl_res['Access-Control-Allow-Origin'] = '*' @riddl_res['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS' @riddl_res['Access-Control-Allow-Headers'] = @riddl_info[:env]['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'] if @riddl_info[:env]['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'] @riddl_res['Access-Control-Max-Age'] = '0' @riddl_res['Content-Length'] = '0' @riddl_status = 200 else @riddl_log.write "501: the #{@riddl_method} parameters are not matching anything in the description.\n" @riddl_status = 501 # not implemented?! end else if !@riddl_message.nil? && @accessible_description && @riddl_message.in.name == 'riddl-description-request' && @riddl_method == 'get' && '/' + @riddl_info[:s].join('/') == '/' run Riddl::Utils::Description::RDR, @riddl_description_string elsif !@riddl_message.nil? && @accessible_description && @riddl_message.in.name == 'riddl-resource-description-request' && @riddl_method == 'get' @riddl_path = File.dirname('/' + @riddl_info[:s].join('/')).gsub(/\/+/,'/') on resource File.basename('/' + @riddl_info[:s].join('/')).gsub(/\/+/,'/') do run Riddl::Utils::Description::RDR, @riddl.resource_description(@riddl_matching_path[0]) end else if @riddl.description? instance_exec(@riddl_info, &@riddl_interfaces[nil]) elsif @riddl.declaration? mess = @riddl_message @riddl_message.route_to_a.each do |m| @riddl_message = m @riddl_path = '/' if m.interface.base.nil? if @riddl_interfaces.key? m.interface.name @riddl_info[:r] = m.interface.real_path(@riddl_pinfo).sub(/^\//,'').split('/') @riddl_info[:h]['RIDDL_DECLARATION_PATH'] = @riddl_pinfo @riddl_info[:h]['RIDDL_DECLARATION_RESOURCE'] = m.interface.top @riddl_info[:s] = m.interface.sub.sub(/\//,'').split('/') @riddl_info.merge!(:match => matching_path) instance_exec(@riddl_info, &@riddl_interfaces[m.interface.name]) else @riddl_log.write "501: not implemented (for remote: add @location in declaration; for local: add to Riddl::Server).\n" @riddl_status = 501 # not implemented?! break end else run Riddl::Utils::Description::Call, @riddl_exe, @riddl_pinfo, m.interface.top, m.interface.base, m.interface.real_path(@riddl_pinfo) end break if @riddl_status < 200 || @riddl_status >= 300 @riddl_info.merge!(:h => @riddl_exe.headers, :p => @riddl_exe.response) end @riddl_message = mess end end if @riddl_info[:env].has_key?('HTTP_ORIGIN') && @riddl_cross_site_xhr @riddl_res['Access-Control-Allow-Origin'] = '*' @riddl_res['Access-Control-Max-Age'] = '0' end end end |
#__http_call(env) ⇒ Object
}}}
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 |
# File 'lib/ruby/riddl/server.rb', line 384 def __http_call(env) #{{{ @riddl_env = env @riddl_env['rack.logger'] = @riddl_logger if @riddl_logger @riddl_log = @riddl_logger || @riddl_env['rack.errors'] @riddl_res = Rack::Response.new @riddl_status = 404 @riddl_pinfo = Riddl::Protocols::Utils::unescape(@riddl_env["PATH_INFO"].gsub(/\/+/,'/')) @riddl_matching_path = @riddl_paths.find{ |e| @riddl_pinfo.match(e[1]).to_s.length == @riddl_pinfo.length } if @riddl_matching_path @riddl_query_string = @riddl_env['QUERY_STRING'] @riddl_raw = @riddl_env['rack.input'] @riddl_headers = {} @riddl_env.each do |h,v| @riddl_headers[$1] = v if h =~ /^HTTP_(.*)$/ end @riddl_parameters = Protocols::HTTP::Parser.new( @riddl_query_string, @riddl_raw, @riddl_env['CONTENT_TYPE'], @riddl_env['CONTENT_LENGTH'], @riddl_env['HTTP_CONTENT_DISPOSITION'], @riddl_env['HTTP_CONTENT_ID'], @riddl_env['HTTP_RIDDL_TYPE'] ).params @riddl_method = @riddl_env['REQUEST_METHOD'].downcase @riddl_path = '/' @riddl_info = { :h => @riddl_headers, :p => @riddl_parameters, :r => @riddl_pinfo.sub(/^\//,'').split('/').map{|e|Protocols::Utils::unescape(e)}, :s => @riddl_matching_path[0].sub(/\//,'').split('/'), :m => @riddl_method, :env => @riddl_env.reject{|k,v| k =~ /^rack\./}.merge({'riddl.transport' => 'http', 'xmpp' => @riddl_opts[:xmpp]}), :match => [] } if @riddl_info[:env]["HTTP_CONNECTION"] =~ /Upgrade/ && @riddl_info[:env]["HTTP_UPGRADE"] =~ /\AWebSocket\z/i # TODO raise error when declaration and route or (not route and non-local interface) # raise SpecificationError, 'RIDDL description does not conform to specification' unless @riddl.validate! @riddl_info[:m] = @riddl_method = 'websocket' @riddl_message = @riddl.(@riddl_matching_path[0],'websocket',@riddl_parameters,@riddl_headers) if @riddl.description? instance_exec(@riddl_info, &@riddl_interfaces[nil]) elsif @riddl.declaration? # one ws connection, no overlay unless @riddl_message.nil? if @riddl_interfaces.key? @riddl_message.interface.name @riddl_info[:r] = @riddl_message.interface.real_path(@riddl_pinfo).sub(/^\//,'').split('/') @riddl_info[:h]['RIDDL_DECLARATION_PATH'] = @riddl_pinfo @riddl_info[:h]['RIDDL_DECLARATION_RESOURCE'] = @riddl_message.interface.top @riddl_info[:s] = @riddl_message.interface.sub.sub(/\//,'').split('/') @riddl_info.merge!(:match => matching_path) instance_exec(@riddl_info, &@riddl_interfaces[@riddl_message.interface.name]) end end end throw :async else __call end else @riddl_log.write "404: this resource for sure does not exist.\n" @riddl_status = 404 # client requests wrong path end if @riddl_exe @riddl_res.write Protocols::HTTP::Generator.new(@riddl_exe.response,@riddl_res).generate.read @riddl_exe.headers.each do |n,h| @riddl_res[n] = h end end @riddl_res.status = @riddl_status @riddl_res.finish end |
#__xmpp_call(env, raw) ⇒ Object
}}}
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/ruby/riddl/server.rb', line 328 def __xmpp_call(env,raw) #{{{ @riddl_log = @riddl_logger || STDOUT @riddl_env = XML::Smart::Dom::Element.new(raw).parent @riddl_env.register_namespace 'xr', Riddl::Protocols::XMPP::XR_NS @riddl_res = env @riddl_status = 404 @riddl_pinfo = ('/' + @riddl_env.root.attributes['to'].sub(/^[^\/]+/,'')).gsub(/\/+/,'/') @riddl_pinfo.gsub!(/\?(.*)/).each do @riddl_query_string = $1; '' end @riddl_matching_path = @riddl_paths.find{ |e| @riddl_pinfo.match(e[1]).to_s.length == @riddl_pinfo.length } if @riddl_matching_path @riddl_method = @riddl_env.find('string(/message/xr:operation)').downcase @riddl_headers = {} @riddl_env.find('/message/xr:header').each do |e| @riddl_headers[e.attributes['name']] = e.text end @riddl_parameters = Protocols::XMPP::Parser.new( @riddl_query_string, @riddl_env ).params @riddl_path = '/' @riddl_info = { :h => @riddl_headers, :p => @riddl_parameters, :r => @riddl_pinfo.sub(/^\//,'').split('/').map{|e|Protocols::Utils::unescape(e)}, :s => @riddl_matching_path[0].sub(/\//,'').split('/'), :m => @riddl_method, :env => Hash[@riddl_env.root.attributes.map{|a| [a.qname.name, a.value] }].merge({ 'riddl.transport' => 'xmpp', 'xmpp' => @riddl_res }), :match => [] } __call else @riddl_log.write "404: this resource for sure does not exist.\n" @riddl_status = 404 # client requests wrong path end stanza = if @riddl_exe && @riddl_status >= 200 && @riddl_status < 300 return if @riddl_message.out.nil? Protocols::XMPP::Generator.new(@riddl_status,@riddl_exe.response,@riddl_exe.headers).generate else Protocols::XMPP::Error.new(@riddl_status).generate end stanza.from = raw.to stanza.to = raw.from stanza.id = raw.id @riddl_res.write stanza end |
#accessible_description(ad) ⇒ Object
}}}
476 477 478 |
# File 'lib/ruby/riddl/server.rb', line 476 def accessible_description(ad)# {{{ @accessible_description = ad end |
#at_exit(&blk) ⇒ Object
}}}
261 262 263 |
# File 'lib/ruby/riddl/server.rb', line 261 def at_exit(&blk) @riddl_at_exit = blk end |
#call(env) ⇒ Object
{{{
265 266 267 |
# File 'lib/ruby/riddl/server.rb', line 265 def call(env)# {{{ dup.__http_call(env) end |
#cross_site_xhr(csxhr) ⇒ Object
}}}
470 471 472 |
# File 'lib/ruby/riddl/server.rb', line 470 def cross_site_xhr(csxhr)# {{{ @riddl_cross_site_xhr = csxhr end |
#declaration_path ⇒ Object
}}}
551 552 553 |
# File 'lib/ruby/riddl/server.rb', line 551 def declaration_path #{{{ @riddl_info[:h]['RIDDL_DECLARATION_PATH'] end |
#declaration_resource ⇒ Object
}}}
554 555 556 |
# File 'lib/ruby/riddl/server.rb', line 554 def declaration_resource #{{{ @riddl_info[:h]['RIDDL_DECLARATION_RESOURCE'] end |
#delete(min = '*') ⇒ Object
542 |
# File 'lib/ruby/riddl/server.rb', line 542 def delete(min='*'); return false if @riddl_message.nil?; @riddl_path == '/' + @riddl_info[:s].join('/') && @riddl_message.in && min == @riddl_message.in.name && @riddl_method == 'delete' end |
#get(min = '*') ⇒ Object
541 |
# File 'lib/ruby/riddl/server.rb', line 541 def get(min='*'); return false if @riddl_message.nil?; @riddl_path == '/' + @riddl_info[:s].join('/') && @riddl_message.in && min == @riddl_message.in.name && @riddl_method == 'get' end |
#interface(name, &block) ⇒ Object
}}}
479 480 481 |
# File 'lib/ruby/riddl/server.rb', line 479 def interface(name,&block) #{{{ @riddl_interfaces[name] = block end |
#logger(lgr) ⇒ Object
}}}
473 474 475 |
# File 'lib/ruby/riddl/server.rb', line 473 def logger(lgr)# {{{ @riddl_logger = lgr end |
#loop! ⇒ Object
{{{
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/ruby/riddl/server.rb', line 60 def loop! #{{{ ######################################################################################################################## # status and info ######################################################################################################################## pid = File.read(@riddl_opts[:basepath] + '/' + @riddl_opts[:pidfile]).to_i rescue pid = -1 status = Proc.new do begin Process.getpgid pid true rescue Errno::ESRCH false end end if @riddl_opts[:cmdl_operation] == "info" && status.call == false puts "Server (#{@riddl_opts[:url]}) not running" exit end if @riddl_opts[:cmdl_operation] == "info" && status.call == true puts "Server (#{@riddl_opts[:url]}) running as #{pid}" begin stats = `ps -o "vsz,rss,lstart,time" -p #{pid}`.split("\n")[1].strip.split(/ +/) puts "Virtual: #{"%0.2f" % (stats[0].to_f/1024)} MiB" puts "Resident: #{"%0.2f" % (stats[1].to_f/1024)} MiB" puts "Started: #{stats[2..-2].join(' ')}" puts "CPU Time: #{stats.last}" rescue end exit end if %w{start}.include?(@riddl_opts[:cmdl_operation]) && status.call == true puts "Server (#{@riddl_opts[:url]}) already started" exit end ######################################################################################################################## # stop/restart server ######################################################################################################################## if %w{stop restart}.include?(@riddl_opts[:cmdl_operation]) if status.call == false puts "Server (#{@riddl_opts[:url]}) maybe not started?" else puts "Server (#{@riddl_opts[:url]}) stopped" puts "Waiting while server goes down ..." while status.call Process.kill "SIGTERM", pid sleep 0.3 end end exit unless @riddl_opts[:cmdl_operation] == "restart" end ######################################################################################################################## # go through user defined startup thingis ######################################################################################################################## @riddl_opts[:runtime_options].each do |ro| ro[2].call(status.call) if @riddl_opts[:cmdl_operation] == ro[0] end app = Rack::Builder.new self unless @riddl_logger.nil? app.use Rack::CommonLogger, @riddl_logger end server = Rack::Server.new( :app => app, :Host => '0.0.0.0', :Port => @riddl_opts[:port], :environment => @riddl_opts[:verbose] ? 'deployment' : 'none', :server => 'thin', :pid => File.(@riddl_opts[:basepath] + '/' + @riddl_opts[:pidfile]), :signals => false ) puts "Server (#{@riddl_opts[:url]}) started as PID:#{Process.pid}" puts "XMPP support (#{@riddl_xmpp_jid}) active" if @riddl_xmpp_jid && @riddl_xmpp_pass && !@riddl_opts[:http_only] Process.daemon(@riddl_opts[:basepath]) unless @riddl_opts[:verbose] Dir.chdir(@riddl_opts[:basepath]) ::Kernel::at_exit do @riddl_at_exit.call if @riddl_at_exit end begin EM.run do if @riddl_opts[:secure] server.start do |srv| srv.ssl = true srv. = @riddl_opts[:secure_options] end else server.start end @riddl_opts[:xmpp] = nil if @riddl_xmpp_jid && @riddl_xmpp_pass && !@riddl_opts[:http_only] xmpp = Blather::Client.setup @riddl_xmpp_jid, @riddl_xmpp_pass @riddl_opts[:xmpp] = xmpp xmpp.register_handler(:message, '/message/ns:operation', :ns => 'http://riddl.org/ns/xmpp-rest') do |m| began_at = Time.now instance = dup instance.__xmpp_call(xmpp,m) now = Time.now instance.riddl_log.write Rack::CommonLogger::FORMAT % [ @riddl_xmpp_jid || "-", m.from || "-", now.strftime("%d/%b/%Y %H:%M:%S"), instance.riddl_method.upcase, instance.riddl_pinfo, '', 'XMPP', instance.riddl_status, '?', now - began_at ] end xmpp.connect end [:INT, :TERM].each do |signal| Signal.trap(signal) do EM.stop end end end rescue => e if e.is_a?(Blather::Stream::ConnectionFailed) puts "Server (#{@riddl_xmpp_jid}) stopped due to connection error (PID:#{Process.pid})" else puts "Server (#{@riddl_opts[:url]}) stopped due to connection error (PID:#{Process.pid})" end end end |
#matching_path ⇒ Object
{{{
547 548 549 |
# File 'lib/ruby/riddl/server.rb', line 547 def matching_path #{{{ @riddl_path.sub(/\//,'').split('/') end |
#method(what) ⇒ Object
}}}
532 533 534 535 536 537 538 539 |
# File 'lib/ruby/riddl/server.rb', line 532 def method(what)# {{{ if !@riddl_message.nil? && what.class == Hash && what.length == 1 met, min = what.first @riddl_path == @riddl_matching_path[0] && min == @riddl_message.in.name && @riddl_method == met.to_s.downcase else false end end |
#on(resource, &block) ⇒ Object
}}}
483 484 485 486 487 488 489 490 491 492 493 494 495 496 |
# File 'lib/ruby/riddl/server.rb', line 483 def on(resource, &block)# {{{ if @riddl_paths.empty? # default interface, when a description and "on" syntax in server @riddl_interfaces[nil] = block return end @riddl_path << (@riddl_path == '/' ? resource : '/' + resource) ### only descend when there is a possibility that it holds the right path rp = @riddl_path.sub(/\//,'').split('/') block.call(@riddl_info.merge!(:match => matching_path)) if @riddl_info[:s][rp.length-1] == rp.last @riddl_path = File.dirname(@riddl_path).gsub(/\/+/,'/') end |
#post(min = '*') ⇒ Object
}}}
540 |
# File 'lib/ruby/riddl/server.rb', line 540 def post(min='*'); return false if @riddl_message.nil?; @riddl_path == '/' + @riddl_info[:s].join('/') && @riddl_message.in && min == @riddl_message.in.name && @riddl_method == 'post' end |
#process_out(pout) ⇒ Object
}}}
462 463 464 |
# File 'lib/ruby/riddl/server.rb', line 462 def process_out(pout)# {{{ @riddl_process_out = pout end |
#put(min = '*') ⇒ Object
543 |
# File 'lib/ruby/riddl/server.rb', line 543 def put(min='*'); return false if @riddl_message.nil?; @riddl_path == '/' + @riddl_info[:s].join('/') && @riddl_message.in && min == @riddl_message.in.name && @riddl_method == 'put' end |
#resource(rname = nil) ⇒ Object
545 |
# File 'lib/ruby/riddl/server.rb', line 545 def resource(rname=nil); return rname.nil? ? '{}' : rname end |
#run(what, *args) ⇒ Object
}}}
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
# File 'lib/ruby/riddl/server.rb', line 502 def run(what,*args)# {{{ return if @riddl_path == '' if what.class == Class && what.superclass == Riddl::WebSocketImplementation data = Riddl::Protocols::WebSocket::ParserData.new data.request_path = @riddl_pinfo data.request_url = @riddl_pinfo + '?' + @riddl_query_string data.query_string = @riddl_query_string data.http_method = @riddl_env['REQUEST_METHOD'] data.body = @riddl_env['rack.input'].read data.headers = Hash[ @riddl_headers.map { |key, value| [key.downcase.gsub('_','-'), value] } ] w = what.new(@riddl_info.merge!(:a => args, :version => @riddl_env['HTTP_SEC_WEBSOCKET_VERSION'], :match => matching_path)) w.io = Riddl::Protocols::WebSocket.new(w, @riddl_env['thin.connection']) w.io.dispatch(data) end if what.class == Class && what.superclass == Riddl::Implementation w = what.new(@riddl_info.merge!(:a => args, :match => matching_path)) @riddl_exe = Riddl::Server::Execution.new(w.response,w.headers) @riddl_status = w.status if @riddl_process_out && @riddl_status >= 200 && @riddl_status < 300 unless @riddl.(@riddl_exe.response,@riddl_exe.headers,@riddl_message.out) @riddl_log.write "500: the return for the #{@riddl_method} is not matching anything in the description.\n" @riddl_status = 500 return end end end end |
#use(blk, *args) ⇒ Object
}}}
498 499 500 |
# File 'lib/ruby/riddl/server.rb', line 498 def use(blk,*args)# {{{ instance_eval(&blk) end |
#websocket ⇒ Object
544 |
# File 'lib/ruby/riddl/server.rb', line 544 def websocket; return false if @riddl_message.nil?; @riddl_path == '/' + @riddl_info[:s].join('/') && @riddl_method == 'websocket' end |
#xmpp(jid, pass) ⇒ Object
}}}
465 466 467 468 469 |
# File 'lib/ruby/riddl/server.rb', line 465 def xmpp(jid,pass)# {{{ @riddl_xmpp_jid = jid @riddl_xmpp_pass = pass @riddl_opts[:jid] = jid end |