riddl 1.0.21 → 1.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28692624877cae67118d788e232ffad0707e98f685257ae38661a50235cc2e19
4
- data.tar.gz: 773269607873f5d8153cb92accdb3bbcd058109c3ea00f1704807d5b5496d8af
3
+ metadata.gz: bf7d97b1b574404dc2f76129b0ea87d9c7b222402973e8ba4d77ca635b329c62
4
+ data.tar.gz: 1275acd2daa1d92e06b8d5e7243f56e803707c9f8b4d29cbd62237cbe6fbfcb4
5
5
  SHA512:
6
- metadata.gz: d4ac230888df9ae43b840f407764ee293d6d1ddfe9c242ea9fa5e850c8b455a1722a9a1da6ba675710b310e9fa10804d67b037424799e671b4ef6b2cd299bd93
7
- data.tar.gz: 5bb88e50380fcc18206f5d0c021cbeac4c7c473e97e94c221af6880baa9aac20b8f39057e042127fd2cce4e8157710eadbf630174f8a3caa426d7c1f5f083c31
6
+ metadata.gz: f2abf3efdbd30009c447f7a8883b8974d6dd1375ac2b999da997f72d5b108a783fefd931f140a3b095d82da5e426a3a514a14beb2d6a93fbe841e8df6a45257d
7
+ data.tar.gz: 20d181c772539e9b15a100b914c6d567e06c1f38493544d983f8669cba50699ef30e11da0e3ac71d6255d121736fc8224ebc85d1f1e7922f4a87d21845863dcc
@@ -1,6 +1,19 @@
1
1
  module Riddl
2
2
  module Handlers
3
3
  class RelaxNG < Riddl::Handlers::Implementation
4
+ MAX_SCHEMAS = 500 # clients may see any number of descriptions, so don't grow forever
5
+ @schemas = {}
6
+
7
+ def self::schema(hinfo)
8
+ @schemas[hinfo] || begin
9
+ rng = XML::Smart.string("<payload>" + hinfo + "</payload>")
10
+ rng.register_namespace 'r', 'http://relaxng.org/ns/structure/1.0'
11
+ doc = rng.find("//r:grammar|//r:element").first.to_doc
12
+ @schemas.clear if @schemas.length >= MAX_SCHEMAS
13
+ @schemas[hinfo] = Nokogiri::XML::RelaxNG.from_document(doc.instance_variable_get(:@dom))
14
+ end
15
+ end
16
+
4
17
  def self::handle(what,hinfo)
5
18
  begin
6
19
  w = if what.class == Riddl::Parameter::Tempfile || what.class == File
@@ -8,9 +21,7 @@ module Riddl
8
21
  else
9
22
  XML::Smart.string(what)
10
23
  end
11
- rng = XML::Smart.string("<payload>" + hinfo + "</payload>")
12
- rng.register_namespace 'r', 'http://relaxng.org/ns/structure/1.0'
13
- w.validate_against(rng.find("//r:grammar|//r:element").first.to_doc) rescue false
24
+ schema(hinfo).valid?(w.instance_variable_get(:@dom)) rescue false
14
25
  rescue
15
26
  puts 'The XML sent to the server is b0rked/>'
16
27
  false
@@ -1,13 +1,29 @@
1
1
  module Riddl
2
2
  module Handlers
3
3
  class XMLSchema < Riddl::Handlers::Implementation
4
+ MAX_SCHEMAS = 500 # clients may see any number of descriptions, so don't grow forever
5
+ XSD_TO_RNG = File.join(Gem.loaded_specs['xml-smart'].full_gem_path,'lib','xml','XSDtoRNG.xsl')
6
+ @schemas = {}
7
+
8
+ def self::schema(hinfo)
9
+ @schemas[hinfo] || begin
10
+ xsd = XML::Smart.string(hinfo)
11
+ doc = xsd.instance_variable_get(:@dom)
12
+ unless xsd.root.namespaces.has_ns?("http://relaxng.org/ns/structure/1.0")
13
+ doc = Nokogiri::XSLT.parse(File.read(XSD_TO_RNG)).transform(doc)
14
+ end
15
+ @schemas.clear if @schemas.length >= MAX_SCHEMAS
16
+ @schemas[hinfo] = Nokogiri::XML::RelaxNG.from_document(doc)
17
+ end
18
+ end
19
+
4
20
  def self::handle(what,hinfo)
5
21
  w = if what.class == Riddl::Parameter::Tempfile || what.class == File
6
22
  XML::Smart.open_unprotected(what)
7
23
  else
8
24
  XML::Smart.string(what)
9
25
  end
10
- w.validate_against(XML::Smart.string(hinfo)) rescue false
26
+ schema(hinfo).valid?(w.instance_variable_get(:@dom)) rescue false
11
27
  end
12
28
  end
13
29
  end
@@ -203,10 +203,8 @@ module Riddl
203
203
  @riddl_message = @riddl.io_messages(@riddl_matching_path[0],@riddl_method,@riddl_parameters,@riddl_headers)
204
204
  if @riddl_message.nil?
205
205
  if @riddl_info[:env].has_key?('HTTP_ORIGIN') && @riddl_cross_site_xhr && @riddl_method == 'options'
206
- @riddl_res['Access-Control-Allow-Origin'] = '*'
207
206
  @riddl_res['Access-Control-Allow-Methods'] = 'GET, POST, PUT, PATCH, DELETE, OPTIONS'
208
207
  @riddl_res['Access-Control-Allow-Headers'] = @riddl_info[:env]['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'] if @riddl_info[:env]['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']
209
- @riddl_res['Access-Control-Max-Age'] = '0'
210
208
  @riddl_res['Content-Length'] = '0'
211
209
  @riddl_status = 200
212
210
  else
@@ -251,10 +249,6 @@ module Riddl
251
249
  @riddl_message = mess
252
250
  end
253
251
  end
254
- if @riddl_info[:env].has_key?('HTTP_ORIGIN') && @riddl_cross_site_xhr
255
- @riddl_res['Access-Control-Allow-Origin'] = '*'
256
- @riddl_res['Access-Control-Max-Age'] = '0'
257
- end
258
252
  end
259
253
  end #}}}
260
254
 
@@ -263,6 +257,10 @@ module Riddl
263
257
  @riddl_env['rack.logger'] = @riddl_logger if @riddl_logger
264
258
  @riddl_log = @riddl_logger || @riddl_env['rack.errors']
265
259
  @riddl_res = Rack::Response.new
260
+ if @riddl_env.has_key?('HTTP_ORIGIN') && @riddl_cross_site_xhr
261
+ @riddl_res['Access-Control-Allow-Origin'] = '*'
262
+ @riddl_res['Access-Control-Max-Age'] = '0'
263
+ end
266
264
  @riddl_status = 404
267
265
  @riddl_async_response = nil
268
266
 
@@ -69,6 +69,10 @@ module Riddl
69
69
  end
70
70
  def initialize_copy(o)
71
71
  @content = @content.dup
72
+ @schemas = nil
73
+ end
74
+ def schemas # compiled schemas for simple parameters and headers, filled by MessageParser
75
+ @schemas ||= {}
72
76
  end
73
77
  def transform(trans)
74
78
  ret = self.dup
@@ -30,6 +30,7 @@ module Riddl
30
30
 
31
31
  # do it
32
32
  m = what.content.root
33
+ @schemas = what.schemas
33
34
 
34
35
  m.find("des:header").each do |h|
35
36
  return false unless header h
@@ -192,29 +193,39 @@ module Riddl
192
193
  if a.attributes['fixed']
193
194
  a.attributes['fixed'] == b
194
195
  else
195
- value = XML::Smart::string("<check/>")
196
- value.root.text = b
197
- if a.find('des:choice').length > 0
198
- type = XML::Smart::string(CHECK_CHOICE)
199
- data = type.root
200
- else
201
- type = XML::Smart::string(CHECK_DATA)
202
- data = type.root.children[0]
203
- data.attributes['type'] = a.attributes['type']
204
- end
205
- a.children.each do |e|
206
- unless e.class == XML::Smart::Dom::Text
207
- e = e.to_doc.root
208
- e.namespaces[nil] = 'http://relaxng.org/ns/structure/1.0'
209
- data.add e
210
- end
211
- end
212
- value.validate_against type
196
+ value = Nokogiri::XML::Document.new
197
+ value.root = value.create_element('check')
198
+ value.root.content = b.to_s
199
+ # the description does not change, so each schema is only compiled once
200
+ schema = (@schemas[a.unique_id] ||= compile_simple(a))
201
+ schema.valid?(value)
213
202
  end
214
203
  #}}}
215
204
  end
216
205
  private :match_simple
217
206
 
207
+ def compile_simple(a)
208
+ #{{{
209
+ if a.find('des:choice').length > 0
210
+ type = XML::Smart::string(CHECK_CHOICE)
211
+ data = type.root
212
+ else
213
+ type = XML::Smart::string(CHECK_DATA)
214
+ data = type.root.children[0]
215
+ data.attributes['type'] = a.attributes['type']
216
+ end
217
+ a.children.each do |e|
218
+ unless e.class == XML::Smart::Dom::Text
219
+ e = e.to_doc.root
220
+ e.namespaces[nil] = 'http://relaxng.org/ns/structure/1.0'
221
+ data.add e
222
+ end
223
+ end
224
+ Nokogiri::XML::RelaxNG.from_document(type.instance_variable_get(:@dom))
225
+ #}}}
226
+ end
227
+ private :compile_simple
228
+
218
229
  def match_mimetype(a,b)
219
230
  if (a.attributes['mimetype'] == '*' || b.mimetype == a.attributes['mimetype'])
220
231
  true
data/riddl.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "riddl"
3
- s.version = "1.0.21"
3
+ s.version = "1.0.22"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.license = "LGPL-3.0-or-later"
6
6
  s.summary = "Restful Interface Description and Declaration Language: tools and client/server libs"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riddl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.21
4
+ version: 1.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juergen 'eTM' Mangler
@@ -533,7 +533,7 @@ homepage: http://github.com/etm/riddl/
533
533
  licenses:
534
534
  - LGPL-3.0-or-later
535
535
  metadata:
536
- documentation_uri: https://gemdocs.org/gems/riddl/1.0.21/
536
+ documentation_uri: https://gemdocs.org/gems/riddl/1.0.22/
537
537
  rdoc_options: []
538
538
  require_paths:
539
539
  - lib/ruby