[Ruburple-submits] [11] trunk/ruburple/ext/ruburple_ext.c: made it possible to create an account and set password at the same time

nobody at rubyforge.org nobody at rubyforge.org
Sat May 5 06:25:25 EDT 2007


Revision: 11
Author:   zond
Date:     2007-05-05 06:25:25 -0400 (Sat, 05 May 2007)

Log Message:
-----------
made it possible to create an account and set password at the same time

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

Modified: trunk/ruburple/ext/ruburple_ext.c
===================================================================
--- trunk/ruburple/ext/ruburple_ext.c	2007-05-05 02:19:45 UTC (rev 10)
+++ trunk/ruburple/ext/ruburple_ext.c	2007-05-05 10:25:25 UTC (rev 11)
@@ -521,20 +521,47 @@
   return (gpointer) purple_account_new((char *) args[0], (char *) args[1]);
 }
 
+static gpointer
+ruburple_protocol_get_account_and_set_password(gpointer data)
+{
+  gpointer *args = (gpointer *) data;
+  gpointer return_value;
+  return_value = (gpointer) purple_account_new((char *) args[0], (char *) args[1]);
+  purple_account_set_password((PurpleAccount *) return_value, (char *) args[2]);
+  return return_value;
+}
+
 static VALUE
-rb_ruburple_protocol_get_account(VALUE self, VALUE name)
+rb_ruburple_protocol_get_account(int argc, VALUE *argv, VALUE self)
 {
   PurplePlugin *plugin;
-  gpointer *args = g_new(gpointer, 2);
+  gpointer *args;
   VALUE return_value;
 
-  Check_Type(name, T_STRING);
+  if (argc > 2)
+    rb_raise(rb_eRuntimeError, "Ruburple::Protocol#get_account(USERNAME, PASSWORD = nil) takes at most 2 arguments");
+  else if (argc < 1)
+    rb_raise(rb_eRuntimeError, "Ruburple::Protocol#get_account(USERNAME, PASSWORD = nil) takes at least 1 argument");
+  else if (argc > 1)
+    Check_Type(argv[1], T_STRING);
+  Check_Type(argv[0], T_STRING);
+
   PURPLE_PLUGIN(self, plugin);
 
-  args[0] = (gpointer) RSTRING(name)->ptr;
+  if (argc == 1)
+    args = g_new(gpointer, 2);
+  else if (argc == 2)
+    args = g_new(gpointer, 3);
+
+  args[0] = (gpointer) RSTRING(argv[0])->ptr;
   args[1] = (gpointer) plugin->info->id;
   
-  return_value = RB_RUBURPLE_PROTOCOL_ACCOUNT_gc((PurpleAccount *) call_and_get_result(ruburple_protocol_get_account, args));
+  if (argc == 1)
+    return_value = RB_RUBURPLE_PROTOCOL_ACCOUNT_gc((PurpleAccount *) call_and_get_result(ruburple_protocol_get_account, args));
+  else if (argc == 2) {
+    args[2] = (gpointer) RSTRING(argv[1])->ptr;
+    return_value = RB_RUBURPLE_PROTOCOL_ACCOUNT_gc((PurpleAccount *) call_and_get_result(ruburple_protocol_get_account_and_set_password, args));
+  }
 
   g_free(args);
 
@@ -1036,7 +1063,7 @@
   int rval;
 
   if (argc > 3)
-    rb_raise(rb_eRuntimeError, "Connection#send_im(RECIPIENT, MESSAGE, FLAGS = 0) takes at most 3 arguments");
+    rb_raise(rb_eRuntimeError, "Ruburple::Protocol::Connection#send_im(RECIPIENT, MESSAGE, FLAGS = 0) takes at most 3 arguments");
   if (argc == 3) {
     Check_Type(argv[2], T_FIXNUM);
     flags = NUM2INT(argv[2]);
@@ -1045,7 +1072,7 @@
     Check_Type(argv[1], T_STRING);
     Check_Type(argv[0], T_STRING);
   } else {
-    rb_raise(rb_eRuntimeError, "Connection#send_im(RECIPIENT, MESSAGE, FLAGS = 0) takes at least 2 arguments");
+    rb_raise(rb_eRuntimeError, "Ruburple::Protocol::Connection#send_im(RECIPIENT, MESSAGE, FLAGS = 0) takes at least 2 arguments");
   }
 
   PURPLE_CONNECTION(self, connection);
@@ -1159,7 +1186,7 @@
     rb_ruburple_plugin = rb_define_class_under(rb_ruburple, "Plugin", rb_cObject);
 
     rb_ruburple_protocol = rb_define_class_under(rb_ruburple, "Protocol", rb_ruburple_plugin);
-    rb_define_method(rb_ruburple_protocol, "get_account", rb_ruburple_protocol_get_account, 1);
+    rb_define_method(rb_ruburple_protocol, "get_account", rb_ruburple_protocol_get_account, -1);
     rb_define_method(rb_ruburple_protocol, "id", rb_protocol_get_id, 0);
     rb_define_method(rb_ruburple_protocol, "name", rb_protocol_get_name, 0);
     rb_define_method(rb_ruburple_protocol, "version", rb_protocol_get_version, 0);




More information about the Ruburple-submits mailing list