yong-stropheruby 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -2,7 +2,7 @@
2
2
  History.txt
3
3
  Manifest.txt
4
4
  PostInstall.txt
5
- README.rdoc
5
+ README.txt
6
6
  Rakefile
7
7
  examples/xmpp_client.rb
8
8
  ext/md5.c
@@ -8,15 +8,20 @@ This is a fork of flamontagne's stropheruby (http://github.com/flamontagne/strop
8
8
  * (libstrophe) Fixed a timeout issue on Mac OSX: http://groups.google.com/group/strophe-dev/browse_thread/thread/ef4cb19785020fb6
9
9
  * (libstrophe) Fixed basic auth: http://groups.google.com/group/strophe-dev/browse_thread/thread/b770f72c83d1a0b9
10
10
  * (libstrophe) Changed xmpp_run_once's return code so that the application can tell if an error or timeout occurs
11
+ * (libstrophe) Better error reporting for login failure
11
12
  * (stropheruby) Added send_raw_string method
12
13
  * (stropheruby) Detect login failure
13
14
  * (stropheruby) Fix resource leak
15
+ * (stropheruby) Added wrapper class for xmpp_stream_error_t (StropheRuby::StreamError)
14
16
 
15
17
  == INSTALLATION
16
18
 
17
19
  sudo gem sources -a http://gems.github.com
18
20
  sudo gem install yong-stropheruby
19
21
 
22
+ For Rails app, add this line in your config/environment.rb:
23
+ config.gem "yong-stropheruby", :source => "http://gems.github.com", :lib => "strophe_ruby"
24
+
20
25
  == EXAMPLE
21
26
 
22
27
  See example.rb
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'hoe'
3
3
 
4
4
  EXT = "ext/strophe_ruby.#{Hoe::DLEXT}"
5
5
 
6
- Hoe.new('stropheruby', '0.1.0') do |p|
6
+ Hoe.new('stropheruby', '0.1.1') do |p|
7
7
  p.developer('François Lamontagne', 'flamontagne@gmail.com')
8
8
  p.summary = 'strophe_ruby'
9
9
 
@@ -18,22 +18,21 @@ class XmppClient
18
18
 
19
19
  private
20
20
 
21
- def new_connection(jid, password)
21
+ def new_connection(jid, password, login_can_not_fail = true)
22
22
  lib = StropheRuby::EventLoop.prepare
23
23
  @ctx = StropheRuby::Context.new(StropheRuby::Logging::DEBUG)
24
24
  @connection = StropheRuby::Connection.new(@ctx)
25
25
  @connection.jid = jid
26
26
  @connection.password = password
27
- connected = false
28
- @connection.connect do |status|
29
- if !connected
30
- connected = true
31
- if status != StropheRuby::ConnectionEvents::CONNECT
27
+ logged_in = false
28
+ @connection.connect do |status, error, stream_error|
29
+ if !logged_in
30
+ if login_can_not_fail && status != StropheRuby::ConnectionEvents::CONNECT
32
31
  #do somthing after login fails
33
- raise 'failed to login'
32
+ raise "failed to login: #{error} #{stream_error}"
34
33
  else
35
- #do something after login
36
34
  yield if block_given?
35
+ logged_in = true
37
36
  end
38
37
  end
39
38
  end
data/ext/event.c CHANGED
@@ -231,7 +231,10 @@ int xmpp_run_once(xmpp_ctx_t *ctx, const unsigned long timeout)
231
231
  }
232
232
 
233
233
  /* no events happened */
234
- if (ret == 0) return 1;
234
+ if (ret == 0) {
235
+ conn->error = ETIMEDOUT;
236
+ return 1;
237
+ }
235
238
 
236
239
  /* process events */
237
240
  connitem = ctx->connlist;
@@ -244,7 +247,8 @@ int xmpp_run_once(xmpp_ctx_t *ctx, const unsigned long timeout)
244
247
  /* connection complete */
245
248
 
246
249
  /* check for error */
247
- if (sock_connect_error(conn->sock) != 0) {
250
+ conn->error = sock_connect_error(conn->sock);
251
+ if (conn->error != 0) {
248
252
  /* connection failed */
249
253
  xmpp_debug(ctx, "xmpp", "connection failed");
250
254
  conn_disconnect(conn);
data/ext/extconf.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'mkmf'
2
2
  have_library("expat")
3
3
  have_library("resolv")
4
- $CFLAGS = "#{ENV['CFLAGS']} -Wall -O3 "
4
+ $CFLAGS = "#{ENV['CFLAGS']} -Wall -O3 -g"
5
5
  if CONFIG["MAJOR"].to_i >= 1 && CONFIG["MINOR"].to_i >= 8
6
6
  $CFLAGS << " -DHAVE_DEFINE_ALLOC_FUNCTION"
7
7
  end
data/ext/strophe_ruby.c CHANGED
@@ -12,6 +12,7 @@ VALUE cStreamError;
12
12
  VALUE cEventLoop;
13
13
  VALUE client_conn_handler;
14
14
  VALUE cStanza;
15
+ VALUE cStreamError;
15
16
 
16
17
  /* release the stanza. Called automatically by the GC */
17
18
  static void t_xmpp_stanza_release(void *stanza) {
@@ -186,8 +187,34 @@ static void _conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t stat
186
187
  const int error, xmpp_stream_error_t * const stream_error,
187
188
  void * const userdata) {
188
189
  //yield code block for connection
189
- if (RTEST(client_conn_handler))
190
- rb_funcall(client_conn_handler, rb_intern("call"), 1, INT2FIX(status));
190
+ if (RTEST(client_conn_handler)) {
191
+ VALUE args[3];
192
+ args[0] = INT2FIX(status);
193
+ args[1] = INT2FIX(error);
194
+ args[2] = (NULL == stream_error) ? Qnil : Data_Wrap_Struct(cStreamError, 0, NULL, stream_error);
195
+ rb_funcall2(client_conn_handler, rb_intern("call"), 3, args);
196
+ }
197
+ }
198
+
199
+ /*Get the type of a StreamError. */
200
+ static VALUE t_xmpp_stream_error_get_type(VALUE self) {
201
+ xmpp_stream_error_t *stream_error;
202
+ Data_Get_Struct(self, xmpp_stream_error_t, stream_error);
203
+ return INT2FIX(stream_error->type);
204
+ }
205
+
206
+ /*Get the text of a StreamError. */
207
+ static VALUE t_xmpp_stream_error_get_text(VALUE self) {
208
+ xmpp_stream_error_t *stream_error;
209
+ Data_Get_Struct(self, xmpp_stream_error_t, stream_error);
210
+ return (NULL != stream_error->text) ? rb_str_new2(stream_error->text) : Qnil;
211
+ }
212
+
213
+ /*Get the stanza of a StreamError. */
214
+ static VALUE t_xmpp_stream_error_get_stanza(VALUE self) {
215
+ xmpp_stream_error_t *stream_error;
216
+ Data_Get_Struct(self, xmpp_stream_error_t, stream_error);
217
+ return (NULL != stream_error->stanza) ? Data_Wrap_Struct(cStanza, 0, NULL, stream_error->stanza) : Qnil;
191
218
  }
192
219
 
193
220
  /*this is called in a loop (rb_iterate). We invoke the block passed by the user*/
@@ -506,6 +533,7 @@ static VALUE t_xmpp_stanza_set_ns(VALUE self, VALUE rb_ns) {
506
533
  return Qtrue;
507
534
  }
508
535
 
536
+ /*Convert Stanza to String */
509
537
  static VALUE t_xmpp_stanza_to_text(VALUE self) {
510
538
  xmpp_stanza_t *stanza;
511
539
  Data_Get_Struct(self, xmpp_stanza_t, stanza);
@@ -661,6 +689,12 @@ void Init_strophe_ruby() {
661
689
  rb_define_method(cConnection, "add_handler", t_xmpp_handler_add, 1);
662
690
  rb_define_method(cConnection, "add_id_handler", t_xmpp_id_handler_add, 3);
663
691
 
692
+ /*StreamError*/
693
+ cStreamError = rb_define_class_under(mStropheRuby, "StreamError", rb_cObject);
694
+ rb_define_method(cStreamError, "error_type", t_xmpp_stream_error_get_type, 0);
695
+ rb_define_method(cStreamError, "text", t_xmpp_stream_error_get_text, 0);
696
+ rb_define_method(cStreamError, "stanza", t_xmpp_stream_error_get_stanza, 0);
697
+
664
698
  /*Stanza*/
665
699
  cStanza = rb_define_class_under(mStropheRuby, "Stanza", rb_cObject);
666
700
  rb_define_singleton_method(cStanza, "new", t_xmpp_stanza_new, 0);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yong-stropheruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Fran\xC3\xA7ois Lamontagne"
@@ -38,7 +38,7 @@ files:
38
38
  - History.txt
39
39
  - Manifest.txt
40
40
  - PostInstall.txt
41
- - README.rdoc
41
+ - README.txt
42
42
  - Rakefile
43
43
  - ext/md5.c
44
44
  - ext/parser.c