yong-purple_ruby 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/ext/purple_ruby.c +61 -14
  3. metadata +1 -1
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'hoe'
3
3
 
4
4
  EXT = "ext/ruburple_ext.#{Hoe::DLEXT}"
5
5
 
6
- Hoe.new('purple_ruby', '0.2.0') do |p|
6
+ Hoe.new('purple_ruby', '0.2.1') do |p|
7
7
  p.author = 'yong'
8
8
  p.email = 'yong@intridea.com'
9
9
  p.url = 'http://www.intridea.com'
data/ext/purple_ruby.c CHANGED
@@ -64,7 +64,7 @@ static guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInput
64
64
  PurpleGLibIOClosure *closure = g_new0(PurpleGLibIOClosure, 1);
65
65
  GIOChannel *channel;
66
66
  GIOCondition cond = 0;
67
-
67
+
68
68
  closure->function = function;
69
69
  closure->data = data;
70
70
 
@@ -109,7 +109,8 @@ static VALUE signed_on_handler = Qnil;
109
109
  static VALUE connection_error_handler = Qnil;
110
110
  static VALUE notify_message_handler = Qnil;
111
111
  static VALUE request_handler = Qnil;
112
- static GHashTable* hash_table = NULL;
112
+ static GHashTable* data_hash_table = NULL;
113
+ static GHashTable* fd_hash_table = NULL;
113
114
  static ID CALL;
114
115
 
115
116
  static void connection_error(PurpleConnection* connection,
@@ -229,7 +230,7 @@ static void* request_action(const char *title, const char *primary, const char *
229
230
  VALUE v = rb_funcall2(request_handler, CALL, 4, args);
230
231
 
231
232
  if (v != Qnil && v != Qfalse) {
232
- const char *text = va_arg(actions, const char *);
233
+ /*const char *text =*/ va_arg(actions, const char *);
233
234
  GCallback ok_cb = va_arg(actions, GCallback);
234
235
  ((PurpleRequestActionCb)ok_cb)(user_data, default_action);
235
236
  }
@@ -303,7 +304,8 @@ static VALUE init(VALUE self, VALUE debug)
303
304
  signal(SIGPIPE, SIG_IGN);
304
305
  signal(SIGINT, sighandler);
305
306
 
306
- hash_table = g_hash_table_new(NULL, NULL);
307
+ data_hash_table = g_hash_table_new(NULL, NULL);
308
+ fd_hash_table = g_hash_table_new(NULL, NULL);
307
309
 
308
310
  purple_debug_set_enabled((debug == Qnil || debug == Qfalse) ? FALSE : TRUE);
309
311
  purple_core_set_ui_ops(&core_uiops);
@@ -382,22 +384,31 @@ static void _read_socket_handler(gpointer data, int socket, PurpleInputCondition
382
384
  if (i > 0) {
383
385
  purple_debug_info("purple_ruby", "recv %d: %d\n", socket, i);
384
386
 
385
- VALUE str = (VALUE)g_hash_table_lookup(hash_table, (gpointer)socket);
387
+ gpointer str = g_hash_table_lookup(data_hash_table, (gpointer)socket);
386
388
  if (NULL == str) rb_raise(rb_eRuntimeError, "can not find socket: %d", socket);
387
- rb_str_append(str, rb_str_new2(message));
389
+ rb_str_append((VALUE)str, rb_str_new2(message));
388
390
  } else {
389
391
  purple_debug_info("purple_ruby", "close connection %d: %d %d\n", socket, i, errno);
390
392
 
391
- close(socket);
392
- purple_input_remove(socket);
393
+ gpointer str = g_hash_table_lookup(data_hash_table, (gpointer)socket);
394
+ if (NULL == str) {
395
+ purple_debug_warning("purple_ruby", "can not find socket in data_hash_table %d\n", socket);
396
+ return;
397
+ }
393
398
 
394
- VALUE str = (VALUE)g_hash_table_lookup(hash_table, (gpointer)socket);
395
- if (NULL == str) return;
399
+ gpointer purple_fd = g_hash_table_lookup(fd_hash_table, (gpointer)socket);
400
+ if (NULL == purple_fd) {
401
+ purple_debug_warning("purple_ruby", "can not find socket in fd_hash_table %d\n", socket);
402
+ return;
403
+ }
396
404
 
397
- g_hash_table_remove(hash_table, (gpointer)socket);
405
+ g_hash_table_remove(fd_hash_table, (gpointer)socket);
406
+ g_hash_table_remove(data_hash_table, (gpointer)socket);
407
+ purple_input_remove((guint)purple_fd);
408
+ close(socket);
398
409
 
399
410
  VALUE *args = g_new(VALUE, 1);
400
- args[0] = str;
411
+ args[0] = (VALUE)str;
401
412
  rb_funcall2((VALUE)data, CALL, 1, args);
402
413
  g_free(args);
403
414
  }
@@ -425,9 +436,10 @@ static void _accept_socket_handler(gpointer data, int server_socket, PurpleInput
425
436
 
426
437
  purple_debug_info("purple_ruby", "new connection: %d\n", client_socket);
427
438
 
428
- g_hash_table_insert(hash_table, (gpointer)client_socket, (gpointer)rb_str_new2(""));
439
+ guint purple_fd = purple_input_add(client_socket, PURPLE_INPUT_READ, _read_socket_handler, data);
429
440
 
430
- purple_input_add(client_socket, PURPLE_INPUT_READ, _read_socket_handler, data);
441
+ g_hash_table_insert(data_hash_table, (gpointer)client_socket, (gpointer)rb_str_new2(""));
442
+ g_hash_table_insert(fd_hash_table, (gpointer)client_socket, (gpointer)purple_fd);
431
443
  }
432
444
 
433
445
  static VALUE watch_incoming_ipc(VALUE self, VALUE serverip, VALUE port)
@@ -514,6 +526,37 @@ static VALUE username(VALUE self)
514
526
  return rb_str_new2(purple_account_get_username(account));
515
527
  }
516
528
 
529
+ static VALUE protocol_id(VALUE self)
530
+ {
531
+ PurpleAccount *account;
532
+ Data_Get_Struct(self, PurpleAccount, account);
533
+ return rb_str_new2(purple_account_get_protocol_id(account));
534
+ }
535
+
536
+ static VALUE protocol_name(VALUE self)
537
+ {
538
+ PurpleAccount *account;
539
+ Data_Get_Struct(self, PurpleAccount, account);
540
+ return rb_str_new2(purple_account_get_protocol_name(account));
541
+ }
542
+
543
+ static VALUE get_bool_setting(VALUE self, VALUE name, VALUE default_value)
544
+ {
545
+ PurpleAccount *account;
546
+ Data_Get_Struct(self, PurpleAccount, account);
547
+ gboolean value = purple_account_get_bool(account, RSTRING(name)->ptr,
548
+ (default_value == Qfalse || default_value == Qnil) ? FALSE : TRUE);
549
+ return (TRUE == value) ? Qtrue : Qfalse;
550
+ }
551
+
552
+ static VALUE get_string_setting(VALUE self, VALUE name, VALUE default_value)
553
+ {
554
+ PurpleAccount *account;
555
+ Data_Get_Struct(self, PurpleAccount, account);
556
+ const char* value = purple_account_get_string(account, RSTRING(name)->ptr, RSTRING(default_value)->ptr);
557
+ return (NULL == value) ? Qnil : rb_str_new2(value);
558
+ }
559
+
517
560
  static VALUE list_protocols(VALUE self)
518
561
  {
519
562
  VALUE array = rb_ary_new();
@@ -611,6 +654,10 @@ void Init_purple_ruby()
611
654
  cAccount = rb_define_class_under(cPurpleRuby, "Account", rb_cObject);
612
655
  rb_define_method(cAccount, "send_im", send_im, 2);
613
656
  rb_define_method(cAccount, "username", username, 0);
657
+ rb_define_method(cAccount, "protocol_id", protocol_id, 0);
658
+ rb_define_method(cAccount, "protocol_name", protocol_name, 0);
659
+ rb_define_method(cAccount, "get_bool_setting", get_bool_setting, 2);
660
+ rb_define_method(cAccount, "get_string_setting", get_string_setting, 2);
614
661
  rb_define_method(cAccount, "add_buddy", add_buddy, 1);
615
662
  rb_define_method(cAccount, "remove_buddy", remove_buddy, 1);
616
663
  rb_define_method(cAccount, "has_buddy?", has_buddy, 1);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yong-purple_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yong