ruburple 0.0.2 → 0.0.3

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.
Files changed (3) hide show
  1. data/README +4 -6
  2. data/ext/ruburple_ext.c +39 -18
  3. metadata +1 -1
data/README CHANGED
@@ -18,17 +18,15 @@ Then, to build, I did:
18
18
 
19
19
  This is mainly because I dont need any of the disabled features to get ruburple running, and the configure script had big trouble finding the gnutls headers and libs on its own.
20
20
 
21
- == Usage example:
21
+ == Usage example (using (almost?) all methods defined in the ruburple gem):
22
22
 
23
23
  require 'ruburple'
24
24
  Ruburple::init
25
25
  Ruburple::subscribe(:received_im_msg, (Proc.new do |a,b,c,d,e| puts "rcv im: #{a}, #{b}, #{c}, #{d}, #{e}" end))
26
26
  Ruburple::subscribe(:signed_on, (Proc.new do |a| puts "signed on: #{a}" end))
27
27
  p = Ruburple::protocols[5]
28
- a = p.get_account("some@msn.account")
29
- a.password = "some_msn_password"
28
+ puts "gonna connect to #{p.id}, #{p.name}, #{p.version}, #{p.summary}, #{p.description}, #{p.author}, #{p.homepage}"
29
+ a = p.get_account("some@msn.account", "some_msn_password")
30
30
  a.connect
31
31
  a.connection.send_im("some_other@msn_account", "some message")
32
-
33
-
34
-
32
+ a.connection.close
data/ext/ruburple_ext.c CHANGED
@@ -195,18 +195,16 @@ typedef struct
195
195
  gpointer result;
196
196
  GCond *done;
197
197
  GMutex *lock;
198
- gboolean do_free;
199
198
  gboolean run;
200
199
  } RuburpleSingleShotCall;
201
200
 
202
201
  /* Creator of single shot calls */
203
202
  static RuburpleSingleShotCall*
204
- ruburple_single_shot_call_new(RuburpleCallFunc function, gpointer data, gboolean do_free)
203
+ ruburple_single_shot_call_new(RuburpleCallFunc function, gpointer data)
205
204
  {
206
205
  RuburpleSingleShotCall *return_value = g_new(RuburpleSingleShotCall, 1);
207
206
  return_value->function = function;
208
207
  return_value->data = data;
209
- return_value->do_free = do_free;
210
208
  return_value->run = FALSE;
211
209
  return_value->done = g_cond_new();
212
210
  return_value->lock = g_mutex_new();
@@ -236,18 +234,14 @@ call_single_shot(gpointer data)
236
234
 
237
235
  g_mutex_unlock(call->lock);
238
236
 
239
- if (call->do_free) {
240
- ruburple_single_shot_call_free(call);
241
- }
242
-
243
237
  return FALSE;
244
238
  }
245
239
 
246
240
  /* Ask glib to run something once */
247
241
  static RuburpleSingleShotCall*
248
- add_single_shot(RuburpleCallFunc function, gpointer data, gboolean do_free)
242
+ add_single_shot(RuburpleCallFunc function, gpointer data)
249
243
  {
250
- RuburpleSingleShotCall *call = ruburple_single_shot_call_new(function, data, do_free);
244
+ RuburpleSingleShotCall *call = ruburple_single_shot_call_new(function, data);
251
245
  g_idle_add(call_single_shot, call);
252
246
  return call;
253
247
  }
@@ -256,7 +250,7 @@ add_single_shot(RuburpleCallFunc function, gpointer data, gboolean do_free)
256
250
  static gpointer
257
251
  call_and_get_result(RuburpleCallFunc function, gpointer data)
258
252
  {
259
- RuburpleSingleShotCall *call = add_single_shot(function, data, FALSE);
253
+ RuburpleSingleShotCall *call = add_single_shot(function, data);
260
254
  gpointer return_value;
261
255
 
262
256
  g_mutex_lock(call->lock);
@@ -527,20 +521,47 @@ ruburple_protocol_get_account(gpointer data)
527
521
  return (gpointer) purple_account_new((char *) args[0], (char *) args[1]);
528
522
  }
529
523
 
524
+ static gpointer
525
+ ruburple_protocol_get_account_and_set_password(gpointer data)
526
+ {
527
+ gpointer *args = (gpointer *) data;
528
+ gpointer return_value;
529
+ return_value = (gpointer) purple_account_new((char *) args[0], (char *) args[1]);
530
+ purple_account_set_password((PurpleAccount *) return_value, (char *) args[2]);
531
+ return return_value;
532
+ }
533
+
530
534
  static VALUE
531
- rb_ruburple_protocol_get_account(VALUE self, VALUE name)
535
+ rb_ruburple_protocol_get_account(int argc, VALUE *argv, VALUE self)
532
536
  {
533
537
  PurplePlugin *plugin;
534
- gpointer *args = g_new(gpointer, 2);
538
+ gpointer *args;
535
539
  VALUE return_value;
536
540
 
537
- Check_Type(name, T_STRING);
541
+ if (argc > 2)
542
+ rb_raise(rb_eRuntimeError, "Ruburple::Protocol#get_account(USERNAME, PASSWORD = nil) takes at most 2 arguments");
543
+ else if (argc < 1)
544
+ rb_raise(rb_eRuntimeError, "Ruburple::Protocol#get_account(USERNAME, PASSWORD = nil) takes at least 1 argument");
545
+ else if (argc > 1)
546
+ Check_Type(argv[1], T_STRING);
547
+ Check_Type(argv[0], T_STRING);
548
+
538
549
  PURPLE_PLUGIN(self, plugin);
539
550
 
540
- args[0] = (gpointer) RSTRING(name)->ptr;
551
+ if (argc == 1)
552
+ args = g_new(gpointer, 2);
553
+ else if (argc == 2)
554
+ args = g_new(gpointer, 3);
555
+
556
+ args[0] = (gpointer) RSTRING(argv[0])->ptr;
541
557
  args[1] = (gpointer) plugin->info->id;
542
558
 
543
- return_value = RB_RUBURPLE_PROTOCOL_ACCOUNT_gc((PurpleAccount *) call_and_get_result(ruburple_protocol_get_account, args));
559
+ if (argc == 1)
560
+ return_value = RB_RUBURPLE_PROTOCOL_ACCOUNT_gc((PurpleAccount *) call_and_get_result(ruburple_protocol_get_account, args));
561
+ else if (argc == 2) {
562
+ args[2] = (gpointer) RSTRING(argv[1])->ptr;
563
+ return_value = RB_RUBURPLE_PROTOCOL_ACCOUNT_gc((PurpleAccount *) call_and_get_result(ruburple_protocol_get_account_and_set_password, args));
564
+ }
544
565
 
545
566
  g_free(args);
546
567
 
@@ -1042,7 +1063,7 @@ rb_ruburple_protocol_connection_send_im(int argc, VALUE *argv, VALUE self)
1042
1063
  int rval;
1043
1064
 
1044
1065
  if (argc > 3)
1045
- rb_raise(rb_eRuntimeError, "Connection#send_im(RECIPIENT, MESSAGE, FLAGS = 0) takes at most 3 arguments");
1066
+ rb_raise(rb_eRuntimeError, "Ruburple::Protocol::Connection#send_im(RECIPIENT, MESSAGE, FLAGS = 0) takes at most 3 arguments");
1046
1067
  if (argc == 3) {
1047
1068
  Check_Type(argv[2], T_FIXNUM);
1048
1069
  flags = NUM2INT(argv[2]);
@@ -1051,7 +1072,7 @@ rb_ruburple_protocol_connection_send_im(int argc, VALUE *argv, VALUE self)
1051
1072
  Check_Type(argv[1], T_STRING);
1052
1073
  Check_Type(argv[0], T_STRING);
1053
1074
  } else {
1054
- rb_raise(rb_eRuntimeError, "Connection#send_im(RECIPIENT, MESSAGE, FLAGS = 0) takes at least 2 arguments");
1075
+ rb_raise(rb_eRuntimeError, "Ruburple::Protocol::Connection#send_im(RECIPIENT, MESSAGE, FLAGS = 0) takes at least 2 arguments");
1055
1076
  }
1056
1077
 
1057
1078
  PURPLE_CONNECTION(self, connection);
@@ -1165,7 +1186,7 @@ extern "C" {
1165
1186
  rb_ruburple_plugin = rb_define_class_under(rb_ruburple, "Plugin", rb_cObject);
1166
1187
 
1167
1188
  rb_ruburple_protocol = rb_define_class_under(rb_ruburple, "Protocol", rb_ruburple_plugin);
1168
- rb_define_method(rb_ruburple_protocol, "get_account", rb_ruburple_protocol_get_account, 1);
1189
+ rb_define_method(rb_ruburple_protocol, "get_account", rb_ruburple_protocol_get_account, -1);
1169
1190
  rb_define_method(rb_ruburple_protocol, "id", rb_protocol_get_id, 0);
1170
1191
  rb_define_method(rb_ruburple_protocol, "name", rb_protocol_get_name, 0);
1171
1192
  rb_define_method(rb_ruburple_protocol, "version", rb_protocol_get_version, 0);
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: ruburple
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.2
6
+ version: 0.0.3
7
7
  date: 2007-05-05 00:00:00 +02:00
8
8
  summary: An ruby extension to libpurple.
9
9
  require_paths: