[Ruburple-submits] [26] trunk/ruburple/ext/ruburple_ext.c: added methods to fetch protocol from account and connection

nobody at rubyforge.org nobody at rubyforge.org
Mon May 7 08:21:23 EDT 2007


Revision: 26
Author:   zond
Date:     2007-05-07 08:21:23 -0400 (Mon, 07 May 2007)

Log Message:
-----------
added methods to fetch protocol from account and connection

Modified Paths:
--------------
    trunk/ruburple/ext/ruburple_ext.c

Modified: trunk/ruburple/ext/ruburple_ext.c
===================================================================
--- trunk/ruburple/ext/ruburple_ext.c	2007-05-07 11:43:33 UTC (rev 25)
+++ trunk/ruburple/ext/ruburple_ext.c	2007-05-07 12:21:23 UTC (rev 26)
@@ -504,6 +504,12 @@
   return (gpointer) purple_plugins_get_protocols();
 }
 
+static gpointer
+ruburple_get_protocol(gpointer data)
+{
+  return (gpointer) purple_plugins_find_with_name((char *) data);
+}
+
 static VALUE
 rb_ruburple_get_protocols(VALUE self)
 {
@@ -520,15 +526,9 @@
 static VALUE
 rb_ruburple_get_protocol(VALUE self, VALUE name)
 {
-  GList *iter;
-  VALUE return_value;
-
-  for (iter = (GList *) call_and_get_result(ruburple_get_protocols, NULL); iter; iter = iter->next) {
-    if (strcmp(purple_plugin_get_name((PurplePlugin *) iter->data), RSTRING(name)->ptr) == 0)
-      return RB_RUBURPLE_PROTOCOL(iter->data);
-  }
-
-  return Qnil;
+  PurplePlugin *protocol = (PurplePlugin *) call_and_get_result(ruburple_get_protocol, (gpointer) RSTRING(name)->ptr);
+  RETURN_QNIL_IF_NULL(protocol);
+  return RB_RUBURPLE_PROTOCOL(protocol);
 }
 
 static VALUE
@@ -1376,6 +1376,29 @@
   return INT2NUM((int) account);
 }
 
+static gpointer
+ruburple_protocol_account_get_protocol(gpointer data)
+{
+  return (gpointer) purple_plugins_find_with_id(purple_account_get_protocol_id((PurpleAccount *) data));
+}
+
+static VALUE
+rb_ruburple_protocol_account_get_protocol(VALUE self)
+{
+  PurpleAccount *account;
+  PURPLE_ACCOUNT(self, account);
+  return RB_RUBURPLE_PROTOCOL((PurplePlugin *) call_and_get_result(ruburple_protocol_account_get_protocol, account));
+}
+
+static VALUE
+rb_ruburple_protocol_connection_get_protocol(VALUE self)
+{
+  PurpleConnection *connection;
+  PURPLE_CONNECTION(self, connection);
+  RETURN_QNIL_IF_NULL(connection->prpl);
+  return RB_RUBURPLE_PROTOCOL(connection->prpl);
+}
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -1462,6 +1485,7 @@
 
     rb_ruburple_protocol_account = rb_define_class_under(rb_ruburple, "Account", rb_cObject);
     rb_define_method(rb_ruburple_protocol_account, "password=", rb_ruburple_protocol_account_set_password, 1);
+    rb_define_method(rb_ruburple_protocol_account, "protocol", rb_ruburple_protocol_account_get_protocol, 0);
     rb_define_method(rb_ruburple_protocol_account, "connect", rb_ruburple_protocol_account_connect, 0);
     rb_define_method(rb_ruburple_protocol_account, "enabled=", rb_ruburple_protocol_account_set_enabled, 1);
     rb_define_method(rb_ruburple_protocol_account, "savedstatus=", rb_ruburple_protocol_account_set_savedstatus, 1);
@@ -1496,6 +1520,7 @@
 
     rb_ruburple_protocol_connection = rb_define_class_under(rb_ruburple_protocol, "Connection", rb_cObject);
     rb_define_method(rb_ruburple_protocol_connection, "send_im", rb_ruburple_protocol_connection_send_im, -1);
+    rb_define_method(rb_ruburple_protocol_connection, "protocol", rb_ruburple_protocol_connection_get_protocol, 0);
     rb_define_method(rb_ruburple_protocol_connection, "close", rb_ruburple_protocol_connection_close, 0);
     rb_define_method(rb_ruburple_protocol_connection, "account", rb_ruburple_protocol_connection_get_account, 0);
 




More information about the Ruburple-submits mailing list