blather 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/push_parser.c +4 -32
- data/lib/blather/errors.rb +14 -3
- data/lib/blather/stream.rb +3 -0
- data/lib/blather/stream/parser.rb +8 -4
- data/spec/blather/stream/client_spec.rb +33 -1
- metadata +2 -2
data/ext/push_parser.c
CHANGED
@@ -80,24 +80,6 @@ push_parser_receive (
|
|
80
80
|
/*********
|
81
81
|
CALLBACKS
|
82
82
|
**********/
|
83
|
-
static void
|
84
|
-
push_parser_start_document_callback (
|
85
|
-
void *ctx)
|
86
|
-
{
|
87
|
-
VALUE handler = (VALUE) ctx;
|
88
|
-
if (handler != Qnil)
|
89
|
-
rb_funcall (handler, rb_intern("on_start_document"), 0);
|
90
|
-
}
|
91
|
-
|
92
|
-
static void
|
93
|
-
push_parser_end_document_callback (
|
94
|
-
void *ctx)
|
95
|
-
{
|
96
|
-
VALUE handler = (VALUE) ctx;
|
97
|
-
if (handler != Qnil)
|
98
|
-
rb_funcall (handler, rb_intern("on_end_document"), 0);
|
99
|
-
}
|
100
|
-
|
101
83
|
static void
|
102
84
|
push_parser_start_element_ns_callback (
|
103
85
|
void * ctx,
|
@@ -177,16 +159,6 @@ push_parser_characters_callback (
|
|
177
159
|
rb_funcall (handler, rb_intern("on_characters"), 1, rb_str_new(chars, len));
|
178
160
|
}
|
179
161
|
|
180
|
-
static void
|
181
|
-
push_parser_structured_error_callback (
|
182
|
-
void *ctx,
|
183
|
-
xmlErrorPtr error)
|
184
|
-
{
|
185
|
-
VALUE handler = (VALUE) ctx;
|
186
|
-
if (handler != Qnil)
|
187
|
-
rb_funcall (handler, rb_intern("on_error"), 1, rb_str_new2((const char*)error->message));
|
188
|
-
}
|
189
|
-
|
190
162
|
xmlSAXHandler saxHandler = {
|
191
163
|
0, //internalSubset
|
192
164
|
0, //isStandalone
|
@@ -200,8 +172,8 @@ xmlSAXHandler saxHandler = {
|
|
200
172
|
0, //elementDecl
|
201
173
|
0, //unparsedEntityDecl
|
202
174
|
0, //setDocumentLocator
|
203
|
-
(
|
204
|
-
(
|
175
|
+
0, //(startDocument)
|
176
|
+
0, //(endDocument)
|
205
177
|
0, //startElement
|
206
178
|
0, //endElement
|
207
179
|
0, //reference
|
@@ -210,7 +182,7 @@ xmlSAXHandler saxHandler = {
|
|
210
182
|
0, //processingInstruction
|
211
183
|
0, //comment
|
212
184
|
0, //warning
|
213
|
-
|
185
|
+
0, //error
|
214
186
|
0, //fatalError
|
215
187
|
0, //getParameterEntity
|
216
188
|
0, //cdataBlock
|
@@ -219,7 +191,7 @@ xmlSAXHandler saxHandler = {
|
|
219
191
|
0, //_private
|
220
192
|
(startElementNsSAX2Func) push_parser_start_element_ns_callback,
|
221
193
|
(endElementNsSAX2Func) push_parser_end_element_ns_callback,
|
222
|
-
|
194
|
+
0 // LibXML handles this globally
|
223
195
|
};
|
224
196
|
|
225
197
|
void
|
data/lib/blather/errors.rb
CHANGED
@@ -40,14 +40,25 @@ module Blather
|
|
40
40
|
register :tls_failure
|
41
41
|
end
|
42
42
|
|
43
|
+
class ParseWarning < BlatherError
|
44
|
+
register :parse_warning
|
45
|
+
attr_reader :libxml_error, :message
|
46
|
+
|
47
|
+
def initialize(err)
|
48
|
+
@libxml_error = err
|
49
|
+
@message = err.to_s
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
43
53
|
##
|
44
54
|
# Something bad happened while parsing the incoming stream
|
45
55
|
class ParseError < BlatherError
|
46
56
|
register :parse_error
|
47
|
-
attr_reader :message
|
57
|
+
attr_reader :libxml_error, :message
|
48
58
|
|
49
|
-
def initialize(
|
50
|
-
@
|
59
|
+
def initialize(err)
|
60
|
+
@libxml_error = err
|
61
|
+
@message = err.to_s
|
51
62
|
end
|
52
63
|
end
|
53
64
|
end
|
data/lib/blather/stream.rb
CHANGED
@@ -77,8 +77,11 @@ module Blather
|
|
77
77
|
LOG.debug "<< #{data}"
|
78
78
|
@parser.receive_data data
|
79
79
|
|
80
|
+
rescue ParseWarning => e
|
81
|
+
@client.receive_data e
|
80
82
|
rescue ParseError => e
|
81
83
|
@error = e
|
84
|
+
send "<stream:error><xml-not-well-formed xmlns='urn:ietf:params:xml:ns:xmpp-streams'/></stream:error>"
|
82
85
|
stop
|
83
86
|
end
|
84
87
|
|
@@ -9,8 +9,6 @@ class Stream # :nodoc:
|
|
9
9
|
def self.debug; @@debug; end
|
10
10
|
def self.debug=(debug); @@debug = debug; end
|
11
11
|
|
12
|
-
include XML::SaxParser::Callbacks
|
13
|
-
|
14
12
|
def initialize(receiver)
|
15
13
|
@receiver = receiver
|
16
14
|
@current = nil
|
@@ -68,8 +66,14 @@ class Stream # :nodoc:
|
|
68
66
|
end
|
69
67
|
end
|
70
68
|
|
71
|
-
def on_error(
|
72
|
-
|
69
|
+
def on_error(err)
|
70
|
+
err_klass = case err.level
|
71
|
+
when XML::Error::WARNING
|
72
|
+
ParseWarning
|
73
|
+
when XML::Error::ERROR, XML::Error::FATAL
|
74
|
+
ParseError
|
75
|
+
end
|
76
|
+
raise err_klass.new(err)
|
73
77
|
end
|
74
78
|
end #Parser
|
75
79
|
|
@@ -783,6 +783,38 @@ describe 'Blather::Stream::Client' do
|
|
783
783
|
end
|
784
784
|
end
|
785
785
|
|
786
|
+
it 'sends the client a warning on parse warning' do
|
787
|
+
@client = mock()
|
788
|
+
@client.expects(:receive_data).with do |v|
|
789
|
+
EM.stop
|
790
|
+
v.must_be_kind_of ParseWarning
|
791
|
+
v.message.must_match(/vcard\-temp/)
|
792
|
+
end
|
793
|
+
state = nil
|
794
|
+
mocked_server(2) do |val, server|
|
795
|
+
case state
|
796
|
+
when nil
|
797
|
+
state = :started
|
798
|
+
server.send_data "<?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"
|
799
|
+
server.send_data "<stream:features><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind' /></stream:features>"
|
800
|
+
val.must_match(/stream:stream/)
|
801
|
+
|
802
|
+
when :started
|
803
|
+
server.send_data <<-XML
|
804
|
+
<iq xmlns="jabber:client" to="utterance.localhost" type="get" id="2590">
|
805
|
+
<vCard xmlns="vcard-temp" />
|
806
|
+
</iq>
|
807
|
+
XML
|
808
|
+
true
|
809
|
+
|
810
|
+
else
|
811
|
+
EM.stop
|
812
|
+
false
|
813
|
+
|
814
|
+
end
|
815
|
+
end
|
816
|
+
end
|
817
|
+
|
786
818
|
it 'sends client an error on parse error' do
|
787
819
|
@client = mock()
|
788
820
|
@client.expects(:receive_data).with do |v|
|
@@ -804,7 +836,7 @@ describe 'Blather::Stream::Client' do
|
|
804
836
|
|
805
837
|
when :parse_error
|
806
838
|
EM.stop
|
807
|
-
val.must_equal "
|
839
|
+
val.must_equal "<stream:error><xml-not-well-formed xmlns='urn:ietf:params:xml:ns:xmpp-streams'/></stream:error></stream:stream>"
|
808
840
|
|
809
841
|
else
|
810
842
|
EM.stop
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blather
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Smick
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-22 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|