ruburple 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -14,9 +14,13 @@ pkg-config:: Just for extconf.rb to be able to find glib-2.0. Should be installe
14
14
  I hade some trouble getting a precompiled set of libpurple libs with headers, so I downloaded the source.
15
15
 
16
16
  Then, to build, I did:
17
- ./configure --disable-gtkui --disable-consoleui --disable-screensaver --disable-startup-notification --disable-sm --disable-gtkspell --disable-gevolution --disable-cap --disable-gstreamer --disable-tcl --disable-tk --disable-doxygen --disable-perl --with-gnutls-includes=/opt/local/include/ --with-gnutls-libs=/opt/local/lib/
17
+ env CFLAGS="-I/opt/local/include -L/opt/local/lib" ./configure --disable-gtkui --disable-consoleui --disable-screensaver --disable-startup-notification --disable-sm --disable-gtkspell --disable-gevolution --disable-cap --disable-gstreamer --disable-tcl --disable-tk --disable-doxygen --disable-perl --with-gnutls-includes=/opt/local/include/ --with-gnutls-libs=/opt/local/lib/
18
18
 
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.
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. Also, the CFLAGS are because for some reason configure couldnt find my gettext header files...
20
+
21
+ !!!NOTE!!! You wont be able to use MSN and some other protocols unless your build finds an SSL library, like gnutls above!
22
+
23
+ To make sure that you have found an SSL library, just look at the results of the ./configure command.
20
24
 
21
25
  == Usage example:
22
26
 
data/ext/ruburple_ext.c CHANGED
@@ -53,8 +53,8 @@ static VALUE rb_ruburple_protocol_account_transfer;
53
53
  static VALUE rb_ruburple_protocol_account_conversation;
54
54
  static VALUE rb_ruburple_protocol_account_chat;
55
55
  static VALUE rb_ruburple_protocol_account_savedstatus;
56
+ static VALUE rb_ruburple_protocol_account_status;
56
57
  static VALUE rb_ruburple_protocol_connection;
57
- static VALUE rb_ruburple_blist_status;
58
58
  static VALUE rb_ruburple_blist;
59
59
  static VALUE rb_ruburple_blist_buddy_icon;
60
60
  static VALUE rb_ruburple_blist_buddy;
@@ -113,7 +113,7 @@ static VALUE delete_method_id;
113
113
  #define RB_RUBURPLE_PROTOCOL(purple_plugin_pointer) Data_Wrap_Struct(rb_ruburple_protocol, NULL, NULL, purple_plugin_pointer)
114
114
  #define RB_RUBURPLE_PLUGIN(purple_plugin_pointer) Data_Wrap_Struct(rb_ruburple_plugin, NULL, NULL, purple_plugin_pointer)
115
115
  #define RB_RUBURPLE_PROTOCOL_INFO(purple_plugin_info_pointer) Data_Wrap_Struct(rb_ruburple_protocol_info, NULL, NULL, purple_plugin_info_pointer)
116
- #define RB_RUBURPLE_BLIST_STATUS(purple_status_pointer) Data_Wrap_Struct(rb_ruburple_blist_status, NULL, NULL, purple_status_pointer)
116
+ #define RB_RUBURPLE_PROTOCOL_ACCOUNT_STATUS(purple_status_pointer) Data_Wrap_Struct(rb_ruburple_protocol_account_status, NULL, NULL, purple_status_pointer)
117
117
  #define RB_RUBURPLE_BLIST(purple_blist_pointer) Data_Wrap_Struct(rb_ruburple_blist, NULL, NULL, purple_blist_pointer)
118
118
  #define RB_RUBURPLE_BLIST_BUDDY(purple_buddy_pointer) Data_Wrap_Struct(rb_ruburple_blist_buddy, NULL, NULL, purple_buddy_pointer)
119
119
  #define RB_RUBURPLE_BLIST_NODE(purple_blist_node_pointer) Data_Wrap_Struct(rb_ruburple_blist_node, NULL, NULL, purple_blist_node_pointer)
@@ -139,7 +139,7 @@ static VALUE delete_method_id;
139
139
  #define RUBURPLE_SIGNAL_HANDLER(rb_ruburple_subscription,ruburple_signal_handler_pointer) Data_Get_Struct(rb_ruburple_subscription, RuburpleSignalHandler, ruburple_signal_handler_pointer)
140
140
  #define PURPLE_CONNECTION(rb_ruburple_protocol_connection,purple_connection_pointer) Data_Get_Struct(rb_ruburple_protocol_connection, PurpleConnection, purple_connection_pointer)
141
141
  #define PURPLE_BUDDY(rb_ruburple_blist_buddy,purple_buddy_pointer) Data_Get_Struct(rb_ruburple_blist_buddy, PurpleBuddy, purple_buddy_pointer)
142
- #define PURPLE_STATUS(rb_ruburple_blist_status,purple_status_pointer) Data_Get_Struct(rb_ruburple_blist_status, PurpleStatus, purple_status_pointer)
142
+ #define PURPLE_STATUS(rb_ruburple_protocol_account_status,purple_status_pointer) Data_Get_Struct(rb_ruburple_protocol_account_status, PurpleStatus, purple_status_pointer)
143
143
  #define GPOINTER(rb_ruburple_pointer,gpointer) Data_Get_Struct(rb_ruburple_pointer, void, gpointer)
144
144
 
145
145
  /*
@@ -341,15 +341,55 @@ static guint glib_input_add(gint fd, PurpleInputCondition condition, PurpleInput
341
341
  }
342
342
 
343
343
  static PurpleEventLoopUiOps glib_eventloops =
344
- {
345
- g_timeout_add,
346
- g_source_remove,
347
- glib_input_add,
348
- g_source_remove,
349
- NULL
350
- };
344
+ {
345
+ g_timeout_add,
346
+ g_source_remove,
347
+ glib_input_add,
348
+ g_source_remove,
349
+ NULL
350
+ };
351
351
  /*** End of the eventloop functions. ***/
352
352
 
353
+ static gpointer
354
+ ruburple_notify_message(PurpleNotifyMsgType type,
355
+ const char *title,
356
+ const char *primary,
357
+ const char *secondary)
358
+ {
359
+ switch (type) {
360
+ case PURPLE_NOTIFY_MSG_ERROR:
361
+ printf("Error message: %s\n%s\n%s\n", title, primary, secondary);
362
+ break;
363
+ case PURPLE_NOTIFY_MSG_WARNING:
364
+ printf("Warning message: %s\n%s\n%s\n", title, primary, secondary);
365
+ break;
366
+ case PURPLE_NOTIFY_MSG_INFO:
367
+ printf("Error message: %s\n%s\n%s\n", title, primary, secondary);
368
+ break;
369
+ default:
370
+ printf("Unknown message: %s\n%s\n%s\n", title, primary, secondary);
371
+ break;
372
+ }
373
+ fflush(NULL);
374
+ }
375
+
376
+ static PurpleNotifyUiOps notify_ops =
377
+ {
378
+ ruburple_notify_message,
379
+ NULL,
380
+ NULL,
381
+ NULL,
382
+ NULL,
383
+ NULL,
384
+ NULL,
385
+ NULL,
386
+ NULL,
387
+ NULL,
388
+ NULL,
389
+ NULL,
390
+ NULL,
391
+ };
392
+
353
393
  static gpointer
354
394
  run_the_loop(gpointer data)
355
395
  {
@@ -367,6 +407,8 @@ rb_ruburple_init(VALUE self)
367
407
  /* Set the uiops for the eventloop. If your client is glib-based, you can safely
368
408
  * copy this verbatim. */
369
409
  purple_eventloop_set_ui_ops(&glib_eventloops);
410
+
411
+ purple_notify_set_ui_ops(&notify_ops);
370
412
 
371
413
  /* Now that all the essential stuff has been set, let's try to init the core. It's
372
414
  * necessary to provide a non-NULL name for the current ui to the core. This name
@@ -726,7 +768,7 @@ rb_ruburple_protocol_account_get_status(VALUE self)
726
768
  PURPLE_ACCOUNT(self, account);
727
769
  status = (PurpleStatus *) call_and_get_result(ruburple_protocol_account_get_status, (gpointer) account);
728
770
  RETURN_QNIL_IF_NULL(status);
729
- return RB_RUBURPLE_BLIST_STATUS(status);
771
+ return RB_RUBURPLE_PROTOCOL_ACCOUNT_STATUS(status);
730
772
  }
731
773
 
732
774
  static gpointer
@@ -835,7 +877,7 @@ get_ruby_instance_from_subtype(PurpleValue *value, gpointer data, int i, char *s
835
877
  return(RB_RUBURPLE_CIPHER((PurpleCipher *) data));
836
878
  break;
837
879
  case PURPLE_SUBTYPE_STATUS:
838
- return(RB_RUBURPLE_BLIST_STATUS((PurpleStatus *) data));
880
+ return(RB_RUBURPLE_PROTOCOL_ACCOUNT_STATUS((PurpleStatus *) data));
839
881
  break;
840
882
  case PURPLE_SUBTYPE_LOG:
841
883
  return(RB_RUBURPLE_LOG((PurpleLog *) data));
@@ -1362,18 +1404,41 @@ rb_ruburple_blist_buddy_get_name(VALUE self)
1362
1404
  }
1363
1405
 
1364
1406
  static gpointer
1365
- ruburple_blist_status_get_name(gpointer data)
1407
+ ruburple_protocol_account_status_get_name(gpointer data)
1366
1408
  {
1367
1409
  PurpleStatus *status = (PurpleStatus *) data;
1368
1410
  return (gpointer) purple_status_get_name(status);
1369
1411
  }
1370
1412
 
1371
1413
  static VALUE
1372
- rb_ruburple_blist_status_get_name(VALUE self)
1414
+ rb_ruburple_protocol_account_status_get_name(VALUE self)
1373
1415
  {
1374
1416
  PurpleStatus *status;
1375
1417
  PURPLE_STATUS(self, status);
1376
- return rb_str_new2((char *) call_and_get_result(ruburple_blist_status_get_name, (gpointer) status));
1418
+ return rb_str_new2((char *) call_and_get_result(ruburple_protocol_account_status_get_name, (gpointer) status));
1419
+ }
1420
+
1421
+ static gpointer
1422
+ ruburple_protocol_account_status_get_primitive(gpointer data)
1423
+ {
1424
+ gpointer *args = (gpointer *) data;
1425
+ * (int *) args[1] = purple_status_type_get_primitive((PurpleStatusType *) args[0]);
1426
+ return NULL;
1427
+ }
1428
+
1429
+ static VALUE
1430
+ rb_ruburple_protocol_account_status_get_primitive(VALUE self)
1431
+ {
1432
+ PurpleStatus *status;
1433
+ PurpleStatusType *type;
1434
+ gpointer args[2];
1435
+ int rval;
1436
+ PURPLE_STATUS(self, status);
1437
+ type = purple_status_get_type(status);
1438
+ args[0] = type;
1439
+ args[1] = &rval;
1440
+ call_and_get_result(ruburple_protocol_account_status_get_primitive, (gpointer) args);
1441
+ return INT2NUM(rval);
1377
1442
  }
1378
1443
 
1379
1444
  static VALUE
@@ -1404,7 +1469,7 @@ rb_ruburple_blist_buddy_get_status(VALUE self)
1404
1469
  {
1405
1470
  PurpleBuddy *buddy;
1406
1471
  PURPLE_BUDDY(self, buddy);
1407
- return RB_RUBURPLE_BLIST_STATUS((PurpleStatus *) call_and_get_result(ruburple_blist_buddy_get_status, (gpointer) buddy));
1472
+ return RB_RUBURPLE_PROTOCOL_ACCOUNT_STATUS((PurpleStatus *) call_and_get_result(ruburple_blist_buddy_get_status, (gpointer) buddy));
1408
1473
  }
1409
1474
 
1410
1475
  #ifdef __cplusplus
@@ -1491,7 +1556,7 @@ extern "C" {
1491
1556
  rb_define_method(rb_ruburple_protocol, "author", rb_protocol_get_author, 0);
1492
1557
  rb_define_method(rb_ruburple_protocol, "homepage", rb_protocol_get_homepage, 0);
1493
1558
 
1494
- rb_ruburple_protocol_account = rb_define_class_under(rb_ruburple, "Account", rb_cObject);
1559
+ rb_ruburple_protocol_account = rb_define_class_under(rb_ruburple_protocol, "Account", rb_cObject);
1495
1560
  rb_define_method(rb_ruburple_protocol_account, "password=", rb_ruburple_protocol_account_set_password, 1);
1496
1561
  rb_define_method(rb_ruburple_protocol_account, "connect", rb_ruburple_protocol_account_connect, 0);
1497
1562
  rb_define_method(rb_ruburple_protocol_account, "enabled=", rb_ruburple_protocol_account_set_enabled, 1);
@@ -1516,16 +1581,17 @@ extern "C" {
1516
1581
 
1517
1582
  rb_ruburple_blist = rb_define_class_under(rb_ruburple, "BuddyList", rb_cObject);
1518
1583
 
1519
- rb_ruburple_blist_status = rb_define_class_under(rb_ruburple_blist, "Status", rb_cObject);
1520
- rb_define_method(rb_ruburple_blist_status, "name", rb_ruburple_blist_status_get_name, 0);
1521
- rb_define_const(rb_ruburple_blist_status, "STATUS_UNSET", INT2NUM(PURPLE_STATUS_UNSET));
1522
- rb_define_const(rb_ruburple_blist_status, "STATUS_OFFLINE", INT2NUM(PURPLE_STATUS_OFFLINE));
1523
- rb_define_const(rb_ruburple_blist_status, "STATUS_AVAILABLE", INT2NUM(PURPLE_STATUS_AVAILABLE));
1524
- rb_define_const(rb_ruburple_blist_status, "STATUS_UNAVAILABLE", INT2NUM(PURPLE_STATUS_UNAVAILABLE));
1525
- rb_define_const(rb_ruburple_blist_status, "STATUS_INVISIBLE", INT2NUM(PURPLE_STATUS_INVISIBLE));
1526
- rb_define_const(rb_ruburple_blist_status, "STATUS_AWAY", INT2NUM(PURPLE_STATUS_AWAY));
1527
- rb_define_const(rb_ruburple_blist_status, "STATUS_EXTENDED_AWAY", INT2NUM(PURPLE_STATUS_EXTENDED_AWAY));
1528
- rb_define_const(rb_ruburple_blist_status, "STATUS_MOBILE", INT2NUM(PURPLE_STATUS_MOBILE));
1584
+ rb_ruburple_protocol_account_status = rb_define_class_under(rb_ruburple_protocol_account, "Status", rb_cObject);
1585
+ rb_define_method(rb_ruburple_protocol_account_status, "name", rb_ruburple_protocol_account_status_get_name, 0);
1586
+ rb_define_method(rb_ruburple_protocol_account_status, "primitive", rb_ruburple_protocol_account_status_get_primitive, 0);
1587
+ rb_define_const(rb_ruburple_protocol_account_status, "STATUS_UNSET", INT2NUM(PURPLE_STATUS_UNSET));
1588
+ rb_define_const(rb_ruburple_protocol_account_status, "STATUS_OFFLINE", INT2NUM(PURPLE_STATUS_OFFLINE));
1589
+ rb_define_const(rb_ruburple_protocol_account_status, "STATUS_AVAILABLE", INT2NUM(PURPLE_STATUS_AVAILABLE));
1590
+ rb_define_const(rb_ruburple_protocol_account_status, "STATUS_UNAVAILABLE", INT2NUM(PURPLE_STATUS_UNAVAILABLE));
1591
+ rb_define_const(rb_ruburple_protocol_account_status, "STATUS_INVISIBLE", INT2NUM(PURPLE_STATUS_INVISIBLE));
1592
+ rb_define_const(rb_ruburple_protocol_account_status, "STATUS_AWAY", INT2NUM(PURPLE_STATUS_AWAY));
1593
+ rb_define_const(rb_ruburple_protocol_account_status, "STATUS_EXTENDED_AWAY", INT2NUM(PURPLE_STATUS_EXTENDED_AWAY));
1594
+ rb_define_const(rb_ruburple_protocol_account_status, "STATUS_MOBILE", INT2NUM(PURPLE_STATUS_MOBILE));
1529
1595
 
1530
1596
  rb_ruburple_protocol_connection = rb_define_class_under(rb_ruburple_protocol, "Connection", rb_cObject);
1531
1597
  rb_define_method(rb_ruburple_protocol_connection, "send_im", rb_ruburple_protocol_connection_send_im, -1);
@@ -29,22 +29,23 @@ class RuburpleTest < Test::Unit::TestCase
29
29
  }
30
30
  end
31
31
 
32
- def test_protocols
33
- $TEST_ACCOUNTS.keys.each do |key|
34
- test_operations(key)
32
+ def test_accounts
33
+ $TEST_ACCOUNTS.each do |ac1, ac2|
34
+ test_operations(ac1, ac2)
35
35
  end
36
36
  end
37
37
 
38
38
  private
39
39
 
40
- def test_operations(protocol)
41
- puts "testing #{protocol}..."
42
- assert(Ruburple::has_protocol?(protocol))
43
- test_accounts = $TEST_ACCOUNTS[protocol]
44
- p = Ruburple::get_protocol(protocol)
40
+ def test_operations(ac1, ac2)
41
+ puts "testing #{ac1.protocol} + #{ac2.protocol}..."
42
+ assert(Ruburple::has_protocol?(ac1.protocol))
43
+ assert(Ruburple::has_protocol?(ac2.protocol))
44
+ p1 = Ruburple::get_protocol(ac1.protocol)
45
+ p2 = Ruburple::get_protocol(ac2.protocol)
45
46
  puts "testing get account..."
46
- a1 = p.get_account(test_accounts.first.username, test_accounts.first.password)
47
- a2 = p.get_account(test_accounts.last.username, test_accounts.last.password)
47
+ a1 = p1.get_account(ac1.username, ac1.password)
48
+ a2 = p2.get_account(ac2.username, ac2.password)
48
49
  puts "testing connecting..."
49
50
  assert(!a1.connecting?)
50
51
  a1.connect
@@ -60,13 +61,12 @@ class RuburpleTest < Test::Unit::TestCase
60
61
  puts "testing uid..."
61
62
  assert(a1.uid != a2.uid)
62
63
  assert_equal(a1.uid, a1.connection.account.uid)
64
+ sleep 2
63
65
  puts "testing buddies..."
64
66
  assert(a1.has_buddy?(a2.username))
65
67
  assert(buddy2 = a1.buddies.find do |b|
66
- b.name == a2.username
68
+ a2.username =~ /#{Regexp.escape(b.name)}/
67
69
  end)
68
- puts "testing presence..."
69
- assert_equal("Offline", buddy2.status.name)
70
70
  puts "testing set enabled..."
71
71
  a2.enabled = true
72
72
  assert_within(30) do
@@ -74,18 +74,19 @@ class RuburpleTest < Test::Unit::TestCase
74
74
  e.account.username == a2.username
75
75
  end
76
76
  end
77
+ a1.savedstatus = Ruburple::Protocol::Account::SavedStatus.new(Ruburple::Protocol::Account::Status::STATUS_AVAILABLE)
78
+ a2.savedstatus = Ruburple::Protocol::Account::SavedStatus.new(Ruburple::Protocol::Account::Status::STATUS_AVAILABLE)
79
+ puts "testing status..."
80
+ assert_equal("Available", a1.status.name)
81
+ assert_equal("Available", a2.status.name)
82
+ assert_equal(Ruburple::Protocol::Account::Status::STATUS_AVAILABLE, a1.status.primitive)
83
+ assert_equal(Ruburple::Protocol::Account::Status::STATUS_AVAILABLE, a2.status.primitive)
77
84
  puts "testing buddies..."
85
+ sleep 2
78
86
  assert(a2.has_buddy?(a1.username))
79
87
  assert(buddy1 = a2.buddies.find do |b|
80
- b.name == a1.username
88
+ a1.username =~ /#{Regexp.escape(b.name)}/
81
89
  end)
82
- puts "testing presence..."
83
- assert_within(30) do
84
- buddy1.status.name == "Available"
85
- end
86
- assert_within(30) do
87
- buddy2.status.name == "Available"
88
- end
89
90
  puts "testing send im..."
90
91
  a1.connection.send_im(a2.username, "hello a2")
91
92
  a2.connection.send_im(a1.username, "hello a1")
@@ -100,10 +101,6 @@ class RuburpleTest < Test::Unit::TestCase
100
101
  end
101
102
  puts "testing set enabled..."
102
103
  a1.enabled = false
103
- puts "testing presence..."
104
- assert_within(30) do
105
- buddy1.status.name == "Offline"
106
- end
107
104
  puts "testing close..."
108
105
  a2.connection.close
109
106
  end
@@ -1,7 +1,8 @@
1
1
 
2
- $TEST_ACCOUNTS = {
3
- "MSN" => [
4
- TestAccount.new("MSN", "blabahtest1@blabah.com", "blabah"),
5
- TestAccount.new("MSN", "blabahtest2@blabah.com", "blabah")
6
- ]
7
- }
2
+ #
3
+ # These accounts should be on each others buddy lists for the tests to run.
4
+ #
5
+ $TEST_ACCOUNTS = [[
6
+ TestAccount.new("XMPP", "blabahtest1@gmail.com", "blabah1"),
7
+ TestAccount.new("XMPP", "blabahtest3@gmail.com", "blabah3")
8
+ ]]
@@ -2,9 +2,7 @@
2
2
  #
3
3
  # These accounts should be on each others buddy lists for the tests to run.
4
4
  #
5
- $TEST_ACCOUNTS = {
6
- "MSN" => [
7
- TestAccount.new("MSN", "some@msn.account", "some_msn_password"),
8
- TestAccount.new("MSN", "some@msn.account", "some_msn_password")
9
- ]
10
- }
5
+ $TEST_ACCOUNTS = [[
6
+ TestAccount.new("XMPP", "some@xmpp.account", "some_xmpp_password"),
7
+ TestAccount.new("XMPP", "some@xmpp.account", "some_xmpp_password")
8
+ ]]
metadata CHANGED
@@ -3,8 +3,8 @@ 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.6
7
- date: 2007-05-08 00:00:00 +02:00
6
+ version: 0.0.7
7
+ date: 2007-05-13 00:00:00 +02:00
8
8
  summary: An ruby extension to libpurple.
9
9
  require_paths:
10
10
  - lib