riddl 0.99.199 → 0.99.200

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d652a220a391aac5d409098c11e8b3fd1751eca
4
- data.tar.gz: bd48be6547472fe6f4a5ef8dcb9baa476bda6fac
3
+ metadata.gz: c67aa38ff11dcb881b3ea8653e11d12da9611687
4
+ data.tar.gz: cb1bde4833c693dae96bd714d1d30b38e78b798a
5
5
  SHA512:
6
- metadata.gz: 5ccbbbc6861559ea2021da5cc072be8d2e4f5e0ae3c1bc557e5ea3ddef41a0ed2a99b63f66d4ae5ffbb99f4fea33819f9974f5bbe188ed5b685f7aa344881cfe
7
- data.tar.gz: 2cca480107181de68fdd7c802b708345382895a8be1650b2d45768fe9b03a155d34dd8e8c8a09b0f680c89339c948b4573c267978ae06063de8d2a55c20d8ddf
6
+ metadata.gz: d5229e2f25d0b333031a6ee59e097056a9653f198924245d2f4b16c4914c37d6f8a25a5068696aa6c390be9fd7618f63dd2ea2a77a99dbfea266e28a53ce2a9f
7
+ data.tar.gz: c4743b2544bf733c8e24339c61503d19f895a6b8b3562d31ceb23f9e364362043597bf9f440973c6a540dd23c0ede4ab3a0367daf46f137b9d5bffb28cbae89c
@@ -0,0 +1 @@
1
+ 24293
File without changes
@@ -38,47 +38,26 @@ module Riddl
38
38
  end
39
39
  @headers.compact!
40
40
  @response.compact!
41
- @headers = Hash[ @headers.map{ |h| [h.name, h.value] } ]
41
+ @headers = Hash[ @headers.map{ |h| [h.name, h.value] } ]
42
42
  end
43
43
  end #}}}
44
44
 
45
- OPTS = {
45
+ OPTS = {
46
46
  :host => 'localhost',
47
47
  :port => 9292,
48
48
  :secure => false,
49
49
  :mode => :debug,
50
+ :verbose => false,
51
+ :http_only => false,
50
52
  :basepath => File.expand_path(File.dirname($0)),
51
53
  :pidfile => File.basename($0,'.rb') + '.pid',
52
54
  :conffile => File.basename($0,'.rb') + '.conf',
53
- :runtime_options => []
55
+ :runtime_options => [],
56
+ :cmdl_parsing => true,
57
+ :cmdl_operation => 'start'
54
58
  }
55
59
 
56
60
  def loop! #{{{
57
- ########################################################################################################################
58
- # parse arguments
59
- ########################################################################################################################
60
- verbose = false
61
- http_only = false
62
- operation = "start"
63
- ARGV.options { |opt|
64
- opt.summary_indent = ' ' * 4
65
- opt.banner = "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"
66
- opt.on("Options:")
67
- opt.on("--http-only", "-s", "Only http, no other protocols.") { http_only = true }
68
- opt.on("--verbose", "-v", "Do not daemonize. Write ouput to console.") { verbose = true }
69
- opt.on("--help", "-h", "This text.") { puts opt; exit }
70
- opt.separator(opt.summary_indent + "start|stop|restart|info".ljust(opt.summary_width+1) + "Do operation start, stop, restart or get information.")
71
- @riddl_opts[:runtime_options].each do |ro|
72
- opt.separator(opt.summary_indent + ro[0].ljust(opt.summary_width+1) + ro[1])
73
- end
74
- opt.parse!
75
- }
76
- unless (%w{start stop restart info} + @riddl_opts[:runtime_options].map{|ro| ro[0] }).include?(ARGV[0])
77
- puts ARGV.options
78
- exit
79
- end
80
- operation = ARGV[0]
81
-
82
61
  ########################################################################################################################
83
62
  # status and info
84
63
  ########################################################################################################################
@@ -91,11 +70,11 @@ module Riddl
91
70
  false
92
71
  end
93
72
  end
94
- if operation == "info" && status.call == false
73
+ if @riddl_opts[:cmdl_operation] == "info" && status.call == false
95
74
  puts "Server (#{@riddl_opts[:url]}) not running"
96
75
  exit
97
76
  end
98
- if operation == "info" && status.call == true
77
+ if @riddl_opts[:cmdl_operation] == "info" && status.call == true
99
78
  puts "Server (#{@riddl_opts[:url]}) running as #{pid}"
100
79
  begin
101
80
  stats = `ps -o "vsz,rss,lstart,time" -p #{pid}`.split("\n")[1].strip.split(/ +/)
@@ -107,15 +86,15 @@ module Riddl
107
86
  end
108
87
  exit
109
88
  end
110
- if %w{start}.include?(operation) && status.call == true
89
+ if %w{start}.include?(@riddl_opts[:cmdl_operation]) && status.call == true
111
90
  puts "Server (#{@riddl_opts[:url]}) already started"
112
91
  exit
113
92
  end
114
-
93
+
115
94
  ########################################################################################################################
116
95
  # stop/restart server
117
96
  ########################################################################################################################
118
- if %w{stop restart}.include?(operation)
97
+ if %w{stop restart}.include?(@riddl_opts[:cmdl_operation])
119
98
  if status.call == false
120
99
  puts "Server (#{@riddl_opts[:url]}) maybe not started?"
121
100
  else
@@ -124,16 +103,16 @@ module Riddl
124
103
  while status.call
125
104
  Process.kill "SIGTERM", pid
126
105
  sleep 0.3
127
- end
106
+ end
128
107
  end
129
- exit unless operation == "restart"
108
+ exit unless @riddl_opts[:cmdl_operation] == "restart"
130
109
  end
131
-
110
+
132
111
  ########################################################################################################################
133
112
  # go through user defined startup thingis
134
113
  ########################################################################################################################
135
114
  @riddl_opts[:runtime_options].each do |ro|
136
- ro[2].call(status.call) if operation == ro[0]
115
+ ro[2].call(status.call) if @riddl_opts[:cmdl_operation] == ro[0]
137
116
  end
138
117
 
139
118
  app = Rack::Builder.new self
@@ -145,19 +124,19 @@ module Riddl
145
124
  :app => app,
146
125
  :Host => '0.0.0.0',
147
126
  :Port => @riddl_opts[:port],
148
- :environment => verbose ? 'deployment' : 'none',
127
+ :environment => @riddl_opts[:verbose] ? 'deployment' : 'none',
149
128
  :server => 'thin',
150
129
  :pid => File.expand_path(@riddl_opts[:basepath] + '/' + @riddl_opts[:pidfile]),
151
130
  :signals => false
152
131
  )
153
132
 
154
133
  puts "Server (#{@riddl_opts[:url]}) started as PID:#{Process.pid}"
155
- puts "XMPP support (#{@riddl_xmpp_jid}) active" if @riddl_xmpp_jid && @riddl_xmpp_pass && !http_only
156
- Process.daemon(@riddl_opts[:basepath]) unless verbose
134
+ puts "XMPP support (#{@riddl_xmpp_jid}) active" if @riddl_xmpp_jid && @riddl_xmpp_pass && !@riddl_opts[:http_only]
135
+ Process.daemon(@riddl_opts[:basepath]) unless @riddl_opts[:verbose]
157
136
  Dir.chdir(@riddl_opts[:basepath])
158
137
  ::Kernel::at_exit do
159
138
  @riddl_at_exit.call if @riddl_at_exit
160
- end
139
+ end
161
140
  begin
162
141
  EM.run do
163
142
  if @riddl_opts[:secure]
@@ -170,7 +149,7 @@ module Riddl
170
149
  end
171
150
 
172
151
  @riddl_opts[:xmpp] = nil
173
- if @riddl_xmpp_jid && @riddl_xmpp_pass && !http_only
152
+ if @riddl_xmpp_jid && @riddl_xmpp_pass && !@riddl_opts[:http_only]
174
153
  xmpp = Blather::Client.setup @riddl_xmpp_jid, @riddl_xmpp_pass
175
154
  @riddl_opts[:xmpp] = xmpp
176
155
  xmpp.register_handler(:message, '/message/ns:operation', :ns => 'http://riddl.org/ns/xmpp-rest') do |m|
@@ -198,14 +177,14 @@ module Riddl
198
177
  Signal.trap(signal) do
199
178
  EM.stop
200
179
  end
201
- end
180
+ end
202
181
 
203
182
  end
204
183
 
205
- rescue => e
184
+ rescue => e
206
185
  if e.is_a?(Blather::Stream::ConnectionFailed)
207
186
  puts "Server (#{@riddl_xmpp_jid}) stopped due to connection error (PID:#{Process.pid})"
208
- else
187
+ else
209
188
  puts "Server (#{@riddl_opts[:url]}) stopped due to connection error (PID:#{Process.pid})"
210
189
  end
211
190
  end
@@ -215,19 +194,49 @@ module Riddl
215
194
 
216
195
  def initialize(riddl,opts={},&blk)# {{{
217
196
  @riddl_opts = {}
218
- @riddl_opts = OPTS.merge(opts)
197
+ @riddl_opts = OPTS.merge(opts)
219
198
 
220
199
  if File.exists?(@riddl_opts[:basepath] + '/' + @riddl_opts[:conffile])
221
200
  @riddl_opts.merge!(Psych::load_file(@riddl_opts[:basepath] + '/' + @riddl_opts[:conffile]))
222
201
  end
202
+
203
+ ########################################################################################################################
204
+ # parse arguments
205
+ ########################################################################################################################
206
+ if @riddl_opts[:cmdl_parsing]
207
+ @riddl_opts[:cmdl_operation] = "start"
208
+ ARGV.options { |opt|
209
+ opt.summary_indent = ' ' * 4
210
+ opt.banner = "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"
211
+ opt.on("Options:")
212
+ opt.on("--port [PORT]", "-p [PORT]", "Specify http port.") do |p|
213
+ @riddl_opts[:port] = p.to_i
214
+ @riddl_opts[:pidfile] = @riddl_opts[:pidfile].gsub(/\.pid/,'') + '-' + @riddl_opts[:port].to_s + '.pid'
215
+ end
216
+ opt.on("--http-only", "-s", "Only http, no other protocols.") { @riddl_opts[:http_only] = true }
217
+ opt.on("--verbose", "-v", "Do not daemonize. Write ouput to console.") { @riddl_opts[:verbose] = true }
218
+ opt.on("--help", "-h", "This text.") { puts opt; exit }
219
+ opt.separator(opt.summary_indent + "start|stop|restart|info".ljust(opt.summary_width+1) + "Do operation start, stop, restart or get information.")
220
+ @riddl_opts[:runtime_options].each do |ro|
221
+ opt.separator(opt.summary_indent + ro[0].ljust(opt.summary_width+1) + ro[1])
222
+ end
223
+ opt.parse!
224
+ }
225
+ unless (%w{start stop restart info} + @riddl_opts[:runtime_options].map{|ro| ro[0] }).include?(ARGV[0])
226
+ puts ARGV.options
227
+ exit
228
+ end
229
+ @riddl_opts[:cmdl_operation] = ARGV[0]
230
+ end
231
+ ########################################################################################################################
223
232
  @riddl_opts[:url] = (@riddl_opts[:secure] ? 'https://' : 'http://') + @riddl_opts[:host] + ':' + @riddl_opts[:port].to_s
224
233
 
225
234
  @riddl_logger = nil
226
- @riddl_process_out = true
235
+ @riddl_process_out = true
227
236
  @riddl_cross_site_xhr = false
228
237
  @accessible_description = false
229
238
  @riddl_description_string = ''
230
- @riddl_paths = []
239
+ @riddl_paths = []
231
240
 
232
241
  @riddl_at_exit = nil
233
242
 
@@ -270,18 +279,18 @@ module Riddl
270
279
  else
271
280
  @riddl_log.write "501: the #{@riddl_method} parameters are not matching anything in the description.\n"
272
281
  @riddl_status = 501 # not implemented?!
273
- end
282
+ end
274
283
  else
275
284
  if !@riddl_message.nil? && @accessible_description && @riddl_message.in.name == 'riddl-description-request' && @riddl_method == 'get' && '/' + @riddl_info[:s].join('/') == '/'
276
- run Riddl::Utils::Description::RDR, @riddl_description_string
285
+ run Riddl::Utils::Description::RDR, @riddl_description_string
277
286
  elsif !@riddl_message.nil? && @accessible_description && @riddl_message.in.name == 'riddl-resource-description-request' && @riddl_method == 'get'
278
287
  @riddl_path = File.dirname('/' + @riddl_info[:s].join('/')).gsub(/\/+/,'/')
279
288
  on resource File.basename('/' + @riddl_info[:s].join('/')).gsub(/\/+/,'/') do
280
289
  run Riddl::Utils::Description::RDR, @riddl.resource_description(@riddl_matching_path[0])
281
- end
290
+ end
282
291
  else
283
292
  if @riddl.description?
284
- instance_exec(@riddl_info, &@riddl_interfaces[nil])
293
+ instance_exec(@riddl_info, &@riddl_interfaces[nil])
285
294
  elsif @riddl.declaration?
286
295
  mess = @riddl_message
287
296
  @riddl_message.route_to_a.each do |m|
@@ -295,11 +304,11 @@ module Riddl
295
304
  @riddl_info[:s] = m.interface.sub.sub(/\//,'').split('/')
296
305
  @riddl_info.merge!(:match => matching_path)
297
306
  instance_exec(@riddl_info, &@riddl_interfaces[m.interface.name])
298
- else
307
+ else
299
308
  @riddl_log.write "501: not implemented (for remote: add @location in declaration; for local: add to Riddl::Server).\n"
300
309
  @riddl_status = 501 # not implemented?!
301
310
  break
302
- end
311
+ end
303
312
  else
304
313
  run Riddl::Utils::Description::Call, @riddl_exe, @riddl_pinfo, m.interface.top, m.interface.base, m.interface.real_path(@riddl_pinfo)
305
314
  end
@@ -313,7 +322,7 @@ module Riddl
313
322
  @riddl_res['Access-Control-Allow-Origin'] = '*'
314
323
  @riddl_res['Access-Control-Max-Age'] = '0'
315
324
  end
316
- end
325
+ end
317
326
  end #}}}
318
327
 
319
328
  def __xmpp_call(env,raw) #{{{
@@ -343,12 +352,12 @@ module Riddl
343
352
  ).params
344
353
 
345
354
  @riddl_path = '/'
346
- @riddl_info = {
355
+ @riddl_info = {
347
356
  :h => @riddl_headers,
348
357
  :p => @riddl_parameters,
349
- :r => @riddl_pinfo.sub(/\//,'').split('/').map{|e|Protocols::Utils::unescape(e)},
358
+ :r => @riddl_pinfo.sub(/\//,'').split('/').map{|e|Protocols::Utils::unescape(e)},
350
359
  :s => @riddl_matching_path[0].sub(/\//,'').split('/'),
351
- :m => @riddl_method,
360
+ :m => @riddl_method,
352
361
  :env => Hash[@riddl_env.root.attributes.map{|a| [a.qname.name, a.value] }].merge({ 'riddl.transport' => 'xmpp', 'xmpp' => @riddl_res }),
353
362
  :match => []
354
363
  }
@@ -375,7 +384,7 @@ module Riddl
375
384
  def __http_call(env) #{{{
376
385
  @riddl_env = env
377
386
  @riddl_env['rack.logger'] = @riddl_logger if @riddl_logger
378
- @riddl_log = @riddl_logger || @riddl_env['rack.errors']
387
+ @riddl_log = @riddl_logger || @riddl_env['rack.errors']
379
388
  @riddl_res = Rack::Response.new
380
389
  @riddl_status = 404
381
390
 
@@ -402,12 +411,12 @@ module Riddl
402
411
 
403
412
  @riddl_method = @riddl_env['REQUEST_METHOD'].downcase
404
413
  @riddl_path = '/'
405
- @riddl_info = {
414
+ @riddl_info = {
406
415
  :h => @riddl_headers,
407
416
  :p => @riddl_parameters,
408
- :r => @riddl_pinfo.sub(/\//,'').split('/').map{|e|Protocols::Utils::unescape(e)},
417
+ :r => @riddl_pinfo.sub(/\//,'').split('/').map{|e|Protocols::Utils::unescape(e)},
409
418
  :s => @riddl_matching_path[0].sub(/\//,'').split('/'),
410
- :m => @riddl_method,
419
+ :m => @riddl_method,
411
420
  :env => @riddl_env.reject{|k,v| k =~ /^rack\./}.merge({'riddl.transport' => 'http', 'xmpp' => @riddl_opts[:xmpp]}),
412
421
  :match => []
413
422
  }
@@ -430,12 +439,12 @@ module Riddl
430
439
  @riddl_info.merge!(:match => matching_path)
431
440
  instance_exec(@riddl_info, &@riddl_interfaces[@riddl_message.interface.name])
432
441
  end
433
- end
434
- end
435
- throw :async
442
+ end
443
+ end
444
+ throw :async
436
445
  else
437
446
  __call
438
- end
447
+ end
439
448
  else
440
449
  @riddl_log.write "404: this resource for sure does not exist.\n"
441
450
  @riddl_status = 404 # client requests wrong path
@@ -448,8 +457,8 @@ module Riddl
448
457
  end
449
458
  @riddl_res.status = @riddl_status
450
459
  @riddl_res.finish
451
- end #}}}
452
-
460
+ end #}}}
461
+
453
462
  def process_out(pout)# {{{
454
463
  @riddl_process_out = pout
455
464
  end# }}}
@@ -475,7 +484,7 @@ module Riddl
475
484
  if @riddl_paths.empty? # default interface, when a description and "on" syntax in server
476
485
  @riddl_interfaces[nil] = block
477
486
  return
478
- end
487
+ end
479
488
 
480
489
  @riddl_path << (@riddl_path == '/' ? resource : '/' + resource)
481
490
 
@@ -493,19 +502,19 @@ module Riddl
493
502
  def run(what,*args)# {{{
494
503
  return if @riddl_path == ''
495
504
  if what.class == Class && what.superclass == Riddl::WebSocketImplementation
496
- data = Riddl::Protocols::WebSocket::ParserData.new
497
- data.request_path = @riddl_pinfo
505
+ data = Riddl::Protocols::WebSocket::ParserData.new
506
+ data.request_path = @riddl_pinfo
498
507
  data.request_url = @riddl_pinfo + '?' + @riddl_query_string
499
508
  data.query_string = @riddl_query_string
500
- data.http_method = @riddl_env['REQUEST_METHOD']
501
- data.body = @riddl_env['rack.input'].read
509
+ data.http_method = @riddl_env['REQUEST_METHOD']
510
+ data.body = @riddl_env['rack.input'].read
502
511
  data.headers = Hash[
503
512
  @riddl_headers.map { |key, value| [key.downcase.gsub('_','-'), value] }
504
513
  ]
505
514
  w = what.new(@riddl_info.merge!(:a => args, :version => @riddl_env['HTTP_SEC_WEBSOCKET_VERSION'], :match => matching_path))
506
- w.io = Riddl::Protocols::WebSocket.new(w, @riddl_env['thin.connection'])
507
- w.io.dispatch(data)
508
- end
515
+ w.io = Riddl::Protocols::WebSocket.new(w, @riddl_env['thin.connection'])
516
+ w.io.dispatch(data)
517
+ end
509
518
  if what.class == Class && what.superclass == Riddl::Implementation
510
519
  w = what.new(@riddl_info.merge!(:a => args, :match => matching_path))
511
520
  @riddl_exe = Riddl::Server::Execution.new(w.response,w.headers)
@@ -515,7 +524,7 @@ module Riddl
515
524
  @riddl_log.write "500: the return for the #{@riddl_method} is not matching anything in the description.\n"
516
525
  @riddl_status = 500
517
526
  return
518
- end
527
+ end
519
528
  end
520
529
  end
521
530
  end# }}}
@@ -524,7 +533,7 @@ module Riddl
524
533
  if !@riddl_message.nil? && what.class == Hash && what.length == 1
525
534
  met, min = what.first
526
535
  @riddl_path == @riddl_matching_path[0] && min == @riddl_message.in.name && @riddl_method == met.to_s.downcase
527
- else
536
+ else
528
537
  false
529
538
  end
530
539
  end # }}}
@@ -536,7 +545,7 @@ module Riddl
536
545
  def resource(rname=nil); return rname.nil? ? '{}' : rname end
537
546
 
538
547
  def matching_path #{{{
539
- @riddl_path.sub(/\//,'').split('/')
548
+ @riddl_path.sub(/\//,'').split('/')
540
549
  end #}}}
541
550
 
542
551
  def declaration_path #{{{
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "riddl"
3
- s.version = "0.99.199"
3
+ s.version = "0.99.200"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "LGPL-3"
6
6
  s.summary = "restful interface description and declaration language: tools and client/server libs"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riddl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.99.199
4
+ version: 0.99.200
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen eTM Mangler
8
8
  autorequire:
9
9
  bindir: tools
10
10
  cert_chain: []
11
- date: 2015-10-07 00:00:00.000000000 Z
11
+ date: 2015-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xml-smart
@@ -337,7 +337,8 @@ files:
337
337
  - examples/library/rngs/list-of-books.rng
338
338
  - examples/library/rngs/list-of-customers.rng
339
339
  - examples/library/rngs/list-of-loans.rng
340
- - examples/library/server
340
+ - examples/library/server-9292.pid
341
+ - examples/library/server.rb
341
342
  - examples/library/static/info.txt
342
343
  - examples/notifications/implementation/index.html
343
344
  - examples/notifications/implementation/juergen.html